use of net.heartsome.xml.HSErrorHandler in project translationstudio8 by heartsome.
the class XSLTransformationDialog method transform.
/**
* 转换文件
* @param strSourcePath
* 源文件路径
* @param strXSLPath
* XSL 文件路径
* @param strTargetPath
* 转变文件路径
* @throws Exception
* ;
*/
private void transform(String strSourcePath, String strXSLPath, String strTargetPath) throws Exception {
TransformerFactory tfactory = TransformerFactory.newInstance();
String catalogPath = PluginUtil.getCataloguePath();
if (tfactory.getFeature(SAXSource.FEATURE)) {
// Standard way of creating an XMLReader in JAXP 1.1.
SAXParserFactory pfactory = SAXParserFactory.newInstance();
// Very important!
pfactory.setNamespaceAware(true);
// Turn on validation.
// pfactory.setValidating(true);
// Get an XMLReader.
XMLReader reader = pfactory.newSAXParser().getXMLReader();
reader.setEntityResolver(new Catalogue(catalogPath));
// Instantiate an error handler (see the Handler inner class below)
// that will report any
// errors or warnings that occur as the XMLReader is parsing the XML
// input.
reader.setErrorHandler(new HSErrorHandler());
// Standard way of creating a transformer from a URL.
Transformer t = tfactory.newTransformer(new StreamSource(strXSLPath));
// Specify a SAXSource that takes both an XMLReader and a URL.
SAXSource source = new SAXSource(reader, new InputSource(strSourcePath));
// Transform to a file.
t.transform(source, new StreamResult(strTargetPath));
} else {
//$NON-NLS-1$
throw new Exception(Messages.getString("dialog.XSLTransformationDialog.msg6"));
}
}
Aggregations