Java Code Examples for org.simpleframework.xml.stream.InputNode#getValue()

The following examples show how to use org.simpleframework.xml.stream.InputNode#getValue() . 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: ExampleConverters.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Cat read(InputNode source) throws Exception{
   int age = 0;
   String name = null;     
   while(true) {
      InputNode node = source.getNext();
      if(node == null) {
         break;
      }else if(node.getName().equals(ELEMENT_NAME)) {
         name = node.getValue();
      }else if(node.getName().equals(ELEMENT_AGE)){
         age = Integer.parseInt(node.getValue().trim());
      } 
   }
   return new Cat(name, age);
}
 
Example 2
Source File: PropertyValueXmlAdapter.java    From openkeepass with Apache License 2.0 5 votes vote down vote up
private boolean isProtected(InputNode node) throws Exception {
    InputNode isProtectedNode = node.getAttribute("Protected");
    if (isProtectedNode == null) {
        return false;
    }

    String value = isProtectedNode.getValue();
    return value.equalsIgnoreCase("true");
}
 
Example 3
Source File: PropertyValueXmlAdapter.java    From openkeepass with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyValue read(InputNode node) throws Exception {
    String value = node.getValue();

    if (value == null) {
        return new PropertyValue(false, "");
    }

    if (isProtected(node)) {
        String rawValue = strategy.apply(value);
        return new PropertyValue(true, rawValue);
    }
    
    return new PropertyValue(false, value);
}
 
Example 4
Source File: ConversionTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Cat read(InputNode source) throws Exception{
   int age = 0;
   String name = null;     
   while(true) {
      InputNode node = source.getNext();
      if(node == null) {
         break;
      }else if(node.getName().equals(ELEMENT_NAME)) {
         name = node.getValue();
      }else if(node.getName().equals(ELEMENT_AGE)){
         age = Integer.parseInt(node.getValue().trim());
      } 
   }
   return new Cat(name, age);
}
 
Example 5
Source File: DecoratorTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void read(Class field, NodeMap<InputNode> node) throws Exception{
    InputNode value = node.remove(replace);
    if(value != null) {
        String name = value.getValue();
        String type = read.get(name);
        if(type == null) {
            throw new PersistenceException("Could not match name %s", name);
        }
        node.put(label, type);
    }
}
 
Example 6
Source File: AnnotationTypeTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Value read(Type type, NodeMap<InputNode> node, Map map) throws Exception {
   Component component = type.getAnnotation(Component.class);
   
   if(component != null) {
      String name = component.name();
      InputNode value = node.get(KEY);
      
      if(!value.getValue().equals(name)) {
         throw new IllegalStateException("Component name incorrect, expected '"+name+"' but was '"+value.getValue()+"'");
      }
   }
   return strategy.read(type, node, map);
}
 
Example 7
Source File: EmptyElementConverterTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Object read(InputNode node) throws Exception {
   String value = node.getValue();
   
   if(value == null) {
      return "";
   }
   return value;
}
 
Example 8
Source File: IntegerConvert.java    From FlowGeek with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Integer read(InputNode node) throws Exception {
    try {
        String value = node.getValue();
        return Integer.valueOf(node.getValue());
    }catch (Exception e){
        return 0;
    }
}
 
Example 9
Source File: DynamicMapOfAttributesTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Car read(InputNode node) throws Exception {
   Car car = persister.read(Car.class, node, false);
   NodeMap<InputNode> attributes = node.getAttributes();
   
   for(String name : attributes) {
      InputNode attribute = attributes.get(name);
      String value = attribute.getValue();
      
      car.furtherAttributes.put(name, value);
   }
   return car;
}
 
Example 10
Source File: WrapperTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Wrapper read(InputNode node) throws Exception {
   InputNode type = node.getAttribute("type");
   InputNode child = node.getNext();
   String className = type.getValue();
   Object value = null;
   if(child != null) {
      value = serializer.read(Class.forName(className), child);
   }
   return new Wrapper(value);
}
 
Example 11
Source File: UuidConverter.java    From KeePassJava2 with Apache License 2.0 5 votes vote down vote up
@Override
public UUID read(InputNode inputNode) throws Exception {
    String value = inputNode.getValue();
    if (value == null || value.equals("")) {
        return UUID.randomUUID();
    }
    return Helpers.uuidFromBase64(value);
}
 
Example 12
Source File: TimeConverter.java    From KeePassJava2 with Apache License 2.0 5 votes vote down vote up
@Override
public Date read(InputNode inputNode) throws Exception {
    String value = inputNode.getValue();
    if (value.equals("${creationDate}")) {
        return new Date();
    }
    return Helpers.toDate(value);
}
 
Example 13
Source File: ConverterMapTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
private Entry readEntry(InputNode node) throws Exception {
   InputNode key = node.getAttribute("key");
   InputNode value = node.getNext("value");
   
   return new Entry(key.getValue(), value.getValue());
}
 
Example 14
Source File: ConverterDecorationTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public ConverterDecorationExample read(InputNode node) throws Exception {
   String name = node.getValue();
   return new ConverterDecorationExample(name);
}
 
Example 15
Source File: PathWithConverterTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public ServerDetails read(InputNode node) throws Exception {
   String host = node.getAttribute("host").getValue();
   String port = node.getAttribute("port").getValue();
   String name = node.getValue();
   return new ServerDetails(host, Integer.parseInt(port), name);
}
 
Example 16
Source File: EmptyStringConverter.java    From KeePassJava2 with Apache License 2.0 4 votes vote down vote up
@Override
public String read(InputNode inputNode) throws Exception {
    String value = inputNode.getValue();
    return value == null ? "": value;
}
 
Example 17
Source File: Base64ByteArrayConverter.java    From KeePassJava2 with Apache License 2.0 4 votes vote down vote up
@Override
public KeePassFile.ByteArray read(InputNode inputNode) throws Exception {
    String input = inputNode.getValue();
    byte[] value = input == null? new byte[0] : input.getBytes();
    return new KeePassFile.ByteArray(Helpers.decodeBase64Content(value, false));
}
 
Example 18
Source File: Primitive.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This <code>validate</code> method will validate the primitive 
 * by checking the node text. If the value is a reference then 
 * this will not extract any value from the node. Transformation
 * of the extracted value is not done as it can not account for
 * template variables. Thus any text extracted is valid.
 *
 * @param node this is the node to be validated as a primitive
 *
 * @return this returns the primitive that has been validated
 */ 
public boolean validate(InputNode node) throws Exception {
   if(node.isElement()) {
      validateElement(node);
   } else {
      node.getValue();
   }
   return true;
}
 
Example 19
Source File: Primitive.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This <code>read</code> method will extract the text value from
 * the node and replace any template variables before converting
 * it to a primitive value. This uses the <code>Context</code>
 * object used for this instance of serialization to replace all
 * template variables with values from the context filter.
 *
 * @param node this is the node to be converted to a primitive
 * @param type this is the type to read the primitive with
 *
 * @return this returns the primitive that has been deserialized
 */ 
public Object read(InputNode node, Class type) throws Exception{
   String value = node.getValue();

   if(value == null) {
      return null;
   }
   if(empty != null && value.equals(empty)) {
      return empty;         
   }
   return readTemplate(value, type);
}