1 package org.jahia.clipbuilder.html.util; 2 3 import org.jdom.*; 4 import org.jdom.output.*; 5 import org.jdom.xpath.*; 6 7 import java.util.*; 8 9 14 public abstract class JDomUtilities { 15 private static org.apache.log4j.Logger logger = 16 org.apache.log4j.Logger.getLogger(JDomUtilities.class); 17 18 19 22 public JDomUtilities() { 23 } 24 25 26 33 public static boolean isSibling(Element first, Element second) { 34 boolean result = false; 35 Parent parentFirst = first.getParent(); 37 Parent parentSecond = second.getParent(); 38 if (parentFirst.equals(parentSecond)) { 39 logger.debug("[ " + first.getName() + " and " + second.getName() + 40 " are sibling]"); 41 logger.debug("[Parent is " + first.getParentElement().getName() + "]"); 42 result = true; 43 } 44 else { 45 logger.debug("[ " + first.getName() + " and " + second.getName() + 46 " are not sibling]"); 47 logger.debug("[Parent first is " + first.getParentElement().getName() + 48 "]"); 49 logger.debug("[Parent second is " + second.getParentElement().getName() + 50 "]"); 51 52 result = false; 53 } 54 return result; 55 } 56 57 58 64 public static String getDocumentAsString(Document doc) { 65 String res = "<p> Error !!! </p>"; 66 XMLOutputter serializer = new XMLOutputter(); 67 serializer.setFormat(org.jdom.output.Format.getPrettyFormat()); 68 res = serializer.outputString(doc); 69 logger.debug("[document from neko and jdom] " + doc); 70 return res; 72 } 73 74 75 81 public static Document getDocument(String xmlContent) { 82 org.jdom.input.DOMBuilder builder = new org.jdom.input.DOMBuilder(); 83 org.jdom.Document jdomDoc = builder.build(org.jahia.clipbuilder.html.util.DomUtilities.getDocument(xmlContent)); 84 return jdomDoc; 85 } 86 87 88 96 public static List getElementByXPath(Document doc, String xPath) throws JDOMException { 97 List result = null; 98 XPath x = XPath.newInstance(xPath); 99 result = null; 100 result = x.selectNodes(doc); 101 if (result.isEmpty()) { 102 logger.debug("Result set is empty for xpath = " + xPath); 103 } 104 else { 105 logger.debug("Result set is not empty for xpath = " + xPath); 106 } 107 return result; 108 } 109 110 } 111 | Popular Tags |