Changeset 33632

Show
Ignore:
Timestamp:
07.11.2019 14:53:54 (7 days ago)
Author:
kjdon
Message:

overhaul of TransformingReceptionist?. changed the order of inlining include/import with expanding gslib - we want to be able to use gslib in the included files eg main.xsl and header.xsl. The main bulk of tidying up done, still a bit of work to go to do with making names more sensible

Files:
1 modified

Legend:

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

    r33079 r33632  
    4949public class TransformingReceptionist extends Receptionist 
    5050{ 
    51     protected static final int CONFIG_PASS = 1; 
    52     protected static final int TEXT_PASS = 2; 
     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; 
    5353 
    5454    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.TransformingReceptionist.class.getName()); 
     
    5757    static final String preprocess_xsl_filename = GlobalProperties.getGSDL3Home() + File.separatorChar + "interfaces" + File.separatorChar + "core" + File.separatorChar + "transform" + File.separatorChar + "preProcess.xsl"; 
    5858 
     59  static final String gslib_filename = "gslib.xsl"; 
     60   
    5961    /** the list of xslt to use for actions */ 
    6062    protected HashMap<String, String> xslt_map = null; 
     
    610612 
    611613    /** 
    612      * transform the page using xslt we need to get any format element out of 
    613      * the page and add it to the xslt before transforming 
     614     * transform the page using xslt. 
     615     * we need to get any format element out of the page and add it to the xslt before transforming 
    614616     */ 
    615         protected Node transformPage(Element page,String currentInterface,String output) 
     617        protected Node transformPage(Element page_xml, String currentInterface, String output) 
    616618    { 
    617619        _debug = false; 
    618620 
    619         Element request = (Element) GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM); 
     621        Element request = (Element) GSXML.getChildByTagName(page_xml, GSXML.PAGE_REQUEST_ELEM); 
    620622 
    621623        //logger.info("Current output mode is: " + output + ", current interface name is: " + currentInterface); 
    622624         
    623         // DocType defaults in case the skin doesn't have an "xsl:output" element 
    624         String qualifiedName = "html"; 
    625         String publicID = "-//W3C//DTD HTML 4.01 Transitional//EN"; 
    626         String systemID = "http://www.w3.org/TR/html4/loose.dtd"; 
    627  
    628         // We need to create an empty document with a predefined DocType, 
    629         // that will then be used for the transformation by the DOMResult 
    630         Document docWithDoctype = converter.newDOM(qualifiedName, publicID, systemID); 
    631  
    632625        if (output.equals("xsltclient")) 
    633626        { 
    634                 String baseURL = request.getAttribute(GSXML.BASE_URL); 
    635                  
    636             // If you're just getting the client-side transform page, why bother with the rest of this? 
    637             Element html = docWithDoctype.createElement("html"); 
    638             Element img = docWithDoctype.createElement("img"); 
    639             img.setAttribute("src", "loading.gif"); // Make it dynamic 
    640             img.setAttribute("alt", "Please wait..."); 
    641             Text title_text = docWithDoctype.createTextNode("Please wait..."); // Make this language dependent 
    642             Element head = docWithDoctype.createElement("head"); 
    643  
    644             // e.g., <base href="http://localhost:8383/greenstone3/" /><!-- [if lte IE 6]></base><![endif] --> 
    645             Element base = docWithDoctype.createElement("base"); 
    646             base.setAttribute("href",baseURL); 
    647             Comment opt_end_base = docWithDoctype.createComment("[if lte IE 6]></base><![endif]"); 
    648              
    649             Element title = docWithDoctype.createElement("title"); 
    650             title.appendChild(title_text); 
    651  
    652             Element body = docWithDoctype.createElement("body"); 
    653  
    654             Element jquery_script = docWithDoctype.createElement("script"); 
    655             jquery_script.setAttribute("src", "jquery-1.10-min.js"); 
    656             jquery_script.setAttribute("type", "text/javascript"); 
    657             Comment jquery_comment = docWithDoctype.createComment("jQuery"); 
    658             jquery_script.appendChild(jquery_comment); 
    659  
    660             Element saxonce_script = docWithDoctype.createElement("script"); 
    661             saxonce_script.setAttribute("src", "Saxonce/Saxonce.nocache.js"); 
    662             saxonce_script.setAttribute("type", "text/javascript"); 
    663             Comment saxonce_comment = docWithDoctype.createComment("SaxonCE"); 
    664             saxonce_script.appendChild(saxonce_comment); 
    665  
    666             Element xsltutil_script = docWithDoctype.createElement("script"); 
    667             xsltutil_script.setAttribute("src", "xslt-util.js"); 
    668             xsltutil_script.setAttribute("type", "text/javascript"); 
    669             Comment xsltutil_comment = docWithDoctype.createComment("JavaScript version of XSLTUtil.java"); 
    670             xsltutil_script.appendChild(xsltutil_comment); 
    671  
    672             Element script = docWithDoctype.createElement("script"); 
    673             Comment script_comment = docWithDoctype.createComment("Filler for browser"); 
    674             script.setAttribute("src", "client-side-xslt.js"); 
    675             script.setAttribute("type", "text/javascript"); 
    676             script.appendChild(script_comment); 
    677              
    678             Element pagevar = docWithDoctype.createElement("script"); 
    679             Element style = docWithDoctype.createElement("style"); 
    680             style.setAttribute("type", "text/css"); 
    681             Text style_text = docWithDoctype.createTextNode("body { text-align: center; padding: 50px; font: 14pt Arial, sans-serif; font-weight: bold; }"); 
    682             pagevar.setAttribute("type", "text/javascript"); 
    683             Text page_var_text = docWithDoctype.createTextNode("var placeholder = true;"); 
    684  
    685             html.appendChild(head); 
    686             head.appendChild(base); head.appendChild(opt_end_base); 
    687             head.appendChild(title); 
    688             head.appendChild(style); 
    689             style.appendChild(style_text); 
    690             html.appendChild(body); 
    691             head.appendChild(pagevar); 
    692             head.appendChild(jquery_script); 
    693             head.appendChild(saxonce_script); 
    694             head.appendChild(xsltutil_script); 
    695             head.appendChild(script); 
    696             pagevar.appendChild(page_var_text); 
    697  
    698             body.appendChild(img); 
    699             docWithDoctype.appendChild(html); 
    700  
    701             return (Node) docWithDoctype; 
    702         } 
    703  
    704         // Passing in the pretty string here means it needs to be generated even when not debugging; so use custom function to return blank when debug is off 
    705         //logger.debug("page before transforming:"); 
    706         //logger.debug(this.converter.getPrettyStringLogger(page, logger)); 
    707  
     627          return generateXSLTClientOutput(request); 
     628        } 
     629         
    708630        String action = request.getAttribute(GSXML.ACTION_ATT); 
    709631        String subaction = request.getAttribute(GSXML.SUBACTION_ATT); 
     
    713635        // for now, if output=xml, we don't transform the page, we just return  
    714636        // the page xml 
    715         Document theXML = null; 
     637        Document page_with_xslt_params_doc = null; 
    716638 
    717639        if (output.equals("xml") || (output.equals("json")) || output.equals("clientside")) 
    718640        { 
    719             // Append some bits and pieces first... 
    720             theXML = converter.newDOM(); 
     641            // Append the xsltparams to the page 
     642                page_with_xslt_params_doc = converter.newDOM(); 
    721643            // Import into new document first! 
    722             Node newPage = theXML.importNode(page, true); 
    723             theXML.appendChild(newPage); 
    724             Element root = theXML.createElement("xsltparams"); 
    725             newPage.appendChild(root); 
    726  
    727             Element libname = theXML.createElement("param"); 
    728             libname.setAttribute("name", "library_name"); 
    729             Text libnametext = theXML.createTextNode((String) config_params.get(GSConstants.LIBRARY_NAME)); 
    730             libname.appendChild(libnametext); 
    731  
    732             Element intname = theXML.createElement("param"); 
    733             intname.setAttribute("name", "interface_name"); 
    734             Text intnametext = theXML.createTextNode((String) config_params.get(GSConstants.INTERFACE_NAME)); 
    735             intname.appendChild(intnametext); 
    736  
    737             Element siteName = theXML.createElement("param"); 
    738             siteName.setAttribute("name", "site_name"); 
    739             Text siteNameText = theXML.createTextNode((String) config_params.get(GSConstants.SITE_NAME)); 
    740             siteName.appendChild(siteNameText); 
    741  
    742             Element clientSideXSLTName = theXML.createElement("param"); 
    743             clientSideXSLTName.setAttribute("name", "use_client_side_xslt"); 
     644            Node page_with_xslt_params = page_with_xslt_params_doc.importNode(page_xml, true); 
     645            page_with_xslt_params_doc.appendChild(page_with_xslt_params); 
     646            Element xslt_params = page_with_xslt_params_doc.createElement("xsltparams"); 
     647            page_with_xslt_params.appendChild(xslt_params); 
     648 
     649            GSXML.addParameter2ToList(xslt_params, "library_name", (String) config_params.get(GSConstants.LIBRARY_NAME)); 
     650            GSXML.addParameter2ToList(xslt_params, "interface_name", (String) config_params.get(GSConstants.INTERFACE_NAME)); 
     651            GSXML.addParameter2ToList(xslt_params, "site_name", (String) config_params.get(GSConstants.SITE_NAME)); 
    744652            Boolean useClientXSLT = (Boolean) config_params.get(GSConstants.USE_CLIENT_SIDE_XSLT); 
    745             Text clientSideXSLTNameText = theXML.createTextNode(useClientXSLT.toString()); 
    746             clientSideXSLTName.appendChild(clientSideXSLTNameText); 
     653            GSXML.addParameter2ToList(xslt_params, "use_client_side_xslt", useClientXSLT.toString()); 
     654            GSXML.addParameter2ToList(xslt_params, "filepath", GlobalProperties.getGSDL3Home()); 
    747655             
    748             Element filepath = theXML.createElement("param"); 
    749             filepath.setAttribute("name", "filepath"); 
    750             Text filepathtext = theXML.createTextNode(GlobalProperties.getGSDL3Home()); 
    751             filepath.appendChild(filepathtext); 
    752  
    753             root.appendChild(libname); 
    754             root.appendChild(intname); 
    755             root.appendChild(siteName); 
    756             root.appendChild(clientSideXSLTName); 
    757             root.appendChild(filepath); 
    758  
    759656            if ((output.equals("xml")) || output.equals("json")) 
    760657            { 
    761                 // in the case of "json", calling method responsible for converting to JSON-string 
    762                 return theXML.getDocumentElement(); 
    763             } 
     658              // Just return the page XML 
     659              // in the case of "json", calling method responsible for converting to JSON-string 
     660              return page_with_xslt_params_doc.getDocumentElement(); 
     661            } 
     662            // in the case of client side, later on we'll use this doc with xslt params added, 
     663            // along with the xsl. 
    764664        } 
    765665 
    766666        Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    767667        String collection = ""; 
    768         String inlineTemplate = ""; 
     668        String inline_template = ""; 
    769669        if (cgi_param_list != null) 
    770670        { 
     
    777677            } 
    778678 
    779             inlineTemplate = (String) params.get(GSParams.INLINE_TEMPLATE); 
     679            inline_template = (String) params.get(GSParams.INLINE_TEMPLATE); 
    780680            String debug_p = (String) params.get(GSParams.DEBUG); 
    781681            if (debug_p != null && (debug_p.equals("on") || debug_p.equals("1") || debug_p.equals("true"))) 
     
    812712        config_params.put("collName", collection); 
    813713 
    814         Document style_doc = getXSLTDocument(action, subaction, collection); 
    815         if (style_doc == null) 
    816         { 
    817           // this getParseErrorMessage may have originally worked, but now it doesn't. 
    818           // //String errorPage = this.converter.getParseErrorMessage(); 
    819           //    if (errorPage != null) 
    820           //    { 
    821           //      return XMLTransformer.constructErrorXHTMLPage("Cannot parse the xslt file\n");// + errorPage); 
    822           //    } 
    823             return page; 
    824         } 
    825  
     714        // find the appropriate stylesheet (based on action/subaction) - eg a=p&sa=home will be home.xsl 
     715        // This mapping is defined in interfaceConfig.xsl 
     716        // All versions of the stylesheet (base interface, interface, site, collection) are 
     717        // merged together into one document 
     718        Document page_xsl = getXSLTDocument(action, subaction, collection); 
     719        String page_xsl_filename = getXSLTFilename(action, subaction); // for debug purposes 
     720        if (page_xsl == null) 
     721        { 
     722          logger.error("Couldn't find and/or load the stylesheet ("+page_xsl_filename+") for a="+action+", sa="+subaction+", in collection "+collection); 
     723          return XMLTransformer.constructErrorXHTMLPage("Couldn't find and/or load the stylesheet \""+page_xsl_filename+"\" for a="+action+", sa="+subaction+", in collection "+collection); 
     724        } 
     725 
     726        if (output.equals("xsl1")) { 
     727          // if we just output the page_xsl directly then there may be unescaped & in the javascript, 
     728          // and the page won't display properly 
     729          return converter.getDOM(getStringFromDocument(page_xsl)); 
     730        } 
     731 
     732         
    826733        // put the page into a document - this is necessary for xslt to get 
    827734        // the paths right if you have paths relative to the document root 
    828735        // eg /page. 
    829         Document doc = XMLConverter.newDOM(); 
    830         doc.appendChild(doc.importNode(page, true)); 
    831         Element page_response = (Element) GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM); 
     736        Document page_xml_doc = XMLConverter.newDOM(); 
     737        page_xml_doc.appendChild(page_xml_doc.importNode(page_xml, true)); 
     738        Element page_response = (Element) GSXML.getChildByTagName(page_xml, GSXML.PAGE_RESPONSE_ELEM); 
    832739        Element format_elem = (Element) GSXML.getChildByTagName(page_response, GSXML.FORMAT_ELEM); 
    833740 
    834         NodeList pageElems = doc.getElementsByTagName("page"); 
    835         if (pageElems.getLength() > 0) 
    836         { 
    837             Element pageElem = (Element) pageElems.item(0); 
    838             String langAtt = pageElem.getAttribute(GSXML.LANG_ATT); 
    839  
    840             if (langAtt != null && langAtt.length() > 0) 
    841             { 
    842                 config_params.put("lang", langAtt); 
    843             } 
    844         } 
    845  
    846         if (output.equals("formatelem")) 
     741        if (output.equals("format")) 
    847742        { 
    848743            return format_elem; 
    849744        } 
     745 
     746        // do we have language attribute for page? 
     747        String lang_att = page_xml.getAttribute(GSXML.LANG_ATT); 
     748        if (lang_att != null && lang_att.length() > 0) 
     749          { 
     750            config_params.put("lang", lang_att); 
     751          } 
     752         
    850753        if (format_elem != null) 
    851754        { 
    852             //page_response.removeChild(format_elem); 
    853             logger.debug("format elem=" + this.converter.getPrettyStringLogger(format_elem, logger)); 
    854             // need to transform the format info 
    855             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.xsl"); 
     755          //page_response.removeChild(format_elem); 
     756           
     757          // need to transform the format info 
     758          // run config_format.xsl over the format_elem. We need to do this now to turn 
     759          // eg gsf:template into xsl:template so that the merging works properly. 
     760          // xsl:templates will get merged 
     761          // into the main stylesheet, but gsf:templates won't. 
     762           
     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); 
    856764            Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file)); 
    857765 
     
    881789                    new_format = (Element) result; 
    882790                } 
    883                 logger.debug("new format elem=" + this.converter.getPrettyStringLogger(new_format, logger)); 
     791                 
    884792                if (output.equals("newformat")) 
    885793                { 
     
    887795                } 
    888796 
    889                 // add extracted GSF statements in to the main stylesheet 
     797                // add the extracted format statements in to the main stylesheet 
    890798                if (_debug) 
    891799                { 
    892800                    String siteHome = GSFile.siteHome(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME)); 
    893                     GSXSLT.mergeStylesheetsDebug(style_doc, new_format, true, true, "OTHER1", GSFile.collectionConfigFile(siteHome, collection)); 
     801                    GSXSLT.mergeStylesheetsDebug(page_xsl, new_format, true, true, "OTHER1", GSFile.collectionConfigFile(siteHome, collection)); 
    894802                } 
    895803                else 
    896804                { 
    897                     GSXSLT.mergeStylesheets(style_doc, new_format, true); 
    898                 } 
    899                 //System.out.println("added extracted GSF statements into the main stylesheet") ; 
    900  
    901                 // add extracted GSF statements in to the debug test stylesheet 
    902                 //GSXSLT.mergeStylesheets(oldStyle_doc, new_format); 
     805                  GSXSLT.mergeStylesheets(page_xsl, new_format, true); 
     806                } 
     807 
    903808            } 
    904809            else 
    905810            { 
    906                 logger.error(" couldn't parse the config_format stylesheet, adding the format info as is"); 
    907                 GSXSLT.mergeStylesheets(style_doc, format_elem, true); 
    908                 //GSXSLT.mergeStylesheets(oldStyle_doc, format_elem); 
    909             } 
    910             logger.debug("the converted stylesheet is:"); 
    911             logger.debug(this.converter.getPrettyStringLogger(style_doc.getDocumentElement(), logger)); 
    912         } 
    913  
    914         //for debug purposes only 
    915         Document oldStyle_doc = style_doc; 
    916         Document preprocessingXsl; 
     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            } 
     816        } 
     817 
     818        if (output.equals("xsl2")) { 
     819          return converter.getDOM(getStringFromDocument(page_xsl)); 
     820        } 
     821 
     822        if (inline_template != null) 
     823        { 
     824            try 
     825            { 
     826                Document inline_template_doc = this.converter.getDOM("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet version=\"1.0\" "+GSXML.ALL_NAMESPACES_ATTS +  ">" + inline_template + "</xsl:stylesheet>", "UTF-8"); 
     827 
     828                if (_debug) 
     829                { 
     830                    GSXSLT.mergeStylesheetsDebug(page_xsl, inline_template_doc.getDocumentElement(), true, true, "OTHER2", "INLINE"); 
     831                } 
     832                else 
     833                { 
     834                  //GSXSLT.mergeStylesheets(skinAndLibraryDoc, inlineTemplateDoc.getDocumentElement(), true); 
     835                  GSXSLT.mergeStylesheets(page_xsl, inline_template_doc.getDocumentElement(), true); 
     836                } 
     837            } 
     838            catch (Exception ex) 
     839            { 
     840                ex.printStackTrace(); 
     841            } 
     842        } 
     843 
     844        if (output.equals("xsl3")) { 
     845          return converter.getDOM(getStringFromDocument(page_xsl)); 
     846        } 
     847 
     848        // once we are here, have got the main page xsl loaded up. Have added in any format statements from the source xml, and added in any inline template which came through cgi params. 
     849         
     850        // next we load in the import and include files. - these, too, go through the inheritance cascade (base interface, interface, site, collection) before being added into the main document 
     851         
     852        if (_debug) 
     853        { 
     854          GSXSLT.inlineImportAndIncludeFilesDebug(page_xsl, null, _debug, page_xsl_filename, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 
     855        } 
     856        else 
     857        { 
     858          GSXSLT.inlineImportAndIncludeFiles(page_xsl, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 
     859         
     860        } 
     861 
     862        if (output.equals("xsl4")) { 
     863          return converter.getDOM(getStringFromDocument(page_xsl)); 
     864        } 
     865   
     866  // The next steg is to process the page_xsl +  gslib.xsl by preProcess.xsl to expand all the 
     867  // gslib elements 
     868 
     869                Document preprocessingXsl; 
    917870        try 
    918871        { 
     872          // interfaces/core/transform/preProcess.xsl 
     873          // this takes skinandLibraryXsl, copies skinXSL, merges elements of libraryXsl into it, and replaces gslib elements 
    919874            preprocessingXsl = getDoc(preprocess_xsl_filename); 
    920875            String errMsg = ((XMLConverter.ParseErrorHandler) parser.getErrorHandler()).getErrorMessage(); 
    921876            if (errMsg != null) 
    922877            { 
    923                 return XMLTransformer.constructErrorXHTMLPage("error loading preprocess xslt file: " + preprocess_xsl_filename + "\n" + errMsg); 
     878                return XMLTransformer.constructErrorXHTMLPage("error loading core/transform/preProcess xslt file: " + preprocess_xsl_filename + "\n" + errMsg); 
    924879            } 
    925880        } 
     
    932887            e.printStackTrace(); 
    933888            System.out.println("error loading preprocess xslt"); 
    934             return XMLTransformer.constructErrorXHTMLPage("error loading preprocess xslt\n" + e.getMessage()); 
    935         } 
    936  
     889            return XMLTransformer.constructErrorXHTMLPage("Error loading interfaces/core/transform/preProcess xslt\n" + e.getMessage()); 
     890        } 
     891 
     892        // gslib.xsl 
    937893        Document libraryXsl = null; 
    938894        try 
    939895        { 
    940             libraryXsl = GSXSLT.mergedXSLTDocumentCascade("gslib.xsl", (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, _debug); 
     896            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); 
    941897        } 
    942898        catch (Exception e) 
     
    947903        } 
    948904 
     905  if (output.equals("preprocess")) { 
     906    return converter.getDOM(getStringFromDocument(preprocessingXsl)); 
     907  } 
     908  if (output.equals("gslib")) { 
     909    return converter.getDOM(getStringFromDocument(libraryXsl)); 
     910  } 
    949911        //   Combine the skin file and library variables/templates into one document.  
    950912        //   Please note: We dont just use xsl:import because the preprocessing stage   
     
    954916        Document skinAndLibraryDoc = converter.newDOM(); 
    955917 
    956         // Applying the preprocessing XSLT - in its own block {} to allow use of non-unique variable names 
    957         { 
    958  
    959             skinAndLibraryXsl = converter.newDOM(); 
    960             Element root = skinAndLibraryXsl.createElement("skinAndLibraryXsl"); 
    961             skinAndLibraryXsl.appendChild(root); 
    962  
    963             Element s = skinAndLibraryXsl.createElement("skinXsl"); 
    964             s.appendChild(skinAndLibraryXsl.importNode(style_doc.getDocumentElement(), true)); 
    965             root.appendChild(s); 
    966  
    967             Element l = skinAndLibraryXsl.createElement("libraryXsl"); 
    968             if (libraryXsl != null) 
    969             { 
    970                 Element libraryXsl_el = libraryXsl.getDocumentElement(); 
    971                 l.appendChild(skinAndLibraryXsl.importNode(libraryXsl_el, true)); 
    972             } 
    973             root.appendChild(l); 
    974  
    975             //System.out.println("Skin and Library XSL are now together") ; 
    976  
    977             //System.out.println("Pre-processing the skin file...") ; 
    978  
    979             //pre-process the skin style sheet 
    980             //In other words, apply the preProcess.xsl to 'skinAndLibraryXsl' in order to 
    981             //expand all GS-Lib statements into complete XSL statements and also to create 
    982             //a valid xsl style sheet document. 
    983  
    984             XMLTransformer preProcessor = new XMLTransformer(); 
    985             // Perform the transformation, by passing in: 
    986             // preprocess-stylesheet, source-xsl (skinAndLibraryXsl), and the node that should  
    987             // be in the result (skinAndLibraryDoc) 
    988             preProcessor.transform_withResultNode(preprocessingXsl, skinAndLibraryXsl, skinAndLibraryDoc); 
    989             //System.out.println("GS-Lib statements are now expanded") ; 
    990         } 
    991  
    992         // there is a thing called a URIResolver which you can set for a 
    993         // transformer or transformer factory. may be able to use this 
    994         // instead of this absoluteIncludepaths hack 
    995  
    996         //GSXSLT.absoluteIncludePaths(skinAndLibraryDoc, GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 
    997  
    998         //Same but for the debug version when we want the do the transformation like we use to do 
    999         //without any gslib elements. 
    1000         GSXSLT.absoluteIncludePaths(oldStyle_doc, GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 
    1001  
    1002         //Send different stages of the skin xslt to the browser for debug purposes only 
    1003         //using &o=skindoc or &o=skinandlib etc... 
    1004         if (output.equals("skindoc")) 
    1005         { 
    1006             return converter.getDOM(getStringFromDocument(style_doc)); 
    1007         } 
    1008         if (output.equals("skinandlib")) 
    1009         { 
    1010             return converter.getDOM(getStringFromDocument(skinAndLibraryXsl)); 
    1011         } 
    1012         if (output.equals("skinandlibdoc")) 
    1013         { 
    1014  
    1015             Node skinAndLib = converter.getDOM(getStringFromDocument(skinAndLibraryDoc)); 
    1016             return skinAndLib;           
    1017         } 
    1018         if (output.equals("oldskindoc")) 
    1019         { 
    1020             return converter.getDOM(getStringFromDocument(oldStyle_doc)); 
    1021         } 
    1022  
    1023         // We now no longer create a document with doctype before the transformation 
    1024         // We let the XMLTransformer do the work of first working out the doctype from any  
    1025         // that may be set in the (merged) stylesheets and then setting the doctype when transforming 
    1026  
    1027         /* 
    1028         // Try to get the system and public ID from the current skin xsl document 
    1029         // otherwise keep the default values. 
    1030         Element root = skinAndLibraryDoc.getDocumentElement(); 
    1031         NodeList nodes = root.getElementsByTagName("xsl:output"); 
    1032         // If there is at least one "xsl:output" command in the final xsl then... 
    1033         if (nodes.getLength() != 0) 
    1034         { 
    1035             // There should be only one element called xsl:output,  
    1036             // but if this is not the case get the last one 
    1037             Element xsl_output = (Element) nodes.item(nodes.getLength() - 1); 
    1038             if (xsl_output != null) 
    1039             { 
    1040                 // Qualified name will always be html even for xhtml pages 
    1041                 //String attrValue = xsl_output.getAttribute("method"); 
    1042                 //qualifiedName = attrValue.equals("") ? qualifiedName : attrValue; 
    1043  
    1044                 String attrValue = xsl_output.getAttribute("doctype-system"); 
    1045                 systemID = attrValue.equals("") ? systemID : attrValue; 
    1046  
    1047                 attrValue = xsl_output.getAttribute("doctype-public"); 
    1048                 publicID = attrValue.equals("") ? publicID : attrValue; 
    1049             } 
    1050         } 
    1051  
    1052         //System.out.println(converter.getPrettyString(docWithDoctype)); 
    1053         //System.out.println("Doctype vals: " + qualifiedName + " " + publicID + " " + systemID) ; 
    1054  
    1055         docWithDoctype = converter.newDOM(qualifiedName, publicID, systemID); 
    1056         */ 
    1057  
    1058         //System.out.println("Generate final HTML from current skin") ; 
    1059         //Transformation of the XML message from the receptionist to HTML with doctype 
    1060  
    1061         if (inlineTemplate != null) 
    1062         { 
    1063             try 
    1064             { 
    1065                 Document inlineTemplateDoc = this.converter.getDOM("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet version=\"1.0\" "+GSXML.ALL_NAMESPACES_ATTS +  ">" + inlineTemplate + "</xsl:stylesheet>", "UTF-8"); 
    1066  
    1067                 if (_debug) 
    1068                 { 
    1069                     GSXSLT.mergeStylesheetsDebug(skinAndLibraryDoc, inlineTemplateDoc.getDocumentElement(), true, true, "OTHER2", "INLINE"); 
    1070                 } 
    1071                 else 
    1072                 { 
    1073                     GSXSLT.mergeStylesheets(skinAndLibraryDoc, inlineTemplateDoc.getDocumentElement(), true); 
    1074                 } 
    1075             } 
    1076             catch (Exception ex) 
    1077             { 
    1078                 ex.printStackTrace(); 
    1079             } 
    1080         } 
    1081  
    1082         if (_debug) 
    1083         { 
    1084             GSXSLT.inlineImportAndIncludeFilesDebug(skinAndLibraryDoc, null, _debug, this.getGSLibXSLFilename(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 
    1085         } 
    1086         else 
    1087         { 
    1088             GSXSLT.inlineImportAndIncludeFiles(skinAndLibraryDoc, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 
    1089         } 
    1090         skinAndLibraryDoc = (Document) performFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request), TEXT_PASS); 
    1091         skinAndLibraryDoc = (Document) performFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request), CONFIG_PASS); 
    1092  
    1093         if (output.equals("xmlfinal")) 
    1094         { 
    1095             return doc; 
    1096         } 
    1097  
    1098         if (output.equals("skinandlibdocfinal") || output.equals("clientside")) 
    1099         { 
    1100             if (output.equals("skinandlibdocfinal")) 
    1101             { 
    1102                     Node skinAndLibFinal = converter.getDOM(getStringFromDocument(skinAndLibraryDoc)); 
    1103                 return skinAndLibFinal; 
    1104             } 
    1105             else 
    1106             { 
    1107                     // Go through and 'fix up' any 'util:...' or 'java:...' attributes the skinAndLibraryDoc has 
    1108                     String lang = (String)config_params.get("lang"); 
    1109                     resolveExtendedNamespaceAttributesXSLT(skinAndLibraryDoc,currentInterface,lang); // test= and select= attributes 
    1110                 resolveExtendedNamespaceAttributesXML(skinAndLibraryDoc,currentInterface,lang);  // href= and src= attributes 
    1111                 Node skinAndLibFinal = converter.getDOM(getStringFromDocument(skinAndLibraryDoc)); 
    1112                  
    1113                 // Send XML and skinandlibdoc down the line together 
    1114                 Document finalDoc = converter.newDOM(); 
    1115                 Node finalDocSkin = finalDoc.importNode(skinAndLibraryDoc.getDocumentElement(), true); 
    1116                 Node finalDocXML = finalDoc.importNode(theXML.getDocumentElement(), true); 
    1117                 Element root = finalDoc.createElement("skinlibfinalPlusXML"); 
    1118                 root.appendChild(finalDocSkin); 
    1119                 root.appendChild(finalDocXML); 
    1120                 finalDoc.appendChild(root); 
    1121                 return (Node) finalDoc.getDocumentElement(); 
    1122             } 
    1123  
    1124  
    1125  
    1126              
    1127         } 
    1128  
     918                // add in all gslib.xsl's include and import files 
     919        // debug?? use debug method?? or does it not make sense here?? 
     920        GSXSLT.inlineImportAndIncludeFiles(libraryXsl, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 
     921 
     922        // now, we transform all the gslib elements 
     923        { 
     924           
     925 
     926          skinAndLibraryXsl = converter.newDOM(); 
     927          Element root = skinAndLibraryXsl.createElement("skinAndLibraryXsl"); 
     928          skinAndLibraryXsl.appendChild(root); 
     929           
     930          Element s = skinAndLibraryXsl.createElement("skinXsl"); 
     931          s.appendChild(skinAndLibraryXsl.importNode(page_xsl.getDocumentElement(), true)); 
     932          root.appendChild(s); 
     933           
     934          Element l = skinAndLibraryXsl.createElement("libraryXsl"); 
     935          if (libraryXsl != null) 
     936            { 
     937              Element libraryXsl_el = libraryXsl.getDocumentElement(); 
     938              l.appendChild(skinAndLibraryXsl.importNode(libraryXsl_el, true)); 
     939            } 
     940          root.appendChild(l); 
     941 
     942          XMLTransformer preProcessor = new XMLTransformer(); 
     943          preProcessor.transform_withResultNode(preprocessingXsl, skinAndLibraryXsl, skinAndLibraryDoc); 
     944 
     945        } 
     946        if (output.equals("xsl5")) { 
     947          return converter.getDOM(getStringFromDocument(skinAndLibraryDoc)); 
     948        } 
     949 
     950        skinAndLibraryDoc = (Document) transformGSFElements(collection, skinAndLibraryDoc, TEXT_FORMAT_FILE);  
     951           
     952        skinAndLibraryDoc = (Document) transformGSFElements(collection, skinAndLibraryDoc, CONFIG_FORMAT_FILE);  
     953        } 
     954         
     955 
     956        if (output.equals("xsl6") || output.equals("skinandlibdocfinal") 
     957        { 
     958          return converter.getDOM(getStringFromDocument(skinAndLibraryDoc)); 
     959        } 
     960         
     961        if (output.equals("clientside")) 
     962        { 
     963                     
     964          // Go through and 'fix up' any 'util:...' or 'java:...' attributes the skinAndLibraryDoc has 
     965          String lang = (String)config_params.get("lang"); 
     966          resolveExtendedNamespaceAttributesXSLT(skinAndLibraryDoc,currentInterface,lang); // test= and select= attributes 
     967          resolveExtendedNamespaceAttributesXML(skinAndLibraryDoc,currentInterface,lang);  // href= and src= attributes 
     968          Node skinAndLibFinal = converter.getDOM(getStringFromDocument(skinAndLibraryDoc)); 
     969           
     970          // Send XML and skinandlibdoc down the line together 
     971          Document finalDoc = converter.newDOM(); 
     972          Node finalDocSkin = finalDoc.importNode(skinAndLibraryDoc.getDocumentElement(), true); 
     973          Node finalDocXML = finalDoc.importNode(page_with_xslt_params_doc.getDocumentElement(), true); 
     974          Element root = finalDoc.createElement("skinlibfinalPlusXML"); 
     975          root.appendChild(finalDocSkin); 
     976          root.appendChild(finalDocXML); 
     977          finalDoc.appendChild(root); 
     978          return (Node) finalDoc.getDocumentElement(); 
     979        } 
     980         
     981        logger.debug("final xml is "); 
     982        logger.debug(XMLConverter.getPrettyString(page_xml_doc)); 
     983 
     984        logger.debug("final xsl is"); 
     985        logger.debug(XMLConverter.getPrettyString(skinAndLibraryDoc)); 
     986         
    1129987        // The transformer will now work out the resulting doctype from any set in the (merged) stylesheets and 
    1130988        // will set this in the output document it creates. So don't pass in any docWithDocType to the transformer 
    1131         //Node finalResult = this.transformer.transform(skinAndLibraryDoc, doc, config_params, docWithDoctype); 
    1132         Node finalResult = this.transformer.transform(skinAndLibraryDoc, doc, config_params); 
     989 
     990  // Here, we finally transform the page xml source with the complete xsl file 
     991  Node finalResult = this.transformer.transform(skinAndLibraryDoc, page_xml_doc, config_params); 
    1133992 
    1134993        if (_debug) 
     
    1139998        return finalResult; 
    1140999 
    1141         // The line below will do the transformation like we use to do before having Skin++ implemented, 
    1142         // it will not contain any GS-Lib statements expanded, and the result will not contain any doctype. 
    1143  
    1144         //return (Element)this.transformer.transform(style_doc, doc, config_params);   
    1145         //return null; // For now - change later 
    1146     } 
    1147  
    1148     protected Node performFormatPass(String collection, Document skinAndLibraryDoc, Document doc, UserContext userContext, int pass) 
    1149     { 
    1150         String formatFile; 
    1151         if (pass == CONFIG_PASS) 
    1152         { 
    1153             formatFile = "config_format.xsl"; 
    1154         } 
    1155         else 
    1156         { 
    1157             formatFile = "text_fragment_format.xsl"; 
    1158         } 
    1159  
    1160         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); 
    1161         Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file)); 
    1162  
    1163         if (configStylesheet_doc != null) 
    1164         { 
    1165             return this.transformer.transform(configStylesheet_doc, skinAndLibraryDoc, config_params); 
    1166         } 
    1167         return skinAndLibraryDoc; 
    1168     } 
     1000    } 
     1001 
     1002  protected Node generateXSLTClientOutput(Element request) { 
     1003 
     1004    // DocType defaults in case the skin doesn't have an "xsl:output" element 
     1005    String qualifiedName = "html"; 
     1006    String publicID = "-//W3C//DTD HTML 4.01 Transitional//EN"; 
     1007    String systemID = "http://www.w3.org/TR/html4/loose.dtd"; 
     1008 
     1009    // We need to create an empty document with a predefined DocType, 
     1010    // that will then be used for the transformation by the DOMResult 
     1011    Document docWithDoctype = converter.newDOM(qualifiedName, publicID, systemID); 
     1012    String baseURL = request.getAttribute(GSXML.BASE_URL); 
     1013                 
     1014    // If you're just getting the client-side transform page, why bother with the rest of this? 
     1015    Element html = docWithDoctype.createElement("html"); 
     1016    Element img = docWithDoctype.createElement("img"); 
     1017    img.setAttribute("src", "loading.gif"); // Make it dynamic 
     1018    img.setAttribute("alt", "Please wait..."); 
     1019    Text title_text = docWithDoctype.createTextNode("Please wait..."); // Make this language dependent 
     1020    Element head = docWithDoctype.createElement("head"); 
     1021 
     1022    // e.g., <base href="http://localhost:8383/greenstone3/" /><!-- [if lte IE 6]></base><![endif] --> 
     1023    Element base = docWithDoctype.createElement("base"); 
     1024    base.setAttribute("href",baseURL); 
     1025    Comment opt_end_base = docWithDoctype.createComment("[if lte IE 6]></base><![endif]"); 
     1026             
     1027    Element title = docWithDoctype.createElement("title"); 
     1028    title.appendChild(title_text); 
     1029 
     1030    Element body = docWithDoctype.createElement("body"); 
     1031 
     1032    Element jquery_script = docWithDoctype.createElement("script"); 
     1033    jquery_script.setAttribute("src", "jquery-1.10-min.js"); 
     1034    jquery_script.setAttribute("type", "text/javascript"); 
     1035    Comment jquery_comment = docWithDoctype.createComment("jQuery"); 
     1036    jquery_script.appendChild(jquery_comment); 
     1037 
     1038    Element saxonce_script = docWithDoctype.createElement("script"); 
     1039    saxonce_script.setAttribute("src", "Saxonce/Saxonce.nocache.js"); 
     1040    saxonce_script.setAttribute("type", "text/javascript"); 
     1041    Comment saxonce_comment = docWithDoctype.createComment("SaxonCE"); 
     1042    saxonce_script.appendChild(saxonce_comment); 
     1043 
     1044    Element xsltutil_script = docWithDoctype.createElement("script"); 
     1045    xsltutil_script.setAttribute("src", "xslt-util.js"); 
     1046    xsltutil_script.setAttribute("type", "text/javascript"); 
     1047    Comment xsltutil_comment = docWithDoctype.createComment("JavaScript version of XSLTUtil.java"); 
     1048    xsltutil_script.appendChild(xsltutil_comment); 
     1049 
     1050    Element script = docWithDoctype.createElement("script"); 
     1051    Comment script_comment = docWithDoctype.createComment("Filler for browser"); 
     1052    script.setAttribute("src", "client-side-xslt.js"); 
     1053    script.setAttribute("type", "text/javascript"); 
     1054    script.appendChild(script_comment); 
     1055             
     1056    Element pagevar = docWithDoctype.createElement("script"); 
     1057    Element style = docWithDoctype.createElement("style"); 
     1058    style.setAttribute("type", "text/css"); 
     1059    Text style_text = docWithDoctype.createTextNode("body { text-align: center; padding: 50px; font: 14pt Arial, sans-serif; font-weight: bold; }"); 
     1060    pagevar.setAttribute("type", "text/javascript"); 
     1061    Text page_var_text = docWithDoctype.createTextNode("var placeholder = true;"); 
     1062 
     1063    html.appendChild(head); 
     1064    head.appendChild(base); head.appendChild(opt_end_base); 
     1065    head.appendChild(title); 
     1066    head.appendChild(style); 
     1067    style.appendChild(style_text); 
     1068    html.appendChild(body); 
     1069    head.appendChild(pagevar); 
     1070    head.appendChild(jquery_script); 
     1071    head.appendChild(saxonce_script); 
     1072    head.appendChild(xsltutil_script); 
     1073    head.appendChild(script); 
     1074    pagevar.appendChild(page_var_text); 
     1075 
     1076    body.appendChild(img); 
     1077    docWithDoctype.appendChild(html); 
     1078 
     1079    return (Node) docWithDoctype; 
     1080 
     1081  } 
     1082 
     1083  // transform the xsl with xsl to replace all gsf elements. We do this in 2 stages - 
     1084  // first do just a text pass, that way we can have gsf elements in the text content  
     1085  protected Node transformGSFElements(String collection, Document skinAndLibraryDoc, String formatFile) { 
     1086 
     1087    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); 
     1088    Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file)); 
     1089     
     1090    if (configStylesheet_doc != null) 
     1091      { 
     1092    return this.transformer.transform(configStylesheet_doc, skinAndLibraryDoc, config_params); 
     1093      } 
     1094    return skinAndLibraryDoc; 
     1095     
     1096  }     
    11691097 
    11701098    // method to convert Document to a proper XML string for debug purposes only 
     
    12051133    } 
    12061134 
     1135  protected String getXSLTFilename(String action, String subaction) { 
     1136    String name = null; 
     1137    if (!subaction.equals("")) 
     1138      { 
     1139    String key = action + ":" + subaction; 
     1140    name = this.xslt_map.get(key); 
     1141      } 
     1142    // try the action by itself 
     1143    if (name == null) 
     1144      { 
     1145    name = this.xslt_map.get(action); 
     1146      } 
     1147    if (name == null) 
     1148      { 
     1149    // so we can reandomly create any named page 
     1150    if (action.equals("p") && !subaction.equals("")) 
     1151      { 
     1152        // TODO: pages/ won't work for interface other than default!! 
     1153        name = "pages/" + subaction + ".xsl"; 
     1154      } 
     1155     
     1156      } 
     1157    return name; 
     1158  } 
     1159 
     1160   
    12071161    protected Document getXSLTDocument(String action, String subaction, String collection) 
    12081162    { 
    1209         String name = null; 
    1210         if (!subaction.equals("")) 
    1211         { 
    1212             String key = action + ":" + subaction; 
    1213             name = this.xslt_map.get(key); 
    1214         } 
    1215         // try the action by itself 
    1216         if (name == null) 
    1217         { 
    1218             name = this.xslt_map.get(action); 
    1219         } 
    1220         if (name == null) 
    1221         { 
    1222             // so we can reandomly create any named page 
    1223             if (action.equals("p") && !subaction.equals("")) 
    1224             { 
    1225                 // TODO: pages/ won't work for interface other than default!! 
    1226                 name = "pages/" + subaction + ".xsl"; 
    1227             } 
    1228  
    1229         } 
    1230          
     1163      String name = getXSLTFilename(action, subaction); 
    12311164        Document finalDoc = null; 
    12321165        if(name != null) 
    12331166        { 
    1234             finalDoc = GSXSLT.mergedXSLTDocumentCascade(name, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, _debug); 
     1167          // this finds all the stylesheets named "name" and merges them together, in the order of 
     1168          // base interface, current interface, site, collection - the latter overriding the former. 
     1169          // templates with the same name will replace earlier versions 
     1170          finalDoc = GSXSLT.mergedXSLTDocumentCascade(name, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, _debug); 
    12351171        } 
    12361172        return finalDoc;