Example usage for org.dom4j Element getNamespaceURI

List of usage examples for org.dom4j Element getNamespaceURI

Introduction

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

Prototype

String getNamespaceURI();

Source Link

Document

Returns the URI mapped to the namespace of this element if one exists otherwise an empty String is returned.

Usage

From source file:com.collabnet.ccf.core.ga.GenericArtifactHelper.java

License:Open Source License

/**
 * Extracts the artifact-root-element out of a Dom4J XML document
 * // ww  w.j a v  a  2s. c  o m
 * @param document
 *            XML document in question
 * @return generic artifact root-element
 * @throws GenericArtifactParsingException
 *             thrown if document is not compliant to the generic artifact
 *             schema
 */
private static Element getRootElement(Document document) throws GenericArtifactParsingException {
    Element rootElement = document.getRootElement();
    if (!ARTIFACT_ROOT_ELEMENT_NAME.equals(rootElement.getName()))
        throw new GenericArtifactParsingException("Root-element of XML document is not named "
                + ARTIFACT_ROOT_ELEMENT_NAME + "but " + rootElement.getName());
    if (!CCF_ARTIFACT_NAMESPACE.equals(rootElement.getNamespaceURI()))
        throw new GenericArtifactParsingException("Namespace-URI of root-element of XML document is not named "
                + CCF_ARTIFACT_NAMESPACE + "but " + rootElement.getNamespaceURI());
    return rootElement;
}

From source file:com.collabnet.ccf.core.utils.XPathUtils.java

License:Open Source License

/**
 * Extracts the artifact-root-element out of a Dom4J XML document
 * /*from   w  ww . j a v  a2s.  c o m*/
 * @param document
 *            XML document in question
 * @return generic artifact root-element
 * @throws GenericArtifactParsingException
 *             thrown if document is not compliant to the generic artifact
 *             schema
 */
public static Element getRootElement(Document document) throws GenericArtifactParsingException {
    Element rootElement = document.getRootElement();
    if (rootElement == null) {
        throw new GenericArtifactParsingException(
                "Received empty XML document. The reason might be an invalid data mapping.");
    }
    if (!ARTIFACT_ROOT_ELEMENT_NAME.equals(rootElement.getName()))
        throw new GenericArtifactParsingException("Root-element of XML document is not named "
                + ARTIFACT_ROOT_ELEMENT_NAME + "but " + rootElement.getName());
    if (!CCF_ARTIFACT_NAMESPACE.equals(rootElement.getNamespaceURI()))
        throw new GenericArtifactParsingException("Namespace-URI of root-element of XML document is not named "
                + CCF_ARTIFACT_NAMESPACE + "but " + rootElement.getNamespaceURI());
    return rootElement;
}

From source file:com.hand.hemp.push.server.xmpp.router.IQRouter.java

License:Open Source License

private void handle(IQ packet) {
    try {//  w w w  .  j ava 2  s. c o  m
        Element childElement = packet.getChildElement();
        String namespace = null;
        if (childElement != null) {
            namespace = childElement.getNamespaceURI();
        }
        if (namespace == null) {
            if (packet.getType() != IQ.Type.result && packet.getType() != IQ.Type.error) {
                log.warn("Unknown packet " + packet);
            } else if (packet.getType() == IQ.Type.result) {
                String id = packet.getID();
                JID from = packet.getFrom();
                String userName = from.getNode();
                //TODO FIXME ???
                updateNotification(id, userName);
            }
        } else {
            IQHandler handler = getHandler(namespace);
            if (handler == null) {
                sendErrorPacket(packet, PacketError.Condition.service_unavailable);
            } else {
                handler.process(packet);
            }
        }

    } catch (Exception e) {
        log.error("Could not route packet", e);
        Session session = sessionManager.getSession(packet.getFrom());
        if (session != null && !IQ.Type.result.equals(packet.getType())) {
            IQ reply = IQ.createResultIQ(packet);
            reply.setError(PacketError.Condition.internal_server_error);
            session.process(reply);
        }
    }
}

