org.purl.xnode
Class XNode

java.lang.Object
  extended by org.purl.xnode.XNode
Direct Known Subclasses:
XNodeImpl

public abstract class XNode
extends Object

XNode is an abstract class for an object acting as a container for XML content. XNode provides an envelope element and an extensible metadata container (in an <xnode:Header> element) for attributes such as a node ID, creation and modification timestamps, etc., with the document content stored in an <xnode:Body> element.

The XNode API (the package org.purl.xnode.*, both its source code and documentation), are released under the Apache 2.0 License. For more details, check the LICENSE file contained with the distribution, or see The Ceryle Project for more information. It is distributed with no warranty.

The following example shows an XNode wrapper around an XHTML document:

     <xnode:Envelope xmlns:xnode="http://www.purl.org/xnode/1.2/"
           xnode:id="n3892">
       <xnode:Header
           xnode:created="2001-10-22T18:33:56"
           xnode:modified="2003-08-19T12:23:37">
         <xnode:Property
             xnode:name="DC.format"
             xnode:value="application/xhtml+xml"/>
       </xnode:Header>
       <xnode:Body>
         <html xmlns="http://www.w3.org/1999/xhtml">
            [document content]
         </html>
       </xnode:Body>
       <xnode:Repository/>
     </xnode:Envelope>
  

The current XNode version is indicated by the XML Namespace value found in XMLNS_xnode12.

Notes

Note 1:

XNode 1.3 is completely backward-compatible with XNode 1.2, adding the ability to contain a new XNodeLink class (expressed in XML syntax by the <xnode:Link> Element) within properties. XNodeIDs are the targets of XNodeLinks.

Note 2:

XNode 1.2 adds revision control features but is essentially backwards compatible with 1.1. Over the history of the XNode API attributes have included the XML Namespace prefix. In XNode 1.2 all attributes are unprefixed so as to simplify the syntax (and given prefixing attributes within the same element namespace is a silly thing).

Note 3:

XNode 1.1 is nominally backward-compatible with XNode 1.0, but but no longer supports deprecated methods, and uses a different XML Namespace identifier (see XMLNS_xnode). XNode 1.1 now includes event-handling methods to track changes to the XNodeStore, and also allows for embedded XML content as XNode metadata.

Note 4:

The protected constructors and methods in this class are generally called by XNodeFactory or XNodeStore.

Note 5:

Date and time strings should follow the combined date and format defined in §5.4 of International Standard ISO 8601, "YYYY-MM-DD'T'hh:mm:ss", e.g., "2003-08-19T13:47:22". No time zone indicator is included as stored values should always be in Coordinated Universal Time (UTC). For more information, see: ISO 8601.

Since:
JDK1.3
Version:
$Id: XNode.java,v 3.12 2007-06-20 01:28:43 altheim Exp $
Author:
Murray Altheim

Field Summary
static String ATTR_created
          The local name of the created attribute.
static String ATTR_id
          The local name of the id attribute.
static String ATTR_index
          The local name of the index attribute.
static String ATTR_modified
          The local name of the modified attribute.
static String ATTR_name
          The local name of the name attribute.
static String ATTR_size
          The local name of the size attribute.
static String ATTR_value
          The local name of the value attribute.
static String ATTR_version
          The local name of the version attribute.
static String ATTR_weight
          The local name of the weight attribute.
static String ELT_body
          The local name of the <xnode:Body> element.
static String ELT_collection
          The local name of the <xnode:Collection> element.
static String ELT_envelope
          The local name of the <xnode:Envelope> element.
static String ELT_header
          The local name of the <xnode:Header> element.
static String ELT_link
          The local name of the <xnode:Link> element.
static String ELT_property
          The local name of the <xnode:Property> element.
static String ELT_repository
          The local name of the <xnode:Repository> element.
static String ELT_revision
          The local name of the <xnode:Revision> element.
static String ELT_text
          The local name of the <xnode:Text> element.
static String VERSION_10
          A String containing the XNode 1.0 version string.
static String VERSION_11
          A String containing the XNode 1.1 version string.
