1adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/* 2320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one or more 3320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * contributor license agreements. See the NOTICE file distributed with 4320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * this work for additional information regarding copyright ownership. 5320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The ASF licenses this file to You under the Apache License, Version 2.0 6320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * (the "License"); you may not use this file except in compliance with 7320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the License. You may obtain a copy of the License at 8adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * 9320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 10adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * 11adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software 12adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 13adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * See the License for the specific language governing permissions and 15adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * limitations under the License. 16adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 17adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 18320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson// $Id: SAXParser.java 584483 2007-10-14 02:54:48Z mrglavas $ 19320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 20adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectpackage javax.xml.parsers; 21adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 22320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilsonimport java.io.File; 23320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilsonimport java.io.IOException; 24320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilsonimport java.io.InputStream; 25320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilsonimport javax.xml.validation.Schema; 26adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.xml.sax.HandlerBase; 27adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.xml.sax.InputSource; 28adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.xml.sax.Parser; 29adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.xml.sax.SAXException; 30adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.xml.sax.SAXNotRecognizedException; 31adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.xml.sax.SAXNotSupportedException; 32adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.xml.sax.XMLReader; 33adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.xml.sax.helpers.DefaultHandler; 34adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 35adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 36adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/** 37320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Defines the API that wraps an {@link org.xml.sax.XMLReader} 38320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * implementation class. In JAXP 1.0, this class wrapped the 39320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link org.xml.sax.Parser} interface, however this interface was 40320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * replaced by the {@link org.xml.sax.XMLReader}. For ease 41320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * of transition, this class continues to support the same name 42320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * and interface as well as supporting new methods. 43320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 44320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * An instance of this class can be obtained from the 45320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link javax.xml.parsers.SAXParserFactory#newSAXParser()} method. 46320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Once an instance of this class is obtained, XML can be parsed from 47320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * a variety of input sources. These input sources are InputStreams, 48320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Files, URLs, and SAX InputSources.<p> 49320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 50320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * This static method creates a new factory instance based 51320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * on a system property setting or uses the platform default 52320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * if no property has been defined.<p> 53320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 54320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The system property that controls which Factory implementation 55320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * to create is named <code>"javax.xml.parsers.SAXParserFactory"</code>. 56320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * This property names a class that is a concrete subclass of this 57320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * abstract class. If no property is defined, a platform default 58320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * will be used.</p> 59320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 60320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * As the content is parsed by the underlying parser, methods of the 61320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * given {@link org.xml.sax.HandlerBase} or the 62320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link org.xml.sax.helpers.DefaultHandler} are called.<p> 63320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 6481bcd5c1f677de9c79155c87bcfbfc5896920403Jesse Wilson * Implementations of this class which wrap an underlying implementation 65320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * can consider using the {@link org.xml.sax.helpers.ParserAdapter} 66320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * class to initially adapt their SAX1 implementation to work under 67320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * this revised class. 68320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 69320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a> 70320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @version $Revision: 584483 $, $Date: 2007-10-13 19:54:48 -0700 (Sat, 13 Oct 2007) $ 71adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 72320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilsonpublic abstract class SAXParser { 73f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 74320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson private static final boolean DEBUG = false; 75f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 76adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 77320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p>Protected constructor to prevent instantiation. 78320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Use {@link javax.xml.parsers.SAXParserFactory#newSAXParser()}.</p> 79adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 80320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson protected SAXParser () { 81f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 82adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 83adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 84d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes /** 85d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes * <p>Reset this <code>SAXParser</code> to its original configuration.</p> 86f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 87d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes * <p><code>SAXParser</code> is reset to the same state as when it was created with 88d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes * {@link SAXParserFactory#newSAXParser()}. 89d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes * <code>reset()</code> is designed to allow the reuse of existing <code>SAXParser</code>s 90d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes * thus saving resources associated with the creation of new <code>SAXParser</code>s.</p> 91f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 92d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes * <p>The reset <code>SAXParser</code> is not guaranteed to have the same {@link Schema} 93d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes * <code>Object</code>, e.g. {@link Object#equals(Object obj)}. It is guaranteed to have a functionally equal 94d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes * <code>Schema</code>.</p> 95f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 96d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes * @since 1.5 97d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes */ 98d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes public void reset() { 99adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 100d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes // implementors should override this method 101d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes throw new UnsupportedOperationException( 102d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes "This SAXParser, \"" + this.getClass().getName() + "\", does not support the reset functionality." 103d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes + " Specification \"" + this.getClass().getPackage().getSpecificationTitle() + "\"" 104d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes + " version \"" + this.getClass().getPackage().getSpecificationVersion() + "\"" 105d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes ); 106d21d78fd49a2d798218e8c8aefbddb26a0e71bbbElliott Hughes } 107adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 108adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 109320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p>Parse the content of the given {@link java.io.InputStream} 110320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * instance as XML using the specified {@link org.xml.sax.HandlerBase}. 111320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <i> Use of the DefaultHandler version of this method is recommended as 112320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the HandlerBase class has been deprecated in SAX 2.0</i>.</p> 113320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 114320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param is InputStream containing the content to be parsed. 115320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param hb The SAX HandlerBase to use. 116f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 117320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the given InputStream is null. 118320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If parse produces a SAX error. 119320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If an IO error occurs interacting with the 120320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>InputStream</code>. 121f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 122320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler 123f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes */ 124320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse(InputStream is, HandlerBase hb) 125320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 126320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (is == null) { 127320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("InputStream cannot be null"); 128320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson } 129adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 130320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputSource input = new InputSource(is); 131320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson this.parse(input, hb); 132320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson } 133adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 134adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 135320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p>Parse the content of the given {@link java.io.InputStream} 136320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * instance as XML using the specified {@link org.xml.sax.HandlerBase}. 137320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <i> Use of the DefaultHandler version of this method is recommended as 138320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the HandlerBase class has been deprecated in SAX 2.0</i>.</p> 139320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 140320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param is InputStream containing the content to be parsed. 141320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param hb The SAX HandlerBase to use. 142320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param systemId The systemId which is needed for resolving relative URIs. 143f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 144320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the given <code>InputStream</code> is 145320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>null</code>. 146320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If any IO error occurs interacting with the 147320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <code>InputStream</code>. 148320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 149f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 150320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler version of this method instead. 151adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 152320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse( 153320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputStream is, 154320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson HandlerBase hb, 155320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson String systemId) 156320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 157320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (is == null) { 158320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("InputStream cannot be null"); 159320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson } 160adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 161320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputSource input = new InputSource(is); 162320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson input.setSystemId(systemId); 163320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson this.parse(input, hb); 164adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 165f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 166adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 167320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Parse the content of the given {@link java.io.InputStream} 168320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * instance as XML using the specified 169320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link org.xml.sax.helpers.DefaultHandler}. 170320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 171320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param is InputStream containing the content to be parsed. 172320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param dh The SAX DefaultHandler to use. 173f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 174320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the given InputStream is null. 175320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If any IO errors occur. 176320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 177f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 178320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler 179adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 180320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse(InputStream is, DefaultHandler dh) 181320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 182320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (is == null) { 183320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("InputStream cannot be null"); 184adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 185320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 186320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputSource input = new InputSource(is); 187320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson this.parse(input, dh); 188adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 189adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 190adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 191320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Parse the content of the given {@link java.io.InputStream} 192320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * instance as XML using the specified 193320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link org.xml.sax.helpers.DefaultHandler}. 194320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 195320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param is InputStream containing the content to be parsed. 196320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param dh The SAX DefaultHandler to use. 197320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param systemId The systemId which is needed for resolving relative URIs. 198f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 199320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the given InputStream is null. 200320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If any IO errors occur. 201320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 202f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 203320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler version of this method instead. 204adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 205320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse( 206320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputStream is, 207320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson DefaultHandler dh, 208320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson String systemId) 209320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 210320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (is == null) { 211320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("InputStream cannot be null"); 212adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 213320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 214320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputSource input = new InputSource(is); 215320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson input.setSystemId(systemId); 216320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson this.parse(input, dh); 217adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 218adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 219adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 220320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Parse the content described by the giving Uniform Resource 221320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Identifier (URI) as XML using the specified 222320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link org.xml.sax.HandlerBase}. 223320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <i> Use of the DefaultHandler version of this method is recommended as 224320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the <code>HandlerBase</code> class has been deprecated in SAX 2.0</i> 225320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 226320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param uri The location of the content to be parsed. 227320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param hb The SAX HandlerBase to use. 228f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 229320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the uri is null. 230320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If any IO errors occur. 231320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 232f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 233320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler 234adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 235320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse(String uri, HandlerBase hb) 236320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 237320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (uri == null) { 238320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("uri cannot be null"); 239adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 240320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 241320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputSource input = new InputSource(uri); 242320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson this.parse(input, hb); 243adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 244f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 245320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 246320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Parse the content described by the giving Uniform Resource 247320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Identifier (URI) as XML using the specified 248320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link org.xml.sax.helpers.DefaultHandler}. 249320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 250320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param uri The location of the content to be parsed. 251320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param dh The SAX DefaultHandler to use. 252f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 253320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the uri is null. 254320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If any IO errors occur. 255320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 256f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 257320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler 258f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes */ 259320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse(String uri, DefaultHandler dh) 260320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 261320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (uri == null) { 262320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("uri cannot be null"); 263320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson } 264adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 265320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputSource input = new InputSource(uri); 266320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson this.parse(input, dh); 267320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson } 268f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 269adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 270320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Parse the content of the file specified as XML using the 271320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * specified {@link org.xml.sax.HandlerBase}. 272320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <i> Use of the DefaultHandler version of this method is recommended as 273320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the HandlerBase class has been deprecated in SAX 2.0</i> 274320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 275320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param f The file containing the XML to parse 276320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param hb The SAX HandlerBase to use. 277f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 278320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the File object is null. 279320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If any IO errors occur. 280320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 281f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 282320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler 283adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 284320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse(File f, HandlerBase hb) 285320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 286320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (f == null) { 287320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("File cannot be null"); 288adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 289f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 290320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson String escapedURI = FilePathToURI.filepath2URI(f.getAbsolutePath()); 291320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 292320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (DEBUG) { 293320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson System.out.println("Escaped URI = " + escapedURI); 294adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 295adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 296320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputSource input = new InputSource(escapedURI); 297320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson this.parse(input, hb); 298adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 299f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 300adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 301320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Parse the content of the file specified as XML using the 302320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * specified {@link org.xml.sax.helpers.DefaultHandler}. 303320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 304320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param f The file containing the XML to parse 305320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param dh The SAX DefaultHandler to use. 306f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 307320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the File object is null. 308320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If any IO errors occur. 309320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 310f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 311320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler 312adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 313320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse(File f, DefaultHandler dh) 314320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 315320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (f == null) { 316320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("File cannot be null"); 317adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 318f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 319320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson String escapedURI = FilePathToURI.filepath2URI(f.getAbsolutePath()); 320320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 321320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (DEBUG) { 322320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson System.out.println("Escaped URI = " + escapedURI); 323adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 324adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 325320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson InputSource input = new InputSource(escapedURI); 326320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson this.parse(input, dh); 327320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson } 328f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 329adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 330320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Parse the content given {@link org.xml.sax.InputSource} 331320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * as XML using the specified 332320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link org.xml.sax.HandlerBase}. 333320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <i> Use of the DefaultHandler version of this method is recommended as 334320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the HandlerBase class has been deprecated in SAX 2.0</i> 335320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 336320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param is The InputSource containing the content to be parsed. 337320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param hb The SAX HandlerBase to use. 338f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 339320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the <code>InputSource</code> object 340320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * is <code>null</code>. 341320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If any IO errors occur. 342320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 343f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 344320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler 345adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 346320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse(InputSource is, HandlerBase hb) 347320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 348320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (is == null) { 349320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("InputSource cannot be null"); 350adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 351adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 352320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson Parser parser = this.getParser(); 353320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (hb != null) { 354320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson parser.setDocumentHandler(hb); 355320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson parser.setEntityResolver(hb); 356320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson parser.setErrorHandler(hb); 357320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson parser.setDTDHandler(hb); 358adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 359320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson parser.parse(is); 360adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 361f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 362adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 363320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Parse the content given {@link org.xml.sax.InputSource} 364320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * as XML using the specified 365320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link org.xml.sax.helpers.DefaultHandler}. 366320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 367320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param is The InputSource containing the content to be parsed. 368320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param dh The SAX DefaultHandler to use. 369f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 370320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalArgumentException If the <code>InputSource</code> object 371320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * is <code>null</code>. 372320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IOException If any IO errors occur. 373320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 374f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 375320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.DocumentHandler 376adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 377320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public void parse(InputSource is, DefaultHandler dh) 378320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXException, IOException { 379320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (is == null) { 380320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new IllegalArgumentException("InputSource cannot be null"); 381adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 382adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 383320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson XMLReader reader = this.getXMLReader(); 384320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson if (dh != null) { 385320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson reader.setContentHandler(dh); 386320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson reader.setEntityResolver(dh); 387320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson reader.setErrorHandler(dh); 388320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson reader.setDTDHandler(dh); 389adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 390320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson reader.parse(is); 391adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 392f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 393adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 394320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Returns the SAX parser that is encapsulated by the 395320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * implementation of this class. 396320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 397320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return The SAX parser that is encapsulated by the 398320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * implementation of this class. 399f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 400320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 401320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 402320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract org.xml.sax.Parser getParser() throws SAXException; 403320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 404320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 405320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Returns the {@link org.xml.sax.XMLReader} that is encapsulated by the 406320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * implementation of this class. 407320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 408320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return The XMLReader that is encapsulated by the 409320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * implementation of this class. 410f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 411320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXException If any SAX errors occur during processing. 412adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 413adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 414320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract org.xml.sax.XMLReader getXMLReader() throws SAXException; 415f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 416320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 417320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Indicates whether or not this parser is configured to 418320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * understand namespaces. 419320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 420320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return true if this parser is configured to 421320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * understand namespaces; false otherwise. 422320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 423f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 424320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract boolean isNamespaceAware(); 425adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 426320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 427320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Indicates whether or not this parser is configured to 428320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * validate XML documents. 429320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 430320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return true if this parser is configured to 431320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * validate XML documents; false otherwise. 432320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 433f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 434320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract boolean isValidating(); 435adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 436adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 437320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p>Sets the particular property in the underlying implementation of 438320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link org.xml.sax.XMLReader}. 439320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * A list of the core features and properties can be found at 440320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <a href="http://sax.sourceforge.net/?selected=get-set"> 441320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * http://sax.sourceforge.net/?selected=get-set</a>.</p> 442320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 443320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param name The name of the property to be set. 444320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param value The value of the property to be set. 445f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 446320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXNotRecognizedException When the underlying XMLReader does 447320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * not recognize the property name. 448320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXNotSupportedException When the underlying XMLReader 449320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * recognizes the property name but doesn't support the property. 450320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 451320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.XMLReader#setProperty 452adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 453320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract void setProperty(String name, Object value) 454320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXNotRecognizedException, SAXNotSupportedException; 455adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 456adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project /** 457320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p>Returns the particular property requested for in the underlying 458320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * implementation of {@link org.xml.sax.XMLReader}.</p> 459320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 460320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param name The name of the property to be retrieved. 461320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return Value of the requested property. 462320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 463320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXNotRecognizedException When the underlying XMLReader does 464320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * not recognize the property name. 465320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws SAXNotSupportedException When the underlying XMLReader 466320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * recognizes the property name but doesn't support the property. 467320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 468320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see org.xml.sax.XMLReader#getProperty 469320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 470320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract Object getProperty(String name) 471320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throws SAXNotRecognizedException, SAXNotSupportedException; 472320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 473320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** <p>Get a reference to the the {@link Schema} being used by 474320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the XML processor.</p> 475320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 476320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p>If no schema is being used, <code>null</code> is returned.</p> 477320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 478320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return {@link Schema} being used or <code>null</code> 479320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * if none in use 480f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 481320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws UnsupportedOperationException 482320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * For backward compatibility, when implementations for 483320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * earlier versions of JAXP is used, this exception will be 484320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * thrown. 485f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 486320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @since 1.5 487320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 488320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public Schema getSchema() { 489320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new UnsupportedOperationException( 490320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson "This parser does not support specification \"" 491320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson + this.getClass().getPackage().getSpecificationTitle() 492320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson + "\" version \"" 493320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson + this.getClass().getPackage().getSpecificationVersion() 494320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson + "\"" 495320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson ); 496320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson } 497f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 498320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 499320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p>Get the XInclude processing mode for this parser.</p> 500f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 501320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return 502320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the return value of 503320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the {@link SAXParserFactory#isXIncludeAware()} 504320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * when this parser was created from factory. 505f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 506320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws UnsupportedOperationException 507320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * For backward compatibility, when implementations for 508320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * earlier versions of JAXP is used, this exception will be 509320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * thrown. 510f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 511320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @since 1.5 512f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 513320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @see SAXParserFactory#setXIncludeAware(boolean) 514adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */ 515320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public boolean isXIncludeAware() { 516320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson throw new UnsupportedOperationException( 517320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson "This parser does not support specification \"" 518320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson + this.getClass().getPackage().getSpecificationTitle() 519320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson + "\" version \"" 520320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson + this.getClass().getPackage().getSpecificationVersion() 521320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson + "\"" 522320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson ); 523320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson } 524adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project} 525