Package org.apache.axiom.om

Examples of org.apache.axiom.om.OMDocument


     */
    public void outputTo(XMLStreamWriter writer) throws XMLStreamException {
        // Using OM to convert the reader to a writer.  This seems to be
        // the safest way to make the conversion, and it promotes code re-use.
        StAXOMBuilder builder = new StAXOMBuilder(reader);
        OMDocument omDocument = builder.getDocument();
        Iterator it = omDocument.getChildren();
        while (it.hasNext()) {
            OMNode omNode = (OMNode)it.next();
            // TODO Using serialize and consume
            // caused an axiom bug...falling back to serialize
            // (which is less performant due to om caching)
View Full Code Here


        // Please change this code if an easier mechanism is discovered.

        OMXMLParserWrapper builder = e.getBuilder();
        if (builder instanceof StAXBuilder) {
            StAXBuilder staxBuilder = (StAXBuilder)builder;
            OMDocument document = staxBuilder.getDocument();
            if (document != null) {
                OMFactory factory = document.getOMFactory();
                if (factory instanceof SOAPFactory) {
                    return (SOAPFactory)factory;
                }
            }
        }
View Full Code Here

            XMLStreamWriter w = StAXUtils.createXMLStreamWriter(out);
            XMLStreamWriter pw = new PrettyStreamWriter(w);
            OMElement om = (base instanceof Document) ? getOMElement(((Document)base).getRoot()) : (OMElement)base;
            String charset = options.getCharset();
            if (om.getParent() != null && om.getParent() instanceof OMDocument) {
                OMDocument doc = (OMDocument)om.getParent();
                pw.writeStartDocument(charset != null ? charset : doc.getCharsetEncoding(), doc.getXMLVersion());
            }
            om.serialize(pw);
            pw.writeEndDocument();
            if (options.getAutoClose())
                out.close();
View Full Code Here

        return this;
    }

    public Object clone() {
        Document<T> doc = ((FOMFactory)factory).newDocument();
        OMDocument omdoc = (OMDocument)doc;
        for (Iterator i = getChildren(); i.hasNext();) {
            OMNode node = (OMNode)i.next();
            switch (node.getType()) {
                case OMNode.COMMENT_NODE:
                    OMComment comment = (OMComment)node;
                    factory.createOMComment(omdoc, comment.getValue());
                    break;
                // TODO: Decide what to do with this code; it will no longer work in Axiom 1.2.14 (because of AXIOM-437).
                //       On the other hand, since we filter out DTDs, this code is never triggered.
//                case OMNode.DTD_NODE:
//                    OMDocType doctype = (OMDocType)node;
//                    factory.createOMDocType(omdoc, doctype.getValue());
//                    break;
                case OMNode.ELEMENT_NODE:
                    Element el = (Element)node;
                    omdoc.addChild((OMNode)el.clone());
                    break;
                case OMNode.PI_NODE:
                    OMProcessingInstruction pi = (OMProcessingInstruction)node;
                    factory.createOMProcessingInstruction(omdoc, pi.getTarget(), pi.getValue());
                    break;
View Full Code Here

      OMElement om = (base instanceof Document) ?
        getOMElement(((Document)base).getRoot()) :
        (OMElement)base;
      String charset = options.getCharset();
      if (om.getParent() != null && om.getParent() instanceof OMDocument) {
        OMDocument doc = (OMDocument) om.getParent();
        pw.writeStartDocument(
          charset != null ? charset :
            doc.getCharsetEncoding(), doc.getXMLVersion());
      }
      om.serialize(pw);
      pw.writeEndDocument();
      if (options.getAutoClose()) out.close();
    } catch (XMLStreamException e) {
View Full Code Here

    return this;
  }
 
  public Object clone() {
    Document<T> doc = ((FOMFactory)factory).newDocument();
    OMDocument omdoc = (OMDocument) doc;
    for (Iterator i = getChildren(); i.hasNext();) {
      OMNode node = (OMNode) i.next();
      switch(node.getType()) {
        case OMNode.COMMENT_NODE:
          OMComment comment = (OMComment) node;
          factory.createOMComment(omdoc, comment.getValue());
          break;
        case OMNode.DTD_NODE:
          OMDocType doctype = (OMDocType) node;
          factory.createOMDocType(omdoc, doctype.getValue());
          break;
        case OMNode.ELEMENT_NODE:
          Element el = (Element) node;
          omdoc.addChild((OMNode) el.clone());
          break;
        case OMNode.PI_NODE:
          OMProcessingInstruction pi = (OMProcessingInstruction) node;
          factory.createOMProcessingInstruction(omdoc, pi.getTarget(), pi.getValue());
          break;
View Full Code Here

        super(metaFactory);
    }

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMDocument document = factory.createOMDocument();
        OMElement documentElement = factory.createOMElement("root", null, document);
        assertSame(documentElement, document.getOMDocumentElement());
        documentElement.detach();
        assertNull(document.getOMDocumentElement());
    }
View Full Code Here

        super(metaFactory);
    }

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory,
                new StringReader("<!--comment1--><root/><!--comment2-->")).getDocument();
        OMElement documentElement = factory.createOMElement("new", null);
        document.setOMDocumentElement(documentElement);
        assertSame(documentElement, document.getOMDocumentElement());
        Iterator it = document.getChildren();
        assertTrue(it.hasNext());
        OMNode child = (OMNode)it.next();
        assertTrue(child instanceof OMComment);
        assertEquals("comment1", ((OMComment)child).getValue());
        assertTrue(it.hasNext());
View Full Code Here

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMElement incompleteElement = OMXMLBuilderFactory.createOMBuilder(factory,
                new StringReader("<elem>text</elem>")).getDocumentElement(true);
        OMDocument document = factory.createOMDocument();
        OMElement root = factory.createOMElement("root", null, document);
        root.addChild(incompleteElement);
        StringWriter out = new StringWriter();
        document.serializeAndConsume(out);
        XMLAssert.assertXMLEqual("<root><elem>text</elem></root>", out.toString());
        assertConsumed(incompleteElement);
    }
View Full Code Here

        super(metaFactory);
    }

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMDocument parent = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!--a--><b/><!--c-->")).getDocument();
        parent.addChild(factory.createOMComment(null, "d"));
        Iterator it = parent.getChildren();
        assertEquals("a", ((OMComment)it.next()).getValue());
        assertEquals("b", ((OMElement)it.next()).getLocalName());
        assertEquals("c", ((OMComment)it.next()).getValue());
        assertEquals("d", ((OMComment)it.next()).getValue());
        assertFalse(it.hasNext());
View Full Code Here

TOP

Related Classes of org.apache.axiom.om.OMDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.