static String VERSION_12
          A String containing the XNode 1.2 version string.
static String VERSION_13
          A String containing the XNode 1.3 version string.
static String XMLNS_base
          A String containing a URI identifying the base XNode XML Namespace.
static String XMLNS_pfx
          The default XML Namespace prefix for XNode 1.x.
static String XMLNS_xnode
          The XML namespace identifier set to the most recent version of the XNode API.
static String XMLNS_xnode10
          A String containing a URI identifying the deprecated XNode 1.0 XML Namespace.
static String XMLNS_xnode11
          A String containing a URI identifying the deprecated XNode 1.1 XML Namespace.
static String XMLNS_xnode12
          A String containing a URI identifying the XNode 1.2 XML Namespace.
static String XMLNS_xnode13
          A String containing a URI identifying the XNode 1.3 XML Namespace.
 
Constructor Summary
protected XNode(String nid)
          Constructor with a required ID nid.
protected XNode(String nid, Node content)
          Constructor with a required ID nid and a DOM Node content.
 
Method Summary
abstract  Node getContent()
          Return a DOM Node containing this XNode's embedded content (exclusive of the XNode envelope), null if not set.
abstract  String getCreated()
          Return the creation date of this XNode as a String.
 String getID()
          Return the ID of this XNode as a String.
abstract  String getModified()
          Return the modification date of this XNode as a String.
abstract  Set getProperties()
          Return a Set containing all named properties of this XNode, an empty Set (not null) if none have been set.
abstract  Object getProperty(String name)
          Return the named property name as an Object, null if it has not been set.
abstract  List getRepository()
          Returns the List backing this XNode's repository (i.e., the List of individual XNodeRevision objects).
abstract  void modifyContent(Node content)
          Modifies this XNode by setting its content to the DOM Node content.
protected abstract  void setContent(Node content)
          Set the content of this XNode to the DOM Node content.
abstract  void setCreated(String timestamp)
          Set the creation date of this XNode to the String timestamp.
protected  void setID(String nid)
          Set the ID of this XNode to the String nid.
abstract  void setModified(String timestamp)
          Set the modification date of this XNode to the String timestamp.
abstract  void setProperty(String name, Object value)
          Set the named property name to the Object value.
abstract  String toString()
          Return a String representation of this XNode, including the XNode envelope.
abstract  String toString(boolean includeEnvelope)
          Return a String representation of this XNode, including the envelope if includeEnvelope is true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

XMLNS_base

public static final String XMLNS_base
A String containing a URI identifying the base XNode XML Namespace. This is absent any version; the value of the URI is:
   http://purl.org/xnode/

See Also:
Constant Field Values

VERSION_13

public static final String VERSION_13
A String containing the XNode 1.3 version string. The value is: "1.3".

See Also:
Constant Field Values

XMLNS_xnode13

public static final String XMLNS_xnode13
A String containing a URI identifying the XNode 1.3 XML Namespace. The value of the URI for XNode 1.3 is:
   http://purl.org/xnode/1.3/

See Also:
Constant Field Values

VERSION_12

public static final String VERSION_12
A String containing the XNode 1.2 version string. The value is: "1.2".

See Also:
Constant Field Values

XMLNS_xnode12

public static final String XMLNS_xnode12
A String containing a URI identifying the XNode 1.2 XML Namespace. The value of the URI for XNode 1.2 is:
   http://purl.org/xnode/1.2/

See Also:
Constant Field Values

VERSION_11

public static final String VERSION_11
A String containing the XNode 1.1 version string. The value is: "1.1".

See Also:
Constant Field Values

XMLNS_xnode11

public static final String XMLNS_xnode11
A String containing a URI identifying the deprecated XNode 1.1 XML Namespace. The value of the URI for XNode 1.1 is:
   http://purl.org/xnode/1.1/

See Also:
Constant Field Values

VERSION_10

public static final String VERSION_10
A String containing the XNode 1.0 version string. The value is: "1.0".

See Also:
Constant Field Values

XMLNS_xnode10

