protected OMNode getNextNode(OMNode currentNode) { return currentNode.getNextOMSibling(); } }
OMNode child = omElement.getFirstOMChild(); while ( child != null ) { if ( child instanceof OMText ) { // process 'child' text here final OMNode nextSibling = child.getNextOMSibling(); child.detach(); // detach from OM to keep memory usage low child = nextSibling; } }
@Override public boolean isTextOnly(OMElement element) throws XML2JavaMapperException { OMNode firstChild = element.getFirstOMChild(); return firstChild instanceof OMText && firstChild.getNextOMSibling() == null; }
OMElement getNextOMElementSibling(OMElement ele) { OMNode n = null; for (n = ele.getNextOMSibling(); n != null && !(n instanceof OMElement); n = n.getNextOMSibling()) ; return (OMElement) n; }
OMElement findPeerWithName(OMElement ele, String name) { if (name == null) return null; OMNode focus = ele; while (focus != null) { if ((focus instanceof OMElement)) { OMElement focusEle = (OMElement) focus; if (focusEle.getLocalName().equals(name)) return focusEle; } focus = focus.getNextOMSibling(); } return null; }
public Node getNextSibling() { if (next == null) { if (node.getParent() instanceof OMDocument) { OMNode n = node.getNextOMSibling(); do { if (!(n instanceof OMText)) { next = fac.getNode(n); break; } n = n.getNextOMSibling(); } while (true); } else { next = fac.getNode(node.getNextOMSibling()); } } return next; }
public <T extends Element> T getNextSibling() { OMNode el = this.getNextOMSibling(); while (el != null) { if (el instanceof Element) return (T)getWrapped((Element)el); else el = el.getNextOMSibling(); } return null; }
public Node getFirstChild() { // an XML Document node should not give Text nodes as children. OMNode n = doc.getFirstOMChild(); do { if (!(n instanceof OMText)){ return fac.getNode(n); } n = n.getNextOMSibling(); } while (true); }
/** * @param node * @return next sibling or null */ private OMNode getNextSibling(OMNode node) { if (isOMSourcedElement(node)) { return node.getNextOMSibling(); } else { return ((OMNodeEx) node).getNextOMSiblingIfAvailable(); } }
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; }
public boolean hasNext() { if (!advance) { return current != null; } advance = false; OMNode sibling = current.getNextOMSibling(); while (sibling != null) { if (sibling instanceof SOAPHeaderBlock) { SOAPHeaderBlock possible = (SOAPHeaderBlock) sibling; if (checkHeader(possible)) { current = (SOAPHeaderBlock) sibling; return true; } } sibling = sibling.getNextOMSibling(); } current = null; return false; }
public final void hasNumberOfChildren(int expected) { OMNode child = getSubject().getFirstOMChild(); int actual = 0; while (child != null) { actual++; child = child.getNextOMSibling(); } if (actual != expected) { failWithRawMessage("number of children is %s instead of %s", actual, expected); } } }
/** * @param node * @return first child or null */ private OMNode _getFirstChild(OMContainer node) { if (isOMSourcedElement(node)) { OMNode first = node.getFirstOMChild(); OMNode sibling = first; while (sibling != null) { sibling = sibling.getNextOMSibling(); } return first; } else { return ((IContainer)node).getFirstOMChildIfAvailable(); } }
public void set(OMElement root) { String localname = root.getLocalName(); if (requiresHome(localname)) root.addAttribute("home", home, null); for (OMNode child=root.getFirstElement(); child != null; child=child.getNextOMSibling()) { if (child instanceof OMElement) { OMElement child_e = (OMElement) child; set(child_e); } // OMElement child_e = (OMElement) child; // set(child_e); } }
public void setText(String text) { complete(); if (text != null) { OMNode child = this.getFirstOMChild(); while (child != null) { if (child.getType() == OMNode.TEXT_NODE) { child.detach(); } child = child.getNextOMSibling(); } getOMFactory().createOMText(this, text); } else _removeAllChildren(); // return (T)this; }
public <T extends Element> T setText(Text.Type type, String value) { complete(); init(type); if (value != null) { OMNode child = this.getFirstOMChild(); while (child != null) { if (child.getType() == OMNode.TEXT_NODE) { child.detach(); } child = child.getNextOMSibling(); } getOMFactory().createOMText(this, value); } else _removeAllChildren(); return (T)this; }
public <T extends Element> T setText(Content.Type type, String value) { complete(); init(type); if (value != null) { OMNode child = this.getFirstOMChild(); while (child != null) { if (child.getType() == OMNode.TEXT_NODE) { child.detach(); } child = child.getNextOMSibling(); } getOMFactory().createOMText(this, value); } else _removeAllChildren(); return (T)this; }
public void testSynapse242() throws Exception { // create a new switch mediator XSLTMediator transformMediator = new XSLTMediator(); // set XSLT transformation URL setXsltTransformationURL(transformMediator, "xslt-key"); // invoke transformation, with static enveope MessageContext synCtx = new TestMessageContextBuilder().addFileEntry("xslt-key", "../../repository/conf/sample/resources/transform/transform_load_2.xml") .setBodyFromFile("../../repository/conf/sample/resources/transform/med_message.xml") .addTextAroundBody().setRequireAxis2MessageContext(true).build(); transformMediator.mediate(synCtx); // validate result OMContainer body = synCtx.getEnvelope().getBody(); assertTrue(body.getFirstOMChild().getNextOMSibling() instanceof OMElement); assertTrue(((OMElement) body.getFirstOMChild().getNextOMSibling()).getText().length() > 0); }
public void testTransformXSLTCustomSource() throws Exception { // create a new XSLT mediator XSLTMediator transformMediator = new XSLTMediator(); // set xpath condition to select source SynapseXPath xpath = new SynapseXPath("//m0:CheckPriceRequest"); xpath.addNamespace("m0", "http://services.samples/xsd"); transformMediator.setSource(xpath); // set XSLT transformation URL setXsltTransformationURL(transformMediator, "xslt-key"); MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry ("xslt-key", "../../repository/conf/sample/resources/transform/transform_unittest.xslt") .setBodyFromString(SOURCE).addTextAroundBody().build(); transformMediator.mediate(synCtx); // validate result assertQuoteElement(synCtx.getEnvelope().getBody().getFirstOMChild().getNextOMSibling()); }