|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jasig.portal.utils.XSLT
public class XSLT
This utility provides methods for transforming XML documents via XSLT. It takes advantage of Xalan's ability to pre-compile stylehseets into StylesheetRoot objects. The first time a transform is requested, a stylesheet is compiled and cached.
None of the method signatures in this class should contain classes specific to a particular XSLT engine, e.g. Xalan, or XML parser, e.g. Xerces.
The constructor for XSLT takes an instance of whatever class is requesting the transformation. XSLT uses this instance to locate resources relative to the classpath.
Typical usage:
XSLT xslt = new XSLT(this);
xslt.setXML("myXMLDoc.xml");
xslt.setSSL("myChannel.ssl", "aTitle", runtimeData.getBrowserInfo());
xslt.setTarget(out);
xslt.setStylesheetParameter("param1Name", "param1Value");
xslt.setStylesheetParameter("param2Name", "param2Value");
xslt.transform();
Field Summary | |
---|---|
protected java.lang.Object |
caller
|
protected java.util.ResourceBundle |
l18n
|
private static org.apache.commons.logging.Log |
log
|
protected static java.lang.String |
mediaProps
|
private static javax.xml.transform.sax.SAXTransformerFactory |
saxTFactory
|
protected java.util.HashMap |
stylesheetParams
|
protected static java.util.Hashtable |
stylesheetRootCache
|
protected static boolean |
stylesheetRootCacheEnabled
|
protected static java.util.Hashtable |
stylesheetSetCache
|
protected static boolean |
stylesheetSetCacheEnabled
|
protected javax.xml.transform.Result |
xmlResult
|
protected javax.xml.transform.Source |
xmlSource
|
protected java.lang.String |
xslURI
|
Constructor Summary | |
---|---|
XSLT(java.lang.Object instance)
Constructs an XSLT object. |
Method Summary | |
---|---|
protected static void |
addLocalization(org.w3c.dom.Document xsl,
java.util.ResourceBundle localization)
Writes a set of key/value pairs from a resourcebundle as global variables in an xsl stylesheet |
protected static java.lang.String |
escape(java.lang.String s)
Escape problem characters which will be inserted into XSL |
static javax.xml.transform.sax.SAXTransformerFactory |
getSAXTFactory()
|
static int |
getStylesheetCacheSize()
Get the number of stylesheets in the stylesheet root cache. |
static StylesheetSet |
getStylesheetSet(java.lang.String stylesheetListURI)
This method caches compiled stylesheet set objects, keyed by the stylesheet list's URI. |
static java.lang.String |
getStylesheetURI(java.lang.String sslUri,
BrowserInfo browserInfo)
Returns a stylesheet URI exactly as it appears in a stylesheet list file. |
static java.lang.String |
getStylesheetURI(java.lang.String sslUri,
java.lang.String title,
BrowserInfo browserInfo)
Returns a stylesheet URI exactly as it appears in a stylesheet list file. |
static javax.xml.transform.Templates |
getTemplates(java.lang.String stylesheetURI)
This method caches compiled stylesheet objects, keyed by the stylesheet's URI. |
static javax.xml.transform.Templates |
getTemplates(java.lang.String stylesheetURI,
java.util.ResourceBundle l18n)
This method caches compiled stylesheet objects, keyed by the stylesheet's URI and locale. |
static XSLT |
getTransformer(java.lang.Object instance)
Factory method that produces an XSLT transformer utility. |
static XSLT |
getTransformer(java.lang.Object instance,
java.util.Locale[] locales)
Factory method that produces an XSLT transformer utility with a capability of choosing a stylesheet depending on a list of locales. |
static javax.xml.transform.Transformer |
getTransformer(java.lang.String stylesheetURI)
This method returns a Transformer for a given stylesheet. |
static javax.xml.transform.Transformer |
getTransformer(java.lang.String stylesheetURI,
java.util.ResourceBundle l18n)
This method returns a localized Transformer for a given stylesheet. |
static javax.xml.transform.sax.TransformerHandler |
getTransformerHandler(java.lang.String stylesheetURI)
This method returns a TransformerHandler for a given stylesheet. |
static javax.xml.transform.sax.TransformerHandler |
getTransformerHandler(java.lang.String stylesheetURI,
java.util.Locale[] locales,
java.lang.Object caller)
This method returns a localized TransformerHandler for a given stylesheet. |
static void |
purgeStylesheetCache()
Purge the cache of stylesheet roots and stylesheet sets. |
void |
setResourceBundle(java.util.ResourceBundle bundle)
|
void |
setStylesheetParameter(java.lang.String name,
java.lang.String value)
Sets all the stylesheet parameters at once. |
void |
setStylesheetParameters(java.util.HashMap stylesheetParameters)
Sets all the stylesheet parameters at once. |
void |
setStylesheetParameters(java.util.Hashtable stylesheetParameters)
Sets all the stylesheet parameters at once. |
private static void |
setStylesheetParams(javax.xml.transform.Transformer transformer,
java.util.HashMap stylesheetParams)
Extracts name/value pairs from a Hashtable and uses them to create stylesheet parameters |
private static void |
setStylesheetParams(javax.xml.transform.Transformer transformer,
java.util.Hashtable stylesheetParams)
Deprecated. replaced by setStylesheetParams(Transformer, HashMap) |
void |
setTarget(org.xml.sax.ContentHandler contentHandler)
Configures the xslt target. |
void |
setTarget(org.w3c.dom.Node node)
Configures the xslt target. |
void |
setTarget(java.io.OutputStream os)
Configures the xslt target. |
void |
setXML(java.io.File file)
Configures the xml source. |
void |
setXML(java.io.InputStream is)
Configures the xml source. |
void |
setXML(org.w3c.dom.Node xml)
Configures the xml source. |
void |
setXML(java.lang.String xml)
Configures the xml source. |
void |
setXSL(java.lang.String xslUri)
Configures the xsl source. |
void |
setXSL(java.lang.String sslUri,
BrowserInfo browserInfo)
Configures the xsl source by choosing the appropriate stylesheet from the provided stylesheet list file. |
void |
setXSL(java.lang.String sslUri,
java.lang.String stylesheetTitle,
BrowserInfo browserInfo)
Configures the xsl source by choosing the appropriate stylesheet from the provided stylesheet list file. |
java.lang.String |
toString()
|
void |
transform()
Performs a transformation. |
static void |
transform(javax.xml.transform.Source xmlSource,
javax.xml.transform.Result xmlResult,
java.util.Hashtable stylesheetParams,
java.lang.String xslURI)
Performs an XSL transformation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final org.apache.commons.logging.Log log
protected static boolean stylesheetRootCacheEnabled
protected static boolean stylesheetSetCacheEnabled
protected static final java.lang.String mediaProps
protected static final java.util.Hashtable stylesheetRootCache
protected static final java.util.Hashtable stylesheetSetCache
private static javax.xml.transform.sax.SAXTransformerFactory saxTFactory
protected java.lang.Object caller
protected javax.xml.transform.Source xmlSource
protected javax.xml.transform.Result xmlResult
protected java.util.HashMap stylesheetParams
protected java.lang.String xslURI
protected java.util.ResourceBundle l18n
Constructor Detail |
---|
public XSLT(java.lang.Object instance)
instance
- the client of this utilityMethod Detail |
---|
public static XSLT getTransformer(java.lang.Object instance)
instance
- the client of this utility
public static XSLT getTransformer(java.lang.Object instance, java.util.Locale[] locales)
instance
- the client of this utility
public static javax.xml.transform.sax.SAXTransformerFactory getSAXTFactory()
public void setXML(java.lang.String xml)
xml
- a string representing the xml documentpublic void setXML(org.w3c.dom.Node xml)
xml
- a node representing the xml documentpublic void setXML(java.io.InputStream is)
is
- an input stream to the serialized xml sourcepublic void setXML(java.io.File file)
file
- a File object representing the xml sourcepublic void setXSL(java.lang.String xslUri) throws PortalException
xslUri
- the URL of an XSLT stylesheet
PortalException
public void setXSL(java.lang.String sslUri, java.lang.String stylesheetTitle, BrowserInfo browserInfo) throws PortalException
sslUri
- the URL of the stylesheet list filestylesheetTitle
- the title of a stylesheet within the stylesheet list filebrowserInfo
- the browser info object
PortalException
public void setXSL(java.lang.String sslUri, BrowserInfo browserInfo) throws PortalException
sslUri
- the URL of the stylesheet list filebrowserInfo
- the browser info object
PortalException
public void setTarget(org.xml.sax.ContentHandler contentHandler)
contentHandler
- the content handlerpublic void setTarget(java.io.OutputStream os)
os
- output streampublic void setTarget(org.w3c.dom.Node node)
node
- target nodepublic void setStylesheetParameters(java.util.Hashtable stylesheetParameters)
stylesheetParameters
- a Hashtable of stylesheet parameterspublic void setStylesheetParameters(java.util.HashMap stylesheetParameters)
stylesheetParameters
- a HashMap of stylesheet parameterspublic void setStylesheetParameter(java.lang.String name, java.lang.String value)
name
- the name of the stylesheet parametervalue
- the value of the stylesheet parameterpublic void transform() throws PortalException
PortalException
public static void transform(javax.xml.transform.Source xmlSource, javax.xml.transform.Result xmlResult, java.util.Hashtable stylesheetParams, java.lang.String xslURI) throws PortalException
xmlSource
- the source to be transformednxmlResult
- the result to be populatedstylesheetParams
- a Hashtable of key/value pairs or null
if no parametersxslURI
- the uri of the stylesheet to be used
PortalException
- if something goes wrongprivate static void setStylesheetParams(javax.xml.transform.Transformer transformer, java.util.Hashtable stylesheetParams)
setStylesheetParams(Transformer, HashMap)
transformer
- the XSLT processorstylesheetParams
- name/value pairs used as stylesheet parametersprivate static void setStylesheetParams(javax.xml.transform.Transformer transformer, java.util.HashMap stylesheetParams)
transformer
- the XSLT processorstylesheetParams
- name/value pairs used as stylesheet parameterspublic void setResourceBundle(java.util.ResourceBundle bundle)
public static javax.xml.transform.Templates getTemplates(java.lang.String stylesheetURI, java.util.ResourceBundle l18n) throws org.xml.sax.SAXException, PortalException, javax.xml.transform.TransformerConfigurationException
stylesheetURI
- the URI of the XSLT stylesheetl18n
- the localized strings to add to the xsl
org.xml.sax.SAXException
PortalException
javax.xml.transform.TransformerConfigurationException
public static javax.xml.transform.Templates getTemplates(java.lang.String stylesheetURI) throws org.xml.sax.SAXException, PortalException
stylesheetURI
- the URI of the XSLT stylesheet
org.xml.sax.SAXException
PortalException
public static javax.xml.transform.Transformer getTransformer(java.lang.String stylesheetURI, java.util.ResourceBundle l18n) throws org.xml.sax.SAXException, PortalException
stylesheetURI
- the URI of the XSLT stylesheet
Transformer
org.xml.sax.SAXException
PortalException
public static javax.xml.transform.Transformer getTransformer(java.lang.String stylesheetURI) throws org.xml.sax.SAXException, PortalException
stylesheetURI
- the URI of the XSLT stylesheet
Transformer
org.xml.sax.SAXException
PortalException
public static javax.xml.transform.sax.TransformerHandler getTransformerHandler(java.lang.String stylesheetURI) throws org.xml.sax.SAXException, PortalException
stylesheetURI
- the URI of the XSLT stylesheet
Transformer
org.xml.sax.SAXException
PortalException
public static javax.xml.transform.sax.TransformerHandler getTransformerHandler(java.lang.String stylesheetURI, java.util.Locale[] locales, java.lang.Object caller) throws org.xml.sax.SAXException, PortalException
stylesheetURI
- the URI of the XSLT stylesheetlocales
- the list of localescaller
- the calling class
Transformer
org.xml.sax.SAXException
PortalException
public static StylesheetSet getStylesheetSet(java.lang.String stylesheetListURI) throws PortalException
stylesheetListURI
- the URI of the XSLT stylesheet list file (.ssl)
PortalException
public static java.lang.String getStylesheetURI(java.lang.String sslUri, BrowserInfo browserInfo) throws PortalException
sslUri
- the stylesheet list file URIbrowserInfo
- the browser information
PortalException
public static java.lang.String getStylesheetURI(java.lang.String sslUri, java.lang.String title, BrowserInfo browserInfo) throws PortalException
sslUri
- the stylesheet list file URItitle
- the stylesheet titlebrowserInfo
- the browser information
PortalException
protected static void addLocalization(org.w3c.dom.Document xsl, java.util.ResourceBundle localization)
xsl
- the xsl stylesheet as a DOM documentlocalization
- the resource bundle of key/value pairs to be written to xsl variablesprotected static java.lang.String escape(java.lang.String s)
s
- the string to escapepublic static void purgeStylesheetCache()
public static int getStylesheetCacheSize()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |