Example usage for org.dom4j Element setQName

List of usage examples for org.dom4j Element setQName

Introduction

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

Prototype

void setQName(QName qname);

Source Link

Document

Sets the QName of this element which represents the local name, the qualified name and the Namespace.

Usage

From source file:org.etudes.component.app.melete.MeleteImportServiceImpl.java

License:Apache License

private void removeNamespaces(Element elem) {
    elem.setQName(QName.get(elem.getName(), Namespace.NO_NAMESPACE, elem.getQualifiedName()));
    Node n = null;//from   w w  w . j a  v  a 2  s . co  m
    for (int i = 0; i < elem.content().size(); i++) {
        n = (Node) elem.content().get(i);
        if (n.getNodeType() == Node.ATTRIBUTE_NODE)
            ((Attribute) n).setNamespace(Namespace.NO_NAMESPACE);
        if (n.getNodeType() == Node.ELEMENT_NODE)
            removeNamespaces((Element) n);
    }
}

From source file:org.etudes.jforum.view.admin.ImportExportAction.java

License:Apache License

/**
 * creates the default namespace element
 * //from www  .j av a  2 s  .  c  o  m
 * @param elename
 *            - element name
 * @param qname
 *            - qualified name
 * @return - returns the default namespace element
 */
private Element createDefaultNSElement(String elename, String qname) {
    Element metadata = DocumentHelper.createElement(elename);
    metadata.setQName(new QName(qname, new Namespace(null, DEFAULT_NAMESPACE_URI)));
    return metadata;
}

From source file:org.etudes.jforum.view.admin.ImportExportAction.java

License:Apache License

/**
 * creates the LOM metadata element// w ww  . j  av a2 s . co  m
 * 
 * @param elename
 *            - element name
 * @param qname
 *            - qualified name
 * @return - returns the metadata element
 */
private Element createLOMElement(String elename, String qname) {

    Element imsmdlom = DocumentHelper.createElement(elename);
    imsmdlom.setQName(new QName(qname, new Namespace("imsmd", IMSMD_NAMESPACE_URI)));

    return imsmdlom;
}

From source file:org.intalio.tempo.workflow.fds.core.UserProcessMessageConvertor.java

License:Open Source License

/**
 * Converts a SOAP message from a user process to the WorkflowProcesses
 * format. <br>/* ww  w . j a  v  a 2  s  .c  om*/
 * The conversion is done in-place. The passed <code>Document</code>
 * instance gets converted to the Workflow Processes format and its previous
 * format is lost.
 * 
 * @param message
 *            The SOAP message from a user process to convert to the
 *            Workflow Processes format.
 * @throws MessageFormatException
 *             If the specified message has an invalid format. Note that if
 *             this exception is thrown, <code>message</code> may have
 *             already been partly processed and therefore should be assumed
 *             to be corrupted.
 */
