KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > util > DefaultXMLFilter


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.util;
24
25 import org.xml.sax.*;
26 import org.xml.sax.ext.LexicalHandler JavaDoc;
27 import org.xml.sax.helpers.XMLFilterImpl JavaDoc;
28
29 /**
30  * An XMLFilter implementation which filters also LexicalHandler events
31  */

32 public class DefaultXMLFilter extends XMLFilterImpl JavaDoc
33   implements LexicalHandler JavaDoc
34 {
35 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
36 private static final String JavaDoc RCSName = "$Name: $";
37   private LexicalHandler JavaDoc lexicalHandler = null;
38
39   /** Constructor
40    */

41   public DefaultXMLFilter() {
42     super();
43   }
44
45   /** Constructor
46    * @param reader The parent XMLReader that is filtered.
47    */

48   public DefaultXMLFilter(XMLReader reader) {
49     super(reader);
50   }
51
52   //////////////////////////////////////////////////////
53
// Implementation of XMLReader interface.
54
//////////////////////////////////////////////////////
55
public void setProperty(String JavaDoc name, Object JavaDoc value)
56     throws SAXNotRecognizedException, SAXNotSupportedException
57   {
58     if (name.equals("http://xml.org/sax/properties/lexical-handler"))
59       setLexicalHandler((LexicalHandler JavaDoc)value);
60     else
61         super.setProperty(name, value);
62   }
63     
64   public Object JavaDoc getProperty(String JavaDoc name)
65     throws SAXNotRecognizedException, SAXNotSupportedException
66   {
67     if (name.equals("http://xml.org/sax/properties/lexical-handler"))
68       return getLexicalHandler();
69     else
70       return super.getProperty(name);
71   }
72
73   public LexicalHandler JavaDoc getLexicalHandler() {
74     return lexicalHandler;
75   }
76
77   public void setLexicalHandler(LexicalHandler JavaDoc handler) {
78     try {
79       if (getParent() != null)
80         getParent().setProperty("http://xml.org/sax/properties/lexical-handler", this);
81       lexicalHandler = handler;
82     } catch (SAXException ex) {
83       // Should not occur
84
}
85   }
86   
87   //////////////////////////////////////////////////////
88
// Implementation of LexicalHandler interface.
89
//////////////////////////////////////////////////////
90
public void startDTD(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId)
91     throws SAXException
92   {
93     lexicalHandler.startDTD(name, publicId, systemId);
94   }
95
96   public void endDTD() throws SAXException
97   {
98     lexicalHandler.endDTD();
99   }
100   
101   public void startEntity(String JavaDoc name) throws SAXException
102   {
103     lexicalHandler.startEntity(name);
104   }
105
106   public void endEntity(String JavaDoc name) throws SAXException
107   {
108     lexicalHandler.endEntity(name);
109   }
110
111   public void startCDATA() throws SAXException
112   {
113     lexicalHandler.startCDATA();
114   }
115   
116   public void endCDATA() throws SAXException
117   {
118     lexicalHandler.endCDATA();
119   }
120     
121   public void comment(char ch[], int start, int length) throws SAXException
122   {
123     lexicalHandler.comment(ch, start, length);
124   }
125 }
126
127
Popular Tags