Example usage for org.dom4j DocumentHelper createElement

List of usage examples for org.dom4j DocumentHelper createElement

Introduction

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

Prototype

public static Element createElement(String name) 

Source Link

Usage

From source file:mesquite.minimal.Simplicity.Simplicity.java

License:Open Source License

public void renameSettingsFile(int i, String newName) {
    if (!MesquiteInteger.isCombinable(i) || i < 0 || i >= InterfaceManager.settingsFiles.size())
        return;/*from w ww .j  a  v  a2s .  c om*/
    StringArray s = (StringArray) InterfaceManager.settingsFiles.elementAt(i);
    String path = s.getValue(PATH);
    String settingsXML = s.getValue(XML);
    Element root = XMLUtil.getRootXMLElementFromString("mesquite", settingsXML);
    if (root == null)
        return;
    Element element = root.element("simplicitySettings");
    if (element != null) {
        Element versionElement = element.element("version");
        if (versionElement == null)
            return;
        else {
            int version = MesquiteInteger.fromString(element.elementText("version"));
            boolean acceptableVersion = version == 1;
            if (acceptableVersion) {
                Element name = element.element("name");

                Element settingsFile = DocumentHelper.createElement("mesquite");
                Document doc = DocumentHelper.createDocument(settingsFile);
                Element hidden = DocumentHelper.createElement("simplicitySettings");
                settingsFile.add(hidden);
                XMLUtil.addFilledElement(hidden, "version", "1");
                XMLUtil.addFilledElement(hidden, "name", newName);
                Element hp = element.element("hiddenPackages");
                element.remove(hp);
                hidden.add(hp);
                hp = element.element("hiddenMenuItems");
                element.remove(hp);
                hidden.add(hp);
                hp = element.element("hiddenTools");
                element.remove(hp);
                hidden.add(hp);
                s.setName(newName);
                MesquiteFile.putFileContents(path, XMLUtil.getDocumentAsXMLString(doc), false);
            }
        }
    }
}

From source file:mesquite.minimal.Simplicity.Simplicity.java

License:Open Source License

public String makeSettingsFile(String name) {
    Element settingsFile = DocumentHelper.createElement("mesquite");
    Document doc = DocumentHelper.createDocument(settingsFile);
    Element hidden = DocumentHelper.createElement("simplicitySettings");
    settingsFile.add(hidden);/*from   ww w.  j  av  a  2  s  .c  om*/
    XMLUtil.addFilledElement(hidden, "version", "1");
    XMLUtil.addFilledElement(hidden, "name", name);

    Element hiddenPkgs = DocumentHelper.createElement("hiddenPackages");
    hidden.add(hiddenPkgs);
    for (int i = 0; i < InterfaceManager.hiddenPackages.size(); i++) {
        MesquiteString ms = (MesquiteString) InterfaceManager.hiddenPackages.elementAt(i);
        Element elem = DocumentHelper.createElement("package");
        hiddenPkgs.add(elem);
        XMLUtil.addFilledElement(elem, "name", ms.getName());
    }

    Element hiddenMs = DocumentHelper.createElement("hiddenMenuItems");
    hidden.add(hiddenMs);
    for (int i = 0; i < InterfaceManager.hiddenMenuItems.size(); i++) {
        MenuVisibility mv = (MenuVisibility) InterfaceManager.hiddenMenuItems.elementAt(i);
        Element elem = DocumentHelper.createElement("menuItem");
        hiddenMs.add(elem);
        XMLUtil.addFilledElement(elem, "label", mv.label);
        if (mv.arguments != null)
            XMLUtil.addFilledElement(elem, "arguments", mv.arguments);
        XMLUtil.addFilledElement(elem, "command", mv.command);
        XMLUtil.addFilledElement(elem, "commandableClass", mv.commandableClassName);
        XMLUtil.addFilledElement(elem, "dutyClass", mv.dutyClass);
    }
    Element hiddenT = DocumentHelper.createElement("hiddenTools");
    hidden.add(hiddenT);
    for (int i = 0; i < InterfaceManager.hiddenTools.size(); i++) {
        MesquiteString s = (MesquiteString) InterfaceManager.hiddenTools.elementAt(i);
        Element elem = DocumentHelper.createElement("tool");
        hiddenT.add(elem);
        XMLUtil.addFilledElement(elem, "name", s.getName());
        XMLUtil.addFilledElement(elem, "description", s.getValue());
    }
    return XMLUtil.getDocumentAsXMLString(doc);
}