@SuppressWarnings("unchecked")
public void convertMessage(Document message) throws MessageFormatException, AxisFault {
    FormDispatcherConfiguration config = FormDispatcherConfiguration.getInstance();

    XPath xpath = null;
    xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body/soapenv:Fault");
    List<Node> fault = xpath.selectNodes(message);
    if (fault.size() != 0)
        throw new RuntimeException(fault.toString());

    // Check SOAP action
    xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body");
    xpath.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> bodyQueryResult = xpath.selectNodes(message);
    if (bodyQueryResult.size() != 0) {
        Element root = (Element) bodyQueryResult.get(0);
        if (root.asXML().indexOf("createTaskRequest") != -1) {
            _soapAction = "createTask";
            xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Header/addr:Action");
            xpath.setNamespaceURIs(MessageConstants.get_nsMap());
            List<Node> wsaActionQueryResult = xpath.selectNodes(message);
            if (wsaActionQueryResult.size() != 0) {
                Element wsaToElement = (Element) wsaActionQueryResult.get(0);
                wsaToElement.setText(_soapAction);
            } else
                _log.warn("Did not find addr:Action in SOAP header");
        }
    }
    _log.debug("Converted SOAP Action: " + _soapAction);

    /*
     * Change the wsa:To endpoint to Workflow Processes, if a wsa:To header
     * is present.
     */
    xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Header/addr:To");
    xpath.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> wsaToQueryResult = xpath.selectNodes(message);
    if (wsaToQueryResult.size() != 0) {
        Element wsaToElement = (Element) wsaToQueryResult.get(0);
        String workflowProcessesUrl = config.getPxeBaseUrl() + config.getWorkflowProcessesRelativeUrl();
        wsaToElement.setText(workflowProcessesUrl);
    } else
        _log.debug("Did not find addr:To in SOAP header");

    /*
     * Change the session address to be FDS endpoint and retrieve sender
     * endpoint
     */
    xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Header/intalio:callback/addr:Address");
    xpath.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> callbackToQueryResult = xpath.selectNodes(message);
    if (callbackToQueryResult.size() != 0) {
        Element wsaToElement = (Element) callbackToQueryResult.get(0);
        _userProcessEndpoint = wsaToElement.getText();
        wsaToElement.setText(config.getFdsUrl());
    } else
        _log.debug("Did not find intalio:callback/addr:Address in SOAP header");

    /* Next, fetch the user process namespace URI from the task metadata */
    /*
     * 1. fetch the first element of SOAP envelope body.
     */
    List<Node> allSoapBodyElements = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body//*")
            .selectNodes(message);
    if (allSoapBodyElements.size() == 0) {
        throw new MessageFormatException("No elements found inside soapenv:Body.");
    }
    Element firstPayloadElement = (Element) allSoapBodyElements.get(0);

    /*
     * 2. fetch its namespace and use it to fetch the userProcessEndpoint
     * and userProcessNamespaceURI element (which should be in the same
     * namespace). If those elements are not found, nothing is reported.
     * This is necessary for converting responses, where this information is
     * not present.
     */
    String messageNamespace = firstPayloadElement.getNamespaceURI();
    _userProcessNamespaceUri = messageNamespace;

    Map<String, String> namespaceURIs = new HashMap<String, String>(MessageConstants.get_nsMap());
    namespaceURIs.put(REQUEST_PREFIX, _userProcessNamespaceUri);

    /*
     * Add session in task meta data so that it can be retrieved when
     * workflow process needs to send a message to the user process
     */
    xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Header/intalio:callback/intalio:session");
    xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */);
    List<Node> sessionQueryResult = xpath.selectNodes(message);
    if (sessionQueryResult.size() != 0) {
        Element wsaToElement = (Element) sessionQueryResult.get(0);
        String session = wsaToElement.getText();
        xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":taskMetaData");
        xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */);
        List<Node> tmdQueryResult = xpath.selectNodes(message);
        Element tmdElement = (Element) tmdQueryResult.get(0);
        Element sessionElement = tmdElement.addElement("session", MessageConstants.IB4P_NS);
        sessionElement.setText(session);
    }

    // retrieve userProcessEndpoint from task meta data
    // or put sender endpoint in task meta data if not defined
    xpath = DocumentHelper
            .createXPath("//" + REQUEST_PREFIX + ":taskMetaData/" + REQUEST_PREFIX + ":userProcessEndpoint");
    xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */);
    List<Node> endpointQueryResult = xpath.selectNodes(message);
    if (endpointQueryResult.size() != 0) {
        Element userProcessEndpointElement = (Element) endpointQueryResult.get(0);
        String value = userProcessEndpointElement.getText();
        if (value != null && value.length() > 0)
            _userProcessEndpoint = value;
        else if (_userProcessEndpoint != null) {
            _log.info("User process endpoint is empty in task metadata, adding " + _userProcessEndpoint);
            userProcessEndpointElement.setText(_userProcessEndpoint);
        }
    } else if (_userProcessEndpoint != null) {
        _log.info("User process endpoint is not defined in task metadata, adding " + _userProcessEndpoint);
        xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":taskMetaData");
        xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */);
        List<Node> tmdQueryResult = xpath.selectNodes(message);
        if (tmdQueryResult.size() > 0) {
            Element wsaToElement = (Element) tmdQueryResult.get(0);
            Element nsElement = wsaToElement.addElement("userProcessEndpoint", MessageConstants.IB4P_NS);
            nsElement.setText(_userProcessEndpoint);
        }
    }

    // Add user process namespace to taskmetadata if not already defined
    xpath = DocumentHelper.createXPath(
            "//" + REQUEST_PREFIX + ":taskMetaData/" + REQUEST_PREFIX + ":userProcessNamespaceURI");
    xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */);
    List<Node> nsQueryResult = xpath.selectNodes(message);
    if (nsQueryResult.size() == 0 && _userProcessNamespaceUri != null) {
        xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":taskMetaData");
        xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */);
        List<Node> tmdQueryResult = xpath.selectNodes(message);
        if (tmdQueryResult.size() > 0) {
            _log.info("User process namespace is not defined in task metadata, adding "
                    + _userProcessNamespaceUri);
            Element wsaToElement = (Element) tmdQueryResult.get(0);
            Element nsElement = wsaToElement.addElement("userProcessNamespaceURI", MessageConstants.IB4P_NS);
            nsElement.setText(_userProcessNamespaceUri);
        }
    } else {
        Element wsaToElement = (Element) nsQueryResult.get(0);
        if (wsaToElement.getTextTrim().length() == 0) {
            _log.info("User process namespace is empty in task metadata, adding " + _userProcessNamespaceUri);
            wsaToElement.setText(_userProcessNamespaceUri);
        }
    }

    /*
     * Now, change the namespace of all soapenv:Body elements, except the
     * task input and the attachments, to ib4p.
     */
    xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":taskInput//*");
    xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */);
    List<Node> allTaskInputElements = xpath.selectNodes(message);
    xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":attachments//*");
    xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */);
    List<Node> allAttachmentsElements = xpath.selectNodes(message);
    for (int i = 0; i < allSoapBodyElements.size(); ++i) {
        Node node = (Node) allSoapBodyElements.get(i);
        if (!allTaskInputElements.contains(node) && !allAttachmentsElements.contains(node)) {

            Element element = (Element) node;
            element.remove(element.getNamespace());
            element.setQName(QName.get(element.getName(), "ib4p", MessageConstants.IB4P_NS));
        }
    }
}

