Changeset 24884 for main/trunk/greenstone3
- Timestamp:
- 2011-12-13T09:55:30+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java
r24703 r24884 15 15 16 16 // other java classes 17 import java.io.ByteArrayInputStream; 17 18 import java.io.File; 19 import java.io.StringReader; 18 20 import java.io.StringWriter; 19 21 import java.io.FileReader; … … 449 451 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 450 452 String collection = ""; 453 String inlineTemplate = ""; 451 454 if (cgi_param_list != null) 452 455 { 453 456 // Don't waste time getting all the parameters 454 HashMap params = GSXML.extractParams(cgi_param_list, false , GSParams.COLLECTION);457 HashMap params = GSXML.extractParams(cgi_param_list, false); 455 458 collection = (String) params.get(GSParams.COLLECTION); 456 459 if (collection == null) 460 { 457 461 collection = ""; 462 } 463 464 inlineTemplate = (String) params.get(GSParams.INLINE_TEMPLATE); 458 465 } 459 466 … … 535 542 try 536 543 { 537 preprocessingXsl = get PreprocessDoc();544 preprocessingXsl = getDoc(preprocess_xsl_filename); 538 545 String errMsg = ((XMLConverter.ParseErrorHandler) parser.getErrorHandler()).getErrorMessage(); 539 546 if (errMsg != null) … … 556 563 try 557 564 { 558 libraryXsl = get LibraryDoc();565 libraryXsl = getDoc(this.getLibraryXSLFilename()); 559 566 String errMsg = ((XMLConverter.ParseErrorHandler) parser.getErrorHandler()).getErrorMessage(); 560 567 if (errMsg != null) … … 755 762 //System.out.println("Generate final HTML from current skin") ; 756 763 //Transformation of the XML message from the receptionist to HTML with doctype 764 765 if(inlineTemplate != null) 766 { 767 try 768 { 769 Document inlineTemplateDoc = this.converter.getDOM("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:java=\"http://xml.apache.org/xslt/java\" xmlns:util=\"xalan://org.greenstone.gsdl3.util.XSLTUtil\" xmlns:gsf=\"http://www.greenstone.org/greenstone3/schema/ConfigFormat\">" + inlineTemplate + "</xsl:stylesheet>"); 770 GSXSLT.mergeStylesheets(skinAndLibraryDoc, inlineTemplateDoc.getDocumentElement()); 771 } 772 catch(Exception ex) 773 { 774 ex.printStackTrace(); 775 } 776 } 757 777 758 if (skinAndLibraryDoc.getElementsByTagName("gsf:metadata").getLength() > 0)778 if (skinAndLibraryDoc.getElementsByTagName("gsf:metadata").getLength() > 0) 759 779 { 760 780 secondConfigFormatPass(collection, skinAndLibraryDoc, doc, request.getAttribute("lang"), request.getAttribute("uid")); 761 781 } 762 782 763 783 if (output.equals("xmlfinal")) 764 784 { 765 785 return doc; 766 786 } 767 787 768 788 return this.transformer.transform(skinAndLibraryDoc, doc, config_params, docWithDoctype); // The default 769 789 … … 774 794 //return null; // For now - change later 775 795 } 776 796 777 797 protected void secondConfigFormatPass(String collection, Document skinAndLibraryDoc, Document doc, String lang, String uid) 778 798 { … … 782 802 Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 783 803 Element docNodeList = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 784 804 785 805 NodeList metaNodes = skinAndLibraryDoc.getElementsByTagName("gsf:metadata"); 786 806 787 for (int i = 0; i < metaNodes.getLength(); i++)807 for (int i = 0; i < metaNodes.getLength(); i++) 788 808 { 789 809 Element param = this.doc.createElement(GSXML.PARAM_ELEM); 790 810 param.setAttribute(GSXML.NAME_ATT, "metadata"); 791 param.setAttribute(GSXML.VALUE_ATT, ((Element) metaNodes.item(i)).getAttribute(GSXML.NAME_ATT));811 param.setAttribute(GSXML.VALUE_ATT, ((Element) metaNodes.item(i)).getAttribute(GSXML.NAME_ATT)); 792 812 paramList.appendChild(param); 793 813 } 794 814 metaRequest.appendChild(paramList); 795 815 796 816 NodeList docNodes = doc.getElementsByTagName("documentNode"); 797 for (int i = 0; i < docNodes.getLength(); i++)817 for (int i = 0; i < docNodes.getLength(); i++) 798 818 { 799 819 Element docNode = this.doc.createElement(GSXML.DOC_NODE_ELEM); 800 docNode.setAttribute(GSXML.NODE_ID_ATT, ((Element) docNodes.item(i)).getAttribute(GSXML.NODE_ID_ATT));801 docNode.setAttribute(GSXML.NODE_TYPE_ATT, ((Element) docNodes.item(i)).getAttribute(GSXML.NODE_TYPE_ATT));820 docNode.setAttribute(GSXML.NODE_ID_ATT, ((Element) docNodes.item(i)).getAttribute(GSXML.NODE_ID_ATT)); 821 docNode.setAttribute(GSXML.NODE_TYPE_ATT, ((Element) docNodes.item(i)).getAttribute(GSXML.NODE_TYPE_ATT)); 802 822 docNodeList.appendChild(docNode); 803 823 } … … 805 825 806 826 metaMessage.appendChild(metaRequest); 807 Element response = (Element) mr.process(metaMessage);827 Element response = (Element) mr.process(metaMessage); 808 828 809 829 NodeList metaDocNodes = response.getElementsByTagName(GSXML.DOC_NODE_ELEM); 810 for (int i = 0; i < docNodes.getLength(); i++)830 for (int i = 0; i < docNodes.getLength(); i++) 811 831 { 812 832 GSXML.mergeMetadataLists(docNodes.item(i), metaDocNodes.item(i)); 813 833 } 814 834 815 835 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"); 816 836 Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file)); … … 821 841 format_doc.appendChild(format_doc.importNode(skinAndLibraryDoc.getDocumentElement().cloneNode(true), true)); 822 842 Node result = this.transformer.transform(configStylesheet_doc, format_doc, config_params); 823 GSXSLT.mergeStylesheets(skinAndLibraryDoc, ((Document) result).getDocumentElement());843 GSXSLT.mergeStylesheets(skinAndLibraryDoc, ((Document) result).getDocumentElement()); 824 844 } 825 845 } … … 850 870 } 851 871 852 protected Document getPreprocessDoc() throws Exception 853 { 854 855 File xslt_file = new File(preprocess_xsl_filename); 872 protected synchronized Document getDoc(String docName) throws Exception 873 { 874 File xslt_file = new File(docName); 856 875 857 876 FileReader reader = new FileReader(xslt_file); … … 863 882 } 864 883 865 protected Document getLibraryDoc() throws Exception866 {867 Document doc = null;868 File xslt_file = new File(this.getLibraryXSLFilename());869 870 FileReader reader = new FileReader(xslt_file);871 InputSource xml_source = new InputSource(reader);872 this.parser.parse(xml_source);873 874 doc = this.parser.getDocument();875 return doc;876 }877 878 884 protected Document getXSLTDocument(String action, String subaction, String collection) 879 885 { … … 898 904 } 899 905 logger.debug("Stylesheet: " + name); 900 901 Document finalDoc = this.converter.getDOM(stylesheets.get(stylesheets.size() - 1), "UTF-8");902 if (finalDoc == null)906 907 Document finalDoc = this.converter.getDOM(stylesheets.get(stylesheets.size() - 1), "UTF-8"); 908 if (finalDoc == null) 903 909 { 904 910 return null; 905 911 } 906 907 for (int i = stylesheets.size() - 2; i >= 0; i--)912 913 for (int i = stylesheets.size() - 2; i >= 0; i--) 908 914 { 909 915 Document currentDoc = this.converter.getDOM(stylesheets.get(i), "UTF-8"); 910 if (currentDoc == null)916 if (currentDoc == null) 911 917 { 912 918 return null; 913 919 } 914 920 915 921 GSXSLT.mergeStylesheets(finalDoc, currentDoc.getDocumentElement()); 916 922 } 917 923 918 924 return finalDoc; 919 925 }
Note:
See TracChangeset
for help on using the changeset viewer.