From source file:net.contextfw.web.application.component.DOMBuilder.java

License:Apache License

public DOMBuilder(String rootName, AttributeSerializer<Object> serializer, ComponentBuilder componentBuilder,
        Collection<KeyValue<String, String>> namespaces) {

    this.serializer = serializer;
    root = DocumentHelper.createElement(rootName);
    document = DocumentHelper.createDocument();
    document.setRootElement(root);//from  ww w .  ja  v a 2s  . c  o  m
    for (KeyValue<String, String> namespace : namespaces) {
        root.add(DocumentHelper.createNamespace(namespace.getKey(), namespace.getValue()));
    }

    this.componentBuilder = componentBuilder;
}

From source file:net.emiva.crossfire.plugin.muc.spi.IQMUCRegisterHandler.java

License:Open Source License

public void initialize() {
    if (probeResult == null) {
        // Create the registration form of the room which contains information
        // such as: first name, last name and  nickname.
        final DataForm registrationForm = new DataForm(DataForm.Type.form);
        registrationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.reg.title"));
        registrationForm.addInstruction(LocaleUtils.getLocalizedString("muc.form.reg.instruction"));

        final FormField fieldForm = registrationForm.addField();
        fieldForm.setVariable("FORM_TYPE");
        fieldForm.setType(FormField.Type.hidden);
        fieldForm.addValue("http://jabber.org/protocol/muc#register");

        final FormField fieldReg = registrationForm.addField();
        fieldReg.setVariable("muc#register_first");
        fieldReg.setType(FormField.Type.text_single);
        fieldReg.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name"));
        fieldReg.setRequired(true);//w  w w  . ja v a 2 s . c om

        final FormField fieldLast = registrationForm.addField();
        fieldLast.setVariable("muc#register_last");
        fieldLast.setType(FormField.Type.text_single);
        fieldLast.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name"));
        fieldLast.setRequired(true);

        final FormField fieldNick = registrationForm.addField();
        fieldNick.setVariable("muc#register_roomnick");
        fieldNick.setType(FormField.Type.text_single);
        fieldNick.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname"));
        fieldNick.setRequired(true);

        final FormField fieldUrl = registrationForm.addField();
        fieldUrl.setVariable("muc#register_url");
        fieldUrl.setType(FormField.Type.text_single);
        fieldUrl.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url"));

        final FormField fieldMail = registrationForm.addField();
        fieldMail.setVariable("muc#register_email");
        fieldMail.setType(FormField.Type.text_single);
        fieldMail.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email"));

        final FormField fieldFaq = registrationForm.addField();
        fieldFaq.setVariable("muc#register_faqentry");
        fieldFaq.setType(FormField.Type.text_single);
        fieldFaq.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry"));

        // Create the probeResult and add the registration form
        probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register"));
        probeResult.add(registrationForm.getElement());
    }
}

From source file:net.emiva.crossfire.plugin.muc.spi.IQMUCSearchHandler.java

License:Open Source License

/**
 * Utility method that returns a 'jabber:iq:search' child element filled
 * with a blank dataform./*ww w  .ja v  a2 s  . c om*/
 * 
 * @return Element, named 'query', escaped by the 'jabber:iq:search'
 *         namespace, filled with a blank dataform.
 */
