|
||||||||||
| 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 Object |
caller
|
protected ResourceBundle |
l18n
|
protected static String |
mediaProps
|
protected HashMap |
stylesheetParams
|
protected static boolean |
stylesheetRootCacheEnabled
|
protected static boolean |
stylesheetSetCacheEnabled
|
protected Result |
xmlResult
|
protected Source |
xmlSource
|
protected String |
xslURI
|
| Constructor Summary | |
|---|---|
XSLT(Object instance)
Constructs an XSLT object. |
|
| Method Summary | |
|---|---|
protected static void |
addLocalization(Document xsl,
ResourceBundle localization)
Writes a set of key/value pairs from a resourcebundle as global variables in an xsl stylesheet |
protected static String |
escape(String s)
Escape problem characters which will be inserted into XSL |
static SAXTransformerFactory |
getSAXTFactory()
|
static int |
getStylesheetCacheSize()
Get the number of stylesheets in the stylesheet root cache. |
static StylesheetSet |
getStylesheetSet(String stylesheetListURI)
This method caches compiled stylesheet set objects, keyed by the stylesheet list's URI. |
static String |
getStylesheetURI(String sslUri,
BrowserInfo browserInfo)
Returns a stylesheet URI exactly as it appears in a stylesheet list file. |
static String |
getStylesheetURI(String sslUri,
String title,
BrowserInfo browserInfo)
Returns a stylesheet URI exactly as it appears in a stylesheet list file. |
static Templates |
getTemplates(String stylesheetURI)
This method caches compiled stylesheet objects, keyed by the stylesheet's URI. |
static Templates |
getTemplates(String stylesheetURI,
ResourceBundle l18n)
This method caches compiled stylesheet objects, keyed by the stylesheet's URI and locale. |
static XSLT |
getTransformer(Object instance)
Factory method that produces an XSLT transformer utility. |
static XSLT |
getTransformer(Object instance,
Locale[] locales)
Factory method that produces an XSLT transformer utility with a capability of choosing a stylesheet depending on a list of locales. |
static Transformer |
getTransformer(String stylesheetURI)
This method returns a Transformer for a given stylesheet. |
static Transformer |
getTransformer(String stylesheetURI,
ResourceBundle l18n)
This method returns a localized Transformer for a given stylesheet. |
static TransformerHandler |
getTransformerHandler(String stylesheetURI)
This method returns a TransformerHandler for a given stylesheet. |
static TransformerHandler |
getTransformerHandler(String stylesheetURI,
Locale[] locales,
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(ResourceBundle bundle)
|
void |
setStylesheetParameter(String name,
String value)
Sets all the stylesheet parameters at once. |
void |
setStylesheetParameters(HashMap stylesheetParameters)
Sets all the stylesheet parameters at once. |
void |
setStylesheetParameters(Hashtable stylesheetParameters)
Sets all the stylesheet parameters at once. |
void |
setTarget(ContentHandler contentHandler)
Configures the xslt target. |
void |
setTarget(Node node)
Configures the xslt target. |
void |
setTarget(OutputStream os)
Configures the xslt target. |
void |
setXML(File file)
Configures the xml source. |
void |
setXML(InputStream is)
Configures the xml source. |
void |
setXML(Node xml)
Configures the xml source. |
void |
setXML(String xml)
Configures the xml source. |
void |
setXSL(String xslUri)
Configures the xsl source. |
void |
setXSL(String sslUri,
BrowserInfo browserInfo)
Configures the xsl source by choosing the appropriate stylesheet from the provided stylesheet list file. |
void |
setXSL(String sslUri,
String stylesheetTitle,
BrowserInfo browserInfo)
Configures the xsl source by choosing the appropriate stylesheet from the provided stylesheet list file. |
String |
toString()
|
void |
transform()
Performs a transformation. |
static void |
transform(Source xmlSource,
Result xmlResult,
Hashtable stylesheetParams,
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 |
|---|
protected static boolean stylesheetRootCacheEnabled
protected static boolean stylesheetSetCacheEnabled
protected static final String mediaProps
protected Object caller
protected Source xmlSource
protected Result xmlResult
protected HashMap stylesheetParams
protected String xslURI
protected ResourceBundle l18n
| Constructor Detail |
|---|
public XSLT(Object instance)
instance - the client of this utility| Method Detail |
|---|
public static XSLT getTransformer(Object instance)
instance - the client of this utility
public static XSLT getTransformer(Object instance,
Locale[] locales)
instance - the client of this utility
public static SAXTransformerFactory getSAXTFactory()
public void setXML(String xml)
xml - a string representing the xml documentpublic void setXML(Node xml)
xml - a node representing the xml documentpublic void setXML(InputStream is)
is - an input stream to the serialized xml sourcepublic void setXML(File file)
file - a File object representing the xml source
public void setXSL(String xslUri)
throws PortalException
xslUri - the URL of an XSLT stylesheet
PortalException
public void setXSL(String sslUri,
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(String sslUri,
BrowserInfo browserInfo)
throws PortalException
sslUri - the URL of the stylesheet list filebrowserInfo - the browser info object
PortalExceptionpublic void setTarget(ContentHandler contentHandler)
contentHandler - the content handlerpublic void setTarget(OutputStream os)
os - output streampublic void setTarget(Node node)
node - target nodepublic void setStylesheetParameters(Hashtable stylesheetParameters)
stylesheetParameters - a Hashtable of stylesheet parameterspublic void setStylesheetParameters(HashMap stylesheetParameters)
stylesheetParameters - a HashMap of stylesheet parameters
public void setStylesheetParameter(String name,
String value)
name - the name of the stylesheet parametervalue - the value of the stylesheet parameter
public void transform()
throws PortalException
PortalException
public static void transform(Source xmlSource,
Result xmlResult,
Hashtable stylesheetParams,
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 wrongpublic void setResourceBundle(ResourceBundle bundle)
public static Templates getTemplates(String stylesheetURI,
ResourceBundle l18n)
throws SAXException,
PortalException,
TransformerConfigurationException
stylesheetURI - the URI of the XSLT stylesheetl18n - the localized strings to add to the xsl
SAXException
PortalException
TransformerConfigurationException
public static Templates getTemplates(String stylesheetURI)
throws SAXException,
PortalException
stylesheetURI - the URI of the XSLT stylesheet
SAXException
PortalException
public static Transformer getTransformer(String stylesheetURI,
ResourceBundle l18n)
throws SAXException,
PortalException
stylesheetURI - the URI of the XSLT stylesheet
Transformer
SAXException
PortalException
public static Transformer getTransformer(String stylesheetURI)
throws SAXException,
PortalException
stylesheetURI - the URI of the XSLT stylesheet
Transformer
SAXException
PortalException
public static TransformerHandler getTransformerHandler(String stylesheetURI)
throws SAXException,
PortalException
stylesheetURI - the URI of the XSLT stylesheet
Transformer
SAXException
PortalException
public static TransformerHandler getTransformerHandler(String stylesheetURI,
Locale[] locales,
Object caller)
throws SAXException,
PortalException
stylesheetURI - the URI of the XSLT stylesheetlocales - the list of localescaller - the calling class
Transformer
SAXException
PortalException
public static StylesheetSet getStylesheetSet(String stylesheetListURI)
throws PortalException
stylesheetListURI - the URI of the XSLT stylesheet list file (.ssl)
PortalException
public static String getStylesheetURI(String sslUri,
BrowserInfo browserInfo)
throws PortalException
sslUri - the stylesheet list file URIbrowserInfo - the browser information
PortalException
public static String getStylesheetURI(String sslUri,
String title,
BrowserInfo browserInfo)
throws PortalException
sslUri - the stylesheet list file URItitle - the stylesheet titlebrowserInfo - the browser information
PortalException
protected static void addLocalization(Document xsl,
ResourceBundle localization)
xsl - the xsl stylesheet as a DOM documentlocalization - the resource bundle of key/value pairs to be written to xsl variablesprotected static String escape(String s)
s - the string to escapepublic static void purgeStylesheetCache()
public static int getStylesheetCacheSize()
public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||