Example usage for org.dom4j Namespace get

List of usage examples for org.dom4j Namespace get

Introduction

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

Prototype

public static Namespace get(String uri) 

Source Link

Document

A helper method to return the Namespace instance for no prefix and the URI

Usage

From source file:org.openzal.zal.soap.InternalDocumentService.java

License:Open Source License

@Override
public void registerHandlers(DocumentDispatcher dispatcher) {
    mHandlerMapPublisher.receivedHandlerMap(dispatcher.getHandlers());

    Map<QName, ? extends SoapHandler> services = mSoapService.getServices();
    for (Map.Entry<QName, ? extends SoapHandler> entry : services.entrySet()) {
        QName qName = entry.getKey();
        org.dom4j.QName zimbraQName = new org.dom4j.QName(qName.getName(), Namespace.get(qName.getNamespace()));

        dispatcher.registerHandler(zimbraQName, wrapHandler(entry.getValue()));
    }//from  w w w .ja  va2  s .c  o  m
}

From source file:org.openzal.zal.soap.InternalOverrideDocumentServiceImpl.java

License:Open Source License

@Override
public void registerHandlers(DocumentDispatcher dispatcher) {
    // these are latest original handlers, they may be already overriden
    Map<org.dom4j.QName, DocumentHandler> oringinalHandlers = dispatcher.getHandlers();
    mHandlerMapPublisher.receivedHandlerMap(oringinalHandlers);

    Map<QName, OverridenSoapHandler> services = mSoapService.getServices();
    for (Map.Entry<QName, OverridenSoapHandler> entry : services.entrySet()) {
        QName qName = entry.getKey();
        org.dom4j.QName zimbraQName = new org.dom4j.QName(qName.getName(), Namespace.get(qName.getNamespace()));

        DocumentHandler originalDocumentHandler = null;
        if (mOriginalHandlers.containsKey(zimbraQName)) {
            originalDocumentHandler = mOriginalHandlers.get(zimbraQName);
            entry.getValue().setOriginalHandler(unWrapHandler(originalDocumentHandler));
        }//from w w w.java 2 s. com

        if (originalDocumentHandler != null) {
            dispatcher.registerHandler(zimbraQName, wrapHandler(entry.getValue(), originalDocumentHandler));
        } else {
            ZimbraLog.extensions.warn("Unable to proxy SOAP Request: " + zimbraQName.toString());
        }
    }
}

From source file:org.openzal.zal.soap.InternalRestoreDocumentService.java

License:Open Source License

@Override
public void registerHandlers(@NotNull DocumentDispatcher dispatcher) {
    Map<QName, ? extends SoapHandler> services = mSoapService.getServices();
    for (QName qName : services.keySet()) {
        org.dom4j.QName zimbraQName = new org.dom4j.QName(qName.getName(), Namespace.get(qName.getNamespace()));

        dispatcher.unRegisterHandler(zimbraQName);

        if (mOriginalHandlersMap.containsKey(zimbraQName)) {
            dispatcher.registerHandler(zimbraQName, mOriginalHandlersMap.get(zimbraQName));
        }//from   w  w  w.  jav  a2 s . com
    }
}

From source file:org.openzal.zal.soap.InternalUnregisterDocumentService.java

License:Open Source License

@Override
public void registerHandlers(@NotNull DocumentDispatcher dispatcher) {
    Map<QName, ? extends SoapHandler> services = mSoapService.getServices();
    for (QName qName : services.keySet()) {
        org.dom4j.QName zimbraQName = new org.dom4j.QName(qName.getName(), Namespace.get(qName.getNamespace()));

        dispatcher.unRegisterHandler(zimbraQName);
    }/*w  ww  . j a  v  a2 s .co  m*/
}

From source file:org.xmpp.packet.Roster.java

License:Open Source License

/**
 * Adds a new item to the roster. If the roster packet already contains an item
 * using the same JID, the information in the existing item will be overwritten
 * with the new information.<p>//from w w  w . j a va 2 s.  c om
 *
 * The XMPP specification recommends that if the roster item is associated with another
 * instant messaging user (human), that the JID be in bare form (e.g. user@domain).
 * Use the {@link JID#toBareJID() toBareJID()} method for a bare JID.
 *
 * @param jid the JID.
 * @param name the nickname.
 * @param ask the ask type.
 * @param subscription the subscription type.
 * @param groups a Collection of groups.
 * @return the newly created item.
 */
public Item addItem(JID jid, String name, Ask ask, Subscription subscription, Collection<String> groups) {
    if (jid == null) {
        throw new NullPointerException("JID cannot be null");
    }
    if (subscription == null) {
        throw new NullPointerException("Subscription cannot be null");
    }
    Element query = element.element(new QName("query", Namespace.get("jabber:iq:roster")));
    if (query == null) {
        query = element.addElement("query", "jabber:iq:roster");
    }
    Element item = null;
    for (Iterator i = query.elementIterator("item"); i.hasNext();) {
        Element el = (Element) i.next();
        if (el.attributeValue("jid").equals(jid.toString())) {
            item = el;
        }
    }
    if (item == null) {
        item = query.addElement("item");
    }
    item.addAttribute("jid", jid.toBareJID());
    item.addAttribute("name", name);
    if (ask != null) {
        item.addAttribute("ask", ask.toString());
    }
    item.addAttribute("subscription", subscription.toString());
    // Erase existing groups in case the item previously existed.
    for (Iterator i = item.elementIterator("group"); i.hasNext();) {
        item.remove((Element) i.next());
    }
    // Add in groups.
    if (groups != null) {
        for (String group : groups) {
            item.addElement("group").setText(group);
        }
    }
    return new Item(jid, name, ask, subscription, groups);
}

From source file:org.xmpp.packet.Roster.java

License:Open Source License

/**
 * Removes an item from this roster.//from   ww w.  ja v  a  2 s.  com
 *
 * @param jid the JID of the item to remove.
 */
public void removeItem(JID jid) {
    Element query = element.element(new QName("query", Namespace.get("jabber:iq:roster")));
    if (query != null) {
        for (Iterator i = query.elementIterator("item"); i.hasNext();) {
            Element item = (Element) i.next();
            if (item.attributeValue("jid").equals(jid.toString())) {
                query.remove(item);
                return;
            }
        }
    }
}

From source file:org.xmpp.packet.Roster.java

License:Open Source License

/**
 * Returns an unmodifiable copy of the {@link Item Items} in the roster packet.
 *
 * @return an unmodifable copy of the {@link Item Items} in the roster packet.
 *//*w  ww . j  a va2s  .  c o  m*/
public Collection<Item> getItems() {
    Collection<Item> items = new ArrayList<Item>();
    Element query = element.element(new QName("query", Namespace.get("jabber:iq:roster")));
    if (query != null) {
        for (Iterator i = query.elementIterator("item"); i.hasNext();) {
            Element item = (Element) i.next();
            String jid = item.attributeValue("jid");
            String name = item.attributeValue("name");
            String ask = item.attributeValue("ask");
            String subscription = item.attributeValue("subscription");
            Collection<String> groups = new ArrayList<String>();
            for (Iterator j = item.elementIterator("group"); j.hasNext();) {
                Element group = (Element) j.next();
                groups.add(group.getTextTrim());
            }
            Ask askStatus = ask == null ? null : Ask.valueOf(ask);
            Subscription subStatus = subscription == null ? null : Subscription.valueOf(subscription);
            items.add(new Item(new JID(jid), name, askStatus, subStatus, groups));
        }
    }
    return Collections.unmodifiableCollection(items);
}