private static Element getDataElement() {
    final DataForm searchForm = new DataForm(DataForm.Type.form);
    searchForm.setTitle("Chat Rooms Search");
    searchForm.addInstruction("Instructions");

    final FormField typeFF = searchForm.addField();
    typeFF.setVariable("FORM_TYPE");
    typeFF.setType(FormField.Type.hidden);
    typeFF.addValue("jabber:iq:search");

    final FormField nameFF = searchForm.addField();
    nameFF.setVariable("name");
    nameFF.setType(FormField.Type.text_single);
    nameFF.setLabel("Name");
    nameFF.setRequired(false);

    final FormField matchFF = searchForm.addField();
    matchFF.setVariable("name_is_exact_match");
    matchFF.setType(FormField.Type.boolean_type);
    matchFF.setLabel("Name must match exactly");
    matchFF.setRequired(false);

    final FormField subjectFF = searchForm.addField();
    subjectFF.setVariable("subject");
    subjectFF.setType(FormField.Type.text_single);
    subjectFF.setLabel("Subject");
    subjectFF.setRequired(false);

    final FormField userAmountFF = searchForm.addField();
    userAmountFF.setVariable("num_users");
    userAmountFF.setType(FormField.Type.text_single);
    userAmountFF.setLabel("Number of users");
    userAmountFF.setRequired(false);

    final FormField maxUsersFF = searchForm.addField();
    maxUsersFF.setVariable("num_max_users");
    maxUsersFF.setType(FormField.Type.text_single);
    maxUsersFF.setLabel("Max number allowed of users");
    maxUsersFF.setRequired(false);

    final FormField includePasswordProtectedFF = searchForm.addField();
    includePasswordProtectedFF.setVariable("include_password_protected");
    includePasswordProtectedFF.setType(FormField.Type.boolean_type);
    includePasswordProtectedFF.setLabel("Include password protected rooms");
    includePasswordProtectedFF.setRequired(false);

    final Element probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:search"));
    probeResult.add(searchForm.getElement());
    return probeResult;
}

From source file:net.emiva.crossfire.plugin.muc.spi.IQMUCSearchHandler.java

License:Open Source License

/**
 * Constructs an answer on a IQ stanza that contains a search request. The
 * answer will be an IQ stanza of type 'result' or 'error'.
 * /* www  .j  a  va2s .  c om*/
 * @param iq
 *            The IQ stanza that is the search request.
 * @return An answer to the provided request.
 */
