/** * Creates a new instance that wraps the submitted XML document. * * @param doc * xml content * @param systemId * the URL that is the source of the passed doc. If this URL is not available or unknown, the string * should contain the value of XMLFragment.DEFAULT_URL */ public XMLAdapter( OMDocument doc, String systemId ) { this( doc.getOMDocumentElement(), systemId ); }
public static OMElement wrapBoxCarringResponse(OMElement result) { OMFactory fac = OMAbstractFactory.getOMFactory(); OMElement wrapperElement = fac.createOMElement(new QName(DBConstants.WSO2_DS_NAMESPACE, DBConstants.DATA_SERVICE_REQUEST_BOX_RESPONSE_WRAPPER_ELEMENT)); if (result != null) { wrapperElement.addChild(result); } OMDocument doc = fac.createOMDocument(); doc.addChild(wrapperElement); return doc.getOMDocumentElement(); }
encoding = document.getCharsetEncoding(); String version = document.getXMLVersion(); if (version == null) { version = "1.0"; if (cache || document.isComplete() || document.getBuilder() == null) { OMSerializerUtil.serializeChildren(document, writer, cache); } else { StreamingOMSerializer streamingOMSerializer = new StreamingOMSerializer(); XMLStreamReader reader = document.getXMLStreamReaderWithoutCaching(); while (reader.getEventType() != XMLStreamReader.END_DOCUMENT) { streamingOMSerializer.serialize(reader, writer);
public static OMElement extractElement(XMLStreamReader reader, boolean proceedToNext) { OMDocument document = OMXMLBuilderFactory.createStAXOMBuilder( new XMLFragmentStreamReader(reader, proceedToNext)).getDocument(); document.build(); return document.getOMDocumentElement(); } }
public String serialize() throws Exception { String result = null; OMDocument document = factory.createOMDocument(); OMElement documentElement = getDocumentElement(); document.addChild(documentElement); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { prettify(documentElement, outputStream); } catch (Exception e) { throw new MojoExecutionException("Error serializing",e); } result = outputStream.toString(); return result; }
private void handleChartTitle(String chartText) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:" + chartText + "//a:chart//a:chartTitle//a:titleExpression"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); element.setText(""); OMFactory factory = document.getOMFactory(); OMText cdataField = factory.createOMText(element, "\"" + chart.getTitle() + "\"", OMText.CDATA_SECTION_NODE); element.addChild(cdataField); }
public OMElement processMIMEMessage(Attachments attachments, String contentType, MessageContext messageContext) throws AxisFault { try { // TODO: this will be changed later (see AXIS2-5308) messageContext.setAttachmentMap(attachments); SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments); OMDocument document = builder.getDocument(); String charsetEncoding = document.getCharsetEncoding(); if (charsetEncoding == null) { charsetEncoding = MessageContext.UTF_8; } messageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charsetEncoding); SOAPEnvelope envelope = (SOAPEnvelope)document.getOMDocumentElement(); // TODO: Axiom should take care of this, but we need to validate that // BuilderUtil // .validateSOAPVersion(BuilderUtil.getEnvelopeNamespace(contentType), envelope); // BuilderUtil.validateCharSetEncoding(charSetEncoding, builder.getDocument() // .getCharsetEncoding(), envelope.getNamespace().getNamespaceURI()); messageContext.setDoingMTOM(true); return envelope; } catch (OMException e) { throw AxisFault.makeFault(e); } } }
private void write(OutputStream out) throws IOException, XMLStreamException { if (targetNamespace == null) { targetNamespace = detectTargetNamespace(); } if (targetNamespace == null) { throw new PaxmlRuntimeException("No @targetNamespace attribute given on <soap> tag," + " and the target namespace cannot be detected from WSDL: " + getWsdlUrl()); } OMFactory factory = AxiomUtils.getOMFactory(); Map<?, ?> bd = (Map<?, ?>) this.body; OMNamespace targetNs = factory.createOMNamespace(targetNamespace, "ns"); OMNamespace ns = factory.createOMNamespace(SOAP_NS, "soapenv"); OMDocument doc = AxiomUtils.newDocument(); doc.setXMLEncoding("UTF-8"); OMElement root = factory.createOMElement("Envelope", ns); doc.addChild(root); OMElement headerEle = factory.createOMElement("Header", ns); root.addChild(headerEle); OMElement bodyEle = factory.createOMElement("Body", ns); root.addChild(bodyEle); Iterator<?> it = bd.entrySet().iterator(); if (!it.hasNext()) { throw new PaxmlRuntimeException("No webservice operation name given!"); } toXml(bodyEle, bd, targetNs, factory); doc.serializeAndConsume(out); }
/** * {@inheritDoc} */ public CAppArtifactDependency export(OMElement artifactDefinition, CAppArtifactDependency synapseArtifactClone, File workDir) throws Exception { // Create the temporary directory. workDir.mkdirs(); // Serialize the sequence definition. String artifactName = getArtifactName(artifactDefinition); File artifactContentFile = new File(workDir, String.format("%s.xml", artifactName)); FileOutputStream fos = null; try { fos = new FileOutputStream(artifactContentFile); OMFactory omFactory = OMAbstractFactory.getOMFactory(); OMDocument omDocument = omFactory.createOMDocument(); omDocument.addChild(artifactDefinition); omDocument.serialize(fos); } finally { IOUtils.closeQuietly(fos); } // Create the sequence artifact. MavenProject dummyMavenProject = MavenUtils.createMavenProject(synapseArtifactClone.getcAppArtifact().getProject().getGroupId(), artifactName, synapseArtifactClone.getVersion(), getArtifactType()); CAppArtifactDependency cAppArtifactDependency = new CAppArtifactDependency(dummyMavenProject, getArtifactType(), synapseArtifactClone.getServerRole()); cAppArtifactDependency.setDummyDependency(true); cAppArtifactDependency.setArtifactFiles(new File[]{artifactContentFile}); cAppArtifactDependency.getcAppArtifact().setFile(artifactContentFile.getName()); return cAppArtifactDependency; }
public String getCharsetEncoding() { return document.getCharsetEncoding(); }
public void writeTo(Base base, Writer out, WriterOptions options) throws IOException { try { 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(); } catch (XMLStreamException e) { throw new RuntimeException(e); } }
public NodeList getChildNodes() { Iterator itr = null; if (nl == null) { // ok then this is the first call to this method list = new ArrayList(); nl = new NodeListImpl(list, fac); itr = doc.getChildren(); Object o; while(itr.hasNext()) { o = itr.next(); // Axiom returns OMText nodes even for newline characters // we don't want these to be returned from an XML Document node if (o instanceof OMText) { continue; } list.add(o); } } return nl; }
String getCharacterEncodingScheme() { if (currentEvent == START_DOCUMENT) { if (node instanceof OMDocument) { return ((OMDocument)node).getXMLEncoding(); } else { return null; } } else { throw new IllegalStateException(); } }
public AxisMessage(MessageContext msgContext) throws Exception { envelope = msgContext.getEnvelope(); // If possible, build the parent (i.e. the OMDocument) to make sure that the entire message is read. // If the transport doesn't handle the end of the message properly, then this problem // will show up here. OMDocument document = (OMDocument)envelope.getParent(); if (document != null) { document.build(); } else { envelope.build(); } // TODO: quick & dirty hack to force expansion of OMSourceElement payloads OMElement content = envelope.getBody().getFirstElement(); if (content instanceof OMSourcedElement) { ((OMSourcedElement)content).getFirstOMChild(); ((OMSourcedElement)content).build(); } if (msgContext.isDoingSwA()) { // Make sure that all attachments are read attachments = msgContext.getAttachmentMap(); attachments.getAllContentIDs(); } messageType = (String)msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE); }
public String serialize() { String result = null; OMDocument document = factory.createOMDocument(); OMElement documentElement = getDocumentElement(); document.addChild(documentElement); try { result = getPretifiedString(documentElement); } catch (Exception e) { e.printStackTrace(); return null; } return result; }
private void handleChartSubTitle(String chartText) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:" + chartText + "//a:chart//a:chartSubtitle//a:subtitleExpression"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); element.setText(""); OMFactory factory = document.getOMFactory(); OMText cdataField = factory.createOMText(element, "\"" + chart.getSubTitle() + "\"", OMText.CDATA_SECTION_NODE); element.addChild(cdataField); }
messageContext.setProperty(Constants.BUILDER, builder); OMDocument document = builder.getDocument(); String charsetEncoding = document.getCharsetEncoding(); if (charsetEncoding == null) { charsetEncoding = MessageContext.UTF_8; charsetEncoding); SOAPEnvelope envelope = (SOAPEnvelope)document.getOMDocumentElement();
private void write(OutputStream out) throws IOException, XMLStreamException { if (targetNamespace == null) { targetNamespace = detectTargetNamespace(); } if (targetNamespace == null) { throw new PaxmlRuntimeException("No @targetNamespace attribute given on <soap> tag," + " and the target namespace cannot be detected from WSDL: " + getWsdlUrl()); } OMFactory factory = AxiomUtils.getOMFactory(); Map<?, ?> bd = (Map<?, ?>) this.body; OMNamespace targetNs = factory.createOMNamespace(targetNamespace, "ns"); OMNamespace ns = factory.createOMNamespace(SOAP_NS, "soapenv"); OMDocument doc = AxiomUtils.newDocument(); doc.setXMLEncoding("UTF-8"); OMElement root = factory.createOMElement("Envelope", ns); doc.addChild(root); OMElement headerEle = factory.createOMElement("Header", ns); root.addChild(headerEle); OMElement bodyEle = factory.createOMElement("Body", ns); root.addChild(bodyEle); Iterator<?> it = bd.entrySet().iterator(); if (!it.hasNext()) { throw new PaxmlRuntimeException("No webservice operation name given!"); } toXml(bodyEle, bd, targetNs, factory); doc.serializeAndConsume(out); }
String getEncoding() { if (currentEvent == START_DOCUMENT) { if (node instanceof OMDocument) { return ((OMDocument)node).getCharsetEncoding(); } else { return null; } } else { throw new IllegalStateException(); } }
/** * Gets the valid element collection of an OMDocument. OMElement and OMProcessingInstruction * only * * @param document * @return Returns a collection of OMProcessingInstructions and OMElements */ public Collection getValidElements(OMDocument document) { ArrayList list = new ArrayList(); Iterator itr = document.getChildren(); while (itr.hasNext()) { OMNode node = (OMNode) itr.next(); if (node.getType() == OMNode.ELEMENT_NODE || node.getType() == OMNode.PI_NODE) list.add(node); } return list; }