Example usage for org.w3c.dom Element getNamespaceURI

List of usage examples for org.w3c.dom Element getNamespaceURI

Introduction

In this page you can find the example usage for org.w3c.dom Element getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:org.fireflow.service.email.send.MailSendServiceParser.java

@Override
public ServiceDef deserializeService(Element svcElem) throws DeserializerException {
    String localName_1 = svcElem.getLocalName();
    String namespaceUri_1 = svcElem.getNamespaceURI();

    if (!equalStrings(localName_1, SERVICE_NAME) || !equalStrings(namespaceUri_1, SERVICE_NS_URI)) {
        throw new DeserializerException(
                "The element is not a java service, the element name is '" + localName_1 + "'");
    }//w  w  w . java 2s .  c  om

    MailSendServiceDef mailSendServiceDef = new MailSendServiceDef();

    this.loadCommonServiceAttribute(mailSendServiceDef, svcElem);

    //?
    Element mailTemplateElem = Util4Deserializer.child(svcElem, this.MAIL_TEMPLATE);
    if (mailTemplateElem != null) {
        String from = Util4Deserializer.elementAsString(mailTemplateElem, FROM);
        mailSendServiceDef.setFrom(from);
        MailTemplate mailTemplate = new MailTemplate();
        mailSendServiceDef.setMailTemplate(mailTemplate);

        Element _childElm = Util4Deserializer.child(mailTemplateElem, MAILTO_LIST);
        if (_childElm != null) {
            Element expElem = Util4Deserializer.child(_childElm, EXPRESSION);
            mailTemplate.setMailToList(this.createExpression(expElem));
        }
        _childElm = Util4Deserializer.child(mailTemplateElem, CARBONCOPY_LIST);
        if (_childElm != null) {
            Element expElem = Util4Deserializer.child(_childElm, EXPRESSION);
            mailTemplate.setCarbonCopyList(this.createExpression(expElem));
        }
        _childElm = Util4Deserializer.child(mailTemplateElem, SUBJECT);
        if (_childElm != null) {
            Element expElem = Util4Deserializer.child(_childElm, EXPRESSION);
            mailTemplate.setSubject(this.createExpression(expElem));
        }

        _childElm = Util4Deserializer.child(mailTemplateElem, EMAIL_BODY);
        if (_childElm != null) {
            Element expElem = Util4Deserializer.child(_childElm, EXPRESSION);
            mailTemplate.setBody(this.createExpression(expElem));
        }

        _childElm = Util4Deserializer.child(mailTemplateElem, BODY_IS_HTML);
        if (_childElm != null) {
            Element expElem = Util4Deserializer.child(_childElm, EXPRESSION);
            mailTemplate.setBodyIsHtml(this.createExpression(expElem));
        }

    }

    //?
    Element connectInfoElem = Util4Deserializer.child(svcElem, CONNECT_INFO);
    String protocol = Util4Deserializer.elementAsString(connectInfoElem, PROTOCOL);
    if (!StringUtils.isEmpty(protocol)) {
        mailSendServiceDef.setProtocol(protocol);
    }

    String serverUrl = Util4Deserializer.elementAsString(connectInfoElem, SERVER_URL);
    mailSendServiceDef.setSmtpServer(serverUrl);

    String port = Util4Deserializer.elementAsString(connectInfoElem, PORT);
    mailSendServiceDef.setSmtpPort(Integer.parseInt(port));

    String needAuth = Util4Deserializer.elementAsString(connectInfoElem, NEED_AUTH);
    mailSendServiceDef.setNeedAuth(Boolean.parseBoolean(needAuth));

    String userName = Util4Deserializer.elementAsString(connectInfoElem, USER_NAME);
    mailSendServiceDef.setUserName(userName);

    String password = Util4Deserializer.elementAsString(connectInfoElem, PASSWORD);
    mailSendServiceDef.setPassword(password);

    String useSSL = Util4Deserializer.elementAsString(connectInfoElem, USE_SSL);
    mailSendServiceDef.setUseSSL(Boolean.parseBoolean(useSSL));

    String charset = Util4Deserializer.elementAsString(connectInfoElem, CHARSET);
    mailSendServiceDef.setCharset(charset);

    this.loadExtendedAttributes(mailSendServiceDef.getExtendedAttributes(),
            Util4Deserializer.child(svcElem, EXTENDED_ATTRIBUTES));

    return mailSendServiceDef;
}

