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

The following examples show how to use org.simpleframework.xml.stream.InputNode#getAttribute() . 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: 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 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: 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 4
Source File: PrimitiveKey.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This method is used to read the key value from the node. The 
 * value read from the node is resolved using the template filter.
 * If the key value can not be found according to the annotation
 * attributes then an null is assumed and returned.
 * 
 * @param node this is the node to read the key value from
 * @param key this is the name of the attribute used by the key 
 *     
 * @return this returns the value deserialized from the node
 */
private Object readAttribute(InputNode node, String key) throws Exception {     
   String name = style.getAttribute(key);
   InputNode child = node.getAttribute(name);
   
   if(child == null) {
      return null;
   }
   return root.read(child);
}
 
Example 5
Source File: PrimitiveKey.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This method is used to read the key value from the node. The 
 * value read from the node is resolved using the template filter.
 * If the key value can not be found according to the annotation
 * attributes then the node is considered as null and is valid.
 * 
 * @param node this is the node to read the key value from
 * @param key this is the name of the attribute used by the key 
 *     
 * @return this returns the value deserialized from the node
 */
private boolean validateAttribute(InputNode node, String key) throws Exception {     
   String name = style.getElement(key);
   InputNode child = node.getAttribute(name);
   
   if(child == null) {
      return true;
   }
   return root.validate(child);
}
 
Example 6
Source File: Composite.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This <code>readAttributes</code> method reads the attributes from
 * the provided XML element. This will iterate over all attributes
 * within the element and convert those attributes as primitives to
 * contact values within the source object.
 * <p>
 * Once all attributes within the XML element have been evaluated
 * the <code>Schema</code> is checked to ensure that there are no
 * required contacts annotated with the <code>Attribute</code> that
 * remain. If any required attribute remains an exception is thrown. 
 * 
 * @param node this is the XML element to be evaluated
 * @param source the type of the object that is being deserialized
 * @param section this is the XML section that contains the structure
 */
private void readAttributes(InputNode node, Object source, Section section) throws Exception {
   NodeMap<InputNode> list = node.getAttributes();
   LabelMap map = section.getAttributes();

   for(String name : list) {         
      InputNode value = node.getAttribute(name);
      
      if(value != null) {
         readAttribute(value, source, section, map);
      }
   }  
   validate(node, map, source);
}
 
Example 7
Source File: Composite.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This <code>validateAttributes</code> method validates the attributes 
 * from the provided XML element. This will iterate over all attributes
 * within the element and validate those attributes as primitives to
 * contact values within the source object.
 * <p>
 * Once all attributes within the XML element have been evaluated the
 * <code>Schema</code> is checked to ensure that there are no required 
 * contacts annotated with the <code>Attribute</code> that remain. If 
 * any required attribute remains an exception is thrown. 
 * 
 * @param node this is the XML element to be validated
 * @param section this is the section that defines the XML structure
 */
private void validateAttributes(InputNode node, Section section) throws Exception {
   NodeMap<InputNode> list = node.getAttributes();
   LabelMap map = section.getAttributes();

   for(String name : list) {         
      InputNode value = node.getAttribute(name);
      
      if(value != null) {
         validateAttribute(value, section, map);
      }
   }  
   validate(node, map);
}
 
Example 8
Source File: PrimitiveValue.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This method is used to read the text value from the node. The 
 * value read from the node is resolved using the template filter.
 * If the value value can not be found according to the annotation
 * attributes then null is assumed and returned.
 * 
 * @param node this is the node to read the value object from
 * @param name this is the name of the value XML attribute, if any
 * 
 * @return this returns the value deserialized from the node
 */ 
private Object readAttribute(InputNode node, String name) throws Exception {
   if(name != null) {
      name = style.getAttribute(name);
      node = node.getAttribute(name);
   }       
   if(node == null) {
      return null;        
   }
   return root.read(node);      
}