Package org.apache.vysper.xml.fragment

Examples of org.apache.vysper.xml.fragment.Attribute


    }

    private static List<Attribute> createAttributes(String nick, Entity jid, Role role, Affiliation affiliation) {
        List<Attribute> attributes = new ArrayList<Attribute>();
        if (nick != null) {
            attributes.add(new Attribute("nick", nick));
        }
        if (jid != null) {
            attributes.add(new Attribute("jid", jid.getFullQualifiedName()));
        }
        if (role != null) {
            attributes.add(new Attribute("role", role.toString()));
        }
        if (affiliation != null) {
            attributes.add(new Attribute("affiliation", affiliation.toString()));
        }
       
        return attributes;
    }
View Full Code Here


import org.apache.vysper.xmpp.protocol.NamespaceURIs;

public class Delay extends XMLElement {

    public Delay(Entity from, Calendar timestamp) {
        super(NamespaceURIs.URN_XMPP_DELAY, "delay", null, Arrays.asList(new Attribute("from", from
                .getFullQualifiedName()), new Attribute("stamp", DateTimeProfile.getInstance().getDateTimeInUTC(
                timestamp.getTime()))), null);
    }
View Full Code Here

    }

    private static List<Attribute> createAttributes(StatusCode code) {
        List<Attribute> attributes = new ArrayList<Attribute>();
        if (code != null)
            attributes.add(new Attribute("code", Integer.toString(code.code())));
        return attributes;
    }
View Full Code Here

    }

    private static List<Attribute> createAttributes(Entity from, Entity to) {
        List<Attribute> attributes = new ArrayList<Attribute>();
        if (to != null)
            attributes.add(new Attribute("to", to.getFullQualifiedName()));
        if (from != null)
            attributes.add(new Attribute("from", from.getFullQualifiedName()));
        return attributes;
    }
