public String getTrimmedText() { String childText = null; OMNode child = this.getFirstOMChild(); OMText textNode; while (child != null) { if (child.getType() == OMNode.TEXT_NODE) { textNode = (OMText) child; String textValue = textNode.getText(); if (textValue != null && !"".equals(textValue.trim())) { if (childText == null) childText = ""; childText += textValue.trim(); } } child = child.getNextOMSibling(); } return childText; }
/** * Returns the first Element node. * * @see org.apache.axiom.om.OMElement#getFirstElement() */ public OMElement getFirstElement() { OMNode node = getFirstOMChild(); while (node != null) { if (node.getType() == Node.ELEMENT_NODE) { return (OMElement) node; } else { node = node.getNextOMSibling(); } } return null; }
/** * Gets all the text children and concatinates them to a single string. * * @see org.apache.axiom.om.OMElement#getText() */ public String getText() { String childText = ""; OMNode child = this.getFirstOMChild(); OMText textNode; while (child != null) { final int type = child.getType(); if (type == OMNode.TEXT_NODE || type == OMNode.CDATA_SECTION_NODE) { textNode = (OMText) child; if (textNode.getText() != null && !"".equals(textNode.getText())) { childText += textNode.getText(); } } child = child.getNextOMSibling(); } return childText; }
/** * Creates a text node with the given value and adds it to the element. * * @see org.apache.axiom.om.OMElement#setText(String) */ public void setText(String text) { if (this.isReadonly()) { String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); } // if we already have other text nodes remove them OMNode child = this.getFirstOMChild(); while (child != null) { if (child.getType() == OMNode.TEXT_NODE) { child.detach(); } child = child.getNextOMSibling(); } TextImpl textNode = (TextImpl) (this.ownerNode) .createTextNode(text); this.addChild(textNode); }