~ubuntu-branches/ubuntu/karmic/libxerces2-java/karmic

« back to all changes in this revision

Viewing changes to src/org/apache/xerces/jaxp/SAXParserFactoryImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-12-04 17:37:55 UTC
  • mfrom: (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20061204173755-hb6ybrrrk097zhx7
Tags: 2.8.1-1ubuntu1
* Merge with Debian unstable; remaining changes:
  - Build -gcj package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *
3
 
 * The Apache Software License, Version 1.1
4
 
 *
5
 
 *
6
 
 * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights 
7
 
 * reserved.
8
 
 *
9
 
 * Redistribution and use in source and binary forms, with or without
10
 
 * modification, are permitted provided that the following conditions
11
 
 * are met:
12
 
 *
13
 
 * 1. Redistributions of source code must retain the above copyright
14
 
 *    notice, this list of conditions and the following disclaimer. 
15
 
 *
16
 
 * 2. Redistributions in binary form must reproduce the above copyright
17
 
 *    notice, this list of conditions and the following disclaimer in
18
 
 *    the documentation and/or other materials provided with the
19
 
 *    distribution.
20
 
 *
21
 
 * 3. The end-user documentation included with the redistribution,
22
 
 *    if any, must include the following acknowledgment:  
23
 
 *       "This product includes software developed by the
24
 
 *        Apache Software Foundation (http://www.apache.org/)."
25
 
 *    Alternately, this acknowledgment may appear in the software itself,
26
 
 *    if and wherever such third-party acknowledgments normally appear.
27
 
 *
28
 
 * 4. The names "Xerces" and "Apache Software Foundation" must
29
 
 *    not be used to endorse or promote products derived from this
30
 
 *    software without prior written permission. For written 
31
 
 *    permission, please contact apache@apache.org.
32
 
 *
33
 
 * 5. Products derived from this software may not be called "Apache",
34
 
 *    nor may "Apache" appear in their name, without prior written
35
 
 *    permission of the Apache Software Foundation.
36
 
 *
37
 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38
 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39
 
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40
 
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41
 
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42
 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43
 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44
 
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45
 
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46
 
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47
 
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48
 
 * SUCH DAMAGE.
49
 
 * ====================================================================
50
 
 *
51
 
 * This software consists of voluntary contributions made by many
52
 
 * individuals on behalf of the Apache Software Foundation and was
53
 
 * originally based on software copyright (c) 1999, Sun Microsystems, Inc., 
54
 
 * http://www.sun.com.  For more information on the Apache Software 
55
 
 * Foundation, please see <http://www.apache.org/>.
 
2
 * Copyright 2000-2002,2004-2006 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.
56
15
 */
57
16
 
58
 
 
59
17
package org.apache.xerces.jaxp;
60
18
 
61
19
import java.util.Hashtable;
62
20
 
 
21
import javax.xml.XMLConstants;
63
22
import javax.xml.parsers.ParserConfigurationException;
64
23
import javax.xml.parsers.SAXParser;
65
24
import javax.xml.parsers.SAXParserFactory;
 
25
import javax.xml.validation.Schema;
66
26
 
 
27
import org.apache.xerces.impl.Constants;
67
28
import org.xml.sax.SAXException;
68
29
import org.xml.sax.SAXNotRecognizedException;
69
30
import org.xml.sax.SAXNotSupportedException;
70
31
 
71
32
/**
72
 
 * @author Rajiv Mordani
73
 
 * @author Edwin Goei
74
 
 * @version $Id: SAXParserFactoryImpl.java,v 1.9 2003/05/08 20:11:58 elena Exp $
75
 
 */
76
 
 
77
 
/**
78
33
 * This is the implementation specific class for the
79
34
 * <code>javax.xml.parsers.SAXParserFactory</code>. This is the platform
80
35
 * default implementation for the platform.
 
36
 * 
 
37
 * @author Rajiv Mordani
 
38
 * @author Edwin Goei
 
39
 * 
 
40
 * @version $Id: SAXParserFactoryImpl.java 439017 2006-08-31 19:18:44Z mrglavas $
81
41
 */
82
42
public class SAXParserFactoryImpl extends SAXParserFactory {
 
43
    
 
44
    /** Feature identifier: namespaces. */
 
45
    private static final String NAMESPACES_FEATURE =
 
46
        Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
 
47
 
 
48
    /** Feature identifier: validation. */
 
49
    private static final String VALIDATION_FEATURE =
 
50
        Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
 
51
    
 
52
    /** Feature identifier: XInclude processing */
 
53
    private static final String XINCLUDE_FEATURE = 
 
54
        Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FEATURE;
 
55
    
83
56
    private Hashtable features;
 
57
    private Schema grammar;
 
58
    private boolean isXIncludeAware;
 
59
    
 
60
    /**
 
61
     * State of the secure processing feature, initially <code>false</code>
 
62
     */
 
63
    private boolean fSecureProcess = false;
84
64
 
85
65
    /**
86
66
     * Creates a new instance of <code>SAXParser</code> using the currently
88
68
     * @return javax.xml.parsers.SAXParser
89
69
     */
90
70
    public SAXParser newSAXParser()
91
 
        throws ParserConfigurationException
92
 
    {
 
71
        throws ParserConfigurationException {
 
72
        
93
73
        SAXParser saxParserImpl;
94
74
        try {
95
 
            saxParserImpl = new SAXParserImpl(this, features);
96
 
        } catch (SAXException se) {
 
75
            saxParserImpl = new SAXParserImpl(this, features, fSecureProcess);
 
76
        } 
 
77
        catch (SAXException se) {
97
78
            // Translate to ParserConfigurationException
98
79
            throw new ParserConfigurationException(se.getMessage());
99
80
        }
100
 
        return saxParserImpl;
 
81
        return saxParserImpl;
101
82
    }
102
83
 
103
84
    /**
105
86
     */
106
87
    private SAXParserImpl newSAXParserImpl()
107
88
        throws ParserConfigurationException, SAXNotRecognizedException, 
108
 
        SAXNotSupportedException
109
 
    {
 
89
        SAXNotSupportedException {
 
90
        
110
91
        SAXParserImpl saxParserImpl;
111
92
        try {
112
93
            saxParserImpl = new SAXParserImpl(this, features);
126
107
     */
127
108
    public void setFeature(String name, boolean value)
128
109
        throws ParserConfigurationException, SAXNotRecognizedException, 
129
 
                SAXNotSupportedException
130
 
    {
 
110
                SAXNotSupportedException {
 
111
        if (name == null) {
 
112
            throw new NullPointerException();
 
113
        }
 
114
        // If this is the secure processing feature, save it then return.
 
115
        if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
 
116
            fSecureProcess = value;
 
117
            return;
 
118
        }
 
119
        // Keep built-in settings in synch with the feature values.
 
120
        else if (name.equals(NAMESPACES_FEATURE)) {
 
121
            setNamespaceAware(value);
 
122
            return;
 
123
        }
 
124
        else if (name.equals(VALIDATION_FEATURE)) {
 
125
            setValidating(value);
 
126
            return;
 
127
        }
 
128
        else if (name.equals(XINCLUDE_FEATURE)) {
 
129
            setXIncludeAware(value);
 
130
            return;
 
131
        }
 
132
        
131
133
        // XXX This is ugly.  We have to collect the features and then
132
134
        // later create an XMLReader to verify the features.
133
135
        if (features == null) {
138
140
        // Test the feature by possibly throwing SAX exceptions
139
141
        try {
140
142
            newSAXParserImpl();
141
 
        } catch (SAXNotSupportedException e) {
 
143
        } 
 
144
        catch (SAXNotSupportedException e) {
142
145
            features.remove(name);
143
146
            throw e;
144
 
        } catch (SAXNotRecognizedException e) {
 
147
        } 
 
148
        catch (SAXNotRecognizedException e) {
145
149
            features.remove(name);
146
150
            throw e;
147
151
        }
153
157
     */
154
158
    public boolean getFeature(String name)
155
159
        throws ParserConfigurationException, SAXNotRecognizedException,
156
 
                SAXNotSupportedException
157
 
    {
 
160
                SAXNotSupportedException {
 
161
        if (name == null) {
 
162
            throw new NullPointerException();
 
163
        }
 
164
        if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
 
165
            return fSecureProcess;
 
166
        }
 
167
        else if (name.equals(NAMESPACES_FEATURE)) {
 
168
            return isNamespaceAware();
 
169
        }
 
170
        else if (name.equals(VALIDATION_FEATURE)) {
 
171
            return isValidating();
 
172
        }
 
173
        else if (name.equals(XINCLUDE_FEATURE)) {
 
174
            return isXIncludeAware();
 
175
        }
158
176
        // Check for valid name by creating a dummy XMLReader to get
159
177
        // feature value
160
178
        return newSAXParserImpl().getXMLReader().getFeature(name);
161
179
    }
 
180
    
 
181
    public Schema getSchema() {
 
182
        return grammar;
 
183
    }
 
184
 
 
185
    public void setSchema(Schema grammar) {
 
186
        this.grammar = grammar;
 
187
    }
 
188
 
 
189
    public boolean isXIncludeAware() {
 
190
        return this.isXIncludeAware;
 
191
    }
 
192
 
 
193
    public void setXIncludeAware(boolean state) {
 
194
        this.isXIncludeAware = state;
 
195
    }
162
196
}