List of usage examples for javax.xml.transform TransformerConfigurationException getMessageAndLocation
public String getMessageAndLocation()
From source file:Main.java
public static String transform(String xmlString, String stylesheetPathname) throws Exception { try {//w w w . j av a 2 s. c om TransformerFactory factory = TransformerFactory.newInstance(); Source stylesheetSource = new StreamSource(new File(stylesheetPathname).getAbsoluteFile()); Transformer transformer = factory.newTransformer(stylesheetSource); Source inputSource = new StreamSource(new StringReader(xmlString)); Writer outputWriter = new StringWriter(); Result outputResult = new StreamResult(outputWriter); transformer.transform(inputSource, outputResult); return outputWriter.toString(); } catch (TransformerConfigurationException tce) { throw new Exception(tce.getMessageAndLocation()); } catch (TransformerException te) { throw new Exception(te.getMessageAndLocation()); } }
From source file:Main.java
public static String transform(String xmlString, String stylesheetPathname) throws TransformerException { try {// w w w . j a va 2 s . c o m TransformerFactory factory = TransformerFactory.newInstance(); Source stylesheetSource = new StreamSource(new File(stylesheetPathname).getAbsoluteFile()); Transformer transformer = factory.newTransformer(stylesheetSource); Source inputSource = new StreamSource(new StringReader(xmlString)); Writer outputWriter = new StringWriter(); Result outputResult = new StreamResult(outputWriter); transformer.transform(inputSource, outputResult); return outputWriter.toString(); } catch (TransformerConfigurationException tce) { throw new TransformerException(tce.getMessageAndLocation()); } catch (TransformerException te) { throw new TransformerException(te.getMessageAndLocation()); } }
From source file:com.portfolio.data.utils.DomUtils.java
public static void processXSLT(Source xml, String xsltName, Result result, StringBuffer outTrace, boolean trace) throws Exception { // ======================================= outTrace.append("<br>processXSLT... " + xsltName); TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource stylesource = new StreamSource(xsltName); Transformer transformer = tFactory.newTransformer(stylesource); try {/*from ww w . j ava 2s. c o m*/ transformer.transform(xml, result); } catch (TransformerConfigurationException tce) { throw new TransformerException(tce.getMessageAndLocation()); } catch (TransformerException te) { throw new TransformerException(te.getMessageAndLocation()); } if (trace) outTrace.append(" ... ok"); }
From source file:org.pepstock.jem.ant.validator.transformer.TransformerValidator.java
/** * Do the xsl transformation. During the transformation, the transformer * object is locked, so the file listner is inhibited to do a refresh of * transformer object//from w ww. ja va2 s.c o m * * @param inXmlContent the in xml content * @throws ValidationException the validation exception */ private synchronized void transform(String inXmlContent) throws ValidationException { // sync is necessary to avoid concurrent access to transformer by file // listner synchronized (this) { StreamSource source = null; StreamResult result = null; try { // traverse the transformation, if some errors are found will be // generated some exceptions, otherwise do nothing InputStream is = new ByteArrayInputStream(inXmlContent.getBytes(CharSet.DEFAULT)); source = new StreamSource(is); // Use the Transformer to transform an XML Source and send the // output to a Result object. StringWriter sw = new StringWriter(); result = new StreamResult(sw); transformer.transform(source, result); sw.close(); } catch (TransformerConfigurationException e) { throw new ValidationException(e); } catch (TransformerException e) { throw new ValidationException(e.getMessageAndLocation(), e); } catch (Exception e) { throw new ValidationException(e); } } }