Java Code Examples for org.simpleframework.xml.stream.OutputNode#setValue()

The following examples show how to use org.simpleframework.xml.stream.OutputNode#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityWithAnyElementConverter.java    From sardine-android with Apache License 2.0 6 votes vote down vote up
@Override
public void write(OutputNode node, T entity) throws Exception {
    for(org.w3c.dom.Element domElement : entity.getAny()) {
        ElementConverter.write(node, domElement);
    }
    Map<String, Field> entityFields = getEntityFields();
    for (String fieldName : entityFields.keySet()) {
        Field field = entityFields.get(fieldName);
        Object value = getGetterForField(field).invoke(entity);
        if (value == null) {
            continue;
        }
        if (value instanceof String) {
            OutputNode childNode = node.getChild(fieldName);
            childNode.setReference(SardineUtil.DEFAULT_NAMESPACE_URI);
            childNode.setValue((String)value);
        } else {
            serializer.write(value, node);
        }
    }
}
 
Example 2
Source File: EntityWithAnyElementConverter.java    From simpletask-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void write(OutputNode node, T entity) throws Exception {
    for(org.w3c.dom.Element domElement : entity.getAny()) {
        ElementConverter.write(node, domElement);
    }
    Map<String, Field> entityFields = getEntityFields();
    for (String fieldName : entityFields.keySet()) {
        Field field = entityFields.get(fieldName);
        Object value = getGetterForField(field).invoke(entity);
        if (value == null) {
            continue;
        }
        if (value instanceof String) {
            OutputNode childNode = node.getChild(fieldName);
            childNode.setReference(SardineUtil.DEFAULT_NAMESPACE_URI);
            childNode.setValue((String)value);
        } else {
            serializer.write(value, node);
        }
    }
}
 
Example 3
Source File: EmptyStringConverter.java    From KeePassJava2 with Apache License 2.0 5 votes vote down vote up
@Override
public void write(OutputNode outputNode, String s) throws Exception {
    if(s==null || s.equals("")) {
        outputNode.setValue(null);
    } else {
        outputNode.setValue(s);
    }
}
 
Example 4
Source File: ConverterMapTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void write(OutputNode node, Map map) throws Exception {
   Set keys = map.keySet();
   
   for(Object key : keys) {
      OutputNode next = node.getChild("entry");
      next.setAttribute("key", key.toString());
      OutputNode value = next.getChild("value");
      value.setValue(map.get(key).toString());
   }
}
 
Example 5
Source File: NamespaceDecoratorTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testQualifier() throws Exception {
   NamespaceDecorator global = new NamespaceDecorator();
   NamespaceDecorator qualifier = new NamespaceDecorator();
   NamespaceDecorator attribute = new NamespaceDecorator();
   
   global.add(new MockNamespace("global", "http://www.domain.com/global")); 
   qualifier.add(new MockNamespace("a", "http://www.domain.com/a"));
   qualifier.add(new MockNamespace("b", "http://www.domain.com/b"));
   qualifier.add(new MockNamespace("c", "http://www.domain.com/c"));
   attribute.add(new MockNamespace("d", "http://www.domain.com/d"));
   
   global.set(new MockNamespace("first", "http://www.domain.com/ignore"));
   qualifier.set(new MockNamespace("a", "http://www.domain.com/a"));
   attribute.set(new MockNamespace("b", "http://www.domain.com/b"));

   StringWriter out = new StringWriter(); 
   
   OutputNode top = NodeBuilder.write(out);
   OutputNode root = top.getChild("root");
   
   root.setAttribute("version", "1.0");
   qualifier.decorate(root, global);
   
   OutputNode child = root.getChild("child");
   child.setAttribute("name", "John Doe");
   
   OutputNode name = child.getAttributes().get("name");
   attribute.decorate(name);
   
   OutputNode grandChild = child.getChild("grandChild");
   grandChild.setValue("this is the grand child");
   
   root.commit();
   validate(out.toString());     
}
 
Example 6
Source File: TimeConverter.java    From KeePassJava2 with Apache License 2.0 4 votes vote down vote up
@Override
public void write(OutputNode outputNode, Date date) throws Exception {
    outputNode.setValue(Helpers.fromDate(date));
}
 
