Changeset 667


Ignore:
Timestamp:
1999-10-15T11:58:05+13:00 (25 years ago)
Author:
sjboddie
Message:

finished up on changes to browseing support - may still need some
tidying up

File:
1 edited

Legend:

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

    r649 r667  
    2929/*
    3030   $Log$
     31   Revision 1.26  1999/10/14 22:58:05  sjboddie
     32   finished up on changes to browseing support - may still need some
     33   tidying up
     34
    3135   Revision 1.25  1999/10/10 08:14:04  sjboddie
    3236   - metadata now returns mp rather than array
     
    162166}
    163167
    164 // expects haschidren, doctype, and classifytype metadata elements
     168// output_controls displays the detach, expand/contract contents,
     169// expand/contract text and highlighting/no highlighting buttons
     170static void output_controls (cgiargsclass &args, const text_tarray &ibuttons,
     171                 recptproto * /*collectproto*/, displayclass &disp,
     172                 outconvertclass &outconvert, ostream &textout,
     173                 ostream &/*logout*/) {
     174
     175  if (args["u"] != "1") {
     176   
     177    FilterResponse_t response;
     178    text_tarray metadata;
     179    text_tarray buttons;
     180   
     181    text_tarray::const_iterator here = ibuttons.begin();
     182    text_tarray::const_iterator end = ibuttons.end();
     183   
     184    while (here != end) {
     185     
     186      if (*here == "Detach")
     187    buttons.push_back ("_document:imagedetach_");
     188      else if (*here == "Highlight") {
     189    if (args["hl"] == "1")
     190      buttons.push_back ("_document:imagenohighlight_");
     191    else
     192      buttons.push_back ("_document:imagehighlight_");
     193      } else if (*here == "Expand Contents") {
     194    if (args["gc"] == "1")
     195      buttons.push_back ("_document:imagecontracttoc_");
     196    else
     197      buttons.push_back ("_document:imageexpandtoc_");
     198      } else if (*here == "Expand Text") {
     199    if (args.getintarg("gt"))
     200      buttons.push_back ("_document:imagecontracttext_");
     201    else
     202      buttons.push_back ("_document:imageexpandtext_");
     203      }
     204      here ++;
     205    }
     206   
     207    here = buttons.begin();
     208    end = buttons.end();
     209    int count = 0;
     210    while (here != end) {
     211      if ((count != 0) && ((count % 3) == 0)) textout << "<br>\n";
     212      textout << outconvert << disp << *here;
     213      count ++;
     214      here ++;
     215    }
     216  }
     217}
     218
     219
     220// at the moment this just writes out the html to display
     221// the cover image (assuming it's called cover.jpg)
     222// this whole thing should be done with a call to the collection
     223// server which would send a link to the cover image if there
     224// was one otherwise send title, author and stuff
     225static void output_cover_image (cgiargsclass &args, recptproto */*collectproto*/,
     226                displayclass &disp, outconvertclass &outconvert,
     227                ostream &textout, ostream &/*logout*/) {
     228 
     229  if (args["d"].empty()) return;
     230 
     231  textout << outconvert << disp <<
     232    "<img src=\"_httpcollection_/archives/_thisOID_/cover.jpg\"><br>\n";
     233}
     234
     235static void output_titles (cgiargsclass &args, recptproto *collectproto,
     236               formatinfo_t &formatinfo, displayclass &disp,
     237               outconvertclass &outconvert, ostream &textout,
     238               ostream &logout) {
     239
     240  if (args["d"].empty()) return;
     241
     242  text_tset metadata;
     243  bool getParents;
     244  FilterResponse_t response;
     245
     246  format_t *formatlistptr = new format_t();
     247  parse_formatstring (formatinfo.DocumentHeading, formatlistptr, metadata, getParents);
     248
     249  text_t topOID;
     250  get_top (args["d"], topOID);
     251
     252  if (!get_info (topOID, args["c"], metadata, getParents, collectproto, response, logout))
     253    return;
     254
     255  textout << outconvert << disp << get_formatted_string (response.docInfo[0], formatlistptr);
     256}
     257
     258
    165259static void recurse_contents (ResultDocInfo_t &section, cgiargsclass &args,
    166260                  browserclass *bptr, text_tset &metadata, bool &getParents,
     
    176270  // output this section
    177271  bool use_table = is_table_content (formatlistptr);
    178   colnumber += bptr->output_section_group (section, args, colnumber, formatlistptr,
    179                        use_table, disp, outconvert, textout, logout);
     272  colnumber += bptr->output_section_group (section, args, colnumber, formatlistptr, use_table,
     273                       metadata, getParents, collectproto, disp, outconvert,
     274                       textout, logout);
    180275
    181276  text_t classification;
     
    187282  text_t classifytype = section.metadata["classifytype"].values[0];
    188283  // HLists are displayed as VLists when contents are expanded,
    189   // Books are displayed as HLists
     284  // Paged documents are displayed as HLists
    190285  if (classifytype == "HList") classifytype = "VList";
    191   if (classifytype == "Book") classifytype = "HList";
     286  if (classifytype == "Paged") classifytype = "HList";
    192287
    193288  // recurse through children
     
    322417}
    323418
     419
    324420static void load_formatstring (const text_t &classifytype, text_tset &metadata,
    325421                   bool &getParents, const text_t &classification,
     
    357453
    358454  while (thisdoc != lastdoc) {
    359     if (classification != "Document" && is_top ((*thisdoc).OID)) {
    360       text_t &thistype = (*thisdoc).metadata["thistype"].values[0];
    361       if (!thistype.empty()) load_formatstring (thistype, metadata, getParents, classification,
    362                         browsermap, formatinfo, formatlistmap);
    363     }
     455
     456    if (is_top ((*thisdoc).OID))
     457      load_formatstring ((*thisdoc).metadata["thistype"].values[0], metadata,
     458             getParents, classification, browsermap, formatinfo,
     459             formatlistmap);
     460
    364461    text_t &childtype = (*thisdoc).metadata["childtype"].values[0];
    365462    text_tset::const_iterator it = cache.find (childtype);
    366463    if (it == cache.end()) {
    367       if (!childtype.empty()) {
    368     load_formatstring (childtype, metadata, getParents, classification,
    369                browsermap, formatinfo, formatlistmap);
    370     cache.insert (childtype);
    371       }
     464      load_formatstring (childtype, metadata, getParents, classification,
     465             browsermap, formatinfo, formatlistmap);
     466      cache.insert (childtype);
    372467    }
    373468    thisdoc ++;
     469  }
     470}
     471
     472static void output_parents (FilterResponse_t &response, cgiargsclass &args,
     473                browsermapclass *browsermap, formatinfo_t &formatinfo,
     474                format_tmap &formatlistmap, const text_t &classification,
     475                int &colnumber, text_tset &metadata, bool &getParents,
     476                recptproto *collectproto, displayclass &disp,
     477                outconvertclass &outconvert, ostream textout,
     478                ostream &logout) {
     479
     480  format_t *formatlistptr = NULL;
     481  text_t classifytype, formatstring;
     482  bool use_table, first = true;
     483  ResultDocInfo_tarray::iterator thisparent = response.docInfo.begin();
     484  ResultDocInfo_tarray::iterator lastparent = response.docInfo.end();
     485  while (thisparent != lastparent) {
     486
     487    // get classifytype of this level
     488    if (is_top ((*thisparent).OID)) classifytype = (*thisparent).metadata["thistype"].values[0];
     489    else if (!first) classifytype = (*(thisparent-1)).metadata["childtype"].values[0];
     490   
     491    // if we still don't have a classifytype we'll use the default
     492    if (classifytype.empty()) {
     493      browserclass *bptr = browsermap->get_default_browser ();
     494      classifytype = bptr->get_browser_name ();
     495    }
     496   
     497    browserclass *bptr = browsermap->getbrowser (classifytype);
     498
     499    // get the formatstring if there is one or use the browsers default
     500    if (!get_formatstring (classification, classifytype,
     501               formatinfo.formatstrings, formatstring))
     502      formatstring = bptr->get_default_formatstring();
     503   
     504    // see if it's cached
     505    format_tmap::const_iterator it = formatlistmap.find (formatstring);
     506    if (it != formatlistmap.end()) formatlistptr = (*it).second;
     507    else {
     508      logout << "browsetools error\n";
     509      return;
     510    }
     511   
     512    use_table = is_table_content (formatlistptr);
     513    colnumber += bptr->output_section_group (*thisparent, args, colnumber, formatlistptr, use_table,
     514                         metadata, getParents, collectproto, disp, outconvert,
     515                         textout, logout);
     516    first = false;
     517    thisparent ++;
    374518  }
    375519}
     
    383527  text_tset metadata;
    384528  bool getParents = false;
     529  text_t formatstring;
    385530  text_tarray parents;
    386531  text_t OID = args["d"];
    387   if (OID.empty()) OID = args["d"];
    388532  text_t classification = "Document";
    389   if (args["d"].empty()) get_top (args["cl"], classification);
     533  if (OID.empty()) {
     534    OID = args["cl"];
     535    get_top (OID, classification);
     536  }
     537  int colnumber = 0;
    390538
    391539  bool haschildren = has_children (OID, args["c"], collectproto, logout);
     
    394542  else get_parents_array (OID, parents);
    395543
    396   // get classifytypes of each parent
    397   metadata.insert ("thistype");
    398   metadata.insert ("childtype");
    399   if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
    400     return;
    401  
    402   metadata.erase (metadata.begin(), metadata.end());
    403 
    404   // get formatstrings for all parents
    405   format_tmap formatlistmap; 
    406   load_formatstrings (response, metadata, getParents, classification,
    407               browsermap, formatinfo, formatlistmap);
    408 
    409   ///////////////////
    410 
     544  if (!parents.empty()) {
     545    // get classifytypes of each parent
     546    metadata.insert ("thistype");
     547    metadata.insert ("childtype");
     548   
     549    if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
     550      return;
     551   
     552    // get formatstrings for all parents
     553    format_tmap formatlistmap; 
     554    load_formatstrings (response, metadata, getParents, classification,
     555            browsermap, formatinfo, formatlistmap);
     556
     557    if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
     558      return;
     559   
     560    // display each parent
     561    output_parents (response, args, browsermap, formatinfo, formatlistmap,
     562            classification, colnumber, metadata, getParents,
     563            collectproto, disp, outconvert, textout, logout);
     564   
     565    metadata.erase (metadata.begin(), metadata.end());
     566   
     567    // clean up cached format list pointers
     568    format_tmap::const_iterator here = formatlistmap.begin();
     569    format_tmap::const_iterator end = formatlistmap.end();
     570    while (here != end) {
     571      delete (*here).second;
     572      here ++;
     573    }
     574  }
     575
     576  // get childrens classifytype
     577  text_t classifytype;
     578  int numparents = response.docInfo.size();
     579  if (!parents.empty())
     580    classifytype = response.docInfo[numparents-1].metadata["childtype"].values[0];
     581  else {
     582    // use the default
     583    browserclass *bptr = browsermap->get_default_browser ();
     584    classifytype = bptr->get_browser_name ();
     585  }
     586   
     587  // load up metadata array with browser defaults
     588  browserclass *bptr = browsermap->getbrowser (classifytype);
     589  bptr->load_metadata_defaults (metadata);
     590
     591  // get the formatstring if there is one or use the browsers default
     592  if (!get_formatstring (classification, classifytype,
     593             formatinfo.formatstrings, formatstring))
     594    formatstring = bptr->get_default_formatstring();
     595
     596  format_t *formatlistptr = new format_t();
     597  parse_formatstring (formatstring, formatlistptr, metadata, getParents);
     598
     599  if (haschildren)
     600    get_children (OID, args["c"], metadata, getParents,
     601          collectproto, response, logout);
     602  else
     603    get_children (OID + ".pr", args["c"], metadata, getParents,
     604          collectproto, response, logout);
     605
     606  // display children
     607  bool use_table = is_table_content (formatlistptr);
     608  bptr->output_section_group (response, args, colnumber, formatlistptr, use_table,
     609                  metadata, getParents, collectproto, disp, outconvert,
     610                  textout, logout);
     611 
     612  delete formatlistptr;
    411613}
    412614
     
    416618                 ostream &textout, ostream &logout) {
    417619
    418   if (args.getintarg("gc") == 1) {
    419 
    420     // expanded table of contents
    421     expanded_contents (args, browsermap, formatinfo, collectproto,
    422                disp, outconvert, textout, logout);
    423   } else {
    424 
    425     // contracted table of contents
    426     contracted_contents (args, browsermap, formatinfo, collectproto,
     620  bool havecontrols = false;
     621 
     622  // get the cover image (if there is one) and the control buttons
     623  // if we're inside a book
     624  if (!args["d"].empty()) {
     625    textout << "<p><table cellpadding=0 cellspacing=0><tr>\n";
     626    textout << "<td valign=top width=200>\n";
     627    if (formatinfo.DocumentImages)
     628      output_cover_image (args, collectproto, disp, outconvert, textout, logout);
     629    else if (formatinfo.DocumentTitles)
     630      output_titles (args, collectproto, formatinfo, disp, outconvert, textout, logout);
     631    output_controls (args, formatinfo.DocumentButtons, collectproto, disp,
     632             outconvert, textout, logout);
     633    textout << "</td><td valign=top>\n";
     634    havecontrols = true;
     635  }
     636
     637  if (formatinfo.DocumentContents) {
     638    if (args.getintarg("gc") == 1) {
     639     
     640      // expanded table of contents
     641      expanded_contents (args, browsermap, formatinfo, collectproto,
    427642             disp, outconvert, textout, logout);
    428 
    429   }
    430 }
     643    } else {
     644     
     645      // contracted table of contents
     646      contracted_contents (args, browsermap, formatinfo, collectproto,
     647               disp, outconvert, textout, logout);
     648    }
     649  }
     650
     651  if (havecontrols) textout << "</td></tr></table>\n";
     652}
Note: See TracChangeset for help on using the changeset viewer.