List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:org.apereo.portal.layout.dlm.providers.Paren.java
License:Apache License
@Override public void toElement(Element parent) { // Assertions. if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }//from www . jav a2s . c o m // NB: This method behaves vastly different depending on whether // the parent of this Paren is an instance of FragmentDefinition. Element rslt = null; if (parent.getName().equals("fragment")) { // The parent is a fragment, so we render as a <dlm:audience> element... QName q = new QName("audience", FragmentDefinition.NAMESPACE); rslt = DocumentHelper.createElement(q); // Discover the EvaluatorFactory class... rslt.addAttribute("evaluatorFactory", this.getFactoryClass().getName()); } else { // The parent is *not* a fragment, so we render as a <paren> element... rslt = DocumentHelper.createElement("paren"); rslt.addAttribute("mode", this.type.toString()); } // Serialize our children... for (Evaluator v : this.evaluators) { v.toElement(rslt); } // Append ourself... parent.add(rslt); }
From source file:org.apereo.portal.layout.dlm.providers.ProfileEvaluator.java
License:Apache License
@Override public void toElement(Element parent) { // Assertions. if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }//from w w w.ja v a 2 s . co m Element rslt = DocumentHelper.createElement("profile"); rslt.addAttribute("fname", this.profileFname); parent.add(rslt); }
From source file:org.apereo.portal.layout.dlm.providers.SubscribedTabEvaluator.java
License:Apache License
@Override public void toElement(Element parent) { // Assertions. if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }//from www.j a v a2s . co m Element rslt = null; QName q = new QName("audience", FragmentDefinition.NAMESPACE); rslt = DocumentHelper.createElement(q); rslt.addAttribute("evaluatorFactory", this.getFactoryClass().getName()); parent.add(rslt); }
From source file:org.b5chat.crossfire.core.net.sasl.SASLAuthentication.java
License:Open Source License
public static Element getSASLMechanismsElement(ISession session) { if (!(session instanceof IClientSession)) { return null; }/*w ww . j av a2 s . c om*/ Element mechs = DocumentHelper .createElement(new QName("mechanisms", new Namespace("", "urn:ietf:params:xml:ns:xmpp-sasl"))); for (String mech : getSupportedMechanisms()) { Element mechanism = mechs.addElement("mechanism"); mechanism.setText(mech); } return mechs; }
From source file:org.b5chat.crossfire.xmpp.auth.IQAuthHandler.java
License:Open Source License
/** * Clients are not authenticated when accessing this handler. *//* ww w. ja v a 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 = Globals.getBooleanProperty("xmpp.auth.anonymous"); }
From source file:org.b5chat.crossfire.xmpp.disco.IQDiscoInfoHandler.java
License:Open Source License
public IQDiscoInfoHandler() { super("XMPP Disco Info Handler"); info = new IQHandlerInfo("query", NAMESPACE_DISCO_INFO); // Initialize the user identity and features collections (optimization to avoid creating // the same objects for each response) Element userIdentity = DocumentHelper.createElement("identity"); userIdentity.addAttribute("category", "account"); userIdentity.addAttribute("type", "anonymous"); anonymousUserIdentities.add(userIdentity); userIdentity = DocumentHelper.createElement("identity"); userIdentity.addAttribute("category", "account"); userIdentity.addAttribute("type", "registered"); registeredUserIdentities.add(userIdentity); userFeatures.add(NAMESPACE_DISCO_INFO); }
From source file:org.b5chat.crossfire.xmpp.disco.IQDiscoInfoHandler.java
License:Open Source License
/** * Returns the IDiscoInfoProvider responsible for providing information at the server level. This * means that this IDiscoInfoProvider will provide information whenever a disco request whose * recipient JID is the server (e.g. localhost) is made. * * @return the IDiscoInfoProvider responsible for providing information at the server level. *///from ww w.j a v a 2s .com private IDiscoInfoProvider getServerInfoProvider() { return new IDiscoInfoProvider() { final ArrayList<Element> identities = new ArrayList<Element>(); public Iterator<Element> getIdentities(String name, String node, JID senderJID) { if (node != null && serverNodeProviders.get(node) != null) { // Redirect the request to the disco info provider of the specified node return serverNodeProviders.get(node).getIdentities(name, node, senderJID); } if (name == null) { // Answer identity of the server synchronized (identities) { if (identities.isEmpty()) { Element identity = DocumentHelper.createElement("identity"); identity.addAttribute("category", "server"); identity.addAttribute("name", Globals.getProperty("xmpp.server.name", "crossfire Server")); identity.addAttribute("type", "im"); identities.add(identity); // Include identities from modules that implement IServerIdentitiesProvider for (Element identityElement : serverIdentities) { identities.add(identityElement); } } } return identities.iterator(); } else { if (SessionManager.getInstance().isAnonymousRoute(name)) { // Answer identity of an anonymous user. return anonymousUserIdentities.iterator(); } else { // Answer identity of a registered user. // Note: We know that this user exists because #hasInfo returned true return registeredUserIdentities.iterator(); } } } public Iterator<String> getFeatures(String name, String node, JID senderJID) { if (node != null && serverNodeProviders.get(node) != null) { // Redirect the request to the disco info provider of the specified node return serverNodeProviders.get(node).getFeatures(name, node, senderJID); } if (name == null) { // Answer features of the server return new HashSet<String>(serverFeatures.keySet()).iterator(); } else { // Answer features of the user return userFeatures.iterator(); } } public boolean hasInfo(String name, String node, JID senderJID) { if (node != null) { if (serverNodeProviders.get(node) != null) { // Redirect the request to the disco info provider of the specified node return serverNodeProviders.get(node).hasInfo(name, node, senderJID); } // Unknown node return false; } try { // True if it is an info request of the server, a registered user or an // anonymous user. We now support disco of user's bare JIDs return name == null || UserManager.getInstance().getUser(name) != null || SessionManager.getInstance().isAnonymousRoute(name); } catch (UserNotFoundException e) { return false; } } public DataForm getExtendedInfo(String name, String node, JID senderJID) { if (node != null && serverNodeProviders.get(node) != null) { // Redirect the request to the disco info provider of the specified node return serverNodeProviders.get(node).getExtendedInfo(name, node, senderJID); } return null; } }; }
From source file:org.b5chat.crossfire.xmpp.disco.IQDiscoItemsHandler.java
License:Open Source License
/** * Registers a new disco item for a component. The jid attribute of the item will match the jid * of the component and the name should be the name of the component discovered using disco. * * @param jid the jid of the component./*from w w w . j a v a 2s. c om*/ * @param node the node that complements the jid address. * @param name the discovered name of the component. */ public void addComponentItem(String jid, String node, String name) { Lock lock = CacheFactory.getLock(jid, serverItems); try { lock.lock(); Element item = serverItems.get(jid); if (item == null) { // First time a node registers a server item for this component item = DocumentHelper.createElement("item"); item.addAttribute("jid", jid); item.addAttribute("node", node); item.addAttribute("name", name); } // Update the cache with latest info serverItems.put(jid, item); // Keep track of the new server item added by this JVM localServerItems.put(jid, item); } finally { lock.unlock(); } }
From source file:org.b5chat.crossfire.xmpp.disco.IQDiscoItemsHandler.java
License:Open Source License
public Iterator<Element> getUserItems(String name, JID senderJID) { List<Element> answer = new ArrayList<Element>(); try {//from w w w . ja v a2s . c o m User user = UserManager.getInstance().getUser(name); RosterItem item = user.getRoster().getRosterItem(senderJID); // If the requesting entity is subscribed to the account's presence then // answer the user's "available resources" if (item.getSubStatus() == RosterItem.SUB_FROM || item.getSubStatus() == RosterItem.SUB_BOTH) { for (ISession session : SessionManager.getInstance().getSessions(name)) { Element element = DocumentHelper.createElement("item"); element.addAttribute("jid", session.getAddress().toString()); answer.add(element); } } return answer.iterator(); } catch (UserNotFoundException e) { return answer.iterator(); } }
From source file:org.b5chat.crossfire.xmpp.handler.IQRegisterHandler.java
License:Open Source License
@Override public void initialize(XmppServer server) { super.initialize(server); userManager = server.getUserManager(); rosterManager = server.getRosterManager(); if (probeResult == null) { // Create the basic element of the probeResult which contains the basic registration // information (e.g. username, passoword and email) probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register")); probeResult.addElement("username"); probeResult.addElement("password"); probeResult.addElement("email"); probeResult.addElement("name"); // Create the registration form to include in the probeResult. The form will include // the basic information plus name and visibility of name and email. // TODO Future versions could allow plugin modules to add new fields to the form final DataForm registrationForm = new DataForm(DataForm.Type.form); registrationForm.setTitle("XMPP Client Registration"); registrationForm.addInstruction("Please provide the following information"); final FormField fieldForm = registrationForm.addField(); fieldForm.setVariable("FORM_TYPE"); fieldForm.setType(FormField.Type.hidden); fieldForm.addValue("jabber:iq:register"); final FormField fieldUser = registrationForm.addField(); fieldUser.setVariable("username"); fieldUser.setType(FormField.Type.text_single); fieldUser.setLabel("Username"); fieldUser.setRequired(true);//from w ww .ja va 2s. com final FormField fieldName = registrationForm.addField(); fieldName.setVariable("name"); fieldName.setType(FormField.Type.text_single); fieldName.setLabel("Full name"); if (UserManager.getUserProvider().isNameRequired()) { fieldName.setRequired(true); } final FormField fieldMail = registrationForm.addField(); fieldMail.setVariable("email"); fieldMail.setType(FormField.Type.text_single); fieldMail.setLabel("Email"); if (UserManager.getUserProvider().isEmailRequired()) { fieldMail.setRequired(true); } final FormField fieldPwd = registrationForm.addField(); fieldPwd.setVariable("password"); fieldPwd.setType(FormField.Type.text_private); fieldPwd.setLabel("Password"); fieldPwd.setRequired(true); // Add the registration form to the probe result. probeResult.add(registrationForm.getElement()); } // See if in-band registration should be enabled (default is true). registrationEnabled = Globals.getBooleanProperty("register.inband", true); // See if users can change their passwords (default is true). canChangePassword = Globals.getBooleanProperty("register.password", true); }