From source file:org.fireflow.service.java.JavaServiceParser.java

public ServiceDef deserializeService(Element element) throws DeserializerException {
    String localName_1 = element.getLocalName();
    String namespaceUri_1 = element.getNamespaceURI();

    if (!equalStrings(localName_1, SERVICE_NAME) || !equalStrings(namespaceUri_1, SERVICE_NS_URI)) {
        throw new DeserializerException(
                "The element is not a java service, the element name is '" + localName_1 + "'");
    }//from www  .  j av a 2s  .c om
    JavaService javaService = new JavaService();
    this.loadCommonServiceAttribute(javaService, element);

    InterfaceDef _interface = loadInterface(Util4Deserializer.child(element, INTERFACE));
    javaService.setInterface(_interface);

    String javaBeanName = Util4Deserializer.elementAsString(element, JAVA_BEAN_NAME);
    if (!StringUtils.isEmpty(javaBeanName)) {
        javaService.setJavaBeanName(javaBeanName);
    }

    String javaClassName = Util4Deserializer.elementAsString(element, JAVA_CLASS_NAME);
    if (!StringUtils.isEmpty(javaClassName)) {
        javaService.setJavaClassName(javaClassName);
    }

    return javaService;
}

From source file:org.firesoa.common.schema.DOMInitializer.java

private static String getQualifiedName(Document doc, QName qName) {
    Element rootElement = (Element) doc.getDocumentElement();

    if (rootElement != null && !equalStrings(qName.getNamespaceURI(), rootElement.getNamespaceURI())) {
        //         Attr attrTmp = rootElement.getAttributeNodeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, "ns0");
        //         System.out.println("===========found attrTmp=="+attrTmp);

        String nsPrefix = null;//www  . j  ava2 s.  c  o  m
        nsPrefix = rootElement.lookupPrefix(qName.getNamespaceURI());
        if (nsPrefix == null || nsPrefix.trim().equals("")) {
            int nsNumber = 1;
            NamedNodeMap attrMap = rootElement.getAttributes();
            int length = attrMap.getLength();

            for (int i = 0; i < length; i++) {
                Attr attr = (Attr) attrMap.item(i);
                String name = attr.getName();
                if (name.startsWith(Constants.XMLNS_ATTRIBUTE)) {
                    if (attr.getValue().equals(qName.getNamespaceURI())) {
                        // Namespace?
                        nsPrefix = attr.getLocalName();
                        break;
                    }
                    nsNumber++;
                }
            }
            if (nsPrefix == null) {
                nsPrefix = "ns" + nsNumber;
            }
        }

        Attr attr = doc.createAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI,
                Constants.XMLNS_ATTRIBUTE + ":" + nsPrefix);
        attr.setValue(qName.getNamespaceURI());
        rootElement.setAttributeNode(attr);

        return nsPrefix + ":" + qName.getLocalPart();
    } else {
        return "ns0:" + qName.getLocalPart();
    }

}

From source file:org.infoscoop.util.Xml2Json.java

private String getXPath(Element element) {
    if (element == null)
        return null;
    StringBuffer xpath = new StringBuffer();
    xpath.append("/");
    String uri = element.getNamespaceURI();
    String prefix = (String) namespaceResolvers.get(uri);
    if (prefix != null)
        xpath.append(prefix).append(":");
    xpath.append(getTagName(element));//from w w  w  .ja v  a2 s  .c  o m
    Element parent = element;
    try {
        while (true) {
            parent = (Element) parent.getParentNode();
            if (parent == null)
                break;
            xpath.insert(0, getTagName(parent));
            uri = parent.getNamespaceURI();
            prefix = (String) namespaceResolvers.get(uri);
            if (prefix != null)
                xpath.insert(0, prefix + ":");
            xpath.insert(0, "/");
        }
    } catch (ClassCastException e) {

    }
    String xpathStr = xpath.toString();
    if (this.basePath != null)
        xpathStr = xpathStr.replaceFirst("^" + this.basePath, "");
    return xpathStr;
}

From source file:org.jboss.bpm.console.server.util.DOMUtils.java

