package net.ihe.xcpd.init.tools; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import net.ihe.gazelle.simulator.common.model.ApplicationConfiguration; /** * @author abderrazek boufahja */ public class XSLTransformer { public static String resultTransformation(String inDetailedResult, String inXslPath) { if (inDetailedResult == null ||inDetailedResult.length() == 0) return null; if (inXslPath == null || inXslPath.length() == 0) return null; try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer( new javax.xml.transform.stream.StreamSource(ApplicationConfiguration.getValueOfVariable("gazelle_bin")+ File.separatorChar + "xsl" + File.separatorChar + inXslPath)); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamResult out = new StreamResult(baos); ByteArrayInputStream bais = new ByteArrayInputStream(inDetailedResult.getBytes("UTF8")); transformer.transform(new javax.xml.transform.stream.StreamSource(bais), out); String tmp = new String (baos.toByteArray()) ; return tmp; } catch (Exception e) { e.printStackTrace( ); return "The document cannot be displayed using this stylesheet"; } } }