public static final String XMLNS_xnode10
A String containing a URI identifying the deprecated XNode 1.0 XML Namespace. The value of the URI for XNode 1.0 is:
   http://purl.org/xnode/1.0/

See Also:
Constant Field Values

XMLNS_xnode

public static final String XMLNS_xnode
The XML namespace identifier set to the most recent version of the XNode API. The value is "http://purl.org/xnode/1.3/".

This is the place where the version string for XNode is set.

See Also:
Constant Field Values

XMLNS_pfx

public static String XMLNS_pfx
The default XML Namespace prefix for XNode 1.x. Note that this String should not include a colon character, e.g., simply "xnode".


ELT_envelope

public static final String ELT_envelope
The local name of the <xnode:Envelope> element.

See Also:
Constant Field Values

ELT_header

public static final String ELT_header
The local name of the <xnode:Header> element.

See Also:
Constant Field Values

ELT_body

public static final String ELT_body
The local name of the <xnode:Body> element.

See Also:
Constant Field Values

ELT_text

public static final String ELT_text
The local name of the <xnode:Text> element.

See Also:
Constant Field Values

ELT_property

public static final String ELT_property
The local name of the <xnode:Property> element.

See Also:
Constant Field Values

ELT_link

public static final String ELT_link
The local name of the <xnode:Link> element.

See Also:
Constant Field Values

ELT_repository

public static final String ELT_repository
The local name of the <xnode:Repository> element.

See Also:
Constant Field Values

ELT_revision

public static final String ELT_revision
The local name of the <xnode:Revision> element.

See Also:
Constant Field Values

ELT_collection

public static final String ELT_collection
The local name of the <xnode:Collection> element.

See Also:
Constant Field Values

ATTR_id

public static final String ATTR_id
The local name of the id attribute.

See Also:
Constant Field Values

ATTR_created

public static final String ATTR_created
The local name of the created attribute.

See Also:
Constant Field Values

ATTR_modified

public static final String ATTR_modified
The local name of the modified attribute.

See Also:
Constant Field Values

ATTR_name

public static final String ATTR_name
The local name of the name attribute.

See Also:
Constant Field Values

ATTR_value

public static final String ATTR_value
The local name of the value attribute.

See Also:
Constant Field Values

ATTR_version

public static final String ATTR_version
The local name of the version attribute.

See Also:
Constant Field Values

ATTR_size

public static final String ATTR_size
The local name of the size attribute.

See Also:
Constant Field Values

ATTR_index

public static final String ATTR_index
The local name of the index attribute.

See Also:
Constant Field Values

ATTR_weight

public static final String ATTR_weight
The local name of the weight attribute.

See Also:
Constant Field Values
Constructor Detail

XNode

protected XNode(String nid)
         throws XNodeException
Constructor with a required ID nid.

Parameters:
nid - the XNode ID.
Throws:
XNodeException - if the ID value is not an XML Name.
Since:
XNode 1.0

XNode

protected XNode(String nid,
                Node content)
         throws XNodeException
Constructor with a required ID nid and a DOM Node content.

Parameters:
nid - the XNode ID.
content - the DOM Node used as XNode content.
Throws:
XNodeException - if the ID value is not an XML Name.
Since:
XNode 1.0
Method Detail

setID

protected void setID(String nid)
              throws XNodeException
Set the ID of this XNode to the String nid. XNode implementations should throw an XNodeException if the ID is already set or if the value is not a valid XML Name.

Parameters:
nid - the XNode ID.
Throws:
XNodeException - if already set, or is not an XML Name.
Since:
XNode 1.0

getID

public String getID()
Return the ID of this XNode as a String.

Returns:
the XNode ID.
Since:
XNode 1.0

setCreated

public abstract void setCreated(String timestamp)
                         throws XNodeException
Set the creation date of this XNode to the String timestamp.

See Note.

Parameters:
timestamp - the creation timestamp as a String.
Throws:
XNodeException - if already set or an error occurs (such as the timestamp being in an unrecognizable format).
Since:
XNode 1.0

getCreated

public abstract String getCreated()
Return the creation date of this XNode as a String.