public IQ handleIQ(IQ iq) {
    final IQ reply = IQ.createResultIQ(iq);
    final Element formElement = iq.getChildElement().element(QName.get("x", "jabber:x:data"));
    if (formElement == null) {
        reply.setChildElement(getDataElement());
        return reply;
    }

    // parse params from request.
    final DataForm df = new DataForm(formElement);
    boolean name_is_exact_match = false;
    String subject = null;
    int numusers = -1;
    int numaxusers = -1;
    boolean includePasswordProtectedRooms = true;

    final Set<String> names = new HashSet<String>();
    for (final FormField field : df.getFields()) {
        if (field.getVariable().equals("name")) {
            names.add(field.getFirstValue());
        }
    }

    final FormField matchFF = df.getField("name_is_exact_match");
    if (matchFF != null) {
        final String b = matchFF.getFirstValue();
        if (b != null) {
            name_is_exact_match = b.equals("1") || b.equalsIgnoreCase("true") || b.equalsIgnoreCase("yes");
        }
    }

    final FormField subjectFF = df.getField("subject");
    if (subjectFF != null) {
        subject = subjectFF.getFirstValue();
    }

    try {
        final FormField userAmountFF = df.getField("num_users");
        if (userAmountFF != null) {
            String value = userAmountFF.getFirstValue();
            if (value != null && !"".equals(value)) {
                numusers = Integer.parseInt(value);
            }
        }

        final FormField maxUsersFF = df.getField("num_max_users");
        if (maxUsersFF != null) {
            String value = maxUsersFF.getFirstValue();
            if (value != null && !"".equals(value)) {
                numaxusers = Integer.parseInt(value);
            }
        }
    } catch (NumberFormatException e) {
        reply.setError(PacketError.Condition.bad_request);
        return reply;
    }

    final FormField includePasswordProtectedRoomsFF = df.getField("include_password_protected");
    if (includePasswordProtectedRoomsFF != null) {
        final String b = includePasswordProtectedRoomsFF.getFirstValue();
        if (b != null) {
            if (b.equals("0") || b.equalsIgnoreCase("false") || b.equalsIgnoreCase("no")) {
                includePasswordProtectedRooms = false;
            }
        }
    }

    // search for chatrooms matching the request params.
    final List<MUCRoom> mucs = new ArrayList<MUCRoom>();
    for (MUCRoom room : mucService.getChatRooms()) {
        boolean find = false;

        if (names.size() > 0) {
            for (final String name : names) {
                if (name_is_exact_match) {
                    if (name.equalsIgnoreCase(room.getNaturalLanguageName())) {
                        find = true;
                        break;
                    }
                } else {
                    if (room.getNaturalLanguageName().toLowerCase().indexOf(name.toLowerCase()) != -1) {
                        find = true;
                        break;
                    }
                }
            }
        }

        if (subject != null && room.getSubject().toLowerCase().indexOf(subject.toLowerCase()) != -1) {
            find = true;
        }

        if (numusers > -1 && room.getParticipants().size() < numusers) {
            find = false;
        }

        if (numaxusers > -1 && room.getMaxUsers() < numaxusers) {
            find = false;
        }

        if (!includePasswordProtectedRooms && room.isPasswordProtected()) {
            find = false;
        }

        if (find && canBeIncludedInResult(room)) {
            mucs.add(room);
        }
    }

    final ResultSet<MUCRoom> searchResults = new ResultSetImpl<MUCRoom>(sortByUserAmount(mucs));

    // See if the requesting entity would like to apply 'result set
    // management'
    final Element set = iq.getChildElement()
            .element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT));
    final List<MUCRoom> mucrsm;

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

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

        try {
            mucrsm = searchResults.applyRSMDirectives(set);
        } catch (NullPointerException e) {
            final IQ itemNotFound = IQ.createResultIQ(iq);
            itemNotFound.setError(Condition.item_not_found);
            return itemNotFound;
        }
    } else {
        // if no rsm, all found rooms are part of the result.
        mucrsm = new ArrayList<MUCRoom>(searchResults);
    }

    final Element res = DocumentHelper.createElement(QName.get("query", "jabber:iq:search"));

    final DataForm resultform = new DataForm(DataForm.Type.result);
    boolean atLeastoneResult = false;
    for (MUCRoom room : mucrsm) {
        final Map<String, Object> fields = new HashMap<String, Object>();
        fields.put("name", room.getNaturalLanguageName());
        fields.put("subject", room.getSubject());
        fields.put("num_users", room.getOccupantsCount());
        fields.put("num_max_users", room.getMaxUsers());
        fields.put("is_password_protected", room.isPasswordProtected());
        fields.put("is_member_only", room.isMembersOnly());
        fields.put("jid", room.getRole().getRoleAddress().toString());
        resultform.addItemFields(fields);
        atLeastoneResult = true;
    }
    if (atLeastoneResult) {
        resultform.addReportedField("name", "Name", FormField.Type.text_single);
        resultform.addReportedField("subject", "Subject", FormField.Type.text_single);
        resultform.addReportedField("num_users", "Number of users", FormField.Type.text_single);
        resultform.addReportedField("num_max_users", "Max number allowed of users", FormField.Type.text_single);
        resultform.addReportedField("is_password_protected", "Is a password protected room.",
                FormField.Type.boolean_type);
        resultform.addReportedField("is_member_only", "Is a member only room.", FormField.Type.boolean_type);
        resultform.addReportedField("jid", "JID", FormField.Type.jid_single);
    }
    res.add(resultform.getElement());
    if (applyRSM) {
        res.add(searchResults.generateSetElementFromResults(mucrsm));
    }

    reply.setChildElement(res);

    return reply;
}

From source file:net.emiva.crossfire.plugin.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 w ww . ja  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("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.owner_registration"));

    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());
}

From source file:net.emiva.crossfire.plugin.muc.spi.LocalMUCRole.java

License:Open Source License

/**
 * Create a new role./*from  w w w.  j ava 2 s  .c  om*/
 * 
 * @param chatserver the server hosting the role.
 * @param chatroom the room the role is valid in.
 * @param nickname the nickname of the user in the role.
 * @param role the role of the user in the room.
 * @param affiliation the affiliation of the user in the room.
 * @param chatuser the user on the chat server.
 * @param presence the presence sent by the user to join the room.
 * @param packetRouter the packet router for sending messages from this role.
 */
