List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:org.jivesoftware.openfire.fastpath.settings.SettingsManager.java
License:Open Source License
public void setState(Workgroup workgroup, WorkgroupSettings workgroupSettings, QName namespace) { this.workgroupSettings = workgroupSettings; this.workgroup = workgroup; this.namespace = namespace; try {//from ww w . j av a 2 s.c o m final Element element = workgroupSettings.get(workgroup.getJID().toBareJID(), DocumentHelper.createElement(namespace)); final List list = element.elements(); final Iterator iter = list.iterator(); while (iter.hasNext()) { Element el = (Element) iter.next(); addToSettings(el); } } catch (Exception ex) { Log.error(ex.getMessage(), ex); } }
From source file:org.jivesoftware.openfire.fastpath.settings.SettingsManager.java
License:Open Source License
public void setMap(Map map) { Element element = DocumentHelper.createElement(namespace); final Iterator i = element.elementIterator(); while (i.hasNext()) { element.remove((Element) i.next()); }//from w w w . ja va2s.co m final Iterator iter = map.keySet().iterator(); while (iter.hasNext()) { String key = (String) iter.next(); String value = (String) map.get(key); Element elem = DocumentHelper.createElement("entry"); elem.addElement(key).setText(value); element.add(elem); } try { workgroupSettings.add(workgroup.getJID().toBareJID(), element); } catch (Exception ex) { Log.error(ex.getMessage(), ex); } }
From source file:org.jivesoftware.openfire.filetransfer.proxy.FileTransferProxy.java
License:Open Source License
public Iterator<Element> getIdentities(String name, String node, JID senderJID) { List<Element> identities = new ArrayList<Element>(); // Answer the identity of the proxy Element identity = DocumentHelper.createElement("identity"); identity.addAttribute("category", "proxy"); identity.addAttribute("name", "SOCKS5 Bytestreams Service"); identity.addAttribute("type", "bytestreams"); identities.add(identity);/*from ww w . j a v a 2s . c o m*/ return identities.iterator(); }
From source file:org.jivesoftware.openfire.forms.spi.XDataFormImpl.java
License:Open Source License
public Element asXMLElement() { Element x = DocumentHelper.createElement(QName.get("x", "jabber:x:data")); if (getType() != null) { x.addAttribute("type", getType()); }//from w w w . j a v a2 s.com if (getTitle() != null) { x.addElement("title").addText(getTitle()); } if (instructions.size() > 0) { Iterator instrItr = getInstructions(); while (instrItr.hasNext()) { x.addElement("instructions").addText((String) instrItr.next()); } } // Append the list of fields returned from a search if (reportedFields.size() > 0) { Element reportedElement = x.addElement("reported"); Iterator fieldsItr = reportedFields.iterator(); while (fieldsItr.hasNext()) { XFormFieldImpl field = (XFormFieldImpl) fieldsItr.next(); reportedElement.add(field.asXMLElement()); } } // Append the list of items returned from a search // Note: each item contains a List of XFormFieldImpls if (reportedItems.size() > 0) { Iterator itemsItr = reportedItems.iterator(); while (itemsItr.hasNext()) { // Add a new item element for this list of fields Element itemElement = x.addElement("item"); List fields = (List) itemsItr.next(); Iterator fieldsItr = fields.iterator(); // Iterate on the fields and add them to the new item while (fieldsItr.hasNext()) { XFormFieldImpl field = (XFormFieldImpl) fieldsItr.next(); itemElement.add(field.asXMLElement()); } } } if (fields.size() > 0) { Iterator fieldsItr = getFields(); while (fieldsItr.hasNext()) { XFormFieldImpl field = (XFormFieldImpl) fieldsItr.next(); x.add(field.asXMLElement()); } } return x; }
From source file:org.jivesoftware.openfire.forms.spi.XFormFieldImpl.java
License:Open Source License
public Element asXMLElement() { Element field = DocumentHelper.createElement(QName.get("field", "jabber:x:data")); if (getLabel() != null) { field.addAttribute("label", getLabel()); }/*from w w w .java 2 s . c o m*/ if (getVariable() != null) { field.addAttribute("var", getVariable()); } if (getType() != null) { field.addAttribute("type", getType()); } if (getDescription() != null) { field.addElement("desc").addText(getDescription()); } if (isRequired()) { field.addElement("required"); } // Loop through all the values and append them to the stream writer if (values.size() > 0) { Iterator<String> valuesItr = getValues(); while (valuesItr.hasNext()) { field.addElement("value").addText(valuesItr.next()); } } // Loop through all the options and append them to the stream writer if (options.size() > 0) { Iterator<Option> optionsItr = getOptions(); while (optionsItr.hasNext()) { field.add((optionsItr.next()).asXMLElement()); } } // Loop through all the values and append them to the stream writer /*Iterator frags = fragments.iterator(); while (frags.hasNext()){ XMPPFragment frag = (XMPPFragment) frags.next(); frag.send(xmlSerializer,version); }*/ return field; }
From source file:org.jivesoftware.openfire.handler.IQAuthHandler.java
License:Open Source License
/** * Clients are not authenticated when accessing this handler. *///from w ww.j a va 2 s .c o m public IQAuthHandler() { super("XMPP Authentication handler"); info = new IQHandlerInfo("query", "jabber:iq:auth"); probeResponse = DocumentHelper.createElement(QName.get("query", "jabber:iq:auth")); probeResponse.addElement("username"); if (AuthFactory.isPlainSupported()) { probeResponse.addElement("password"); } if (AuthFactory.isDigestSupported()) { probeResponse.addElement("digest"); } probeResponse.addElement("resource"); anonymousAllowed = JiveGlobals.getBooleanProperty("xmpp.auth.anonymous"); }
From source file:org.jivesoftware.openfire.handler.IQBlockingHandler.java
License:Open Source License
@Override public IQ handleIQ(IQ iq) throws UnauthorizedException { if (iq.isResponse()) { return null; }/*from w w w . ja v a2s . com*/ final JID requester = iq.getFrom(); if (!XMPPServer.getInstance().getUserManager().isRegisteredUser(requester)) { final IQ error = IQ.createResultIQ(iq); error.setError(PacketError.Condition.not_authorized); return error; } final User user; try { user = UserManager.getInstance().getUser(requester.getNode()); } catch (UserNotFoundException e) { Log.error("Unable to retrieve user '{}' that was verified to be an existing user!", requester.getNode(), e); final IQ error = IQ.createResultIQ(iq); error.setError(PacketError.Condition.internal_server_error); return error; } try { if (iq.getType().equals(IQ.Type.get) && "blocklist".equals(iq.getChildElement().getName())) { final Set<JID> blocklist = getBlocklist(user); final IQ response = IQ.createResultIQ(iq); final Element blocklistElement = DocumentHelper .createElement(QName.get(getInfo().getName(), getInfo().getNamespace())); for (final JID blocked : blocklist) { blocklistElement.addElement("item").addAttribute("jid", blocked.toString()); } response.setChildElement(blocklistElement); sessionManager.getSession(iq.getFrom()).setHasRequestedBlocklist(true); return response; } else if (iq.getType().equals(IQ.Type.set) && "block".equals(iq.getChildElement().getName())) { final List<Element> items = iq.getChildElement().elements("item"); if (items == null || items.isEmpty()) { final IQ error = IQ.createResultIQ(iq); error.setError(PacketError.Condition.bad_request); return error; } final List<JID> toBlocks = new ArrayList<>(); for (final Element item : items) { toBlocks.add(new JID(item.attributeValue("jid"))); } addToBlockList(user, toBlocks); pushBlocklistUpdates(user, toBlocks); return IQ.createResultIQ(iq); } else if (iq.getType().equals(IQ.Type.set) && "unblock".equals(iq.getChildElement().getName())) { final Set<JID> unblocked; final List<Element> items = iq.getChildElement().elements("item"); if (items == null || items.isEmpty()) { unblocked = removeAllFromBlocklist(user); } else { final Collection<JID> toUnblocks = new ArrayList<>(); for (final Element item : items) { toUnblocks.add(new JID(item.attributeValue("jid"))); } unblocked = removeFromBlockList(user, toUnblocks); } pushBlocklistUpdates(user, unblocked); sendPresence(user, unblocked); return IQ.createResultIQ(iq); } else { final IQ error = IQ.createResultIQ(iq); error.setError(PacketError.Condition.feature_not_implemented); return error; } } catch (Exception e) { Log.warn("An exception occurred while trying to process an IQ block request from '{}':", iq.getFrom(), e); final IQ error = IQ.createResultIQ(iq); error.setError(PacketError.Condition.internal_server_error); return error; } }
From source file:org.jivesoftware.openfire.handler.IQBlockingHandler.java
License:Open Source License
/** * Adds a collection of JIDs to the blocklist of the provided user. * * This method adds the JIDs to the default privacy list, creating a new privacy list (and setting it as default) * if the user does not have a default privacy list. * * The newly added JIDs are push on the front end of the list. The order of pre-existing list items is modified. * * @param user The owner of the blocklist to which JIDs are to be added (cannot be null). * @param toBlocks The JIDs to be added (can be null, which results in a noop). *//* w ww .j a v a 2 s . c om*/ protected void addToBlockList(User user, List<JID> toBlocks) { if (toBlocks == null || toBlocks.isEmpty()) { return; } Log.debug("Obtain or create a the default privacy list for '{}'", user.getUsername()); PrivacyList defaultPrivacyList = PrivacyListManager.getInstance().getDefaultPrivacyList(user.getUsername()); if (defaultPrivacyList == null) { final Element listElement = DocumentFactory.getInstance().createDocument().addElement("list", "jabber:iq:privacy"); listElement.addAttribute("name", "blocklist"); defaultPrivacyList = PrivacyListManager.getInstance().createPrivacyList(user.getUsername(), "blocklist", listElement); PrivacyListManager.getInstance().changeDefaultList(user.getUsername(), defaultPrivacyList, null); } Log.debug("Adding {} JIDs as blocked items to the beginning of list '{}' (belonging to '{}')", toBlocks.size(), defaultPrivacyList.getName(), user.getUsername()); final Element listElement = defaultPrivacyList.asElement(); for (int i = 0; i < toBlocks.size(); i++) { final Element element = DocumentHelper.createElement("item").addAttribute("type", "jid") .addAttribute("value", toBlocks.get(i).toString()).addAttribute("action", "deny") .addAttribute("order", Integer.toString(i)); listElement.elements().add(i, element); } Log.debug( "Iterating over all items of list '{}' (belonging to '{}'), to ensure that their 'order' value is unique.", defaultPrivacyList.getName(), user.getUsername()); final List<Element> elements = listElement.elements(); for (int i = 0; i < elements.size(); i++) { elements.get(i).attribute("order").setValue(Integer.toString(i)); } defaultPrivacyList.updateList(listElement); PrivacyListProvider.getInstance().updatePrivacyList(user.getUsername(), defaultPrivacyList); }
From source file:org.jivesoftware.openfire.handler.IQEntityTimeHandler.java
License:Open Source License
@Override public IQ handleIQ(IQ packet) { IQ response = IQ.createResultIQ(packet); Element timeElement = DocumentHelper.createElement(QName.get(info.getName(), info.getNamespace())); timeElement.addElement("tzo").setText(formatsTimeZone(TimeZone.getDefault())); timeElement.addElement("utc").setText(getUtcDate(new Date())); response.setChildElement(timeElement); return response; }
From source file:org.jivesoftware.openfire.handler.IQFindUserByPlateHandler.java
License:Open Source License
public IQFindUserByPlateHandler() { super("XMPP Server Time Handler"); info = new IQHandlerInfo("query", "jabber:iq:plate"); responseElement = DocumentHelper.createElement(QName.get("query", "jabber:iq:plate")); responseElement.addElement("username"); }