01: /*
02: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation; either version 2 of the License, or
12: * (at your option) any later version.
13: *
14: * Resin Open Source is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17: * of NON-INFRINGEMENT. See the GNU General Public License for more
18: * details.
19: *
20: * You should have received a copy of the GNU General Public License
21: * along with Resin Open Source; if not, write to the
22: * Free SoftwareFoundation, Inc.
23: * 59 Temple Place, Suite 330
24: * Boston, MA 02111-1307 USA
25: *
26: * @author Scott Ferguson
27: */
28:
29: package com.caucho.xsl;
30:
31: import com.caucho.java.LineMap;
32: import com.caucho.vfs.IOExceptionWrapper;
33: import com.caucho.xml.DOMBuilder;
34: import com.caucho.xml.Xml;
35:
36: import org.w3c.dom.Node;
37: import org.xml.sax.SAXException;
38:
39: import java.io.IOException;
40: import java.io.InputStream;
41:
42: public class NodeTransformerImpl extends TransformerImpl {
43: protected LineMap _lineMap;
44:
45: NodeTransformerImpl(StylesheetImpl stylesheet) {
46: super (stylesheet);
47: }
48:
49: public Object getProperty(String name) {
50: if (name.equals(LINE_MAP))
51: return _lineMap;
52: else
53: return super .getProperty(name);
54: }
55:
56: /**
57: * Transforms the input stream as an XML document into children
58: * of the result node.
59: *
60: * @param source InputStream containing an XML document.
61: * @param node parent of the new results.
62: */
63: public Node transform(InputStream source, Node node)
64: throws SAXException, IOException {
65: return transform(parseDocument(source, null), node);
66: }
67:
68: public Node transform(String systemId, Node node)
69: throws SAXException, IOException {
70: return transform(parseDocument(systemId), node);
71: }
72:
73: public Node transformString(String source, Node node)
74: throws SAXException, IOException {
75: return transform(parseStringDocument(source, null), node);
76: }
77:
78: public Node transform(Node sourceNode, Node destNode)
79: throws SAXException, IOException {
80: _lineMap = null;
81: OutputFormat output = _stylesheet.getOutputFormat();
82:
83: if (destNode == null)
84: destNode = Xml.createDocument();
85:
86: DOMBuilder out = new DOMBuilder();
87: out.init(destNode);
88:
89: try {
90: out.startDocument();
91: _stylesheet.transform(sourceNode, out, this );
92: out.endDocument();
93: } catch (Exception e) {
94: throw new IOExceptionWrapper(e);
95: }
96:
97: return destNode;
98: }
99: }
|