Changeset 26458
- Timestamp:
- 2012-11-14T15:37:35+13:00 (11 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java
r26426 r26458 924 924 } 925 925 926 GSXSLT.inlineImportAndIncludeFiles(skinAndLibraryDoc, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 926 if (_debug) 927 { 928 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); 929 } 930 else 931 { 932 GSXSLT.inlineImportAndIncludeFiles(skinAndLibraryDoc, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces); 933 } 927 934 skinAndLibraryDoc = (Document) performFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request), TEXT_PASS); 928 935 skinAndLibraryDoc = (Document) performFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request), CONFIG_PASS); 929 936 937 if (output.equals("xmlfinal")) 938 { 939 return doc; 940 } 941 942 if (output.equals("skinandlibdocfinal")) 943 { 944 return converter.getDOM(getStringFromDocument(skinAndLibraryDoc)); 945 } 946 947 Node finalResult = this.transformer.transform(skinAndLibraryDoc, doc, config_params, docWithDoctype); 948 930 949 if (_debug) 931 950 { 932 GSXML.addDebugSpanTags(skinAndLibraryDoc); 933 } 934 935 if (output.equals("xmlfinal")) 936 { 937 return doc; 938 } 939 940 if (output.equals("skinandlibdocfinal")) 941 { 942 return converter.getDOM(getStringFromDocument(skinAndLibraryDoc)); 943 } 944 945 return this.transformer.transform(skinAndLibraryDoc, doc, config_params, docWithDoctype); 951 GSXSLT.fixTables((Document) finalResult); 952 } 953 954 return finalResult; 946 955 947 956 // The line below will do the transformation like we use to do before having Skin++ implemented, -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java
r26055 r26458 23 23 import java.util.Vector; 24 24 25 import org.apache.log4j.Logger; 25 26 import org.greenstone.util.GlobalProperties; 26 27 import org.w3c.dom.Document; 27 28 import org.w3c.dom.Element; 29 import org.w3c.dom.NamedNodeMap; 28 30 import org.w3c.dom.Node; 29 31 import org.w3c.dom.NodeList; 30 31 import org.apache.log4j.*;32 32 33 33 /** various functions for manipulating Greenstone xslt */ … … 55 55 if (debug) 56 56 { 57 System.err.println("ADDING DEBUG ELEMENTS WITH FILE NAME " + firstDocFileName);58 57 insertDebugElements(main_xsl, firstDocFileName); 59 58 } … … 188 187 if (debug) 189 188 { 190 System.err.println("ADDING DEBUG ELEMENTS WITH FILE NAME " + secondDocFileName);191 189 insertDebugElements(main_xsl, secondDocFileName); 192 190 } 193 191 } 194 192 195 protected static void insertDebugElements(Document doc, String fileName) 196 { 197 NodeList htmlTags = GSXML.getHTMLStructureElements(doc); 198 System.err.println("HTML TAGS SIZE IS " + htmlTags.getLength()); 199 for (int i = 0; i < htmlTags.getLength(); i++) 200 { 201 Element current = (Element) htmlTags.item(i); 202 if (current.getUserData("GSDEBUGFILENAME") == null) 203 { 204 Element xslParent = (Element) current.getParentNode(); 205 206 while (xslParent.getNamespaceURI() != GSXML.XSL_NAMESPACE && !xslParent.getNodeName().startsWith("xsl:")) 207 { 208 xslParent = (Element) xslParent.getParentNode(); 209 } 210 211 System.err.println("ADDING FILE NAME " + fileName); 212 current.setUserData("GSDEBUGFILENAME", fileName, null); 213 current.setUserData("GSDEBUGXML", xslParent.cloneNode(true), null); 193 protected static void insertDebugElements(Document doc, String filename) 194 { 195 NodeList xslTemplates = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template"); 196 NodeList gsfTemplates = doc.getElementsByTagNameNS(GSXML.GSF_NAMESPACE, "template"); 197 198 for (int i = 0; i < xslTemplates.getLength() + gsfTemplates.getLength(); i++) 199 { 200 boolean gsf = (i >= xslTemplates.getLength()); 201 Element currentTemplate = (Element) (!gsf ? xslTemplates.item(i) : gsfTemplates.item(i - xslTemplates.getLength())); 202 203 NodeList childNodes = currentTemplate.getChildNodes(); 204 boolean debugInformationAlreadyExists = false; 205 for (int j = 0; j < childNodes.getLength(); j++) 206 { 207 Node current = childNodes.item(j); 208 if (current instanceof Element && ((Element) current).getNodeName().equals("debug") && (!((Element) current).getAttribute("nodename").startsWith("gsf:") || ((Element) current).getAttribute("nodename").equals("gsf:template"))) 209 { 210 debugInformationAlreadyExists = true; 211 break; 212 } 213 } 214 215 if (debugInformationAlreadyExists) 216 { 217 continue; 218 } 219 220 Element debugElement = doc.createElement("debug"); 221 debugElement.setAttribute("filename", filename); 222 debugElement.setAttribute("nodename", gsf ? "gsf:template" : "xsl:template"); 223 if (currentTemplate.getAttribute("match").length() > 0) 224 { 225 debugElement.setAttribute("match", currentTemplate.getAttribute("match")); 226 } 227 if (currentTemplate.getAttribute("name").length() > 0) 228 { 229 debugElement.setAttribute("name", currentTemplate.getAttribute("name")); 230 } 231 232 Element currentDebugElement = (Element) debugElement.cloneNode(true); 233 234 if (childNodes.getLength() > 0) 235 { 236 int paramCount = 0; 237 while (childNodes.getLength() > paramCount) 238 { 239 Node currentNode = childNodes.item(paramCount); 240 if (currentNode instanceof Element) 241 { 242 if (((Element) currentNode).getNodeName().equals("xsl:param") || ((Element) currentNode).getNodeName().equals("xslt:param") || (((Element) currentNode).getNodeName().equals("param") && ((Element) currentNode).getNamespaceURI().equals(GSXML.XSL_NAMESPACE))) 243 { 244 paramCount++; 245 } 246 else 247 { 248 currentDebugElement.appendChild(currentNode); 249 } 250 } 251 else 252 { 253 currentDebugElement.appendChild(currentNode); 254 } 255 } 256 currentTemplate.appendChild(currentDebugElement); 214 257 } 215 258 else 216 259 { 217 System.err.println("ALREADY SET!"); 218 } 260 currentTemplate.appendChild(currentDebugElement); 261 } 262 263 Element textElement = doc.createElementNS(GSXML.XSL_NAMESPACE, "text"); 264 textElement.appendChild(doc.createTextNode(" ")); 265 currentDebugElement.appendChild(textElement); 219 266 } 220 267 } … … 227 274 public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, boolean debug, String docFileName, String site, String collection, String interface_name, ArrayList<String> base_interfaces) 228 275 { 229 XMLConverter converter = new XMLConverter();230 231 276 String path = (pathExtra == null) ? "" : pathExtra; 232 277 … … 238 283 Element current = (Element) ((i < importList.getLength()) ? importList.item(i) : includeList.item(i - importList.getLength())); 239 284 String href = current.getAttribute("href"); 240 //String filePath = GSFile.interfaceHome(GlobalProperties.getGSDL3Home(), interface_name) + File.separator + "transform" + File.separator + path.replace("/", File.separator) + href.replace("/", File.separator);241 //String filePath = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), site_name, collection, interface_name, base_interfaces,242 285 243 286 try … … 254 297 //Do this recursively 255 298 inlineImportAndIncludeFilesDebug(inlineDoc, newPath, debug, "merged " + href/* filePath */, site, collection, interface_name, base_interfaces); 256 257 299 GSXSLT.mergeStylesheetsDebug(doc, inlineDoc.getDocumentElement(), false, debug, docFileName, /* filePath */"merged " + href); 258 300 } … … 312 354 } 313 355 356 if (stylesheets.size() == 1 && debug) 357 { 358 insertDebugElements(finalDoc, stylesheets.get(0).getAbsolutePath()); 359 } 360 314 361 return finalDoc; 315 362 } 316 363 317 public static void modifyConfigFormatForDebug(Document doc, String file Name)364 public static void modifyConfigFormatForDebug(Document doc, String filename) 318 365 { 319 366 NodeList templateNodes = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template"); … … 323 370 } 324 371 325 String debugElementString = ""; 326 debugElementString += "<span class=\"configDebugSpan\" style=\"display:none;\">"; 327 debugElementString += " \"filename\":\"" + fileName + "\","; 328 debugElementString += " \"xml\":\"<xsl:value-of select=\"util:xmlNodeToString(.)\"/>\""; //<xsl:copy><xsl:copy-of select=\"@*\"/></xsl:copy> 329 debugElementString += "</span>"; 330 331 XMLConverter converter = new XMLConverter(); 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(); 372 Element debugElement = doc.createElement("debug"); 373 debugElement.setAttribute("filename", filename); 333 374 334 375 for (int i = 0; i < templateNodes.getLength(); i++) 335 376 { 336 377 Element currentTemplate = (Element) templateNodes.item(i); 337 if (currentTemplate.getAttribute("match") != null && (currentTemplate.getAttribute("match").equals("gsf:metadata") || currentTemplate.getAttribute("match").equals("*") || currentTemplate.getAttribute("match").equals("format")))378 if (currentTemplate.getAttribute("match").equals("*") || currentTemplate.getAttribute("match").equals("format")) 338 379 { 339 380 continue; 340 381 } 341 382 383 Element currentDebugElement = (Element) debugElement.cloneNode(true); 384 385 //The xsl that gets the name of current node (e.g. gsf:icon) 386 Element nodeNameAttribute = doc.createElementNS(GSXML.XSL_NAMESPACE, "attribute"); 387 nodeNameAttribute.setAttribute(GSXML.NAME_ATT, "nodeName"); 388 Element nodeNameValue = doc.createElementNS(GSXML.XSL_NAMESPACE, "value-of"); 389 nodeNameValue.setAttribute("select", "name()"); 390 nodeNameAttribute.appendChild(nodeNameValue); 391 currentDebugElement.appendChild(nodeNameAttribute); 392 393 //The xsl that copies the attributes of the current node 394 Element attributeCopy = doc.createElementNS(GSXML.XSL_NAMESPACE, "copy-of"); 395 attributeCopy.setAttribute("select", "@*"); 396 currentDebugElement.appendChild(attributeCopy); 397 342 398 if (currentTemplate.hasChildNodes()) 343 399 { 344 currentTemplate.insertBefore(doc.importNode(debugElement.cloneNode(true), true), currentTemplate.getFirstChild()); 400 NodeList childNodes = currentTemplate.getChildNodes(); 401 while (childNodes.getLength() > 0) 402 { 403 currentDebugElement.appendChild(childNodes.item(0)); 404 } 405 currentTemplate.appendChild(currentDebugElement); 345 406 } 346 407 else 347 408 { 348 currentTemplate.appendChild( doc.importNode(debugElement.cloneNode(true), true));409 currentTemplate.appendChild(currentDebugElement); 349 410 } 350 411 } … … 485 546 } 486 547 } 548 549 public static void fixTables(Document doc) 550 { 551 NodeList debugElements = doc.getElementsByTagName("debug"); 552 for (int i = 0; i < debugElements.getLength(); i++) 553 { 554 Element currentElement = (Element) debugElements.item(i); 555 556 boolean hasChildElements = false; 557 NodeList children = currentElement.getChildNodes(); 558 for (int j = 0; j < children.getLength(); j++) 559 { 560 Node current = children.item(j); 561 if (current instanceof Element) 562 { 563 hasChildElements = true; 564 } 565 } 566 567 if (hasChildElements && currentElement.getParentNode() != null && currentElement.getParentNode() instanceof Element) 568 { 569 Element parent = (Element) currentElement.getParentNode(); 570 if (parent.getNodeName().toLowerCase().equals("table") || parent.getNodeName().toLowerCase().equals("tr")) 571 { 572 parent.setAttribute("debug", "true"); 573 NamedNodeMap attributes = currentElement.getAttributes(); 574 for (int j = 0; j < attributes.getLength(); j++) 575 { 576 Node currentAttribute = attributes.item(j); 577 String name = currentAttribute.getNodeName(); 578 String value = currentAttribute.getNodeValue(); 579 parent.setAttribute(name, value); 580 } 581 } 582 } 583 } 584 } 487 585 }
Note:
See TracChangeset
for help on using the changeset viewer.