Search in sources :

Example 1 with TextContent

use of org.apache.axiom.om.impl.intf.TextContent in project webservices-axiom by apache.

the class OMFactoryImpl method importChildNode.

private AxiomChildNode importChildNode(OMNode child) {
    int type = child.getType();
    switch(type) {
        case OMNode.ELEMENT_NODE:
            {
                OMElement element = (OMElement) child;
                AxiomElement importedElement = createNode(AxiomElement.class);
                copyName(element, importedElement);
                for (Iterator<OMAttribute> it = element.getAllAttributes(); it.hasNext(); ) {
                    importedElement.coreAppendAttribute(importAttribute(it.next()));
                }
                for (Iterator<OMNamespace> it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
                    OMNamespace ns = it.next();
                    AxiomNamespaceDeclaration nsDecl = createNode(AxiomNamespaceDeclaration.class);
                    nsDecl.coreSetDeclaredNamespace(ns.getPrefix(), ns.getNamespaceURI());
                    importedElement.coreAppendAttribute(nsDecl);
                }
                importChildren(element, importedElement);
                return importedElement;
            }
        case OMNode.TEXT_NODE:
        case OMNode.SPACE_NODE:
        case OMNode.CDATA_SECTION_NODE:
            {
                OMText text = (OMText) child;
                Object content;
                if (text.isBinary()) {
                    content = new TextContent(text.getContentID(), text.getDataHandler(), text.isOptimized());
                } else {
                    content = text.getText();
                }
                return createAxiomText(null, content, type);
            }
        case OMNode.PI_NODE:
            {
                OMProcessingInstruction pi = (OMProcessingInstruction) child;
                AxiomProcessingInstruction importedPI = createNode(AxiomProcessingInstruction.class);
                importedPI.setTarget(pi.getTarget());
                importedPI.setValue(pi.getValue());
                return importedPI;
            }
        case OMNode.COMMENT_NODE:
            {
                OMComment comment = (OMComment) child;
                AxiomComment importedComment = createNode(AxiomComment.class);
                importedComment.setValue(comment.getValue());
                return importedComment;
            }
        case OMNode.DTD_NODE:
            {
                OMDocType docType = (OMDocType) child;
                AxiomDocType importedDocType = createNode(AxiomDocType.class);
                importedDocType.coreSetRootName(docType.getRootName());
                importedDocType.coreSetPublicId(docType.getPublicId());
                importedDocType.coreSetSystemId(docType.getSystemId());
                importedDocType.coreSetInternalSubset(docType.getInternalSubset());
                return importedDocType;
            }
        case OMNode.ENTITY_REFERENCE_NODE:
            AxiomEntityReference importedEntityRef = createNode(AxiomEntityReference.class);
            importedEntityRef.coreSetName(((OMEntityReference) child).getName());
            return importedEntityRef;
        default:
            throw new IllegalArgumentException("Unsupported node type");
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) AxiomDocType(org.apache.axiom.om.impl.intf.AxiomDocType) AxiomProcessingInstruction(org.apache.axiom.om.impl.intf.AxiomProcessingInstruction) AxiomEntityReference(org.apache.axiom.om.impl.intf.AxiomEntityReference) OMElement(org.apache.axiom.om.OMElement) AxiomNamespaceDeclaration(org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMDocType(org.apache.axiom.om.OMDocType) OMComment(org.apache.axiom.om.OMComment) AxiomComment(org.apache.axiom.om.impl.intf.AxiomComment) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) TextContent(org.apache.axiom.om.impl.intf.TextContent)

Example 2 with TextContent

use of org.apache.axiom.om.impl.intf.TextContent in project webservices-axiom by apache.

the class StAXPullReader method processText.

private void processText(int textType) throws StreamException {
    if (textType == XMLStreamConstants.CHARACTERS && dataHandlerReader != null && dataHandlerReader.isBinary()) {
        TextContent data;
        if (dataHandlerReader.isDeferred()) {
            data = new TextContent(dataHandlerReader.getContentID(), dataHandlerReader.getDataHandlerProvider(), dataHandlerReader.isOptimized());
        } else {
            try {
                data = new TextContent(dataHandlerReader.getContentID(), dataHandlerReader.getDataHandler(), dataHandlerReader.isOptimized());
            } catch (XMLStreamException ex) {
                throw new OMException(ex);
            }
        }
        handler.processCharacterData(data, false);
    } else {
        // Some parsers (like Woodstox) parse text nodes lazily and may throw a
        // RuntimeException in getText()
        String text;
        try {
            text = parser.getText();
        } catch (RuntimeException ex) {
            parserException = ex;
            throw ex;
        }
        switch(textType) {
            case XMLStreamConstants.CHARACTERS:
                handler.processCharacterData(text, false);
                break;
            case XMLStreamConstants.SPACE:
                handler.processCharacterData(text, true);
                break;
            case XMLStreamConstants.CDATA:
                handler.startCDATASection();
                handler.processCharacterData(text, false);
                handler.endCDATASection();
                break;
            default:
                throw new IllegalStateException();
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) TextContent(org.apache.axiom.om.impl.intf.TextContent) OMException(org.apache.axiom.om.OMException)

Example 3 with TextContent

use of org.apache.axiom.om.impl.intf.TextContent in project webservices-axiom by apache.

the class XOPEncodingFilterHandler method processCharacterData.

@Override
protected String processCharacterData(Object data) throws StreamException {
    if (data instanceof TextContent) {
        TextContent textContent = (TextContent) data;
        if (textContent.isBinary()) {
            Object dataHandlerObject = textContent.getDataHandlerObject();
            boolean optimize;
            try {
                if (dataHandlerObject instanceof DataHandlerProvider) {
                    optimize = optimizationPolicy.isOptimized((DataHandlerProvider) dataHandlerObject, textContent.isOptimize());
                } else {
                    optimize = optimizationPolicy.isOptimized((DataHandler) dataHandlerObject, textContent.isOptimize());
                }
            } catch (IOException ex) {
                throw new StreamException(ex);
            }
            if (optimize) {
                String contentID = contentIDGenerator.generateContentID(textContent.getContentID());
                dataHandlerObjects.put(contentID, dataHandlerObject);
                return contentID;
            }
        }
    }
    return null;
}
Also used : DataHandlerProvider(org.apache.axiom.ext.stax.datahandler.DataHandlerProvider) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) TextContent(org.apache.axiom.om.impl.intf.TextContent) StreamException(org.apache.axiom.core.stream.StreamException)

Aggregations

TextContent (org.apache.axiom.om.impl.intf.TextContent)3 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 DataHandler (javax.activation.DataHandler)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 StreamException (org.apache.axiom.core.stream.StreamException)1 DataHandlerProvider (org.apache.axiom.ext.stax.datahandler.DataHandlerProvider)1 OMComment (org.apache.axiom.om.OMComment)1 OMDocType (org.apache.axiom.om.OMDocType)1 OMElement (org.apache.axiom.om.OMElement)1 OMException (org.apache.axiom.om.OMException)1 OMNamespace (org.apache.axiom.om.OMNamespace)1 OMProcessingInstruction (org.apache.axiom.om.OMProcessingInstruction)1 OMText (org.apache.axiom.om.OMText)1 AxiomComment (org.apache.axiom.om.impl.intf.AxiomComment)1 AxiomDocType (org.apache.axiom.om.impl.intf.AxiomDocType)1 AxiomElement (org.apache.axiom.om.impl.intf.AxiomElement)1 AxiomEntityReference (org.apache.axiom.om.impl.intf.AxiomEntityReference)1 AxiomNamespaceDeclaration (org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration)1 AxiomProcessingInstruction (org.apache.axiom.om.impl.intf.AxiomProcessingInstruction)1