Example usage for org.jdom2 Element setAttribute

List of usage examples for org.jdom2 Element setAttribute

Introduction

In this page you can find the example usage for org.jdom2 Element setAttribute.

Prototype

public Element setAttribute(final String name, final String value) 

Source Link

Document

This sets an attribute value for this element.

Usage

From source file:com.kixeye.kixmpp.server.module.muc.MucRoom.java

License:Apache License

private Element createPresence(KixmppJid from, KixmppJid to, MucRole role, String type) {
    Element presence = new Element("presence");

    presence.setAttribute("id", UUID.randomUUID().toString());
    presence.setAttribute("from", from.toString());
    presence.setAttribute("to", to.toString());

    Element x = new Element("x", Namespace.getNamespace("http://jabber.org/protocol/muc#user"));

    if (type != null) {
        presence.setAttribute("type", type);
    }/*from w  ww .  j  av  a  2s. co m*/

    Element item = new Element("item", Namespace.getNamespace("http://jabber.org/protocol/muc#user"));
    item.setAttribute("affiliation", "member");

    switch (role) {
    case Participant:
        item.setAttribute("role", "participant");
        break;
    case Moderator:
        item.setAttribute("role", "moderator");
        break;
    case Visitor:
        item.setAttribute("role", "visitor");
        break;
    }
    x.addContent(item);
    presence.addContent(x);

    return presence;
}

From source file:com.kixeye.kixmpp.server.module.muc.MucRoom.java

License:Apache License

/**
 * Sends an direct invitation to a user.  Note: The smack client does not recognize this as a valid room invite.
 *//*from w w w.  j av a 2s.  c  o  m*/
public void sendDirectInvite(KixmppJid from, Channel userChannelToInvite, String reason) {
    Element message = new Element("message");
    message.setAttribute("to", userChannelToInvite.attr(BindKixmppServerModule.JID).get().getFullJid());
    if (from != null) {
        message.setAttribute("from", from.getFullJid());
    }

    Element x = new Element("x", Namespace.getNamespace("jabber:x:conference"));
    x.setAttribute("jid", roomJid.getFullJid());
    if (reason != null) {
        x.setAttribute("reason", reason);
    }

    message.addContent(x);

    userChannelToInvite.writeAndFlush(message);
}

From source file:com.kixeye.kixmpp.server.module.muc.MucRoom.java

License:Apache License

/**
 * Sends a mediated invitation to a user.
 *//*from w ww.  ja  va 2 s  .co m*/
public void sendMediatedInvite(KixmppJid from, Channel userChannelToInvite, String reason) {

    Element invite = new Element("invite");
    invite.setAttribute("from", from.getFullJid());
    if (reason != null) {
        Element el = new Element("reason");
        el.setText(reason);
        invite.addContent(el);
    }

    Element x = new Element("x", Namespace.getNamespace("http://jabber.org/protocol/muc#user"));
    x.addContent(invite);

    Element message = new Element("message");
    message.setAttribute("to", userChannelToInvite.attr(BindKixmppServerModule.JID).get().getFullJid());
    message.setAttribute("from", roomJid.getFullJid());
    message.addContent(x);

    userChannelToInvite.writeAndFlush(message);
}

From source file:com.medvision360.medrecord.basex.MockLocatableSerializer.java

License:Creative Commons License

@Override
public void serialize(Locatable locatable, OutputStream os, String encoding) throws IOException {
    String rmEntity = locatable.getArchetypeDetails().getArchetypeId().rmEntity();
    Element root = new Element(rmEntity);
    root.setAttribute("archetype_node_id", locatable.getArchetypeNodeId());

    set(root, "/uid/value", locatable.getUid().getValue());
    set(root, "/archetype_id/value", locatable.getArchetypeDetails().getArchetypeId().getValue());
    set(root, "/name/value", locatable.getName().getValue());

    Document d = new Document(root);

    Format format = Format.getPrettyFormat();
    format.setEncoding(encoding);// w ww  . j a  va2 s .c  om
    XMLOutputter output = new XMLOutputter(format);
    output.output(d, os);
}

From source file:com.novell.ldapchai.cr.ChaiHelpdeskAnswer.java

License:Open Source License

public Element toXml() throws ChaiOperationException {
    final Element answerElement = new Element(ChaiResponseSet.XML_NODE_ANSWER_VALUE);
    answerElement.setText(encryptValue(answer, challengeText));
    answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT, FormatType.HELPDESK.toString());
    return answerElement;
}

From source file:com.novell.ldapchai.cr.ChaiResponseSet.java

License:Open Source License

