org.purl.sword.base
Class XmlElement

java.lang.Object
  extended by org.purl.sword.base.XmlElement
Direct Known Subclasses:
Author, BasicContentElement, Collection, Content, Entry, Generator, Link, Service, Source, SwordAcceptPackaging, TextConstruct, Workspace

public abstract class XmlElement
extends Object

Parent class for all classes that represent an XML element. This provides some common utility methods that are useful for marshalling and unmarshalling data.

Author:
Neil Taylor

Field Summary
protected static String DATE_FORMAT
          The Date format that is used to parse dates to and from the ISO format in the XML data.
protected static String[] DATE_FORMATS
          Array of possible date formats that are permitted for date elements.
protected  XmlName xmlName
           
 
Constructor Summary
XmlElement(String localName)
          Create a new instance.
XmlElement(String prefix, String localName)
          Create a new instance.
XmlElement(String prefix, String localName, String namespaceUri)
          Create a new insatnce.
XmlElement(XmlName name)
           
 
Method Summary
protected  SwordValidationInfo createValidAttributeInfo(String name, String content)
           
 String getQualifiedName()
          Retrieve the qualified name for this object.
 String getQualifiedName(String name)
          Retrieve the qualified name.
 String getQualifiedNameWithPrefix(String prefix, String name)
          Get the qualified name for the given prefix and name
 XmlName getXmlName()
           
protected  SwordValidationInfo handleIncorrectElement(nu.xom.Element element, Properties validationProperties)
           
protected  boolean isInstanceOf(nu.xom.Element element, String localName, String namespaceURI)
          Determines if the specified element is an instance of the element name.
protected  boolean isInstanceOf(nu.xom.Element element, XmlName xmlName)
           
protected  void processUnexpectedAttributes(nu.xom.Element element, ArrayList<SwordValidationInfo> attributeItems)
           
protected  void processUnexpectedAttributes(nu.xom.Element element, SwordValidationInfo info)
          Add the information to the unmarshall attribute section of the specified info object.
protected  boolean unmarshallBoolean(nu.xom.Element element)
          Extract a boolean value from the specified element.
protected  int unmarshallInteger(nu.xom.Element element)
          Extract an integer value from the specified element.
protected  String unmarshallString(nu.xom.Element element)
          Extract a string value from the specified element.
abstract  SwordValidationInfo validate(Properties validationContext)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlName

protected XmlName xmlName

DATE_FORMAT

protected static final String DATE_FORMAT
The Date format that is used to parse dates to and from the ISO format in the XML data.

See Also:
Constant Field Values

DATE_FORMATS

protected static final String[] DATE_FORMATS
Array of possible date formats that are permitted for date elements.

Constructor Detail

XmlElement

public XmlElement(String localName)
Create a new instance. Set the local name that will be used.

Parameters:
localName - The local name for the element.

XmlElement

public XmlElement(String prefix,
                  String localName)
Create a new instance. Set the prefix and local name.

Parameters:
prefix - The prefix for the element.
localName - The local name for the element.

XmlElement

public XmlElement(String prefix,
                  String localName,
                  String namespaceUri)
Create a new insatnce. Set the prefix, local name and the namespace URI.

Parameters:
prefix - The prefix.
localName - The element's local name.
namespaceUri - The namespace URI.

XmlElement

public XmlElement(XmlName name)
Parameters:
name -
Method Detail

getXmlName

public XmlName getXmlName()

unmarshallBoolean

protected boolean unmarshallBoolean(nu.xom.Element element)
                             throws UnmarshallException
Extract a boolean value from the specified element. The boolean value is represented as the string 'true' or 'false' as the only child of the specified element.

Parameters:
element - The element that contains the boolean value.
Returns:
True or false, based on the string in the element's content.
Throws:
UnmarshallException - If the element does not contain a single child, or if the child does not contain the value 'true' or 'false'.

unmarshallString

protected String unmarshallString(nu.xom.Element element)
                           throws UnmarshallException
Extract a string value from the specified element. The value is the only child of the specified element.

Parameters:
element - The element that contains the string value.
Returns:
The string.
Throws:
UnmarshallException - If the element does not contain a single child.

unmarshallInteger

protected int unmarshallInteger(nu.xom.Element element)
                         throws UnmarshallException
Extract an integer value from the specified element. The integer value is represented as a string in the only child of the specified element.

Parameters:
element - The element that contains the integer.
Returns:
The integer.
Throws:
UnmarshallException - If the element does not contain a single child, or if the child does not contain the valid integer.

isInstanceOf

protected boolean isInstanceOf(nu.xom.Element element,
                               String localName,
                               String namespaceURI)
Determines if the specified element is an instance of the element name. If you are checking the name title in the ATOM namespace, then the local name should be 'title' and the namespaceURI is the URI for the ATOM namespace.

Parameters:
element - The specified element.
localName - The local name for the element.
namespaceURI - The namespace for the element.
Returns:
True if the element matches the localname and namespace. Otherwise, false.

isInstanceOf

protected boolean isInstanceOf(nu.xom.Element element,
                               XmlName xmlName)
Parameters:
element -
xmlName -
Returns:

getQualifiedName

public String getQualifiedName()
Retrieve the qualified name for this object. This uses the prefix and local name stored in this object.

Returns:
A string of the format 'prefix:localName'

getQualifiedName

public String getQualifiedName(String name)
Retrieve the qualified name. The prefix for this object is prepended onto the specified local name.

Parameters:
name - the specified local name.
Returns:
A string of the format 'prefix:name'

getQualifiedNameWithPrefix

public String getQualifiedNameWithPrefix(String prefix,
                                         String name)
Get the qualified name for the given prefix and name

Parameters:
prefix - the prefix
name - the name
Returns:
the qualified name

validate

public abstract SwordValidationInfo validate(Properties validationContext)

processUnexpectedAttributes

protected void processUnexpectedAttributes(nu.xom.Element element,
                                           ArrayList<SwordValidationInfo> attributeItems)

processUnexpectedAttributes

protected void processUnexpectedAttributes(nu.xom.Element element,
                                           SwordValidationInfo info)
Add the information to the unmarshall attribute section of the specified info object.

Parameters:
element -
info -

handleIncorrectElement

protected SwordValidationInfo handleIncorrectElement(nu.xom.Element element,
                                                     Properties validationProperties)
                                              throws UnmarshallException
Throws:
UnmarshallException

createValidAttributeInfo

protected SwordValidationInfo createValidAttributeInfo(String name,
                                                       String content)


Copyright © 2010 DuraSpace. All Rights Reserved.