Example 7
Source File: KeePassBooleanConverter.java    From KeePassJava2 with Apache License 2.0 4 votes vote down vote up
@Override
public void write(OutputNode outputNode, Boolean bool) throws Exception {
    outputNode.setValue(Helpers.fromBoolean(bool));
}
 
Example 8
Source File: Base64ByteArrayConverter.java    From KeePassJava2 with Apache License 2.0 4 votes vote down vote up
@Override
public void write(OutputNode outputNode, KeePassFile.ByteArray bytes) throws Exception {
    outputNode.setValue(Helpers.encodeBase64Content(bytes.getContent(), false));
}
 
Example 9
Source File: UuidConverter.java    From KeePassJava2 with Apache License 2.0 4 votes vote down vote up
@Override
public void write(OutputNode outputNode, UUID uuid) throws Exception {
    outputNode.setValue(Helpers.base64FromUuid(uuid));
}
 
Example 10
Source File: ExampleConverters.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public void write(OutputNode node, Cat cat)throws Exception {
   OutputNode name = node.getChild(ELEMENT_NAME);
   name.setValue(cat.getName());
   OutputNode age = node.getChild(ELEMENT_AGE);
   age.setValue(String.valueOf(cat.getAge()));
}
 
Example 11
Source File: EmptyElementConverterTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public void write(OutputNode node, Object value) throws Exception {
   node.setValue(String.valueOf(value));
}
 
Example 12
Source File: ConverterDecorationTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public void write(OutputNode node, ConverterDecorationExample value) throws Exception {
   node.setValue(value.name);
}
 
Example 13
Source File: PathWithConverterTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public void write(OutputNode node, ServerDetails value) throws Exception {
   node.setAttribute("host", value.host);
   node.setAttribute("port", String.valueOf(value.port));
   node.setValue(value.name);
}
 
Example 14
Source File: ConversionTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public void write(OutputNode node, Cat cat)throws Exception {
   OutputNode name = node.getChild(ELEMENT_NAME);
   name.setValue(cat.getName());
   OutputNode age = node.getChild(ELEMENT_AGE);
   age.setValue(String.valueOf(cat.getAge()));
}
 
Example 15
Source File: ElementConverter.java    From simpletask-android with GNU General Public License v3.0 4 votes vote down vote up
public static void write(OutputNode parent, Element domElement) throws Exception {
    OutputNode child = parent.getChild(domElement.getNodeName());
    child.getNamespaces().setReference(domElement.getNamespaceURI(), domElement.getPrefix());
    child.setValue(domElement.getTextContent());
    child.commit();
}
 
Example 16
Source File: ElementConverter.java    From sardine-android with Apache License 2.0 4 votes vote down vote up
public static void write(OutputNode parent, Element domElement) throws Exception {
    OutputNode child = parent.getChild(domElement.getNodeName());
    child.getNamespaces().setReference(domElement.getNamespaceURI(), domElement.getPrefix());
    child.setValue(domElement.getTextContent());
    child.commit();
}
 
Example 17
Source File: Primitive.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This <code>write</code> method will serialize the contents of
 * the provided object to the given XML element. This will use
 * the <code>String.valueOf</code> method to convert the object to
 * a string if the object represents a primitive, if however the
 * object represents an enumerated type then the text value is
 * created using <code>Enum.name</code>.
 *
 * @param source this is the object to be serialized
 * @param node this is the XML element to have its text set
 */  
public void write(OutputNode node, Object source) throws Exception {
   String text = factory.getText(source);
 
   if(text != null) {
      node.setValue(text);
   }  
}
 
Example 18
Source File: Composite.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This write method is used to set the value of the provided object
 * as the text for the XML element. This will acquire the string
 * value of the object using <code>toString</code> only if the
 * object provided is not an enumerated type. If the object is an
 * enumerated type then the <code>Enum.name</code> method is used.
 * 
 * @param value this is the value to set as the XML element text
 * @param node this is the XML element to write the text value to
 * @param label the label that contains the contact details
 */
private void writeText(OutputNode node, Object value, Label label) throws Exception {
   if(value != null && !label.isTextList()) {         
      String text = factory.getText(value); 
      boolean data = label.isData();
      
      node.setData(data);
      node.setValue(text);        
   }
}