Package org.apache.vysper.xml.fragment

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


    assertRendering("<foo attr1=\"val&gt;ue1\"></foo>", elm);
  }

  // < must be escaped
  public void testRenderAttributeWithLt() {
    XMLElement elm = new XMLElement(null, "foo", null, new Attribute[]{new Attribute("attr1", "val<ue1")}, null);
    assertRendering("<foo attr1=\"val&lt;ue1\"></foo>", elm);
  }
View Full Code Here


    assertRendering("<foo attr1=\"val&lt;ue1\"></foo>", elm);
  }

  public void testRenderNamespacedAttribute() {
    XMLElement elm = new XMLElement(null, "foo", null, new Attribute[]{
        new Attribute("http://example.com", "attr1", "value1"),
        new NamespaceAttribute("pr1", "http://example.com")
        }, null);
    assertRendering("<foo xmlns:pr1=\"http://example.com\" pr1:attr1=\"value1\"></foo>", elm);
  }
View Full Code Here

  }

  // make sure we render the xml namespace correctly, e.g for xml:lang
  public void testRenderXmlNamespacedAttribute() {
    XMLElement elm = new XMLElement(null, "foo", null, new Attribute[]{
        new Attribute(NamespaceURIs.XML, "lang", "sv")
        }, null);
    assertRendering("<foo xml:lang=\"sv\"></foo>", elm);
  }
View Full Code Here

    assertRendering("<foo xml:lang=\"sv\"></foo>", elm);
  }
 
  public void testRenderUndeclaredNamespacedAttribute() {
    XMLElement elm = new XMLElement(null, "foo", null, new Attribute[]{
        new Attribute("http://example.com", "attr1", "value1")
        }, null);
   
    assertRendering("<foo xmlns:ns1=\"http://example.com\" ns1:attr1=\"value1\"></foo>", elm);
  }
View Full Code Here

        List<Attribute> attributes = stanza.getAttributes();

        // inner attribues are immutable
        int size = attributes.size();
        try {
            attributes.add(new Attribute("not", "insertable"));
            fail("attributes should be immutable");
        } catch (UnsupportedOperationException e) {
            // succeeded
        }
        assertEquals("nothing inserted", size, attributes.size());

        assertEquals("a1", "at1", attributes.get(0).getName());
        assertEquals("a1", "av1", attributes.get(0).getValue());
        assertEquals("a2", "at2", attributes.get(1).getName());
        assertEquals("a2", "av2", attributes.get(1).getValue());
        try {
            attributes.add(new Attribute("unmodName", "unmodValue"));
            fail("could modify mutual attribute list");
        } catch (UnsupportedOperationException e) {
            // fall through
        }
    }
View Full Code Here

                    } else {
                        stack.pop();
                        currentState = AttributeParseState.BEFORE_KEY;
                        value = collect.toString();
                        collect = null;
                        attributes.add(new Attribute(key, value));
                    }
                    break;
            }
        }
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", NamespaceURIs.JABBER_X_DATA, 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()));
        }

        ArrayList<XMLFragment> descFragment = new ArrayList<XMLFragment>();
        if (field.getDesc() != null) {
            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);
            fieldElements.add(optionElement);
        }
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

     * @param to if NOT NULL, the new 'to'
     * @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

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.