List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java
private void addFileContent(XMLStreamWriter xmlStreamWriter, String urlString, String type) throws XMLStreamException { xmlStreamWriter.writeStartElement("content"); xmlStreamWriter.writeAttribute("type", type); String content;/*from ww w. j a va 2 s . c o m*/ try { content = getHtml(urlString); } catch (Exception e) { error(xmlStreamWriter, "error occured during getting file content", e, true); content = null; } if (content != null) { Vector<String> warnMessage = new Vector<String>(); try { if (type.equals("jmsDest") || type.equals("jmsDestConf")) { // AMX - receive (for jmsInboundDest) Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "namedResource/@name"); if (c1 != null && c1.size() > 0) { if (c1.size() > 1) { warnMessage.add("more then one resourceName found"); } String resourceName = (String) c1.iterator().next(); xmlStreamWriter.writeStartElement("resourceName"); xmlStreamWriter.writeCharacters(resourceName); xmlStreamWriter.writeEndElement(); } else { warnMessage.add("no resourceName found"); } Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content, "namedResource/configuration/@jndiName"); if (c2 != null && c2.size() > 0) { if (c2.size() > 1) { warnMessage.add("more then one resourceJndiName found"); } String resourceJndiName = (String) c2.iterator().next(); xmlStreamWriter.writeStartElement("resourceJndiName"); xmlStreamWriter.writeCharacters(resourceJndiName); xmlStreamWriter.writeEndElement(); } else { warnMessage.add("no resourceJndiName found"); } } else if (type.equals("composite")) { // AMX - receive Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "composite/service/bindingAdjunct/property[@name='JmsInboundDestinationConfig']/@simpleValue"); if (c1 != null && c1.size() > 0) { for (Iterator<String> c1it = c1.iterator(); c1it.hasNext();) { xmlStreamWriter.writeStartElement("jmsInboundDest"); xmlStreamWriter.writeCharacters(c1it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no jmsInboundDest found"); } // AMX - send Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content, "composite/reference/interface.wsdl/@wsdlLocation"); if (c2 != null && c2.size() > 0) { for (Iterator<String> c2it = c2.iterator(); c2it.hasNext();) { String itn = c2it.next(); String wsdl = null; try { URL url = new URL(urlString); URL wsdlUrl = new URL(url, itn); wsdl = getHtml(wsdlUrl.toString()); } catch (Exception e) { error(xmlStreamWriter, "error occured during getting wsdl file content", e, true); wsdl = null; } if (wsdl != null) { Collection<String> c3 = XmlUtils.evaluateXPathNodeSet(wsdl, // "definitions/service/port/targetAddress", // "concat(.,';',../../@name)"); "definitions/service/port/targetAddress"); if (c3 != null && c3.size() > 0) { for (Iterator<String> c3it = c3.iterator(); c3it.hasNext();) { xmlStreamWriter.writeStartElement("targetAddr"); xmlStreamWriter.writeCharacters(c3it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no targetAddr found"); } } else { warnMessage.add("wsdl [" + itn + "] not found"); } } } else { warnMessage.add("no wsdlLocation found"); } } else if (type.equals("process")) { // BW - receive Double d1 = XmlUtils.evaluateXPathNumber(content, "count(ProcessDefinition/starter[type='com.tibco.plugin.soap.SOAPEventSource']/config)"); if (d1 > 0) { Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "ProcessDefinition/starter[type='com.tibco.plugin.soap.SOAPEventSource']/config/sharedChannels/jmsChannel/JMSTo"); if (c1 != null && c1.size() > 0) { for (Iterator<String> c1it = c1.iterator(); c1it.hasNext();) { xmlStreamWriter.writeStartElement("jmsTo"); xmlStreamWriter.writeAttribute("type", "soapEventSource"); xmlStreamWriter.writeCharacters(c1it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no jmsTo found for soapEventSource"); } } else { warnMessage.add("no soapEventSource found"); } // BW - send Double d2 = XmlUtils.evaluateXPathNumber(content, "count(ProcessDefinition/activity[type='com.tibco.plugin.soap.SOAPSendReceiveActivity']/config)"); if (d2 > 0) { Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content, "ProcessDefinition/activity[type='com.tibco.plugin.soap.SOAPSendReceiveActivity']/config/sharedChannels/jmsChannel/JMSTo"); if (c2 != null && c2.size() > 0) { for (Iterator<String> c2it = c2.iterator(); c2it.hasNext();) { xmlStreamWriter.writeStartElement("jmsTo"); xmlStreamWriter.writeAttribute("type", "soapSendReceiveActivity"); xmlStreamWriter.writeCharacters(c2it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no jmsTo found for soapSendReceiveActivity"); } } else { warnMessage.add("no soapSendReceiveActivity found"); } } else if (type.equals("substVar")) { String path = StringUtils .substringBeforeLast(StringUtils.substringAfterLast(urlString, "/defaultVars/"), "/"); Map<String, String> m1 = XmlUtils.evaluateXPathNodeSet(content, "repository/globalVariables/globalVariable", "name", "value"); if (m1 != null && m1.size() > 0) { for (Iterator<String> m1it = m1.keySet().iterator(); m1it.hasNext();) { Object key = m1it.next(); Object value = m1.get(key); xmlStreamWriter.writeStartElement("globalVariable"); xmlStreamWriter.writeAttribute("name", (String) key); xmlStreamWriter.writeAttribute("ref", "%%" + path + "/" + key + "%%"); xmlStreamWriter.writeCharacters((String) value); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no globalVariable found"); } /* * } else { content = XmlUtils.removeNamespaces(content); * xmlStreamWriter.writeCharacters(content); */ } } catch (Exception e) { error(xmlStreamWriter, "error occured during processing " + type + " file", e, true); } if (warnMessage.size() > 0) { xmlStreamWriter.writeStartElement("warnMessages"); for (int i = 0; i < warnMessage.size(); i++) { xmlStreamWriter.writeStartElement("warnMessage"); xmlStreamWriter.writeCharacters(warnMessage.elementAt(i)); xmlStreamWriter.writeEndElement(); } xmlStreamWriter.writeEndElement(); } } xmlStreamWriter.writeEndElement(); }
From source file:nl.nn.adapterframework.soap.Wsdl.java
/** * Writes the WSDL to an output stream// www . j a v a 2s .c o m * @param out * @param servlet The servlet what is used as the web service (because this needs to be present in the WSDL) * @throws XMLStreamException * @throws IOException */ public void wsdl(OutputStream out, String servlet) throws XMLStreamException, IOException, ConfigurationException, NamingException { XMLStreamWriter w = WsdlUtils.getWriter(out, isIndent()); w.writeStartDocument(XmlUtils.STREAM_FACTORY_ENCODING, "1.0"); w.setPrefix(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE); w.setPrefix(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE); w.setPrefix(soapPrefix, soapNamespace); if (jmsActive) { if (esbSoap) { w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, ESB_SOAP_JMS_NAMESPACE); w.setPrefix(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE); } else { w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, SOAP_JMS_NAMESPACE); } } w.setPrefix(getTargetNamespacePrefix(), getTargetNamespace()); for (String prefix : namespaceByPrefix.keySet()) { w.setPrefix(prefix, namespaceByPrefix.get(prefix)); } w.writeStartElement(WSDL_NAMESPACE, "definitions"); { w.writeNamespace(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE); w.writeNamespace(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE); w.writeNamespace(soapPrefix, soapNamespace); if (esbSoap) { w.writeNamespace(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE); } w.writeNamespace(getTargetNamespacePrefix(), getTargetNamespace()); for (String prefix : namespaceByPrefix.keySet()) { w.writeNamespace(prefix, namespaceByPrefix.get(prefix)); } w.writeAttribute("targetNamespace", getTargetNamespace()); documentation(w); types(w); messages(w); portType(w); binding(w); service(w, servlet); } w.writeEndDocument(); warnings(w); w.close(); }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void message(XMLStreamWriter w, String root, Collection<QName> parts) throws XMLStreamException, IOException { if (!parts.isEmpty()) { w.writeStartElement(WSDL_NAMESPACE, "message"); w.writeAttribute("name", "Message_" + root); {// w ww .j a v a2s. c om for (QName part : parts) { w.writeEmptyElement(WSDL_NAMESPACE, "part"); w.writeAttribute("name", "Part_" + part.getLocalPart()); String type = part.getPrefix() + ":" + part.getLocalPart(); w.writeAttribute("element", type); } } w.writeEndElement(); } }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void portType(XMLStreamWriter w) throws XMLStreamException, IOException { w.writeStartElement(WSDL_NAMESPACE, "portType"); w.writeAttribute("name", "PortType_" + getName()); {//w ww . j a v a2 s.c om for (IListener listener : WsdlUtils.getListeners(pipeLine.getAdapter())) { if (listener instanceof WebServiceListener || listener instanceof JmsListener) { w.writeStartElement(WSDL_NAMESPACE, "operation"); w.writeAttribute("name", "Operation_" + WsdlUtils.getNCName(getSoapAction(listener))); { if (StringUtils.isNotEmpty(inputRoot)) { w.writeEmptyElement(WSDL_NAMESPACE, "input"); w.writeAttribute("message", getTargetNamespacePrefix() + ":" + "Message_" + inputRoot); } if (StringUtils.isNotEmpty(outputRoot)) { w.writeEmptyElement(WSDL_NAMESPACE, "output"); w.writeAttribute("message", getTargetNamespacePrefix() + ":" + "Message_" + outputRoot); } } w.writeEndElement(); } } } w.writeEndElement(); }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void httpBinding(XMLStreamWriter w, String namePrefix) throws XMLStreamException, IOException, ConfigurationException { w.writeStartElement(WSDL_NAMESPACE, "binding"); w.writeAttribute("name", namePrefix + "Binding_" + WsdlUtils.getNCName(getName())); w.writeAttribute("type", getTargetNamespacePrefix() + ":" + "PortType_" + getName()); {/*from w w w . j a v a 2 s. com*/ w.writeEmptyElement(soapNamespace, "binding"); w.writeAttribute("transport", SOAP_HTTP_NAMESPACE); w.writeAttribute("style", "document"); for (IListener listener : WsdlUtils.getListeners(pipeLine.getAdapter())) { if (listener instanceof WebServiceListener) { writeSoapOperation(w, listener); } } } w.writeEndElement(); }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void writeSoapOperation(XMLStreamWriter w, IListener listener) throws XMLStreamException, IOException, ConfigurationException { w.writeStartElement(WSDL_NAMESPACE, "operation"); w.writeAttribute("name", "Operation_" + WsdlUtils.getNCName(getSoapAction(listener))); {/* w w w. ja v a 2 s. c o m*/ w.writeEmptyElement(soapNamespace, "operation"); w.writeAttribute("style", "document"); w.writeAttribute("soapAction", getSoapAction(listener)); w.writeStartElement(WSDL_NAMESPACE, "input"); { writeSoapHeader(w, inputRoot, inputHeaderElement, inputHeaderIsOptional); writeSoapBody(w, inputBodyElement); } w.writeEndElement(); if (outputValidator != null) { w.writeStartElement(WSDL_NAMESPACE, "output"); { writeSoapHeader(w, outputRoot, outputHeaderElement, outputHeaderIsOptional); writeSoapBody(w, outputBodyElement); } w.writeEndElement(); } } w.writeEndElement(); }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void writeSoapHeader(XMLStreamWriter w, String root, QName headerElement, boolean isHeaderOptional) throws XMLStreamException, IOException { if (headerElement != null) { w.writeEmptyElement(soapNamespace, "header"); w.writeAttribute("part", "Part_" + headerElement.getLocalPart()); w.writeAttribute("use", "literal"); w.writeAttribute("message", getTargetNamespacePrefix() + ":" + "Message_" + root + (isHeaderOptional ? "_" + headerElement.getLocalPart() : "")); }/*from w w w .j av a 2 s. c o m*/ }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void writeSoapBody(XMLStreamWriter w, QName bodyElement) throws XMLStreamException, IOException { if (bodyElement != null) { w.writeEmptyElement(soapNamespace, "body"); w.writeAttribute("parts", "Part_" + bodyElement.getLocalPart()); w.writeAttribute("use", "literal"); }//from w w w . ja va 2 s. c om }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void jmsBinding(XMLStreamWriter w, String namePrefix) throws XMLStreamException, IOException, ConfigurationException { w.writeStartElement(WSDL_NAMESPACE, "binding"); w.writeAttribute("name", namePrefix + "Binding_" + WsdlUtils.getNCName(getName())); w.writeAttribute("type", getTargetNamespacePrefix() + ":" + "PortType_" + getName()); {/* w ww. j a va 2s. c o m*/ w.writeEmptyElement(soapNamespace, "binding"); w.writeAttribute("style", "document"); if (esbSoap) { w.writeAttribute("transport", ESB_SOAP_JMS_NAMESPACE); w.writeEmptyElement(ESB_SOAP_JMS_NAMESPACE, "binding"); w.writeAttribute("messageFormat", "Text"); for (IListener listener : WsdlUtils.getListeners(pipeLine.getAdapter())) { if (listener instanceof JmsListener) { writeSoapOperation(w, listener); } } } else { w.writeAttribute("transport", SOAP_JMS_NAMESPACE); } } w.writeEndElement(); }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void httpService(XMLStreamWriter w, String servlet, String namePrefix) throws XMLStreamException { w.writeStartElement(WSDL_NAMESPACE, "service"); w.writeAttribute("name", "Service_" + WsdlUtils.getNCName(getName())); {//from www . j a v a 2 s . c om w.writeStartElement(WSDL_NAMESPACE, "port"); w.writeAttribute("name", namePrefix + "Port_" + WsdlUtils.getNCName(getName())); w.writeAttribute("binding", getTargetNamespacePrefix() + ":" + namePrefix + "Binding_" + WsdlUtils.getNCName(getName())); { w.writeEmptyElement(soapNamespace, "address"); w.writeAttribute("location", getLocation(servlet)); } w.writeEndElement(); } w.writeEndElement(); }