From source file:org.intalio.tempo.workflow.fds.core.WorkflowProcessesMessageConvertor.java

License:Open Source License

/**
 * Converts a SOAP message from the Workflow Processes format to the format
 * of the user process the message is targetted for. <br>
 * The target user process is figured out from the message payload. <br>
 * The conversion is done in-place. The passed <code>Document</code>
 * instance gets converted to the user process format and its previous
 * format is lost.//from w w  w.ja  va 2  s  .c o m
 * 
 * @param message
 *            The SOAP message coming from the Workflow Processes to convert
 *            to the user process format.
 * @param userProcessNamespaceUri
 *            The user process namespace URI. Should be <code>null</code>
 *            when converting the <i>requests</i>. Must be specified when
 *            converting the <i>replies</i>, since in this case no
 *            information about the target user process is specified inside
 *            the message.
 * @throws MessageFormatException
 *             If the specified message has an invalid format. Note that if
 *             this exception is thrown, <code>message</code> may have
 *             already been partly processed and therefore should be assumed
 *             to be corrupted.
 */
@SuppressWarnings("unchecked")
public void convertMessage(Document message, String userProcessNamespaceUri) throws MessageFormatException {
    XPath xpathSelector = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body/soapenv:Fault");
    xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> fault = xpathSelector.selectNodes(message);
    if (fault.size() != 0) {
        // return fault as-is
        LOG.error("Fault in response:\n" + message.asXML());
        return;
    }

    //retrieve session
    xpathSelector = DocumentHelper
            .createXPath("/soapenv:Envelope/soapenv:Body/*[1]/ib4p:taskMetaData/ib4p:session");
    xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> sessionNodes = xpathSelector.selectNodes(message);
    if (sessionNodes.size() > 0) {
        Element sessionElement = (Element) sessionNodes.get(0);
        String session = sessionElement.getText();

        //remove callback
        xpathSelector = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Header/intalio:callback");
        xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
        List<Node> callbackNodes = xpathSelector.selectNodes(message);
        if (callbackNodes.size() != 0) {
            Element wsaTo = (Element) callbackNodes.get(0);
            Element header = (Element) wsaTo.getParent();
            header.remove(wsaTo);
            sessionElement = header.addElement("session", MessageConstants.INTALIO_NS);
            sessionElement.setText(session);
        }
    }

    /* fetch the user process endpoint element from the task metadata */
    xpathSelector = DocumentHelper
            .createXPath("/soapenv:Envelope/soapenv:Body/*[1]/ib4p:taskMetaData/ib4p:userProcessEndpoint");
    xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> userProcessEndpointNodes = xpathSelector.selectNodes(message);
    if (userProcessEndpointNodes.size() > 0) {
        /* found the user process endpoint element */
        Element userProcessEndpointElement = (Element) userProcessEndpointNodes.get(0);
        /* save it for later use */
        _userProcessEndpoint = userProcessEndpointElement.getText();

        /* do we have a wsa:To element? */
        xpathSelector = DocumentHelper.createXPath("//wsa:To");
        xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
        List<Node> wsaToNodes = xpathSelector.selectNodes(message);
        if (wsaToNodes.size() != 0) {
            /* We have the wsa:To element. Set the correct target endpoint */
            Element wsaTo = (Element) wsaToNodes.get(0);
            wsaTo.setText(_userProcessEndpoint);
        }

        /* do we have a addr:To element? */
        xpathSelector = DocumentHelper.createXPath("//addr:To");
        xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
        List<Node> addrToNodes = xpathSelector.selectNodes(message);
        if (addrToNodes.size() != 0) {
            /* We have the wsa:To element. Set the correct target endpoint */
            Element wsaTo = (Element) addrToNodes.get(0);
            //wsaTo.removeChildren();
            wsaTo.setText(_userProcessEndpoint);
        }
    }

    /*
     * If the user process namespace URI is not specified explicitly, the
     * userProcessNamespaceURI element must be present in the metadata
     * section.
     */
    if (userProcessNamespaceUri == null) {
        xpathSelector = DocumentHelper.createXPath(
                "/soapenv:Envelope/soapenv:Body/*[1]/ib4p:taskMetaData/ib4p:userProcessNamespaceURI");
        xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
        List<Node> namespaceElementQueryResult = xpathSelector.selectNodes(message);
        if (namespaceElementQueryResult.size() == 0) {
            throw new MessageFormatException("No user process namespace specified "
                    + "and no ib4p:userProcessNamespaceURI element present to determine those.");
        }
        Element userProcessNamespaceUriElement = (Element) namespaceElementQueryResult.get(0);
        userProcessNamespaceUri = userProcessNamespaceUriElement.getText();
        _userProcessNamespaceUri = userProcessNamespaceUri;
    }

    xpathSelector = DocumentHelper.createXPath(
            "/soapenv:Envelope/soapenv:Body/*[1]/ib4p:taskMetaData/ib4p:userProcessCompleteSOAPAction");
    xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> soapActionQueryResult = xpathSelector.selectNodes(message);
    if (soapActionQueryResult.size() > 0) {
        Element soapActionElement = (Element) soapActionQueryResult.get(0);
        _soapAction = soapActionElement.getText();

        xpathSelector = DocumentHelper.createXPath("//addr:Action");
        xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
        List<Node> actionNodes = xpathSelector.selectNodes(message);
        if (actionNodes.size() > 0) {
            Element wsaTo = (Element) actionNodes.get(0);
            //wsaTo.removeChildren();
            wsaTo.setText(_soapAction);
        }
    }

    // TODO: generate a unique namespace prefix?
    String userProcessNamespace = "userProcess";

    /* Select all elements inside the soap envelope body. */
    xpathSelector = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body//*");
    xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> bodyNodes = xpathSelector.selectNodes(message);
    /* Select all elements inside the task output payload. */
    xpathSelector = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body/*[1]/ib4p:taskOutput//*");
    xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> taskOutputNodes = xpathSelector.selectNodes(message);
    /* Select all the attachments. */
    xpathSelector = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body//ib4p:attachments//*");
    xpathSelector.setNamespaceURIs(MessageConstants.get_nsMap());
    List<Node> attachementsNode = xpathSelector.selectNodes(message);

    /*
     * Change namespace for all the elements which are inside the soap
     * envelope body but not inside the task output payload.
     */
    for (int i = 0; i < bodyNodes.size(); ++i) {
        Node node = (Node) bodyNodes.get(i);

        if (!taskOutputNodes.contains(node) && !attachementsNode.contains(node)) {
            Element element = (Element) node;
            element.remove(element.getNamespace());
            element.setQName(QName.get(element.getName(), userProcessNamespace, userProcessNamespaceUri));
        }
    }
}

