01: //=============================================================================
02: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
03: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
04: //=== and United Nations Environment Programme (UNEP)
05: //===
06: //=== This program is free software; you can redistribute it and/or modify
07: //=== it under the terms of the GNU General Public License as published by
08: //=== the Free Software Foundation; either version 2 of the License, or (at
09: //=== your option) any later version.
10: //===
11: //=== This program is distributed in the hope that it will be useful, but
12: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
13: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: //=== General Public License for more details.
15: //===
16: //=== You should have received a copy of the GNU General Public License
17: //=== along with this program; if not, write to the Free Software
18: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19: //===
20: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
21: //=== Rome - Italy. email: geonetwork@osgeo.org
22: //==============================================================================
23:
24: package org.wfp.vam.intermap.util;
25:
26: import java.io.File;
27: import java.io.OutputStream;
28: import javax.xml.transform.Source;
29: import javax.xml.transform.Transformer;
30: import javax.xml.transform.TransformerFactory;
31: import javax.xml.transform.stream.StreamResult;
32: import javax.xml.transform.stream.StreamSource;
33: import org.jdom.Document;
34: import org.jdom.Element;
35: import org.jdom.transform.JDOMResult;
36: import org.jdom.transform.JDOMSource;
37:
38: /**
39: * @author ETj: Decompiled by Jad v1.5.8e.
40: */
41: public class XmlTransformer {
42: public static Element transform(Element xml, String styleSheet)
43: throws Exception {
44: return transform(xml, ((Source) (new StreamSource(styleSheet))));
45: }
46:
47: public static Element transform(Element xml, Element styleSheet)
48: throws Exception {
49: return transform(xml, ((Source) (new JDOMSource(new Document(
50: (Element) styleSheet.detach())))));
51: }
52:
53: public static Element transform(Element xml, Source srcSheet)
54: throws Exception {
55: TransformerFactory transFact = TransformerFactory.newInstance();
56: Source srcXml = new JDOMSource(new Document((Element) xml
57: .detach()));
58: JDOMResult resXml = new JDOMResult();
59: Transformer t = transFact.newTransformer(srcSheet);
60: t.transform(srcXml, resXml);
61: return (Element) resXml.getDocument().getRootElement().detach();
62: }
63:
64: public static void transform(Element xml, String styleSheet,
65: OutputStream out) throws Exception {
66: transform(xml,
67: ((Source) (new StreamSource(new File(styleSheet)))),
68: out);
69: }
70:
71: public static void transform(Element xml, Element styleSheet,
72: OutputStream out) throws Exception {
73: transform(xml, ((Source) (new JDOMSource(new Document(
74: (Element) styleSheet.detach())))), out);
75: }
76:
77: public static void transform(Element xml, Source srcSheet,
78: OutputStream out) throws Exception {
79: TransformerFactory transFact = TransformerFactory.newInstance();
80: Source srcXml = new JDOMSource(new Document((Element) xml
81: .detach()));
82: javax.xml.transform.Result resStream = new StreamResult(out);
83: Transformer t = transFact.newTransformer(srcSheet);
84: t.transform(srcXml, resStream);
85: }
86:
87: }
|