List of usage examples for javax.xml.transform TransformerConfigurationException getLocationAsString
public String getLocationAsString()
From source file:Main.java
/** * This method performs XSL Transformation. <br> * <b>Deprecated use XmlTransformer.transform</b> * // w w w .j a va 2 s. com * @param source * The input XML document * @param stylesheet * The XSL stylesheet * @param params * parameters to apply to the XSL Stylesheet * @param outputProperties * properties to use for the xsl transform. Will overload the xsl output definition. * @return The output document transformed * @throws Exception * The exception */ @Deprecated public static String transform(Source source, Source stylesheet, Map<String, String> params, Properties outputProperties) throws Exception { try { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(stylesheet); if (outputProperties != null) { transformer.setOutputProperties(outputProperties); } if (params != null) { transformer.clearParameters(); for (Entry<String, String> entry : params.entrySet()) { String name = entry.getKey(); String value = entry.getValue(); transformer.setParameter(name, value); } } StringWriter sw = new StringWriter(); Result result = new StreamResult(sw); transformer.transform(source, result); return sw.toString(); } catch (TransformerConfigurationException e) { String strMessage = e.getMessage(); if (e.getLocationAsString() != null) { strMessage += ("- location : " + e.getLocationAsString()); } throw new Exception("Error transforming document XSLT : " + strMessage, e.getCause()); } catch (TransformerFactoryConfigurationError e) { throw new Exception("Error transforming document XSLT : " + e.getMessage(), e); } catch (TransformerException e) { String strMessage = e.getMessage(); if (e.getLocationAsString() != null) { strMessage += ("- location : " + e.getLocationAsString()); } throw new Exception("Error transforming document XSLT : " + strMessage, e.getCause()); } catch (Exception e) { throw new Exception("Error transforming document XSLT : " + e.getMessage(), e); } }
From source file:fr.paris.lutece.plugins.calendar.service.XMLUtils.java
/** * This method performs XSL Transformation. * //from ww w . j a v a2 s.com * @param strXml The input XML document * @param baSource The source input stream * @param params parameters to apply to the XSL Stylesheet * @param outputProperties properties to use for the xsl transform. Will * overload the xsl output definition. * @return The output document transformed * @throws Exception The exception */ public static byte[] transformXMLToXSL(String strXml, InputStream baSource, Map<String, String> params, Properties outputProperties) throws Exception { Source stylesheet = new StreamSource(baSource); StringReader srInputXml = new StringReader(strXml); StreamSource source = new StreamSource(srInputXml); try { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(stylesheet); if (outputProperties != null) { transformer.setOutputProperties(outputProperties); } if (params != null) { transformer.clearParameters(); Set<Entry<String, String>> entries = params.entrySet(); for (Entry<String, String> entry : entries) { String name = entry.getKey(); String value = entry.getValue(); transformer.setParameter(name, value); } } ByteArrayOutputStream out = new ByteArrayOutputStream(); Result result = new StreamResult(out); transformer.transform(source, result); return out.toByteArray(); } catch (TransformerConfigurationException e) { String strMessage = e.getMessage(); if (e.getLocationAsString() != null) { strMessage += ("- location : " + e.getLocationAsString()); } throw new Exception("Error transforming document XSLT : " + strMessage, e.getCause()); } catch (TransformerFactoryConfigurationError e) { throw new Exception("Error transforming document XSLT : " + e.getMessage(), e); } catch (TransformerException e) { String strMessage = e.getMessage(); if (e.getLocationAsString() != null) { strMessage += ("- location : " + e.getLocationAsString()); } throw new Exception("Error transforming document XSLT : " + strMessage, e.getCause()); } catch (Exception e) { throw new Exception("Error transforming document XSLT : " + e.getMessage(), e); } }