KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > jaxp > UnparsedEntityHandler


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.jaxp;
18
19 import java.util.HashMap JavaDoc;
20
21 import org.apache.xerces.impl.validation.EntityState;
22 import org.apache.xerces.impl.validation.ValidationManager;
23 import org.apache.xerces.xni.Augmentations;
24 import org.apache.xerces.xni.XMLDTDHandler;
25 import org.apache.xerces.xni.XMLLocator;
26 import org.apache.xerces.xni.XMLResourceIdentifier;
27 import org.apache.xerces.xni.XMLString;
28 import org.apache.xerces.xni.XNIException;
29 import org.apache.xerces.xni.parser.XMLDTDFilter;
30 import org.apache.xerces.xni.parser.XMLDTDSource;
31
32 /**
33  * <p>This filter records which unparsed entities have been
34  * declared in the DTD and provides this information to a ValidationManager.
35  * Events are forwarded to the registered XMLDTDHandler without modification.</p>
36  *
37  * @author Michael Glavassevich, IBM
38  * @version $Id: UnparsedEntityHandler.java,v 1.4 2005/06/22 02:03:40 mrglavas Exp $
39  */

40 final class UnparsedEntityHandler implements XMLDTDFilter, EntityState {
41
42     /** DTD source and handler. **/
43     private XMLDTDSource fDTDSource;
44     private XMLDTDHandler fDTDHandler;
45     
46     /** Validation manager. */
47     private final ValidationManager fValidationManager;
48     
49     /** Map for tracking unparsed entities. */
50     private HashMap JavaDoc fUnparsedEntities = null;
51     
52     UnparsedEntityHandler(ValidationManager manager) {
53         fValidationManager = manager;
54     }
55     
56     /*
57      * XMLDTDHandler methods
58      */

59
60     public void startDTD(XMLLocator locator, Augmentations augmentations)
61             throws XNIException {
62         fValidationManager.setEntityState(this);
63         if (fUnparsedEntities != null && !fUnparsedEntities.isEmpty()) {
64             // should only clear this if the last document contained unparsed entities
65
fUnparsedEntities.clear();
66         }
67         if (fDTDHandler != null) {
68             fDTDHandler.startDTD(locator, augmentations);
69         }
70     }
71
72     public void startParameterEntity(String JavaDoc name,
73             XMLResourceIdentifier identifier, String JavaDoc encoding,
74             Augmentations augmentations) throws XNIException {
75         if (fDTDHandler != null) {
76             fDTDHandler.startParameterEntity(name, identifier, encoding, augmentations);
77         }
78     }
79
80     public void textDecl(String JavaDoc version, String JavaDoc encoding,
81             Augmentations augmentations) throws XNIException {
82         if (fDTDHandler != null) {
83             fDTDHandler.textDecl(version, encoding, augmentations);
84         }
85     }
86
87     public void endParameterEntity(String JavaDoc name, Augmentations augmentations)
88             throws XNIException {
89         if (fDTDHandler != null) {
90             fDTDHandler.endParameterEntity(name, augmentations);
91         }
92     }
93
94     public void startExternalSubset(XMLResourceIdentifier identifier,
95             Augmentations augmentations) throws XNIException {
96         if (fDTDHandler != null) {
97             fDTDHandler.startExternalSubset(identifier, augmentations);
98         }
99     }
100
101     public void endExternalSubset(Augmentations augmentations)
102             throws XNIException {
103         if (fDTDHandler != null) {
104             fDTDHandler.endExternalSubset(augmentations);
105         }
106     }
107
108     public void comment(XMLString text, Augmentations augmentations)
109             throws XNIException {
110         if (fDTDHandler != null) {
111             fDTDHandler.comment(text, augmentations);
112         }
113     }
114
115     public void processingInstruction(String JavaDoc target, XMLString data,
116             Augmentations augmentations) throws XNIException {
117         if (fDTDHandler != null) {
118             fDTDHandler.processingInstruction(target, data, augmentations);
119         }
120     }
121
122     public void elementDecl(String JavaDoc name, String JavaDoc contentModel,
123             Augmentations augmentations) throws XNIException {
124         if (fDTDHandler != null) {
125             fDTDHandler.elementDecl(name, contentModel, augmentations);
126         }
127     }
128
129     public void startAttlist(String JavaDoc elementName, Augmentations augmentations)
130             throws XNIException {
131         if (fDTDHandler != null) {
132             fDTDHandler.startAttlist(elementName, augmentations);
133         }
134     }
135
136     public void attributeDecl(String JavaDoc elementName, String JavaDoc attributeName,
137             String JavaDoc type, String JavaDoc[] enumeration, String JavaDoc defaultType,
138             XMLString defaultValue, XMLString nonNormalizedDefaultValue,
139             Augmentations augmentations) throws XNIException {
140         if (fDTDHandler != null) {
141             fDTDHandler.attributeDecl(elementName, attributeName,
142                     type, enumeration, defaultType,
143                     defaultValue, nonNormalizedDefaultValue,
144                     augmentations);
145         }
146     }
147
148     public void endAttlist(Augmentations augmentations) throws XNIException {
149         if (fDTDHandler != null) {
150             fDTDHandler.endAttlist(augmentations);
151         }
152     }
153
154     public void internalEntityDecl(String JavaDoc name, XMLString text,
155             XMLString nonNormalizedText, Augmentations augmentations)
156             throws XNIException {
157         if (fDTDHandler != null) {
158             fDTDHandler.internalEntityDecl(name, text,
159                     nonNormalizedText, augmentations);
160         }
161     }
162
163     public void externalEntityDecl(String JavaDoc name,
164             XMLResourceIdentifier identifier, Augmentations augmentations)
165             throws XNIException {
166         if (fDTDHandler != null) {
167             fDTDHandler.externalEntityDecl(name, identifier, augmentations);
168         }
169     }
170
171     public void unparsedEntityDecl(String JavaDoc name,
172             XMLResourceIdentifier identifier, String JavaDoc notation,
173             Augmentations augmentations) throws XNIException {
174         if (fUnparsedEntities == null) {
175             fUnparsedEntities = new HashMap JavaDoc();
176         }
177         fUnparsedEntities.put(name, name);
178         if (fDTDHandler != null) {
179             fDTDHandler.unparsedEntityDecl(name, identifier, notation, augmentations);
180         }
181     }
182
183     public void notationDecl(String JavaDoc name, XMLResourceIdentifier identifier,
184             Augmentations augmentations) throws XNIException {
185         if (fDTDHandler != null) {
186             fDTDHandler.notationDecl(name, identifier, augmentations);
187         }
188     }
189
190     public void startConditional(short type, Augmentations augmentations)
191             throws XNIException {
192         if (fDTDHandler != null) {
193             fDTDHandler.startConditional(type, augmentations);
194         }
195     }
196
197     public void ignoredCharacters(XMLString text, Augmentations augmentations)
198             throws XNIException {
199         if (fDTDHandler != null) {
200             fDTDHandler.ignoredCharacters(text, augmentations);
201         }
202
203     }
204
205     public void endConditional(Augmentations augmentations) throws XNIException {
206         if (fDTDHandler != null) {
207             fDTDHandler.endConditional(augmentations);
208         }
209     }
210
211     public void endDTD(Augmentations augmentations) throws XNIException {
212         if (fDTDHandler != null) {
213             fDTDHandler.endDTD(augmentations);
214         }
215     }
216
217     public void setDTDSource(XMLDTDSource source) {
218         fDTDSource = source;
219     }
220
221     public XMLDTDSource getDTDSource() {
222         return fDTDSource;
223     }
224     
225     /*
226      * XMLDTDSource methods
227      */

228
229     public void setDTDHandler(XMLDTDHandler handler) {
230         fDTDHandler = handler;
231     }
232
233     public XMLDTDHandler getDTDHandler() {
234         return fDTDHandler;
235     }
236     
237     /*
238      * EntityState methods
239      */

240
241     public boolean isEntityDeclared(String JavaDoc name) {
242         return false;
243     }
244
245     public boolean isEntityUnparsed(String JavaDoc name) {
246         if (fUnparsedEntities != null) {
247             return fUnparsedEntities.containsKey(name);
248         }
249         return false;
250     }
251     
252 }
253
Popular Tags