KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > parsers > XPointerParserConfiguration


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 package org.apache.xerces.parsers;
17
18 import org.apache.xerces.impl.Constants;
19 import org.apache.xerces.util.SymbolTable;
20 import org.apache.xerces.xpointer.XPointerHandler;
21 import org.apache.xerces.xinclude.XIncludeHandler;
22 import org.apache.xerces.xinclude.XIncludeNamespaceSupport;
23 import org.apache.xerces.xni.XMLDocumentHandler;
24 import org.apache.xerces.xni.grammars.XMLGrammarPool;
25 import org.apache.xerces.xni.parser.XMLComponentManager;
26 import org.apache.xerces.xni.parser.XMLConfigurationException;
27 import org.apache.xerces.xni.parser.XMLDocumentSource;
28
29 /**
30  * This parser configuration includes an <code>XPointerHandler</code> in the pipeline
31  * before the schema validator, or as the last component in the pipeline if there is
32  * no schema validator. Using this pipeline will enable processing according to the
33  * XML Inclusions specification with XPointers, to the conformance level described in
34  * <code>XPointerHandler.</code>.
35  *
36  * @see org.apache.xerces.xpointer.XPointerHandler
37  */

38 public class XPointerParserConfiguration extends XML11Configuration {
39
40     private XPointerHandler fXPointerHandler;
41     
42     private XIncludeHandler fXIncludeHandler;
43
44     /** Feature identifier: allow notation and unparsed entity events to be sent out of order. */
45     protected static final String JavaDoc ALLOW_UE_AND_NOTATION_EVENTS =
46         Constants.SAX_FEATURE_PREFIX + Constants.ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE;
47     
48     /** Feature identifier: fixup base URIs. */
49     protected static final String JavaDoc XINCLUDE_FIXUP_BASE_URIS =
50         Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE;
51     
52     /** Feature identifier: fixup language. */
53     protected static final String JavaDoc XINCLUDE_FIXUP_LANGUAGE =
54         Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_LANGUAGE_FEATURE;
55
56     /** Property identifier: error reporter. */
57     protected static final String JavaDoc XPOINTER_HANDLER =
58         Constants.XERCES_PROPERTY_PREFIX + Constants.XPOINTER_HANDLER_PROPERTY;
59
60     /** Property identifier: error reporter. */
61     protected static final String JavaDoc XINCLUDE_HANDLER =
62         Constants.XERCES_PROPERTY_PREFIX + Constants.XINCLUDE_HANDLER_PROPERTY;
63     
64     /** Property identifier: error reporter. */
65     protected static final String JavaDoc NAMESPACE_CONTEXT =
66         Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY;
67
68     /** Default constructor. */
69     public XPointerParserConfiguration() {
70         this(null, null, null);
71     } // <init>()
72

73     /**
74      * Constructs a parser configuration using the specified symbol table.
75      *
76      * @param symbolTable The symbol table to use.
77      */

78     public XPointerParserConfiguration(SymbolTable symbolTable) {
79         this(symbolTable, null, null);
80     } // <init>(SymbolTable)
81

82     /**
83      * Constructs a parser configuration using the specified symbol table and
84      * grammar pool.
85      * <p>
86      *
87      * @param symbolTable The symbol table to use.
88      * @param grammarPool The grammar pool to use.
89      */

90     public XPointerParserConfiguration(
91         SymbolTable symbolTable,
92         XMLGrammarPool grammarPool) {
93         this(symbolTable, grammarPool, null);
94     } // <init>(SymbolTable,XMLGrammarPool)
95

96     /**
97      * Constructs a parser configuration using the specified symbol table,
98      * grammar pool, and parent settings.
99      * <p>
100      *
101      * @param symbolTable The symbol table to use.
102      * @param grammarPool The grammar pool to use.
103      * @param parentSettings The parent settings.
104      */

105     public XPointerParserConfiguration(
106         SymbolTable symbolTable,
107         XMLGrammarPool grammarPool,
108         XMLComponentManager parentSettings) {
109         super(symbolTable, grammarPool, parentSettings);
110
111         fXIncludeHandler = new XIncludeHandler();
112         addCommonComponent(fXIncludeHandler);
113         
114         fXPointerHandler = new XPointerHandler();
115         addCommonComponent(fXPointerHandler);
116         
117         final String JavaDoc[] recognizedFeatures = {
118             ALLOW_UE_AND_NOTATION_EVENTS,
119             XINCLUDE_FIXUP_BASE_URIS,
120             XINCLUDE_FIXUP_LANGUAGE
121         };
122         addRecognizedFeatures(recognizedFeatures);
123
124         // add default recognized properties
125
final String JavaDoc[] recognizedProperties =
126             { XINCLUDE_HANDLER, XPOINTER_HANDLER, NAMESPACE_CONTEXT };
127         addRecognizedProperties(recognizedProperties);
128         
129         setFeature(ALLOW_UE_AND_NOTATION_EVENTS, true);
130         setFeature(XINCLUDE_FIXUP_BASE_URIS, true);
131         setFeature(XINCLUDE_FIXUP_LANGUAGE, true);
132         
133         setProperty(XINCLUDE_HANDLER, fXIncludeHandler);
134         setProperty(XPOINTER_HANDLER, fXPointerHandler);
135         setProperty(NAMESPACE_CONTEXT, new XIncludeNamespaceSupport());
136         
137             
138     } // <init>(SymbolTable,XMLGrammarPool)}
139

140     
141     /** Configures the pipeline. */
142     protected void configurePipeline() {
143         super.configurePipeline();
144
145         //configure DTD pipeline
146
fDTDScanner.setDTDHandler(fDTDProcessor);
147         fDTDProcessor.setDTDSource(fDTDScanner);
148
149         fDTDProcessor.setDTDHandler(fXIncludeHandler);
150         fXIncludeHandler.setDTDSource(fDTDProcessor);
151         fXIncludeHandler.setDTDHandler(fXPointerHandler);
152         fXPointerHandler.setDTDSource(fXIncludeHandler);
153         fXPointerHandler.setDTDHandler(fDTDHandler);
154         if (fDTDHandler != null) {
155             fDTDHandler.setDTDSource(fXPointerHandler);
156         }
157         
158         // configure XML document pipeline: insert after DTDValidator and
159
// before XML Schema validator
160
XMLDocumentSource prev = null;
161         if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
162             // we don't have to worry about fSchemaValidator being null, since
163
// super.configurePipeline() instantiated it if the feature was set
164
prev = fSchemaValidator.getDocumentSource();
165         }
166         // Otherwise, insert after the last component in the pipeline
167
else {
168             prev = fLastComponent;
169             fLastComponent = fXPointerHandler;
170         }
171
172         XMLDocumentHandler next = prev.getDocumentHandler();
173         prev.setDocumentHandler(fXIncludeHandler);
174         fXIncludeHandler.setDocumentSource(prev);
175
176         if (next != null) {
177             fXIncludeHandler.setDocumentHandler(next);
178             next.setDocumentSource(fXIncludeHandler);
179         }
180
181         fXIncludeHandler.setDocumentHandler(fXPointerHandler);
182         fXPointerHandler.setDocumentSource(fXIncludeHandler);
183     } // configurePipeline()
184

