KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.L10N;
32 import com.caucho.xml.DOMBuilder;
33 import com.caucho.xml.QDocument;
34
35 import org.w3c.dom.Node JavaDoc;
36 import org.xml.sax.*;
37 import org.xml.sax.ext.LexicalHandler JavaDoc;
38
39 import javax.xml.transform.TransformerException JavaDoc;
40 import java.io.IOException JavaDoc;
41
42 public class SAXFilterImpl implements XMLFilter {
43   protected static L10N L = new L10N(SAXFilterImpl.class);
44
45   protected TransformerImpl transformer;
46
47   private XMLReader parent;
48   private ContentHandler contentHandler;
49   private LexicalHandler JavaDoc lexicalHandler;
50   private ErrorHandler errorHandler;
51
52   protected SAXFilterImpl(TransformerImpl transformer)
53   {
54     this.transformer = transformer;
55   }
56   
57   public void setParent(XMLReader parent)
58   {
59     this.parent = parent;
60   }
61   
62   public XMLReader getParent()
63   {
64     return parent;
65   }
66   
67   public boolean getFeature(String JavaDoc name)
68     throws SAXNotRecognizedException, SAXNotSupportedException
69   {
70     return false;
71   }
72   
73   public void setFeature(String JavaDoc name, boolean value)
74     throws SAXNotRecognizedException, SAXNotSupportedException
75   {
76   }
77   
78   public Object JavaDoc getProperty(String JavaDoc name)
79     throws SAXNotRecognizedException, SAXNotSupportedException
80   {
81     return null;
82   }
83   
84   public void setProperty(String JavaDoc name, Object JavaDoc value)
85     throws SAXNotRecognizedException, SAXNotSupportedException
86   {
87   }
88   
89   public void setEntityResolver(EntityResolver resolver)
90   {
91   }
92   
93   public EntityResolver getEntityResolver()
94   {
95     return null;
96   }
97   
98   public void setDTDHandler(DTDHandler handler)
99   {
100   }
101   
102   public DTDHandler getDTDHandler()
103   {
104     return null;
105   }
106   
107   public void setContentHandler(ContentHandler handler)
108   {
109     this.contentHandler = handler;
110   }
111   
112   public ContentHandler getContentHandler()
113   {
114     return contentHandler;
115   }
116   
117   public void setErrorHandler(ErrorHandler handler)
118   {
119     this.errorHandler = handler;
120   }
121   
122   public ErrorHandler getErrorHandler()
123   {
124     return errorHandler;
125   }
126   
127   public void parse(InputSource input)
128     throws IOException JavaDoc, SAXException
129   {
130     DOMBuilder builder = new DOMBuilder();
131     Node JavaDoc sourceNode = new QDocument();
132     builder.init(sourceNode);
133
134     parent.setContentHandler(builder);
135     parent.parse(input);
136     
137     try {
138       transformer.transform(sourceNode, contentHandler, lexicalHandler);
139     } catch (TransformerException JavaDoc e) {
140       throw new SAXException(String.valueOf(e));
141     }
142   }
143   
144   public void parse(String JavaDoc systemId)
145     throws IOException JavaDoc, SAXException
146   {
147     DOMBuilder builder = new DOMBuilder();
148     Node JavaDoc sourceNode = new QDocument();
149     builder.init(sourceNode);
150
151     parent.setContentHandler(builder);
152     
153     parent.parse(systemId);
154
155     try {
156       transformer.transform(sourceNode, contentHandler, lexicalHandler);
157     } catch (TransformerException JavaDoc e) {
158       throw new SAXException(String.valueOf(e));
159     }
160   }
161 }
162
Popular Tags