Changeset 38964


Ignore:
Timestamp:
2024-04-30T18:49:50+12:00 (7 weeks ago)
Author:
anupama
Message:

Certain user-customised GLI Collage classifier options need to go into the pageResponse to be incorporated into the applet shim. 1. buildConfigxml.pm modified to push these options out into buildConfig.xml. 2. AbstractBrowse.java (classifier Service) has been modified to push out any classifier option subelements out into the pageResponse. 3. classifier.xsl has been modified to construct its applet HTML element's parameter elements taking into account any customised values in the pageResponse or using the old defaults for fallback. 4. The JavaScript code in webswing-collage.xsl doesn't have ready access to the pageResponse elements (this may need revisiting for if the applet element was accidentally removed from the page), but was already taking into account any applet parameters. webswing-collage.xsl has been modified to use any static/dynamic width and height attributes set on the applet parameter to reset the width and height on the div id=webswing-collage element, as webswing uses the dimensions set on the HTML element housing the webswing instance if running the instance as an applet. It does not resize the webswing applet thereafter. So the most transparent way to allow the user customised dimensions to control the dimensions of the webswing application as intended by the user, is to modify the dimensions set on the webswing-collage element's div before launching the webswing application.

Location:
main/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/buildConfigxml.pm

    r38951 r38964  
    793793      my $hfilename = '';
    794794      my $metadataname = '';
     795      my %options = ();
     796     
    795797      if ($classname eq "DateList") {
    796798    $content = "Date";
    797       } else {
     799      }
     800      else {
    798801    for (my $j=0; $j<scalar(@$cl); $j++) {
    799802      my $arg = @$cl[$j];
     
    809812                }
    810813          }
     814      if ($classname eq "Collage")
     815      {
     816          # Need to copy some collConfig Collage classifier options from collCfg to buildCfg
     817          # so that the Collage applet HTML element can have these configuration options
     818          # set to the customised values.
     819          # Then GS3 runtime AbstractBrowse.addAnySavedOptions() will push these options
     820          # into the pageResponse (without hyphen prefix to the option name).
     821          if ($arg =~ m/-(geometry|verbosity|maxDepth|maxDisplay|imageType|bgcolor|refreshDelay|isJava2|imageMustNotHave)/)
     822          {         
     823          $options{$arg} = @$cl[$j+1]; #$options{$1} is $options{$arg} without the hyphen
     824          }
     825      }     
    811826      if ($arg eq "-buttonname"){
    812827        $content = @$cl[$j+1];
    813         last;
     828        last unless ($classname eq "Collage");
    814829      } elsif ($arg eq "-metadata") {
    815830        $content = @$cl[$j+1];
     
    821836      {
    822837    &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" metadata=\"", $metadataname, "\" hfile=\"", $hfilename, "\" />"]);
    823       } else
    824       {
     838      } elsif ($classname eq "Collage") {
     839      &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\">"]);
     840      while(my ($key, $value) = each(%options)) {
     841          # do something with $key and $value
     842          &write_line('COLCFG', ["<option name=\"", $key, "\" value=\"", $value, "\" />"]);
     843      }
     844      &write_line('COLCFG', ["</classifier>"]); 
     845      } else { 
    825846        &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" />"]);
    826       }     
     847      }
    827848    }
    828849    if ($started_classifiers) {
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractBrowse.java

    r38181 r38964  
    2121// Greenstone classes
    2222import java.util.ArrayList;
     23import java.util.Map;
     24import java.util.HashMap;
    2325
    2426import org.apache.log4j.Logger;
     
    275277                new_cl.appendChild(cl_desc);
    276278
     279               
     280                // For a collage classifier, option elements were added in
     281                // to config_info
     282                // NodeList options = cl.getElementsByTagName(GSXML.PARAM_OPTION_ELEM);
     283                // for (int j = 0; j < options.getLength(); j++) {
     284                //     Element option = (Element) doc.importNode(options.item(j), true);
     285                //     String optionName = option.getAttribute(GSXML.NAME_ATT);
     286                //     // remove hyphen at start
     287                //     if(optionName.startsWith("-")) {
     288                //  optionName = optionName.substring(1);
     289                //     }
     290                //     option.setAttribute(GSXML.NAME_ATT, optionName);
     291                //     new_cl.appendChild(option);
     292                // }
     293               
    277294            }
    278295            return cb_service;
     
    361378                cl.appendChild(owner.importNode(format, true));
    362379            }
     380
     381            /*
     382            // If a Collage classifier, add in the classifier's option subelements
     383            String classifierName = node_extra.getAttribute(GSXML.NAME_ATT);
     384            logger.error("*** classifierName: " + classifierName);
     385           
     386            if(classifierName.equals("Collage")) {
     387                logger.error("*** collage classifier: " + XMLConverter.getPrettyString(node_extra));
     388       
     389                NodeList options = node_extra.getElementsByTagName(GSXML.PARAM_OPTION_ELEM);
     390                if (options != null) {
     391                //Element option = owner.createElement(GSXML.PARAM_OPTION_ELEM);
     392                for (int j = 0; j < options.getLength(); j++) {
     393                    //Element e = (Element) options.item(j);
     394                    //cl.appendChild(owner.importNode(e, true));
     395                    Element option = (Element) owner.importNode(options.item(j), true);
     396                    String optionName = option.getAttribute(GSXML.NAME_ATT);
     397                    // remove hyphen at start of classifier configuration option
     398                    if(optionName.startsWith("-")) {
     399                    optionName = optionName.substring(1);
     400                    }
     401                    option.setAttribute(GSXML.NAME_ATT, optionName);
     402                    cl.appendChild(option);
     403                    // Collage classifier option elements are actually added
     404                    // to info=this.config_info
     405                }
     406                }
     407            }
     408            */
     409               
    363410        } // for each classifier
    364411
     
    514561                // Add the requested structure information
    515562                Element base_node = createClassifierNode(result_doc, node_id); //, false, false);
    516 
     563                addAnyClassifierOptions(result_doc, base_node, node_id);
     564                //logger.error("*** base_node: " + XMLConverter.getPrettyString(base_node));
    517565                //Ancestors: continually add parent nodes until the root is reached
    518566                Element top_node = base_node; // the top node so far
     
    674722    }
    675723
     724    protected void addAnyClassifierOptions(Document doc, Element node, String node_id) {
     725    // e.g for a collage classifier, option elements would be present in config_info
     726    // which we'd like to copy into the node parameter that goes out into the pageResponse
     727    Element class_list = (Element) GSXML.getChildByTagName(this.config_info, GSXML.CLASSIFIER_ELEM + GSXML.LIST_MODIFIER);
     728    NodeList classifiers = GSXML.getNamedElements(class_list, GSXML.CLASSIFIER_ELEM, GSXML.NAME_ATT, node_id);
     729   
     730    if(classifiers.getLength() > 0) {
     731        Element cl = (Element)classifiers.item(0);
     732       
     733        NodeList options = cl.getElementsByTagName(GSXML.PARAM_OPTION_ELEM);
     734        for (int j = 0; j < options.getLength(); j++) {
     735        Element option = (Element) doc.importNode(options.item(j), true);
     736       
     737        // remove hyphen at start of option names
     738        String optionName = option.getAttribute(GSXML.NAME_ATT);       
     739        if(optionName.startsWith("-")) {
     740            optionName = optionName.substring(1);
     741        }
     742        option.setAttribute(GSXML.NAME_ATT, optionName);
     743       
     744        node.appendChild(option);
     745        }
     746
     747        //if(options.getLength() > 0) {
     748        //logger.info("node after adding any classifier options: " + XMLConverter.getPrettyString(node));
     749        //}
     750    }
     751    }
     752   
    676753    /** Creates a classifier node */
    677754  protected Element createClassifierNode(Document doc, String node_id)
  • main/trunk/greenstone3/web/interfaces/default/transform/layouts/webswing-collage.xsl

    r38956 r38964  
    164164       webswingParams["height"] = stripUnitOffAttribute("px", h);
    165165
    166        
     166       // Webswing only uses the width and height set on the webswing-collage element
     167       // Override this with any dimensions set on any applet element, as that is user-controlled
     168       // from GLI. style.setProperty failed without the important parameter to force the setting.
     169       // https://stackoverflow.com/questions/5191478/changing-element-style-attribute-dynamically-using-javascript
     170       document.getElementById("webswing-collage").style.setProperty("width", webswingParams["width"] + "px", "important");
     171       document.getElementById("webswing-collage").style.setProperty("height", webswingParams["height"] + "px", "important");
     172
    167173       // Having collected all the webswingParams, we can finally build up the single webswing customArgs string
    168174       var _args = "";
  • main/trunk/greenstone3/web/interfaces/default/transform/pages/classifier.xsl

    r38950 r38964  
    151151  <xsl:template name="collage-applet-shim">
    152152    <!--<xsl:text>TODO: Here is the collage applet</xsl:text>-->
     153   
    153154    <!-- Copied from GS2.88's about.dm (document.dm has more applet params).
    154155
     
    173174    id="collage-applet-element"
    174175    code="org.greenstone.applet.GsdlCollageApplet.GsdlCollageApplet.class"
    175     archive="GsdlCollageApplet.jar, webswing-api.jar"
    176     width="800"
    177     height="400">
     176    archive="GsdlCollageApplet.jar, webswing-api.jar">
    178177      <xsl:attribute name="codebase">/<xsl:value-of select="$servlet_context"/>/applet</xsl:attribute>
    179 
     178      <xsl:choose>
     179        <xsl:when test="option[@name='geometry']/@value">
     180      <xsl:attribute name="width">
     181        <xsl:value-of select="substring-before(option[@name='geometry']/@value, 'x')" />
     182      </xsl:attribute>
     183      <xsl:attribute name="height">
     184        <xsl:value-of select="substring-after(option[@name='geometry']/@value, 'x')" />
     185      </xsl:attribute>
     186    </xsl:when>
     187      </xsl:choose>
     188     
    180189      <!-- declaring some local variables -->
    181190      <xsl:variable name="coll_name">
     
    183192      </xsl:variable>
    184193      <xsl:variable name="classifier">
    185         <xsl:value-of select="/page/pageRequest/paramList/param[@name='cl']/@value"/>
     194    <xsl:value-of select="/page/pageRequest/paramList/param[@name='cl']/@value"/>
    186195      </xsl:variable>
    187196      <xsl:variable name="fullURL">
    188         <xsl:value-of select="/page/pageRequest/@fullURL"/>
     197    <xsl:value-of select="/page/pageRequest/@fullURL"/>
    189198      </xsl:variable>
    190199      <xsl:variable name="url_protocol_prefix">
    191         <xsl:value-of select="substring-before (/page/pageRequest/@fullURL,'/')"/>
    192       </xsl:variable>
    193 
     200    <xsl:value-of select="substring-before (/page/pageRequest/@fullURL,'/')"/>
     201      </xsl:variable>
     202     
    194203      <!-- setting the applet parameters: first the dynamic ones -->
    195204     
     
    218227     
    219228      <!-- applet parameters that can be manually adjusted -->
    220       <param name="imageType" value=".jpg%.png" />     
     229      <!--
     230      <param name="imageType" value=".jpg%.png" />
    221231      <param name="verbosity" value="3" />
    222232      <param name="maxDepth" value="500"/>
     
    225235      <param name="isJava2" value="auto"/>
    226236      <param name="bgcolor" value="#96c29a" />
    227 The Collage Applet.
    228 
     237      -->
     238      <!--<param name="imageType" value="{option[@name='imageType']/@value}" />-->
     239      <xsl:call-template name="add-applet-param">
     240    <xsl:with-param name="paramName">imageType</xsl:with-param>
     241    <xsl:with-param name="paramDefaultValue">.jpg%.png</xsl:with-param>
     242      </xsl:call-template>
     243      <xsl:call-template name="add-applet-param">
     244    <xsl:with-param name="paramName">verbosity</xsl:with-param>
     245    <xsl:with-param name="paramDefaultValue">3</xsl:with-param>
     246      </xsl:call-template>
     247      <xsl:call-template name="add-applet-param">
     248    <xsl:with-param name="paramName">maxDepth</xsl:with-param>
     249    <xsl:with-param name="paramDefaultValue">500</xsl:with-param>
     250      </xsl:call-template>
     251      <xsl:call-template name="add-applet-param">
     252    <xsl:with-param name="paramName">maxDisplay</xsl:with-param>
     253    <xsl:with-param name="paramDefaultValue">25</xsl:with-param>
     254      </xsl:call-template>
     255      <xsl:call-template name="add-applet-param">
     256    <xsl:with-param name="paramName">refreshDelay</xsl:with-param>
     257    <xsl:with-param name="paramDefaultValue">1500</xsl:with-param>
     258      </xsl:call-template>
     259      <xsl:call-template name="add-applet-param">
     260    <xsl:with-param name="paramName">isJava2</xsl:with-param>
     261    <xsl:with-param name="paramDefaultValue">auto</xsl:with-param>
     262      </xsl:call-template>
     263      <xsl:call-template name="add-applet-param">
     264    <xsl:with-param name="paramName">bgcolor</xsl:with-param>
     265    <xsl:with-param name="paramDefaultValue">#96c29a</xsl:with-param>
     266      </xsl:call-template>     
     267      The Collage Applet.     
    229268   </applet>
    230269  </xsl:template>
    231270
     271  <!-- https://our.umbraco.com/forum/developers/xslt/9274-Return-Value-from-a-Template -->
     272 <xsl:template name="add-applet-param">
     273   <xsl:param name = "paramName" />
     274   <xsl:param name = "paramDefaultValue" />
     275   <param name="{$paramName}">
     276     <xsl:attribute name="value">
     277       <xsl:choose>
     278         <xsl:when test="option[@name=$paramName]/@value">
     279       <xsl:value-of select="option[@name=$paramName]/@value"/>
     280     </xsl:when>
     281         <xsl:otherwise>
     282       <xsl:value-of select="$paramDefaultValue"/>
     283     </xsl:otherwise>
     284      </xsl:choose>
     285     </xsl:attribute>
     286   </param>
     287 </xsl:template>
     288 
     289 
    232290  <xsl:template name="Collage_javascript_deprecated">
    233291    <script type="text/javascript" src="interfaces/{$interface_name}/js/collage_scripts.js"><xsl:text> </xsl:text></script>
     
    348406      <xsl:when test="@childType = 'Collage'">
    349407    <xsl:choose>
    350       <xsl:when test="not(*)">
     408      <!--test of not(*) means has no children, not(classNode) has no subelements classNode-->
     409      <xsl:when test="not(classifierNode)">
    351410        <!-- the order of calling these templates now matters since the collage applet now
    352411         serves as a shim in the javascript that gets loaded in the 2nd template call:
Note: See TracChangeset for help on using the changeset viewer.