KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001-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.xinclude.XIncludeHandler;
21 import org.apache.xerces.xinclude.XIncludeNamespaceSupport;
22 import org.apache.xerces.xni.XMLDocumentHandler;
23 import org.apache.xerces.xni.grammars.XMLGrammarPool;
24 import org.apache.xerces.xni.parser.XMLComponentManager;
25 import org.apache.xerces.xni.parser.XMLConfigurationException;
26 import org.apache.xerces.xni.parser.XMLDocumentSource;
27
28 /**
29  * This parser configuration includes an <code>XIncludeHandler</code> in the pipeline
30  * before the schema validator, or as the last component in the pipeline if there is
31  * no schema validator. Using this pipeline will enable processing according to the
32  * XML Inclusions specification, to the conformance level described in
33  * <code>XIncludeHandler</code>.
34  *
35  * @author Peter McCracken, IBM
36  * @see org.apache.xerces.xinclude.XIncludeHandler
37  */

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

67     /**
68      * Constructs a parser configuration using the specified symbol table.
69      *
70      * @param symbolTable The symbol table to use.
71      */

72     public XIncludeParserConfiguration(SymbolTable symbolTable) {
73         this(symbolTable, null, null);
74     } // <init>(SymbolTable)
75

76     /**
77      * Constructs a parser configuration using the specified symbol table and
78      * grammar pool.
79      * <p>
80      *
81      * @param symbolTable The symbol table to use.
82      * @param grammarPool The grammar pool to use.
83      */

84     public XIncludeParserConfiguration(
85         SymbolTable symbolTable,
86         XMLGrammarPool grammarPool) {
87         this(symbolTable, grammarPool, null);
88     } // <init>(SymbolTable,XMLGrammarPool)
89

90     /**
91      * Constructs a parser configuration using the specified symbol table,
92      * grammar pool, and parent settings.
93      * <p>
94      *
95      * @param symbolTable The symbol table to use.
96      * @param grammarPool The grammar pool to use.
97      * @param parentSettings The parent settings.
98      */

99     public XIncludeParserConfiguration(
100         SymbolTable symbolTable,
101         XMLGrammarPool grammarPool,
102         XMLComponentManager parentSettings) {
103         super(symbolTable, grammarPool, parentSettings);
104
105         fXIncludeHandler = new XIncludeHandler();
106         addCommonComponent(fXIncludeHandler);
107         
108         final String JavaDoc[] recognizedFeatures = {
109             ALLOW_UE_AND_NOTATION_EVENTS,
110             XINCLUDE_FIXUP_BASE_URIS,
111             XINCLUDE_FIXUP_LANGUAGE
112         };
113         addRecognizedFeatures(recognizedFeatures);
114
115         // add default recognized properties
116
final String JavaDoc[] recognizedProperties =
117             { XINCLUDE_HANDLER, NAMESPACE_CONTEXT };
118         addRecognizedProperties(recognizedProperties);
119         
120         setFeature(ALLOW_UE_AND_NOTATION_EVENTS, true);
121         setFeature(XINCLUDE_FIXUP_BASE_URIS, true);
122         setFeature(XINCLUDE_FIXUP_LANGUAGE, true);
123         
124         setProperty(XINCLUDE_HANDLER, fXIncludeHandler);
125         setProperty(NAMESPACE_CONTEXT, new XIncludeNamespaceSupport());
126     } // <init>(SymbolTable,XMLGrammarPool)}
127

128     
129     /** Configures the pipeline. */
130     protected void configurePipeline() {
131         super.configurePipeline();
132
133         //configure DTD pipeline
134
fDTDScanner.setDTDHandler(fDTDProcessor);
135         fDTDProcessor.setDTDSource(fDTDScanner);
136         fDTDProcessor.setDTDHandler(fXIncludeHandler);
137         fXIncludeHandler.setDTDSource(fDTDProcessor);
138         fXIncludeHandler.setDTDHandler(fDTDHandler);
139         if (fDTDHandler != null) {
140             fDTDHandler.setDTDSource(fXIncludeHandler);
141         }
142
143         // configure XML document pipeline: insert after DTDValidator and
144
// before XML Schema validator
145
XMLDocumentSource prev = null;
146         if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
147             // we don't have to worry about fSchemaValidator being null, since
148
// super.configurePipeline() instantiated it if the feature was set
149
prev = fSchemaValidator.getDocumentSource();
150         }
151         // Otherwise, insert after the last component in the pipeline
152
else {
153             prev = fLastComponent;
154             fLastComponent = fXIncludeHandler;
155         }
156
157         XMLDocumentHandler next = prev.getDocumentHandler();
158         prev.setDocumentHandler(fXIncludeHandler);
159         fXIncludeHandler.setDocumentSource(prev);
160         if (next != null) {
161             fXIncludeHandler.setDocumentHandler(next);
162             next.setDocumentSource(fXIncludeHandler);
163         }
164
165     } // configurePipeline()
166

167     protected void configureXML11Pipeline() {
168         super.configureXML11Pipeline();
169         
170         // configure XML 1.1. DTD pipeline
171
fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor);
172         fXML11DTDProcessor.setDTDSource(fXML11DTDScanner);
173         fXML11DTDProcessor.setDTDHandler(fXIncludeHandler);
174         fXIncludeHandler.setDTDSource(fXML11DTDProcessor);
175         fXIncludeHandler.setDTDHandler(fDTDHandler);
176         if (fDTDHandler != null) {
177             fDTDHandler.setDTDSource(fXIncludeHandler);
178         }
179         
180         // configure XML document pipeline: insert after DTDValidator and
181
// before XML Schema validator
182
XMLDocumentSource prev = null;
183         if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
184             // we don't have to worry about fSchemaValidator being null, since
185
// super.configurePipeline() instantiated it if the feature was set
186
prev = fSchemaValidator.getDocumentSource();
187         }
188         // Otherwise, insert after the last component in the pipeline
189
else {
190             prev = fLastComponent;
191             fLastComponent = fXIncludeHandler;
192         }
193
194         XMLDocumentHandler next = prev.getDocumentHandler();
195         prev.setDocumentHandler(fXIncludeHandler);
196         fXIncludeHandler.setDocumentSource(prev);
197         if (next != null) {
198             fXIncludeHandler.setDocumentHandler(next);
199             next.setDocumentSource(fXIncludeHandler);
200         }
201
202     } // configureXML11Pipeline()
203

204     public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
205         throws XMLConfigurationException {
206
207         if (propertyId.equals(XINCLUDE_HANDLER)) {
208         }
209
210         super.setProperty(propertyId, value);
211     } // setProperty(String,Object)
212
}
Popular Tags