From source file:com.jpsycn.wggl.mobile.androidpn.xmpp.router.IQRouter.java

License:Open Source License

private void handle(IQ packet) {
    try {/*from   w w  w.ja  va 2  s  .  co  m*/
        Element childElement = packet.getChildElement();
        String namespace = null;
        if (childElement != null) {
            namespace = childElement.getNamespaceURI();
        }
        if (namespace == null) {
            if (packet.getType() != IQ.Type.result && packet.getType() != IQ.Type.error) {
                log.warn("Unknown packet " + packet);
            } else if (packet.getType() == IQ.Type.result) {
                String id = packet.getID();
                JID from = packet.getFrom();
                String userName = from.getNode();
                updateNotification(id, userName);
            }
        } else {
            IQHandler handler = getHandler(namespace);
            if (handler == null) {
                sendErrorPacket(packet, PacketError.Condition.service_unavailable);
            } else {
                handler.process(packet);
            }
        }

    } catch (Exception e) {
        log.error("Could not route packet", e);
        Session session = sessionManager.getSession(packet.getFrom());
        if (session != null && !IQ.Type.result.equals(packet.getType())) {
            IQ reply = IQ.createResultIQ(packet);
            reply.setError(PacketError.Condition.internal_server_error);
            session.process(reply);
        }
    }
}

From source file:com.smartwork.im.StreamError.java

License:Open Source License

/**
 * Returns the error condition./*  w ww .j av a  2  s.com*/
 *
 * @return the error condition.
 * @see Condition
 */
public Condition getCondition() {
    for (Iterator<?> i = element.elementIterator(); i.hasNext();) {
        Element el = (Element) i.next();
        if (el.getNamespaceURI().equals(ERROR_NAMESPACE) && !el.getName().equals("text")) {
            return Condition.fromXMPP(el.getName());
        }
    }
    return null;
}

From source file:com.smartwork.im.StreamError.java

License:Open Source License

/**
 * Sets the error condition./* w  w w  .ja v a  2 s  .c o  m*/
 *
 * @param condition the error condition.
 * @see Condition
 */
public void setCondition(Condition condition) {
    if (condition == null) {
        throw new NullPointerException("Condition cannot be null");
    }
    Element conditionElement = null;
    for (Iterator<?> i = element.elementIterator(); i.hasNext();) {
        Element el = (Element) i.next();
        if (el.getNamespaceURI().equals(ERROR_NAMESPACE) && !el.getName().equals("text")) {
            conditionElement = el;
        }
    }
    if (conditionElement != null) {
        element.remove(conditionElement);
    }

    conditionElement = docFactory.createElement(condition.toXMPP(), ERROR_NAMESPACE);
    element.add(conditionElement);
}

From source file:com.sun.xml.ws.test.container.invm.InVmContainer.java

License:Open Source License

private Element getSoapAddress(Element port) {
    for (Object obj : port.elements()) {
        Element address = (Element) obj;

        //it might be extensibility element, just skip it
        if (!address.getName().equals("address"))
            continue;

        if (address.getNamespaceURI().equals("http://schemas.xmlsoap.org/wsdl/soap/")
                || address.getNamespaceURI().equals("http://schemas.xmlsoap.org/wsdl/soap12/"))
            return address;
    }/*from   w ww  .j ava  2s.c  o m*/
    return null;
}

From source file:com.tedi.engine.XMLOutput.java

License:Open Source License

/**
 * Add name space prefixes to the element.
 * /*w ww .j  a v  a2  s.c  o  m*/
 * @param ele
 *            The element.
 * @param nsMap
 *            The name space map.
 */
