Package org.apache.vysper.xml.fragment

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


        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


                childElements.add(encodeField(field));
            }
        }

        List<Attribute> attributes = new ArrayList<Attribute>();
        attributes.add(new Attribute("type", dataForm.getType().value()));

        return new XMLElement(NamespaceURIs.JABBER_X_DATA, "x", null, attributes, childElements);
    }
View Full Code Here

        ArrayList<XMLFragment> fieldElements = new ArrayList<XMLFragment>();

        List<Attribute> fieldAttributes = new ArrayList<Attribute>();
        if (field.getVar() != null) {
            fieldAttributes.add(new Attribute("var", field.getVar()));
        }
        if (field.getLabel() != null) {
            fieldAttributes.add(new Attribute("label", field.getLabel()));
        }
        if (field.getType() != null) {
            fieldAttributes.add(new Attribute("type", field.getType().value()));
        }

        if (field.getDesc() != null) {
            ArrayList<XMLFragment> descFragment = new ArrayList<XMLFragment>();
            descFragment.add(new XMLText(field.getDesc()));
            fieldElements.add(new XMLElement(NamespaceURIs.JABBER_X_DATA, "desc", null, null, descFragment));
        }

        if (field.isRequired()) {
            fieldElements.add(createEmptyElement(NamespaceURIs.JABBER_X_DATA, "required"));
        }

        Iterator<String> valueIterator = field.getValueIterator();
        while (valueIterator.hasNext()) {
            String value = valueIterator.next();
            XMLElement valueElement = createTextOnlyElement(NamespaceURIs.JABBER_X_DATA, "value", value);
            fieldElements.add(valueElement);
        }

        Iterator<Option> optionIterator = field.getOptions();
        while (optionIterator.hasNext()) {
            Option option = optionIterator.next();

            Attribute[] attributes = option.getLabel() == null ? null : new Attribute[] { new Attribute("label", option
                    .getLabel()) };
            XMLFragment[] elements = option.getValue() == null ? null : new XMLFragment[] { new XMLText(option
                    .getValue()) };

            XMLElement optionElement = new XMLElement(NamespaceURIs.JABBER_X_DATA, "option", null, attributes, elements);
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

        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

     * Creates a XMLElement like this <delete node="nodeName"/>
     * @param nodeName the value for the node attribute
     * @return the XMLElement for inclusion in the delete notification.
     */
    private XMLElement createDeleteElement(String nodeName) {
        return new XMLElement(null, "delete", null, new Attribute[] { new Attribute("node", nodeName) },
                (XMLFragment[]) null);
    }
View Full Code Here

    private static List<Attribute> createAttributes(Integer maxstanzas, Integer maxchars, Integer seconds,
            Calendar since) {
        List<Attribute> attributes = new ArrayList<Attribute>();
        if (maxstanzas != null)
            attributes.add(new Attribute(ATTRIBUTE_MAXSTANZAS, maxstanzas.toString()));
        if (maxchars != null)
            attributes.add(new Attribute(ATTRIBUTE_MAXCHARS, maxchars.toString()));
        if (seconds != null)
            attributes.add(new Attribute(ATTRIBUTE_SECONDS, seconds.toString()));
        if (since != null)
            attributes.add(new Attribute(ATTRIBUTE_SINCE, DateTimeProfile.getInstance().getDateTimeInUTC(
                    since.getTime())));
        return attributes;
    }
View Full Code Here

    }

    private static List<Attribute> createAttributes(Entity jid, String nick, Affiliation affiliation, Role role) {
        List<Attribute> attributes = new ArrayList<Attribute>();
        if (jid != null)
            attributes.add(new Attribute("jid", jid.getFullQualifiedName()));
        if (nick != null)
            attributes.add(new Attribute("nick", nick));
        if (affiliation != null)
            attributes.add(new Attribute("affiliation", affiliation.toString()));
        if (role != null)
            attributes.add(new Attribute("role", role.toString()));
        return attributes;
    }
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.