From source file:org.intalio.tempo.workflow.fds.dispatches.EscalateDispatcher.java

License:Open Source License

public Document dispatchRequest(Document request) throws InvalidInputFormatException {
    Namespace ns = new Namespace(NS_PREFIX, NS_URI);
    Element rootElement = request.getRootElement();
    userProcessNamespace = rootElement.getNamespaceURI();
    userProcessPrefix = rootElement.getNamespacePrefix();
    List nodes = DocumentHelper.createXPath("//*").selectNodes(request);
    for (int i = 0; i < nodes.size(); ++i) {
        Element element = (Element) nodes.get(i);
        element.remove(element.getNamespaceForURI(userProcessNamespace));
        element.setQName(new QName(element.getName(), ns));
    }//from  www  .  j  a  v  a 2s .  co  m

    rootElement.setQName(new QName("escalateTaskRequest", ns));
    // TODO: fix this in VC!
    return request;
}

From source file:org.intalio.tempo.workflow.fds.dispatches.EscalateDispatcher.java

License:Open Source License

public Document dispatchResponse(Document response) throws InvalidInputFormatException {
    // TODO: process the TMP response
    Namespace ns = new Namespace(userProcessPrefix, userProcessNamespace);
    response.getRootElement().setName("escalateResponse");
    List nodes = DocumentHelper.createXPath("//*").selectNodes(response);
    for (int i = 0; i < nodes.size(); ++i) {
        Element element = (Element) nodes.get(i);
        element.remove(element.getNamespaceForURI(NS_URI));
        element.setQName(new QName(element.getName(), ns));
    }//from w ww .  ja v  a 2  s . c  o  m
    return response;
}

