Ejemplo n.º 1
0
bool CGIOutput::writeSearchResult(string resultURL, string origURL, string resultTitle, string resultSummary, double resultScore, int datasource, int resultID) {
  if (currentNumDisplayedResults >= maxResultsPerPage) return false;

  SingleResultItem thisItem(resultItemTemplate);

  thisItem.setVariable("URL", resultURL);
  thisItem.setVariable("title", resultTitle);
  thisItem.setVariable("summary", resultSummary);
  stringstream sScore;
  sScore << resultScore;
  thisItem.setVariable("score", sScore.str());
  stringstream sResultID;
  sResultID << resultID;
  thisItem.setVariable("id", sResultID.str());
  stringstream sDataSourceID;
  sDataSourceID << datasource;
  thisItem.setVariable("datasource", sDataSourceID.str());
  thisItem.setVariable("scriptname", scriptURL);

  if (CGIConfiguration::getInstance().getStripRootPathFlag()) {
    string dRootString(CGIConfiguration::getInstance().getRootPath(0));
    string oURLCopy(origURL);

    if (oURLCopy.find(dRootString)==0) {
      // remove the data root from the docext path...
      oURLCopy.erase(0,dRootString.length());
      thisItem.setVariable("URL", oURLCopy);

      // should we add anything?
      oURLCopy.insert(0, CGIConfiguration::getInstance().getRootAddPath());

      if ((oURLCopy.find("http://")!=0) && (oURLCopy.find("HTTP://")!=0)) {
        oURLCopy="http://" + oURLCopy;
      }
    }
    thisItem.setVariable("origURL", oURLCopy);

    // see if the title has the same problem...
    string tCopy(resultTitle);
    if (tCopy.find(dRootString)==0) {
      tCopy.erase(0, dRootString.length());
      thisItem.setVariable("title", tCopy);
    }

  } else {
    thisItem.setVariable("URL", "");
    thisItem.setVariable("origURL", origURL);
  }

  cout << "<li>" << thisItem.toString() << "</li>\n";

  currentNumDisplayedResults++;

  if (currentNumDisplayedResults >= maxResultsPerPage) return false;

  return true;
}
Ejemplo n.º 2
0
  /**
   * Add an integer value to the next column in this row
   * 
   * @param item The integer value to put in this column.
   */
  void WriteTabular::Write(int item){
    Column thisCol = p_cols[p_curCol];
    if (thisCol.DataType() != Column::Integer &&
        thisCol.DataType() != Column::Pixel) {
      if (thisCol.DataType() == Column::Real ||
          thisCol.DataType() == Column::Pixel) {
        Write((double)item);
        return;
      }
      std::string message = "Wrong data type for this Column";
      throw Isis::iException::Message(Isis::iException::User,message,_FILEINFO_);
    }
    iString thisItem(item);
    if (thisItem.length() > thisCol.Width()) {
      thisItem = "*";
      while (thisItem.length() < thisCol.Width()) {
        thisItem += "*";
      }
    }
    std::stringstream tempStream;
    tempStream.width(thisCol.Width());
    tempStream.fill(' ');

    if (thisCol.Alignment() == Column::Left) {
      tempStream.setf(std::ios::left);
    }
    else tempStream.setf(std::ios::right);

    tempStream << thisItem;
    thisItem = tempStream.str();

    if (p_curCol == 0) {
      p_rows++;
    }

    if (p_curCol < (p_cols.size()-1)) {
      thisItem += p_delimiter;
      p_curCol++;
    }
    else {
      thisItem += "\n";
      p_curCol = 0;
    }
    p_outfile << thisItem.c_str();
  }
Ejemplo n.º 3
0
  /**
   * Writes a floating-point value out to the next column in the current row
   * 
   * @param item The value to be printed out
   */
  void WriteTabular::Write(double item){
    Column thisCol = p_cols[p_curCol];
    if (thisCol.DataType() != Column::Real &&
        thisCol.DataType() != Column::Pixel) {
      std::string message = "Wrong data type for this Column";
      throw Isis::iException::Message(Isis::iException::User,message,_FILEINFO_);
    }

    //Check for special pixels, if it's a pixel column
    if (thisCol.DataType() == Column::Pixel && IsSpecial(item)) {
      if (IsNullPixel(item)) {
        Write("Null");
        return;
      }
      if (IsHisPixel(item)) {
        Write("His");
        return;
      }
      if (IsHrsPixel(item)) {
        Write("Hrs");
        return;
      }
      if (IsLisPixel(item)) {
        Write("Lis");
        return;
      }
      if (IsLrsPixel(item)) {
        Write("Lrs");
        return;
      }
    }

    iString thisItem(item);


    if (thisCol.Alignment() == Column::Decimal) {

      //Format and round the number

      //First, split the number at the decimal point
      iString tempString = thisItem;
      iString intPart = tempString.Token(".");
      //Make the fractional portion appear as such, so the iomanipulators
      //handle it properly
      if (tempString != "") {
        tempString = "0." + tempString;
      }
      else tempString = "0.0";

      //Put the fractional portion into a stringstream, and use
      //stream manipulators to round it properly
      std::stringstream b;
      b << std::showpoint
        << std::setprecision(thisCol.Precision())
        << tempString.ToDouble();

      //if the rounding causes a rollover (i.e. the decimal portion is greater
      //than 0.95) increment the integer portion
      if (iString(b.str()).ToDouble() >= 1) {
        intPart = iString(intPart.ToInteger() + 1);
      }

      //Put it back into an iString, for easier manipulation
      tempString = b.str();
      tempString.Token(".");
      //Add any zeros necessary to pad the number
      while (tempString.size() < thisCol.Precision()) {
        tempString += "0";
      }

      //Put the number back together, adding the decimal point in the right location
      thisItem = intPart + "." + tempString;
    }
    std::stringstream tempStream;
    tempStream.width(thisCol.Width());
    tempStream.fill(' ');

    if (thisCol.Alignment() == Column::Left) {
      tempStream.setf(std::ios::left);
    }
    else tempStream.setf(std::ios::right);

    tempStream << thisItem;
    thisItem = tempStream.str();

    if (p_curCol == 0) {
      p_rows++;
    }

    //If the number is too wide for the column, replace with a string of stars
    if (thisItem.length() > thisCol.Width()) {
      thisItem = "*";
      while (thisItem.length() < thisCol.Width()) {
        thisItem += "*";
      }
    }

    if (p_curCol < (p_cols.size()-1)) {
      thisItem += p_delimiter;
      p_curCol++;
    }
    else {
      thisItem += "\n";
      p_curCol = 0;
    }
    p_outfile << thisItem;

  }