jaxp/src/share/classes/javax/xml/parsers/SAXParserFactory.java
author jjg
Thu, 19 Jun 2008 15:52:31 -0700
changeset 811 687d51cb403b
parent 6 7f561c08de6b
permissions -rw-r--r--
6716866: some javac regression tests fail to compile with re-orged file manager Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 * have any questions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
package javax.xml.parsers;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import javax.xml.validation.Schema;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import org.xml.sax.SAXNotRecognizedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import org.xml.sax.SAXNotSupportedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * Defines a factory API that enables applications to configure and
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * obtain a SAX based parser to parse XML documents.
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * @author <a href="mailto:Neeraj.Bajaj@sun.com">Neeraj Bajaj</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
public abstract class SAXParserFactory {
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
    /** The default property name according to the JAXP spec */
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
    private static final String DEFAULT_PROPERTY_NAME = "javax.xml.parsers.SAXParserFactory";
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
     * <p>Should Parsers be validating?</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
    private boolean validating = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
     * <p>Should Parsers be namespace aware?</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    private boolean namespaceAware = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
     * <p>Protected constructor to force use of {@link #newInstance()}.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    protected SAXParserFactory () {
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     * Obtain a new instance of a <code>SAXParserFactory</code>. This
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
     * static method creates a new factory instance
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
     * This method uses the following ordered lookup procedure to determine
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
     * the <code>SAXParserFactory</code> implementation class to
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     * load:
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
     * <ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
     * <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     * Use the <code>javax.xml.parsers.SAXParserFactory</code> system
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
     * property.
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
     * </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
     * <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
     * Use the properties file "lib/jaxp.properties" in the JRE directory.
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
     * This configuration file is in standard <code>java.util.Properties
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
     * </code> format and contains the fully qualified name of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     * implementation class with the key being the system property defined
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
     * above.
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
     * The jaxp.properties file is read only once by the JAXP implementation
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     * and it's values are then cached for future use.  If the file does not exist
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     * when the first attempt is made to read from it, no further attempts are
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
     * made to check for its existence.  It is not possible to change the value
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
     * of any property in jaxp.properties after it has been read for the first time.
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
     * </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     * <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
     * Use the Services API (as detailed in the JAR specification), if
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
     * available, to determine the classname. The Services API will look
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
     * for a classname in the file
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
     * <code>META-INF/services/javax.xml.parsers.SAXParserFactory</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
     * in jars available to the runtime.
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
     * </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
     * <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
     * Platform default <code>SAXParserFactory</code> instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
     * </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
     * </ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
     * Once an application has obtained a reference to a
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
     * <code>SAXParserFactory</code> it can use the factory to
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
     * configure and obtain parser instances.
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
     * <h2>Tip for Trouble-shooting</h2>
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
     * <p>Setting the <code>jaxp.debug</code> system property will cause
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
     * this method to print a lot of debug messages
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
     * to <code>System.err</code> about what it is doing and where it is looking at.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
     * <p> If you have problems loading {@link DocumentBuilder}s, try:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
     * java -Djaxp.debug=1 YourProgram ....
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
     * @return A new instance of a SAXParserFactory.
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
     * @throws FactoryConfigurationError if the implementation is
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
     *   not available or cannot be instantiated.
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    public static SAXParserFactory newInstance() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
            return (SAXParserFactory) FactoryFinder.find(
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
                /* The default property name according to the JAXP spec */
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
                "javax.xml.parsers.SAXParserFactory",
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
                /* The fallback implementation class name */
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
                "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
        } catch (FactoryFinder.ConfigurationError e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            throw new FactoryConfigurationError(e.getException(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                                                e.getMessage());
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     * <p>Obtain a new instance of a <code>SAXParserFactory</code> from class name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     * This function is useful when there are multiple providers in the classpath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     * It gives more control to the application as it can specify which provider
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     * should be loaded.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
     * <p>Once an application has obtained a reference to a <code>SAXParserFactory</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
     * it can use the factory to configure and obtain parser instances.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
     * <h2>Tip for Trouble-shooting</h2>
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     * <p>Setting the <code>jaxp.debug</code> system property will cause
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     * this method to print a lot of debug messages
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
     * to <code>System.err</code> about what it is doing and where it is looking at.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     * <p> If you have problems, try:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     * java -Djaxp.debug=1 YourProgram ....
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
     * @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.parsers.SAXParserFactory</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
     * @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     *                     current <code>Thread</code>'s context classLoader is used to load the factory class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
     * @return New instance of a <code>SAXParserFactory</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
     * @throws FactoryConfigurationError if <code>factoryClassName</code> is <code>null</code>, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     *                                   the factory class cannot be loaded, instantiated.
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     * @see #newInstance()
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     * @since 1.6
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
    public static SAXParserFactory newInstance(String factoryClassName, ClassLoader classLoader){
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
            //do not fallback if given classloader can't find the class, throw exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
            return (SAXParserFactory) FactoryFinder.newInstance(factoryClassName, classLoader, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
        } catch (FactoryFinder.ConfigurationError e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
            throw new FactoryConfigurationError(e.getException(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
                                                e.getMessage());
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
     * <p>Creates a new instance of a SAXParser using the currently
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
     * configured factory parameters.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
     * @return A new instance of a SAXParser.
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
     * @throws ParserConfigurationException if a parser cannot
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     *   be created which satisfies the requested configuration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     * @throws SAXException for SAX errors.
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    public abstract SAXParser newSAXParser()
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
        throws ParserConfigurationException, SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
     * Specifies that the parser produced by this code will
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
     * provide support for XML namespaces. By default the value of this is set
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
     * to <code>false</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
     * @param awareness true if the parser produced by this code will
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     *                  provide support for XML namespaces; false otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    public void setNamespaceAware(boolean awareness) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
        this.namespaceAware = awareness;
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
     * Specifies that the parser produced by this code will
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
     * validate documents as they are parsed. By default the value of this is
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
     * set to <code>false</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
     * Note that "the validation" here means
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
     * <a href="http://www.w3.org/TR/REC-xml#proc-types">a validating
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
     * parser</a> as defined in the XML recommendation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
     * In other words, it essentially just controls the DTD validation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
     * (except the legacy two properties defined in JAXP 1.2.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
     * </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
     * To use modern schema languages such as W3C XML Schema or
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
     * RELAX NG instead of DTD, you can configure your parser to be
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
     * a non-validating parser by leaving the {@link #setValidating(boolean)}
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
     * method <code>false</code>, then use the {@link #setSchema(Schema)}
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
     * method to associate a schema to a parser.
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
     * </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
     * @param validating true if the parser produced by this code will
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
     *                   validate documents as they are parsed; false otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    public void setValidating(boolean validating) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        this.validating = validating;
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
     * Indicates whether or not the factory is configured to produce
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
     * parsers which are namespace aware.
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
     * @return true if the factory is configured to produce
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
     *         parsers which are namespace aware; false otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
    public boolean isNamespaceAware() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
        return namespaceAware;
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     * Indicates whether or not the factory is configured to produce
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
     * parsers which validate the XML content during parse.
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
     * @return true if the factory is configured to produce parsers which validate
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
     *         the XML content during parse; false otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
    public boolean isValidating() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
        return validating;
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
     * <p>Sets the particular feature in the underlying implementation of
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
     * org.xml.sax.XMLReader.
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
     * A list of the core features and properties can be found at
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
     * <a href="http://www.saxproject.org/">http://www.saxproject.org/</a></p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
         * <p>All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
         * When the feature is</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
         * <ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
         *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
         *     <code>true</code>: the implementation will limit XML processing to conform to implementation limits.
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
         *     Examples include enity expansion limits and XML Schema constructs that would consume large amounts of resources.
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
         *     If XML processing is limited for security reasons, it will be reported via a call to the registered
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
         *     {@link org.xml.sax.ErrorHandler#fatalError(SAXParseException exception)}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
         *     See {@link SAXParser} <code>parse</code> methods for handler specification.
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
         *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
         *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
         *     When the feature is <code>false</code>, the implementation will processing XML according to the XML specifications without
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
         *     regard to possible implementation limits.
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
         *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
         * </ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
     * @param name The name of the feature to be set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
     * @param value The value of the feature to be set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
     * @throws ParserConfigurationException if a parser cannot
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
     *     be created which satisfies the requested configuration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
     * @throws SAXNotRecognizedException When the underlying XMLReader does
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
     *            not recognize the property name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
     * @throws SAXNotSupportedException When the underlying XMLReader
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
     *            recognizes the property name but doesn't support the
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
     *            property.
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
     * @throws NullPointerException If the <code>name</code> parameter is null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
     * @see org.xml.sax.XMLReader#setFeature
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    public abstract void setFeature(String name, boolean value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        throws ParserConfigurationException, SAXNotRecognizedException,
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
                SAXNotSupportedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
     * <p>Returns the particular property requested for in the underlying
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
     * implementation of org.xml.sax.XMLReader.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
     * @param name The name of the property to be retrieved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
     * @return Value of the requested property.
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
     * @throws ParserConfigurationException if a parser cannot be created which satisfies the requested configuration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
     * @throws SAXNotRecognizedException When the underlying XMLReader does not recognize the property name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
     * @throws SAXNotSupportedException When the underlying XMLReader recognizes the property name but doesn't support the property.
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
     * @see org.xml.sax.XMLReader#getProperty
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
    public abstract boolean getFeature(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
        throws ParserConfigurationException, SAXNotRecognizedException,
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
                SAXNotSupportedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
    /* <p>Get current state of canonicalization.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
     * @return current state canonicalization control
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    public boolean getCanonicalization() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
        return canonicalState;
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
     * Gets the {@link Schema} object specified through
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
     * the {@link #setSchema(Schema schema)} method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
     * @throws UnsupportedOperationException When implementation does not
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
     *   override this method
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
     * @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
     *      the {@link Schema} object that was last set through
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
     *      the {@link #setSchema(Schema)} method, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
     *      if the method was not invoked since a {@link SAXParserFactory}
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
     *      is created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
     * @since 1.5
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
    public Schema getSchema() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
        throw new UnsupportedOperationException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
            "This parser does not support specification \""
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
            + this.getClass().getPackage().getSpecificationTitle()
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
            + "\" version \""
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
            + this.getClass().getPackage().getSpecificationVersion()
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
            + "\""
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
            );
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
    /** <p>Set canonicalization control to <code>true</code> or
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
     * </code>false</code>.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     * @param state of canonicalization
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
    public void setCanonicalization(boolean state) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
        canonicalState = state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
     * <p>Set the {@link Schema} to be used by parsers created
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
     * from this factory.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
     * <p>When a {@link Schema} is non-null, a parser will use a validator
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
     * created from it to validate documents before it passes information
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
     * down to the application.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
     * <p>When warnings/errors/fatal errors are found by the validator, the parser must
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
     * handle them as if those errors were found by the parser itself.
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
     * In other words, if the user-specified {@link org.xml.sax.ErrorHandler}
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
     * is set, it must receive those errors, and if not, they must be
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
     * treated according to the implementation specific
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
     * default error handling rules.
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
     * <p>A validator may modify the SAX event stream (for example by
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
     * adding default values that were missing in documents), and a parser
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
     * is responsible to make sure that the application will receive
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
     * those modified event stream.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
     * <p>Initialy, <code>null</code> is set as the {@link Schema}.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
     * <p>This processing will take effect even if
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
     * the {@link #isValidating()} method returns <code>false</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
     * <p>It is an error to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
     * the <code>http://java.sun.com/xml/jaxp/properties/schemaSource</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
     * property and/or the <code>http://java.sun.com/xml/jaxp/properties/schemaLanguage</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
     * property in conjunction with a non-null {@link Schema} object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
     * Such configuration will cause a {@link SAXException}
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
     * exception when those properties are set on a {@link SAXParser}.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
     * <h4>Note for implmentors</h4>
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
     * A parser must be able to work with any {@link Schema}
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
     * implementation. However, parsers and schemas are allowed
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
     * to use implementation-specific custom mechanisms
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
     * as long as they yield the result described in the specification.
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
     * </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
     * @param schema <code>Schema</code> to use, <code>null</code> to remove a schema.
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
     * @throws UnsupportedOperationException When implementation does not
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
     *   override this method
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
     * @since 1.5
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
    public void setSchema(Schema schema) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
        throw new UnsupportedOperationException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
            "This parser does not support specification \""
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
            + this.getClass().getPackage().getSpecificationTitle()
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
            + "\" version \""
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
            + this.getClass().getPackage().getSpecificationVersion()
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
            + "\""
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
            );
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
     * <p>Set state of XInclude processing.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
     * <p>If XInclude markup is found in the document instance, should it be
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
     * processed as specified in <a href="http://www.w3.org/TR/xinclude/">
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
     * XML Inclusions (XInclude) Version 1.0</a>.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
     * <p>XInclude processing defaults to <code>false</code>.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
     * @param state Set XInclude processing to <code>true</code> or
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
     *   <code>false</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
     * @throws UnsupportedOperationException When implementation does not
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
     *   override this method
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
     * @since 1.5
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
    public void setXIncludeAware(final boolean state) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
        throw new UnsupportedOperationException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
            "This parser does not support specification \""
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
            + this.getClass().getPackage().getSpecificationTitle()
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
            + "\" version \""
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
            + this.getClass().getPackage().getSpecificationVersion()
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
            + "\""
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
            );
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
     * <p>Get state of XInclude processing.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
     * @return current state of XInclude processing
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
     * @throws UnsupportedOperationException When implementation does not
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
     *   override this method
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
     * @since 1.5
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
    public boolean isXIncludeAware() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
        throw new UnsupportedOperationException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
            "This parser does not support specification \""
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
            + this.getClass().getPackage().getSpecificationTitle()
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
            + "\" version \""
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
            + this.getClass().getPackage().getSpecificationVersion()
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
            + "\""
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
            );
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
}