- Timestamp:
- 2019-11-12T12:06:56+13:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java
r33647 r33650 49 49 public class TransformingReceptionist extends Receptionist 50 50 { 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"; 60 55 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 61 61 /** the list of xslt to use for actions */ 62 62 protected HashMap<String, String> xslt_map = null; … … 756 756 757 757 // need to transform the format info 758 // run config_format.xsl over the format_elem. We need to do this now to turn758 // run expand-gsf.xsl over the format_elem. We need to do this now to turn 759 759 // eg gsf:template into xsl:template so that the merging works properly. 760 760 // xsl:templates will get merged 761 761 // 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)); 762 765 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. 782 777 Element new_format; 783 778 if (result.getNodeType() == Node.DOCUMENT_NODE) … … 806 801 } 807 802 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 816 804 } 817 805 … … 868 856 return converter.getDOM(getStringFromDocument(page_xsl)); 869 857 } 870 871 // The next steg is to process the page_xsl + gslib.xsl by preProcess.xsl to expand all the 872 //gslib elements873 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; 875 863 try 876 864 { 877 // interfaces/core/transform/ preProcess.xsl865 // interfaces/core/transform/expand-gslib.xsl 878 866 // 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); 880 868 String errMsg = ((XMLConverter.ParseErrorHandler) parser.getErrorHandler()).getErrorMessage(); 881 869 if (errMsg != null) 882 870 { 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); 884 872 } 885 873 } … … 891 879 { 892 880 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()); 895 883 } 896 884 897 885 // gslib.xsl 898 Document libraryXsl= null;886 Document gslib_xsl_doc = null; 899 887 try 900 888 { 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); 902 890 } 903 891 catch (Exception e) … … 908 896 } 909 897 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)); 912 900 } 913 901 if (output.equals("gslib1")) { 914 return converter.getDOM(getStringFromDocument( libraryXsl));902 return converter.getDOM(getStringFromDocument(gslib_xsl_doc)); 915 903 } 916 904 // Combine the skin file and library variables/templates into one document. … … 918 906 // needs to know what's available in the library. 919 907 920 Document skinAndLibraryXsl = null;921 Document skinAndLibraryDoc = converter.newDOM();922 908 923 909 // add in all gslib.xsl's include and import files 924 910 // 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); 926 912 if (output.equals("gslib")) { 927 return converter.getDOM(getStringFromDocument( libraryXsl));913 return converter.getDOM(getStringFromDocument(gslib_xsl_doc)); 928 914 } 929 915 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 931 921 { 932 922 933 923 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); 937 927 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)); 940 930 root.appendChild(s); 941 931 942 Element l = skinAndLibraryXsl.createElement("libraryXsl");943 if ( libraryXsl!= null)932 Element l = pageAndGslibXsl.createElement("gslibXsl"); 933 if (gslib_xsl_doc != null) 944 934 { 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)); 947 937 } 948 938 root.appendChild(l); 949 939 940 if (output.equals("xsl5")) { 941 return converter.getDOM(getStringFromDocument(pageAndGslibXsl)); 942 } 950 943 // actually merge the gslib file with the page 951 944 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 } 961 951 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 966 960 if (output.equals("xsl") || output.equals("skinandlibdocfinal")) 967 961 { 968 return converter.getDOM(getStringFromDocument( skinAndLibraryDoc));962 return converter.getDOM(getStringFromDocument(pageAndGslibDoc)); 969 963 } 970 964 … … 972 966 { 973 967 974 // Go through and 'fix up' any 'util:...' or 'java:...' attributes the skinAndLibraryDoc has968 // Go through and 'fix up' any 'util:...' or 'java:...' attributes the pageAndGslibDoc has 975 969 String lang = (String)config_params.get("lang"); 976 resolveExtendedNamespaceAttributesXSLT( skinAndLibraryDoc,currentInterface,lang); // test= and select= attributes977 resolveExtendedNamespaceAttributesXML( skinAndLibraryDoc,currentInterface,lang); // href= and src= attributes978 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)); 979 973 980 974 // Send XML and skinandlibdoc down the line together 981 975 Document finalDoc = converter.newDOM(); 982 Node finalDocSkin = finalDoc.importNode( skinAndLibraryDoc.getDocumentElement(), true);976 Node finalDocSkin = finalDoc.importNode(pageAndGslibDoc.getDocumentElement(), true); 983 977 Node finalDocXML = finalDoc.importNode(page_with_xslt_params_doc.getDocumentElement(), true); 984 978 Element root = finalDoc.createElement("skinlibfinalPlusXML"); … … 993 987 994 988 ///logger.debug("final xsl is"); 995 ///logger.debug(XMLConverter.getPrettyString( skinAndLibraryDoc));989 ///logger.debug(XMLConverter.getPrettyString(pageAndGslibDoc)); 996 990 997 991 // The transformer will now work out the resulting doctype from any set in the (merged) stylesheets and … … 999 993 1000 994 // 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); 1002 996 1003 997 if (_debug) … … 1093 1087 // transform the xsl with xsl to replace all gsf elements. We do this in 2 stages - 1094 1088 // first do just a text pass, that way we can have gsf elements in the text content 1095 protected Node transformGSFElements(String collection, Document s kinAndLibraryDoc, 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)); 1099 1093 1100 if ( configStylesheet_doc != null)1094 if (expand_gsf_doc != null) 1101 1095 { 1102 return this.transformer.transform( configStylesheet_doc, skinAndLibraryDoc, config_params);1096 return this.transformer.transform(expand_gsf_doc, source_xsl, config_params); 1103 1097 } 1104 return s kinAndLibraryDoc;1098 return source_xsl; 1105 1099 1106 1100 }
Note:
See TracChangeset
for help on using the changeset viewer.