|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dlese.dpc.xml.XSLTransformer
public class XSLTransformer
Transforms files or Strings using XSL stylesheets. In general, Transformer objects are not thread safe, so external synchornization should be applied in concurrent environments such as servlets. Note: some members of this class can be run as a stand-alone class that can be invoked from the command line or from a servlet environment.
Constructor Summary | |
---|---|
XSLTransformer()
Constructor does nothing. |
Method Summary | |
---|---|
static String |
encodeCharsInString(String stg)
Substitutes escape chars for certain sensitive characthers that don't play well in file names or file paths. |
static String |
encodeStringIntoHex(String stg)
Substitutes hex values for all characters EXCEPT digits, letters, and the chars shown below. |
protected static String |
getDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout: |
static Transformer |
getTransformer(String xslFilePath)
Gets a Transformer used to transform XML using
a given XSL stylesheet. |
static Transformer |
getTransformer(String xslFilePath,
String transformerFactoryClass)
Gets a specific Transformer , used to transform
XML using a given XSL stylesheet. |
static Transformer |
getTransformerFromXSLString(String xslString)
Gets a Transformer used to transform XML using a given XSL stylesheet. |
static String |
localizeXml(String xmlString)
Removes all namespace information from XML. |
protected static void |
prtln(String s)
Output a line of text to standard out, with datestamp, if debug is set to true. |
protected static void |
prtlnErr(String s)
Output a line of text to error out, with datestamp. |
protected static void |
prtlnErr(String s,
Throwable t)
Output a line of text to error out, with datestamp. |
protected static void |
prtlnErr(Throwable t)
Output a line of text to error out, with datestamp. |
static void |
setDebug(boolean db)
Sets the debug attribute of the object |
StringBuffer |
transform(String xslFilePath,
String inputFilesDir,
String outputFilesDir)
Perform the transform on each file in the inputFilesDir, using the given xsl stylesheet, placing the resulting transformed files into outpuFilesDir. |
StringBuffer |
transform(String xslFilePath,
String inputFilesDir,
String[] inputFileNames,
String outputFilesDir,
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 String |
transformFile(File inputFile,
Transformer transformer)
Transforms an XML file using a pre-compiled Transformer . |
static String |
transformFile(String inputFilePath,
String xslFilePath)
Transforms an XML file using an XSL stylesheet. |
static String |
transformFile(String inputFilePath,
Transformer transformer)
Transforms an XML file using a pre-compiled Transformer . |
static StringWriter |
transformFileToWriter(String inputFilePath,
String xslFilePath)
Transforms an XML file using an XSL stylesheet. |
static StringWriter |
transformFileToWriter(String inputFilePath,
Transformer transformer)
Transforms an XML file using a pre-compiled Transformer . |
static String |
transformString(String xmlString,
String xslFilePath)
Transforms an XML String using an XSL stylesheet. |
static String |
transformString(String xmlString,
Transformer transformer)
Transforms an XML String using a pre-compiled Transformer . |
static StringWriter |
transformStringToWriter(String xmlString,
String xslFilePath)
Transforms an XML String using an XSL stylesheet. |
static StringWriter |
transformStringToWriter(String xmlString,
Transformer transformer)
Transforms an XML String using a pre-compiled Transformer . |
static String |
transformStringUsingString(String xmlString,
String xslString)
Transforms an XML String using an XSL stylesheet supplied as a String. |
static void |
transformToFile(File inputFile,
FileOutputStream fos,
Transformer transformer)
Transform a single file to the given FileOutputStream using the given transformer. |
static void |
transformToFile(File inputFile,
File outputFile,
Transformer transformer)
Transform a single file to the given output file using the given transformer. |
static void |
transformToFile(String inputFilePath,
String outputFilePath,
Transformer transformer)
Transform a single file to a file at the given output path using the given transformer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XSLTransformer()
Method Detail |
---|
public StringBuffer transform(String xslFilePath, String inputFilesDir, String outputFilesDir) throws 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.
Exception
- If error.public StringBuffer transform(String xslFilePath, String inputFilesDir, String[] inputFileNames, String outputFilesDir, Date modifiedSinceDate) throws 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.
Exception
- If error.public static final void transformToFile(String inputFilePath, String outputFilePath, Transformer transformer) throws 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.
Exception
- If unable to perform the transform.public static final void transformToFile(File inputFile, File outputFile, Transformer transformer) throws 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.
Exception
- If unable to perform the transform.public static final void transformToFile(File inputFile, FileOutputStream fos, Transformer transformer) throws Exception
inputFile
- The input file to transform.fos
- The FileOutputStream where transformed content will be saved.transformer
- The Transformer used to perform the transform.
Exception
- If unable to perform the transform.public static final String transformFile(String inputFilePath, 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 String transformFile(File inputFile, 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 StringWriter transformFileToWriter(String inputFilePath, 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 String transformString(String xmlString, 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 StringWriter transformStringToWriter(String xmlString, 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 String transformFile(String inputFilePath, String xslFilePath)
inputFilePath
- The XML file to transform.xslFilePath
- The XSL file used to perform the transform.
public static final StringWriter transformFileToWriter(String inputFilePath, String xslFilePath)
inputFilePath
- The XML file to transform.xslFilePath
- The XSL file used to perform the transform.
public static final String transformString(String xmlString, String xslFilePath)
xmlString
- The XML String to transform.xslFilePath
- The XSL file used to perform the transform.
public static final String transformStringUsingString(String xmlString, String xslString)
xmlString
- The XML String to transform.xslString
- The XSL String used to define the transform.
public static final String localizeXml(String xmlString)
xmlString
- The XML String to strip of namespaces
#XSLUtils.getRemoveNamespacesXSL()
public static final StringWriter transformStringToWriter(String xmlString, String xslFilePath)
xmlString
- The XML String to transform.xslFilePath
- The XSL file used to perform the transform.
public static Transformer getTransformer(String xslFilePath) throws TransformerConfigurationException, 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.
TransformerConfigurationException
- If error.
FileNotFoundException
- If file can not be found.public static Transformer getTransformer(String xslFilePath, String transformerFactoryClass) throws TransformerConfigurationException, 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")
TransformerConfigurationException
- If error.
FileNotFoundException
- If file can not be found.public static final Transformer getTransformerFromXSLString(String xslString) throws 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 String
TransformerConfigurationException
- If error.public static String encodeStringIntoHex(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 String encodeCharsInString(String stg)
Unix commands cannot include the following chars: * ? ! | \ / ' " { } < > ; , ^ ( ) $ ~
Windows file names may not contain: \ / : * ? " < > |
stg
- A String to encode.
protected static final String getDateStamp()
protected static final void prtlnErr(String s)
s
- The text that will be output to error out.protected static final void prtlnErr(String s, Throwable t)
s
- The text that will be output to error out.t
- The Throwable to output with messageprotected static final void prtlnErr(Throwable t)
t
- The Throwable to output with messageprotected static void prtln(String s)
s
- The String that will be output.public static void setDebug(boolean db)
db
- The new debug value
|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |