Example usage for org.dom4j QName QName

List of usage examples for org.dom4j QName QName

Introduction

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

Prototype

public QName(String name, Namespace namespace) 

Source Link

Usage

From source file:org.jinglenodes.credit.CreditServiceProcessor.java

License:Open Source License

public CreditServiceProcessor(final String elementName, final String xmlns) {
    this.xmlns = xmlns;
    this.requestElement = DocumentHelper.createElement(new QName(elementName, new Namespace("", xmlns)));
}

From source file:org.jinglenodes.relay.RelayEventIQ.java

License:Open Source License

public Element getChildElement() {

    final Element element = DocumentHelper.createElement(new QName(ELEMENT_NAME, new Namespace("", NAMESPACE)));

    if (event != null) {
        element.addAttribute("event", event);
    }/*w w  w.j  a  v  a  2  s  .  c o m*/

    if (event != null) {
        element.addAttribute("time", event);
    }

    if (channelId != null) {
        element.addAttribute("id", channelId);
    }
    return element;

}

From source file:org.jinglenodes.relay.RelayIQ.java

License:Open Source License

public Element getChildElement() {

    final Element element = DocumentHelper.createElement(new QName(ELEMENT_NAME, new Namespace("", NAMESPACE)));

    if (host != null) {
        element.addAttribute("host", host);
    }/* w w  w  .j  ava2 s .c  om*/

    element.addAttribute("localport", localport);

    element.addAttribute("remoteport", remoteport);

    if (channelId != null) {
        element.addAttribute("id", channelId);
    }
    if (protocol != null) {
        element.addAttribute("protocol", protocol);
    }

    return element;

}

From source file:org.jinglenodes.relay.RelayRedirectIQ.java

License:Open Source License

public Element getChildElement() {

    final Element element = DocumentHelper.createElement(new QName(ELEMENT_NAME, new Namespace("", NAMESPACE)));

    if (host != null) {
        element.addAttribute("host", host);
    }/* www . jav a  2 s .c o  m*/

    element.addAttribute("port", port);

    if (channelId != null) {
        element.addAttribute("id", channelId);
    }
    return element;

}

From source file:org.jivesoftware.multiplexer.net.http.HttpSession.java

License:Open Source License

/**
 * Returns the stream features which are available for this session.
 *
 * @return the stream features which are available for this session.
 *//*from w w  w .j a va2 s  .c  om*/
public Collection<Element> getAvailableStreamFeaturesElements() {
    List<Element> elements = new ArrayList<Element>();

    Element sasl = connectionManager.getServerSurrogate().getSASLMechanismsElement(this);
    if (sasl != null) {
        elements.add(sasl);
    }

    Element bind = DocumentHelper
            .createElement(new QName("bind", new Namespace("", "urn:ietf:params:xml:ns:xmpp-bind")));
    elements.add(bind);

    Element session = DocumentHelper
            .createElement(new QName("session", new Namespace("", "urn:ietf:params:xml:ns:xmpp-session")));
    elements.add(session);
    return elements;
}

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;/*from   www .ja  va 2s .c o m*/
        }
        // 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;
}

