public void addElementToContent(final OMElement element) { if (element != null) { if (content == null) this.content = new ArrayList<>(); this.content.add(element.cloneOMElement()); } }
/** * @param element XML element * @param outputStream Output Stream to write the converted JSON representation. * @throws AxisFault * @deprecated Use {@link org.apache.synapse.commons.json.JsonUtil#writeAsJson(org.apache.axiom.om.OMElement, java.io.OutputStream)} */ public static void toJson(OMElement element, OutputStream outputStream) throws AxisFault { JsonUtil.writeAsJson(element.cloneOMElement(), outputStream); }
public void setContent(final Iterator<OMElement> content) { if (!Utils.isNullOrEmpty(content)) { this.content = new ArrayList<>(); while (content.hasNext()) this.content.add(content.next().cloneOMElement()); } else this.content = null; }
/** * Converts an XML element to its JSON representation and returns it as a String. * * @param element OMElement to be converted to JSON. * @return A String builder instance that contains the converted JSON string. */ public static StringBuilder toJsonString(OMElement element) throws AxisFault { if (element == null) { return new StringBuilder("{}"); } org.apache.commons.io.output.ByteArrayOutputStream byteStream = new org.apache.commons.io.output.ByteArrayOutputStream(); writeAsJson(element.cloneOMElement(), byteStream); return new StringBuilder(new String(byteStream.toByteArray())); }
@Override public Object copy(Object source, DataType sourceDataType, DataType targetDataType, Operation sourceOperation, Operation targetOperation) { if ( OMElement.class.isAssignableFrom(source.getClass()) ) { try { OMElement sourceElement = (OMElement)source; return sourceElement.cloneOMElement(); } catch ( Exception e ) { throw new IllegalArgumentException(e); } } return super.copy(source, sourceDataType, targetDataType, sourceOperation, targetOperation); }
@SuppressWarnings("unchecked") private static OMElement stripNamespace(OMElement element) { OMElement parent = OM.createOMElement(new QName("", element.getLocalName())); Iterator<OMElement> iter = (Iterator<OMElement>) element.getChildElements(); while (iter.hasNext()) { OMElement child = iter.next(); child = child.cloneOMElement(); parent.addChild(child); } return parent; }
public Endpoint create(TemplateEndpoint templateEndpoint, Properties properties) { // first go through all the elements and replace with the parameters OMElement clonedElement = element.cloneOMElement(); replaceElement(templateEndpoint, clonedElement); return EndpointFactory.getEndpointFromElement(clonedElement, false, properties); }
private Object getResultValue(MessageContext synCtx) { if (value != null) { return value; } else if (valueElement != null) { // Need to take a clone of the element, otherwise same reference is shared across all the requests return valueElement.cloneOMElement(); } else { return convertValue(expression.stringValueOf(synCtx), type); } }
public Endpoint create(TemplateEndpoint templateEndpoint, Properties properties) { // first go through all the elements and replace with the parameters OMElement clonedElement = element.cloneOMElement(); replaceElement(templateEndpoint, clonedElement); return EndpointFactory.getEndpointFromElement(clonedElement, false, properties); }
private Object getResultValue(MessageContext synCtx) { if (value != null) { return value; } else if (valueElement != null) { //Need to clone to prevent same reference sharing accross all requests return valueElement.cloneOMElement(); } else { if(expression != null) { return convertValue(expression.stringValueOf(synCtx), type); } } return null; }
public static EndpointReference cloneEPR (EndpointReference epr) { EndpointReference newEPR = new EndpointReference (epr.getAddress()); Map<QName, OMElement> referenceParams = epr.getAllReferenceParameters(); if (referenceParams != null) { for (Iterator<Entry<QName, OMElement>> entries = referenceParams.entrySet().iterator(); entries .hasNext();) { Entry<QName, OMElement> entry = entries.next(); Object referenceParam = entry.getValue(); if (referenceParam instanceof OMElement) { OMElement clonedElement = ((OMElement) referenceParam) .cloneOMElement(); clonedElement.setText("false"); newEPR.addReferenceParameter(clonedElement); } } } return newEPR; }
@Override public Object wrap(OMElement template, OMElement os) { OMElement wrapper; if (os != null) { OMNamespace ns = os.declareNamespace(template.getNamespace().getNamespaceURI(), ""); wrapper = factory.createOMElement(template.getLocalName(), ns); wrapper.addChild(os); } else { wrapper = template.cloneOMElement(); } return wrapper; }
private void addParam(String dsname, String className) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:parameter"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); OMElement newParam = element.cloneOMElement(); newParam.getAttribute(new QName("name")).setAttributeValue(dsname); newParam.getAttribute(new QName("class")).setAttributeValue(className); documentElement.addChild(newParam); }
private void addCustomHeader(MessageContext synCtx, String value) { SOAPEnvelope env = synCtx.getEnvelope(); if (env == null) { return; } SOAPFactory fac = (SOAPFactory) env.getOMFactory(); SOAPHeader header = env.getOrCreateHeader(); if (!isImplicit()) { SOAPHeaderBlock hb = header.addHeaderBlock(qName.getLocalPart(), fac.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix())); hb.setText(value); } else if (hasEmbeddedXml()) { for (OMElement e : embeddedXmlContent) { // Don't attach the original OMElement here. // If another mediator down the line, changes the OM, we are in trouble. header.addChild(e.cloneOMElement()); } } }
private void addDataSourcesParams() throws JaxenException { OMElement documentElement = document.getOMDocumentElement(); OMElement tempDocument = documentElement.cloneOMElement(); refreshReport(); int count = 0; for (String aSubReport : subReports) { count++; if (count != 1) addParam("TableDataSource" + count, "net.sf.jasperreports.engine.JRDataSource"); dataSourceNames[count-1] = "TableDataSource"+count; addParam(aSubReport, "net.sf.jasperreports.engine.JasperReport"); } reloadContent(tempDocument); }
public OMElement serializeEndpointTemplate(Template template, OMElement parent) { OMElement templateElement = fac.createOMElement("template", SynapseConstants.SYNAPSE_OMNAMESPACE); templateElement.addAttribute(fac.createOMAttribute("name", nullNS, template.getName())); List<String> parameters = template.getParameters(); for (String entry : parameters) { OMElement paramElement = fac.createOMElement( new QName(SynapseConstants.SYNAPSE_NAMESPACE, "parameter")); paramElement.addAttribute(fac.createOMAttribute("name", nullNS, entry)); templateElement.addChild(paramElement); } templateElement.addChild(template.getElement().cloneOMElement()); if (parent != null) { parent.addChild(templateElement); } return templateElement; } }
public OMElement serializeEndpointTemplate(Template template, OMElement parent) { OMElement templateElement = fac.createOMElement("template", SynapseConstants.SYNAPSE_OMNAMESPACE); templateElement.addAttribute(fac.createOMAttribute("name", nullNS, template.getName())); List<String> parameters = template.getParameters(); for (String entry : parameters) { OMElement paramElement = fac.createOMElement("parameter", SynapseConstants.SYNAPSE_OMNAMESPACE); paramElement.addAttribute(fac.createOMAttribute("name", nullNS, entry)); templateElement.addChild(paramElement); } templateElement.addChild(template.getElement().cloneOMElement()); if (parent != null) { parent.addChild(templateElement); } return templateElement; } }
public void testEntrySerializationScenarioOne() throws Exception { String inputXml = "<localEntry xmlns=\"http://ws.apache.org/ns/synapse\" key=\"key\" " + "><description>description</description><foo/></localEntry>"; OMElement inputOM = createOMElement(inputXml); Entry entry = EntryFactory.createEntry(inputOM.cloneOMElement(), new Properties()); OMElement resultOM = EntrySerializer.serializeEntry(entry, null); assertTrue(compare(resultOM, inputOM)); }
public void testEntrySerializationScenarioThree() throws Exception { String inputXml = "<localEntry xmlns=\"http://ws.apache.org/ns/synapse\" key=\"key\" " + "/>"; OMElement inputOM = createOMElement(inputXml); Entry entry = EntryFactory.createEntry(inputOM.cloneOMElement(), new Properties()); OMElement resultOM = EntrySerializer.serializeEntry(entry, null); assertTrue(compare(resultOM, inputOM)); } }
public void testEntrySerializationScenarioTwo() throws Exception { String inputXml = "<localEntry xmlns=\"http://ws.apache.org/ns/synapse\" key=\"key\"" + "><description>description</description></localEntry>"; OMElement inputOM = createOMElement(inputXml); Entry entry = EntryFactory.createEntry(inputOM.cloneOMElement(), new Properties()); OMElement resultOM = EntrySerializer.serializeEntry(entry, null); assertTrue(compare(resultOM, inputOM)); }