Changeset 1809


Ignore:
Timestamp:
2000-12-19T12:08:17+13:00 (23 years ago)
Author:
paynter
Message:

Sundry improvements. Better handling of empty prefixes & suffixes, full
text of a phrase no longer transmitted (only prefix & suffix), error
messages returned in XML when in xml mode.

Location:
trunk/gsdl/src/phind
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/phind/client/ResultBox.java

    r1635 r1809  
    248248    boolean parseLine() {
    249249
    250     // System.out.println("parseLine " + finished + "(" + expansionsRetrieved + ")");
     250        // System.out.println("parseLine " + finished + "(" + expansionsRetrieved + ")");
    251251    String item;
    252252    int eol = buffer.indexOf((int) '\n');
     
    296296
    297297    }
     298
     299    // The <phinderror> tag contains an error message
     300    else if (buffer.startsWith("<phinderror")) {
     301        item = buffer.substring(0, eol);
     302        System.out.println("phind reported an error: " + item);
     303        buffer = buffer.substring(eol + 1);
     304        return true;
     305    }
    298306 
    299307    // Ignore the piece we've read
     
    412420    //
    413421    // Given a string containing an XML expansin tag of the form:
    414     //   <expansion num="3" id="8421" text="PEOPLE and TREES" tf="3" df="3"/>
    415     //   <expansion num="4" id="8696" text="FOREST TREES" tf="3" df="3"/>
     422    //   <expansion num="3" id="8421" prefix="PEOPLE and" suffix="" tf="3" df="3"/>
     423    //   <expansion num="4" id="8696" prefix="" suffix="products" tf="3" df="3"/>
    416424    // Create a new ResultItem for display
    417425    //
     
    461469        line = line.substring(8);
    462470        nextSplit = line.indexOf((int) '"');
    463         if (nextSplit >= 1) {
     471        if (nextSplit >= 0) {
    464472            prefix = line.substring(0, nextSplit);
    465473            line = line.substring(nextSplit + 1);
     
    473481        line = line.substring(8);
    474482        nextSplit = line.indexOf((int) '"');
    475         if (nextSplit >= 1) {
     483        if (nextSplit >= 0) {
    476484            suffix = line.substring(0, nextSplit);
    477485            line = line.substring(nextSplit + 1);
     
    480488        }
    481489        }
    482 
    483         // Read the text of the phrase
    484         //      else if (line.startsWith("text")) {
    485         //line = line.substring(6);
    486         //nextSplit = line.indexOf((int) '"');
    487         //if (nextSplit >= 1) {
    488         //    body = line.substring(0, nextSplit);
    489         //    line = line.substring(nextSplit + 1);
    490         //} else {
    491         //    System.err.println("ResultBox addExpansionTag: error parsing: " + line);
    492         //}
    493         //}
    494490
    495491        // Read the frequency
  • trunk/gsdl/src/phind/host/phindcgi.cpp

    r1803 r1809  
    9898               UCArray &title, UCArray &hash);
    9999
    100 void cgi_error(char *message);
     100void cgi_error(bool XMLmode, char *message);
    101101
    102102void toUCArray(text_t &in, UCArray &out);
     
    127127 
    128128  if (gsdlhome == NULL) {
    129     cgi_error("GSDLHOME not set in gsdlsite.cfg file.");
     129    cgi_error(XMLmode, "GSDLHOME not set in gsdlsite.cfg file.");
    130130  }
    131131 
     
    137137
    138138  if (collection == NULL) {
    139     cgi_error("No collection");
     139    cgi_error(XMLmode, "No collection");
    140140  }
    141141 
     
    150150   
    151151    if (word.empty()) {
    152       cgi_error("No phrase number or word.");
     152      cgi_error(XMLmode, "No phrase number or word.");
    153153    }
    154154
     
    157157   
    158158    if (result.empty()) {
    159       cout << "couldn't find word: " << word << endl;
     159      cgi_error(XMLmode, "The search term does not occur in the collection.");
    160160      exit(0);
    161161    } else {
     
    326326   
    327327    if (XMLmode) {
     328      // body is always the same as the text of the phrase, so no need to send it
    328329      cout << "<expansion num=\"" << e
    329330       << "\" id=\"" << phrase
    330        << "\" prefix=\"" << prefix 
     331       << "\" prefix=\"" << prefix
    331332       << "\" suffix=\"" << suffix
    332        << "\" text=\"" << word
    333333       << "\" tf=\"" << tf
    334334       << "\" df=\"" << df << "\"/>" << endl;
     
    745745// page and exit(0) the program.
    746746
    747 void cgi_error(char *message){
    748 
    749   cout << "Content-type: text/html" << endl << endl
    750        << "<html><head><title>phind error</title></head>" << endl
    751        << "<body>" << endl
    752        << "<p><h1>phind error</h1>"
    753        << "<p> An error occured processing your request: <p><b>"
    754        << message
    755        << "</b></body></html>" << endl;
     747void cgi_error(bool XMLmode, char *message) {
     748
     749  if (XMLmode) {
     750    cout << "Content-type: text/plain" << endl << endl
     751     << "<phinddata>" << endl
     752     << "<phinderror>" << message << "</phinderror>" << endl
     753     << "</phinddata>" << endl;
     754  } else {
     755    cout << "Content-type: text/html" << endl << endl
     756     << "<html><head><title>phind error</title></head>" << endl
     757     << "<body>" << endl
     758     << "<p><h1>phind error</h1>"
     759     << "<p> An error occured processing your request: <p><b>"
     760     << message
     761     << "</b></body></html>" << endl;
     762  }
    756763  exit(0);
    757764}
Note: See TracChangeset for help on using the changeset viewer.