001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xsl;
030:
031: import com.caucho.util.L10N;
032: import com.caucho.xml.DOMBuilder;
033: import com.caucho.xml.QDocument;
034:
035: import org.w3c.dom.Node;
036: import org.xml.sax.*;
037: import org.xml.sax.ext.LexicalHandler;
038:
039: import javax.xml.transform.TransformerException;
040: import java.io.IOException;
041:
042: public class SAXFilterImpl implements XMLFilter {
043: protected static L10N L = new L10N(SAXFilterImpl.class);
044:
045: protected TransformerImpl transformer;
046:
047: private XMLReader parent;
048: private ContentHandler contentHandler;
049: private LexicalHandler lexicalHandler;
050: private ErrorHandler errorHandler;
051:
052: protected SAXFilterImpl(TransformerImpl transformer) {
053: this .transformer = transformer;
054: }
055:
056: public void setParent(XMLReader parent) {
057: this .parent = parent;
058: }
059:
060: public XMLReader getParent() {
061: return parent;
062: }
063:
064: public boolean getFeature(String name)
065: throws SAXNotRecognizedException, SAXNotSupportedException {
066: return false;
067: }
068:
069: public void setFeature(String name, boolean value)
070: throws SAXNotRecognizedException, SAXNotSupportedException {
071: }
072:
073: public Object getProperty(String name)
074: throws SAXNotRecognizedException, SAXNotSupportedException {
075: return null;
076: }
077:
078: public void setProperty(String name, Object value)
079: throws SAXNotRecognizedException, SAXNotSupportedException {
080: }
081:
082: public void setEntityResolver(EntityResolver resolver) {
083: }
084:
085: public EntityResolver getEntityResolver() {
086: return null;
087: }
088:
089: public void setDTDHandler(DTDHandler handler) {
090: }
091:
092: public DTDHandler getDTDHandler() {
093: return null;
094: }
095:
096: public void setContentHandler(ContentHandler handler) {
097: this .contentHandler = handler;
098: }
099:
100: public ContentHandler getContentHandler() {
101: return contentHandler;
102: }
103:
104: public void setErrorHandler(ErrorHandler handler) {
105: this .errorHandler = handler;
106: }
107:
108: public ErrorHandler getErrorHandler() {
109: return errorHandler;
110: }
111:
112: public void parse(InputSource input) throws IOException,
113: SAXException {
114: DOMBuilder builder = new DOMBuilder();
115: Node sourceNode = new QDocument();
116: builder.init(sourceNode);
117:
118: parent.setContentHandler(builder);
119: parent.parse(input);
120:
121: try {
122: transformer.transform(sourceNode, contentHandler,
123: lexicalHandler);
124: } catch (TransformerException e) {
125: throw new SAXException(String.valueOf(e));
126: }
127: }
128:
129: public void parse(String systemId) throws IOException, SAXException {
130: DOMBuilder builder = new DOMBuilder();
131: Node sourceNode = new QDocument();
132: builder.init(sourceNode);
133:
134: parent.setContentHandler(builder);
135:
136: parent.parse(systemId);
137:
138: try {
139: transformer.transform(sourceNode, contentHandler,
140: lexicalHandler);
141: } catch (TransformerException e) {
142: throw new SAXException(String.valueOf(e));
143: }
144: }
145: }
|