org.ejen.util
Class XSLUtil

java.lang.Object
  |
  +--org.ejen.util.XSLUtil

public class XSLUtil
extends Object

XSL utility (static methods used in java code).

Version:
1.0
Author:
F. Wolff

Constructor Summary
protected XSLUtil()
          Prevents instanciation.
 
Method Summary
static boolean equals(NodeIterator ni1, NodeIterator ni2)
          Checks ni1 and ni2 for strict equality (same names, same attributes, same child nodes...).
static boolean equals(Node n1, Node n2)
          Checks n1 and n2 for strict equality (same names, same attributes, same child nodes...).
static String evaluate(ExpressionContext context, String avt)
          Returns an interpreted value (AVT) of a Node attribute whose name is equals to the avt parameter.
static XObject evaluate(Node contextNode, String str)
          Returns an XObject resulting from the evaluation of the str parameter.
static XObject evaluate(Node contextNode, String str, ErrorListener el)
          Returns an XObject resulting from the evaluation of the str parameter.
static XObject evaluate(Node contextNode, String str, Node namespaceNode, ErrorListener el)
          Returns an XObject resulting from the evaluation of the str parameter.
static String evaluate(XSLProcessorContext context, ElemExtensionCall elem)
          Returns an interpreted value (AVT) of a Node attribute whose name is "avt".
static XObject evaluate(XSLProcessorContext context, ElemExtensionCall elem, String expression)
          Returns the interpretion (AVT) of the expression parameter.
static String evaluateAttribute(StylesheetHandler sh, XPathContext xpc, Node node, String expr)
          Returns a String resulting from the evaluation of the expr parameter (AVT).
static String getAttribute(XSLProcessorContext context, ElemExtensionCall elem, String name, boolean throwsIfNull)
          Returns an interpreted value (AVT) of a Node attribute whose name is 'name'.
static Document getContextDocument(ExpressionContext context)
          Returns the Document used in the context parameter.
static TransformerImpl getDefaultTransformer(TransformerFactoryImpl tfi)
          Returns a new TransformerImpl using the EjenConstants.DEFAULT_XSL_DATA String as source.
static Object getOAttribute(XSLProcessorContext context, ElemExtensionCall elem, String name, Class clazz, boolean isAVT, boolean throwsIfNull)
          Returns an Object value (AVT or not) of a Node attribute whose name is 'name'.
static XObject getXOAttribute(XSLProcessorContext context, ElemExtensionCall elem, String name, boolean isAVT, boolean throwsIfNull)
          Returns an XObject value (AVT or not) of a Node attribute whose name is 'name'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XSLUtil

protected XSLUtil()
Prevents instanciation.

Method Detail

getDefaultTransformer

public static TransformerImpl getDefaultTransformer(TransformerFactoryImpl tfi)
Returns a new TransformerImpl using the EjenConstants.DEFAULT_XSL_DATA String as source.

Parameters:
tfi - the TransformerFactoryImpl to use to build the TransformerImpl.
Returns:
the new TransformerImpl.
Throws:
WrappedRuntimeException - ...

getAttribute

public static String getAttribute(XSLProcessorContext context,
                                  ElemExtensionCall elem,
                                  String name,
                                  boolean throwsIfNull)
Returns an interpreted value (AVT) of a Node attribute whose name is 'name'.

Parameters:
context - the XSLProcessorContext to be used.
elem - the ElemExtensionCall to be used.
name - name of the attribute.
throwsIfNull - if true, an IllegalArgumentException will be thrown if no 'name' attribute can be found, otherwise null will returned.
Returns:
the interpreted value (AVT) of the Node attribute.
Throws:
IllegalArgumentException - ...
WrappedRuntimeException - ...

getXOAttribute

public static XObject getXOAttribute(XSLProcessorContext context,
                                     ElemExtensionCall elem,
                                     String name,
                                     boolean isAVT,
                                     boolean throwsIfNull)
Returns an XObject value (AVT or not) of a Node attribute whose name is 'name'.

Parameters:
context - the XSLProcessorContext to be used.
elem - the ElemExtensionCall to be used.
name - name of the attribute.
isAVT - should the value be interpreted as an AVT?
throwsIfNull - if true, an IllegalArgumentException will be thrown if no 'name' attribute can be found, otherwise null will returned.
Returns:
the interpreted value (if AVT) of the Node attribute.
Throws:
IllegalArgumentException - ...
WrappedRuntimeException - ...

