List of usage examples for javax.xml.transform TransformerConfigurationException getMessage
public String getMessage()
From source file:org.jaggeryjs.hostobjects.xslt.XSLTHostObject.java
private static Transformer getTransformer(Context cx, Scriptable scope, XSLTHostObject xho, NativeObject paramMap, Function uriResolver) throws ScriptException { Transformer transformer;//from www. j a v a2s . co m try { transformer = xho.factory.newTransformer(new StreamSource(xho.xslt)); if (paramMap != null) { setParams(transformer, paramMap); } if (uriResolver != null) { transformer.setURIResolver(getUriResolver(cx, scope, uriResolver)); } return transformer; } catch (TransformerConfigurationException e) { log.error(e.getMessage(), e); throw new ScriptException(e); } }
From source file:org.kuali.kfs.module.tem.batch.PerDiemXmlInputFileType.java
protected Source transform(InputStream fileContents) { try {/*ww w.j a v a 2 s. c om*/ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = documentBuilder.parse(fileContents); document.getDocumentElement().setAttribute("xmlns", "http://www.kuali.org/kfs/tem/perDiem"); Source domSource = new DOMSource(document); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); StreamResult streamResult = new StreamResult(outputStream); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); // Transform the document to the result stream transformer.transform(domSource, streamResult); InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); return new StreamSource(inputStream); } catch (TransformerConfigurationException ex) { LOG.error("error occurred while validating file contents: " + ex.getMessage()); throw new RuntimeException("error occurred while validating file contents: " + ex.getMessage(), ex); } catch (TransformerException ex) { LOG.error("error occurred while validating file contents: " + ex.getMessage()); throw new RuntimeException("error occurred while validating file contents: " + ex.getMessage(), ex); } catch (SAXException e) { LOG.error("error encountered while parsing xml " + e.getMessage()); throw new ParseException("Schema validation error occured while processing file: " + e.getMessage(), e); } catch (IOException e1) { LOG.error("error occured while validating file contents: " + e1.getMessage()); throw new RuntimeException("error occurred while validating file contents: " + e1.getMessage(), e1); } catch (ParserConfigurationException ex) { LOG.error("error occurred while validating file contents: " + ex.getMessage()); throw new RuntimeException("error occurred while validating file contents: " + ex.getMessage(), ex); } }
From source file:org.lareferencia.backend.indexer.IndexerImpl.java
private Transformer buildTransformer() throws IndexerException { Transformer trf;// w ww . j a v a 2s . co m try { StreamSource stylesource = new StreamSource(stylesheet); trf = xformFactory.newTransformer(stylesource); trf = MedatadaDOMHelper.buildXSLTTransformer(stylesheet); trf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trf.setOutputProperty(OutputKeys.INDENT, "no"); trf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); } catch (TransformerConfigurationException e) { throw new IndexerException(e.getMessage(), e.getCause()); } return trf; }
From source file:org.openadaptor.auxil.processor.xml.XsltProcessor.java
/** * Trys to load the XSLT from the file defined in the properties (will also try to find the file on the classpath if * it can).//from w w w . j av a2s . com * * @throws ValidationException * if the XSLT file is not defined in the properties, the file cannot be found or there was an error parsing * it */ private void loadXSLT() { if (xsltFile == null) throw new ValidationException("xsltFile property not set", this); // if the file doesn't exist try to get it via the classpath URL url = FileUtils.toURL(xsltFile); if (url == null) throw new ValidationException("File not found: " + xsltFile, this); // load the transform try { TransformerFactory factory = TransformerFactory.newInstance(); ErrorListener errorListener = new ErrorListener() { public void warning(TransformerException exception) throws TransformerException { log.warn(exception.getMessage(), exception); } public void fatalError(TransformerException exception) throws TransformerException { throw exception; } public void error(TransformerException exception) throws TransformerException { throw exception; } }; factory.setErrorListener(errorListener); transform = factory.newTransformer(new StreamSource(url.getPath())); log.info("Loaded XSLT [" + xsltFile + "] successfully"); } catch (TransformerConfigurationException e) { throw new ValidationException("Failed to load XSLT: " + e.getMessage(), this); } }
From source file:org.openrepose.commons.utils.transform.xslt.AbstractXslTransform.java
public AbstractXslTransform(Templates transformTemplates) { this.transformationTemplates = transformTemplates; xsltResourcePool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<Transformer>() { @Override//from w w w . j a va 2 s .c o m public Transformer makeObject() { try { return transformationTemplates.newTransformer(); } catch (TransformerConfigurationException configurationException) { throw new XsltTransformationException( "Failed to generate XSLT transformer. Reason: " + configurationException.getMessage(), configurationException); } } }); }
From source file:org.openrepose.commons.utils.transform.xslt.XsltTransformConstruction.java
public ObjectPool<Transformer> generateXsltResourcePool(final Templates transformationTemplates) { return new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<Transformer>() { @Override/*from ww w. ja v a 2s . c o m*/ public Transformer makeObject() { try { return transformationTemplates.newTransformer(); } catch (TransformerConfigurationException configurationException) { throw new XsltTransformationException( "Failed to generate XSLT transformer. Reason: " + configurationException.getMessage(), configurationException); } } }); }
From source file:org.pepstock.jem.ant.validator.transformer.TransformerValidator.java
/** * Inits the transformer, load the xslt and validate it, load jem properties * During the transformation, the transformer onbject is locked, so the file * listner is inhibited to do a refresh. * //from w ww. ja v a2 s . c o m * @param xsltvalidatorFile the xslt file * @return the transformer * @throws ValidationException the validation exception */ private Transformer createTransformer(String xsltvalidatorFile) throws ValidationException { Transformer t = null; // Instantiate a TransformerFactory TransformerFactory tFactory = TransformerFactory.newInstance(); // add error listner to capture validation error. ErrorListener tfel = new TransformerFactoryErrorListener(); tFactory.setErrorListener(tfel); // check the transformer compliant if (!tFactory.getFeature(SAXTransformerFactory.FEATURE)) { throw new ValidationException(AntMessage.JEMA050E.toMessage().getFormattedMessage()); } // activate xalan extension NodeInfo to map source xml code position tFactory.setAttribute(TransformerFactoryImpl.FEATURE_SOURCE_LOCATION, Boolean.TRUE); StreamSource ss = new StreamSource(xsltvalidatorFile); try { // A Transformer may be used multiple times. // Parameters and output properties are preserved across // transformations. t = tFactory.newTransformer(ss); } catch (TransformerConfigurationException e) { throw new ValidationException(AntMessage.JEMA047E.toMessage().getFormattedMessage(e.getMessage()), e); } // add custom error listener, necessary to avoid internal catch // of exception throwed by xslt ErrorListener el = new TransformerErrorListener(); t.setErrorListener(el); // pass the parameter list to the xslt for (Object key : System.getProperties().keySet()) { String keyString = key.toString(); String value = System.getProperty(keyString); t.setParameter(keyString, value); } for (String key : System.getenv().keySet()) { String value = System.getenv().get(key); t.setParameter(key, value); } return t; }
From source file:org.plasma.provisioning.xsd.AbstractAssembler.java
protected String serializeElement(ElementNSImpl nsElem) { String result = ""; TransformerFactory transFactory = TransformerFactory.newInstance(); log.debug("transformer factory: " + transFactory.getClass().getName()); //transFactory.setAttribute("indent-number", 2); Transformer idTransform = null; ByteArrayOutputStream stream = null; try {//from w w w . ja v a 2s . co m idTransform = transFactory.newTransformer(); idTransform.setOutputProperty(OutputKeys.METHOD, "xml"); idTransform.setOutputProperty(OutputKeys.INDENT, "yes"); idTransform.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); Source input = new DOMSource(nsElem.getOwnerDocument()); stream = new ByteArrayOutputStream(); Result output = new StreamResult(stream); idTransform.transform(input, output); stream.flush(); result = new String(stream.toByteArray()); return result; } catch (TransformerConfigurationException e1) { log.error(e1.getMessage(), e1); } catch (TransformerException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } finally { if (stream != null) try { stream.close(); } catch (Throwable t) { } } return result; }
From source file:org.plasma.provisioning.xsd.ConverterSupport.java
public String serializeElement(ElementNSImpl nsElem) { String result = ""; TransformerFactory transFactory = TransformerFactory.newInstance(); log.debug("transformer factory: " + transFactory.getClass().getName()); //transFactory.setAttribute("indent-number", 2); Transformer idTransform = null; ByteArrayOutputStream stream = null; try {//from ww w .jav a2 s . c o m idTransform = transFactory.newTransformer(); idTransform.setOutputProperty(OutputKeys.METHOD, "xml"); idTransform.setOutputProperty(OutputKeys.INDENT, "yes"); idTransform.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); Source input = new DOMSource(nsElem.getOwnerDocument()); stream = new ByteArrayOutputStream(); Result output = new StreamResult(stream); idTransform.transform(input, output); stream.flush(); result = new String(stream.toByteArray()); return result; } catch (TransformerConfigurationException e1) { log.error(e1.getMessage(), e1); } catch (TransformerException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } finally { if (stream != null) try { stream.close(); } catch (Throwable t) { } } return result; }
From source file:org.portletbridge.portlet.DefaultTemplateFactory.java
public DefaultTemplateFactory() { defaultTemplateSytemId = getClass().getResource("/org/portletbridge/xsl/default.xsl").toExternalForm(); Source templateSource = new StreamSource(defaultTemplateSytemId); try {//from ww w.j a va2s . c o m defaultTemplate = TransformerFactory.newInstance().newTemplates(templateSource); log.debug("created default template"); } catch (TransformerConfigurationException e) { throw new IllegalStateException(e.getMessage()); } catch (TransformerFactoryConfigurationError e) { throw new IllegalStateException(e.getMessage()); } }