public class XSLTransformer
extends java.lang.Object
Constructor and Description |
---|
XSLTransformer()
Constructor does nothing.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
encodeCharsInString(java.lang.String stg)
Substitutes escape chars for certain sensitive characthers that don't play well in file names or file
paths.
|
static java.lang.String |
encodeStringIntoHex(java.lang.String stg)
Substitutes hex values for all characters EXCEPT digits, letters, and the chars shown below.
|
protected static java.lang.String |
getDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout:
|
static javax.xml.transform.Transformer |
getTransformer(java.lang.String xslFilePath)
Gets a
Transformer used to transform XML using
a given XSL stylesheet. |
static javax.xml.transform.Transformer |
getTransformer(java.lang.String xslFilePath,
java.lang.String transformerFactoryClass)
Gets a specific
Transformer , used to transform
XML using a given XSL stylesheet. |
static javax.xml.transform.Transformer |
getTransformerFromXSLString(java.lang.String xslString)
Gets a
Transformer used to transform XML using a given XSL stylesheet. |
static java.lang.String |
localizeXml(java.lang.String xmlString)
Removes all namespace information from XML.
|
protected static void |
prtln(java.lang.String s)
Output a line of text to standard out, with datestamp, if debug is set to true.
|
protected static void |
prtlnErr(java.lang.String s)
Output a line of text to error out, with datestamp.
|
protected static void |
prtlnErr(java.lang.String s,
java.lang.Throwable t)
Output a line of text to error out, with datestamp.
|
protected static void |
prtlnErr(java.lang.Throwable t)
Output a line of text to error out, with datestamp.
|
static void |
setDebug(boolean db)
Sets the debug attribute of the object
|
java.lang.StringBuffer |
transform(java.lang.String xslFilePath,
java.lang.String inputFilesDir,
java.lang.String outputFilesDir)
Perform the transform on each file in the inputFilesDir, using the given xsl stylesheet, placing the
resulting transformed files into outpuFilesDir.
|
java.lang.StringBuffer |
transform(java.lang.String xslFilePath,
java.lang.String inputFilesDir,
java.lang.String[] inputFileNames,
java.lang.String outputFilesDir,
java.util.Date modifiedSinceDate)
Perform the transform files in inputFilesDir corresponding to the inputFileNames passed in, using the
given xsl stylesheet, placing the resulting transformed files into outpuFilesDir.
|
static java.lang.String |
transformFile(java.io.File inputFile,
javax.xml.transform.Transformer transformer)
Transforms an XML file using a pre-compiled
Transformer . |
static java.lang.String |
transformFile(java.lang.String inputFilePath,
java.lang.String xslFilePath)
Transforms an XML file using an XSL stylesheet.
|
static java.lang.String |
transformFile(java.lang.String inputFilePath,
javax.xml.transform.Transformer transformer)
Transforms an XML file using a pre-compiled
Transformer . |
static java.io.StringWriter |
transformFileToWriter(java.lang.String inputFilePath,
java.lang.String xslFilePath)
Transforms an XML file using an XSL stylesheet.
|
static java.io.StringWriter |
transformFileToWriter(java.lang.String inputFilePath,
javax.xml.transform.Transformer transformer)
Transforms an XML file using a pre-compiled
Transformer . |
static java.lang.String |
transformString(java.lang.String xmlString,
java.lang.String xslFilePath)
Transforms an XML String using an XSL stylesheet.
|
static java.lang.String |
transformString(java.lang.String xmlString,
javax.xml.transform.Transformer transformer)
Transforms an XML String using a pre-compiled
Transformer . |
static java.io.StringWriter |
transformStringToWriter(java.lang.String xmlString,
java.lang.String xslFilePath)
Transforms an XML String using an XSL stylesheet.
|
static java.io.StringWriter |
transformStringToWriter(java.lang.String xmlString,
javax.xml.transform.Transformer transformer)
Transforms an XML String using a pre-compiled
Transformer . |
static java.lang.String |
transformStringUsingString(java.lang.String xmlString,
java.lang.String xslString)
Transforms an XML String using an XSL stylesheet supplied as a String.
|
static void |
transformToFile(java.io.File inputFile,
java.io.FileOutputStream fos,
javax.xml.transform.Transformer transformer)
Transform a single file to the given FileOutputStream using the given transformer.
|
static void |
transformToFile(java.io.File inputFile,
java.io.File outputFile,
javax.xml.transform.Transformer transformer)
Transform a single file to the given output file using the given transformer.
|
static void |
transformToFile(java.lang.String inputFilePath,
java.lang.String outputFilePath,
javax.xml.transform.Transformer transformer)
Transform a single file to a file at the given output path using the given transformer.
|
public XSLTransformer()
public java.lang.StringBuffer transform(java.lang.String xslFilePath, java.lang.String inputFilesDir, java.lang.String outputFilesDir) throws java.lang.Exception
xslFilePath
- Path to an XSL stylesheet.inputFilesDir
- Path to a directory of XML files.outputFilesDir
- Path to a directory where transformed Files will be saved.java.lang.Exception
- If error.public java.lang.StringBuffer transform(java.lang.String xslFilePath, java.lang.String inputFilesDir, java.lang.String[] inputFileNames, java.lang.String outputFilesDir, java.util.Date modifiedSinceDate) throws java.lang.Exception
xslFilePath
- Path to an XSL stylesheet.inputFilesDir
- Path to a directory of XML files.inputFileNames
- An array of file names or null to get the file names from the files found in
inputFilesDiroutputFilesDir
- Path to a directory where transformed Files will be saved.modifiedSinceDate
- Indicates to perform the transform only if the original file has been modified
since the given date, or null to perform the transform regardless of modification date.java.lang.Exception
- If error.public static final void transformToFile(java.lang.String inputFilePath, java.lang.String outputFilePath, javax.xml.transform.Transformer transformer) throws java.lang.Exception
inputFilePath
- The input file to transform.outputFilePath
- The output file where transformed content will be saved.transformer
- The Transformer used to perform the transform.java.lang.Exception
- If unable to perform the transform.public static final void transformToFile(java.io.File inputFile, java.io.File outputFile, javax.xml.transform.Transformer transformer) throws java.lang.Exception
inputFile
- The input file to transform.outputFile
- The output file where transformed content will be saved.transformer
- The Transformer used to perform the transform.java.lang.Exception
- If unable to perform the transform.public static final void transformToFile(java.io.File inputFile, java.io.FileOutputStream fos, javax.xml.transform.Transformer transformer) throws java.lang.Exception
inputFile
- The input file to transform.fos
- The FileOutputStream where transformed content will be saved.transformer
- The Transformer used to perform the transform.java.lang.Exception
- If unable to perform the transform.public static final java.lang.String transformFile(java.lang.String inputFilePath, javax.xml.transform.Transformer transformer)
Transformer
. Use getTransformer(String xslFilePath)
to produce a reusable Transformer
for a
given XSL stylesheet.inputFilePath
- The XML file to transform.transformer
- A pre-compiled Transformer
used to produce transformed
output.public static final java.lang.String transformFile(java.io.File inputFile, javax.xml.transform.Transformer transformer)
Transformer
. Use getTransformer(String xslFilePath)
to produce a reusable Transformer
for a
given XSL stylesheet.inputFile
- The XML file to transform.transformer
- A pre-compiled Transformer
used to produce transformed
output.public static final java.io.StringWriter transformFileToWriter(java.lang.String inputFilePath, javax.xml.transform.Transformer transformer)
Transformer
. Use getTransformer(String xslFilePath)
to produce a reusable Transformer
for a
given XSL stylesheet. To convert the resulting StringWriter to a String, call StringWriter.toString().inputFilePath
- The XML file to transform.transformer
- A pre-compiled Transformer
used to produce transformed
output.public static final java.lang.String transformString(java.lang.String xmlString, javax.xml.transform.Transformer transformer)
Transformer
. Use getTransformer(String xslFilePath)
to produce a reusable Transformer
for a
given XSL stylesheet.xmlString
- The XML String to transform.transformer
- A pre-compiled Transformer
used to produce transformed
output.public static final java.io.StringWriter transformStringToWriter(java.lang.String xmlString, javax.xml.transform.Transformer transformer)
Transformer
. Use getTransformer(String xslFilePath)
to produce a reusable Transformer
for a
given XSL stylesheet. To convert the resulting StringWriter to a String, call StringWriter.toString().xmlString
- The XML String to transform.transformer
- A pre-compiled Transformer
used to produce transformed
output.public static final java.lang.String transformFile(java.lang.String inputFilePath, java.lang.String xslFilePath)
inputFilePath
- The XML file to transform.xslFilePath
- The XSL file used to perform the transform.public static final java.io.StringWriter transformFileToWriter(java.lang.String inputFilePath, java.lang.String xslFilePath)
inputFilePath
- The XML file to transform.xslFilePath
- The XSL file used to perform the transform.public static final java.lang.String transformString(java.lang.String xmlString, java.lang.String xslFilePath)
xmlString
- The XML String to transform.xslFilePath
- The XSL file used to perform the transform.public static final java.lang.String transformStringUsingString(java.lang.String xmlString, java.lang.String xslString)
xmlString
- The XML String to transform.xslString
- The XSL String used to define the transform.public static final java.lang.String localizeXml(java.lang.String xmlString)
xmlString
- The XML String to strip of namespaces#XSLUtils.getRemoveNamespacesXSL()
public static final java.io.StringWriter transformStringToWriter(java.lang.String xmlString, java.lang.String xslFilePath)
xmlString
- The XML String to transform.xslFilePath
- The XSL file used to perform the transform.public static javax.xml.transform.Transformer getTransformer(java.lang.String xslFilePath) throws javax.xml.transform.TransformerConfigurationException, java.io.FileNotFoundException
Transformer
used to transform XML using
a given XSL stylesheet. For efficiency, one Transformer
should be used to transform multiple XMLs from a single stylesheet.xslFilePath
- A path to an XSL stylesheet
file.javax.xml.transform.TransformerConfigurationException
- If error.java.io.FileNotFoundException
- If file can not be found.public static javax.xml.transform.Transformer getTransformer(java.lang.String xslFilePath, java.lang.String transformerFactoryClass) throws javax.xml.transform.TransformerConfigurationException, java.io.FileNotFoundException
Transformer
, used to transform
XML using a given XSL stylesheet.xslFilePath
- A path to an XSL stylesheet
file.transformerFactoryClass
- TransformerFactory class
(e.g. "net.sf.saxon.TransformerFactoryImpl")javax.xml.transform.TransformerConfigurationException
- If error.java.io.FileNotFoundException
- If file can not be found.public static final javax.xml.transform.Transformer getTransformerFromXSLString(java.lang.String xslString) throws javax.xml.transform.TransformerConfigurationException
Transformer
used to transform XML using a given XSL stylesheet. For
efficiency, one Transformer
should be used to transform multiple XMLs from a
single stylesheet.xslString
- XSL supplied as a Stringjavax.xml.transform.TransformerConfigurationException
- If error.public static java.lang.String encodeStringIntoHex(java.lang.String stg)
Excepted chars include digits, letters and: - _ . %
Note: Unix commands cannot include the following chars: * ? ! | \ / ' " { } < > ; , ^ ( ) $ ~ Windows file names may not contain: \ / : * ? " < > |
stg
- A String to encode.public static java.lang.String encodeCharsInString(java.lang.String stg)
Unix commands cannot include the following chars: * ? ! | \ / ' " { } < > ; , ^ ( ) $ ~
Windows file names may not contain: \ / : * ? " < > |
stg
- A String to encode.protected static final java.lang.String getDateStamp()
protected static final void prtlnErr(java.lang.String s)
s
- The text that will be output to error out.protected static final void prtlnErr(java.lang.String s, java.lang.Throwable t)
s
- The text that will be output to error out.t
- The Throwable to output with messageprotected static final void prtlnErr(java.lang.Throwable t)
t
- The Throwable to output with messageprotected static void prtln(java.lang.String s)
s
- The String that will be output.public static void setDebug(boolean db)
db
- The new debug value