From source file:org.jivesoftware.openfire.disco.IQDiscoItemsHandler.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 items to the reply if any otherwise add 
    // a not found error
    IQ reply = IQ.createResultIQ(packet);

    // TODO Implement publishing client items
    if (IQ.Type.set == packet.getType()) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.feature_not_implemented);
        return reply;
    }//w w  w .j a va2  s .  c  o  m

    // Look for a DiscoItemsProvider associated with the requested entity.
    // We consider the host of the recipient JID of the packet as the entity. It's the 
    // DiscoItemsProvider responsibility to provide the items associated with the JID's name  
    // together with any possible requested node.
    DiscoItemsProvider itemsProvider = getProvider(
            packet.getTo() == null ? XMPPServer.getInstance().getServerInfo().getXMPPDomain()
                    : packet.getTo().getDomain());
    if (itemsProvider != null) {
        // Get the JID's name
        String name = packet.getTo() == null ? null : packet.getTo().getNode();
        if (name == null || name.trim().length() == 0) {
            name = null;
        }
        // Get the requested node
        Element iq = packet.getChildElement();
        String node = iq.attributeValue("node");

        // Check if we have items associated with the requested name and node
        Iterator<DiscoItem> itemsItr = itemsProvider.getItems(name, node, packet.getFrom());
        if (itemsItr != null) {
            reply.setChildElement(iq.createCopy());
            Element queryElement = reply.getChildElement();

            // See if the requesting entity would like to apply 'result set
            // management'
            final Element rsmElement = packet.getChildElement()
                    .element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT));

            // apply RSM only if the element exists, and the (total) results
            // set is not empty.
            final boolean applyRSM = rsmElement != null && itemsItr.hasNext();

            if (applyRSM) {
                if (!ResultSet.isValidRSMRequest(rsmElement)) {
                    reply.setError(PacketError.Condition.bad_request);
                    return reply;
                }

                // Calculate which results to include.
                final List<DiscoItem> rsmResults;
                final List<DiscoItem> allItems = new ArrayList<DiscoItem>();
                while (itemsItr.hasNext()) {
                    allItems.add(itemsItr.next());
                }
                final ResultSet<DiscoItem> rs = new ResultSetImpl<DiscoItem>(allItems);
                try {
                    rsmResults = rs.applyRSMDirectives(rsmElement);
                } catch (NullPointerException e) {
                    final IQ itemNotFound = IQ.createResultIQ(packet);
                    itemNotFound.setError(PacketError.Condition.item_not_found);
                    return itemNotFound;
                }

                // add the applicable results to the IQ-result
                for (DiscoItem item : rsmResults) {
                    final Element resultElement = item.getElement();
                    resultElement.setQName(new QName(resultElement.getName(), queryElement.getNamespace()));
                    queryElement.add(resultElement.createCopy());
                }

                // overwrite the 'set' element.
                queryElement.remove(
                        queryElement.element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)));
                queryElement.add(rs.generateSetElementFromResults(rsmResults));
            } else {
                // don't apply RSM:
                // Add to the reply all the items provided by the DiscoItemsProvider
                Element item;
                while (itemsItr.hasNext()) {
                    item = itemsItr.next().getElement();
                    item.setQName(new QName(item.getName(), queryElement.getNamespace()));
                    queryElement.add(item.createCopy());
                }
            }
        } else {
            // If the DiscoItemsProvider has no items 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 DiscoItemsProvider then answer a not found error
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.item_not_found);
    }

    return reply;
}

From source file:org.jivesoftware.openfire.http.HttpBindBody.java

License:Open Source License

public boolean isPoll() {
    boolean isPoll = isEmpty();
    if ("terminate".equals(document.getRootElement().attributeValue("type"))) {
        isPoll = false;// w  ww  .  j  a va  2s.co  m
    } else if ("true".equals(document.getRootElement()
            .attributeValue(new QName("restart", document.getRootElement().getNamespaceForPrefix("xmpp"))))) {
        isPoll = false;
    } else if (document.getRootElement().attributeValue("pause") != null) {
        isPoll = false;
    }

    return isPoll;
}

From source file:org.jivesoftware.openfire.http.HttpBindBody.java

License:Open Source License

public boolean isRestart() {
    final String restart = document.getRootElement()
            .attributeValue(new QName("restart", document.getRootElement().getNamespaceForPrefix("xmpp")));
    return "true".equals(restart);
}

From source file:org.jivesoftware.openfire.http.HttpSession.java

License:Open Source License

/**
 * Returns the stream features which are available for this session.
 *
 * @return the stream features which are available for this session.
 *///from  ww w  .  jav a 2s. com
public Collection<Element> getAvailableStreamFeaturesElements() {
    List<Element> elements = new ArrayList<Element>();

    if (getAuthToken() == null) {
        Element sasl = SASLAuthentication.getSASLMechanismsElement(this);
        if (sasl != null) {
            elements.add(sasl);
        }
    }

    if (XMPPServer.getInstance().getIQRegisterHandler().isInbandRegEnabled()) {
        elements.add(DocumentHelper.createElement(
                new QName("register", new Namespace("", "http://jabber.org/features/iq-register"))));
    }
    Element bind = DocumentHelper
            .createElement(new QName("bind", new Namespace("", "urn:ietf:params:xml:ns:xmpp-bind")));
    elements.add(bind);

    Element session = DocumentHelper
            .createElement(new QName("session", new Namespace("", "urn:ietf:params:xml:ns:xmpp-session")));
    session.addElement("optional");
    elements.add(session);
    return elements;
}