185     protected void configureXML11Pipeline() {
186         super.configureXML11Pipeline();
187     
188         // configure XML 1.1. DTD pipeline
189
fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor);
190         fXML11DTDProcessor.setDTDSource(fXML11DTDScanner);
191         
192         fDTDProcessor.setDTDHandler(fXIncludeHandler);
193         fXIncludeHandler.setDTDSource(fXML11DTDProcessor);
194         fXIncludeHandler.setDTDHandler(fXPointerHandler);
195         fXPointerHandler.setDTDSource(fXIncludeHandler);
196         fXPointerHandler.setDTDHandler(fDTDHandler);
197         if (fDTDHandler != null) {
198             fDTDHandler.setDTDSource(fXPointerHandler);
199         }
200
201         
202         // configure XML document pipeline: insert after DTDValidator and
203
// before XML Schema validator
204
XMLDocumentSource prev = null;
205         if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
206             // we don't have to worry about fSchemaValidator being null, since
207
// super.configurePipeline() instantiated it if the feature was set
208
prev = fSchemaValidator.getDocumentSource();
209         }
210         // Otherwise, insert after the last component in the pipeline
211
else {
212             prev = fLastComponent;
213             fLastComponent = fXPointerHandler;
214         }
215
216         XMLDocumentHandler next = prev.getDocumentHandler();
217         prev.setDocumentHandler(fXIncludeHandler);
218         fXIncludeHandler.setDocumentSource(prev);
219
220         if (next != null) {
221             fXIncludeHandler.setDocumentHandler(next);
222             next.setDocumentSource(fXIncludeHandler);
223         }
224         
225         fXIncludeHandler.setDocumentHandler(fXPointerHandler);
226         fXPointerHandler.setDocumentSource(fXIncludeHandler);
227
228         
229     } // configureXML11Pipeline()
230

231     public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
232         throws XMLConfigurationException {
233
234         //if (propertyId.equals(XINCLUDE_HANDLER)) {
235
//}
236

237         super.setProperty(propertyId, value);
238     } // setProperty(String,Object)
239
}
Popular Tags