See Note.

Returns:
the creation date of this XNode.
Since:
XNode 1.0

setModified

public abstract void setModified(String timestamp)
                          throws XNodeException
Set the modification date of this XNode to the String timestamp.

See Note.

Parameters:
timestamp - the modification timestamp as a String.
Throws:
XNodeException - if an error occurs (such as the timestamp being in an unrecognizable format).
Since:
XNode 1.0

getModified

public abstract String getModified()
Return the modification date of this XNode as a String.

See Note.

Returns:
the modification date of this XNode, null if not set.
Since:
XNode 1.0

setProperty

public abstract void setProperty(String name,
                                 Object value)
                          throws XNodeException,
                                 NullPointerException
Set the named property name to the Object value. If the property has already been set, its value is replaced. If the property has been set and the provided value is null, the named property is removed.

The provided value must be a String or a DOM Node, otherwise an XNodeException is thrown.

Modified from XNode 1.0

Parameters:
name - the property name.
value - the property value, a String or DOM Node.
Throws:
XNodeException - if the property value is invalid.
NullPointerException - if either name or value parameter is null.
Since:
XNode 1.1

getProperty

public abstract Object getProperty(String name)
                            throws NullPointerException
Return the named property name as an Object, null if it has not been set. The returned value will be either a String or DOM Node.

Modified from XNode 1.0

Parameters:
name - the property name.
Returns:
the property value, null if not set.
Throws:
NullPointerException - if the name parameter is null.
Since:
XNode 1.1

getProperties

public abstract Set getProperties()
Return a Set containing all named properties of this XNode, an empty Set (not null) if none have been set.

Returns:
the Set of named properties (as Strings).
Since:
XNode 1.1

setContent

protected abstract void setContent(Node content)
                            throws XNodeException
Set the content of this XNode to the DOM Node content. The provided DOM node must already be a child of the XNode envelope. Note that the created and modified timestamps for this XNode are not set by this method. Setting the content to null will nullify the internal DOM representation of the XNode.

Parameters:
content - the Node to set as the content of this XNode.
Throws:
XNodeException - if there is existing content.
Since:
XNode 1.0

modifyContent

public abstract void modifyContent(Node content)
                            throws XNodeException
Modifies this XNode by setting its content to the DOM Node content. The content can be set to null. The provided DOM node must already be a child of the XNode envelope. Note that the created and modified timestamps for this XNode are not set by this method. Setting the content to null will nullify the internal DOM representation of the XNode.

Parameters:
content - the Node to set as the content of this XNode.
Throws:
XNodeException - if any problem occurs during modification.
Since:
XNode 1.0

getContent

public abstract Node getContent()
                         throws XNodeException
Return a DOM Node containing this XNode's embedded content (exclusive of the XNode envelope), null if not set.

Returns:
the DOM Node containing this XNode's content.
Throws:
XNodeException
Since:
XNode 1.0

getRepository

public abstract List getRepository()
                            throws XNodeException
Returns the List backing this XNode's repository (i.e., the List of individual XNodeRevision objects). This will return an empty List rather than null if there are no revisions. Note that while creation of the List is the responsibility of the XNode, its population and management is handled entirely by the XNodeRevisionManager.

Throws:
XNodeException
Since:
XNode 1.2

toString

public abstract String toString()
Return a String representation of this XNode, including the XNode envelope. If the XNode's content is null or empty, this returns an empty envelope.

Note:

Serializations of XNodes are more efficient using the XNodeFactory.serializeXNode(XNode,Writer,boolean) method than using either toString() method, since implementations may find it necessary to create an XML parser instance for each method call. If toString() is unimplemented, it is appropriate to throw a UnsupportedOperationException rather than return an incorrect XML serialization.

Overrides:
toString in class Object
Returns:
a String representation of this XNode.
Since:
XNode 1.0

toString

public abstract String toString(boolean includeEnvelope)
Return a String representation of this XNode, including the envelope if includeEnvelope is true. See toString() for notes regarding use of this method.

Returns:
a String representation of this XNode.
Since:
XNode 1.0


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.