KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xsl > NodeTransformerImpl


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * 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 JavaDoc;
37 import org.xml.sax.SAXException JavaDoc;
38
39 import java.io.IOException JavaDoc;
40 import java.io.InputStream JavaDoc;
41
42 public class NodeTransformerImpl extends TransformerImpl {
43   protected LineMap _lineMap;
44   
45   NodeTransformerImpl(StylesheetImpl stylesheet)
46   {
47     super(stylesheet);
48   }
49
50   public Object JavaDoc getProperty(String JavaDoc name)
51   {
52     if (name.equals(LINE_MAP))
53       return _lineMap;
54     else
55       return super.getProperty(name);
56   }
57
58   /**
59    * Transforms the input stream as an XML document into children
60    * of the result node.
61    *
62    * @param source InputStream containing an XML document.
63    * @param node parent of the new results.
64    */

65   public Node JavaDoc transform(InputStream JavaDoc source, Node JavaDoc node)
66     throws SAXException JavaDoc, IOException JavaDoc
67   {
68     return transform(parseDocument(source, null), node);
69   }
70   
71   public Node JavaDoc transform(String JavaDoc systemId, Node JavaDoc node)
72     throws SAXException JavaDoc, IOException JavaDoc
73   {
74     return transform(parseDocument(systemId), node);
75   }
76   
77   public Node JavaDoc transformString(String JavaDoc source, Node JavaDoc node)
78     throws SAXException JavaDoc, IOException JavaDoc
79   {
80     return transform(parseStringDocument(source, null), node);
81   }
82   
83   public Node JavaDoc transform(Node JavaDoc sourceNode, Node JavaDoc destNode)
84     throws SAXException JavaDoc, IOException JavaDoc
85   {
86     _lineMap = null;
87     OutputFormat output = _stylesheet.getOutputFormat();
88
89     if (destNode == null)
90       destNode = Xml.createDocument();
91
92     DOMBuilder out = new DOMBuilder();
93     out.init(destNode);
94
95     try {
96       out.startDocument();
97       _stylesheet.transform(sourceNode, out, this);
98       out.endDocument();
99     } catch (Exception JavaDoc e) {
100       throw new IOExceptionWrapper(e);
101     }
102
103     return destNode;
104   }
105 }
106
Popular Tags