private static void search(List<Element> list, Element baseElement, QName nodeName, boolean recursive) {
    if (nodeName == null) {
        list.add(baseElement);/*from   ww  w  . j a  v a2s . co m*/
    } else {
        QName qname;
        if (nodeName.getNamespaceURI().length() > 0) {
            qname = new QName(baseElement.getNamespaceURI(), baseElement.getLocalName());
        } else {
            qname = new QName(baseElement.getLocalName());
        }
        if (qname.equals(nodeName)) {
            list.add(baseElement);
        }
    }
    if (recursive) {
        NodeList nlist = baseElement.getChildNodes();
        for (int i = 0; i < nlist.getLength(); i++) {
            Node child = nlist.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                search(list, (Element) child, nodeName, recursive);
            }
        }
    }
}

From source file:org.jboss.jaxr.juddi.transport.WS4EESaajTransport.java

private SOAPElement getSOAPElement(SOAPBody soapBody, Element elem) {
    String xmlns = IRegistry.UDDI_V2_NAMESPACE;
    SOAPElement soapElement = null;
    SOAPFactory factory = null;/*w w  w  .  j  a  v  a  2 s . com*/
    try {
        factory = SOAPFactory.newInstance();
        //Go through the element
        String name = elem.getNodeName();
        String nsuri = elem.getNamespaceURI();
        if (nsuri == null)
            nsuri = xmlns;
        soapElement = factory.createElement(name, "ns1", nsuri);
        //Get Attributes
        if (elem.hasAttributes()) {
            NamedNodeMap nnm = elem.getAttributes();
            int len = nnm != null ? nnm.getLength() : 0;
            for (int i = 0; i < len; i++) {
                Node n = nnm.item(i);
                String nodename = n.getNodeName();
                String nodevalue = n.getNodeValue();
                soapElement.addAttribute(factory.createName(nodename), nodevalue);
            }
        } else {
            soapElement.addAttribute(factory.createName("xmlns:ns1"), nsuri);
        }

        NodeList nlist = elem.getChildNodes();
        int len = nlist != null ? nlist.getLength() : 0;

        for (int i = 0; i < len; i++) {
            Node node = nlist.item(i);
            short nodeType = node != null ? node.getNodeType() : -100;
            if (Node.ELEMENT_NODE == nodeType) {
                soapElement.addChildElement(getSOAPElement(soapBody, (Element) node));
            } else if (nodeType == Node.TEXT_NODE) {
                soapElement.addTextNode(node.getNodeValue());
            }

        }
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return soapElement;
}

From source file:org.jbpm.bpel.endpointref.EndpointReference.java

public static EndpointReference readServiceRef(Element referenceElem) {
    String scheme;//www.  j  av  a 2  s . co  m
    Element endpointRefElem;
    // is the given element a service reference container?
    if (BpelConstants.NS_SERVICE_REF.equals(referenceElem.getNamespaceURI())
            && BpelConstants.ELEM_SERVICE_REF.equals(referenceElem.getLocalName())) {
        // read element following the schema of bpel:service-ref
        scheme = referenceElem.getAttribute(BpelConstants.ATTR_REFERENCE_SCHEME);
        endpointRefElem = XmlUtil.getElement(referenceElem);
    } else {
        // assume the given element is the actual endpoint reference value
        scheme = null;
        endpointRefElem = referenceElem;
    }
    // locate a factory that understands this reference
    QName endpointRefName = QNameUtils.newQName(endpointRefElem);
    EndpointReferenceFactory factory = EndpointReferenceFactory.getInstance(endpointRefName, scheme);
    if (factory == null)
        throw new BpelFaultException(BpelConstants.FAULT_UNSUPPORTED_REFERENCE);
    // produce the endpoint reference
    EndpointReference endpointRef = factory.createEndpointReference();
    endpointRef.setScheme(scheme);
    endpointRef.readEndpointRef(endpointRefElem);
    return endpointRef;
}

From source file:org.jbpm.bpel.endpointref.EndpointReference.java

public void writeServiceRef(Element referenceElem) {
    // write the endpoint reference value
    Element endpointRefElem = writeEndpointRef(referenceElem.getOwnerDocument());
    // is the given element a service reference container?
    if (BpelConstants.NS_SERVICE_REF.equals(referenceElem.getNamespaceURI())
            && BpelConstants.ELEM_SERVICE_REF.equals(referenceElem.getLocalName())) {
        // clean the container element
        XmlUtil.removeAttributes(referenceElem);
        XmlUtil.removeChildNodes(referenceElem);
        // set reference scheme attribute
        if (scheme == null || scheme.length() == 0)
            referenceElem.setAttribute(BpelConstants.ATTR_REFERENCE_SCHEME, scheme);
        // add endpoint reference child element
        referenceElem.appendChild(endpointRefElem);
    } else {//from  w  ww . j  a  va2  s .  c  o  m
        // copy the reference value directly to the given element
        XmlUtil.copy(referenceElem, endpointRefElem);
    }
}

From source file:org.jbpm.bpel.graph.exe.ScopeInstance.java

/**
 * Selects a handler for the internal fault. The handler is selected as follows.
 * <ul>/*from w  w  w  . j a  v  a  2s.c o m*/
 * <li>if the fault has no data, select a handler with a matching faultName and no faultVariable</li>
 * <li>if the fault has data, select a handler with a matching faultName and a matching
 * faultVariable; if there is no such handler then select a handler with a matching faultVariable
 * and no faultName</li>
 * <li>otherwise, select the catchAll handler if it exists</li>
 * </ul>
 * @return the selected fault handler, or <code>null</code> if no handler is able to catch the
 * fault
 */
public Handler getFaultHandler() {
    if (faultInstance == null)
        throw new IllegalStateException("scope has not faulted");

    // determine the type of fault data
    VariableType dataType;
    // is it a message?
    MessageValue messageValue = faultInstance.getMessageValue();
    if (messageValue != null)
        dataType = messageValue.getType();
    else {
        // is it an element?
        Element elementValue = faultInstance.getElementValue();
        if (elementValue != null) {
            QName elementName = new QName(elementValue.getNamespaceURI(), elementValue.getLocalName());
            dataType = definition.getBpelProcessDefinition().getImportDefinition().getElementType(elementName);
        }
        // it is none of the above
        else
            dataType = null;
    }
    return definition.selectFaultHandler(faultInstance.getName(), dataType);
}

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

public static void copyChildElement(SOAPElement parent, Element source) throws SOAPException {
    String localName = source.getLocalName();
    String prefix = source.getPrefix();
    String namespaceURI = source.getNamespaceURI();

    Name targetName;/* w ww . jav a2 s.c  o  m*/
    SOAPEnvelope envelope = findEnvelope(parent);

    if (prefix == null || prefix.length() == 0) {
        // source has no prefix, distinguish between no namespace and default namespace
        if (namespaceURI == null || namespaceURI.length() == 0) {
            // no namespace
            targetName = envelope.createName(localName);
            if (traceEnabled)
                log.trace("appended element: " + localName);
        } else {
            // default namespace, look for existing prefix at target
            prefix = getPrefix(namespaceURI, parent);

            // no prefix for that namespace?
            if (prefix == null) {
                prefix = XmlUtil.generatePrefix(DEFAULT_NAMESPACE_PREFIX, source);
            }
            // BPEL-195 source maps prefix to another URI?
            else if (!namespaceURI.equals(source.getAttributeNS(BpelConstants.NS_XMLNS, prefix))) {
                prefix = XmlUtil.generatePrefix(prefix, source);
            }

            targetName = envelope.createName(localName, prefix, namespaceURI);
            if (traceEnabled)
                log.trace("added child element: {" + namespaceURI + '}' + prefix + ':' + localName);
        }
    } else {
        // source has prefix
        targetName = envelope.createName(localName, prefix, namespaceURI);
        if (traceEnabled)
            log.trace("added child element: {" + namespaceURI + '}' + prefix + ':' + localName);
    }

    SOAPElement target;
    if (parent instanceof SOAPBody) {
        /*
         * jboss-ws4ee throws ClassCastException upon calling the remote endpoint if child elements
         * other than SOAPBodyElements are added to SOAPBody
         */
        SOAPBody body = (SOAPBody) parent;
        target = body.addBodyElement(targetName);
    } else
        target = parent.addChildElement(targetName);

    // namespaces
    copyNamespaces(target, source);
    ensureOwnNamespaceDeclared(target);
    // attributes
    copyAttributes(target, source);
    // child nodes
    copyChildNodes(target, source);
}