Changeset 33650


Ignore:
Timestamp:
2019-11-12T12:06:56+13:00 (4 years ago)
Author:
kjdon
Message:

updated to match the new xsl file names; lots of variable renames to hopefully make the code clearer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java

    r33647 r33650  
    4949public class TransformingReceptionist extends Receptionist
    5050{
    51   protected static final String CONFIG_FORMAT_FILE = "config_format.xsl"; //int CONFIG_PASS = 1;
    52   protected static final String TEXT_FORMAT_FILE = "text_fragment_format.xsl"; //int TEXT_PASS = 2;
    53 
    54     static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.TransformingReceptionist.class.getName());
    55 
    56     /** The preprocess.xsl file is in a fixed location */
    57     static final String preprocess_xsl_filename = GlobalProperties.getGSDL3Home() + File.separatorChar + "interfaces" + File.separatorChar + "core" + File.separatorChar + "transform" + File.separatorChar + "preProcess.xsl";
    58 
    59   static final String gslib_filename = "gslib.xsl";
     51  protected static final String EXPAND_GSF_FILE = "expand-gsf.xsl";
     52  protected static final String EXPAND_GSF_PASS1_FILE = "expand-gsf-pass1.xsl";
     53  protected static final String EXPAND_GSLIB_FILE = "expand-gslib.xsl";
     54  protected static final String GSLIB_FILE = "gslib.xsl";
    6055 
     56  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.TransformingReceptionist.class.getName());
     57
     58    /** The expand-gslib.xsl file is in a fixed location */
     59    static final String expand_gslib_filepath = GlobalProperties.getGSDL3Home() + File.separatorChar + "interfaces" + File.separatorChar + "core" + File.separatorChar + "transform" + File.separatorChar + EXPAND_GSLIB_FILE;
     60
    6161    /** the list of xslt to use for actions */
    6262    protected HashMap<String, String> xslt_map = null;
     
    756756         
    757757          // need to transform the format info
    758           // run config_format.xsl over the format_elem. We need to do this now to turn
     758          // run expand-gsf.xsl over the format_elem. We need to do this now to turn
    759759          // eg gsf:template into xsl:template so that the merging works properly.
    760760          // xsl:templates will get merged
    761761          // into the main stylesheet, but gsf:templates won't.
     762
     763          Document format_doc = XMLConverter.newDOM();
     764          format_doc.appendChild(format_doc.importNode(format_elem, true));
    762765         
    763             String configStylesheet_file = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, CONFIG_FORMAT_FILE);
    764             Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file));
    765 
    766             if (configStylesheet_doc != null)
    767             {
    768                 Document format_doc = XMLConverter.newDOM();
    769                 format_doc.appendChild(format_doc.importNode(format_elem, true));
    770 
    771                 if (_debug)
    772                 {
    773                     String siteHome = GSFile.siteHome(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME));
    774                     GSXSLT.insertDebugElements(format_doc, GSFile.collectionConfigFile(siteHome, collection));
    775                 }
    776 
    777                 Node result = this.transformer.transform(configStylesheet_doc, format_doc, config_params); // Needs addressing <-
    778 
    779                 // Since we started creating documents with DocTypes, we can end up with
    780                 // Document objects here. But we will be working with an Element instead,
    781                 // so we grab the DocumentElement() of the Document object in such a case.
     766          if (_debug) {
     767           
     768            String siteHome = GSFile.siteHome(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME));
     769            GSXSLT.insertDebugElements(format_doc, GSFile.collectionConfigFile(siteHome, collection));
     770          }
     771         
     772          // should we be doing the double pass here too?
     773          Node result = transformGSFElements(collection, format_doc, EXPAND_GSF_FILE);
     774          // Since we started creating documents with DocTypes, we can end up with
     775          // Document objects here. But we will be working with an Element instead,
     776          // so we grab the DocumentElement() of the Document object in such a case.
    782777                Element new_format;
    783778                if (result.getNodeType() == Node.DOCUMENT_NODE)
     
    806801                }
    807802
    808             }
    809             else
    810             {
    811               // Is this a fatal error, or are there situations where we could carry on here...
    812               logger.error(" Couldn't parse the "+CONFIG_FORMAT_FILE+" stylesheet");
    813               return XMLTransformer.constructErrorXHTMLPage("Couldn't find and/or load the stylesheet \""+CONFIG_FORMAT_FILE);
    814               //GSXSLT.mergeStylesheets(page_xsl, format_elem, true);
    815             }
     803       
    816804        }
    817805
     
    868856          return converter.getDOM(getStringFromDocument(page_xsl));
    869857        }
    870  
    871   // The next steg is to process the page_xsl +  gslib.xsl by preProcess.xsl to expand all the
    872   // gslib elements
    873 
    874                 Document preprocessingXsl;
     858       
     859        // The next step is to process the page_xsl +  gslib_xsl by
     860        // expand-gslib.xsl to expand all the gslib elements
     861
     862                Document expand_gslib_xsl_doc;
    875863        try
    876864        {
    877           // interfaces/core/transform/preProcess.xsl
     865          // interfaces/core/transform/expand-gslib.xsl
    878866          // this takes skinandLibraryXsl, copies skinXSL, merges elements of libraryXsl into it, and replaces gslib elements
    879             preprocessingXsl = getDoc(preprocess_xsl_filename);
     867            expand_gslib_xsl_doc = getDoc(expand_gslib_filepath);
    880868            String errMsg = ((XMLConverter.ParseErrorHandler) parser.getErrorHandler()).getErrorMessage();
    881869            if (errMsg != null)
    882870            {
    883                 return XMLTransformer.constructErrorXHTMLPage("error loading core/transform/preProcess xslt file: " + preprocess_xsl_filename + "\n" + errMsg);
     871                return XMLTransformer.constructErrorXHTMLPage("error loading file: " + expand_gslib_filepath + "\n" + errMsg);
    884872            }
    885873        }
     
    891879        {
    892880            e.printStackTrace();
    893             System.out.println("error loading preprocess xslt");
    894             return XMLTransformer.constructErrorXHTMLPage("Error loading interfaces/core/transform/preProcess xslt\n" + e.getMessage());
     881            System.out.println("error loading "+expand_gslib_filepath);
     882            return XMLTransformer.constructErrorXHTMLPage("Error loading file: "+ expand_gslib_filepath+"\n" + e.getMessage());
    895883        }
    896884
    897885        // gslib.xsl
    898         Document libraryXsl = null;
     886        Document gslib_xsl_doc = null;
    899887        try
    900888        {
    901             libraryXsl = GSXSLT.mergedXSLTDocumentCascade(gslib_filename, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, _debug);
     889            gslib_xsl_doc = GSXSLT.mergedXSLTDocumentCascade(GSLIB_FILE, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, _debug);
    902890        }
    903891        catch (Exception e)
     
    908896        }
    909897
    910   if (output.equals("preprocess")) {
    911     return converter.getDOM(getStringFromDocument(preprocessingXsl));
     898  if (output.equals("gslib-expander")) {
     899    return converter.getDOM(getStringFromDocument(expand_gslib_xsl_doc));
    912900  }
    913901  if (output.equals("gslib1")) {
    914     return converter.getDOM(getStringFromDocument(libraryXsl));
     902    return converter.getDOM(getStringFromDocument(gslib_xsl_doc));
    915903  }
    916904        //   Combine the skin file and library variables/templates into one document.
     
    918906        //   needs to know what's available in the library.
    919907
    920         Document skinAndLibraryXsl = null;
    921         Document skinAndLibraryDoc = converter.newDOM();
    922908
    923909                // add in all gslib.xsl's include and import files
    924910        // debug?? use debug method?? or does it not make sense here??
    925         GSXSLT.inlineImportAndIncludeFiles(libraryXsl, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces);
     911        GSXSLT.inlineImportAndIncludeFiles(gslib_xsl_doc, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces);
    926912  if (output.equals("gslib")) {
    927     return converter.getDOM(getStringFromDocument(libraryXsl));
     913    return converter.getDOM(getStringFromDocument(gslib_xsl_doc));
    928914  }
    929915
    930         // now, we transform all the gslib elements
     916
     917        Document pageAndGslibXsl = null;
     918        Document pageAndGslibDoc = converter.newDOM();
     919
     920  // now, we transform all the gslib elements
    931921        {
    932922         
    933923
    934           skinAndLibraryXsl = converter.newDOM();
    935           Element root = skinAndLibraryXsl.createElement("skinAndLibraryXsl");
    936           skinAndLibraryXsl.appendChild(root);
     924          pageAndGslibXsl = converter.newDOM();
     925          Element root = pageAndGslibXsl.createElement("pageAndGslibXsl");
     926          pageAndGslibXsl.appendChild(root);
    937927         
    938           Element s = skinAndLibraryXsl.createElement("skinXsl");
    939           s.appendChild(skinAndLibraryXsl.importNode(page_xsl.getDocumentElement(), true));
     928          Element s = pageAndGslibXsl.createElement("pageXsl");
     929          s.appendChild(pageAndGslibXsl.importNode(page_xsl.getDocumentElement(), true));
    940930          root.appendChild(s);
    941931         
    942           Element l = skinAndLibraryXsl.createElement("libraryXsl");
    943           if (libraryXsl != null)
     932          Element l = pageAndGslibXsl.createElement("gslibXsl");
     933          if (gslib_xsl_doc != null)
    944934            {
    945               Element libraryXsl_el = libraryXsl.getDocumentElement();
    946               l.appendChild(skinAndLibraryXsl.importNode(libraryXsl_el, true));
     935              Element gslib_xsl_el = gslib_xsl_doc.getDocumentElement();
     936              l.appendChild(pageAndGslibXsl.importNode(gslib_xsl_el, true));
    947937            }
    948938          root.appendChild(l);
    949939
     940          if (output.equals("xsl5")) {
     941            return converter.getDOM(getStringFromDocument(pageAndGslibXsl));
     942          }
    950943          // actually merge the gslib file with the page
    951944          XMLTransformer preProcessor = new XMLTransformer();
    952           preProcessor.transform_withResultNode(preprocessingXsl, skinAndLibraryXsl, skinAndLibraryDoc);
    953 
    954         }
    955         if (output.equals("xsl5")) {
    956           return converter.getDOM(getStringFromDocument(skinAndLibraryDoc));
    957         }
    958 
    959         // now we need to transform all the gsf elements
    960         skinAndLibraryDoc = (Document) transformGSFElements(collection, skinAndLibraryDoc, TEXT_FORMAT_FILE);
     945          preProcessor.transform_withResultNode(expand_gslib_xsl_doc, pageAndGslibXsl, pageAndGslibDoc);
     946
     947        }
     948        if (output.equals("xsl6")) {
     949          return converter.getDOM(getStringFromDocument(pageAndGslibDoc));
     950        }
    961951         
    962         skinAndLibraryDoc = (Document) transformGSFElements(collection, skinAndLibraryDoc, CONFIG_FORMAT_FILE);
    963    
    964        
    965 
     952        pageAndGslibDoc = (Document) transformGSFElements(collection, pageAndGslibDoc, EXPAND_GSF_PASS1_FILE);
     953
     954        if (output.equals("xsl7")) {
     955          return converter.getDOM(getStringFromDocument(pageAndGslibDoc));
     956        }
     957       
     958        pageAndGslibDoc = (Document) transformGSFElements(collection, pageAndGslibDoc, EXPAND_GSF_FILE);
     959       
    966960        if (output.equals("xsl") || output.equals("skinandlibdocfinal"))
    967961        {
    968           return converter.getDOM(getStringFromDocument(skinAndLibraryDoc));
     962          return converter.getDOM(getStringFromDocument(pageAndGslibDoc));
    969963        }
    970964       
     
    972966        {
    973967                   
    974           // Go through and 'fix up' any 'util:...' or 'java:...' attributes the skinAndLibraryDoc has
     968          // Go through and 'fix up' any 'util:...' or 'java:...' attributes the pageAndGslibDoc has
    975969          String lang = (String)config_params.get("lang");
    976           resolveExtendedNamespaceAttributesXSLT(skinAndLibraryDoc,currentInterface,lang); // test= and select= attributes
    977           resolveExtendedNamespaceAttributesXML(skinAndLibraryDoc,currentInterface,lang);  // href= and src= attributes
    978           Node skinAndLibFinal = converter.getDOM(getStringFromDocument(skinAndLibraryDoc));
     970          resolveExtendedNamespaceAttributesXSLT(pageAndGslibDoc,currentInterface,lang); // test= and select= attributes
     971          resolveExtendedNamespaceAttributesXML(pageAndGslibDoc,currentInterface,lang);  // href= and src= attributes
     972          Node skinAndLibFinal = converter.getDOM(getStringFromDocument(pageAndGslibDoc));
    979973         
    980974          // Send XML and skinandlibdoc down the line together
    981975          Document finalDoc = converter.newDOM();
    982           Node finalDocSkin = finalDoc.importNode(skinAndLibraryDoc.getDocumentElement(), true);
     976          Node finalDocSkin = finalDoc.importNode(pageAndGslibDoc.getDocumentElement(), true);
    983977          Node finalDocXML = finalDoc.importNode(page_with_xslt_params_doc.getDocumentElement(), true);
    984978          Element root = finalDoc.createElement("skinlibfinalPlusXML");
     
    993987
    994988        ///logger.debug("final xsl is");
    995         ///logger.debug(XMLConverter.getPrettyString(skinAndLibraryDoc));
     989        ///logger.debug(XMLConverter.getPrettyString(pageAndGslibDoc));
    996990       
    997991        // The transformer will now work out the resulting doctype from any set in the (merged) stylesheets and
     
    999993
    1000994  // Here, we finally transform the page xml source with the complete xsl file
    1001   Node finalResult = this.transformer.transform(skinAndLibraryDoc, page_xml_doc, config_params);
     995  Node finalResult = this.transformer.transform(pageAndGslibDoc, page_xml_doc, config_params);
    1002996
    1003997        if (_debug)
     
    10931087  // transform the xsl with xsl to replace all gsf elements. We do this in 2 stages -
    10941088  // first do just a text pass, that way we can have gsf elements in the text content
    1095   protected Node transformGSFElements(String collection, Document skinAndLibraryDoc, String formatFile) {
    1096 
    1097     String configStylesheet_file = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, formatFile);
    1098     Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file));
     1089  protected Node transformGSFElements(String collection, Document source_xsl, String expand_gsf_filename) {
     1090
     1091    String expand_gsf_file = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, expand_gsf_filename);
     1092    Document expand_gsf_doc = this.converter.getDOM(new File(expand_gsf_file));
    10991093   
    1100     if (configStylesheet_doc != null)
     1094    if (expand_gsf_doc != null)
    11011095      {
    1102     return this.transformer.transform(configStylesheet_doc, skinAndLibraryDoc, config_params);
     1096    return this.transformer.transform(expand_gsf_doc, source_xsl, config_params);
    11031097      }
    1104     return skinAndLibraryDoc;
     1098    return source_xsl;
    11051099   
    11061100  }   
Note: See TracChangeset for help on using the changeset viewer.