comparison gnv/src/main/java/de/intevation/gnv/util/XSLTransformer.java @ 36:ad381cc47217

Format Code to max 80 Chars per Row gnv/trunk@172 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 02 Oct 2009 08:54:13 +0000
parents 4405f31bbc30
children fccf90761825
comparison
equal deleted inserted replaced
35:4405f31bbc30 36:ad381cc47217
20 import org.apache.log4j.Logger; 20 import org.apache.log4j.Logger;
21 import org.w3c.dom.Node; 21 import org.w3c.dom.Node;
22 22
23 /** 23 /**
24 * @author Tim Englich <tim.englich@intevation.de> 24 * @author Tim Englich <tim.englich@intevation.de>
25 * 25 *
26 */ 26 */
27 public class XSLTransformer { 27 public class XSLTransformer {
28 /** 28 /**
29 * the logger, used to log exceptions and additonaly information 29 * the logger, used to log exceptions and additonaly information
30 */ 30 */
31 private static Logger log = Logger.getLogger(XSLTransformer.class); 31 private static Logger log = Logger.getLogger(XSLTransformer.class);
32
32 /** 33 /**
33 * Constructor 34 * Constructor
34 */ 35 */
35 public XSLTransformer() { 36 public XSLTransformer() {
36 super(); 37 super();
37 } 38 }
38 39
39 public String transform(Node toTransform, String encoding, String templateFileName){ 40 public String transform(Node toTransform, String encoding,
41 String templateFileName) {
40 String resultValue = null; 42 String resultValue = null;
41 try { 43 try {
42 XMLUtils xmlUtils = new XMLUtils(); 44 XMLUtils xmlUtils = new XMLUtils();
43 Source templateSource = new StreamSource(new File(templateFileName)); 45 Source templateSource = new StreamSource(new File(templateFileName));
44 TransformerFactory xformFactory = TransformerFactory.newInstance(); 46 TransformerFactory xformFactory = TransformerFactory.newInstance();
45 Transformer transformer = xformFactory.newTransformer(templateSource); 47 Transformer transformer = xformFactory
46 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 48 .newTransformer(templateSource);
47 StreamResult scrResult = new StreamResult(baos); 49 ByteArrayOutputStream baos = new ByteArrayOutputStream();
48 //log.debug(xmlUtils.writeNode2String(toTransform)); 50 StreamResult scrResult = new StreamResult(baos);
49 DOMSource source = new DOMSource(toTransform); 51 // log.debug(xmlUtils.writeNode2String(toTransform));
50 transformer.transform(source, scrResult); 52 DOMSource source = new DOMSource(toTransform);
51 resultValue = new String(baos.toByteArray(),encoding); 53 transformer.transform(source, scrResult);
52 } catch (TransformerConfigurationException e) { 54 resultValue = new String(baos.toByteArray(), encoding);
53 log.error(e,e); 55 } catch (TransformerConfigurationException e) {
54 } catch (UnsupportedEncodingException e) { 56 log.error(e, e);
55 log.error(e,e); 57 } catch (UnsupportedEncodingException e) {
56 } catch (TransformerFactoryConfigurationError e) { 58 log.error(e, e);
57 log.error(e,e); 59 } catch (TransformerFactoryConfigurationError e) {
58 } catch (TransformerException e) { 60 log.error(e, e);
59 log.error(e,e); 61 } catch (TransformerException e) {
60 } 62 log.error(e, e);
61 63 }
64
62 return resultValue; 65 return resultValue;
63 } 66 }
64 67
65 } 68 }

http://dive4elements.wald.intevation.org