public OMElement convert(XMLStreamReader s) { return OMXMLBuilderFactory .createStAXOMBuilder(OMAbstractFactory.getOMFactory(), s) .getDocumentElement(); }
/** * Parse input stream to get document. * @param in input stream * @return the document */ public static OMDocument getDocument(InputStream in) { // create the builder OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(in); // get the root element OMDocument doc = builder.getDocument(); return doc; } /**
/** * Converts a given inputstream to an OMNode * The reurned OMNode is fully built if buildAll is true. * If buildAll is false, the caller is responsible for closing the parser. * * @param inputStream * @param buildAll * @return OMNode * @throws javax.xml.stream.XMLStreamException * */ public static OMNode toOM(InputStream inputStream, boolean buildAll) throws XMLStreamException { OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(inputStream); OMNode omNode = builder.getDocumentElement(); if (buildAll) { omNode.build(); builder.close(); } return omNode; }
/** * Convert DOM Element into a fully built OMElement * @param element dom Element * @return OMElement * @throws Exception */ public static OMElement toOM(Element element) throws Exception { OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(element, true); builder.detach(); return builder.getDocumentElement(); }
/** * Simple utility that takes an XMLStreamReader and writes it * to an XMLStreamWriter * @param reader * @param writer * @throws XMLStreamException */ public static void reader2writer(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(reader); try { OMDocument omDocument = builder.getDocument(); Iterator it = omDocument.getChildren(); while (it.hasNext()) { OMNode omNode = (OMNode) it.next(); omNode.serializeAndConsume(writer); } } finally { builder.close(); } } }
public OMElement processDocument(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault { try { String charSetEncoding = (String) messageContext .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING); // createSOAPModelBuilder takes care of configuring the underlying parser to // avoid the security issue described in CVE-2010-1632 OMXMLParserWrapper builder = OMXMLBuilderFactory.createSOAPModelBuilder(inputStream, charSetEncoding); messageContext.setProperty(Constants.BUILDER, builder); SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement(); BuilderUtil .validateSOAPVersion(BuilderUtil.getEnvelopeNamespace(contentType), envelope); BuilderUtil.validateCharSetEncoding(charSetEncoding, builder.getDocument() .getCharsetEncoding(), envelope.getNamespace().getNamespaceURI()); return envelope; } catch (IOException e) { throw AxisFault.makeFault(e); } }
/** * Close the builders. * * @param messageContext * @throws ServletException */ void closeStaxBuilder(MessageContext messageContext) throws ServletException { if (closeReader && messageContext != null) { try { SOAPEnvelope envelope = messageContext.getEnvelope(); if(envelope != null) { OMXMLParserWrapper builder = envelope.getBuilder(); if (builder != null) { builder.close(); } } } catch (Exception e) { log.debug(e.toString(), e); } } }
parser = (XMLStreamReader) builder.getParser(); } catch (Exception e) { throw new XMLStreamException("problem accessing the parser", e);
public OMElement processDocument(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault { try { String charSetEncoding = (String) messageContext .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING); // Apply a detachable inputstream. This can be used later // to (a) get the length of the incoming message or (b) // free transport resources. DetachableInputStream is = new DetachableInputStream(inputStream); messageContext.setProperty(Constants.DETACHABLE_INPUT_STREAM, is); // createSOAPModelBuilder takes care of configuring the underlying parser to // avoid the security issue described in CVE-2010-1632 OMXMLParserWrapper builder = OMXMLBuilderFactory.createSOAPModelBuilder(is, charSetEncoding); SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement(); BuilderUtil .validateSOAPVersion(BuilderUtil.getEnvelopeNamespace(contentType), envelope); BuilderUtil.validateCharSetEncoding(charSetEncoding, builder.getDocument() .getCharsetEncoding(), envelope.getNamespace().getNamespaceURI()); return envelope; } catch (IOException e) { throw AxisFault.makeFault(e); } }
optimizedContentType, isSOAP); envelope = (SOAPEnvelope) builder.getDocumentElement(); } else { builder = OMXMLBuilderFactory.createSOAPModelBuilder(mis, charSetEnc); envelope = (SOAPEnvelope) builder.getDocumentElement(); } finally { builder.detach();
setParser((XMLStreamReader) builder.getParser()); } catch (Exception e) { throw new XMLStreamException("problem accessing the parser. " + e.getMessage(),
/** * Returns the parsed xml document. * * @param stream input stream of xml string or document needed to be parsed * @return parsed document */ public OMElement getParsedOMElement(InputStream stream) { OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(stream); return builder.getDocumentElement(); }
/** * Converts a given Reader to an OMNode. * The reurned OMNode is fully built if buildAll is true. * If buildAll is false, the caller is responsible for closing the parser. * * @param reader * @param buildAll * @return OMNode * @throws XMLStreamException */ public static OMNode toOM(Reader reader, boolean buildAll) throws XMLStreamException { OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(reader); OMNode omNode = builder.getDocumentElement(); if (buildAll) { omNode.build(); builder.close(); } return omNode; } }
boolean isSOAP = true; builder = getAttachmentsBuilder(mc, mis, optimizedContentType, isSOAP); envelope = (SOAPEnvelope) builder.getDocumentElement(); } else { builder = OMXMLBuilderFactory.createSOAPModelBuilder(mis, charSetEnc); envelope = (SOAPEnvelope) builder.getDocumentElement(); } finally { builder.detach();
/** * Parse input stream to get document. * * @param in * input stream * @return the document */ public static OMDocument getDocument(final InputStream in) { // create the builder OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(new StAXParserConfiguration() { @Override public XMLInputFactory configure(XMLInputFactory factory, StAXDialect dialect) { return factory; } }, in); // get the root element OMDocument doc = builder.getDocument(); return doc; }
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(stream); OMElement documentElement = builder.getDocumentElement(); Iterator it = documentElement.getChildrenWithName(new QName("http://namespace", "elementName")); if (it.hasNext()) { it.next(); it.remove(); }
/** * Converts a given inputstream to an OMNode * The reurned OMNode is fully built if buildAll is true. * If buildAll is false, the caller is responsible for closing the parser. * * @param inputStream * @param buildAll * @return OMNode * @throws javax.xml.stream.XMLStreamException * */ public static OMNode toOM(InputStream inputStream, boolean buildAll) throws XMLStreamException { OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(inputStream); OMNode omNode = builder.getDocumentElement(); if (buildAll) { omNode.build(); builder.close(); } return omNode; }
/** * Loads a document from the given URI. * * @param uri the URI of the document to load * @return Returns the document. * @throws FunctionCallException if the document could not be loaded */ public Object getDocument(String uri) throws FunctionCallException { InputStream in = null; try { if (uri.indexOf(':') == -1) { in = new FileInputStream(uri); } else { URL url = new URL(uri); in = url.openStream(); } return OMXMLBuilderFactory.createOMBuilder(in).getDocument(); } catch (Exception e) { if (in != null) { try { in.close(); } catch (IOException ex) { // Ignore } } throw new FunctionCallException(e); } }
public OMElement convert(Element s) { return OMXMLBuilderFactory.createOMBuilder(new DOMSource(s)).getDocumentElement(); } }
/** * Convert DOM Element into a fully built OMElement * @param element * @param buildAll if true, full OM tree is immediately built. if false, caller is responsible * for building the tree and closing the parser. * @return * @throws Exception */ public static OMElement toOM(Element element, boolean buildAll) throws Exception { Source source = new DOMSource(element); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Result result = new StreamResult(baos); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source, result); ByteArrayInputStream is = new ByteArrayInputStream(baos.toByteArray()); OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(is); OMElement omElement = builder.getDocumentElement(); if (buildAll) { omElement.build(); builder.close(); } return omElement; }