Ignore:
Timestamp:
1999-08-11T10:40:01+12:00 (25 years ago)
Author:
sjboddie
Message:

added some more format options including the ability to format the
document text

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/documentaction.cpp

    r438 r443  
    1212/*
    1313   $Log$
     14   Revision 1.19  1999/08/10 22:40:01  sjboddie
     15   added some more format options including the ability to format the
     16   document text
     17
    1418   Revision 1.18  1999/08/09 04:25:18  sjboddie
    1519   moved OID translation stuff from documentaction::define_external_macros
     
    9195
    9296
     97#include <string.h>
    9398#include "documentaction.h"
    9499#include "browsetools.h"
     
    356361
    357362// define all the macros which are related to pages generated
    358 // by this action
     363// by this action. we also load up the formatinfo structure
     364// here (it's used in do_action as well as here)
    359365void documentaction::define_internal_macros (const ColInfoResponse_t &collectinfo, displayclass &disp,
    360366                         cgiargsclass &args, recptproto *collectproto,
     
    390396  if (collectproto == NULL) return;
    391397
     398  // load up formatinfo
     399  formatinfo.clear();
     400  text_tmap::const_iterator format_here = collectinfo.format.begin();
     401  text_tmap::const_iterator format_end = collectinfo.format.end();
     402
     403  while (format_here != format_end) {
     404    if (((*format_here).first == "DocumentImages") &&
     405    ((*format_here).second == "true"))
     406      formatinfo.DocumentImages = true;
     407    else if (((*format_here).first == "DocumentTopPages") &&
     408         ((*format_here).second == "false"))
     409      formatinfo.DocumentTopPages = false;
     410    else if ((*format_here).first == "DocumentHeading")
     411      formatinfo.DocumentHeading = (*format_here).second;
     412    else if (((*format_here).first == "DocumentArrowsTop") &&
     413         ((*format_here).second == "false"))
     414      formatinfo.DocumentArrowsTop = false;
     415    else if (((*format_here).first == "DocumentArrowsBottom") &&
     416         ((*format_here).second == "false"))
     417      formatinfo.DocumentArrowsBottom = false;
     418    else if (((*format_here).first == "DocumentGoTo") &&
     419         ((*format_here).second == "false"))
     420      formatinfo.DocumentGoTo = false;
     421    else if ((*format_here).first == "DocumentButtons")
     422      splitchar ((*format_here).second.begin(), (*format_here).second.end(),
     423         '|', formatinfo.DocumentButtons);
     424    else if ((*format_here).first == "DocumentText")
     425      formatinfo.DocumentText = (*format_here).second;
     426
     427    format_here ++;
     428  }
    392429 
    393430  text_tarray metadata;
     
    428465      text_t &classifytype = response.docInfo[0].metadata[1].values[0];
    429466      if (classifytype.empty()) classifytype = "Book"; // defaults to Book
    430       if ((classifytype == "Book") || (classifytype == "Hierarchy")) {
    431     bool ShowTopPages = true;
    432     text_tmap::const_iterator it = collectinfo.format.find("ShowTopPages");
    433     if ((it != collectinfo.format.end()) && ((*it).second == "false")) ShowTopPages = false;
    434     set_arrow_macros (arg_d, classifytype, ShowTopPages, disp,
    435               collectproto, collection, logout);
    436       }
     467
     468      // set arrow macros if required
     469      if (((classifytype == "Book") || (classifytype == "Hierarchy")) &&
     470      (formatinfo.DocumentArrowsTop || formatinfo.DocumentArrowsBottom))
     471    set_arrow_macros (arg_d, classifytype, formatinfo.DocumentTopPages,
     472              disp, collectproto, collection, logout);
     473
    437474
    438475      if (args["u"] != "1") {
    439476    javaimagescontent = "_javaextras_";
    440     javaimagescontent += "_javadetach_";
    441     if (args["gt"] == "1")
    442       javaimagescontent += "_javacontracttext__javacontinue_";
    443     else
    444       javaimagescontent += "_javaexpandtext_";
    445     if (classifytype == "Hierarchy")
    446       if (args["gc"] == "1")
    447         javaimagescontent += "_javacontractcontents_";
    448       else
    449         javaimagescontent += "_javaexpandcontents_";
    450     if (args["hl"] != "1")
    451       javaimagescontent += "_javahighlighting_";
    452     else
    453       javaimagescontent += "_javanohighlighting_";
     477   
     478    int arg_gt = args.getintarg("gt");
     479    int arg_gc = args.getintarg("gc");
     480    int arg_hl = args.getintarg("hl");
     481
     482    text_tarray::const_iterator button_here = formatinfo.DocumentButtons.begin();
     483    text_tarray::const_iterator button_end = formatinfo.DocumentButtons.end();
     484
     485    while (button_here != button_end) {
     486      if (*button_here == "Detach")
     487        javaimagescontent += "_javadetach_";
     488      else if (*button_here == "Expand Text") {
     489        if (arg_gt == 1)
     490          javaimagescontent += "_javacontracttext__javacontinue_";
     491        else if (arg_gt == 2)
     492          javaimagescontent += "_javacontracttext_";
     493        else
     494          javaimagescontent += "_javaexpandtext_";
     495      } else if (*button_here == "Expand Contents") {
     496        if (classifytype == "Hierarchy")
     497          if (arg_gc == 1)
     498        javaimagescontent += "_javacontractcontents_";
     499          else
     500        javaimagescontent += "_javaexpandcontents_";
     501      } else if (*button_here == "Highlight") {
     502        if (arg_hl == 1)
     503          javaimagescontent += "_javanohighlighting_";
     504        else
     505          javaimagescontent += "_javahighlighting_";
     506      }
     507      button_here ++;
     508    }
    454509    disp.setmacro ("javaimagescontent", "document", javaimagescontent);
    455510      }
     
    586641    }
    587642
    588     bool ShowCoverImages = false;
    589643    text_t formatkey = toptype + toptitle;
    590644    if (!arg_d.empty()) formatkey = toptype + "Document";
     
    592646    text_tmap::const_iterator it = collectinfo.format.find(formatkey);
    593647    if (it != collectinfo.format.end()) formatstring = (*it).second;
    594     it = collectinfo.format.find("ShowCoverImages");
    595     if ((it != collectinfo.format.end()) && ((*it).second == "true")) ShowCoverImages = true;
    596648
    597649    // output the table of contents
     
    599651     
    600652      if (toptype == "Hierarchy")
    601     output_toc (thistype, formatstring, args, ShowCoverImages, collectproto,
    602             disp, outconvert, textout, logout);
     653    output_standard_toc (thistype, formatinfo, formatstring, args,
     654                 collectproto, disp, outconvert, textout, logout);
    603655
    604656      else
    605     // Book is the default for a document level toc
    606     book_toc (args, collectproto, disp,
    607           outconvert, textout, logout);
     657    output_document_toc (args, formatinfo, collectproto, disp,
     658                 outconvert, textout, logout);
    608659
    609660    } else {
    610       // Book should never used at classification level (I think;)
    611       output_toc (thistype, formatstring, args, false, collectproto,
    612           disp, outconvert, textout, logout);
     661      output_standard_toc (thistype, formatinfo, formatstring, args,
     662               collectproto, disp, outconvert, textout, logout);
    613663    }
    614664
    615665    // output the document text
    616     output_document (OID, args, collectinfo, collectproto, disp,
    617              outconvert, textout, logout);
     666    output_document (OID, args, collectproto, disp, outconvert, textout, logout);
    618667
    619668    textout << outconvert << disp << "_document:footer_\n";
     
    622671}
    623672
     673void documentaction::output_text (const ResultDocInfo_t &docinfo, format_t *formatlistptr,
     674                  const TermInfo_tarray &terminfo, const text_t &OID,
     675                  bool highlight, const text_t &hastxt, int wanttext,
     676                  text_t &collection, recptproto *collectproto, displayclass &disp,
     677                  outconvertclass &outconvert, ostream &textout,
     678                  ostream &logout) {
     679 
     680  DocumentRequest_t docrequest;
     681  DocumentResponse_t docresponse;
     682  comerror_t err;
     683
     684  if (hastxt == "1") {
     685
     686    if (wanttext) {
     687      // get the text
     688      docrequest.OID = OID;
     689      collectproto->get_document (collection, docrequest, docresponse, err, logout);
     690
     691      // cut down on overhead by not using formattools if we only want the text
     692      // (wanttext will equal 2 if we want text and other stuff too)
     693      if (wanttext == 1)
     694    if (highlight)
     695      highlighttext(docresponse.doc, terminfo, disp, outconvert, textout, logout);
     696    else
     697      textout << outconvert << disp << docresponse.doc;
     698    }
     699 
     700    if (wanttext != 1) {
     701      text_t doctext = get_formatted_string (docinfo, formatlistptr, docresponse.doc);
     702     
     703      if (highlight)
     704    highlighttext(doctext, terminfo, disp, outconvert, textout, logout);
     705      else
     706    textout << outconvert << disp << doctext;
     707    }
     708  }
     709}
     710
    624711
    625712void documentaction::output_document (const text_t &OID, cgiargsclass &args,
    626                       const ColInfoResponse_t &collectinfo,
    627713                      recptproto *collectproto, displayclass &disp,
    628714                      outconvertclass &outconvert, ostream &textout,
    629715                      ostream &logout) {
    630716  FilterResponse_t inforesponse;
    631   DocumentRequest_t docrequest;
    632   DocumentResponse_t docresponse;
    633717  FilterResponse_t queryresponse;
    634   comerror_t err;
    635718  text_tarray metadata;
     719  bool getParents = false;
    636720  bool highlight = false;
     721  int wanttext = 0;
    637722  int arg_gt = args.getintarg("gt");
    638723  text_t &collection = args["c"];
     
    647732  }
    648733
    649   bool ShowSectionTitles = true;
    650   text_tmap::const_iterator it = collectinfo.format.find("ShowSectionTitles");
    651   if ((it != collectinfo.format.end()) && ((*it).second == "false")) ShowSectionTitles = false;
    652 
    653   // get info on this document
    654   metadata.push_back("Title");
     734  format_t *formatlistptr = new format_t();
     735  parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
     736
    655737  metadata.push_back("hastxt");
    656738  metadata.push_back("haschildren");
     739 
     740  if (formatinfo.DocumentText == "[Text]")
     741    wanttext = 1;
     742  else {
     743    char *docformat = formatinfo.DocumentText.getcstr();
     744    if (strstr (docformat, "[Text]") != NULL)
     745      wanttext = 2;
     746    delete docformat;
     747  }
    657748   
    658   if (get_info (OID, collection, metadata, false, collectproto, inforesponse, logout)) {
    659     text_t title = inforesponse.docInfo[0].metadata[0].values[0];
    660     int hastxt = inforesponse.docInfo[0].metadata[1].values[0].getint();
    661     int haschildren = inforesponse.docInfo[0].metadata[2].values[0].getint();
    662      
     749  int metasize = metadata.size();
     750
     751  if (get_info (OID, collection, metadata, getParents, collectproto, inforesponse, logout)) {
     752    text_t hastxt = inforesponse.docInfo[0].metadata[metasize-2].values.back();
     753    text_t &haschildren = inforesponse.docInfo[0].metadata[metasize-1].values.back();
     754
    663755    if (arg_gt == 0) {
    664       if (hastxt == 1) {
    665     // get the text
    666     docrequest.OID = OID;
    667     collectproto->get_document (collection, docrequest, docresponse, err, logout);
    668      
    669     if (ShowSectionTitles)
    670       textout << outconvert << disp << "<p>\n<h3>" << title << "</h3>";
    671     if (highlight)
    672       highlighttext(docresponse.doc, queryresponse.termInfo, disp,
    673             outconvert, textout, logout);
    674     else
    675       textout << outconvert << disp << docresponse.doc;
    676       }
     756      output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
     757           OID, highlight, hastxt, wanttext, collection, collectproto,
     758           disp, outconvert, textout, logout);
     759
     760
    677761    } else {
     762
     763      ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
    678764   
    679765      // text is to be expanded
    680766      text_t exOID = OID;
    681       if (!haschildren) exOID = get_parent (OID);
     767      if (haschildren != "1") exOID = get_parent (OID);
     768      if (exOID.empty()) exOID = OID;
    682769   
    683770      // if we're not in a document (i.e. we're in a top level classification)
     
    687774      if (args["d"].empty()) classifytype = "classify";
    688775
    689       int i; // not used
    690       get_contents (exOID, classifytype, i, collection, collectproto, inforesponse, logout);
     776      int i = 0; // not used
     777      get_contents (exOID, classifytype, metadata, i, collection,
     778            collectproto, inforesponse, logout);
    691779   
    692780      ResultDocInfo_tarray::const_iterator sechere = inforesponse.docInfo.begin();
     
    700788    int seccount = 0;
    701789    while (sechere != secend) {
    702       if ((*sechere).metadata[3].values[0] == "1") seccount ++;
     790      const text_t &shastxt = (*sechere).metadata[metasize-2].values.back();
     791      if (shastxt == "1") seccount ++;
    703792      if (seccount > 10) break;
    704793      sechere ++;
     
    708797      // for current section only
    709798      textout << outconvert << disp << "_document:textltwarning_";
    710       docrequest.OID = OID;
    711       collectproto->get_document (collection, docrequest, docresponse, err, logout);
     799
     800      output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
     801               OID, highlight, hastxt, wanttext, collection,
     802               collectproto, disp, outconvert, textout, logout);
    712803     
    713       if (ShowSectionTitles)
    714         textout << outconvert << disp << "<p>\n<h3>" << title << "</h3>";
    715       if (highlight)
    716         highlighttext(docresponse.doc, queryresponse.termInfo, disp,
    717               outconvert, textout, logout);
    718       else
    719         textout << outconvert << disp << docresponse.doc;
    720804    }
    721805    else arg_gt = 2;
     
    727811    int count = 0;
    728812    while (sechere != secend) {
    729       textout << outconvert << disp << "\n<p><a name=" << count << ">";
    730       if (ShowSectionTitles)
    731         textout << outconvert << disp << "<h3>"
    732             << (*sechere).metadata[0].values[0] << "</h3>";
    733       textout << "</a>\n";
    734 
    735       if ((*sechere).metadata[3].values[0] == "1") {
    736         docrequest.OID = (*sechere).OID;
    737         collectproto->get_document (collection, docrequest, docresponse, err, logout);
    738         if (highlight)
    739           highlighttext(docresponse.doc, queryresponse.termInfo, disp,
    740                 outconvert, textout, logout);
    741         else
    742           textout << outconvert << disp << docresponse.doc;
    743       }
     813      textout << outconvert << disp << "\n<p><a name=" << count << "></a>\n";
     814
     815      const text_t &shastxt = (*sechere).metadata[metasize-2].values.back();
     816
     817      output_text (*sechere, formatlistptr, queryresponse.termInfo,
     818               (*sechere).OID, highlight, shastxt, wanttext, collection,
     819               collectproto, disp, outconvert, textout, logout);
    744820      count ++;
    745821      sechere ++;
     
    748824    }
    749825  }
     826  delete formatlistptr;
    750827}
    751828
    752829// highlighttext highlights query terms in text string and outputs the resulting text string
    753 void documentaction::highlighttext(text_t &text, TermInfo_tarray &terms, displayclass &disp,
    754                    outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) {
     830void documentaction::highlighttext(text_t &text, const TermInfo_tarray &terms,
     831                   displayclass &disp, outconvertclass &outconvert,
     832                   ostream &textout, ostream &/*logout*/) {
    755833
    756834  text_tmap allterms;
Note: See TracChangeset for help on using the changeset viewer.