static String rsToChaiXML(final ChaiResponseSet rs) throws ChaiValidationException, ChaiOperationException {
    final Element rootElement = new Element(XML_NODE_ROOT);
    rootElement.setAttribute(XML_ATTRIBUTE_MIN_RANDOM_REQUIRED,
            String.valueOf(rs.getChallengeSet().getMinRandomRequired()));
    rootElement.setAttribute(XML_ATTRIBUTE_LOCALE, rs.getChallengeSet().getLocale().toString());
    rootElement.setAttribute(XML_ATTRIBUTE_VERSION, VALUE_VERSION);
    rootElement.setAttribute(XML_ATTRIBUTE_CHAI_VERSION, ChaiConstant.CHAI_API_VERSION);

    if (rs.caseInsensitive) {
        rootElement.setAttribute(XML_ATTRIBUTE_CASE_INSENSITIVE, "true");
    }//w  ww  .j  a v  a 2 s.c o m

    if (rs.csIdentifier != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_CHALLENGE_SET_IDENTIFER, rs.csIdentifier);
    }

    if (rs.timestamp != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_TIMESTAMP, DATE_FORMATTER.format(rs.timestamp));
    }

    if (rs.crMap != null) {
        for (final Challenge loopChallenge : rs.crMap.keySet()) {
            final Answer answer = rs.crMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }

    if (rs.helpdeskCrMap != null) {
        for (final Challenge loopChallenge : rs.helpdeskCrMap.keySet()) {
            final Answer answer = rs.helpdeskCrMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_HELPDESK_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }

    final Document doc = new Document(rootElement);
    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode(Format.TextMode.PRESERVE);
    format.setLineSeparator("");
    outputter.setFormat(format);
    return outputter.outputString(doc);
}

From source file:com.novell.ldapchai.cr.ChaiResponseSet.java

License:Open Source License

private static Element challengeToXml(final Challenge loopChallenge, final Answer answer,
        final String elementName) throws ChaiOperationException {
    final Element responseElement = new Element(elementName);
    responseElement/*ww  w  .  j a  v  a  2  s . com*/
            .addContent(new Element(XML_NODE_CHALLENGE).addContent(new Text(loopChallenge.getChallengeText())));
    final Element answerElement = answer.toXml();
    responseElement.addContent(answerElement);
    responseElement.setAttribute(XML_ATTRIBUTE_ADMIN_DEFINED, String.valueOf(loopChallenge.isAdminDefined()));
    responseElement.setAttribute(XML_ATTRIBUTE_REQUIRED, String.valueOf(loopChallenge.isRequired()));
    responseElement.setAttribute(XNL_ATTRIBUTE_MIN_LENGTH, String.valueOf(loopChallenge.getMinLength()));
    responseElement.setAttribute(XNL_ATTRIBUTE_MAX_LENGTH, String.valueOf(loopChallenge.getMaxLength()));
    return responseElement;
}

From source file:com.novell.ldapchai.cr.HashSaltAnswer.java

License:Open Source License

public Element toXml() {
    final Element answerElement = new Element(ChaiResponseSet.XML_NODE_ANSWER_VALUE);
    answerElement.setText(version.toString() + VERSION_SEPARATOR + answerHash);
    if (salt != null && salt.length() > 0) {
        answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_SALT, salt);
    }/*from  w w w.java  2  s .  co m*/
    answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT, formatType.toString());
    if (hashCount > 1) {
        answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_HASH_COUNT, String.valueOf(hashCount));
    }
    return answerElement;
}

From source file:com.novell.ldapchai.cr.TextAnswer.java

License:Open Source License

public Element toXml() {
    final Element answerElement = new Element(ChaiResponseSet.XML_NODE_ANSWER_VALUE);
    answerElement.setText(answer);//from  w  w  w  .  j ava 2s . co  m
    answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT, FormatType.TEXT.toString());
    return answerElement;
}

From source file:com.novell.ldapchai.impl.edir.NmasResponseSet.java

License:Open Source License

static String csToNmasXML(final ChallengeSet cs, final String guidValue) {
    final Element rootElement = new Element(NMAS_XML_ROOTNODE);
    rootElement.setAttribute(NMAS_XML_ATTR_RANDOM_COUNT, String.valueOf(cs.getMinRandomRequired()));
    if (guidValue != null) {
        rootElement.setAttribute("GUID", guidValue);
    } else {/*from www.  ja v a 2  s  .  c o  m*/
        rootElement.setAttribute("GUID", "0");
    }

    for (final Challenge challenge : cs.getChallenges()) {
        final Element loopElement = new Element(NMAS_XML_NODE_CHALLENGE);
        if (challenge.getChallengeText() != null) {
            loopElement.setText(challenge.getChallengeText());
        }

        if (challenge.isAdminDefined()) {
            loopElement.setAttribute(NMAS_XML_ATTR_DEFINE, "Admin");
        } else {
            loopElement.setAttribute(NMAS_XML_ATTR_DEFINE, "User");
        }

        if (challenge.isRequired()) {
            loopElement.setAttribute(NMAS_XML_ATTR_TYPE, "Required");
        } else {
            loopElement.setAttribute(NMAS_XML_ATTR_TYPE, "Random");
        }

        loopElement.setAttribute(NMAS_XML_ATTR_MIN_LENGTH, String.valueOf(challenge.getMinLength()));
        loopElement.setAttribute(NMAS_XML_ATTR_MAX_LENGTH, String.valueOf(challenge.getMaxLength()));

        rootElement.addContent(loopElement);
    }

    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode(Format.TextMode.PRESERVE);
    format.setLineSeparator("");
    outputter.setFormat(format);
    return outputter.outputString(rootElement);
}