getOAttribute

public static Object getOAttribute(XSLProcessorContext context,
                                   ElemExtensionCall elem,
                                   String name,
                                   Class clazz,
                                   boolean isAVT,
                                   boolean throwsIfNull)
Returns an Object value (AVT or not) of a Node attribute whose name is 'name'.

Parameters:
context - the XSLProcessorContext to be used.
elem - the ElemExtensionCall to be used.
name - name of the attribute.
clazz - Class of the Object to return.
isAVT - should the value be interpreted as an AVT?
throwsIfNull - if true, an IllegalArgumentException will be thrown if no 'name' attribute can be found, otherwise null will returned.
Returns:
the interpreted value (if AVT) of the Node attribute.
Throws:
ClassCastException - if the Object is not an instance of clazz.
IllegalArgumentException - ...
WrappedRuntimeException - ...

evaluate

public static String evaluate(XSLProcessorContext context,
                              ElemExtensionCall elem)
Returns an interpreted value (AVT) of a Node attribute whose name is "avt".

Parameters:
context - the XSLProcessorContext to be used.
elem - the ElemExtensionCall to be used.
Returns:
the evaluated result.
Throws:
IllegalArgumentException - bad context.
WrappedRuntimeException - ...

evaluate

public static String evaluate(ExpressionContext context,
                              String avt)
Returns an interpreted value (AVT) of a Node attribute whose name is equals to the avt parameter.

Parameters:
context - the ExpressionContext to be used.
avt - the name of the attribute.
Returns:
the evaluated result.
Throws:
IllegalArgumentException - bad context.
WrappedRuntimeException - ...

evaluate

public static XObject evaluate(XSLProcessorContext context,
                               ElemExtensionCall elem,
                               String expression)
Returns the interpretion (AVT) of the expression parameter.

Parameters:
context - the XSLProcessorContext to be used.
elem - the ElemExtensionCall to be used.
expression - the expression to be evaluated.
Returns:
the evaluated result.
Throws:
WrappedRuntimeException - ...

evaluate

public static XObject evaluate(Node contextNode,
                               String str)
Returns an XObject resulting from the evaluation of the str parameter.

Parameters:
contextNode - the Node to be used as context.
str - the expression to be evaluated.
Returns:
the evaluated result.
Throws:
WrappedRuntimeException - ...

evaluate

public static XObject evaluate(Node contextNode,
                               String str,
                               ErrorListener el)
Returns an XObject resulting from the evaluation of the str parameter.

Parameters:
contextNode - the Node to be used as context.
str - the expression to be evaluated.
el - the ErrorListener to be used.
Returns:
the evaluated result.
Throws:
WrappedRuntimeException - ...

evaluate

public static XObject evaluate(Node contextNode,
                               String str,
                               Node namespaceNode,
                               ErrorListener el)
Returns an XObject resulting from the evaluation of the str parameter.

Parameters:
contextNode - the Node to be used as context.
str - the expression to be evaluated.
namespaceNode - the namespace Node to be used.
el - the ErrorListener to be used.
Returns:
the evaluated result.
Throws:
WrappedRuntimeException - ...

evaluateAttribute

public static String evaluateAttribute(StylesheetHandler sh,
                                       XPathContext xpc,
                                       Node node,
                                       String expr)
                                throws TransformerException
Returns a String resulting from the evaluation of the expr parameter (AVT).

Parameters:
sh - the StylesheetHandler to be used.
xpc - the XPathContext to be used.
node - the Node to be used as context.
expr - the expression to be evaluated.
Returns:
the evaluated result.
Throws:
TransformerException - ...

equals

public static boolean equals(NodeIterator ni1,
                             NodeIterator ni2)
Checks ni1 and ni2 for strict equality (same names, same attributes, same child nodes...).

Parameters:
ni1 - the first NodeIterator.
ni2 - the second NodeIterator.
Returns:
true if ni1 equals ni2, false otherwise.

equals

public static boolean equals(Node n1,
                             Node n2)
Checks n1 and n2 for strict equality (same names, same attributes, same child nodes...).

Parameters:
n1 - the first Node.
n2 - the second Node.
Returns:
true if n1 equals n2, false otherwise.

getContextDocument

public static Document getContextDocument(ExpressionContext context)
Returns the Document used in the context parameter.

Parameters:
context - an ExpressionContext.
Returns:
the Document.
Throws:
WrappedRuntimeException - failed...