- Timestamp:
- 2012-08-01T13:57:10+12:00 (12 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSFile.java
r26027 r26055 19 19 package org.greenstone.gsdl3.util; 20 20 21 import java.io.File;22 //import org.apache.soap.encoding.soapenc.Base64;23 import org.apache.axis.encoding.Base64;24 21 import java.io.BufferedInputStream; 25 22 import java.io.BufferedOutputStream; 23 import java.io.File; 26 24 import java.io.FileInputStream; 27 25 import java.io.FileOutputStream; 28 import java.io.InputStream;29 26 import java.io.IOException; 30 import java.lang.ClassLoader; // to find files on the class path31 import java.net.URL;32 27 import java.nio.channels.FileChannel; 33 28 import java.util.ArrayList; 34 import java.util.Collection; 35 36 import org.apache.log4j. *;29 30 import org.apache.axis.encoding.Base64; 31 import org.apache.log4j.Logger; 37 32 import org.greenstone.util.GlobalProperties; 38 33 -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
r26047 r26055 291 291 public static final String VLIST = "VList"; 292 292 293 //for namespaces 294 public static final String XSL_NAMESPACE = "http://www.w3.org/1999/XSL/Transform"; 295 public static final String GSF_NAMESPACE = "http://www.greenstone.org/greenstone3/schema/ConfigFormat"; 296 public static final String JAVA_NAMESPACE = "http://xml.apache.org/xslt/java"; 297 public static final String UTIL_NAMESPACE = "xalan://org.greenstone.gsdl3.util.XSLTUtil"; 298 293 299 /** 294 300 * takes a list of elements, and returns an array of strings of the values -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java
r25988 r26055 61 61 Element main = main_xsl.getDocumentElement(); 62 62 Node insertion_point = null; 63 Element last_import = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "import");63 Element last_import = GSXML.getLastElementByTagNameNS(main, GSXML.XSL_NAMESPACE, "import"); 64 64 if (last_import != null) 65 65 { … … 72 72 73 73 // imports 74 NodeList children = extra_xsl.getElementsByTagNameNS( "http://www.w3.org/1999/XSL/Transform", "import");74 NodeList children = extra_xsl.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "import"); 75 75 for (int i = 0; i < children.getLength(); i++) 76 76 { … … 78 78 // If the new xsl:import element is identical (in terms of href attr value) 79 79 // to any in the merged document, don't copy it over 80 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "import", "href", node.getAttribute("href")) == null)80 if (GSXML.getNamedElementNS(main, GSXML.XSL_NAMESPACE, "import", "href", node.getAttribute("href")) == null) 81 81 { 82 82 // Import statements should be the first children of an xsl:stylesheet element … … 90 90 91 91 // do we have a new insertion point?? 92 Element last_include = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "include");92 Element last_include = GSXML.getLastElementByTagNameNS(main, GSXML.XSL_NAMESPACE, "include"); 93 93 if (last_include != null) 94 94 { … … 97 97 98 98 // includes 99 children = extra_xsl.getElementsByTagNameNS( "http://www.w3.org/1999/XSL/Transform", "include");99 children = extra_xsl.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "include"); 100 100 for (int i = 0; i < children.getLength(); i++) 101 101 { … … 105 105 // Although Node.appendChild() will first remove identical nodes before appending, we check 106 106 // only the href attribute to see if they're "identical" to any pre-existing <xsl:include> 107 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "include", "href", node.getAttribute("href")) == null)107 if (GSXML.getNamedElementNS(main, GSXML.XSL_NAMESPACE, "include", "href", node.getAttribute("href")) == null) 108 108 { 109 109 //main.appendChild(main_xsl.importNode(node, true)); … … 112 112 } // for each include 113 113 114 if (main.getElementsByTagNameNS( "http://www.w3.org/1999/XSL/Transform", "output").getLength() == 0)114 if (main.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "output").getLength() == 0) 115 115 { 116 116 // outputs 117 children = extra_xsl.getElementsByTagNameNS( "http://www.w3.org/1999/XSL/Transform", "output");117 children = extra_xsl.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "output"); 118 118 for (int i = 0; i < children.getLength(); i++) 119 119 { … … 128 128 // variables - only top level ones!! 129 129 // append to end of document 130 children = GSXML.getChildrenByTagNameNS(extra_xsl, "http://www.w3.org/1999/XSL/Transform", "variable");130 children = GSXML.getChildrenByTagNameNS(extra_xsl, GSXML.XSL_NAMESPACE, "variable"); 131 131 for (int i = 0; i < children.getLength(); i++) 132 132 { … … 134 134 // If the new xsl:import element is identical (in terms of href attr value) 135 135 // to any in the merged document, don't copy it over 136 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "variable", "name", node.getAttribute("name")) == null)136 if (GSXML.getNamedElementNS(main, GSXML.XSL_NAMESPACE, "variable", "name", node.getAttribute("name")) == null) 137 137 { 138 138 main.appendChild(main_xsl.importNode(node, true)); … … 142 142 // params - only top level ones!! 143 143 // append to end of document 144 children = GSXML.getChildrenByTagNameNS(extra_xsl, "http://www.w3.org/1999/XSL/Transform", "param");144 children = GSXML.getChildrenByTagNameNS(extra_xsl, GSXML.XSL_NAMESPACE, "param"); 145 145 for (int i = 0; i < children.getLength(); i++) 146 146 { … … 148 148 // If the new xsl:import element is identical (in terms of href attr value) 149 149 // to any in the merged document, don't copy it over 150 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "param", "name", node.getAttribute("name")) == null)150 if (GSXML.getNamedElementNS(main, GSXML.XSL_NAMESPACE, "param", "name", node.getAttribute("name")) == null) 151 151 { 152 152 main.appendChild(main_xsl.importNode(node, true)); … … 156 156 // templates 157 157 // append to end of document 158 children = extra_xsl.getElementsByTagNameNS( "http://www.w3.org/1999/XSL/Transform", "template");158 children = extra_xsl.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template"); 159 159 for (int i = 0; i < children.getLength(); i++) 160 160 { … … 168 168 { 169 169 // if we have a name attribute, remove any other similarly named template 170 GSXML.removeElementsWithAttributesNS(main, "http://www.w3.org/1999/XSL/Transform", "template", new String[] { "name", "match", "mode" }, new String[] { template_name, template_match, template_mode });170 GSXML.removeElementsWithAttributesNS(main, GSXML.XSL_NAMESPACE, "template", new String[] { "name", "match", "mode" }, new String[] { template_name, template_match, template_mode }); 171 171 172 172 // now add our good template in … … 179 179 // there can't be any duplicate named templates, so just look for matches 180 180 // we already have the one with highest import precedence (from the top most level) so don't add any more in 181 if (GSXML.getElementsWithAttributesNS(main, "http://www.w3.org/1999/XSL/Transform", "template", new String[] { "name", "match", "mode" }, new String[] { template_name, template_match, template_mode }).getLength() == 0)181 if (GSXML.getElementsWithAttributesNS(main, GSXML.XSL_NAMESPACE, "template", new String[] { "name", "match", "mode" }, new String[] { template_name, template_match, template_mode }).getLength() == 0) 182 182 { 183 183 main.appendChild(main_xsl.importNode(node, true)); … … 204 204 Element xslParent = (Element) current.getParentNode(); 205 205 206 while (xslParent.getNamespaceURI() != "http://www.w3.org/1999/XSL/Transform"&& !xslParent.getNodeName().startsWith("xsl:"))206 while (xslParent.getNamespaceURI() != GSXML.XSL_NAMESPACE && !xslParent.getNodeName().startsWith("xsl:")) 207 207 { 208 208 xslParent = (Element) xslParent.getParentNode(); … … 220 220 } 221 221 222 223 { 224 225 } 226 227 222 public static void inlineImportAndIncludeFiles(Document doc, String pathExtra, String site, String collection, String interface_name, ArrayList<String> base_interfaces) 223 { 224 inlineImportAndIncludeFilesDebug(doc, pathExtra, false, null, site, collection, interface_name, base_interfaces); 225 } 226 227 public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, boolean debug, String docFileName, String site, String collection, String interface_name, ArrayList<String> base_interfaces) 228 228 { 229 229 XMLConverter converter = new XMLConverter(); … … 231 231 String path = (pathExtra == null) ? "" : pathExtra; 232 232 233 NodeList importList = doc.getElementsByTagNameNS( "http://www.w3.org/1999/XSL/Transform", "import");234 NodeList includeList = doc.getElementsByTagNameNS( "http://www.w3.org/1999/XSL/Transform", "include");233 NodeList importList = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "import"); 234 NodeList includeList = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "include"); 235 235 236 236 for (int i = 0; i < importList.getLength() + includeList.getLength(); i++) … … 243 243 try 244 244 { 245 246 Document inlineDoc = mergedXSLTDocumentCascade(path+href, site, collection, interface_name, base_interfaces, debug);245 //Document inlineDoc = converter.getDOM(new File(filePath), "UTF-8"); 246 Document inlineDoc = mergedXSLTDocumentCascade(path + href, site, collection, interface_name, base_interfaces, debug); 247 247 String newPath = path; 248 248 int lastSepIndex = href.lastIndexOf("/"); … … 253 253 254 254 //Do this recursively 255 inlineImportAndIncludeFilesDebug(inlineDoc, newPath, debug, "merged " +href/*filePath*/, site, collection, interface_name, base_interfaces);256 257 GSXSLT.mergeStylesheetsDebug(doc, inlineDoc.getDocumentElement(), false, debug, docFileName, /* filePath*/"merged "+href);255 inlineImportAndIncludeFilesDebug(inlineDoc, newPath, debug, "merged " + href/* filePath */, site, collection, interface_name, base_interfaces); 256 257 GSXSLT.mergeStylesheetsDebug(doc, inlineDoc.getDocumentElement(), false, debug, docFileName, /* filePath */"merged " + href); 258 258 } 259 259 catch (Exception ex) … … 276 276 } 277 277 278 public static Document mergedXSLTDocumentCascade(String xslt_filename, String site, String collection, String this_interface, ArrayList<String> base_interfaces, boolean debug) { 279 XMLConverter converter = new XMLConverter(); 280 // find the list of stylesheets with this name 281 ArrayList<File> stylesheets = GSFile.getStylesheetFiles(GlobalProperties.getGSDL3Home(), site, collection, this_interface, base_interfaces, xslt_filename); 278 public static Document mergedXSLTDocumentCascade(String xslt_filename, String site, String collection, String this_interface, ArrayList<String> base_interfaces, boolean debug) 279 { 280 XMLConverter converter = new XMLConverter(); 281 // find the list of stylesheets with this name 282 ArrayList<File> stylesheets = GSFile.getStylesheetFiles(GlobalProperties.getGSDL3Home(), site, collection, this_interface, base_interfaces, xslt_filename); 282 283 if (stylesheets.size() == 0) 283 284 { … … 314 315 } 315 316 316 317 318 317 public static void modifyConfigFormatForDebug(Document doc, String fileName) 319 318 { 320 NodeList templateNodes = doc.getElementsByTagNameNS( "http://www.w3.org/1999/XSL/Transform", "template");319 NodeList templateNodes = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template"); 321 320 if (templateNodes.getLength() == 0) 322 321 { … … 331 330 332 331 XMLConverter converter = new XMLConverter(); 333 Element debugElement = (Element) converter.getDOM("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xslt:stylesheet version=\"1.0\" xmlns:xsl=\" http://www.w3.org/1999/XSL/Transform\" xmlns:xslt=\"output.xsl\" xmlns:gsf=\"http://www.greenstone.org/greenstone3/schema/ConfigFormat\">" + debugElementString + "</xslt:stylesheet>").getDocumentElement().getFirstChild();332 Element debugElement = (Element) converter.getDOM("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xslt:stylesheet version=\"1.0\" xmlns:xsl=\"" + GSXML.XSL_NAMESPACE + "\" xmlns:xslt=\"output.xsl\" xmlns:gsf=\"" + GSXML.GSF_NAMESPACE + "\">" + debugElementString + "</xslt:stylesheet>").getDocumentElement().getFirstChild(); 334 333 335 334 for (int i = 0; i < templateNodes.getLength(); i++) … … 419 418 public static void mergeFormatElements(Element mainFormat, Element secondaryFormat, boolean overwrite) 420 419 { 421 NodeList xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.w3.org/1999/XSL/Transform", "variable");422 NodeList gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "variable");420 NodeList xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.XSL_NAMESPACE, "variable"); 421 NodeList gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.GSF_NAMESPACE, "variable"); 423 422 for (int i = 0; i < xslChildren.getLength() + gsfChildren.getLength(); i++) 424 423 { … … 430 429 } 431 430 432 xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.w3.org/1999/XSL/Transform", "param");433 gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "param");431 xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.XSL_NAMESPACE, "param"); 432 gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.GSF_NAMESPACE, "param"); 434 433 for (int i = 0; i < xslChildren.getLength() + gsfChildren.getLength(); i++) 435 434 { … … 441 440 } 442 441 443 xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.w3.org/1999/XSL/Transform", "template");444 gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "template");442 xslChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.XSL_NAMESPACE, "template"); 443 gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.GSF_NAMESPACE, "template"); 445 444 for (int i = 0; i < xslChildren.getLength() + gsfChildren.getLength(); i++) 446 445 { … … 457 456 { 458 457 // if we have a name attribute, remove any other similarly named template 459 GSXML.removeElementsWithAttributesNS(mainFormat, "http://www.w3.org/1999/XSL/Transform", "template", attributeNames, attributeValues);460 GSXML.removeElementsWithAttributesNS(mainFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "template", attributeNames, attributeValues);458 GSXML.removeElementsWithAttributesNS(mainFormat, GSXML.XSL_NAMESPACE, "template", attributeNames, attributeValues); 459 GSXML.removeElementsWithAttributesNS(mainFormat, GSXML.GSF_NAMESPACE, "template", attributeNames, attributeValues); 461 460 462 461 // now add our good template in … … 476 475 } 477 476 478 gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "option");477 gsfChildren = GSXML.getChildrenByTagNameNS(secondaryFormat, GSXML.GSF_NAMESPACE, "option"); 479 478 for (int i = 0; i < gsfChildren.getLength(); i++) 480 479 { 481 480 Element node = (Element) gsfChildren.item(i); 482 if (GSXML.getNamedElementNS(mainFormat, "http://www.greenstone.org/greenstone3/schema/ConfigFormat", "option", "name", node.getAttribute("name")) == null)481 if (GSXML.getNamedElementNS(mainFormat, GSXML.GSF_NAMESPACE, "option", "name", node.getAttribute("name")) == null) 483 482 { 484 483 mainFormat.appendChild(node);
Note:
See TracChangeset
for help on using the changeset viewer.