From source file:org.intalio.tempo.workflow.fds.dispatches.NotifyDispatcher.java

License:Open Source License

public Document dispatchRequest(Document request) throws InvalidInputFormatException {
    Element rootElement = request.getRootElement();
    userProcessNamespace = rootElement.getNamespaceURI();

    Namespace ns = new Namespace("tms", TMS_NS);
    rootElement.setQName(new QName("createTaskRequest", ns));

    Element metadataElement = rootElement.element("metadata");
    metadataElement.setQName(new QName("metadata", ns));
    metadataElement.detach();/*from   w  w w  .  j  a v  a2  s .c om*/

    Element taskElement = rootElement.addElement("task");
    taskElement.setQName(new QName("task", ns));

    taskElement.add(metadataElement);
    if (metadataElement.selectSingleNode("taskId") == null) {
        Element taskIdElement = metadataElement.addElement(new QName("taskId", ns));
        taskIdElement.setText(generateUID());
    }
    if (metadataElement.selectSingleNode("taskType") == null) {
        Element taskTypeElement = metadataElement.addElement(new QName("taskType", ns));
        taskTypeElement.setText("NOTIFICATION");
    }

    Element inputElement = rootElement.element("input");
    inputElement.setQName(new QName("input", ns));
    //inputElement.addNamespace("fe", userProcessNamespace);
    inputElement.detach();
    taskElement.add(inputElement);

    //TODO remove from TMS. Not needed
    rootElement.addElement("participantToken");

    /*
     * Now, change the namespace the
     * input, to TMS_NS.
     */

    XPath xpath = DocumentHelper.createXPath("/tms:createTaskRequest/tms:task/tms:input//*");
    HashMap map = MessageConstants._nsMap;
    map.put("tms", TMS_NS);
    xpath.setNamespaceURIs(MessageConstants._nsMap);
    List allTaskInputElements = xpath.selectNodes(request);

    xpath = DocumentHelper.createXPath("//*");
    List allBody = xpath.selectNodes(request);
    int size = allBody.size();
    LOG.debug(allTaskInputElements.size() + ":" + size);
    for (int i = 0; i < size; ++i) {
        Node node = (Node) allBody.get(i);
        if (!allTaskInputElements.contains(node)) {
            Element element = (Element) node;
            element.remove(element.getNamespaceForURI(userProcessNamespace));
            element.setQName(new QName(element.getName(), ns));
        }
    }

    return request;
}

From source file:org.jage.platform.config.xml.loaders.ComponentsNormalizer.java

License:Open Source License

