Revision 23de68fc
Added by Andreas Müller almost 2 years ago
cdmlib-print/src/main/java/eu/etaxonomy/cdm/print/Transformator.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.print; |
11 | 10 |
|
12 | 11 |
import java.io.IOException; |
... | ... | |
19 | 18 |
import javax.xml.transform.TransformerFactory; |
20 | 19 |
import javax.xml.transform.stream.StreamSource; |
21 | 20 |
|
22 |
import org.apache.log4j.Logger; |
|
21 |
import org.apache.logging.log4j.LogManager; |
|
22 |
import org.apache.logging.log4j.Logger; |
|
23 | 23 |
import org.jdom.Document; |
24 | 24 |
import org.jdom.transform.JDOMResult; |
25 | 25 |
import org.jdom.transform.JDOMSource; |
... | ... | |
27 | 27 |
|
28 | 28 |
/** |
29 | 29 |
* Perform XSL transformations. |
30 |
*
|
|
31 |
* Note: This class provides access to the JAXP XSL transformer currently active.
|
|
32 |
*
|
|
30 |
* |
|
31 |
* Note: This class provides access to the JAXP XSL transformer currently active. |
|
32 |
* |
|
33 | 33 |
* @author n.hoffmann |
34 | 34 |
* @since Apr 20, 2010 |
35 |
* @version 1.0 |
|
36 | 35 |
*/ |
37 | 36 |
public class Transformator { |
38 | 37 |
|
39 |
private static final Logger logger = Logger |
|
40 |
.getLogger(Transformator.class); |
|
38 |
private static final Logger logger = LogManager.getLogger(Transformator.class); |
|
41 | 39 |
private Transformer transformer; |
42 |
|
|
40 |
|
|
43 | 41 |
|
44 | 42 |
public Transformator(InputStream stylesheet) throws XSLTransformException{ |
45 | 43 |
if(stylesheet == null){ |
46 | 44 |
throw new IllegalArgumentException("Stylsheet may not be null"); |
47 | 45 |
} |
48 |
|
|
46 |
|
|
49 | 47 |
try { |
50 | 48 |
TransformerFactory transformerFactory = TransformerFactory.newInstance(); |
51 | 49 |
Templates templates = transformerFactory.newTemplates(new StreamSource(stylesheet)); |
... | ... | |
53 | 51 |
} |
54 | 52 |
catch (TransformerException e) { |
55 | 53 |
throw new XSLTransformException("Could not construct XSLTransformer", e); |
56 |
|
|
54 |
|
|
57 | 55 |
} |
58 | 56 |
} |
59 |
|
|
60 |
|
|
57 |
|
|
58 |
|
|
61 | 59 |
public Transformator(URL stylesheet) throws XSLTransformException, IOException { |
62 | 60 |
this(stylesheet.openStream()); |
63 | 61 |
} |
64 |
|
|
62 |
|
|
65 | 63 |
/** |
66 | 64 |
* Transforms the given document to an output document. |
67 | 65 |
* |
... | ... | |
75 | 73 |
JDOMResult result = new JDOMResult(); |
76 | 74 |
try { |
77 | 75 |
logger.trace("Transforming input document: " + inputDocument); |
78 |
|
|
76 |
|
|
79 | 77 |
transformer.transform(source, result); |
80 | 78 |
Document resultDocument = result.getDocument(); |
81 |
|
|
79 |
|
|
82 | 80 |
resultDocument.getContent(); |
83 |
return resultDocument;
|
|
81 |
return resultDocument; |
|
84 | 82 |
} |
85 | 83 |
catch (TransformerException e) { |
86 | 84 |
logger.error(e); |
Also available in: Unified diff
ref #9359 upgrade cdmlib to log4j 2