protected Node createText (Token token) { return new Text (token); }
@Override public void invoke (Node node) throws Exception { String text = ((Text)node).getText (); method.invoke (handler, text); } }
/** Get the contents of this text node without all whitespace before and after * and with all whitespace between the words in the node reduced to a single space. */ public String getNormalizedText () { return getTrimmedText ().replaceAll ("\\s+", " "); }
public boolean isCDATA () { return getType () == Type.CDATA; }
protected Node createCData (Token token) { return new Text (token); }
/** Get the contents of this text node without all whitespace before and after */ public String getTrimmedText () { return getText ().trim (); }
protected Node createElementWhitespace (Token token) { return new Text (token); }
/** True, if this text node contains only whitespace */ public boolean isWhitespace () { String s = getText (); for (int i=0; i<s.length (); i++) { if (!Character.isWhitespace (s.charAt (i))) return false; } return true; }
/** * Adds the given text to the given node */ public static Text addText(Element element, String text) { Text textNode = new Text(text + " "); element.addNode(textNode); return textNode; }
public String getText () { if (!hasNodes ()) return ""; StringBuilder buffer = new StringBuilder (); for (Node n: getNodes ()) { if (isText (n)) buffer.append (((Text)n).getText ()); else if (isElement (n)) buffer.append (((Element)n).getText ()); else if (n.getType () == Type.ENTITY) buffer.append (((Entity)n).getText ()); } return buffer.toString (); }
/** * Adds the given text to the given node */ public static Text addText(Element element, String text) { Text textNode = new Text(text + " "); element.addNode(textNode); return textNode; }
public Element setText (String text) { clearText (); addNode (0, new Text (text)); return this; }
/** * Creates a new child of the given element adding the text after the new node */ public static Element createChild(Element element, String name, String text) { if (text != null) { element.addNode(new Text(text + " ")); } Element child = new Element(name); element.addNode(child); if (text != null) { element.addNode(new Text(text)); } return child; }
/** * Creates a new child of the given element adding the text after the new node */ public static Element createChild(Element element, String name, String text) { if (text != null) { element.addNode(new Text(text + " ")); } Element child = new Element(name); element.addNode(child); if (text != null) { element.addNode(new Text(text)); } return child; }
protected XMLDeclaration createXMLDeclaration () { if (xmlDeclaration == null) { addNode (0, new XMLDeclaration ("1.0")); addNode (1, new Text ("\n")); } return xmlDeclaration; }
/** * Returns the first child with the given name, lazily creating one if required with the * given text prepended before the element if the text is not null */ public static Element getOrCreateChild(Element element, String name, String text) { Element child = firstChild(element, name); if (child == null) { if (text != null) { element.addNode(new Text(text + " ")); } child = new Element(name); element.addNode(child); if (text != null) { element.addNode(new Text(text + " ")); } } return child; }
/** * Returns the first child with the given name, lazily creating one if required with the * given text prepended before the element if the text is not null */ public static Element getOrCreateChild(Element element, String name, String text) { Element child = firstChild(element, name); if (child == null) { if (text != null) { element.addNode(new Text(text + " ")); } child = new Element(name); element.addNode(child); if (text != null) { element.addNode(new Text(text + " ")); } } return child; }