List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:org.jivesoftware.openfire.handler.IQOfflineMessagesHandler.java
License:Open Source License
public Iterator<Element> getIdentities(String name, String node, JID senderJID) { ArrayList<Element> identities = new ArrayList<Element>(); Element identity = DocumentHelper.createElement("identity"); identity.addAttribute("category", "automation"); identity.addAttribute("type", "message-list"); identities.add(identity);/* w w w.j a v a2s . c o m*/ return identities.iterator(); }
From source file:org.jivesoftware.openfire.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 w w . j a v a2s .c o m 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()); } JiveGlobals.migrateProperty("register.inband"); JiveGlobals.migrateProperty("register.password"); // See if in-band registration should be enabled (default is true). registrationEnabled = JiveGlobals.getBooleanProperty("register.inband", true); // See if users can change their passwords (default is true). canChangePassword = JiveGlobals.getBooleanProperty("register.password", true); }
From source file:org.jivesoftware.openfire.handler.PresenceUpdateHandler.java
License:Open Source License
/** * A session that has transitioned to available status must be initialized. * This includes:// ww w . j av a 2 s . co m * <ul> * <li>Sending all offline presence subscription requests</li> * <li>Sending offline messages</li> * </ul> * * @param session The session being updated * @throws UserNotFoundException If the user being updated does not exist */ private void initSession(ClientSession session) throws UserNotFoundException { // Only user sessions need to be authenticated if (userManager.isRegisteredUser(session.getAddress().getNode())) { String username = session.getAddress().getNode(); // Send pending subscription requests to user if roster service is enabled if (RosterManager.isRosterServiceEnabled()) { Roster roster = rosterManager.getRoster(username); for (RosterItem item : roster.getRosterItems()) { if (item.getRecvStatus() == RosterItem.RECV_SUBSCRIBE) { session.process( createSubscribePresence(item.getJid(), session.getAddress().asBareJID(), true)); } else if (item.getRecvStatus() == RosterItem.RECV_UNSUBSCRIBE) { session.process( createSubscribePresence(item.getJid(), session.getAddress().asBareJID(), false)); } if (item.getSubStatus() == RosterItem.SUB_TO || item.getSubStatus() == RosterItem.SUB_BOTH) { presenceManager.probePresence(session.getAddress(), item.getJid()); } } } if (session.canFloodOfflineMessages()) { // deliver offline messages if any Collection<OfflineMessage> messages = messageStore.getMessages(username, true); Message offlineMessage = new Message(); String threadId = ""; List<String> bodyTags = new ArrayList<String>(); List<String> fromUserTags = new ArrayList<String>(); List<String> toUserTags = new ArrayList<String>(); List<String> creationDateTags = new ArrayList<String>(); List<String> toUserIdTags = new ArrayList<String>(); List<String> subjectTags = new ArrayList<String>(); for (Message message : messages) { String fromUser = message.getElement().attributeValue("from"); String formattedFromUser = fromUser.substring(0, fromUser.indexOf("/")); String toUser = message.getElement().attributeValue("to"); String datetime = message.getElement().attributeValue("datetime"); String toUserId = message.getElement().attributeValue("touserid").trim(); threadId = "1"; bodyTags.add(message.getBody()); fromUserTags.add(formattedFromUser); toUserTags.add(toUser); creationDateTags.add(datetime); toUserIdTags.add(toUserId); subjectTags.add(message.getSubject()); } offlineMessage.setType(Message.Type.normal); org.dom4j.Element offlineMsgTag = DocumentHelper.createElement("offlineMessage"); offlineMsgTag.setText("true"); offlineMessage.addExtension(new PacketExtension(offlineMsgTag)); offlineMessage.setThread(threadId); for (int i = 0; i < bodyTags.size(); i++) { org.dom4j.Element entryTag = DocumentHelper.createElement("entry"); org.dom4j.Element bodyTag = DocumentHelper.createElement("body"); bodyTag.setText(bodyTags.get(i)); org.dom4j.Element fromUserTag = DocumentHelper.createElement("fromUser"); fromUserTag.setText(fromUserTags.get(i)); org.dom4j.Element toUsersTag = DocumentHelper.createElement("toUsers"); toUsersTag.setText(toUserTags.get(i)); org.dom4j.Element creationDatesTag = DocumentHelper.createElement("creationDates"); creationDatesTag.setText(creationDateTags.get(i)); org.dom4j.Element toUserIdTag = DocumentHelper.createElement("toUserId"); toUserIdTag.setText(toUserIdTags.get(i)); org.dom4j.Element subjectTag = DocumentHelper.createElement("subject"); subjectTag.setText(subjectTags.get(i)); entryTag.add(bodyTag); entryTag.add(fromUserTag); entryTag.add(toUsersTag); entryTag.add(creationDatesTag); entryTag.add(toUserIdTag); entryTag.add(subjectTag); offlineMessage.addExtension(new PacketExtension(entryTag)); } session.process(offlineMessage); } } }
From source file:org.jivesoftware.openfire.http.HttpBindServlet.java
License:Open Source License
protected static String createErrorBody(String type, String condition) { final Element body = DocumentHelper.createElement("body"); body.addNamespace("", "http://jabber.org/protocol/httpbind"); body.addAttribute("type", type); body.addAttribute("condition", condition); return body.asXML(); }
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. */// w ww. j a v a 2 s . c o m 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; }
From source file:org.jivesoftware.openfire.http.HttpSession.java
License:Open Source License
protected String createEmptyBody(boolean terminate) { final Element body = DocumentHelper.createElement("body"); if (terminate) { body.addAttribute("type", "terminate"); }/*from w ww . j av a 2 s.c o m*/ body.addNamespace("", "http://jabber.org/protocol/httpbind"); body.addAttribute("ack", String.valueOf(getLastAcknowledged())); return body.asXML(); }
From source file:org.jivesoftware.openfire.http.HttpSession.java
License:Open Source License
private String createSessionRestartResponse() { final Element response = DocumentHelper.createElement("body"); response.addNamespace("", "http://jabber.org/protocol/httpbind"); response.addNamespace("stream", "http://etherx.jabber.org/streams"); final Element features = response.addElement("stream:features"); for (Element feature : getAvailableStreamFeaturesElements()) { features.add(feature);//from w w w .j av a 2s.co m } return response.asXML(); }
From source file:org.jivesoftware.openfire.http.HttpSessionManager.java
License:Open Source License
private static String createSessionCreationResponse(HttpSession session) throws DocumentException { Element response = DocumentHelper.createElement("body"); response.addNamespace("", "http://jabber.org/protocol/httpbind"); response.addNamespace("stream", "http://etherx.jabber.org/streams"); response.addAttribute("from", session.getServerName()); response.addAttribute("authid", session.getStreamID().getID()); response.addAttribute("sid", session.getStreamID().getID()); response.addAttribute("secure", Boolean.TRUE.toString()); response.addAttribute("requests", String.valueOf(session.getMaxRequests())); response.addAttribute("inactivity", String.valueOf(session.getInactivityTimeout())); response.addAttribute("polling", String.valueOf(session.getMaxPollingInterval())); response.addAttribute("wait", String.valueOf(session.getWait())); if ((session.getMajorVersion() == 1 && session.getMinorVersion() >= 6) || session.getMajorVersion() > 1) { response.addAttribute("hold", String.valueOf(session.getHold())); response.addAttribute("ack", String.valueOf(session.getLastAcknowledged())); response.addAttribute("maxpause", String.valueOf(session.getMaxPause())); response.addAttribute("ver", String.valueOf(session.getMajorVersion()) + "." + String.valueOf(session.getMinorVersion())); }//from www . ja va 2 s . c o m Element features = response.addElement("stream:features"); for (Element feature : session.getAvailableStreamFeaturesElements()) { features.add(feature); } return response.asXML(); }
From source file:org.jivesoftware.openfire.mediaproxy.MediaProxyService.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", "Media Proxy Service"); identity.addAttribute("type", "rtpbridge"); identities.add(identity);//from www. j a v a 2 s . c o m return identities.iterator(); }
From source file:org.jivesoftware.openfire.muc.spi.IQOwnerHandler.java
License:Open Source License
private void init() { Element element = DocumentHelper.createElement(QName.get("query", "http://jabber.org/protocol/muc#owner")); configurationForm = new DataForm(DataForm.Type.form); configurationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.conf.title")); List<String> params = new ArrayList<String>(); params.add(room.getName());/*from www . j a v a 2s .c om*/ configurationForm.addInstruction(LocaleUtils.getLocalizedString("muc.form.conf.instruction", params)); configurationForm.addField("FORM_TYPE", null, Type.hidden) .addValue("http://jabber.org/protocol/muc#roomconfig"); configurationForm.addField("muc#roomconfig_roomname", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomname"), Type.text_single); configurationForm.addField("muc#roomconfig_roomdesc", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomdesc"), Type.text_single); configurationForm.addField("muc#roomconfig_changesubject", LocaleUtils.getLocalizedString("muc.form.conf.owner_changesubject"), Type.boolean_type); final FormField maxUsers = configurationForm.addField("muc#roomconfig_maxusers", LocaleUtils.getLocalizedString("muc.form.conf.owner_maxusers"), Type.list_single); maxUsers.addOption("10", "10"); maxUsers.addOption("20", "20"); maxUsers.addOption("30", "30"); maxUsers.addOption("40", "40"); maxUsers.addOption("50", "50"); maxUsers.addOption(LocaleUtils.getLocalizedString("muc.form.conf.none"), "0"); final FormField broadcast = configurationForm.addField("muc#roomconfig_presencebroadcast", LocaleUtils.getLocalizedString("muc.form.conf.owner_presencebroadcast"), Type.list_multi); broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderator"); broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.participant"), "participant"); broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.visitor"), "visitor"); configurationForm.addField("muc#roomconfig_publicroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_publicroom"), Type.boolean_type); configurationForm.addField("muc#roomconfig_persistentroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_persistentroom"), Type.boolean_type); configurationForm.addField("muc#roomconfig_moderatedroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_moderatedroom"), Type.boolean_type); configurationForm.addField("muc#roomconfig_membersonly", LocaleUtils.getLocalizedString("muc.form.conf.owner_membersonly"), Type.boolean_type); configurationForm.addField(null, null, Type.fixed) .addValue(LocaleUtils.getLocalizedString("muc.form.conf.allowinvitesfixed")); configurationForm.addField("muc#roomconfig_allowinvites", LocaleUtils.getLocalizedString("muc.form.conf.owner_allowinvites"), Type.boolean_type); configurationForm.addField("muc#roomconfig_passwordprotectedroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_passwordprotectedroom"), Type.boolean_type); configurationForm.addField(null, null, Type.fixed) .addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomsecretfixed")); configurationForm.addField("muc#roomconfig_roomsecret", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomsecret"), Type.text_private); final FormField whois = configurationForm.addField("muc#roomconfig_whois", LocaleUtils.getLocalizedString("muc.form.conf.owner_whois"), Type.list_single); whois.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderators"); whois.addOption(LocaleUtils.getLocalizedString("muc.form.conf.anyone"), "anyone"); configurationForm.addField("muc#roomconfig_enablelogging", LocaleUtils.getLocalizedString("muc.form.conf.owner_enablelogging"), Type.boolean_type); configurationForm.addField("x-muc#roomconfig_reservednick", LocaleUtils.getLocalizedString("muc.form.conf.owner_reservednick"), Type.boolean_type); configurationForm.addField("x-muc#roomconfig_canchangenick", LocaleUtils.getLocalizedString("muc.form.conf.owner_canchangenick"), Type.boolean_type); configurationForm.addField(null, null, Type.fixed) .addValue(LocaleUtils.getLocalizedString("muc.form.conf.owner_registration")); configurationForm.addField("x-muc#roomconfig_registration", LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"), Type.boolean_type); configurationForm.addField(null, null, Type.fixed) .addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomadminsfixed")); configurationForm.addField("muc#roomconfig_roomadmins", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomadmins"), Type.jid_multi); configurationForm.addField(null, null, Type.fixed) .addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomownersfixed")); configurationForm.addField("muc#roomconfig_roomowners", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomowners"), Type.jid_multi); // Create the probeResult and add the basic info together with the configuration form probeResult = element; probeResult.add(configurationForm.getElement()); }