View Full Code Here

                        logger.debug("Relaying message to all room occupants");
                        for (Occupant occupent : room.getOccupants()) {
                            logger.debug("Relaying message to  {}", occupent);
                            List<Attribute> replaceAttributes = new ArrayList<Attribute>();
                            replaceAttributes.add(new Attribute("from", roomAndSendingNick.getFullQualifiedName()));
                            replaceAttributes.add(new Attribute("to", occupent.getJid().getFullQualifiedName()));

                            relayStanza(occupent.getJid(), StanzaBuilder.createClone(stanza, true, replaceAttributes)
                                    .build(), serverRuntimeContext);

                        }

                        // add to discussion history
                        room.getHistory().append(stanza, sendingOccupant);
                    } else {
                        return createMessageErrorStanza(room.getJID(), from, stanza.getID(), StanzaErrorType.MODIFY,
                                StanzaErrorCondition.FORBIDDEN, stanza);
                    }
                } else {
                    return createMessageErrorStanza(room.getJID(), from, stanza.getID(), StanzaErrorType.MODIFY,
                            StanzaErrorCondition.NOT_ACCEPTABLE, stanza);
                }
            } else {
                return createMessageErrorStanza(moduleDomain, from, stanza.getID(), StanzaErrorType.MODIFY,
                        StanzaErrorCondition.ITEM_NOT_FOUND, stanza);
            }
        } else if (type == null || type == MessageStanzaType.CHAT || type == MessageStanzaType.NORMAL) {
            // private message
            logger.debug("Received direct message to {}", roomWithNickJid);
            Room room = conference.findRoom(roomJid);
            if (room != null) {
                Occupant sendingOccupant = room.findOccupantByJID(from);

                // sender must be participant in room
                if(roomWithNickJid.equals(roomJid)) {
                    // check x element
                   
                    if(stanza.getVerifier().onlySubelementEquals("x", NamespaceURIs.JABBER_X_DATA)) {
                        // voice requests
                        logger.debug("Received voice request for room {}", roomJid);
                       
                        handleVoiceRequest(from, sendingOccupant, room, stanza, serverRuntimeContext);
                    } else if(stanza.getVerifier().onlySubelementEquals("x", NamespaceURIs.XEP0045_MUC)) {
                        // invites/declines
                        return handleInvites(stanza, from, sendingOccupant, room, serverRuntimeContext);
                    }
                } else if (roomWithNickJid.isResourceSet()) {
                    if (sendingOccupant != null) {
                        // got resource, private message for occupant
                        Occupant receivingOccupant = room.findOccupantByNick(roomWithNickJid.getResource());

                        // must be sent to an existing occupant in the room
                        if (receivingOccupant != null) {

                            Entity roomAndSendingNick = new EntityImpl(room.getJID(), sendingOccupant.getNick());
                            logger.debug("Relaying message to  {}", receivingOccupant);
                            List<Attribute> replaceAttributes = new ArrayList<Attribute>();
                            replaceAttributes.add(new Attribute("from", roomAndSendingNick.getFullQualifiedName()));
                            replaceAttributes
                                    .add(new Attribute("to", receivingOccupant.getJid().getFullQualifiedName()));

                            relayStanza(receivingOccupant.getJid(), StanzaBuilder.createClone(stanza, true,
                                    replaceAttributes).build(), serverRuntimeContext);
                        } else {
                            // TODO correct error?
View Full Code Here

        return null;
  }

    private void relayTo(Entity from, List<Entity> tos, PresenceStanza original, SessionContext sessionContext) {
        List<Attribute> toFromReplacements = new ArrayList<Attribute>(2);
        toFromReplacements.add(new Attribute("from", from.getFullQualifiedName()));

        for (Entity to : tos) {
            toFromReplacements.add(new Attribute("to", to.getFullQualifiedName()));
            Stanza outgoingStanza = StanzaBuilder.createClone(original, true, toFromReplacements).build();
            relayStanza(to, outgoingStanza, sessionContext);
            toFromReplacements.remove(toFromReplacements.size()-1); // clear space for new 'to' attribute
        }
    }
View Full Code Here

        List<Attribute> originalAttributes = original.getAttributes();
        for (Attribute originalAttribute : originalAttributes) {
            boolean wasReplaced = false;
            for (Iterator<Attribute> it = replacingAttributesCopy.iterator(); it.hasNext();) {
                Attribute replacingAttribute = it.next();
                if (replacingAttribute == null)
                    continue;
                if (replacingAttribute.getName().equals(originalAttribute.getName())) {
                    stanzaBuilder.addAttribute(replacingAttribute);
                    it.remove(); // this has been processed
                    wasReplaced = true;
                    break;
                }
View Full Code Here

     * @return stanza builder with to and from replaced
     */
    public static StanzaBuilder createForward(Stanza original, Entity from, Entity to) {
        List<Attribute> toFromReplacements = new ArrayList<Attribute>(2);
        if (to != null)
            toFromReplacements.add(new Attribute("to", to.getFullQualifiedName()));
        if (from != null)
            toFromReplacements.add(new Attribute("from", from.getFullQualifiedName()));

        return createClone(original, true, toFromReplacements);
    }
View Full Code Here

                throw new XMLSemanticError("missing item node");
        } catch (XMLSemanticError xmlSemanticError) {
            throw new RosterBadRequestException("roster set needs a single item node.");
        }

        Attribute attributeJID = itemElement.getAttribute("jid");
        if (attributeJID == null || attributeJID.getValue() == null)
            throw new RosterBadRequestException("missing 'jid' attribute on item node");

        XMLElementVerifier verifier = itemElement.getVerifier();
        String name = verifier.attributePresent("name") ? itemElement.getAttribute("name").getValue() : null;
        if (name != null && name.length() > RosterConfiguration.ROSTER_ITEM_NAME_MAX_LENGTH) {
            throw new RosterNotAcceptableException("roster name too long: " + name.length());
        }

        SubscriptionType subscription = verifier.attributePresent("subscription") ? SubscriptionType
                .valueOf(itemElement.getAttribute("subscription").getValue().toUpperCase()) : SubscriptionType.NONE;
        if (!parseSubscriptionTypes && subscription != SubscriptionType.REMOVE)
            subscription = SubscriptionType.NONE; // roster remove is always tolerated

        AskSubscriptionType askSubscriptionType = AskSubscriptionType.NOT_SET;
        if (parseSubscriptionTypes) {
            askSubscriptionType = verifier.attributePresent("ask") ? AskSubscriptionType.valueOf("ASK_"
                    + itemElement.getAttribute("ask").getValue().toUpperCase()) : AskSubscriptionType.NOT_SET;
        }

        String contactJid = attributeJID.getValue();
        Entity contact;
        try {
            contact = EntityImpl.parse(contactJid);
        } catch (EntityFormatException e) {
            throw new RosterNotAcceptableException("jid cannot be parsed: " + contactJid);
View Full Code Here

        XMPPCoreStanza stanza = XMPPCoreStanza.getWrapper(anyStanza);
        if (stanza == null)
            throw new IllegalArgumentException("can only handle core XMPP stanzas (iq, message, presence)");

        // type="error" is common to all stanza, check here some prerequisites
        Attribute typeAttribute = stanza.getAttribute("type");
        XMPPCoreStanza xmppCoreStanza = XMPPCoreStanza.getWrapper(stanza);
        if (xmppCoreStanza != null && typeAttribute != null) {
            String errorDescription = null;
            String type = typeAttribute.getValue();
            if (IQStanzaType.ERROR.value().equals(type)) {
                // assure, result contains zero or one element
                // rfc3920/9.2.3/7.
                if (!stanza.getVerifier().subElementPresent("error")) {
                    errorDescription = "stanza of type error must include an 'error' child";
View Full Code Here

TOP

Related Classes of org.apache.vysper.xml.fragment.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.