Changeset 26558
- Timestamp:
- 2012-12-05T15:15:50+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java
r26472 r26558 21 21 import java.io.File; 22 22 import java.util.ArrayList; 23 import java.util.HashMap; 23 24 import java.util.Vector; 24 25 … … 204 205 } 205 206 206 p rotectedstatic void insertDebugElements(Document doc, String filename)207 public static void insertDebugElements(Document doc, String filename) 207 208 { 208 209 NodeList xslTemplates = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template"); … … 234 235 debugElement.setAttribute("filename", filename); 235 236 debugElement.setAttribute("nodename", gsf ? "gsf:template" : "xsl:template"); 237 236 238 if (currentTemplate.getAttribute("match").length() > 0) 237 239 { … … 242 244 debugElement.setAttribute("name", currentTemplate.getAttribute("name")); 243 245 } 244 245 Element currentDebugElement = (Element) debugElement.cloneNode(true);246 246 247 247 if (childNodes.getLength() > 0) … … 259 259 else 260 260 { 261 currentDebugElement.appendChild(currentNode);261 debugElement.appendChild(currentNode); 262 262 } 263 263 } 264 264 else 265 265 { 266 currentDebugElement.appendChild(currentNode);266 debugElement.appendChild(currentNode); 267 267 } 268 268 } 269 currentTemplate.appendChild( currentDebugElement);269 currentTemplate.appendChild(debugElement); 270 270 } 271 271 else 272 272 { 273 currentTemplate.appendChild( currentDebugElement);273 currentTemplate.appendChild(debugElement); 274 274 } 275 275 276 276 Element textElement = doc.createElementNS(GSXML.XSL_NAMESPACE, "text"); 277 277 textElement.appendChild(doc.createTextNode(" ")); 278 currentDebugElement.appendChild(textElement);278 debugElement.appendChild(textElement); 279 279 } 280 280 } … … 373 373 374 374 return finalDoc; 375 }376 377 public static void modifyConfigFormatForDebug(Document doc, String filename)378 {379 NodeList templateNodes = doc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template");380 if (templateNodes.getLength() == 0)381 {382 templateNodes = doc.getElementsByTagName("xsl:template");383 }384 385 Element debugElement = doc.createElement("debug");386 debugElement.setAttribute("filename", filename);387 388 for (int i = 0; i < templateNodes.getLength(); i++)389 {390 Element currentTemplate = (Element) templateNodes.item(i);391 if (currentTemplate.getAttribute("match").equals("*") || currentTemplate.getAttribute("match").equals("format"))392 {393 continue;394 }395 396 Element currentDebugElement = (Element) debugElement.cloneNode(true);397 398 //The xsl that gets the name of current node (e.g. gsf:icon)399 Element nodeNameAttribute = doc.createElementNS(GSXML.XSL_NAMESPACE, "attribute");400 nodeNameAttribute.setAttribute(GSXML.NAME_ATT, "nodeName");401 Element nodeNameValue = doc.createElementNS(GSXML.XSL_NAMESPACE, "value-of");402 nodeNameValue.setAttribute("select", "name()");403 nodeNameAttribute.appendChild(nodeNameValue);404 currentDebugElement.appendChild(nodeNameAttribute);405 406 //The xsl that copies the attributes of the current node407 Element attributeCopy = doc.createElementNS(GSXML.XSL_NAMESPACE, "copy-of");408 attributeCopy.setAttribute("select", "@*");409 currentDebugElement.appendChild(attributeCopy);410 411 if (currentTemplate.hasChildNodes())412 {413 NodeList childNodes = currentTemplate.getChildNodes();414 while (childNodes.getLength() > 0)415 {416 currentDebugElement.appendChild(childNodes.item(0));417 }418 currentTemplate.appendChild(currentDebugElement);419 }420 else421 {422 currentTemplate.appendChild(currentDebugElement);423 }424 }425 375 } 426 376 … … 563 513 { 564 514 NodeList debugElements = doc.getElementsByTagName("debug"); 515 516 HashMap<Element, ArrayList<Element>> tracker = new HashMap<Element, ArrayList<Element>>(); 565 517 for (int i = 0; i < debugElements.getLength(); i++) 566 518 { … … 580 532 if (hasChildElements && currentElement.getParentNode() != null && currentElement.getParentNode() instanceof Element) 581 533 { 582 Element parent = (Element) currentElement.getParentNode(); 534 Element parent = findNonDebugParent(currentElement); 535 if (parent == null) 536 { 537 continue; 538 } 539 583 540 if (parent.getNodeName().toLowerCase().equals("table") || parent.getNodeName().toLowerCase().equals("tr")) 584 541 { 585 parent.setAttribute("debug", "true"); 586 NamedNodeMap attributes = currentElement.getAttributes(); 587 for (int j = 0; j < attributes.getLength(); j++) 542 if (tracker.get(parent) == null) 588 543 { 589 Node currentAttribute = attributes.item(j); 590 String name = currentAttribute.getNodeName(); 591 String value = currentAttribute.getNodeValue(); 592 parent.setAttribute(name, value); 544 ArrayList<Element> debugElems = new ArrayList<Element>(); 545 debugElems.add(currentElement); 546 tracker.put(parent, debugElems); 593 547 } 594 } 595 } 596 } 548 else 549 { 550 ArrayList<Element> debugElems = tracker.get(parent); 551 debugElems.add(currentElement); 552 } 553 } 554 } 555 } 556 557 for (Element tableElem : tracker.keySet()) 558 { 559 ArrayList<Element> debugElems = tracker.get(tableElem); 560 ArrayList<String> attrNames = new ArrayList<String>(); 561 562 for (Element debugElem : debugElems) 563 { 564 NamedNodeMap attributes = debugElem.getAttributes(); 565 for (int i = 0; i < attributes.getLength(); i++) 566 { 567 attrNames.add(attributes.item(i).getNodeName()); 568 } 569 } 570 571 for (String name : attrNames) 572 { 573 String attrValueString = "["; 574 for (int i = debugElems.size() - 1; i >= 0; i--) 575 { 576 Element current = debugElems.get(i); 577 attrValueString += "\'" + current.getAttribute(name).replace("\\", "\\\\").replace("'", "\\'") + "\'"; 578 if (i != 0) 579 { 580 attrValueString += ","; 581 } 582 } 583 attrValueString += "]"; 584 585 tableElem.setAttribute(name, attrValueString); 586 } 587 tableElem.setAttribute("debug", "true"); 588 tableElem.setAttribute("debugSize", "" + debugElems.size()); 589 } 590 } 591 592 private static Element findNonDebugParent(Element elem) 593 { 594 Node parent = elem.getParentNode(); 595 while (parent instanceof Element && parent.getNodeName().equals("debug")) 596 { 597 parent = parent.getParentNode(); 598 } 599 600 if (parent instanceof Element) 601 { 602 return (Element) parent; 603 } 604 return null; 597 605 } 598 606 }
Note:
See TracChangeset
for help on using the changeset viewer.