Search in sources :

Example 1 with HSErrorHandler

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"));
    }
}
Also used : Catalogue(net.heartsome.xml.Catalogue) HSErrorHandler(net.heartsome.xml.HSErrorHandler) InputSource(org.xml.sax.InputSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) SAXSource(javax.xml.transform.sax.SAXSource) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 SAXSource (javax.xml.transform.sax.SAXSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Catalogue (net.heartsome.xml.Catalogue)1 HSErrorHandler (net.heartsome.xml.HSErrorHandler)1 InputSource (org.xml.sax.InputSource)1 XMLReader (org.xml.sax.XMLReader)1