public LocalMUCRole(MultiUserChatService chatserver, LocalMUCRoom chatroom, String nickname, MUCRole.Role role,
        MUCRole.Affiliation affiliation, LocalMUCUser chatuser, Presence presence, PacketRouter packetRouter) {
    this.room = chatroom;
    this.nick = nickname;
    this.user = chatuser;
    this.server = chatserver;
    this.router = packetRouter;
    this.role = role;
    this.affiliation = affiliation;
    // Cache the user's session (will only work for local users)
    this.session = XMPPServer.getInstance().getSessionManager().getSession(presence.getFrom());

    extendedInformation = DocumentHelper.createElement(QName.get("x", "http://jabber.org/protocol/muc#user"));
    calculateExtendedInformation();
    rJID = new JID(room.getName(), server.getServiceDomain(), nick);
    setPresence(presence);
    // Check if new occupant wants to be a deaf occupant
    Element element = presence.getElement().element(QName.get("x", "http://jivesoftware.org/protocol/muc"));
    if (element != null) {
        voiceOnly = element.element("deaf-occupant") != null;
    }
    // Add the new role to the list of roles
    user.addRole(room.getName(), this);
}

From source file:net.emiva.crossfire.plugin.muc.spi.MultiUserChatServiceImpl.java

License:Open Source License

public Iterator<Element> getIdentities(String name, String node, JID senderJID) {
    ArrayList<Element> identities = new ArrayList<Element>();
    if (name == null && node == null) {
        // Answer the identity of the MUC service
        Element identity = DocumentHelper.createElement("identity");
        identity.addAttribute("category", "conference");
        identity.addAttribute("name", getDescription());
        identity.addAttribute("type", "text");
        identities.add(identity);//  ww  w  .  j  a v a2 s. c  om

        // TODO: Should internationalize Public Chatroom Search, and make it configurable.
        Element searchId = DocumentHelper.createElement("identity");
        searchId.addAttribute("category", "directory");
        searchId.addAttribute("name", "Public Chatroom Search");
        searchId.addAttribute("type", "chatroom");
        identities.add(searchId);

        if (!extraDiscoIdentities.isEmpty()) {
            identities.addAll(extraDiscoIdentities);
        }
    } else if (name != null && node == null) {
        // Answer the identity of a given room
        MUCRoom room = getChatRoom(name);
        if (room != null && canDiscoverRoom(room)) {
            Element identity = DocumentHelper.createElement("identity");
            identity.addAttribute("category", "conference");
            identity.addAttribute("name", room.getNaturalLanguageName());
            identity.addAttribute("type", "text");

            identities.add(identity);
        }
    } else if (name != null && "x-roomuser-item".equals(node)) {
        // Answer reserved nickname for the sender of the disco request in the requested room
        MUCRoom room = getChatRoom(name);
        if (room != null) {
            String reservedNick = room.getReservedNickname(senderJID.toBareJID());
            if (reservedNick != null) {
                Element identity = DocumentHelper.createElement("identity");
                identity.addAttribute("category", "conference");
                identity.addAttribute("name", reservedNick);
                identity.addAttribute("type", "text");

                identities.add(identity);
            }
        }
    }
    return identities.iterator();
}

From source file:net.emiva.crossfire.plugin.muc.spi.MultiUserChatServiceImpl.java

License:Open Source License

/**
 * Adds an extra Disco identity to the list of identities returned for the conference service.
 * @param category Category for identity.  e.g. conference
 * @param name Descriptive name for identity.  e.g. Public Chatrooms
 * @param type Type for identity.  e.g. text 
 *///from  w ww  .  j ava 2  s .  com
public void addExtraIdentity(String category, String name, String type) {
    Element identity = DocumentHelper.createElement("identity");
    identity.addAttribute("category", category);
    identity.addAttribute("name", name);
    identity.addAttribute("type", type);
    extraDiscoIdentities.add(identity);
}