private void addNSPrefixToElement(org.w3c.dom.Element ele, Map nsMap) {

    if (logger.isDebugEnabled()) {
        logger.debug("Adding name space prefixes to the element object.");
    }

    String uri = ele.getNamespaceURI();
    if (uri != null && nsMap.get(uri) != null) {
        ele.setPrefix(nsMap.get(uri).toString());
    }
    org.w3c.dom.NodeList children = ele.getChildNodes();
    for (int i = 0, len = children.getLength(); i < len; i++) {
        if (children.item(i) instanceof org.w3c.dom.Element) {
            addNSPrefixToElement((org.w3c.dom.Element) children.item(i), nsMap);
        }
    }
}

From source file:com.test.android.push.xmpp.net.StanzaHandler.java

License:Open Source License

private IQ getIQ(Element doc) {
    log.debug("getIQ() start...");
    Element query = doc.element("query");
    if (query != null && "jabber:iq:roster".equals(query.getNamespaceURI())) {
        log.debug("getIQ() end...");
        return new Roster(doc);
    } else {//from ww  w .  j a  v a 2 s. com
        log.debug("getIQ() end...");
        return new IQ(doc, false);
    }
}

From source file:com.thinkberg.webdav.data.AbstractDavResource.java

License:Apache License

/**
 * Get property values. This method expects one of either &lt;allprop&gt;, &lt;propnames&gt; or
 * &lt;prop&gt;. If the element is &lt;prop&gt; it will go through the list of it's children
 * and request the values. For &lt;allprop&gt; it will get values of all known properties and
 * &lt;propnames&gt; will return the names of all known properties.
 *
 * @param root       the root of the result document
 * @param propertyEl the prop, propname or allprop element
 * @return the root of the result document
 *//*from w  ww. j  av  a 2 s  .  c  o  m*/
public Element getPropertyValues(Element root, Element propertyEl) {
    // initialize the <propstat> for 200
    Element okPropStatEl = root.addElement(TAG_PROPSTAT);
    Element okPropEl = okPropStatEl.addElement(TAG_PROP);

    // initialize the <propstat> element for 404
    Element failPropStatEl = root.addElement(TAG_PROPSTAT);
    Element failPropEl = failPropStatEl.addElement(TAG_PROP);

    if (TAG_ALLPROP.equalsIgnoreCase(propertyEl.getName())
            || TAG_PROPNAMES.equalsIgnoreCase(propertyEl.getName())) {
        boolean ignoreValue = TAG_PROPNAMES.equalsIgnoreCase(propertyEl.getName());

        // get all known standard properties
        for (String propName : ALL_PROPERTIES) {
            if (!getPropertyValue(okPropEl, propName, ignoreValue)) {
                failPropEl.addElement(propName);
            }
        }

        // additionally try to add all the custom properties
        try {
            FileContent objectContent = object.getContent();
            for (String attributeName : objectContent.getAttributeNames()) {
                if (!getPropertyValue(okPropEl, attributeName, ignoreValue)) {
                    failPropEl.addElement(attributeName);
                }
            }
        } catch (FileSystemException e) {
            LogFactory.getLog(getClass())
                    .error(String.format("can't read attribute properties from '%s'", object.getName()), e);
        }
    } else {
        List requestedProperties = propertyEl.elements();
        for (Object propertyElObject : requestedProperties) {
            Element propEl = (Element) propertyElObject;
            final String nameSpace = propEl.getNamespaceURI();
            if (!getPropertyValue(okPropEl, getFQName(nameSpace, propEl.getName()), false)) {
                failPropEl.addElement(propEl.getQName());
            }
        }
    }

    // only add the OK section, if there is content
    if (okPropEl.elements().size() > 0) {
        okPropStatEl.addElement(TAG_STATUS).addText(STATUS_200);
    } else {
        okPropStatEl.detach();
    }

    // only add the failed section, if there is content
    if (failPropEl.elements().size() > 0) {
        failPropStatEl.addElement(TAG_STATUS).addText(STATUS_404);
    } else {
        failPropStatEl.detach();
    }

    return root;
}