org.ceryle.xnode
Class XNodeUtils

java.lang.Object
  extended by org.ceryle.xnode.XNodeUtils

public class XNodeUtils
extends Object

Provides some static XNode utility methods. This includes some string utilities copied from org.ceryle.util.Utilities to remove the dependency on that class for XNode-specific implementations.

Since:
JDK1.4
Version:
$Id: XNodeUtils.java,v 3.4 2007-06-15 12:10:31 altheim Exp $
Author:
Murray Altheim

Field Summary
static String EMPTY_STRING
           
 
Constructor Summary
XNodeUtils()
           
 
Method Summary
static String convertFromList(List list)
          Converts the provided List of Strings to a whitespace-delimited String.
static List convertToList(String s, String delim)
          Converts the whitespace-delimited String s to a List of Strings.
static String[] decomposeURI(String baseURI, String uri)
          Returns the Collection ID, Node ID, and fragment ID as Strings provided using the database root URI compared with an 'xnode:' URI uri, assuming it is has an xnode: protocol.
static Map getProperties(Element header)
          Provided with the <xnode:Header> DOM Element, returns a Map of name-value pairs of Strings.
static boolean listsAreEquivalent(List a, List b)
          Returns true if the two lists contain the same objects in the same order.
static String metadataMatches(Element header1, Element header2, boolean matchDates, boolean matchVersion)
          Returns null if the two <xnode:Header> elements contain the same set of <xnode:Property> (name-value pairs of metadata) elements, matching on both name and value.
static void modifyXNodeContent(XNode xnode, String content)
          Sets the content of the provided XNode to a CDATASection created from the String content.
static void serialize(XNode xnode, Object out, boolean close)
          Serializes the provided XNode's content to the Object out using the serialization method determined by the XNode's format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRING

public static final String EMPTY_STRING
Constructor Detail

XNodeUtils

public XNodeUtils()
Method Detail

serialize

public static void serialize(XNode xnode,
                             Object out,
                             boolean close)
                      throws XNodeException
Serializes the provided XNode's content to the Object out using the serialization method determined by the XNode's format.

Parameters:
xnode - the optional XNode that is used to set the public and system identifiers, if present.
out - the File, Writer or OutputStream to receive the serialized content.
close - when true, closes the writer upon completion
Throws:
XNodeException - if a serialization error occurs.

metadataMatches

public static String metadataMatches(Element header1,
                                     Element header2,
                                     boolean matchDates,
                                     boolean matchVersion)
Returns null if the two <xnode:Header> elements contain the same set of <xnode:Property> (name-value pairs of metadata) elements, matching on both name and value.

If matchDates is true, checks the created date, and if both are available, the modified dates for a match. If there is a mismatch on either created or modified dates, returns an appropriate message.

If matchVersion is true, the version number property must also match; otherwise it is ignored. If a mismatch if found, returns a message describing the first mismatch found.

Returns:
null if the two property sets match, otherwise a message describing the mismatch.

getProperties

public static Map getProperties(Element header)
Provided with the <xnode:Header> DOM Element, returns a Map of name-value pairs of Strings. If there are no properties, this will return an empty Map rather than null.


modifyXNodeContent

public static void modifyXNodeContent(XNode xnode,
                                      String content)
                               throws XNodeException
Sets the content of the provided XNode to a CDATASection created from the String content. This doesn't perform any sanity checks on existing content, set MIME types, etc.

Throws:
XNodeException

convertToList

public static List convertToList(String s,
                                 String delim)
Converts the whitespace-delimited String s to a List of Strings. If the delimiter set is not provided (ie., the parameter is null), this uses the default StringTokenizer set of delimiters, which is " \t\n\r\f": the space character, the tab character, the newline character, the carriage-return character, and the form-feed character. Returns an empty array rather than null. This will process the special case of a token matchin "_EMPTY_STRING_" as an empty string.


convertFromList

public static String convertFromList(List list)
Converts the provided List of Strings to a whitespace-delimited String. If the list is empty this will return a null value rather than an empty String. Throws a ClassCastException if any of the List elements is not a String.


listsAreEquivalent

public static boolean listsAreEquivalent(List a,
                                         List b)
Returns true if the two lists contain the same objects in the same order. This performs a String comparison when the objects are Strings, otherwise this uses Object's equals() method. Nulls are permitted.


decomposeURI

public static String[] decomposeURI(String baseURI,
                                    String uri)
                             throws XNodeException
Returns the Collection ID, Node ID, and fragment ID as Strings provided using the database root URI compared with an 'xnode:' URI uri, assuming it is has an xnode: protocol. If not, returns { null, null, null }.

(this is not an XNode API method)

Throws:
XNodeException


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