com.cleancode.xml
Class XslQualifier

java.lang.Object
  extended by com.cleancode.xml.XslQualifier

public class XslQualifier
extends Object

A class to safely set XSL transformer parameters. Blithely attempting to set parameters that are not present in an XSL file will result in a TransformerConfigurationException, aborting the transformation. To be able to safely call a Transformer's setParameter method, the XSL file must have defined a receptacle to receive the parameter, in the form:

<xsl:param name="parameter"/>
So we need to look for name attributes of param elements. Furthermore, these elements must be immediate children of the document root; in other words, the grandparent must be a document node.

Since:
CleanCode 0.9
Version:
$Revision: 380 $
Author:
Michael Sorens

Field Summary
static String ANY_NAMESPACE
          Specifier for any namespace in methods such as getElementsByTagNameNS.
static String DEFAULT_SEP
          Default separator between names and values in a single string.
static String PARAM_ATTR
          XSL attribute name for a PARAM_ELEM that names the parameter.
static String PARAM_ELEM
          XSL element name that accepts an input parameter.
static String VERSION
          Current version of this class.
static String XSL_NAMESPACE
          Standard XSL namespace at the time of writing.
 
Constructor Summary
XslQualifier(File file, Transformer transformer)
          Creates an XSlQualifier object for the specified file and transformer.
 
Method Summary
 void allowAnyNamespace(boolean value)
          Allows you to restrict or relax the namespace in which the PARAM_ELEM element must be located.
 void setParameter(String name, String value)
          Safely add a parameter for the transformation.
 void setParameterList(String[] list)
          Safely add multiple parameters for the transformation.
 void setParameterList(String[] list, String regexp)
          Safely add multiple parameters for the transformation, separating names and values with the separator provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Current version of this class.


DEFAULT_SEP

public static final String DEFAULT_SEP
Default separator between names and values in a single string.

See Also:
Constant Field Values

PARAM_ELEM

public static final String PARAM_ELEM
XSL element name that accepts an input parameter.

See Also:
Constant Field Values

PARAM_ATTR

public static final String PARAM_ATTR
XSL attribute name for a PARAM_ELEM that names the parameter.

See Also:
Constant Field Values

ANY_NAMESPACE

public static final String ANY_NAMESPACE
Specifier for any namespace in methods such as getElementsByTagNameNS.

See Also:
Constant Field Values

XSL_NAMESPACE

public static final String XSL_NAMESPACE
Standard XSL namespace at the time of writing.

See Also:
Constant Field Values
Constructor Detail

XslQualifier

public XslQualifier(File file,
                    Transformer transformer)
Creates an XSlQualifier object for the specified file and transformer. The XSL file is scanned and a list of parameter receptacles is created.

Parameters:
file - XSL file to operate on
transformer - transformer to use to set parameters
Method Detail

allowAnyNamespace

public void allowAnyNamespace(boolean value)
Allows you to restrict or relax the namespace in which the PARAM_ELEM element must be located. With a true value, ANY_NAMESPACE is used (the default). With a false value, XSL_NAMESPACE is used.

Parameters:
value - boolean indicating to allow any namespace or not.

setParameter

public void setParameter(String name,
                         String value)
Safely add a parameter for the transformation.

Parameters:
name - - The name of the parameter, which may begin with a namespace URI in curly braces ({}).
value - - The value object. This can be any valid Java object. It is up to the processor to provide the proper object coercion or to simply pass the object on for use in an extension.
See Also:
Transformer.setParameter(java.lang.String, java.lang.Object)

setParameterList

public void setParameterList(String[] list)
Safely add multiple parameters for the transformation. Each element of the parameter list must contain a name and a value separated by the default separator DEFAULT_SEP. Whitespace on either side of either one is ignored.

Parameters:
list - - String array containing parameter names and values.

setParameterList

public void setParameterList(String[] list,
                             String regexp)
Safely add multiple parameters for the transformation, separating names and values with the separator provided. Each element of the parameter list must contain a name and a value separated by the user specified separator. Whitespace on either side of either one is ignored. The default separator, used by the one-argument version, is DEFAULT_SEP.

Parameters:
list - - String array containing parameter names and values.
regexp - - Regular expression used to separate names from values.


CleanCode Java Libraries Copyright © 2001-2012 Michael Sorens - Revised 2012.12.10 Get CleanCode at SourceForge.net. Fast, secure and Free Open Source software downloads