Example usage for javax.xml.soap SOAPElement getAttribute

List of usage examples for javax.xml.soap SOAPElement getAttribute

Introduction

In this page you can find the example usage for javax.xml.soap SOAPElement getAttribute.

Prototype

public String getAttribute(String name);

Source Link

Document

Retrieves an attribute value by name.

Usage

From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java

protected void parseCellDataElement(SOAPElement cellDataElement) throws SOAPException {
    Name name = sf.createName("Cell", "", MDD_URI);
    Iterator<?> itCells = cellDataElement.getChildElements(name);
    while (itCells.hasNext()) {
        SOAPElement cellElement = (SOAPElement) itCells.next();

        Name errorName = sf.createName("Error", "", MDD_URI);
        Iterator<?> errorElems = cellElement.getChildElements(errorName);
        if (errorElems.hasNext()) {
            handleCellErrors(errorElems);
        }/*from   w w  w .  ja v  a 2  s .  co m*/

        Name ordinalName = sf.createName("CellOrdinal");
        String cellOrdinal = cellElement.getAttributeValue(ordinalName);

        Object value = null;
        Iterator<?> valueElements = cellElement.getChildElements(sf.createName("Value", "", MDD_URI));
        if (valueElements.hasNext()) {
            SOAPElement valueElement = (SOAPElement) valueElements.next();
            String valueType = valueElement.getAttribute("xsi:type");
            if (valueType.equals("xsd:int")) {
                value = Long.valueOf(valueElement.getValue());
            } else if (valueType.equals("xsd:double") || valueType.equals("xsd:decimal")) {
                value = Double.valueOf(valueElement.getValue());
            } else {
                value = valueElement.getValue();
            }
        }

        String fmtValue = "";
        Iterator<?> fmtValueElements = cellElement.getChildElements(sf.createName("FmtValue", "", MDD_URI));
        if (fmtValueElements.hasNext()) {
            SOAPElement fmtValueElement = ((SOAPElement) fmtValueElements.next());
            fmtValue = fmtValueElement.getValue();
        }

        int pos = Integer.parseInt(cellOrdinal);
        JRXmlaCell cell = new JRXmlaCell(value, fmtValue);
        xmlaResult.setCell(cell, pos);
    }
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

protected void parseCellDataElement(SOAPElement cellDataElement) throws SOAPException {
    Name name = sf.createName("Cell", "", MDD_URI);
    Iterator itCells = cellDataElement.getChildElements(name);
    while (itCells.hasNext()) {
        SOAPElement cellElement = (SOAPElement) itCells.next();

        Name errorName = sf.createName("Error", "", MDD_URI);
        Iterator errorElems = cellElement.getChildElements(errorName);
        if (errorElems.hasNext()) {
            handleCellErrors(errorElems);
        }/*from ww w  .ja v a2  s. c  o m*/

        Name ordinalName = sf.createName("CellOrdinal");
        String cellOrdinal = cellElement.getAttributeValue(ordinalName);

        Object value = null;
        Iterator valueElements = cellElement.getChildElements(sf.createName("Value", "", MDD_URI));
        if (valueElements.hasNext()) {
            SOAPElement valueElement = (SOAPElement) valueElements.next();
            String valueType = valueElement.getAttribute("xsi:type");
            if (valueType.equals("xsd:int"))
                value = new Long(valueElement.getValue());
            else if (valueType.equals("xsd:double"))
                value = new Double(valueElement.getValue());
            else if (valueType.equals("xsd:decimal"))
                value = new Double(valueElement.getValue());
            else
                value = valueElement.getValue();
        }

        String fmtValue = "";
        Iterator fmtValueElements = cellElement.getChildElements(sf.createName("FmtValue", "", MDD_URI));
        if (fmtValueElements.hasNext()) {
            SOAPElement fmtValueElement = ((SOAPElement) fmtValueElements.next());
            fmtValue = fmtValueElement.getValue();
        }

        int pos = Integer.parseInt(cellOrdinal);
        JRXmlaCell cell = new JRXmlaCell(value, fmtValue);
        ((JRXmlaResult) xmlaResult).setCell(cell, pos);
    }
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

private SOAPElement addSoapElement(Context context, SOAPEnvelope se, SOAPElement soapParent, Node node)
        throws Exception {
    String prefix = node.getPrefix();
    String namespace = node.getNamespaceURI();
    String nodeName = node.getNodeName();
    String localName = node.getLocalName();
    String value = node.getNodeValue();

    boolean includeResponseElement = true;
    if (context.sequenceName != null) {
        includeResponseElement = ((Sequence) context.requestedObject).isIncludeResponseElement();
    }//  w  ww .ja v a2s . c  o m

    SOAPElement soapElement = null;
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;

        boolean toAdd = true;
        if (!includeResponseElement && "response".equalsIgnoreCase(localName)) {
            toAdd = false;
        }
        if ("http://schemas.xmlsoap.org/soap/envelope/".equals(element.getParentNode().getNamespaceURI())
                || "http://schemas.xmlsoap.org/soap/envelope/".equals(namespace)
                || nodeName.toLowerCase().endsWith(":envelope") || nodeName.toLowerCase().endsWith(":body")
        //element.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 ||
        //nodeName.toUpperCase().indexOf("NS0:") != -1
        ) {
            toAdd = false;
        }

        if (toAdd) {
            if (prefix == null || prefix.equals("")) {
                soapElement = soapParent.addChildElement(nodeName);
            } else {
                soapElement = soapParent.addChildElement(se.createName(localName, prefix, namespace));
            }
        } else {
            soapElement = soapParent;
        }

        if (soapElement != null) {
            if (soapParent.equals(se.getBody()) && !soapParent.equals(soapElement)) {
                if (XsdForm.qualified == context.project.getSchemaElementForm()) {
                    if (soapElement.getAttribute("xmlns") == null) {
                        soapElement.addAttribute(se.createName("xmlns"), context.project.getTargetNamespace());
                    }
                }
            }

            if (element.hasAttributes()) {
                String attrType = element.getAttribute("type");
                if (("attachment").equals(attrType)) {
                    if (context.requestedObject instanceof AbstractHttpTransaction) {
                        AttachmentDetails attachment = AttachmentManager.getAttachment(element);
                        if (attachment != null) {
                            byte[] raw = attachment.getData();
                            if (raw != null)
                                soapElement.addTextNode(Base64.encodeBase64String(raw));
                        }

                        /* DON'T WORK YET *\
                        AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), element.getAttribute("content-type"));
                        ap.setContentId(key);
                        ap.setContentLocation(element.getAttribute("url"));
                        responseMessage.addAttachmentPart(ap);
                        \* DON'T WORK YET */
                    }
                }

                if (!includeResponseElement && "response".equalsIgnoreCase(localName)) {
                    // do not add attributes
                } else {
                    NamedNodeMap attributes = element.getAttributes();
                    int len = attributes.getLength();
                    for (int i = 0; i < len; i++) {
                        Node item = attributes.item(i);
                        addSoapElement(context, se, soapElement, item);
                    }
                }
            }

            if (element.hasChildNodes()) {
                NodeList childNodes = element.getChildNodes();
                int len = childNodes.getLength();
                for (int i = 0; i < len; i++) {
                    Node item = childNodes.item(i);
                    switch (item.getNodeType()) {
                    case Node.ELEMENT_NODE:
                        addSoapElement(context, se, soapElement, item);
                        break;
                    case Node.CDATA_SECTION_NODE:
                    case Node.TEXT_NODE:
                        String text = item.getNodeValue();
                        text = (text == null) ? "" : text;
                        soapElement.addTextNode(text);
                        break;
                    default:
                        break;
                    }
                }
            }
        }
    } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
        if (prefix == null || prefix.equals("")) {
            soapElement = soapParent.addAttribute(se.createName(nodeName), value);
        } else {
            soapElement = soapParent.addAttribute(se.createName(localName, prefix, namespace), value);
        }
    }
    return soapElement;
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testRemoveNamespaces_soap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:fish='urn:example:fish'>"
            + "  <lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' "
            + "   xmlns:produce='urn:example:produce' />" + " </soap:Body>" + "</soap:Envelope>";
    ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes());
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream);
    SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch");
    // remove namespaces
    SoapUtil.removeNamespaces(element);/*from  w  w  w . j a  v  a2s . c o  m*/
    // verify remotion
    assertFalse(element.getNamespacePrefixes().hasNext());
    // attributes should still be there
    // qualified attributes
    assertEquals("0.1lb", element.getAttributeNS("urn:example:produce", "lettuce"));
    assertEquals("0.25lb", element.getAttributeNS("urn:example:fish", "fillet"));
    // local attribute
    assertEquals("1200", element.getAttribute("time"));
}