verinec.util
Class DataUtil

java.lang.Object
  extended by verinec.util.DataUtil

public class DataUtil
extends Object

Utility functions for data operations.

Version:
$Revision: 880 $
Author:
david.buchmann at unifr.ch

Field Summary
private static XSLTransformer nodeRemover
          A transformer to remove the <node> tags from a nodes element.
 
Constructor Summary
private DataUtil()
          Do not instantiate DataUtil, it contains only static methods.
 
Method Summary
static List cloneList(List l)
          Return a new list with a clone of each element in the list.
static Element expandVariables(Element nodes)
          Expand all variables to their values.
static Properties jdomToProps(Element nodes)
          Convert a nodes element's variables to properties.
static Element propsToJdom(Properties vars)
          Convert properties to a <nodes> jdom element containing a list of <variable>.
static Element propsToJdom(Properties vars, Namespace ns)
          Convert properties to a <nodes> jdom element containing a list of <variable>.
static Element removeNodeChildren(Element nodes)
          Remove all node elements from a nodes document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodeRemover

private static XSLTransformer nodeRemover
A transformer to remove the <node> tags from a nodes element. Used to store the globals.

Constructor Detail

DataUtil

private DataUtil()
Do not instantiate DataUtil, it contains only static methods.

Method Detail

expandVariables

public static Element expandVariables(Element nodes)
                               throws VerinecException
Expand all variables to their values. Returns the expanded element, the parameter is not modified in any way.

Variables are recognized as a string of [a-zA-Z0-9_], enclosed between dollar signs $. All variables are replaced by looking up the closest value with that name in the tree. To get a $ sign in the output, you have to escape it with a backslash \$.

Normally, variables have to be defined before use. The only exception are the % special variables for java environment values. For example, $%user.name$ results in the current users username.

The variables are expected to exist in the same namespace as the document root element.

Parameters:
nodes - A jdom tree containing variables and nodes.
Returns:
A copy of the node with all var references expanded to their value.
Throws:
VerinecException - if a variable is not defined.

removeNodeChildren

public static Element removeNodeChildren(Element nodes)
                                  throws VerinecException
Remove all node elements from a nodes document.

Parameters:
nodes - The document to treat.
Returns:
A copy of the original document with all node children removed.
Throws:
VerinecException - If an error occurs during remove.

jdomToProps

public static Properties jdomToProps(Element nodes)
Convert a nodes element's variables to properties. All global variables, that is the ones directly under the root node, are put into a Properties object as key->value pairs. It does not matter whether the nodes element contains any node.

Parameters:
nodes - A nodes element according to the schema.
Returns:
A set of key->value pairs for the variables.

propsToJdom

public static Element propsToJdom(Properties vars)
Convert properties to a <nodes> jdom element containing a list of <variable>.

Parameters:
vars - A (possibly empty) list of variables.
Returns:
A nodes element containing the key->value pairs as variables.

propsToJdom

public static Element propsToJdom(Properties vars,
                                  Namespace ns)
Convert properties to a <nodes> jdom element containing a list of <variable>.

Parameters:
vars - A (possibly empty) list of variables.
ns - A Namespace to put the variable elements into.
Returns:
A nodes element containing the key->value pairs as variables.

cloneList

public static List cloneList(List l)
Return a new list with a clone of each element in the list. This is for example useful when copying all jdom attributes to a new element.

Parameters:
l - The list to clone its element. Every single element must be cloneable and have a public clone method.
Returns:
A list with each element of l cloned.

Copyright © 2005 Verinec, DIUF