private static boolean isNotEmptyText (final Content c) { if ( ! (c instanceof Text)) return true; return ((Text)c).getTextTrim().length() > 0; }
/** * Returns the first piece of content that is not an empty (when trimmed) * Text instance. */ public static org.jdom.Content getFirstContent (final org.jdom.Element elt) { final java.util.Iterator it = elt.getContent().iterator(); while (it.hasNext()) { final org.jdom.Content c = (org.jdom.Content)it.next(); if (c instanceof org.jdom.Element) return c; if (c instanceof org.jdom.Text) { final String s = ((org.jdom.Text)c).getTextTrim(); if (s.length() > 0) return c; } // else continue } return null; }
private static org.jdom.Element cleanElement (final org.jdom.Element elt) { final org.jdom.Element result = new org.jdom.Element(elt.getName()); final java.util.Iterator it = elt.getContent().iterator(); while (it.hasNext()) { final org.jdom.Content c = (org.jdom.Content)it.next(); if (c instanceof org.jdom.Text) if (((org.jdom.Text)c).getTextTrim().length() < 1) continue; //log.debug("cleanElement() adding "+XmlUtils.xmlToString(c)); result.addContent((org.jdom.Content)c.clone()); } return result; }
private static Element removeFirstChild (final Element e) { final Content c = e.removeContent(0); if (c == null) return e; if (c instanceof Element) return e; if (c instanceof Text && ((Text)c).getTextTrim().length() > 0) return e; return removeFirstChild(e); }
public static Content car (final Content c) { if (log.isDebugEnabled()) log.debug("car() input is of class "+c.getClass().getName()); final Element elt = toElement(c); if (elt.getContent().size() < 1) throw new IllegalArgumentException("cannot car an empty element"); for (int i=0; i<elt.getContent().size(); i++) { final Content result = (Content)elt.getContent().get(i); if (log.isDebugEnabled()) log.debug("car() result is >"+result.toString()+"<"); if (result instanceof Text) { if (((Text)result).getTextTrim().length() < 1) continue; } if (log.isDebugEnabled()) log.debug("car() returning >"+XmlUtils.xmlToString(result)+"<"); return (Content)result.clone(); } return null; }
final String s = ((Text)c).getTextTrim();
if (lastText != null && lastText.getTextTrim().length() == 0) { lastText = (Text)lastText.clone(); } else {
if (lastText != null && lastText.getTextTrim().length() == 0) { lastText = (Text)lastText.clone(); } else {
/** * Turns a JDOM content instance into a String * (with the application encoding). */ public static String toString (final org.jdom.Content c) { if (c instanceof org.jdom.Text) return ((org.jdom.Text)c).getTextTrim(); org.jdom.Element elt = (org.jdom.Element)c; final boolean hasParent = (elt.getParent() != null); if (hasParent) elt = (org.jdom.Element)elt.clone(); final String result = toString(new org.jdom.Document(elt), null); if ( ! hasParent) elt.detach(); return result; }
@Override public Element findElementWithin(final Element rootElement, final Element element, final Element targetRootElement) throws JDOMException { final XPath xpath = XPath.newInstance("string/text()"); final Text entryIdText = (Text) xpath.selectSingleNode(element); if (entryIdText == null) { return null; } final String id = entryIdText.getTextTrim(); final String xPathString = "/maven2-moduleset/project-properties/entry/string[text()='" + id + "']"; final XPath xPath = XPath.newInstance(xPathString); final Object object = xPath.selectSingleNode(targetRootElement); if (object != null) { final Element parent = ((Element) object).getParentElement(); return parent; } return null; } };
if (previous instanceof Text) { Text txt = (Text)previous; if (txt.getTextTrim().length() == 0) { parent.removeContent(txt);
if (previous instanceof Text) { Text txt = (Text)previous; if (txt.getTextTrim().length() == 0) { parent.removeContent(txt);
if (previous instanceof Text) { Text txt = (Text)previous; if (txt.getTextTrim().length() == 0) { parent.removeContent(txt);
if (previous instanceof Text) { Text txt = (Text)previous; if (txt.getTextTrim().length() == 0) { parent.removeContent(txt);
if (previous instanceof Text) { Text txt = (Text)previous; if (txt.getTextTrim().length() == 0) { parent.removeContent(txt);
if (previous instanceof Text) { Text txt = (Text)previous; if (txt.getTextTrim().length() == 0) { parent.removeContent(txt);
if (previous instanceof Text) { Text txt = (Text)previous; if (txt.getTextTrim().length() == 0) { parent.removeContent(txt);
if ( txt.getTextTrim().length() == 0 )
if ( txt.getTextTrim().length() == 0 )
if (txt.getTextTrim().length() == 0)