@Override
public Document loadDocument(final String path) throws ConfigurationException {
    final Document document = getDelegate().loadDocument(path);

    Namespace namespace = createNamespace("", ConfigNamespaces.DEFAULT.getUri());
    for (Element element : selectNodes(AGENTS, document)) {
        element.setQName(DocumentHelper.createQName(COMPONENT.toString(), namespace));
        element.addAttribute(IS_SINGLETON.toString(), "false");
    }//from  ww w. j av  a  2 s .c  o m
    for (Element element : selectNodes(STRATEGIES, document)) {
        element.setQName(DocumentHelper.createQName(COMPONENT.toString(), namespace));
        element.addAttribute(IS_SINGLETON.toString(), "true");
    }
    return document;
}

From source file:org.jivesoftware.openfire.disco.IQDiscoInfoHandler.java

License:Open Source License

@Override
public IQ handleIQ(IQ packet) {
    // Create a copy of the sent pack that will be used as the reply
    // we only need to add the requested info to the reply if any otherwise add 
    // a not found error
    IQ reply = IQ.createResultIQ(packet);

    // Look for a DiscoInfoProvider associated with the requested entity.
    // We consider the host of the recipient JID of the packet as the entity. It's the 
    // DiscoInfoProvider responsibility to provide information about the JID's name together 
    // with any possible requested node.  
    DiscoInfoProvider infoProvider = getProvider(
            packet.getTo() == null ? XMPPServer.getInstance().getServerInfo().getXMPPDomain()
                    : packet.getTo().getDomain());
    if (infoProvider != null) {
        // Get the JID's name
        String name = packet.getTo() == null ? null : packet.getTo().getNode();
        if (name == null || name.trim().length() == 0) {
            name = null;// w  ww  .ja v a 2 s  .  c  om
        }
        // Get the requested node
        Element iq = packet.getChildElement();
        String node = iq.attributeValue("node");
        //String node = metaData.getProperty("query:node");

        // Check if we have information about the requested name and node
        if (infoProvider.hasInfo(name, node, packet.getFrom())) {
            reply.setChildElement(iq.createCopy());
            Element queryElement = reply.getChildElement();

            // Add to the reply all the identities provided by the DiscoInfoProvider
            Element identity;
            Iterator<Element> identities = infoProvider.getIdentities(name, node, packet.getFrom());
            while (identities.hasNext()) {
                identity = identities.next();
                identity.setQName(new QName(identity.getName(), queryElement.getNamespace()));
                queryElement.add((Element) identity.clone());
            }

            // Add to the reply all the features provided by the DiscoInfoProvider
            Iterator<String> features = infoProvider.getFeatures(name, node, packet.getFrom());
            boolean hasDiscoInfoFeature = false;
            boolean hasDiscoItemsFeature = false;
            boolean hasResultSetManagementFeature = false;

            while (features.hasNext()) {
                final String feature = features.next();
                queryElement.addElement("feature").addAttribute("var", feature);
                if (feature.equals(NAMESPACE_DISCO_INFO)) {
                    hasDiscoInfoFeature = true;
                } else if (feature.equals("http://jabber.org/protocol/disco#items")) {
                    hasDiscoItemsFeature = true;
                } else if (feature.equals(ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)) {
                    hasResultSetManagementFeature = true;
                }
            }

            if (hasDiscoItemsFeature && !hasResultSetManagementFeature) {
                // IQDiscoItemsHandler provides result set management
                // support.
                queryElement.addElement("feature").addAttribute("var",
                        ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT);
            }

            if (!hasDiscoInfoFeature) {
                // XEP-0030 requires that every entity that supports service
                // discovery broadcasts the disco#info feature.
                queryElement.addElement("feature").addAttribute("var", NAMESPACE_DISCO_INFO);
            }

            // Add to the reply the extended info (XDataForm) provided by the DiscoInfoProvider
            DataForm dataForm = infoProvider.getExtendedInfo(name, node, packet.getFrom());
            if (dataForm != null) {
                queryElement.add(dataForm.getElement());
            }
        } else {
            // If the DiscoInfoProvider has no information for the requested name and node 
            // then answer a not found error
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.item_not_found);
        }
    } else {
        // If we didn't find a DiscoInfoProvider then answer a not found error
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.item_not_found);
    }

    return reply;
}