diff -Nru gshell-2.6.5/gshell-util/pom.xml gshell-2.6.5-gil/gshell-util/pom.xml --- gshell-2.6.5/gshell-util/pom.xml 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/pom.xml 2012-06-20 02:10:24.262974280 +0200 @@ -62,6 +62,12 @@ </dependency> <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/ReaderFactory.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/ReaderFactory.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/ReaderFactory.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/ReaderFactory.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,221 +0,0 @@ -package org.codehaus.plexus.util; - -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.nio.charset.Charset; - -import org.codehaus.plexus.util.xml.XmlStreamReader; - -/** - * Utility to create Readers from streams, with explicit encoding choice: platform default, - * XML, or specified. - * - * @author <a href="mailto:hboutemy@codehaus.org">Herve Boutemy</a> - * @see Charset - * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a> - * @version $Id: ReaderFactory.java 8010 2009-01-07 12:59:50Z vsiveton $ - * @since 1.4.3 - */ -@Deprecated -public class ReaderFactory -{ - /** - * ISO Latin Alphabet #1, also known as ISO-LATIN-1. - * Every implementation of the Java platform is required to support this character encoding. - * @see Charset - */ - public static final String ISO_8859_1 = "ISO-8859-1"; - - /** - * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set. - * Every implementation of the Java platform is required to support this character encoding. - * @see Charset - */ - public static final String US_ASCII = "US-ASCII"; - - /** - * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either - * order accepted on input, big-endian used on output). - * Every implementation of the Java platform is required to support this character encoding. - * @see Charset - */ - public static final String UTF_16 = "UTF-16"; - - /** - * Sixteen-bit Unicode Transformation Format, big-endian byte order. - * Every implementation of the Java platform is required to support this character encoding. - * @see Charset - */ - public static final String UTF_16BE = "UTF-16BE"; - - /** - * Sixteen-bit Unicode Transformation Format, little-endian byte order. - * Every implementation of the Java platform is required to support this character encoding. - * @see Charset - */ - public static final String UTF_16LE = "UTF-16LE"; - - /** - * Eight-bit Unicode Transformation Format. - * Every implementation of the Java platform is required to support this character encoding. - * @see Charset - */ - public static final String UTF_8 = "UTF-8"; - - /** - * The <code>file.encoding</code> System Property. - */ - public static final String FILE_ENCODING = System.getProperty( "file.encoding" ); - - /** - * Create a new Reader with XML encoding detection rules. - * - * @param in not null input stream. - * @return an XML reader instance for the input stream. - * @throws IOException if any. - * @see XmlStreamReader - */ - public static XmlStreamReader newXmlReader( InputStream in ) - throws IOException - { - return new XmlStreamReader( in ); - } - - /** - * Create a new Reader with XML encoding detection rules. - * - * @param file not null file. - * @return an XML reader instance for the input file. - * @throws IOException if any. - * @see XmlStreamReader - */ - public static XmlStreamReader newXmlReader( File file ) - throws IOException - { - return new XmlStreamReader( file ); - } - - /** - * Create a new Reader with XML encoding detection rules. - * - * @param url not null url. - * @return an XML reader instance for the input url. - * @throws IOException if any. - * @see XmlStreamReader - */ - public static XmlStreamReader newXmlReader( URL url ) - throws IOException - { - return new XmlStreamReader( url ); - } - - /** - * Create a new Reader with default plaform encoding. - * - * @param in not null input stream. - * @return a reader instance for the input stream using the default platform charset. - * @see Charset#defaultCharset() - */ - public static Reader newPlatformReader( InputStream in ) - { - return new InputStreamReader( in ); - } - - /** - * Create a new Reader with default plaform encoding. - * - * @param file not null file. - * @return a reader instance for the input file using the default platform charset. - * @throws FileNotFoundException if any. - * @see Charset#defaultCharset() - */ - public static Reader newPlatformReader( File file ) - throws FileNotFoundException - { - return new FileReader( file ); - } - - /** - * Create a new Reader with default plaform encoding. - * - * @param url not null url. - * @return a reader instance for the input url using the default platform charset. - * @throws IOException if any. - * @see Charset#defaultCharset() - */ - public static Reader newPlatformReader( URL url ) - throws IOException - { - return new InputStreamReader( url.openStream() ); - } - - /** - * Create a new Reader with specified encoding. - * - * @param in not null input stream. - * @param encoding not null supported encoding. - * @return a reader instance for the input stream using the given encoding. - * @throws UnsupportedEncodingException if any. - * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a> - */ - public static Reader newReader( InputStream in, String encoding ) - throws UnsupportedEncodingException - { - return new InputStreamReader( in, encoding ); - } - - /** - * Create a new Reader with specified encoding. - * - * @param file not null file. - * @param encoding not null supported encoding. - * @return a reader instance for the input file using the given encoding. - * @throws FileNotFoundException if any. - * @throws UnsupportedEncodingException if any. - * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a> - */ - public static Reader newReader( File file, String encoding ) - throws FileNotFoundException, UnsupportedEncodingException - { - return new InputStreamReader( new FileInputStream(file), encoding ); - } - - /** - * Create a new Reader with specified encoding. - * - * @param url not null url. - * @param encoding not null supported encoding. - * @return a reader instance for the input url using the given encoding. - * @throws IOException if any. - * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a> - */ - public static Reader newReader( URL url, String encoding ) - throws IOException - { - return new InputStreamReader( url.openStream(), encoding ); - } -} diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,3375 +0,0 @@ -/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/ -/* - * Copyright (c) 2003 Extreme! Lab, Indiana University. All rights reserved. - * - * This software is open source. See the bottom of this file for the licence. - * - * $Id: MXParser.java 8238 2009-05-28 23:51:31Z vsiveton $ - */ - -package org.codehaus.plexus.util.xml.pull; - -import java.io.EOFException; -import java.io.IOException; -import java.io.Reader; -import java.io.UnsupportedEncodingException; - -import org.codehaus.plexus.util.ReaderFactory; - -//import java.util.Hashtable; - -//TODO best handling of interning issues -// have isAllNewStringInterned ??? - -//TODO handling surrogate pairs: http://www.unicode.org/unicode/faq/utf_bom.html#6 - -//TODO review code for use of bufAbsoluteStart when keeping pos between next()/fillBuf() - -/** - * Absolutely minimal implementation of XMLPULL V1 API. Encoding handling done with XmlReader - * - * @see org.codehaus.plexus.util.xml.XmlReader - * @author <a href="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a> - */ -@Deprecated -public class MXParser - implements XmlPullParser -{ - //NOTE: no interning of those strings --> by Java leng spec they MUST be already interned - protected final static String XML_URI = "http://www.w3.org/XML/1998/namespace"; - protected final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; - protected final static String FEATURE_XML_ROUNDTRIP= - //"http://xmlpull.org/v1/doc/features.html#xml-roundtrip"; - "http://xmlpull.org/v1/doc/features.html#xml-roundtrip"; - protected final static String FEATURE_NAMES_INTERNED = - "http://xmlpull.org/v1/doc/features.html#names-interned"; - protected final static String PROPERTY_XMLDECL_VERSION = - "http://xmlpull.org/v1/doc/properties.html#xmldecl-version"; - protected final static String PROPERTY_XMLDECL_STANDALONE = - "http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone"; - protected final static String PROPERTY_XMLDECL_CONTENT = - "http://xmlpull.org/v1/doc/properties.html#xmldecl-content"; - protected final static String PROPERTY_LOCATION = - "http://xmlpull.org/v1/doc/properties.html#location"; - - /** - * Implementation notice: - * the is instance variable that controls if newString() is interning. - * <p><b>NOTE:</b> newStringIntern <b>always</b> returns interned strings - * and newString MAY return interned String depending on this variable. - * <p><b>NOTE:</b> by default in this minimal implementation it is false! - */ - protected boolean allStringsInterned; - - protected void resetStringCache() { - //System.out.println("resetStringCache() minimum called"); - } - - protected String newString(char[] cbuf, int off, int len) { - return new String(cbuf, off, len); - } - - protected String newStringIntern(char[] cbuf, int off, int len) { - return (new String(cbuf, off, len)).intern(); - } - - private static final boolean TRACE_SIZING = false; - - // NOTE: features are not resetable and typically defaults to false ... - protected boolean processNamespaces; - protected boolean roundtripSupported; - - // global parser state - protected String location; - protected int lineNumber; - protected int columnNumber; - protected boolean seenRoot; - protected boolean reachedEnd; - protected int eventType; - protected boolean emptyElementTag; - // element stack - protected int depth; - protected char[] elRawName[]; - protected int elRawNameEnd[]; - protected int elRawNameLine[]; - - protected String elName[]; - protected String elPrefix[]; - protected String elUri[]; - //protected String elValue[]; - protected int elNamespaceCount[]; - - - - /** - * Make sure that we have enough space to keep element stack if passed size. - * It will always create one additional slot then current depth - */ - protected void ensureElementsCapacity() { - final int elStackSize = elName != null ? elName.length : 0; - if( (depth + 1) >= elStackSize) { - // we add at least one extra slot ... - final int newSize = (depth >= 7 ? 2 * depth : 8) + 2; // = lucky 7 + 1 //25 - if(TRACE_SIZING) { - System.err.println("TRACE_SIZING elStackSize "+elStackSize+" ==> "+newSize); - } - final boolean needsCopying = elStackSize > 0; - String[] arr = null; - // resue arr local variable slot - arr = new String[newSize]; - if(needsCopying) System.arraycopy(elName, 0, arr, 0, elStackSize); - elName = arr; - arr = new String[newSize]; - if(needsCopying) System.arraycopy(elPrefix, 0, arr, 0, elStackSize); - elPrefix = arr; - arr = new String[newSize]; - if(needsCopying) System.arraycopy(elUri, 0, arr, 0, elStackSize); - elUri = arr; - - int[] iarr = new int[newSize]; - if(needsCopying) { - System.arraycopy(elNamespaceCount, 0, iarr, 0, elStackSize); - } else { - // special initialization - iarr[0] = 0; - } - elNamespaceCount = iarr; - - //TODO: avoid using element raw name ... - iarr = new int[newSize]; - if(needsCopying) { - System.arraycopy(elRawNameEnd, 0, iarr, 0, elStackSize); - } - elRawNameEnd = iarr; - - iarr = new int[newSize]; - if(needsCopying) { - System.arraycopy(elRawNameLine, 0, iarr, 0, elStackSize); - } - elRawNameLine = iarr; - - final char[][] carr = new char[newSize][]; - if(needsCopying) { - System.arraycopy(elRawName, 0, carr, 0, elStackSize); - } - elRawName = carr; - // arr = new String[newSize]; - // if(needsCopying) System.arraycopy(elLocalName, 0, arr, 0, elStackSize); - // elLocalName = arr; - // arr = new String[newSize]; - // if(needsCopying) System.arraycopy(elDefaultNs, 0, arr, 0, elStackSize); - // elDefaultNs = arr; - // int[] iarr = new int[newSize]; - // if(needsCopying) System.arraycopy(elNsStackPos, 0, iarr, 0, elStackSize); - // for (int i = elStackSize; i < iarr.length; i++) - // { - // iarr[i] = (i > 0) ? -1 : 0; - // } - // elNsStackPos = iarr; - //assert depth < elName.length; - } - } - - - - // attribute stack - protected int attributeCount; - protected String attributeName[]; - protected int attributeNameHash[]; - //protected int attributeNameStart[]; - //protected int attributeNameEnd[]; - protected String attributePrefix[]; - protected String attributeUri[]; - protected String attributeValue[]; - //protected int attributeValueStart[]; - //protected int attributeValueEnd[]; - - - /** - * Make sure that in attributes temporary array is enough space. - */ - protected void ensureAttributesCapacity(int size) { - final int attrPosSize = attributeName != null ? attributeName.length : 0; - if(size >= attrPosSize) { - final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25 - if(TRACE_SIZING) { - System.err.println("TRACE_SIZING attrPosSize "+attrPosSize+" ==> "+newSize); - } - final boolean needsCopying = attrPosSize > 0; - String[] arr = null; - - arr = new String[newSize]; - if(needsCopying) System.arraycopy(attributeName, 0, arr, 0, attrPosSize); - attributeName = arr; - - arr = new String[newSize]; - if(needsCopying) System.arraycopy(attributePrefix, 0, arr, 0, attrPosSize); - attributePrefix = arr; - - arr = new String[newSize]; - if(needsCopying) System.arraycopy(attributeUri, 0, arr, 0, attrPosSize); - attributeUri = arr; - - arr = new String[newSize]; - if(needsCopying) System.arraycopy(attributeValue, 0, arr, 0, attrPosSize); - attributeValue = arr; - - if( ! allStringsInterned ) { - final int[] iarr = new int[newSize]; - if(needsCopying) System.arraycopy(attributeNameHash, 0, iarr, 0, attrPosSize); - attributeNameHash = iarr; - } - - arr = null; - // //assert attrUri.length > size - } - } - - // namespace stack - protected int namespaceEnd; - protected String namespacePrefix[]; - protected int namespacePrefixHash[]; - protected String namespaceUri[]; - - protected void ensureNamespacesCapacity(int size) { - final int namespaceSize = namespacePrefix != null ? namespacePrefix.length : 0; - if(size >= namespaceSize) { - final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25 - if(TRACE_SIZING) { - System.err.println("TRACE_SIZING namespaceSize "+namespaceSize+" ==> "+newSize); - } - final String[] newNamespacePrefix = new String[newSize]; - final String[] newNamespaceUri = new String[newSize]; - if(namespacePrefix != null) { - System.arraycopy( - namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd); - System.arraycopy( - namespaceUri, 0, newNamespaceUri, 0, namespaceEnd); - } - namespacePrefix = newNamespacePrefix; - namespaceUri = newNamespaceUri; - - - if( ! allStringsInterned ) { - final int[] newNamespacePrefixHash = new int[newSize]; - if(namespacePrefixHash != null) { - System.arraycopy( - namespacePrefixHash, 0, newNamespacePrefixHash, 0, namespaceEnd); - } - namespacePrefixHash = newNamespacePrefixHash; - } - //prefixesSize = newSize; - // //assert nsPrefixes.length > size && nsPrefixes.length == newSize - } - } - - /** - * simplistic implementation of hash function that has <b>constant</b> - * time to compute - so it also means diminishing hash quality for long strings - * but for XML parsing it should be good enough ... - */ - protected static final int fastHash( char ch[], int off, int len ) { - if(len == 0) return 0; - //assert len >0 - int hash = ch[off]; // hash at beginning - //try { - hash = (hash << 7) + ch[ off + len - 1 ]; // hash at the end - //} catch(ArrayIndexOutOfBoundsException aie) { - // aie.printStackTrace(); //should never happen ... - // throw new RuntimeException("this is violation of pre-condition"); - //} - if(len > 16) hash = (hash << 7) + ch[ off + (len / 4)]; // 1/4 from beginning - if(len > 8) hash = (hash << 7) + ch[ off + (len / 2)]; // 1/2 of string size ... - // notice that hash is at most done 3 times <<7 so shifted by 21 bits 8 bit value - // so max result == 29 bits so it is quite just below 31 bits for long (2^32) ... - //assert hash >= 0; - return hash; - } - - // entity replacement stack - protected int entityEnd; - - protected String entityName[]; - protected char[] entityNameBuf[]; - protected String entityReplacement[]; - protected char[] entityReplacementBuf[]; - - protected int entityNameHash[]; - - protected void ensureEntityCapacity() { - final int entitySize = entityReplacementBuf != null ? entityReplacementBuf.length : 0; - if(entityEnd >= entitySize) { - final int newSize = entityEnd > 7 ? 2 * entityEnd : 8; // = lucky 7 + 1 //25 - if(TRACE_SIZING) { - System.err.println("TRACE_SIZING entitySize "+entitySize+" ==> "+newSize); - } - final String[] newEntityName = new String[newSize]; - final char[] newEntityNameBuf[] = new char[newSize][]; - final String[] newEntityReplacement = new String[newSize]; - final char[] newEntityReplacementBuf[] = new char[newSize][]; - if(entityName != null) { - System.arraycopy(entityName, 0, newEntityName, 0, entityEnd); - System.arraycopy(entityNameBuf, 0, newEntityNameBuf, 0, entityEnd); - System.arraycopy(entityReplacement, 0, newEntityReplacement, 0, entityEnd); - System.arraycopy(entityReplacementBuf, 0, newEntityReplacementBuf, 0, entityEnd); - } - entityName = newEntityName; - entityNameBuf = newEntityNameBuf; - entityReplacement = newEntityReplacement; - entityReplacementBuf = newEntityReplacementBuf; - - if( ! allStringsInterned ) { - final int[] newEntityNameHash = new int[newSize]; - if(entityNameHash != null) { - System.arraycopy(entityNameHash, 0, newEntityNameHash, 0, entityEnd); - } - entityNameHash = newEntityNameHash; - } - } - } - - // input buffer management - protected static final int READ_CHUNK_SIZE = 8*1024; //max data chars in one read() call - protected Reader reader; - protected String inputEncoding; - - - protected int bufLoadFactor = 95; // 99% - //protected int bufHardLimit; // only matters when expanding - - protected char buf[] = new char[ - Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256 ]; - protected int bufSoftLimit = ( bufLoadFactor * buf.length ) /100; // desirable size of buffer - protected boolean preventBufferCompaction; - - protected int bufAbsoluteStart; // this is buf - protected int bufStart; - protected int bufEnd; - protected int pos; - protected int posStart; - protected int posEnd; - - protected char pc[] = new char[ - Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 64 ]; - protected int pcStart; - protected int pcEnd; - - - // parsing state - //protected boolean needsMore; - //protected boolean seenMarkup; - protected boolean usePC; - - - protected boolean seenStartTag; - protected boolean seenEndTag; - protected boolean pastEndTag; - protected boolean seenAmpersand; - protected boolean seenMarkup; - protected boolean seenDocdecl; - - // transient variable set during each call to next/Token() - protected boolean tokenize; - protected String text; - protected String entityRefName; - - protected String xmlDeclVersion; - protected Boolean xmlDeclStandalone; - protected String xmlDeclContent; - - protected void reset() { - //System.out.println("reset() called"); - location = null; - lineNumber = 1; - columnNumber = 0; - seenRoot = false; - reachedEnd = false; - eventType = START_DOCUMENT; - emptyElementTag = false; - - depth = 0; - - attributeCount = 0; - - namespaceEnd = 0; - - entityEnd = 0; - - reader = null; - inputEncoding = null; - - preventBufferCompaction = false; - bufAbsoluteStart = 0; - bufEnd = bufStart = 0; - pos = posStart = posEnd = 0; - - pcEnd = pcStart = 0; - - usePC = false; - - seenStartTag = false; - seenEndTag = false; - pastEndTag = false; - seenAmpersand = false; - seenMarkup = false; - seenDocdecl = false; - - xmlDeclVersion = null; - xmlDeclStandalone = null; - xmlDeclContent = null; - - resetStringCache(); - } - - public MXParser() { - } - - - /** - * Method setFeature - * - * @param name a String - * @param state a boolean - * - * @throws XmlPullParserException - * - */ - public void setFeature(String name, - boolean state) throws XmlPullParserException - { - if(name == null) throw new IllegalArgumentException("feature name should not be null"); - if(FEATURE_PROCESS_NAMESPACES.equals(name)) { - if(eventType != START_DOCUMENT) throw new XmlPullParserException( - "namespace processing feature can only be changed before parsing", this, null); - processNamespaces = state; - // } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) { - // if(type != START_DOCUMENT) throw new XmlPullParserException( - // "namespace reporting feature can only be changed before parsing", this, null); - // reportNsAttribs = state; - } else if(FEATURE_NAMES_INTERNED.equals(name)) { - if(state != false) { - throw new XmlPullParserException( - "interning names in this implementation is not supported"); - } - } else if(FEATURE_PROCESS_DOCDECL.equals(name)) { - if(state != false) { - throw new XmlPullParserException( - "processing DOCDECL is not supported"); - } - //} else if(REPORT_DOCDECL.equals(name)) { - // paramNotifyDoctype = state; - } else if(FEATURE_XML_ROUNDTRIP.equals(name)) { - //if(state == false) { - // throw new XmlPullParserException( - // "roundtrip feature can not be switched off"); - //} - roundtripSupported = state; - } else { - throw new XmlPullParserException("unsupporte feature "+name); - } - } - - /** Unknown properties are <string>always</strong> returned as false */ - public boolean getFeature(String name) - { - if(name == null) throw new IllegalArgumentException("feature name should not be nulll"); - if(FEATURE_PROCESS_NAMESPACES.equals(name)) { - return processNamespaces; - // } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) { - // return reportNsAttribs; - } else if(FEATURE_NAMES_INTERNED.equals(name)) { - return false; - } else if(FEATURE_PROCESS_DOCDECL.equals(name)) { - return false; - //} else if(REPORT_DOCDECL.equals(name)) { - // return paramNotifyDoctype; - } else if(FEATURE_XML_ROUNDTRIP.equals(name)) { - //return true; - return roundtripSupported; - } - return false; - } - - public void setProperty(String name, - Object value) - throws XmlPullParserException - { - if(PROPERTY_LOCATION.equals(name)) { - location = (String) value; - } else { - throw new XmlPullParserException("unsupported property: '"+name+"'"); - } - } - - - public Object getProperty(String name) - { - if(name == null) throw new IllegalArgumentException("property name should not be nulll"); - if(PROPERTY_XMLDECL_VERSION.equals(name)) { - return xmlDeclVersion; - } else if(PROPERTY_XMLDECL_STANDALONE.equals(name)) { - return xmlDeclStandalone; - } else if(PROPERTY_XMLDECL_CONTENT.equals(name)) { - return xmlDeclContent; - } else if(PROPERTY_LOCATION.equals(name)) { - return location; - } - return null; - } - - - public void setInput(Reader in) throws XmlPullParserException - { - reset(); - reader = in; - } - - - public void setInput(java.io.InputStream inputStream, String inputEncoding) - throws XmlPullParserException - { - if(inputStream == null) { - throw new IllegalArgumentException("input stream can not be null"); - } - Reader reader; - try { - if(inputEncoding != null) { - reader = ReaderFactory.newReader(inputStream, inputEncoding); - } else { - reader = ReaderFactory.newXmlReader(inputStream); - } - } catch (UnsupportedEncodingException une) { - throw new XmlPullParserException( - "could not create reader for encoding "+inputEncoding+" : "+une, this, une); - } - catch ( IOException e ) - { - throw new XmlPullParserException( - "could not create reader : "+e, this, e); - } - setInput(reader); - //must be here as reset() was called in setInput() and has set this.inputEncoding to null ... - this.inputEncoding = inputEncoding; - } - - public String getInputEncoding() { - return inputEncoding; - } - - public void defineEntityReplacementText(String entityName, - String replacementText) - throws XmlPullParserException - { - // throw new XmlPullParserException("not allowed"); - - if ( !replacementText.startsWith( "&#" ) && this.entityName != null && replacementText.length() > 1 ) - { - String tmp = replacementText.substring( 1, replacementText.length() - 1 ); - for ( int i = 0; i < this.entityName.length; i++ ) - { - if ( this.entityName[i] != null && this.entityName[i].equals( tmp ) ) - { - replacementText = this.entityReplacement[i]; - } - } - } - - //protected char[] entityReplacement[]; - ensureEntityCapacity(); - - // this is to make sure that if interning works we will take advantage of it ... - this.entityName[entityEnd] = newString(entityName.toCharArray(), 0, entityName.length()); - entityNameBuf[entityEnd] = entityName.toCharArray(); - - entityReplacement[entityEnd] = replacementText; - entityReplacementBuf[entityEnd] = replacementText.toCharArray(); - if(!allStringsInterned) { - entityNameHash[ entityEnd ] = - fastHash(entityNameBuf[entityEnd], 0, entityNameBuf[entityEnd].length); - } - ++entityEnd; - //TODO disallow < or & in entity replacement text (or ]]>???) - // TOOD keepEntityNormalizedForAttributeValue cached as well ... - } - - public int getNamespaceCount(int depth) - throws XmlPullParserException - { - if(processNamespaces == false || depth == 0) { - return 0; - } - //int maxDepth = eventType == END_TAG ? this.depth + 1 : this.depth; - //if(depth < 0 || depth > maxDepth) throw new IllegalArgumentException( - if(depth < 0 || depth > this.depth) throw new IllegalArgumentException( - "napespace count mayt be for depth 0.."+this.depth+" not "+depth); - return elNamespaceCount[ depth ]; - } - - public String getNamespacePrefix(int pos) - throws XmlPullParserException - { - - //int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd; - //if(pos < end) { - if(pos < namespaceEnd) { - return namespacePrefix[ pos ]; - } else { - throw new XmlPullParserException( - "position "+pos+" exceeded number of available namespaces "+namespaceEnd); - } - } - - public String getNamespaceUri(int pos) throws XmlPullParserException - { - //int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd; - //if(pos < end) { - if(pos < namespaceEnd) { - return namespaceUri[ pos ]; - } else { - throw new XmlPullParserException( - "position "+pos+" exceedded number of available namespaces "+namespaceEnd); - } - } - - public String getNamespace( String prefix ) - //throws XmlPullParserException - { - //int count = namespaceCount[ depth ]; - if(prefix != null) { - for( int i = namespaceEnd -1; i >= 0; i--) { - if( prefix.equals( namespacePrefix[ i ] ) ) { - return namespaceUri[ i ]; - } - } - if("xml".equals( prefix )) { - return XML_URI; - } else if("xmlns".equals( prefix )) { - return XMLNS_URI; - } - } else { - for( int i = namespaceEnd -1; i >= 0; i--) { - if( namespacePrefix[ i ] == null) { //"") { //null ) { //TODO check FIXME Alek - return namespaceUri[ i ]; - } - } - - } - return null; - } - - - public int getDepth() - { - return depth; - } - - - private static int findFragment(int bufMinPos, char[] b, int start, int end) { - //System.err.println("bufStart="+bufStart+" b="+printable(new String(b, start, end - start))+" start="+start+" end="+end); - if(start < bufMinPos) { - start = bufMinPos; - if(start > end) start = end; - return start; - } - if(end - start > 65) { - start = end - 10; // try to find good location - } - int i = start + 1; - while(--i > bufMinPos) { - if((end - i) > 65) break; - final char c = b[i]; - if(c == '<' && (start - i) > 10) break; - } - return i; - } - - - /** - * Return string describing current position of parsers as - * text 'STATE [seen %s...] @line:column'. - */ - public String getPositionDescription () - { - String fragment = null; - if(posStart <= pos) { - final int start = findFragment(0, buf, posStart, pos); - //System.err.println("start="+start); - if(start < pos) { - fragment = new String(buf, start, pos - start); - } - if(bufAbsoluteStart > 0 || start > 0) fragment = "..." + fragment; - } - // return " at line "+tokenizerPosRow - // +" and column "+(tokenizerPosCol-1) - // +(fragment != null ? " seen "+printable(fragment)+"..." : ""); - return " "+TYPES[ eventType ] + - (fragment != null ? " seen "+printable(fragment)+"..." : "") - +" "+(location != null ? location : "") - +"@"+getLineNumber()+":"+getColumnNumber(); - } - - public int getLineNumber() - { - return lineNumber; - } - - public int getColumnNumber() - { - return columnNumber; - } - - - public boolean isWhitespace() throws XmlPullParserException - { - if(eventType == TEXT || eventType == CDSECT) { - if(usePC) { - for (int i = pcStart; i <pcEnd; i++) - { - if(!isS(pc[ i ])) return false; - } - return true; - } else { - for (int i = posStart; i <posEnd; i++) - { - if(!isS(buf[ i ])) return false; - } - return true; - } - } else if(eventType == IGNORABLE_WHITESPACE) { - return true; - } - throw new XmlPullParserException("no content available to check for whitespaces"); - } - - public String getText() - { - if(eventType == START_DOCUMENT || eventType == END_DOCUMENT) { - //throw new XmlPullParserException("no content available to read"); - // if(roundtripSupported) { - // text = new String(buf, posStart, posEnd - posStart); - // } else { - return null; - // } - } else if(eventType == ENTITY_REF) { - return text; - } - if(text == null) { - if(!usePC || eventType == START_TAG || eventType == END_TAG) { - text = new String(buf, posStart, posEnd - posStart); - } else { - text = new String(pc, pcStart, pcEnd - pcStart); - } - } - return text; - } - - public char[] getTextCharacters(int [] holderForStartAndLength) - { - if( eventType == TEXT ) { - if(usePC) { - holderForStartAndLength[0] = pcStart; - holderForStartAndLength[1] = pcEnd - pcStart; - return pc; - } else { - holderForStartAndLength[0] = posStart; - holderForStartAndLength[1] = posEnd - posStart; - return buf; - - } - } else if( eventType == START_TAG - || eventType == END_TAG - || eventType == CDSECT - || eventType == COMMENT - || eventType == ENTITY_REF - || eventType == PROCESSING_INSTRUCTION - || eventType == IGNORABLE_WHITESPACE - || eventType == DOCDECL) - { - holderForStartAndLength[0] = posStart; - holderForStartAndLength[1] = posEnd - posStart; - return buf; - } else if(eventType == START_DOCUMENT - || eventType == END_DOCUMENT) { - //throw new XmlPullParserException("no content available to read"); - holderForStartAndLength[0] = holderForStartAndLength[1] = -1; - return null; - } else { - throw new IllegalArgumentException("unknown text eventType: "+eventType); - } - // String s = getText(); - // char[] cb = null; - // if(s!= null) { - // cb = s.toCharArray(); - // holderForStartAndLength[0] = 0; - // holderForStartAndLength[1] = s.length(); - // } else { - // } - // return cb; - } - - public String getNamespace() - { - if(eventType == START_TAG) { - //return processNamespaces ? elUri[ depth - 1 ] : NO_NAMESPACE; - return processNamespaces ? elUri[ depth ] : NO_NAMESPACE; - } else if(eventType == END_TAG) { - return processNamespaces ? elUri[ depth ] : NO_NAMESPACE; - } - return null; - // String prefix = elPrefix[ maxDepth ]; - // if(prefix != null) { - // for( int i = namespaceEnd -1; i >= 0; i--) { - // if( prefix.equals( namespacePrefix[ i ] ) ) { - // return namespaceUri[ i ]; - // } - // } - // } else { - // for( int i = namespaceEnd -1; i >= 0; i--) { - // if( namespacePrefix[ i ] == null ) { - // return namespaceUri[ i ]; - // } - // } - // - // } - // return ""; - } - - public String getName() - { - if(eventType == START_TAG) { - //return elName[ depth - 1 ] ; - return elName[ depth ] ; - } else if(eventType == END_TAG) { - return elName[ depth ] ; - } else if(eventType == ENTITY_REF) { - if(entityRefName == null) { - entityRefName = newString(buf, posStart, posEnd - posStart); - } - return entityRefName; - } else { - return null; - } - } - - public String getPrefix() - { - if(eventType == START_TAG) { - //return elPrefix[ depth - 1 ] ; - return elPrefix[ depth ] ; - } else if(eventType == END_TAG) { - return elPrefix[ depth ] ; - } - return null; - // if(eventType != START_TAG && eventType != END_TAG) return null; - // int maxDepth = eventType == END_TAG ? depth : depth - 1; - // return elPrefix[ maxDepth ]; - } - - - public boolean isEmptyElementTag() throws XmlPullParserException - { - if(eventType != START_TAG) throw new XmlPullParserException( - "parser must be on START_TAG to check for empty element", this, null); - return emptyElementTag; - } - - public int getAttributeCount() - { - if(eventType != START_TAG) return -1; - return attributeCount; - } - - public String getAttributeNamespace(int index) - { - if(eventType != START_TAG) throw new IndexOutOfBoundsException( - "only START_TAG can have attributes"); - if(processNamespaces == false) return NO_NAMESPACE; - if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( - "attribute position must be 0.."+(attributeCount-1)+" and not "+index); - return attributeUri[ index ]; - } - - public String getAttributeName(int index) - { - if(eventType != START_TAG) throw new IndexOutOfBoundsException( - "only START_TAG can have attributes"); - if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( - "attribute position must be 0.."+(attributeCount-1)+" and not "+index); - return attributeName[ index ]; - } - - public String getAttributePrefix(int index) - { - if(eventType != START_TAG) throw new IndexOutOfBoundsException( - "only START_TAG can have attributes"); - if(processNamespaces == false) return null; - if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( - "attribute position must be 0.."+(attributeCount-1)+" and not "+index); - return attributePrefix[ index ]; - } - - public String getAttributeType(int index) { - if(eventType != START_TAG) throw new IndexOutOfBoundsException( - "only START_TAG can have attributes"); - if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( - "attribute position must be 0.."+(attributeCount-1)+" and not "+index); - return "CDATA"; - } - - public boolean isAttributeDefault(int index) { - if(eventType != START_TAG) throw new IndexOutOfBoundsException( - "only START_TAG can have attributes"); - if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( - "attribute position must be 0.."+(attributeCount-1)+" and not "+index); - return false; - } - - public String getAttributeValue(int index) - { - if(eventType != START_TAG) throw new IndexOutOfBoundsException( - "only START_TAG can have attributes"); - if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( - "attribute position must be 0.."+(attributeCount-1)+" and not "+index); - return attributeValue[ index ]; - } - - public String getAttributeValue(String namespace, - String name) - { - if(eventType != START_TAG) throw new IndexOutOfBoundsException( - "only START_TAG can have attributes"+getPositionDescription()); - if(name == null) { - throw new IllegalArgumentException("attribute name can not be null"); - } - // TODO make check if namespace is interned!!! etc. for names!!! - if(processNamespaces) { - if(namespace == null) { - namespace = ""; - } - - for(int i = 0; i < attributeCount; ++i) { - if((namespace == attributeUri[ i ] || - namespace.equals(attributeUri[ i ]) ) - //(namespace != null && namespace.equals(attributeUri[ i ])) - // taking advantage of String.intern() - && name.equals(attributeName[ i ]) ) - { - return attributeValue[i]; - } - } - } else { - if(namespace != null && namespace.length() == 0) { - namespace = null; - } - if(namespace != null) throw new IllegalArgumentException( - "when namespaces processing is disabled attribute namespace must be null"); - for(int i = 0; i < attributeCount; ++i) { - if(name.equals(attributeName[i])) - { - return attributeValue[i]; - } - } - } - return null; - } - - - public int getEventType() - throws XmlPullParserException - { - return eventType; - } - - public void require(int type, String namespace, String name) - throws XmlPullParserException, IOException - { - if(processNamespaces == false && namespace != null) { - throw new XmlPullParserException( - "processing namespaces must be enabled on parser (or factory)"+ - " to have possible namespaces delcared on elements" - +(" (postion:"+ getPositionDescription())+")"); - } - if (type != getEventType() - || (namespace != null && !namespace.equals (getNamespace())) - || (name != null && !name.equals (getName ())) ) - { - throw new XmlPullParserException ( - "expected event "+TYPES[ type ] - +(name != null ? " with name '"+name+"'" : "") - +(namespace != null && name != null ? " and" : "") - +(namespace != null ? " with namespace '"+namespace+"'" : "") - +" but got" - +(type != getEventType() ? " "+TYPES[ getEventType() ] : "") - +(name != null && getName() != null && !name.equals (getName ()) - ? " name '"+getName()+"'" : "") - +(namespace != null && name != null - && getName() != null && !name.equals (getName ()) - && getNamespace() != null && !namespace.equals (getNamespace()) - ? " and" : "") - +(namespace != null && getNamespace() != null && !namespace.equals (getNamespace()) - ? " namespace '"+getNamespace()+"'" : "") - +(" (postion:"+ getPositionDescription())+")"); - } - } - - - /** - * Skip sub tree that is currently porser positioned on. - * <br>NOTE: parser must be on START_TAG and when funtion returns - * parser will be positioned on corresponding END_TAG - */ - public void skipSubTree() - throws XmlPullParserException, IOException - { - require(START_TAG, null, null); - int level = 1; - while(level > 0) { - int eventType = next(); - if(eventType == END_TAG) { - --level; - } else if(eventType == START_TAG) { - ++level; - } - } - } - - // public String readText() throws XmlPullParserException, IOException - // { - // if (getEventType() != TEXT) return ""; - // String result = getText(); - // next(); - // return result; - // } - - public String nextText() throws XmlPullParserException, IOException - { - // String result = null; - // boolean onStartTag = false; - // if(eventType == START_TAG) { - // onStartTag = true; - // next(); - // } - // if(eventType == TEXT) { - // result = getText(); - // next(); - // } else if(onStartTag && eventType == END_TAG) { - // result = ""; - // } else { - // throw new XmlPullParserException( - // "parser must be on START_TAG or TEXT to read text", this, null); - // } - // if(eventType != END_TAG) { - // throw new XmlPullParserException( - // "event TEXT it must be immediately followed by END_TAG", this, null); - // } - // return result; - if(getEventType() != START_TAG) { - throw new XmlPullParserException( - "parser must be on START_TAG to read next text", this, null); - } - int eventType = next(); - if(eventType == TEXT) { - final String result = getText(); - eventType = next(); - if(eventType != END_TAG) { - throw new XmlPullParserException( - "TEXT must be immediately followed by END_TAG and not " - +TYPES[ getEventType() ], this, null); - } - return result; - } else if(eventType == END_TAG) { - return ""; - } else { - throw new XmlPullParserException( - "parser must be on START_TAG or TEXT to read text", this, null); - } - } - - public int nextTag() throws XmlPullParserException, IOException - { - next(); - if(eventType == TEXT && isWhitespace()) { // skip whitespace - next(); - } - if (eventType != START_TAG && eventType != END_TAG) { - throw new XmlPullParserException("expected START_TAG or END_TAG not " - +TYPES[ getEventType() ], this, null); - } - return eventType; - } - - public int next() - throws XmlPullParserException, IOException - { - tokenize = false; - return nextImpl(); - } - - public int nextToken() - throws XmlPullParserException, IOException - { - tokenize = true; - return nextImpl(); - } - - - protected int nextImpl() - throws XmlPullParserException, IOException - { - text = null; - pcEnd = pcStart = 0; - usePC = false; - bufStart = posEnd; - if(pastEndTag) { - pastEndTag = false; - --depth; - namespaceEnd = elNamespaceCount[ depth ]; // less namespaces available - } - if(emptyElementTag) { - emptyElementTag = false; - pastEndTag = true; - return eventType = END_TAG; - } - - // [1] document ::= prolog element Misc* - if(depth > 0) { - - if(seenStartTag) { - seenStartTag = false; - return eventType = parseStartTag(); - } - if(seenEndTag) { - seenEndTag = false; - return eventType = parseEndTag(); - } - - // ASSUMPTION: we are _on_ first character of content or markup!!!! - // [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* - char ch; - if(seenMarkup) { // we have read ahead ... - seenMarkup = false; - ch = '<'; - } else if(seenAmpersand) { - seenAmpersand = false; - ch = '&'; - } else { - ch = more(); - } - posStart = pos - 1; // VERY IMPORTANT: this is correct start of event!!! - - // when true there is some potential event TEXT to return - keep gathering - boolean hadCharData = false; - - // when true TEXT data is not continuous (like <![CDATA[text]]>) and requires PC merging - boolean needsMerging = false; - - MAIN_LOOP: - while(true) { - // work on MARKUP - if(ch == '<') { - if(hadCharData) { - //posEnd = pos - 1; - if(tokenize) { - seenMarkup = true; - return eventType = TEXT; - } - } - ch = more(); - if(ch == '/') { - if(!tokenize && hadCharData) { - seenEndTag = true; - //posEnd = pos - 2; - return eventType = TEXT; - } - return eventType = parseEndTag(); - } else if(ch == '!') { - ch = more(); - if(ch == '-') { - // note: if(tokenize == false) posStart/End is NOT changed!!!! - parseComment(); - if(tokenize) return eventType = COMMENT; - if( !usePC && hadCharData ) { - needsMerging = true; - } else { - posStart = pos; //completely ignore comment - } - } else if(ch == '[') { - //posEnd = pos - 3; - // must remember previous posStart/End as it merges with content of CDATA - //int oldStart = posStart + bufAbsoluteStart; - //int oldEnd = posEnd + bufAbsoluteStart; - parseCDSect(hadCharData); - if(tokenize) return eventType = CDSECT; - final int cdStart = posStart; - final int cdEnd = posEnd; - final int cdLen = cdEnd - cdStart; - - - if(cdLen > 0) { // was there anything inside CDATA section? - hadCharData = true; - if(!usePC) { - needsMerging = true; - } - } - - // posStart = oldStart; - // posEnd = oldEnd; - // if(cdLen > 0) { // was there anything inside CDATA section? - // if(hadCharData) { - // // do merging if there was anything in CDSect!!!! - // // if(!usePC) { - // // // posEnd is correct already!!! - // // if(posEnd > posStart) { - // // joinPC(); - // // } else { - // // usePC = true; - // // pcStart = pcEnd = 0; - // // } - // // } - // // if(pcEnd + cdLen >= pc.length) ensurePC(pcEnd + cdLen); - // // // copy [cdStart..cdEnd) into PC - // // System.arraycopy(buf, cdStart, pc, pcEnd, cdLen); - // // pcEnd += cdLen; - // if(!usePC) { - // needsMerging = true; - // posStart = cdStart; - // posEnd = cdEnd; - // } - // } else { - // if(!usePC) { - // needsMerging = true; - // posStart = cdStart; - // posEnd = cdEnd; - // hadCharData = true; - // } - // } - // //hadCharData = true; - // } else { - // if( !usePC && hadCharData ) { - // needsMerging = true; - // } - // } - } else { - throw new XmlPullParserException( - "unexpected character in markup "+printable(ch), this, null); - } - } else if(ch == '?') { - parsePI(); - if(tokenize) return eventType = PROCESSING_INSTRUCTION; - if( !usePC && hadCharData ) { - needsMerging = true; - } else { - posStart = pos; //completely ignore PI - } - - } else if( isNameStartChar(ch) ) { - if(!tokenize && hadCharData) { - seenStartTag = true; - //posEnd = pos - 2; - return eventType = TEXT; - } - return eventType = parseStartTag(); - } else { - throw new XmlPullParserException( - "unexpected character in markup "+printable(ch), this, null); - } - // do content comapctation if it makes sense!!!! - - } else if(ch == '&') { - // work on ENTITTY - //posEnd = pos - 1; - if(tokenize && hadCharData) { - seenAmpersand = true; - return eventType = TEXT; - } - final int oldStart = posStart + bufAbsoluteStart; - final int oldEnd = posEnd + bufAbsoluteStart; - final char[] resolvedEntity = parseEntityRef(); - if(tokenize) return eventType = ENTITY_REF; - // check if replacement text can be resolved !!! - if(resolvedEntity == null) { - if(entityRefName == null) { - entityRefName = newString(buf, posStart, posEnd - posStart); - } - throw new XmlPullParserException( - "could not resolve entity named '"+printable(entityRefName)+"'", - this, null); - } - //int entStart = posStart; - //int entEnd = posEnd; - posStart = oldStart - bufAbsoluteStart; - posEnd = oldEnd - bufAbsoluteStart; - if(!usePC) { - if(hadCharData) { - joinPC(); // posEnd is already set correctly!!! - needsMerging = false; - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - //assert usePC == true; - // write into PC replacement text - do merge for replacement text!!!! - for (int i = 0; i < resolvedEntity.length; i++) - { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = resolvedEntity[ i ]; - - } - hadCharData = true; - //assert needsMerging == false; - } else { - - if(needsMerging) { - //assert usePC == false; - joinPC(); // posEnd is already set correctly!!! - //posStart = pos - 1; - needsMerging = false; - } - - - //no MARKUP not ENTITIES so work on character data ... - - - - // [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) - - - hadCharData = true; - - boolean normalizedCR = false; - final boolean normalizeInput = tokenize == false || roundtripSupported == false; - // use loop locality here!!!! - boolean seenBracket = false; - boolean seenBracketBracket = false; - do { - - // check that ]]> does not show in - if(ch == ']') { - if(seenBracket) { - seenBracketBracket = true; - } else { - seenBracket = true; - } - } else if(seenBracketBracket && ch == '>') { - throw new XmlPullParserException( - "characters ]]> are not allowed in content", this, null); - } else { - if(seenBracket) { - seenBracketBracket = seenBracket = false; - } - // assert seenTwoBrackets == seenBracket == false; - } - if(normalizeInput) { - // deal with normalization issues ... - if(ch == '\r') { - normalizedCR = true; - posEnd = pos -1; - // posEnd is already set - if(!usePC) { - if(posEnd > posStart) { - joinPC(); - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - //assert usePC == true; - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } else if(ch == '\n') { - // if(!usePC) { joinPC(); } else { if(pcEnd >= pc.length) ensurePC(); } - if(!normalizedCR && usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } - normalizedCR = false; - } else { - if(usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = ch; - } - normalizedCR = false; - } - } - - ch = more(); - } while(ch != '<' && ch != '&'); - posEnd = pos - 1; - continue MAIN_LOOP; // skip ch = more() from below - we are already ahead ... - } - ch = more(); - } // endless while(true) - } else { - if(seenRoot) { - return parseEpilog(); - } else { - return parseProlog(); - } - } - } - - - protected int parseProlog() - throws XmlPullParserException, IOException - { - // [2] prolog: ::= XMLDecl? Misc* (doctypedecl Misc*)? and look for [39] element - - char ch; - if(seenMarkup) { - ch = buf[ pos - 1 ]; - } else { - ch = more(); - } - - if(eventType == START_DOCUMENT) { - // bootstrap parsing with getting first character input! - // deal with BOM - // detect BOM and crop it (Unicode int Order Mark) - if(ch == '\uFFFE') { - throw new XmlPullParserException( - "first character in input was UNICODE noncharacter (0xFFFE)"+ - "- input requires int swapping", this, null); - } - if(ch == '\uFEFF') { - // skipping UNICODE int Order Mark (so called BOM) - ch = more(); - } - } - seenMarkup = false; - boolean gotS = false; - posStart = pos - 1; - final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; - boolean normalizedCR = false; - while(true) { - // deal with Misc - // [27] Misc ::= Comment | PI | S - // deal with docdecl --> mark it! - // else parseStartTag seen <[^/] - if(ch == '<') { - if(gotS && tokenize) { - posEnd = pos - 1; - seenMarkup = true; - return eventType = IGNORABLE_WHITESPACE; - } - ch = more(); - if(ch == '?') { - // check if it is 'xml' - // deal with XMLDecl - boolean isXMLDecl = parsePI(); - if(tokenize) { - if (isXMLDecl) { - return eventType = START_DOCUMENT; - } - return eventType = PROCESSING_INSTRUCTION; - } - } else if(ch == '!') { - ch = more(); - if(ch == 'D') { - if(seenDocdecl) { - throw new XmlPullParserException( - "only one docdecl allowed in XML document", this, null); - } - seenDocdecl = true; - parseDocdecl(); - if(tokenize) return eventType = DOCDECL; - } else if(ch == '-') { - parseComment(); - if(tokenize) return eventType = COMMENT; - } else { - throw new XmlPullParserException( - "unexpected markup <!"+printable(ch), this, null); - } - } else if(ch == '/') { - throw new XmlPullParserException( - "expected start tag name and not "+printable(ch), this, null); - } else if(isNameStartChar(ch)) { - seenRoot = true; - return parseStartTag(); - } else { - throw new XmlPullParserException( - "expected start tag name and not "+printable(ch), this, null); - } - } else if(isS(ch)) { - gotS = true; - if(normalizeIgnorableWS) { - if(ch == '\r') { - normalizedCR = true; - //posEnd = pos -1; - //joinPC(); - // posEnd is already set - if(!usePC) { - posEnd = pos -1; - if(posEnd > posStart) { - joinPC(); - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - //assert usePC == true; - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } else if(ch == '\n') { - if(!normalizedCR && usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } - normalizedCR = false; - } else { - if(usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = ch; - } - normalizedCR = false; - } - } - } else { - throw new XmlPullParserException( - "only whitespace content allowed before start tag and not "+printable(ch), - this, null); - } - ch = more(); - } - } - - protected int parseEpilog() - throws XmlPullParserException, IOException - { - if(eventType == END_DOCUMENT) { - throw new XmlPullParserException("already reached end of XML input", this, null); - } - if(reachedEnd) { - return eventType = END_DOCUMENT; - } - boolean gotS = false; - final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; - boolean normalizedCR = false; - try { - // epilog: Misc* - char ch; - if(seenMarkup) { - ch = buf[ pos - 1 ]; - } else { - ch = more(); - } - seenMarkup = false; - posStart = pos - 1; - if(!reachedEnd) { - while(true) { - // deal with Misc - // [27] Misc ::= Comment | PI | S - if(ch == '<') { - if(gotS && tokenize) { - posEnd = pos - 1; - seenMarkup = true; - return eventType = IGNORABLE_WHITESPACE; - } - ch = more(); - if(reachedEnd) { - break; - } - if(ch == '?') { - // check if it is 'xml' - // deal with XMLDecl - parsePI(); - if(tokenize) return eventType = PROCESSING_INSTRUCTION; - - } else if(ch == '!') { - ch = more(); - if(reachedEnd) { - break; - } - if(ch == 'D') { - parseDocdecl(); //FIXME - if(tokenize) return eventType = DOCDECL; - } else if(ch == '-') { - parseComment(); - if(tokenize) return eventType = COMMENT; - } else { - throw new XmlPullParserException( - "unexpected markup <!"+printable(ch), this, null); - } - } else if(ch == '/') { - throw new XmlPullParserException( - "end tag not allowed in epilog but got "+printable(ch), this, null); - } else if(isNameStartChar(ch)) { - throw new XmlPullParserException( - "start tag not allowed in epilog but got "+printable(ch), this, null); - } else { - throw new XmlPullParserException( - "in epilog expected ignorable content and not "+printable(ch), - this, null); - } - } else if(isS(ch)) { - gotS = true; - if(normalizeIgnorableWS) { - if(ch == '\r') { - normalizedCR = true; - //posEnd = pos -1; - //joinPC(); - // posEnd is already set - if(!usePC) { - posEnd = pos -1; - if(posEnd > posStart) { - joinPC(); - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - //assert usePC == true; - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } else if(ch == '\n') { - if(!normalizedCR && usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } - normalizedCR = false; - } else { - if(usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = ch; - } - normalizedCR = false; - } - } - } else { - throw new XmlPullParserException( - "in epilog non whitespace content is not allowed but got "+printable(ch), - this, null); - } - ch = more(); - if(reachedEnd) { - break; - } - - } - } - - // throw Exception("unexpected content in epilog - // catch EOFException return END_DOCUMENT - //try { - } catch(EOFException ex) { - reachedEnd = true; - } - if(reachedEnd) { - if(tokenize && gotS) { - posEnd = pos; // well - this is LAST available character pos - return eventType = IGNORABLE_WHITESPACE; - } - return eventType = END_DOCUMENT; - } else { - throw new XmlPullParserException("internal error in parseEpilog"); - } - } - - - public int parseEndTag() throws XmlPullParserException, IOException { - //ASSUMPTION ch is past "</" - // [42] ETag ::= '</' Name S? '>' - char ch = more(); - if(!isNameStartChar(ch)) { - throw new XmlPullParserException( - "expected name start and not "+printable(ch), this, null); - } - posStart = pos - 3; - final int nameStart = pos - 1 + bufAbsoluteStart; - do { - ch = more(); - } while(isNameChar(ch)); - - // now we go one level down -- do checks - //--depth; //FIXME - - // check that end tag name is the same as start tag - //String name = new String(buf, nameStart - bufAbsoluteStart, - // (pos - 1) - (nameStart - bufAbsoluteStart)); - //int last = pos - 1; - int off = nameStart - bufAbsoluteStart; - //final int len = last - off; - final int len = (pos - 1) - off; - final char[] cbuf = elRawName[depth]; - if(elRawNameEnd[depth] != len) { - // construct strings for exception - final String startname = new String(cbuf, 0, elRawNameEnd[depth]); - final String endname = new String(buf, off, len); - throw new XmlPullParserException( - "end tag name </"+endname+"> must match start tag name <"+startname+">" - +" from line "+elRawNameLine[depth], this, null); - } - for (int i = 0; i < len; i++) - { - if(buf[off++] != cbuf[i]) { - // construct strings for exception - final String startname = new String(cbuf, 0, len); - final String endname = new String(buf, off - i - 1, len); - throw new XmlPullParserException( - "end tag name </"+endname+"> must be the same as start tag <"+startname+">" - +" from line "+elRawNameLine[depth], this, null); - } - } - - while(isS(ch)) { ch = more(); } // skip additional white spaces - if(ch != '>') { - throw new XmlPullParserException( - "expected > to finsh end tag not "+printable(ch) - +" from line "+elRawNameLine[depth], this, null); - } - - - //namespaceEnd = elNamespaceCount[ depth ]; //FIXME - - posEnd = pos; - pastEndTag = true; - return eventType = END_TAG; - } - - public int parseStartTag() throws XmlPullParserException, IOException { - //ASSUMPTION ch is past <T - // [40] STag ::= '<' Name (S Attribute)* S? '>' - // [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' - ++depth; //FIXME - - posStart = pos - 2; - - emptyElementTag = false; - attributeCount = 0; - // retrieve name - final int nameStart = pos - 1 + bufAbsoluteStart; - int colonPos = -1; - char ch = buf[ pos - 1]; - if(ch == ':' && processNamespaces) throw new XmlPullParserException( - "when namespaces processing enabled colon can not be at element name start", - this, null); - while(true) { - ch = more(); - if(!isNameChar(ch)) break; - if(ch == ':' && processNamespaces) { - if(colonPos != -1) throw new XmlPullParserException( - "only one colon is allowed in name of element when namespaces are enabled", - this, null); - colonPos = pos - 1 + bufAbsoluteStart; - } - } - - // retrieve name - ensureElementsCapacity(); - - - //TODO check for efficient interning and then use elRawNameInterned!!!! - - int elLen = (pos - 1) - (nameStart - bufAbsoluteStart); - if(elRawName[ depth ] == null || elRawName[ depth ].length < elLen) { - elRawName[ depth ] = new char[ 2 * elLen ]; - } - System.arraycopy(buf, nameStart - bufAbsoluteStart, elRawName[ depth ], 0, elLen); - elRawNameEnd[ depth ] = elLen; - elRawNameLine[ depth ] = lineNumber; - - String name = null; - - // work on prefixes and namespace URI - String prefix = null; - if(processNamespaces) { - if(colonPos != -1) { - prefix = elPrefix[ depth ] = newString(buf, nameStart - bufAbsoluteStart, - colonPos - nameStart); - name = elName[ depth ] = newString(buf, colonPos + 1 - bufAbsoluteStart, - //(pos -1) - (colonPos + 1)); - pos - 2 - (colonPos - bufAbsoluteStart)); - } else { - prefix = elPrefix[ depth ] = null; - name = elName[ depth ] = newString(buf, nameStart - bufAbsoluteStart, elLen); - } - } else { - - name = elName[ depth ] = newString(buf, nameStart - bufAbsoluteStart, elLen); - - } - - - while(true) { - - while(isS(ch)) { ch = more(); } // skip additional white spaces - - if(ch == '>') { - break; - } else if(ch == '/') { - if(emptyElementTag) throw new XmlPullParserException( - "repeated / in tag declaration", this, null); - emptyElementTag = true; - ch = more(); - if(ch != '>') throw new XmlPullParserException( - "expected > to end empty tag not "+printable(ch), this, null); - break; - } else if(isNameStartChar(ch)) { - ch = parseAttribute(); - ch = more(); - continue; - } else { - throw new XmlPullParserException( - "start tag unexpected character "+printable(ch), this, null); - } - //ch = more(); // skip space - } - - // now when namespaces were declared we can resolve them - if(processNamespaces) { - String uri = getNamespace(prefix); - if(uri == null) { - if(prefix == null) { // no prefix and no uri => use default namespace - uri = NO_NAMESPACE; - } else { - throw new XmlPullParserException( - "could not determine namespace bound to element prefix "+prefix, - this, null); - } - - } - elUri[ depth ] = uri; - - - //String uri = getNamespace(prefix); - //if(uri == null && prefix == null) { // no prefix and no uri => use default namespace - // uri = ""; - //} - // resolve attribute namespaces - for (int i = 0; i < attributeCount; i++) - { - final String attrPrefix = attributePrefix[ i ]; - if(attrPrefix != null) { - final String attrUri = getNamespace(attrPrefix); - if(attrUri == null) { - throw new XmlPullParserException( - "could not determine namespace bound to attribute prefix "+attrPrefix, - this, null); - - } - attributeUri[ i ] = attrUri; - } else { - attributeUri[ i ] = NO_NAMESPACE; - } - } - - //TODO - //[ WFC: Unique Att Spec ] - // check namespaced attribute uniqueness contraint!!! - - for (int i = 1; i < attributeCount; i++) - { - for (int j = 0; j < i; j++) - { - if( attributeUri[j] == attributeUri[i] - && (allStringsInterned && attributeName[j].equals(attributeName[i]) - || (!allStringsInterned - && attributeNameHash[ j ] == attributeNameHash[ i ] - && attributeName[j].equals(attributeName[i])) ) - - ) { - // prepare data for nice error messgae? - String attr1 = attributeName[j]; - if(attributeUri[j] != null) attr1 = attributeUri[j]+":"+attr1; - String attr2 = attributeName[i]; - if(attributeUri[i] != null) attr2 = attributeUri[i]+":"+attr2; - throw new XmlPullParserException( - "duplicated attributes "+attr1+" and "+attr2, this, null); - } - } - } - - - } else { // ! processNamespaces - - //[ WFC: Unique Att Spec ] - // check raw attribute uniqueness contraint!!! - for (int i = 1; i < attributeCount; i++) - { - for (int j = 0; j < i; j++) - { - if((allStringsInterned && attributeName[j].equals(attributeName[i]) - || (!allStringsInterned - && attributeNameHash[ j ] == attributeNameHash[ i ] - && attributeName[j].equals(attributeName[i])) ) - - ) { - // prepare data for nice error messgae? - final String attr1 = attributeName[j]; - final String attr2 = attributeName[i]; - throw new XmlPullParserException( - "duplicated attributes "+attr1+" and "+attr2, this, null); - } - } - } - } - - elNamespaceCount[ depth ] = namespaceEnd; - posEnd = pos; - return eventType = START_TAG; - } - - protected char parseAttribute() throws XmlPullParserException, IOException - { - // parse attribute - // [41] Attribute ::= Name Eq AttValue - // [WFC: No External Entity References] - // [WFC: No < in Attribute Values] - final int prevPosStart = posStart + bufAbsoluteStart; - final int nameStart = pos - 1 + bufAbsoluteStart; - int colonPos = -1; - char ch = buf[ pos - 1 ]; - if(ch == ':' && processNamespaces) throw new XmlPullParserException( - "when namespaces processing enabled colon can not be at attribute name start", - this, null); - - - boolean startsWithXmlns = processNamespaces && ch == 'x'; - int xmlnsPos = 0; - - ch = more(); - while(isNameChar(ch)) { - if(processNamespaces) { - if(startsWithXmlns && xmlnsPos < 5) { - ++xmlnsPos; - if(xmlnsPos == 1) { if(ch != 'm') startsWithXmlns = false; } - else if(xmlnsPos == 2) { if(ch != 'l') startsWithXmlns = false; } - else if(xmlnsPos == 3) { if(ch != 'n') startsWithXmlns = false; } - else if(xmlnsPos == 4) { if(ch != 's') startsWithXmlns = false; } - else if(xmlnsPos == 5) { - if(ch != ':') throw new XmlPullParserException( - "after xmlns in attribute name must be colon" - +"when namespaces are enabled", this, null); - //colonPos = pos - 1 + bufAbsoluteStart; - } - } - if(ch == ':') { - if(colonPos != -1) throw new XmlPullParserException( - "only one colon is allowed in attribute name" - +" when namespaces are enabled", this, null); - colonPos = pos - 1 + bufAbsoluteStart; - } - } - ch = more(); - } - - ensureAttributesCapacity(attributeCount); - - // --- start processing attributes - String name = null; - String prefix = null; - // work on prefixes and namespace URI - if(processNamespaces) { - if(xmlnsPos < 4) startsWithXmlns = false; - if(startsWithXmlns) { - if(colonPos != -1) { - //prefix = attributePrefix[ attributeCount ] = null; - final int nameLen = pos - 2 - (colonPos - bufAbsoluteStart); - if(nameLen == 0) { - throw new XmlPullParserException( - "namespace prefix is required after xmlns: " - +" when namespaces are enabled", this, null); - } - name = //attributeName[ attributeCount ] = - newString(buf, colonPos - bufAbsoluteStart + 1, nameLen); - //pos - 1 - (colonPos + 1 - bufAbsoluteStart) - } - } else { - if(colonPos != -1) { - int prefixLen = colonPos - nameStart; - prefix = attributePrefix[ attributeCount ] = - newString(buf, nameStart - bufAbsoluteStart,prefixLen); - //colonPos - (nameStart - bufAbsoluteStart)); - int nameLen = pos - 2 - (colonPos - bufAbsoluteStart); - name = attributeName[ attributeCount ] = - newString(buf, colonPos - bufAbsoluteStart + 1, nameLen); - //pos - 1 - (colonPos + 1 - bufAbsoluteStart)); - - //name.substring(0, colonPos-nameStart); - } else { - prefix = attributePrefix[ attributeCount ] = null; - name = attributeName[ attributeCount ] = - newString(buf, nameStart - bufAbsoluteStart, - pos - 1 - (nameStart - bufAbsoluteStart)); - } - if(!allStringsInterned) { - attributeNameHash[ attributeCount ] = name.hashCode(); - } - } - - } else { - // retrieve name - name = attributeName[ attributeCount ] = - newString(buf, nameStart - bufAbsoluteStart, - pos - 1 - (nameStart - bufAbsoluteStart)); - ////assert name != null; - if(!allStringsInterned) { - attributeNameHash[ attributeCount ] = name.hashCode(); - } - } - - // [25] Eq ::= S? '=' S? - while(isS(ch)) { ch = more(); } // skip additional spaces - if(ch != '=') throw new XmlPullParserException( - "expected = after attribute name", this, null); - ch = more(); - while(isS(ch)) { ch = more(); } // skip additional spaces - - // [10] AttValue ::= '"' ([^<&"] | Reference)* '"' - // | "'" ([^<&'] | Reference)* "'" - final char delimit = ch; - if(delimit != '"' && delimit != '\'') throw new XmlPullParserException( - "attribute value must start with quotation or apostrophe not " - +printable(delimit), this, null); - // parse until delimit or < and resolve Reference - //[67] Reference ::= EntityRef | CharRef - //int valueStart = pos + bufAbsoluteStart; - - - boolean normalizedCR = false; - usePC = false; - pcStart = pcEnd; - posStart = pos; - - while(true) { - ch = more(); - if(ch == delimit) { - break; - } if(ch == '<') { - throw new XmlPullParserException( - "markup not allowed inside attribute value - illegal < ", this, null); - } if(ch == '&') { - // extractEntityRef - posEnd = pos - 1; - if(!usePC) { - final boolean hadCharData = posEnd > posStart; - if(hadCharData) { - // posEnd is already set correctly!!! - joinPC(); - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - //assert usePC == true; - - final char[] resolvedEntity = parseEntityRef(); - // check if replacement text can be resolved !!! - if(resolvedEntity == null) { - if(entityRefName == null) { - entityRefName = newString(buf, posStart, posEnd - posStart); - } - throw new XmlPullParserException( - "could not resolve entity named '"+printable(entityRefName)+"'", - this, null); - } - // write into PC replacement text - do merge for replacement text!!!! - for (int i = 0; i < resolvedEntity.length; i++) - { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = resolvedEntity[ i ]; - } - } else if(ch == '\t' || ch == '\n' || ch == '\r') { - // do attribute value normalization - // as described in http://www.w3.org/TR/REC-xml#AVNormalize - // TODO add test for it form spec ... - // handle EOL normalization ... - if(!usePC) { - posEnd = pos - 1; - if(posEnd > posStart) { - joinPC(); - } else { - usePC = true; - pcEnd = pcStart = 0; - } - } - //assert usePC == true; - if(pcEnd >= pc.length) ensurePC(pcEnd); - if(ch != '\n' || !normalizedCR) { - pc[pcEnd++] = ' '; //'\n'; - } - - } else { - if(usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = ch; - } - } - normalizedCR = ch == '\r'; - } - - - if(processNamespaces && startsWithXmlns) { - String ns = null; - if(!usePC) { - ns = newStringIntern(buf, posStart, pos - 1 - posStart); - } else { - ns = newStringIntern(pc, pcStart, pcEnd - pcStart); - } - ensureNamespacesCapacity(namespaceEnd); - int prefixHash = -1; - if(colonPos != -1) { - if(ns.length() == 0) { - throw new XmlPullParserException( - "non-default namespace can not be declared to be empty string", this, null); - } - // declare new namespace - namespacePrefix[ namespaceEnd ] = name; - if(!allStringsInterned) { - prefixHash = namespacePrefixHash[ namespaceEnd ] = name.hashCode(); - } - } else { - // declare new default namespace... - namespacePrefix[ namespaceEnd ] = null; //""; //null; //TODO check FIXME Alek - if(!allStringsInterned) { - prefixHash = namespacePrefixHash[ namespaceEnd ] = -1; - } - } - namespaceUri[ namespaceEnd ] = ns; - - // detect duplicate namespace declarations!!! - final int startNs = elNamespaceCount[ depth - 1 ]; - for (int i = namespaceEnd - 1; i >= startNs; --i) - { - if(((allStringsInterned || name == null) && namespacePrefix[ i ] == name) - || (!allStringsInterned && name != null && - namespacePrefixHash[ i ] == prefixHash - && name.equals(namespacePrefix[ i ]) - )) - { - final String s = name == null ? "default" : "'"+name+"'"; - throw new XmlPullParserException( - "duplicated namespace declaration for "+s+" prefix", this, null); - } - } - - ++namespaceEnd; - - } else { - if(!usePC) { - attributeValue[ attributeCount ] = - new String(buf, posStart, pos - 1 - posStart); - } else { - attributeValue[ attributeCount ] = - new String(pc, pcStart, pcEnd - pcStart); - } - ++attributeCount; - } - posStart = prevPosStart - bufAbsoluteStart; - return ch; - } - - protected char[] charRefOneCharBuf = new char[1]; - - protected char[] parseEntityRef() - throws XmlPullParserException, IOException - { - // entity reference http://www.w3.org/TR/2000/REC-xml-20001006#NT-Reference - // [67] Reference ::= EntityRef | CharRef - - // ASSUMPTION just after & - entityRefName = null; - posStart = pos; - char ch = more(); - StringBuffer sb = new StringBuffer(); - if(ch == '#') { - // parse character reference - char charRef = 0; - ch = more(); - if(ch == 'x') { - //encoded in hex - while(true) { - ch = more(); - if(ch >= '0' && ch <= '9') { - charRef = (char)(charRef * 16 + (ch - '0')); - sb.append( ch ); - } else if(ch >= 'a' && ch <= 'f') { - charRef = (char)(charRef * 16 + (ch - ('a' - 10))); - sb.append( ch ); - } else if(ch >= 'A' && ch <= 'F') { - charRef = (char)(charRef * 16 + (ch - ('A' - 10))); - sb.append( ch ); - } else if(ch == ';') { - break; - } else { - throw new XmlPullParserException( - "character reference (with hex value) may not contain " - +printable(ch), this, null); - } - } - } else { - // encoded in decimal - while(true) { - if(ch >= '0' && ch <= '9') { - charRef = (char)(charRef * 10 + (ch - '0')); - } else if(ch == ';') { - break; - } else { - throw new XmlPullParserException( - "character reference (with decimal value) may not contain " - +printable(ch), this, null); - } - ch = more(); - } - } - posEnd = pos - 1; - if ( sb.length() > 0 ) - { - char[] tmp = toChars( Integer.parseInt( sb.toString(), 16 ) ); - charRefOneCharBuf = tmp; - if ( tokenize ) - { - text = newString( charRefOneCharBuf, 0, charRefOneCharBuf.length ); - } - return charRefOneCharBuf; - } - charRefOneCharBuf[0] = charRef; - if(tokenize) { - text = newString(charRefOneCharBuf, 0, 1); - } - return charRefOneCharBuf; - } else { - // [68] EntityRef ::= '&' Name ';' - // scan anem until ; - if(!isNameStartChar(ch)) { - throw new XmlPullParserException( - "entity reference names can not start with character '" - +printable(ch)+"'", this, null); - } - while(true) { - ch = more(); - if(ch == ';') { - break; - } - if(!isNameChar(ch)) { - throw new XmlPullParserException( - "entity reference name can not contain character " - +printable(ch)+"'", this, null); - } - } - posEnd = pos - 1; - // determine what name maps to - final int len = posEnd - posStart; - if(len == 2 && buf[posStart] == 'l' && buf[posStart+1] == 't') { - if(tokenize) { - text = "<"; - } - charRefOneCharBuf[0] = '<'; - return charRefOneCharBuf; - //if(paramPC || isParserTokenizing) { - // if(pcEnd >= pc.length) ensurePC(); - // pc[pcEnd++] = '<'; - //} - } else if(len == 3 && buf[posStart] == 'a' - && buf[posStart+1] == 'm' && buf[posStart+2] == 'p') { - if(tokenize) { - text = "&"; - } - charRefOneCharBuf[0] = '&'; - return charRefOneCharBuf; - } else if(len == 2 && buf[posStart] == 'g' && buf[posStart+1] == 't') { - if(tokenize) { - text = ">"; - } - charRefOneCharBuf[0] = '>'; - return charRefOneCharBuf; - } else if(len == 4 && buf[posStart] == 'a' && buf[posStart+1] == 'p' - && buf[posStart+2] == 'o' && buf[posStart+3] == 's') - { - if(tokenize) { - text = "'"; - } - charRefOneCharBuf[0] = '\''; - return charRefOneCharBuf; - } else if(len == 4 && buf[posStart] == 'q' && buf[posStart+1] == 'u' - && buf[posStart+2] == 'o' && buf[posStart+3] == 't') - { - if(tokenize) { - text = "\""; - } - charRefOneCharBuf[0] = '"'; - return charRefOneCharBuf; - } else { - final char[] result = lookuEntityReplacement(len); - if(result != null) { - return result; - } - } - if(tokenize) text = null; - return null; - } - } - - protected char[] lookuEntityReplacement(int entitNameLen) - throws XmlPullParserException, IOException - - { - if(!allStringsInterned) { - final int hash = fastHash(buf, posStart, posEnd - posStart); - LOOP: - for (int i = entityEnd - 1; i >= 0; --i) - { - if(hash == entityNameHash[ i ] && entitNameLen == entityNameBuf[ i ].length) { - final char[] entityBuf = entityNameBuf[ i ]; - for (int j = 0; j < entitNameLen; j++) - { - if(buf[posStart + j] != entityBuf[j]) continue LOOP; - } - if(tokenize) text = entityReplacement[ i ]; - return entityReplacementBuf[ i ]; - } - } - } else { - entityRefName = newString(buf, posStart, posEnd - posStart); - for (int i = entityEnd - 1; i >= 0; --i) - { - // take advantage that interning for newStirng is enforced - if(entityRefName == entityName[ i ]) { - if(tokenize) text = entityReplacement[ i ]; - return entityReplacementBuf[ i ]; - } - } - } - return null; - } - - - protected void parseComment() - throws XmlPullParserException, IOException - { - // implements XML 1.0 Section 2.5 Comments - - //ASSUMPTION: seen <!- - char ch = more(); - if(ch != '-') throw new XmlPullParserException( - "expected <!-- for comment start", this, null); - if(tokenize) posStart = pos; - - final int curLine = lineNumber; - final int curColumn = columnNumber; - try { - final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; - boolean normalizedCR = false; - - boolean seenDash = false; - boolean seenDashDash = false; - while(true) { - // scan until it hits --> - ch = more(); - if(seenDashDash && ch != '>') { - throw new XmlPullParserException( - "in comment after two dashes (--) next character must be >" - +" not "+printable(ch), this, null); - } - if(ch == '-') { - if(!seenDash) { - seenDash = true; - } else { - seenDashDash = true; - seenDash = false; - } - } else if(ch == '>') { - if(seenDashDash) { - break; // found end sequence!!!! - } else { - seenDashDash = false; - } - seenDash = false; - } else { - seenDash = false; - } - if(normalizeIgnorableWS) { - if(ch == '\r') { - normalizedCR = true; - //posEnd = pos -1; - //joinPC(); - // posEnd is alreadys set - if(!usePC) { - posEnd = pos -1; - if(posEnd > posStart) { - joinPC(); - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - //assert usePC == true; - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } else if(ch == '\n') { - if(!normalizedCR && usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } - normalizedCR = false; - } else { - if(usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = ch; - } - normalizedCR = false; - } - } - } - - } catch(EOFException ex) { - // detect EOF and create meaningful error ... - throw new XmlPullParserException( - "comment started on line "+curLine+" and column "+curColumn+" was not closed", - this, ex); - } - if(tokenize) { - posEnd = pos - 3; - if(usePC) { - pcEnd -= 2; - } - } - } - - protected boolean parsePI() - throws XmlPullParserException, IOException - { - // implements XML 1.0 Section 2.6 Processing Instructions - - // [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' - // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) - //ASSUMPTION: seen <? - if(tokenize) posStart = pos; - final int curLine = lineNumber; - final int curColumn = columnNumber; - int piTargetStart = pos + bufAbsoluteStart; - int piTargetEnd = -1; - final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; - boolean normalizedCR = false; - - try { - boolean seenQ = false; - char ch = more(); - if(isS(ch)) { - throw new XmlPullParserException( - "processing instruction PITarget must be exactly after <? and not white space character", - this, null); - } - while(true) { - // scan until it hits ?> - //ch = more(); - - if(ch == '?') { - seenQ = true; - } else if(ch == '>') { - if(seenQ) { - break; // found end sequence!!!! - } - seenQ = false; - } else { - if(piTargetEnd == -1 && isS(ch)) { - piTargetEnd = pos - 1 + bufAbsoluteStart; - - // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) - if((piTargetEnd - piTargetStart) == 3) { - if((buf[piTargetStart] == 'x' || buf[piTargetStart] == 'X') - && (buf[piTargetStart+1] == 'm' || buf[piTargetStart+1] == 'M') - && (buf[piTargetStart+2] == 'l' || buf[piTargetStart+2] == 'L') - ) - { - if(piTargetStart > 3) { //<?xml is allowed as first characters in input ... - throw new XmlPullParserException( - "processing instruction can not have PITarget with reserveld xml name", - this, null); - } else { - if(buf[piTargetStart] != 'x' - && buf[piTargetStart+1] != 'm' - && buf[piTargetStart+2] != 'l') - { - throw new XmlPullParserException( - "XMLDecl must have xml name in lowercase", - this, null); - } - } - parseXmlDecl(ch); - if(tokenize) posEnd = pos - 2; - final int off = piTargetStart - bufAbsoluteStart + 3; - final int len = pos - 2 - off; - xmlDeclContent = newString(buf, off, len); - return false; - } - } - } - seenQ = false; - } - if(normalizeIgnorableWS) { - if(ch == '\r') { - normalizedCR = true; - //posEnd = pos -1; - //joinPC(); - // posEnd is alreadys set - if(!usePC) { - posEnd = pos -1; - if(posEnd > posStart) { - joinPC(); - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - //assert usePC == true; - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } else if(ch == '\n') { - if(!normalizedCR && usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } - normalizedCR = false; - } else { - if(usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = ch; - } - normalizedCR = false; - } - } - ch = more(); - } - } catch(EOFException ex) { - // detect EOF and create meaningful error ... - throw new XmlPullParserException( - "processing instruction started on line "+curLine+" and column "+curColumn - +" was not closed", - this, ex); - } - if(piTargetEnd == -1) { - piTargetEnd = pos - 2 + bufAbsoluteStart; - //throw new XmlPullParserException( - // "processing instruction must have PITarget name", this, null); - } - piTargetStart -= bufAbsoluteStart; - piTargetEnd -= bufAbsoluteStart; - if(tokenize) { - posEnd = pos - 2; - if(normalizeIgnorableWS) { - --pcEnd; - } - } - return true; - } - - // protected final static char[] VERSION = {'v','e','r','s','i','o','n'}; - // protected final static char[] NCODING = {'n','c','o','d','i','n','g'}; - // protected final static char[] TANDALONE = {'t','a','n','d','a','l','o','n','e'}; - // protected final static char[] YES = {'y','e','s'}; - // protected final static char[] NO = {'n','o'}; - - protected final static char[] VERSION = "version".toCharArray(); - protected final static char[] NCODING = "ncoding".toCharArray(); - protected final static char[] TANDALONE = "tandalone".toCharArray(); - protected final static char[] YES = "yes".toCharArray(); - protected final static char[] NO = "no".toCharArray(); - - - - protected void parseXmlDecl(char ch) - throws XmlPullParserException, IOException - { - // [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' - - // first make sure that relative positions will stay OK - preventBufferCompaction = true; - bufStart = 0; // necessary to keep pos unchanged during expansion! - - // --- parse VersionInfo - - // [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"') - // parse is positioned just on first S past <?xml - ch = skipS(ch); - ch = requireInput(ch, VERSION); - // [25] Eq ::= S? '=' S? - ch = skipS(ch); - if(ch != '=') { - throw new XmlPullParserException( - "expected equals sign (=) after version and not "+printable(ch), this, null); - } - ch = more(); - ch = skipS(ch); - if(ch != '\'' && ch != '"') { - throw new XmlPullParserException( - "expected apostrophe (') or quotation mark (\") after version and not " - +printable(ch), this, null); - } - final char quotChar = ch; - //int versionStart = pos + bufAbsoluteStart; // required if preventBufferCompaction==false - final int versionStart = pos; - ch = more(); - // [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+ - while(ch != quotChar) { - if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') - && ch != '_' && ch != '.' && ch != ':' && ch != '-') - { - throw new XmlPullParserException( - "<?xml version value expected to be in ([a-zA-Z0-9_.:] | '-')" - +" not "+printable(ch), this, null); - } - ch = more(); - } - final int versionEnd = pos - 1; - parseXmlDeclWithVersion(versionStart, versionEnd); - preventBufferCompaction = false; // allow again buffer commpaction - pos MAY chnage - } - //protected String xmlDeclVersion; - - protected void parseXmlDeclWithVersion(int versionStart, int versionEnd) - throws XmlPullParserException, IOException - { - // check version is "1.0" - if((versionEnd - versionStart != 3) - || buf[versionStart] != '1' - || buf[versionStart+1] != '.' - || buf[versionStart+2] != '0') - { - throw new XmlPullParserException( - "only 1.0 is supported as <?xml version not '" - +printable(new String(buf, versionStart, versionEnd - versionStart))+"'", this, null); - } - xmlDeclVersion = newString(buf, versionStart, versionEnd - versionStart); - - // [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" ) - char ch = more(); - ch = skipS(ch); - if(ch == 'e') { - ch = more(); - ch = requireInput(ch, NCODING); - ch = skipS(ch); - if(ch != '=') { - throw new XmlPullParserException( - "expected equals sign (=) after encoding and not "+printable(ch), this, null); - } - ch = more(); - ch = skipS(ch); - if(ch != '\'' && ch != '"') { - throw new XmlPullParserException( - "expected apostrophe (') or quotation mark (\") after encoding and not " - +printable(ch), this, null); - } - final char quotChar = ch; - final int encodingStart = pos; - ch = more(); - // [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* - if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z')) - { - throw new XmlPullParserException( - "<?xml encoding name expected to start with [A-Za-z]" - +" not "+printable(ch), this, null); - } - ch = more(); - while(ch != quotChar) { - if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') - && ch != '.' && ch != '_' && ch != '-') - { - throw new XmlPullParserException( - "<?xml encoding value expected to be in ([A-Za-z0-9._] | '-')" - +" not "+printable(ch), this, null); - } - ch = more(); - } - final int encodingEnd = pos - 1; - - - // TODO reconcile with setInput encodingName - inputEncoding = newString(buf, encodingStart, encodingEnd - encodingStart); - ch = more(); - } - - ch = skipS(ch); - // [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"')) - if(ch == 's') { - ch = more(); - ch = requireInput(ch, TANDALONE); - ch = skipS(ch); - if(ch != '=') { - throw new XmlPullParserException( - "expected equals sign (=) after standalone and not "+printable(ch), - this, null); - } - ch = more(); - ch = skipS(ch); - if(ch != '\'' && ch != '"') { - throw new XmlPullParserException( - "expected apostrophe (') or quotation mark (\") after encoding and not " - +printable(ch), this, null); - } - char quotChar = ch; - int standaloneStart = pos; - ch = more(); - if(ch == 'y') { - ch = requireInput(ch, YES); - //Boolean standalone = new Boolean(true); - xmlDeclStandalone = new Boolean(true); - } else if(ch == 'n') { - ch = requireInput(ch, NO); - //Boolean standalone = new Boolean(false); - xmlDeclStandalone = new Boolean(false); - } else { - throw new XmlPullParserException( - "expected 'yes' or 'no' after standalone and not " - +printable(ch), this, null); - } - if(ch != quotChar) { - throw new XmlPullParserException( - "expected "+quotChar+" after standalone value not " - +printable(ch), this, null); - } - ch = more(); - } - - - ch = skipS(ch); - if(ch != '?') { - throw new XmlPullParserException( - "expected ?> as last part of <?xml not " - +printable(ch), this, null); - } - ch = more(); - if(ch != '>') { - throw new XmlPullParserException( - "expected ?> as last part of <?xml not " - +printable(ch), this, null); - } - - } - protected void parseDocdecl() - throws XmlPullParserException, IOException - { - //ASSUMPTION: seen <!D - char ch = more(); - if(ch != 'O') throw new XmlPullParserException( - "expected <!DOCTYPE", this, null); - ch = more(); - if(ch != 'C') throw new XmlPullParserException( - "expected <!DOCTYPE", this, null); - ch = more(); - if(ch != 'T') throw new XmlPullParserException( - "expected <!DOCTYPE", this, null); - ch = more(); - if(ch != 'Y') throw new XmlPullParserException( - "expected <!DOCTYPE", this, null); - ch = more(); - if(ch != 'P') throw new XmlPullParserException( - "expected <!DOCTYPE", this, null); - ch = more(); - if(ch != 'E') throw new XmlPullParserException( - "expected <!DOCTYPE", this, null); - posStart = pos; - // do simple and crude scanning for end of doctype - - // [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' - // (markupdecl | DeclSep)* ']' S?)? '>' - int bracketLevel = 0; - final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; - boolean normalizedCR = false; - while(true) { - ch = more(); - if(ch == '[') ++bracketLevel; - if(ch == ']') --bracketLevel; - if(ch == '>' && bracketLevel == 0) break; - if(normalizeIgnorableWS) { - if(ch == '\r') { - normalizedCR = true; - //posEnd = pos -1; - //joinPC(); - // posEnd is alreadys set - if(!usePC) { - posEnd = pos -1; - if(posEnd > posStart) { - joinPC(); - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - //assert usePC == true; - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } else if(ch == '\n') { - if(!normalizedCR && usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } - normalizedCR = false; - } else { - if(usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = ch; - } - normalizedCR = false; - } - } - - } - posEnd = pos - 1; - } - - protected void parseCDSect(boolean hadCharData) - throws XmlPullParserException, IOException - { - // implements XML 1.0 Section 2.7 CDATA Sections - - // [18] CDSect ::= CDStart CData CDEnd - // [19] CDStart ::= '<![CDATA[' - // [20] CData ::= (Char* - (Char* ']]>' Char*)) - // [21] CDEnd ::= ']]>' - - //ASSUMPTION: seen <![ - char ch = more(); - if(ch != 'C') throw new XmlPullParserException( - "expected <[CDATA[ for comment start", this, null); - ch = more(); - if(ch != 'D') throw new XmlPullParserException( - "expected <[CDATA[ for comment start", this, null); - ch = more(); - if(ch != 'A') throw new XmlPullParserException( - "expected <[CDATA[ for comment start", this, null); - ch = more(); - if(ch != 'T') throw new XmlPullParserException( - "expected <[CDATA[ for comment start", this, null); - ch = more(); - if(ch != 'A') throw new XmlPullParserException( - "expected <[CDATA[ for comment start", this, null); - ch = more(); - if(ch != '[') throw new XmlPullParserException( - "expected <![CDATA[ for comment start", this, null); - - //if(tokenize) { - final int cdStart = pos + bufAbsoluteStart; - final int curLine = lineNumber; - final int curColumn = columnNumber; - final boolean normalizeInput = tokenize == false || roundtripSupported == false; - try { - if(normalizeInput) { - if(hadCharData) { - if(!usePC) { - // posEnd is correct already!!! - if(posEnd > posStart) { - joinPC(); - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - } - } - boolean seenBracket = false; - boolean seenBracketBracket = false; - boolean normalizedCR = false; - while(true) { - // scan until it hits "]]>" - ch = more(); - if(ch == ']') { - if(!seenBracket) { - seenBracket = true; - } else { - seenBracketBracket = true; - //seenBracket = false; - } - } else if(ch == '>') { - if(seenBracket && seenBracketBracket) { - break; // found end sequence!!!! - } else { - seenBracketBracket = false; - } - seenBracket = false; - } else { - if(seenBracket) { - seenBracket = false; - } - } - if(normalizeInput) { - // deal with normalization issues ... - if(ch == '\r') { - normalizedCR = true; - posStart = cdStart - bufAbsoluteStart; - posEnd = pos - 1; // posEnd is alreadys set - if(!usePC) { - if(posEnd > posStart) { - joinPC(); - } else { - usePC = true; - pcStart = pcEnd = 0; - } - } - //assert usePC == true; - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } else if(ch == '\n') { - if(!normalizedCR && usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = '\n'; - } - normalizedCR = false; - } else { - if(usePC) { - if(pcEnd >= pc.length) ensurePC(pcEnd); - pc[pcEnd++] = ch; - } - normalizedCR = false; - } - } - } - } catch(EOFException ex) { - // detect EOF and create meaningful error ... - throw new XmlPullParserException( - "CDATA section started on line "+curLine+" and column "+curColumn+" was not closed", - this, ex); - } - if(normalizeInput) { - if(usePC) { - pcEnd = pcEnd - 2; - } - } - posStart = cdStart - bufAbsoluteStart; - posEnd = pos - 3; - } - - protected void fillBuf() throws IOException, XmlPullParserException { - if(reader == null) throw new XmlPullParserException( - "reader must be set before parsing is started"); - - // see if we are in compaction area - if(bufEnd > bufSoftLimit) { - - // expand buffer it makes sense!!!! - boolean compact = bufStart > bufSoftLimit; - boolean expand = false; - if(preventBufferCompaction) { - compact = false; - expand = true; - } else if(!compact) { - //freeSpace - if(bufStart < buf.length / 2) { - // less then half buffer available forcompactin --> expand instead!!! - expand = true; - } else { - // at least half of buffer can be reclaimed --> worthwhile effort!!! - compact = true; - } - } - - // if buffer almost full then compact it - if(compact) { - //TODO: look on trashing - // //assert bufStart > 0 - System.arraycopy(buf, bufStart, buf, 0, bufEnd - bufStart); - if(TRACE_SIZING) System.out.println( - "TRACE_SIZING fillBuf() compacting "+bufStart - +" bufEnd="+bufEnd - +" pos="+pos+" posStart="+posStart+" posEnd="+posEnd - +" buf first 100 chars:"+new String(buf, bufStart, - bufEnd - bufStart < 100 ? bufEnd - bufStart : 100 )); - - } else if(expand) { - final int newSize = 2 * buf.length; - final char newBuf[] = new char[ newSize ]; - if(TRACE_SIZING) System.out.println("TRACE_SIZING fillBuf() "+buf.length+" => "+newSize); - System.arraycopy(buf, bufStart, newBuf, 0, bufEnd - bufStart); - buf = newBuf; - if(bufLoadFactor > 0) { - bufSoftLimit = ( bufLoadFactor * buf.length ) /100; - } - - } else { - throw new XmlPullParserException("internal error in fillBuffer()"); - } - bufEnd -= bufStart; - pos -= bufStart; - posStart -= bufStart; - posEnd -= bufStart; - bufAbsoluteStart += bufStart; - bufStart = 0; - if(TRACE_SIZING) System.out.println( - "TRACE_SIZING fillBuf() after bufEnd="+bufEnd - +" pos="+pos+" posStart="+posStart+" posEnd="+posEnd - +" buf first 100 chars:"+new String(buf, 0, bufEnd < 100 ? bufEnd : 100)); - } - // at least one charcter must be read or error - final int len = buf.length - bufEnd > READ_CHUNK_SIZE ? READ_CHUNK_SIZE : buf.length - bufEnd; - final int ret = reader.read(buf, bufEnd, len); - if(ret > 0) { - bufEnd += ret; - if(TRACE_SIZING) System.out.println( - "TRACE_SIZING fillBuf() after filling in buffer" - +" buf first 100 chars:"+new String(buf, 0, bufEnd < 100 ? bufEnd : 100)); - - return; - } - if(ret == -1) { - if(bufAbsoluteStart == 0 && pos == 0) { - throw new EOFException("input contained no data"); - } else { - if(seenRoot && depth == 0) { // inside parsing epilog!!! - reachedEnd = true; - return; - } else { - StringBuffer expectedTagStack = new StringBuffer(); - if(depth > 0) { - //final char[] cbuf = elRawName[depth]; - //final String startname = new String(cbuf, 0, elRawNameEnd[depth]); - expectedTagStack.append(" - expected end tag"); - if(depth > 1) { - expectedTagStack.append("s"); //more than one end tag - } - expectedTagStack.append(" "); - for (int i = depth; i > 0; i--) - { - String tagName = new String(elRawName[i], 0, elRawNameEnd[i]); - expectedTagStack.append("</").append(tagName).append('>'); - } - expectedTagStack.append(" to close"); - for (int i = depth; i > 0; i--) - { - if(i != depth) { - expectedTagStack.append(" and"); //more than one end tag - } - String tagName = new String(elRawName[i], 0, elRawNameEnd[i]); - expectedTagStack.append(" start tag <"+tagName+">"); - expectedTagStack.append(" from line "+elRawNameLine[i]); - } - expectedTagStack.append(", parser stopped on"); - } - throw new EOFException("no more data available" - +expectedTagStack.toString()+getPositionDescription()); - } - } - } else { - throw new IOException("error reading input, returned "+ret); - } - } - - protected char more() throws IOException, XmlPullParserException { - if(pos >= bufEnd) { - fillBuf(); - // this return value should be ignonored as it is used in epilog parsing ... - if(reachedEnd) return (char)-1; - } - final char ch = buf[pos++]; - //line/columnNumber - if(ch == '\n') { ++lineNumber; columnNumber = 1; } - else { ++columnNumber; } - //System.out.print(ch); - return ch; - } - - // /** - // * This function returns position of parser in XML input stream - // * (how many <b>characters</b> were processed. - // * <p><b>NOTE:</b> this logical position and not byte offset as encodings - // * such as UTF8 may use more than one byte to encode one character. - // */ - // public int getCurrentInputPosition() { - // return pos + bufAbsoluteStart; - // } - - protected void ensurePC(int end) { - //assert end >= pc.length; - final int newSize = end > READ_CHUNK_SIZE ? 2 * end : 2 * READ_CHUNK_SIZE; - final char[] newPC = new char[ newSize ]; - if(TRACE_SIZING) System.out.println("TRACE_SIZING ensurePC() "+pc.length+" ==> "+newSize+" end="+end); - System.arraycopy(pc, 0, newPC, 0, pcEnd); - pc = newPC; - //assert end < pc.length; - } - - protected void joinPC() { - //assert usePC == false; - //assert posEnd > posStart; - final int len = posEnd - posStart; - final int newEnd = pcEnd + len + 1; - if(newEnd >= pc.length) ensurePC(newEnd); // add 1 for extra space for one char - //assert newEnd < pc.length; - System.arraycopy(buf, posStart, pc, pcEnd, len); - pcEnd += len; - usePC = true; - - } - - protected char requireInput(char ch, char[] input) - throws XmlPullParserException, IOException - { - for (int i = 0; i < input.length; i++) - { - if(ch != input[i]) { - throw new XmlPullParserException( - "expected "+printable(input[i])+" in "+new String(input) - +" and not "+printable(ch), this, null); - } - ch = more(); - } - return ch; - } - - protected char requireNextS() - throws XmlPullParserException, IOException - { - final char ch = more(); - if(!isS(ch)) { - throw new XmlPullParserException( - "white space is required and not "+printable(ch), this, null); - } - return skipS(ch); - } - - protected char skipS(char ch) - throws XmlPullParserException, IOException - { - while(isS(ch)) { ch = more(); } // skip additional spaces - return ch; - } - - // nameStart / name lookup tables based on XML 1.1 http://www.w3.org/TR/2001/WD-xml11-20011213/ - protected static final int LOOKUP_MAX = 0x400; - protected static final char LOOKUP_MAX_CHAR = (char)LOOKUP_MAX; - // protected static int lookupNameStartChar[] = new int[ LOOKUP_MAX_CHAR / 32 ]; - // protected static int lookupNameChar[] = new int[ LOOKUP_MAX_CHAR / 32 ]; - protected static boolean lookupNameStartChar[] = new boolean[ LOOKUP_MAX ]; - protected static boolean lookupNameChar[] = new boolean[ LOOKUP_MAX ]; - - private static final void setName(char ch) - //{ lookupNameChar[ (int)ch / 32 ] |= (1 << (ch % 32)); } - { lookupNameChar[ ch ] = true; } - private static final void setNameStart(char ch) - //{ lookupNameStartChar[ (int)ch / 32 ] |= (1 << (ch % 32)); setName(ch); } - { lookupNameStartChar[ ch ] = true; setName(ch); } - - static { - setNameStart(':'); - for (char ch = 'A'; ch <= 'Z'; ++ch) setNameStart(ch); - setNameStart('_'); - for (char ch = 'a'; ch <= 'z'; ++ch) setNameStart(ch); - for (char ch = '\u00c0'; ch <= '\u02FF'; ++ch) setNameStart(ch); - for (char ch = '\u0370'; ch <= '\u037d'; ++ch) setNameStart(ch); - for (char ch = '\u037f'; ch < '\u0400'; ++ch) setNameStart(ch); - - setName('-'); - setName('.'); - for (char ch = '0'; ch <= '9'; ++ch) setName(ch); - setName('\u00b7'); - for (char ch = '\u0300'; ch <= '\u036f'; ++ch) setName(ch); - } - - //private final static boolean isNameStartChar(char ch) { - protected boolean isNameStartChar(char ch) { - return (ch < LOOKUP_MAX_CHAR && lookupNameStartChar[ ch ]) - || (ch >= LOOKUP_MAX_CHAR && ch <= '\u2027') - || (ch >= '\u202A' && ch <= '\u218F') - || (ch >= '\u2800' && ch <= '\uFFEF') - ; - - // if(ch < LOOKUP_MAX_CHAR) return lookupNameStartChar[ ch ]; - // else return ch <= '\u2027' - // || (ch >= '\u202A' && ch <= '\u218F') - // || (ch >= '\u2800' && ch <= '\uFFEF') - // ; - //return false; - // return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':' - // || (ch >= '0' && ch <= '9'); - // if(ch < LOOKUP_MAX_CHAR) return (lookupNameStartChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0; - // if(ch <= '\u2027') return true; - // //[#x202A-#x218F] - // if(ch < '\u202A') return false; - // if(ch <= '\u218F') return true; - // // added pairts [#x2800-#xD7FF] | [#xE000-#xFDCF] | [#xFDE0-#xFFEF] | [#x10000-#x10FFFF] - // if(ch < '\u2800') return false; - // if(ch <= '\uFFEF') return true; - // return false; - - - // else return (supportXml11 && ( (ch < '\u2027') || (ch > '\u2029' && ch < '\u2200') ... - } - - //private final static boolean isNameChar(char ch) { - protected boolean isNameChar(char ch) { - //return isNameStartChar(ch); - - // if(ch < LOOKUP_MAX_CHAR) return (lookupNameChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0; - - return (ch < LOOKUP_MAX_CHAR && lookupNameChar[ ch ]) - || (ch >= LOOKUP_MAX_CHAR && ch <= '\u2027') - || (ch >= '\u202A' && ch <= '\u218F') - || (ch >= '\u2800' && ch <= '\uFFEF') - ; - //return false; - // return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':' - // || (ch >= '0' && ch <= '9'); - // if(ch < LOOKUP_MAX_CHAR) return (lookupNameStartChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0; - - //else return - // else if(ch <= '\u2027') return true; - // //[#x202A-#x218F] - // else if(ch < '\u202A') return false; - // else if(ch <= '\u218F') return true; - // // added pairts [#x2800-#xD7FF] | [#xE000-#xFDCF] | [#xFDE0-#xFFEF] | [#x10000-#x10FFFF] - // else if(ch < '\u2800') return false; - // else if(ch <= '\uFFEF') return true; - //else return false; - } - - protected boolean isS(char ch) { - return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'); - // || (supportXml11 && (ch == '\u0085' || ch == '\u2028'); - } - - //protected boolean isChar(char ch) { return (ch < '\uD800' || ch > '\uDFFF') - // ch != '\u0000' ch < '\uFFFE' - - - //protected char printable(char ch) { return ch; } - protected String printable(char ch) { - if(ch == '\n') { - return "\\n"; - } else if(ch == '\r') { - return "\\r"; - } else if(ch == '\t') { - return "\\t"; - } else if(ch == '\'') { - return "\\'"; - } if(ch > 127 || ch < 32) { - return "\\u"+Integer.toHexString((int)ch); - } - return ""+ch; - } - - protected String printable(String s) { - if(s == null) return null; - final int sLen = s.length(); - StringBuffer buf = new StringBuffer(sLen + 10); - for(int i = 0; i < sLen; ++i) { - buf.append(printable(s.charAt(i))); - } - s = buf.toString(); - return s; - } - -// -// Imported code from ASF Harmony project rev 770909 -// http://svn.apache.org/repos/asf/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Character.java -// - - private static int toCodePoint( char high, char low ) - { - // See RFC 2781, Section 2.2 - // http://www.faqs.org/rfcs/rfc2781.html - int h = ( high & 0x3FF ) << 10; - int l = low & 0x3FF; - return ( h | l ) + 0x10000; - } - - private static final char MIN_HIGH_SURROGATE = '\uD800'; - private static final char MAX_HIGH_SURROGATE = '\uDBFF'; - - private static boolean isHighSurrogate( char ch ) - { - return ( MIN_HIGH_SURROGATE <= ch && MAX_HIGH_SURROGATE >= ch ); - } - - private static final int MIN_CODE_POINT = 0x000000; - private static final int MAX_CODE_POINT = 0x10FFFF; - private static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000; - - private static boolean isValidCodePoint( int codePoint ) - { - return ( MIN_CODE_POINT <= codePoint && MAX_CODE_POINT >= codePoint ); - } - - private static boolean isSupplementaryCodePoint( int codePoint ) - { - return ( MIN_SUPPLEMENTARY_CODE_POINT <= codePoint && MAX_CODE_POINT >= codePoint ); - } - - /** - * TODO add javadoc - * - * @param codePoint - * @return - */ - public static char[] toChars( int codePoint ) - { - if ( !isValidCodePoint( codePoint ) ) - { - throw new IllegalArgumentException(); - } - - if ( isSupplementaryCodePoint( codePoint ) ) - { - int cpPrime = codePoint - 0x10000; - int high = 0xD800 | ( ( cpPrime >> 10 ) & 0x3FF ); - int low = 0xDC00 | ( cpPrime & 0x3FF ); - return new char[] { (char) high, (char) low }; - } - - return new char[] { (char) codePoint }; - } -} - - -/* - * Indiana University Extreme! Lab Software License, Version 1.2 - * - * Copyright (C) 2003 The Trustees of Indiana University. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1) All redistributions of source code must retain the above - * copyright notice, the list of authors in the original source - * code, this list of conditions and the disclaimer listed in this - * license; - * - * 2) All redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the disclaimer - * listed in this license in the documentation and/or other - * materials provided with the distribution; - * - * 3) Any documentation included with all redistributions must include - * the following acknowledgement: - * - * "This product includes software developed by the Indiana - * University Extreme! Lab. For further information please visit - * http://www.extreme.indiana.edu/" - * - * Alternatively, this acknowledgment may appear in the software - * itself, and wherever such third-party acknowledgments normally - * appear. - * - * 4) The name "Indiana University" or "Indiana University - * Extreme! Lab" shall not be used to endorse or promote - * products derived from this software without prior written - * permission from Indiana University. For written permission, - * please contact http://www.extreme.indiana.edu/. - * - * 5) Products derived from this software may not use "Indiana - * University" name nor may "Indiana University" appear in their name, - * without prior written permission of the Indiana University. - * - * Indiana University provides no reassurances that the source code - * provided does not infringe the patent or any other intellectual - * property rights of any other entity. Indiana University disclaims any - * liability to any recipient for claims brought by any other entity - * based on infringement of intellectual property rights or otherwise. - * - * LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH - * NO WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA - * UNIVERSITY GIVES NO WARRANTIES AND MAKES NO REPRESENTATION THAT - * SOFTWARE IS FREE OF INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR - * OTHER PROPRIETARY RIGHTS. INDIANA UNIVERSITY MAKES NO WARRANTIES THAT - * SOFTWARE IS FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP - * DOORS", "WORMS", OR OTHER HARMFUL CODE. LICENSEE ASSUMES THE ENTIRE - * RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR ASSOCIATED MATERIALS, - * AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION GENERATED USING - * SOFTWARE. - */ - - - - - - diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,1122 +0,0 @@ -/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/ -// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/) - -package org.codehaus.plexus.util.xml.pull; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; - -/** - * Implementation of XmlSerializer interface from XmlPull V1 API. - * This implementation is optimized for performance and low memory footprint. - * - * <p>Implemented features:<ul> - * <li> FEATURE_NAMES_INTERNED - when enabled all returned names - * (namespaces, prefixes) will be interned and it is required that - * all names passed as arguments MUST be interned - * <li> FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE - * </ul> - * <p>Implemented properties:<ul> - * <li> PROPERTY_SERIALIZER_INDENTATION - * <li> PROPERTY_SERIALIZER_LINE_SEPARATOR - * </ul> - * - */ -@Deprecated -public class MXSerializer implements XmlSerializer { - protected final static String XML_URI = "http://www.w3.org/XML/1998/namespace"; - protected final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; - private static final boolean TRACE_SIZING = false; - - protected final String FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE = - "http://xmlpull.org/v1/doc/features.html#serializer-attvalue-use-apostrophe"; - protected final String FEATURE_NAMES_INTERNED = - "http://xmlpull.org/v1/doc/features.html#names-interned"; - protected final String PROPERTY_SERIALIZER_INDENTATION = - "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"; - protected final String PROPERTY_SERIALIZER_LINE_SEPARATOR = - "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator"; - protected final static String PROPERTY_LOCATION = - "http://xmlpull.org/v1/doc/properties.html#location"; - - // properties/features - protected boolean namesInterned; - protected boolean attributeUseApostrophe; - protected String indentationString = null; //" "; - protected String lineSeparator = "\n"; - - protected String location; - protected Writer out; - - protected int autoDeclaredPrefixes; - - protected int depth = 0; - - // element stack - protected String elNamespace[] = new String[ 2 ]; - protected String elName[] = new String[ elNamespace.length ]; - protected int elNamespaceCount[] = new int[ elNamespace.length ]; - - //namespace stack - protected int namespaceEnd = 0; - protected String namespacePrefix[] = new String[ 8 ]; - protected String namespaceUri[] = new String[ namespacePrefix.length ]; - - protected boolean finished; - protected boolean pastRoot; - protected boolean setPrefixCalled; - protected boolean startTagIncomplete; - - protected boolean doIndent; - protected boolean seenTag; - - protected boolean seenBracket; - protected boolean seenBracketBracket; - - // buffer output if needed to write escaped String see text(String) - private static final int BUF_LEN = Runtime.getRuntime().freeMemory() > 1000000L ? 8*1024 : 256; - protected char buf[] = new char[ BUF_LEN ]; - - - protected static final String precomputedPrefixes[]; - - static { - precomputedPrefixes = new String[32]; //arbitrary number ... - for (int i = 0; i < precomputedPrefixes.length; i++) - { - precomputedPrefixes[i] = ("n"+i).intern(); - } - } - - private boolean checkNamesInterned = false; - - private void checkInterning(String name) { - if(namesInterned && name != name.intern()) { - throw new IllegalArgumentException( - "all names passed as arguments must be interned" - +"when NAMES INTERNED feature is enabled"); - } - } - - protected void reset() { - location = null; - out = null; - autoDeclaredPrefixes = 0; - depth = 0; - - // nullify references on all levels to allow it to be GCed - for (int i = 0; i < elNamespaceCount.length; i++) - { - elName[ i ] = null; - elNamespace[ i ] = null; - elNamespaceCount[ i ] = 2; - } - - - namespaceEnd = 0; - - - //NOTE: no need to intern() as all literal strings and string-valued constant expressions - //are interned. String literals are defined in 3.10.5 of the Java Language Specification - // just checking ... - //assert "xmlns" == "xmlns".intern(); - //assert XMLNS_URI == XMLNS_URI.intern(); - - //TODO: how to prevent from reporting this namespace? - // this is special namespace declared for consistency with XML infoset - namespacePrefix[ namespaceEnd ] = "xmlns"; - namespaceUri[ namespaceEnd ] = XMLNS_URI; - ++namespaceEnd; - - namespacePrefix[ namespaceEnd ] = "xml"; - namespaceUri[ namespaceEnd ] = XML_URI; - ++namespaceEnd; - - finished = false; - pastRoot = false; - setPrefixCalled = false; - startTagIncomplete = false; - //doIntent is not changed - seenTag = false; - - seenBracket = false; - seenBracketBracket = false; - } - - - protected void ensureElementsCapacity() { - final int elStackSize = elName.length; - //assert (depth + 1) >= elName.length; - // we add at least one extra slot ... - final int newSize = (depth >= 7 ? 2 * depth : 8) + 2; // = lucky 7 + 1 //25 - if(TRACE_SIZING) { - System.err.println( - getClass().getName()+" elStackSize "+elStackSize+" ==> "+newSize); - } - final boolean needsCopying = elStackSize > 0; - String[] arr = null; - // reuse arr local variable slot - arr = new String[newSize]; - if(needsCopying) System.arraycopy(elName, 0, arr, 0, elStackSize); - elName = arr; - arr = new String[newSize]; - if(needsCopying) System.arraycopy(elNamespace, 0, arr, 0, elStackSize); - elNamespace = arr; - - final int[] iarr = new int[newSize]; - if(needsCopying) { - System.arraycopy(elNamespaceCount, 0, iarr, 0, elStackSize); - } else { - // special initialization - iarr[0] = 0; - } - elNamespaceCount = iarr; - } - - protected void ensureNamespacesCapacity() { //int size) { - //int namespaceSize = namespacePrefix != null ? namespacePrefix.length : 0; - //assert (namespaceEnd >= namespacePrefix.length); - - //if(size >= namespaceSize) { - //int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25 - final int newSize = namespaceEnd > 7 ? 2 * namespaceEnd : 8; - if(TRACE_SIZING) { - System.err.println( - getClass().getName()+" namespaceSize "+namespacePrefix.length+" ==> "+newSize); - } - final String[] newNamespacePrefix = new String[newSize]; - final String[] newNamespaceUri = new String[newSize]; - if(namespacePrefix != null) { - System.arraycopy( - namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd); - System.arraycopy( - namespaceUri, 0, newNamespaceUri, 0, namespaceEnd); - } - namespacePrefix = newNamespacePrefix; - namespaceUri = newNamespaceUri; - - // TODO use hashes for quick namespace->prefix lookups - // if( ! allStringsInterned ) { - // int[] newNamespacePrefixHash = new int[newSize]; - // if(namespacePrefixHash != null) { - // System.arraycopy( - // namespacePrefixHash, 0, newNamespacePrefixHash, 0, namespaceEnd); - // } - // namespacePrefixHash = newNamespacePrefixHash; - // } - //prefixesSize = newSize; - // ////assert nsPrefixes.length > size && nsPrefixes.length == newSize - //} - } - - - public void setFeature(String name, - boolean state) throws IllegalArgumentException, IllegalStateException - { - if(name == null) { - throw new IllegalArgumentException("feature name can not be null"); - } - if(FEATURE_NAMES_INTERNED.equals(name)) { - namesInterned = state; - } else if(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals(name)) { - attributeUseApostrophe = state; - } else { - throw new IllegalStateException("unsupported feature "+name); - } - } - - public boolean getFeature(String name) throws IllegalArgumentException - { - if(name == null) { - throw new IllegalArgumentException("feature name can not be null"); - } - if(FEATURE_NAMES_INTERNED.equals(name)) { - return namesInterned; - } else if(FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals(name)) { - return attributeUseApostrophe; - } else { - return false; - } - } - - // precomputed variables to simplify writing indentation - protected int offsetNewLine; - protected int indentationJump; - protected char[] indentationBuf; - protected int maxIndentLevel; - protected boolean writeLineSepartor; //should end-of-line be written - protected boolean writeIndentation; // is indentation used? - - /** - * For maximum efficiency when writing indents the required output is pre-computed - * This is internal function that recomputes buffer after user requested chnages. - */ - protected void rebuildIndentationBuf() { - if(doIndent == false) return; - final int maxIndent = 65; //hardcoded maximum indentation size in characters - int bufSize = 0; - offsetNewLine = 0; - if(writeLineSepartor) { - offsetNewLine = lineSeparator.length(); - bufSize += offsetNewLine; - } - maxIndentLevel = 0; - if(writeIndentation) { - indentationJump = indentationString.length(); - maxIndentLevel = maxIndent / indentationJump; - bufSize += maxIndentLevel * indentationJump; - } - if(indentationBuf == null || indentationBuf.length < bufSize) { - indentationBuf = new char[bufSize + 8]; - } - int bufPos = 0; - if(writeLineSepartor) { - for (int i = 0; i < lineSeparator.length(); i++) - { - indentationBuf[ bufPos++ ] = lineSeparator.charAt(i); - } - } - if(writeIndentation) { - for (int i = 0; i < maxIndentLevel; i++) - { - for (int j = 0; j < indentationString.length(); j++) - { - indentationBuf[ bufPos++ ] = indentationString.charAt(j); - } - } - } - } - - // if(doIndent) writeIndent(); - protected void writeIndent() throws IOException { - final int start = writeLineSepartor ? 0 : offsetNewLine; - final int level = (depth > maxIndentLevel) ? maxIndentLevel : depth; - out.write( indentationBuf, start, (level * indentationJump) + offsetNewLine); - } - - public void setProperty(String name, - Object value) throws IllegalArgumentException, IllegalStateException - { - if(name == null) { - throw new IllegalArgumentException("property name can not be null"); - } - if(PROPERTY_SERIALIZER_INDENTATION.equals(name)) { - indentationString = (String)value; - } else if(PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) { - lineSeparator = (String)value; - } else if(PROPERTY_LOCATION.equals(name)) { - location = (String) value; - } else { - throw new IllegalStateException("unsupported property "+name); - } - writeLineSepartor = lineSeparator != null && lineSeparator.length() > 0; - writeIndentation = indentationString != null && indentationString.length() > 0; - // optimize - do not write when nothing to write ... - doIndent = indentationString != null && (writeLineSepartor || writeIndentation); - //NOTE: when indentationString == null there is no indentation - // (even though writeLineSeparator may be true ...) - rebuildIndentationBuf(); - seenTag = false; // for consistency - } - - public Object getProperty(String name) throws IllegalArgumentException - { - if(name == null) { - throw new IllegalArgumentException("property name can not be null"); - } - if(PROPERTY_SERIALIZER_INDENTATION.equals(name)) { - return indentationString; - } else if(PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) { - return lineSeparator; - } else if(PROPERTY_LOCATION.equals(name)) { - return location; - } else { - return null; - } - } - - private String getLocation() { - return location != null ? " @"+location : ""; - } - - // this is special method that can be accessed directly to retrieve Writer serializer is using - public Writer getWriter() - { - return out; - } - - public void setOutput(Writer writer) - { - reset(); - out = writer; - } - - public void setOutput(OutputStream os, String encoding) throws IOException - { - if(os == null) throw new IllegalArgumentException("output stream can not be null"); - reset(); - if(encoding != null) { - out = new OutputStreamWriter(os, encoding); - } else { - out = new OutputStreamWriter(os); - } - } - - public void startDocument (String encoding, Boolean standalone) throws IOException - { - char apos = attributeUseApostrophe ? '\'' : '"'; - if(attributeUseApostrophe) { - out.write("<?xml version='1.0'"); - } else { - out.write("<?xml version=\"1.0\""); - } - if(encoding != null) { - out.write(" encoding="); - out.write(attributeUseApostrophe ? '\'' : '"'); - out.write(encoding); - out.write(attributeUseApostrophe ? '\'' : '"'); - //out.write('\''); - } - if(standalone != null) { - out.write(" standalone="); - out.write(attributeUseApostrophe ? '\'' : '"'); - if(standalone.booleanValue()) { - out.write("yes"); - } else { - out.write("no"); - } - out.write(attributeUseApostrophe ? '\'' : '"'); - // if(standalone.booleanValue()) { - // out.write(" standalone='yes'"); - // } else { - // out.write(" standalone='no'"); - // } - } - out.write("?>"); - if(writeLineSepartor) { - out.write(lineSeparator); - } - } - - public void endDocument() throws IOException - { - // close all unclosed tag; - while(depth > 0) { - endTag(elNamespace[ depth ], elName[ depth ]); - } - if(writeLineSepartor) { - out.write(lineSeparator); - } - //assert depth == 0; - //assert startTagIncomplete == false; - finished = pastRoot = startTagIncomplete = true; - out.flush(); - } - - public void setPrefix(String prefix, String namespace) throws IOException - { - if(startTagIncomplete) closeStartTag(); - //assert prefix != null; - //assert namespace != null; - if (prefix == null) { - prefix = ""; - } - if(!namesInterned) { - prefix = prefix.intern(); //will throw NPE if prefix==null - } else if(checkNamesInterned) { - checkInterning(prefix); - } else if(prefix == null) { - throw new IllegalArgumentException("prefix must be not null"+getLocation()); - } - - //check that prefix is not duplicated ... - for (int i = elNamespaceCount[ depth ]; i < namespaceEnd; i++) - { - if(prefix == namespacePrefix[ i ]) { - throw new IllegalStateException("duplicated prefix "+printable(prefix)+getLocation()); - } - } - - if(!namesInterned) { - namespace = namespace.intern(); - } else if(checkNamesInterned) { - checkInterning(namespace); - } else if(namespace == null) { - throw new IllegalArgumentException("namespace must be not null"+getLocation()); - } - - if(namespaceEnd >= namespacePrefix.length) { - ensureNamespacesCapacity(); - } - namespacePrefix[ namespaceEnd ] = prefix; - namespaceUri[ namespaceEnd ] = namespace; - ++namespaceEnd; - setPrefixCalled = true; - } - - protected String lookupOrDeclarePrefix( String namespace ) { - return getPrefix(namespace, true); - } - - public String getPrefix(String namespace, boolean generatePrefix) - { - //assert namespace != null; - if(!namesInterned) { - // when String is interned we can do much faster namespace stack lookups ... - namespace = namespace.intern(); - } else if(checkNamesInterned) { - checkInterning(namespace); - //assert namespace != namespace.intern(); - } - if(namespace == null) { - throw new IllegalArgumentException("namespace must be not null"+getLocation()); - } else if(namespace.length() == 0) { - throw new IllegalArgumentException("default namespace cannot have prefix"+getLocation()); - } - - // first check if namespace is already in scope - for (int i = namespaceEnd - 1; i >= 0 ; --i) - { - if(namespace == namespaceUri[ i ]) { - final String prefix = namespacePrefix[ i ]; - // now check that prefix is still in scope - for (int p = namespaceEnd - 1; p > i ; --p) - { - if(prefix == namespacePrefix[ p ]) - continue; // too bad - prefix is redeclared with different namespace - } - return prefix; - } - } - - // so not found it ... - if(!generatePrefix) { - return null; - } - return generatePrefix(namespace); - } - - private String generatePrefix(String namespace) { - //assert namespace == namespace.intern(); - while(true) { - ++autoDeclaredPrefixes; - //fast lookup uses table that was pre-initialized in static{} .... - final String prefix = autoDeclaredPrefixes < precomputedPrefixes.length - ? precomputedPrefixes[autoDeclaredPrefixes] : ("n"+autoDeclaredPrefixes).intern(); - // make sure this prefix is not declared in any scope (avoid hiding in-scope prefixes)! - for (int i = namespaceEnd - 1; i >= 0 ; --i) - { - if(prefix == namespacePrefix[ i ]) { - continue; // prefix is already declared - generate new and try again - } - } - // declare prefix - - if(namespaceEnd >= namespacePrefix.length) { - ensureNamespacesCapacity(); - } - namespacePrefix[ namespaceEnd ] = prefix; - namespaceUri[ namespaceEnd ] = namespace; - ++namespaceEnd; - - return prefix; - } - } - - public int getDepth() - { - return depth; - } - - public String getNamespace () - { - return elNamespace[depth]; - } - - public String getName() - { - return elName[depth]; - } - - public XmlSerializer startTag (String namespace, String name) throws IOException - { - - if(startTagIncomplete) { - closeStartTag(); - } - seenBracket = seenBracketBracket = false; - if(doIndent && depth > 0 && seenTag) { - writeIndent(); - } - seenTag = true; - setPrefixCalled = false; - startTagIncomplete = true; - ++depth; - if( (depth + 1) >= elName.length) { - ensureElementsCapacity(); - } - ////assert namespace != null; - - if(checkNamesInterned && namesInterned) checkInterning(namespace); - elNamespace[ depth ] = (namesInterned || namespace == null) ? namespace : namespace.intern(); - //assert name != null; - //elName[ depth ] = name; - if(checkNamesInterned && namesInterned) checkInterning(name); - elName[ depth ] = (namesInterned || name == null) ? name : name.intern(); - if(out == null) { - throw new IllegalStateException("setOutput() must called set before serialization can start"); - } - out.write('<'); - if(namespace != null) { - - if(namespace.length() > 0) { - //ALEK: in future make it as feature on serializer - String prefix = null; - if(depth > 0 && (namespaceEnd - elNamespaceCount[depth-1]) == 1) { - // if only one prefix was declared un-declare it if prefix is already declared on parent el with the same URI - String uri = namespaceUri[namespaceEnd-1]; - if(uri == namespace || uri.equals(namespace)) { - String elPfx = namespacePrefix[namespaceEnd-1]; - // 2 == to skip predefined namespaces (xml and xmlns ...) - for(int pos = elNamespaceCount[depth-1] - 1; pos >= 2; --pos ) { - String pf = namespacePrefix[pos]; - if(pf == elPfx || pf.equals(elPfx)) { - String n = namespaceUri[pos]; - if(n == uri || n.equals(uri)) { - --namespaceEnd; //un-declare namespace - prefix = elPfx; - } - break; - } - } - } - } - if(prefix == null) { - prefix = lookupOrDeclarePrefix( namespace ); - } - //assert prefix != null; - // make sure that default ("") namespace to not print ":" - if(prefix.length() > 0) { - out.write(prefix); - out.write(':'); - } - } else { - // make sure that default namespace can be declared - for (int i = namespaceEnd - 1; i >= 0 ; --i) - { - if(namespacePrefix[ i ] == "") { - final String uri = namespaceUri[ i ]; - if(uri == null) { - // declare default namespace - setPrefix("", ""); - } else if(uri.length() > 0) { - throw new IllegalStateException( - "start tag can not be written in empty default namespace "+ - "as default namespace is currently bound to '"+uri+"'"+getLocation()); - } - break; - } - } - } - - } - out.write(name); - return this; - } - - public XmlSerializer attribute (String namespace, String name, - String value) throws IOException - { - if(!startTagIncomplete) { - throw new IllegalArgumentException("startTag() must be called before attribute()"+getLocation()); - } - //assert setPrefixCalled == false; - out.write(' '); - ////assert namespace != null; - if(namespace != null && namespace.length() > 0) { - //namespace = namespace.intern(); - if(!namesInterned) { - namespace = namespace.intern(); - } else if(checkNamesInterned) { - checkInterning(namespace); - } - String prefix = lookupOrDeclarePrefix( namespace ); - //assert( prefix != null); - if(prefix.length() == 0) { - // needs to declare prefix to hold default namespace - //NOTE: attributes such as a='b' are in NO namespace - prefix = generatePrefix(namespace); - } - out.write(prefix); - out.write(':'); - // if(prefix.length() > 0) { - // out.write(prefix); - // out.write(':'); - // } - } - //assert name != null; - out.write(name); - out.write('='); - //assert value != null; - out.write( attributeUseApostrophe ? '\'' : '"'); - writeAttributeValue(value, out); - out.write( attributeUseApostrophe ? '\'' : '"'); - return this; - } - - protected void closeStartTag() throws IOException { - if(finished) { - throw new IllegalArgumentException("trying to write past already finished output"+getLocation()); - } - if(seenBracket) { - seenBracket = seenBracketBracket = false; - } - if( startTagIncomplete || setPrefixCalled ) { - if(setPrefixCalled) { - throw new IllegalArgumentException( - "startTag() must be called immediately after setPrefix()"+getLocation()); - } - if(!startTagIncomplete) { - throw new IllegalArgumentException("trying to close start tag that is not opened"+getLocation()); - } - - // write all namespace declarations! - writeNamespaceDeclarations(); - out.write('>'); - elNamespaceCount[ depth ] = namespaceEnd; - startTagIncomplete = false; - } - } - - private void writeNamespaceDeclarations() throws IOException - { - //int start = elNamespaceCount[ depth - 1 ]; - for (int i = elNamespaceCount[ depth - 1 ]; i < namespaceEnd; i++) - { - if(doIndent && namespaceUri[ i ].length() > 40) { - writeIndent(); - out.write(" "); - } - if(namespacePrefix[ i ] != "") { - out.write(" xmlns:"); - out.write(namespacePrefix[ i ]); - out.write('='); - } else { - out.write(" xmlns="); - } - out.write( attributeUseApostrophe ? '\'' : '"'); - - //NOTE: escaping of namespace value the same way as attributes!!!! - writeAttributeValue(namespaceUri[ i ], out); - - out.write( attributeUseApostrophe ? '\'' : '"'); - } - } - - public XmlSerializer endTag(String namespace, String name) throws IOException - { - // check that level is valid - ////assert namespace != null; - //if(namespace != null) { - // namespace = namespace.intern(); - //} - seenBracket = seenBracketBracket = false; - if(namespace != null) { - if(!namesInterned) { - namespace = namespace.intern(); - } else if(checkNamesInterned) { - checkInterning(namespace); - } - } - - if(namespace != elNamespace[ depth ]) - { - throw new IllegalArgumentException( - "expected namespace "+printable(elNamespace[ depth ]) - +" and not "+printable(namespace)+getLocation()); - } - if(name == null) { - throw new IllegalArgumentException("end tag name can not be null"+getLocation()); - } - if(checkNamesInterned && namesInterned) { - checkInterning(name); - } - - if((!namesInterned && !name.equals(elName[ depth ])) - || (namesInterned && name != elName[ depth ])) - { - throw new IllegalArgumentException( - "expected element name "+printable(elName[ depth ])+" and not "+printable(name)+getLocation()); - } - if(startTagIncomplete) { - writeNamespaceDeclarations(); - out.write(" />"); //space is added to make it easier to work in XHTML!!! - --depth; - } else { - --depth; - //assert startTagIncomplete == false; - if(doIndent && seenTag) { writeIndent(); } - out.write("</"); - if(namespace != null && namespace.length() > 0) { - //TODO prefix should be alredy known from matching start tag ... - final String prefix = lookupOrDeclarePrefix( namespace ); - //assert( prefix != null); - if(prefix.length() > 0) { - out.write(prefix); - out.write(':'); - } - } - out.write(name); - out.write('>'); - - } - namespaceEnd = elNamespaceCount[ depth ]; - startTagIncomplete = false; - seenTag = true; - return this; - } - - public XmlSerializer text (String text) throws IOException - { - //assert text != null; - if(startTagIncomplete || setPrefixCalled) closeStartTag(); - if(doIndent && seenTag) seenTag = false; - writeElementContent(text, out); - return this; - } - - public XmlSerializer text (char [] buf, int start, int len) throws IOException - { - if(startTagIncomplete || setPrefixCalled) closeStartTag(); - if(doIndent && seenTag) seenTag = false; - writeElementContent(buf, start, len, out); - return this; - } - - public void cdsect (String text) throws IOException - { - if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); - if(doIndent && seenTag) seenTag = false; - out.write("<![CDATA["); - out.write(text); //escape? - out.write("]]>"); - } - - public void entityRef (String text) throws IOException - { - if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); - if(doIndent && seenTag) seenTag = false; - out.write('&'); - out.write(text); //escape? - out.write(';'); - } - - public void processingInstruction (String text) throws IOException - { - if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); - if(doIndent && seenTag) seenTag = false; - out.write("<?"); - out.write(text); //escape? - out.write("?>"); - } - - public void comment (String text) throws IOException - { - if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); - if(doIndent && seenTag) seenTag = false; - out.write("<!--"); - out.write(text); //escape? - out.write("-->"); - } - - public void docdecl (String text) throws IOException - { - if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); - if(doIndent && seenTag) seenTag = false; - out.write("<!DOCTYPE "); - out.write(text); //escape? - out.write(">"); - } - - public void ignorableWhitespace (String text) throws IOException - { - if(startTagIncomplete || setPrefixCalled || seenBracket) closeStartTag(); - if(doIndent && seenTag) seenTag = false; - if(text.length() == 0) { - throw new IllegalArgumentException( - "empty string is not allowed for ignorable whitespace"+getLocation()); - } - out.write(text); //no escape? - } - - public void flush () throws IOException - { - if(!finished && startTagIncomplete) closeStartTag(); - out.flush(); - } - - // --- utility methods - - protected void writeAttributeValue(String value, Writer out) throws IOException - { - //.[apostrophe and <, & escaped], - final char quot = attributeUseApostrophe ? '\'' : '"'; - final String quotEntity = attributeUseApostrophe ? "'" : """; - - int pos = 0; - for (int i = 0; i < value.length(); i++) - { - char ch = value.charAt(i); - if(ch == '&') { - if(i > pos) out.write(value.substring(pos, i)); - out.write("&"); - pos = i + 1; - } if(ch == '<') { - if(i > pos) out.write(value.substring(pos, i)); - out.write("<"); - pos = i + 1; - }else if(ch == quot) { - if(i > pos) out.write(value.substring(pos, i)); - out.write(quotEntity); - pos = i + 1; - } else if(ch < 32) { - //in XML 1.0 only legal character are #x9 | #xA | #xD - // and they must be escaped otherwise in attribute value they are normalized to spaces - if(ch == 13 || ch == 10 || ch == 9) { - if(i > pos) out.write(value.substring(pos, i)); - out.write("&#"); - out.write(Integer.toString(ch)); - out.write(';'); - pos = i + 1; - } else { - throw new IllegalStateException( - "character "+Integer.toString(ch)+" is not allowed in output"+getLocation()); - // in XML 1.1 legal are [#x1-#xD7FF] - // if(ch > 0) { - // if(i > pos) out.write(text.substring(pos, i)); - // out.write("&#"); - // out.write(Integer.toString(ch)); - // out.write(';'); - // pos = i + 1; - // } else { - // throw new IllegalStateException( - // "character zero is not allowed in XML 1.1 output"+getLocation()); - // } - } - } - } - if(pos > 0) { - out.write(value.substring(pos)); - } else { - out.write(value); // this is shortcut to the most common case - } - - } - - protected void writeElementContent(String text, Writer out) throws IOException - { - // escape '<', '&', ']]>', <32 if necessary - int pos = 0; - for (int i = 0; i < text.length(); i++) - { - //TODO: check if doing char[] text.getChars() would be faster than getCharAt(i) ... - char ch = text.charAt(i); - if(ch == ']') { - if(seenBracket) { - seenBracketBracket = true; - } else { - seenBracket = true; - } - } else { - if(ch == '&') { - if(i > pos) out.write(text.substring(pos, i)); - out.write("&"); - pos = i + 1; - } else if(ch == '<') { - if(i > pos) out.write(text.substring(pos, i)); - out.write("<"); - pos = i + 1; - } else if(seenBracketBracket && ch == '>') { - if(i > pos) out.write(text.substring(pos, i)); - out.write(">"); - pos = i + 1; - } else if(ch < 32) { - //in XML 1.0 only legal character are #x9 | #xA | #xD - if( ch == 9 || ch == 10 || ch == 13) { - // pass through - - // } else if(ch == 13) { //escape - // if(i > pos) out.write(text.substring(pos, i)); - // out.write("&#"); - // out.write(Integer.toString(ch)); - // out.write(';'); - // pos = i + 1; - } else { - throw new IllegalStateException( - "character "+Integer.toString(ch)+" is not allowed in output"+getLocation()); - // in XML 1.1 legal are [#x1-#xD7FF] - // if(ch > 0) { - // if(i > pos) out.write(text.substring(pos, i)); - // out.write("&#"); - // out.write(Integer.toString(ch)); - // out.write(';'); - // pos = i + 1; - // } else { - // throw new IllegalStateException( - // "character zero is not allowed in XML 1.1 output"+getLocation()); - // } - } - } - if(seenBracket) { - seenBracketBracket = seenBracket = false; - } - - } - } - if(pos > 0) { - out.write(text.substring(pos)); - } else { - out.write(text); // this is shortcut to the most common case - } - - - - } - - protected void writeElementContent(char[] buf, int off, int len, Writer out) throws IOException - { - // escape '<', '&', ']]>' - final int end = off + len; - int pos = off; - for (int i = off; i < end; i++) - { - final char ch = buf[i]; - if(ch == ']') { - if(seenBracket) { - seenBracketBracket = true; - } else { - seenBracket = true; - } - } else { - if(ch == '&') { - if(i > pos) { - out.write(buf, pos, i - pos); - } - out.write("&"); - pos = i + 1; - } else if(ch == '<') { - if(i > pos) { - out.write(buf, pos, i - pos); - } - out.write("<"); - pos = i + 1; - - } else if(seenBracketBracket && ch == '>') { - if(i > pos) { - out.write(buf, pos, i - pos); - } - out.write(">"); - pos = i + 1; - } else if(ch < 32) { - //in XML 1.0 only legal character are #x9 | #xA | #xD - if( ch == 9 || ch == 10 || ch == 13) { - // pass through - - - // } else if(ch == 13 ) { //if(ch == '\r') { - // if(i > pos) { - // out.write(buf, pos, i - pos); - // } - // out.write("&#"); - // out.write(Integer.toString(ch)); - // out.write(';'); - // pos = i + 1; - } else { - throw new IllegalStateException( - "character "+Integer.toString(ch)+" is not allowed in output"+getLocation()); - // in XML 1.1 legal are [#x1-#xD7FF] - // if(ch > 0) { - // if(i > pos) out.write(text.substring(pos, i)); - // out.write("&#"); - // out.write(Integer.toString(ch)); - // out.write(';'); - // pos = i + 1; - // } else { - // throw new IllegalStateException( - // "character zero is not allowed in XML 1.1 output"+getLocation()); - // } - } - } - if(seenBracket) { - seenBracketBracket = seenBracket = false; - } - // assert seenBracketBracket == seenBracket == false; - } - } - if(end > pos) { - out.write(buf, pos, end - pos); - } - } - - /** simple utility method -- good for debugging */ - protected static final String printable(String s) { - if(s == null) return "null"; - StringBuffer retval = new StringBuffer(s.length() + 16); - retval.append("'"); - char ch; - for (int i = 0; i < s.length(); i++) { - addPrintable(retval, s.charAt(i)); - } - retval.append("'"); - return retval.toString(); - } - - protected static final String printable(char ch) { - StringBuffer retval = new StringBuffer(); - addPrintable(retval, ch); - return retval.toString(); - } - - private static void addPrintable(StringBuffer retval, char ch) - { - switch (ch) - { - case '\b': - retval.append("\\b"); - break; - case '\t': - retval.append("\\t"); - break; - case '\n': - retval.append("\\n"); - break; - case '\f': - retval.append("\\f"); - break; - case '\r': - retval.append("\\r"); - break; - case '\"': - retval.append("\\\""); - break; - case '\'': - retval.append("\\\'"); - break; - case '\\': - retval.append("\\\\"); - break; - default: - if (ch < 0x20 || ch > 0x7e) { - final String ss = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + ss.substring(ss.length() - 4, ss.length())); - } else { - retval.append(ch); - } - } - } - -} - - diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,84 +0,0 @@ -/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/ -// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/) - -package org.codehaus.plexus.util.xml.pull; - -/** - * This exception is thrown to signal XML Pull Parser related faults. - * - * @author <a href="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a> - */ -@Deprecated -public class XmlPullParserException extends Exception { - /** - * @deprecated use generic getCause() method - */ - protected Throwable detail; - protected int row = -1; - protected int column = -1; - - /* public XmlPullParserException() { - }*/ - - public XmlPullParserException(String s) { - super(s); - } - - /* - public XmlPullParserException(String s, Throwable thrwble) { - super(s); - this.detail = thrwble; - } - - public XmlPullParserException(String s, int row, int column) { - super(s); - this.row = row; - this.column = column; - } - */ - - public XmlPullParserException(String msg, XmlPullParser parser, Throwable chain) { - super ((msg == null ? "" : msg+" ") - + (parser == null ? "" : "(position:"+parser.getPositionDescription()+") ") - + (chain == null ? "" : "caused by: "+chain), chain); - - if (parser != null) { - this.row = parser.getLineNumber(); - this.column = parser.getColumnNumber(); - } - this.detail = chain; - } - - /** - * @deprecated Use the generic <code>getCause()</code> method - * @return - */ - public Throwable getDetail() { return getCause(); } - // public void setDetail(Throwable cause) { this.detail = cause; } - public int getLineNumber() { return row; } - public int getColumnNumber() { return column; } - - /* - public String getMessage() { - if(detail == null) - return super.getMessage(); - else - return super.getMessage() + "; nested exception is: \n\t" - + detail.getMessage(); - } - */ - - //NOTE: code that prints this and detail is difficult in J2ME - public void printStackTrace() { - if (getCause() == null) { - super.printStackTrace(); - } else { - synchronized(System.err) { - System.err.println(super.getMessage() + "; nested exception is:"); - getCause().printStackTrace(); - } - } - } - -} - diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,1115 +0,0 @@ -/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/ -// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/) - -package org.codehaus.plexus.util.xml.pull; - -import java.io.InputStream; -import java.io.IOException; -import java.io.Reader; - -/** - * XML Pull Parser is an interface that defines parsing functionality provided - * in <a href="http://www.xmlpull.org/">XMLPULL V1 API</a> (visit this website to - * learn more about API and its implementations). - * - * <p>There are following different - * kinds of parser depending on which features are set:<ul> - * <li><b>non-validating</b> parser as defined in XML 1.0 spec when - * FEATURE_PROCESS_DOCDECL is set to true - * <li><b>validating parser</b> as defined in XML 1.0 spec when - * FEATURE_VALIDATION is true (and that implies that FEATURE_PROCESS_DOCDECL is true) - * <li>when FEATURE_PROCESS_DOCDECL is false (this is default and - * if different value is required necessary must be changed before parsing is started) - * then parser behaves like XML 1.0 compliant non-validating parser under condition that - * <em>no DOCDECL is present</em> in XML documents - * (internal entities can still be defined with defineEntityReplacementText()). - * This mode of operation is intended <b>for operation in constrained environments</b> such as J2ME. - * </ul> - * - * - * <p>There are two key methods: next() and nextToken(). While next() provides - * access to high level parsing events, nextToken() allows access to lower - * level tokens. - * - * <p>The current event state of the parser - * can be determined by calling the - * <a href="#getEventType()">getEventType()</a> method. - * Initially, the parser is in the <a href="#START_DOCUMENT">START_DOCUMENT</a> - * state. - * - * <p>The method <a href="#next()">next()</a> advances the parser to the - * next event. The int value returned from next determines the current parser - * state and is identical to the value returned from following calls to - * getEventType (). - * - * <p>The following event types are seen by next()<dl> - * <dt><a href="#START_TAG">START_TAG</a><dd> An XML start tag was read. - * <dt><a href="#TEXT">TEXT</a><dd> Text content was read; - * the text content can be retrieved using the getText() method. - * (when in validating mode next() will not report ignorable whitespaces, use nextToken() instead) - * <dt><a href="#END_TAG">END_TAG</a><dd> An end tag was read - * <dt><a href="#END_DOCUMENT">END_DOCUMENT</a><dd> No more events are available - * </dl> - * - * <p>after first next() or nextToken() (or any other next*() method) - * is called user application can obtain - * XML version, standalone and encoding from XML declaration - * in following ways:<ul> - * <li><b>version</b>: - * getProperty("<a href="http://xmlpull.org/v1/doc/properties.html#xmldecl-version">http://xmlpull.org/v1/doc/properties.html#xmldecl-version</a>") - * returns String ("1.0") or null if XMLDecl was not read or if property is not supported - * <li><b>standalone</b>: - * getProperty("<a href="http://xmlpull.org/v1/doc/features.html#xmldecl-standalone">http://xmlpull.org/v1/doc/features.html#xmldecl-standalone</a>") - * returns Boolean: null if there was no standalone declaration - * or if property is not supported - * otherwise returns Boolean(true) if standalone="yes" and Boolean(false) when standalone="no" - * <li><b>encoding</b>: obtained from getInputEncoding() - * null if stream had unknown encoding (not set in setInputStream) - * and it was not declared in XMLDecl - * </ul> - * - * A minimal example for using this API may look as follows: - * <pre> - * import java.io.IOException; - * import java.io.StringReader; - * - * import org.xmlpull.v1.XmlPullParser; - * import org.xmlpull.v1.<a href="XmlPullParserException.html">XmlPullParserException.html</a>; - * import org.xmlpull.v1.<a href="XmlPullParserFactory.html">XmlPullParserFactory</a>; - * - * public class SimpleXmlPullApp - * { - * - * public static void main (String args[]) - * throws XmlPullParserException, IOException - * { - * XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); - * factory.setNamespaceAware(true); - * XmlPullParser xpp = factory.newPullParser(); - * - * xpp.<a href="#setInput">setInput</a>( new StringReader ( "<foo>Hello World!</foo>" ) ); - * int eventType = xpp.getEventType(); - * while (eventType != xpp.END_DOCUMENT) { - * if(eventType == xpp.START_DOCUMENT) { - * System.out.println("Start document"); - * } else if(eventType == xpp.END_DOCUMENT) { - * System.out.println("End document"); - * } else if(eventType == xpp.START_TAG) { - * System.out.println("Start tag "+xpp.<a href="#getName()">getName()</a>); - * } else if(eventType == xpp.END_TAG) { - * System.out.println("End tag "+xpp.getName()); - * } else if(eventType == xpp.TEXT) { - * System.out.println("Text "+xpp.<a href="#getText()">getText()</a>); - * } - * eventType = xpp.next(); - * } - * } - * } - * </pre> - * - * <p>The above example will generate the following output: - * <pre> - * Start document - * Start tag foo - * Text Hello World! - * End tag foo - * </pre> - * - * <p>For more details on API usage, please refer to the - * quick Introduction available at <a href="http://www.xmlpull.org">http://www.xmlpull.org</a> - * - * @see #defineEntityReplacementText - * @see #getName - * @see #getNamespace - * @see #getText - * @see #next - * @see #nextToken - * @see #setInput - * @see #FEATURE_PROCESS_DOCDECL - * @see #FEATURE_VALIDATION - * @see #START_DOCUMENT - * @see #START_TAG - * @see #TEXT - * @see #END_TAG - * @see #END_DOCUMENT - * - * @author <a href="http://www-ai.cs.uni-dortmund.de/PERSONAL/haustein.html">Stefan Haustein</a> - * @author <a href="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a> - */ -@Deprecated -public interface XmlPullParser { - - /** This constant represents the default namespace (empty string "") */ - String NO_NAMESPACE = ""; - - // ---------------------------------------------------------------------------- - // EVENT TYPES as reported by next() - - /** - * Signalize that parser is at the very beginning of the document - * and nothing was read yet. - * This event type can only be observed by calling getEvent() - * before the first call to next(), nextToken, or nextTag()</a>). - * - * @see #next - * @see #nextToken - */ - int START_DOCUMENT = 0; - - /** - * Logical end of the xml document. Returned from getEventType, next() - * and nextToken() - * when the end of the input document has been reached. - * <p><strong>NOTE:</strong> calling again - * <a href="#next()">next()</a> or <a href="#nextToken()">nextToken()</a> - * will result in exception being thrown. - * - * @see #next - * @see #nextToken - */ - int END_DOCUMENT = 1; - - /** - * Returned from getEventType(), - * <a href="#next()">next()</a>, <a href="#nextToken()">nextToken()</a> when - * a start tag was read. - * The name of start tag is available from getName(), its namespace and prefix are - * available from getNamespace() and getPrefix() - * if <a href='#FEATURE_PROCESS_NAMESPACES'>namespaces are enabled</a>. - * See getAttribute* methods to retrieve element attributes. - * See getNamespace* methods to retrieve newly declared namespaces. - * - * @see #next - * @see #nextToken - * @see #getName - * @see #getPrefix - * @see #getNamespace - * @see #getAttributeCount - * @see #getDepth - * @see #getNamespaceCount - * @see #getNamespace - * @see #FEATURE_PROCESS_NAMESPACES - */ - int START_TAG = 2; - - /** - * Returned from getEventType(), <a href="#next()">next()</a>, or - * <a href="#nextToken()">nextToken()</a> when an end tag was read. - * The name of start tag is available from getName(), its - * namespace and prefix are - * available from getNamespace() and getPrefix(). - * - * @see #next - * @see #nextToken - * @see #getName - * @see #getPrefix - * @see #getNamespace - * @see #FEATURE_PROCESS_NAMESPACES - */ - int END_TAG = 3; - - - /** - * Character data was read and will is available by calling getText(). - * <p><strong>Please note:</strong> <a href="#next()">next()</a> will - * accumulate multiple - * events into one TEXT event, skipping IGNORABLE_WHITESPACE, - * PROCESSING_INSTRUCTION and COMMENT events, - * In contrast, <a href="#nextToken()">nextToken()</a> will stop reading - * text when any other event is observed. - * Also, when the state was reached by calling next(), the text value will - * be normalized, whereas getText() will - * return unnormalized content in the case of nextToken(). This allows - * an exact roundtrip without changing line ends when examining low - * level events, whereas for high level applications the text is - * normalized appropriately. - * - * @see #next - * @see #nextToken - * @see #getText - */ - int TEXT = 4; - - // ---------------------------------------------------------------------------- - // additional events exposed by lower level nextToken() - - /** - * A CDATA sections was just read; - * this token is available only from calls to <a href="#nextToken()">nextToken()</a>. - * A call to next() will accumulate various text events into a single event - * of type TEXT. The text contained in the CDATA section is available - * by calling getText(). - * - * @see #nextToken - * @see #getText - */ - int CDSECT = 5; - - /** - * An entity reference was just read; - * this token is available from <a href="#nextToken()">nextToken()</a> - * only. The entity name is available by calling getName(). If available, - * the replacement text can be obtained by calling getTextt(); otherwise, - * the user is responsible for resolving the entity reference. - * This event type is never returned from next(); next() will - * accumulate the replacement text and other text - * events to a single TEXT event. - * - * @see #nextToken - * @see #getText - */ - int ENTITY_REF = 6; - - /** - * Ignorable whitespace was just read. - * This token is available only from <a href="#nextToken()">nextToken()</a>). - * For non-validating - * parsers, this event is only reported by nextToken() when outside - * the root element. - * Validating parsers may be able to detect ignorable whitespace at - * other locations. - * The ignorable whitespace string is available by calling getText() - * - * <p><strong>NOTE:</strong> this is different from calling the - * isWhitespace() method, since text content - * may be whitespace but not ignorable. - * - * Ignorable whitespace is skipped by next() automatically; this event - * type is never returned from next(). - * - * @see #nextToken - * @see #getText - */ - int IGNORABLE_WHITESPACE = 7; - - /** - * An XML processing instruction declaration was just read. This - * event type is available only via <a href="#nextToken()">nextToken()</a>. - * getText() will return text that is inside the processing instruction. - * Calls to next() will skip processing instructions automatically. - * @see #nextToken - * @see #getText - */ - int PROCESSING_INSTRUCTION = 8; - - /** - * An XML comment was just read. This event type is this token is - * available via <a href="#nextToken()">nextToken()</a> only; - * calls to next() will skip comments automatically. - * The content of the comment can be accessed using the getText() - * method. - * - * @see #nextToken - * @see #getText - */ - int COMMENT = 9; - - /** - * An XML document type declaration was just read. This token is - * available from <a href="#nextToken()">nextToken()</a> only. - * The unparsed text inside the doctype is available via - * the getText() method. - * - * @see #nextToken - * @see #getText - */ - int DOCDECL = 10; - - /** - * This array can be used to convert the event type integer constants - * such as START_TAG or TEXT to - * to a string. For example, the value of TYPES[START_TAG] is - * the string "START_TAG". - * - * This array is intended for diagnostic output only. Relying - * on the contents of the array may be dangerous since malicious - * applications may alter the array, although it is final, due - * to limitations of the Java language. - */ - String [] TYPES = { - "START_DOCUMENT", - "END_DOCUMENT", - "START_TAG", - "END_TAG", - "TEXT", - "CDSECT", - "ENTITY_REF", - "IGNORABLE_WHITESPACE", - "PROCESSING_INSTRUCTION", - "COMMENT", - "DOCDECL" - }; - - - // ---------------------------------------------------------------------------- - // namespace related features - - /** - * This feature determines whether the parser processes - * namespaces. As for all features, the default value is false. - * <p><strong>NOTE:</strong> The value can not be changed during - * parsing an must be set before parsing. - * - * @see #getFeature - * @see #setFeature - */ - String FEATURE_PROCESS_NAMESPACES = - "http://xmlpull.org/v1/doc/features.html#process-namespaces"; - - /** - * This feature determines whether namespace attributes are - * exposed via the attribute access methods. Like all features, - * the default value is false. This feature cannot be changed - * during parsing. - * - * @see #getFeature - * @see #setFeature - */ - String FEATURE_REPORT_NAMESPACE_ATTRIBUTES = - "http://xmlpull.org/v1/doc/features.html#report-namespace-prefixes"; - - /** - * This feature determines whether the document declaration - * is processed. If set to false, - * the DOCDECL event type is reported by nextToken() - * and ignored by next(). - * - * If this featue is activated, then the document declaration - * must be processed by the parser. - * - * <p><strong>Please note:</strong> If the document type declaration - * was ignored, entity references may cause exceptions - * later in the parsing process. - * The default value of this feature is false. It cannot be changed - * during parsing. - * - * @see #getFeature - * @see #setFeature - */ - String FEATURE_PROCESS_DOCDECL = - "http://xmlpull.org/v1/doc/features.html#process-docdecl"; - - /** - * If this feature is activated, all validation errors as - * defined in the XML 1.0 sepcification are reported. - * This implies that FEATURE_PROCESS_DOCDECL is true and both, the - * internal and external document type declaration will be processed. - * <p><strong>Please Note:</strong> This feature can not be changed - * during parsing. The default value is false. - * - * @see #getFeature - * @see #setFeature - */ - String FEATURE_VALIDATION = - "http://xmlpull.org/v1/doc/features.html#validation"; - - /** - * Use this call to change the general behaviour of the parser, - * such as namespace processing or doctype declaration handling. - * This method must be called before the first call to next or - * nextToken. Otherwise, an exception is thrown. - * <p>Example: call setFeature(FEATURE_PROCESS_NAMESPACES, true) in order - * to switch on namespace processing. The initial settings correspond - * to the properties requested from the XML Pull Parser factory. - * If none were requested, all feautures are deactivated by default. - * - * @exception XmlPullParserException If the feature is not supported or can not be set - * @exception IllegalArgumentException If string with the feature name is null - */ - void setFeature(String name, - boolean state) throws XmlPullParserException; - - /** - * Returns the current value of the given feature. - * <p><strong>Please note:</strong> unknown features are - * <strong>always</strong> returned as false. - * - * @param name The name of feature to be retrieved. - * @return The value of the feature. - * @exception IllegalArgumentException if string the feature name is null - */ - - boolean getFeature(String name); - - /** - * Set the value of a property. - * - * The property name is any fully-qualified URI. - * - * @exception XmlPullParserException If the property is not supported or can not be set - * @exception IllegalArgumentException If string with the property name is null - */ - void setProperty(String name, - Object value) throws XmlPullParserException; - - /** - * Look up the value of a property. - * - * The property name is any fully-qualified URI. - * <p><strong>NOTE:</strong> unknown properties are <strong>always</strong> - * returned as null. - * - * @param name The name of property to be retrieved. - * @return The value of named property. - */ - Object getProperty(String name); - - - /** - * Set the input source for parser to the given reader and - * resets the parser. The event type is set to the initial value - * START_DOCUMENT. - * Setting the reader to null will just stop parsing and - * reset parser state, - * allowing the parser to free internal resources - * such as parsing buffers. - */ - void setInput(Reader in) throws XmlPullParserException; - - - /** - * Sets the input stream the parser is going to process. - * This call resets the parser state and sets the event type - * to the initial value START_DOCUMENT. - * - * <p><strong>NOTE:</strong> If an input encoding string is passed, - * it MUST be used. Otherwise, - * if inputEncoding is null, the parser SHOULD try to determine - * input encoding following XML 1.0 specification (see below). - * If encoding detection is supported then following feature - * <a href="http://xmlpull.org/v1/doc/features.html#detect-encoding">http://xmlpull.org/v1/doc/features.html#detect-encoding</a> - * MUST be true amd otherwise it must be false - * - * @param inputStream contains a raw byte input stream of possibly - * unknown encoding (when inputEncoding is null). - * - * @param inputEncoding if not null it MUST be used as encoding for inputStream - */ - void setInput(InputStream inputStream, String inputEncoding) - throws XmlPullParserException; - - /** - * Returns the input encoding if known, null otherwise. - * If setInput(InputStream, inputEncoding) was called with an inputEncoding - * value other than null, this value must be returned - * from this method. Otherwise, if inputEncoding is null and - * the parser suppports the encoding detection feature - * (http://xmlpull.org/v1/doc/features.html#detect-encoding), - * it must return the detected encoding. - * If setInput(Reader) was called, null is returned. - * After first call to next if XML declaration was present this method - * will return encoding declared. - */ - String getInputEncoding(); - - /** - * Set new value for entity replacement text as defined in - * <a href="http://www.w3.org/TR/REC-xml#intern-replacement">XML 1.0 Section 4.5 - * Construction of Internal Entity Replacement Text</a>. - * If FEATURE_PROCESS_DOCDECL or FEATURE_VALIDATION are set, calling this - * function will result in an exception -- when processing of DOCDECL is - * enabled, there is no need to the entity replacement text manually. - * - * <p>The motivation for this function is to allow very small - * implementations of XMLPULL that will work in J2ME environments. - * Though these implementations may not be able to process the document type - * declaration, they still can work with known DTDs by using this function. - * - * <p><b>Please notes:</b> The given value is used literally as replacement text - * and it corresponds to declaring entity in DTD that has all special characters - * escaped: left angle bracket is replaced with &lt;, ampersnad with &amp; - * and so on. - * - * <p><b>Note:</b> The given value is the literal replacement text and must not - * contain any other entity reference (if it contains any entity reference - * there will be no further replacement). - * - * <p><b>Note:</b> The list of pre-defined entity names will - * always contain standard XML entities such as - * amp (&amp;), lt (&lt;), gt (&gt;), quot (&quot;), and apos (&apos;). - * Those cannot be redefined by this method! - * - * @see #setInput - * @see #FEATURE_PROCESS_DOCDECL - * @see #FEATURE_VALIDATION - */ - void defineEntityReplacementText( String entityName, - String replacementText ) throws XmlPullParserException; - - /** - * Returns the numbers of elements in the namespace stack for the given - * depth. - * If namespaces are not enabled, 0 is returned. - * - * <p><b>NOTE:</b> when parser is on END_TAG then it is allowed to call - * this function with getDepth()+1 argument to retrieve position of namespace - * prefixes and URIs that were declared on corresponding START_TAG. - * <p><b>NOTE:</b> to retrieve lsit of namespaces declared in current element:<pre> - * XmlPullParser pp = ... - * int nsStart = pp.getNamespaceCount(pp.getDepth()-1); - * int nsEnd = pp.getNamespaceCount(pp.getDepth()); - * for (int i = nsStart; i < nsEnd; i++) { - * String prefix = pp.getNamespacePrefix(i); - * String ns = pp.getNamespaceUri(i); - * // ... - * } - * </pre> - * - * @see #getNamespacePrefix - * @see #getNamespaceUri - * @see #getNamespace() - * @see #getNamespace(String) - */ - int getNamespaceCount(int depth) throws XmlPullParserException; - - /** - * Returns the namespace prefixe for the given position - * in the namespace stack. - * Default namespace declaration (xmlns='...') will have null as prefix. - * If the given index is out of range, an exception is thrown. - * <p><b>Please note:</b> when the parser is on an END_TAG, - * namespace prefixes that were declared - * in the corresponding START_TAG are still accessible - * although they are no longer in scope. - */ - String getNamespacePrefix(int pos) throws XmlPullParserException; - - /** - * Returns the namespace URI for the given position in the - * namespace stack - * If the position is out of range, an exception is thrown. - * <p><b>NOTE:</b> when parser is on END_TAG then namespace prefixes that were declared - * in corresponding START_TAG are still accessible even though they are not in scope - */ - String getNamespaceUri(int pos) throws XmlPullParserException; - - /** - * Returns the URI corresponding to the given prefix, - * depending on current state of the parser. - * - * <p>If the prefix was not declared in the current scope, - * null is returned. The default namespace is included - * in the namespace table and is available via - * getNamespace (null). - * - * <p>This method is a convenience method for - * - * <pre> - * for (int i = getNamespaceCount(getDepth ())-1; i >= 0; i--) { - * if (getNamespacePrefix(i).equals( prefix )) { - * return getNamespaceUri(i); - * } - * } - * return null; - * </pre> - * - * <p><strong>Please note:</strong> parser implementations - * may provide more efifcient lookup, e.g. using a Hashtable. - * The 'xml' prefix is bound to "http://www.w3.org/XML/1998/namespace", as - * defined in the - * <a href="http://www.w3.org/TR/REC-xml-names/#ns-using">Namespaces in XML</a> - * specification. Analogous, the 'xmlns' prefix is resolved to - * <a href="http://www.w3.org/2000/xmlns/">http://www.w3.org/2000/xmlns/</a> - * - * @see #getNamespaceCount - * @see #getNamespacePrefix - * @see #getNamespaceUri - */ - String getNamespace (String prefix); - - - // -------------------------------------------------------------------------- - // miscellaneous reporting methods - - /** - * Returns the current depth of the element. - * Outside the root element, the depth is 0. The - * depth is incremented by 1 when a start tag is reached. - * The depth is decremented AFTER the end tag - * event was observed. - * - * <pre> - * <!-- outside --> 0 - * <root> 1 - * sometext 1 - * <foobar> 2 - * </foobar> 2 - * </root> 1 - * <!-- outside --> 0 - * </pre> - */ - int getDepth(); - - /** - * Returns a short text describing the current parser state, including - * the position, a - * description of the current event and the data source if known. - * This method is especially useful to provide meaningful - * error messages and for debugging purposes. - */ - String getPositionDescription (); - - - /** - * Returns the current line number, starting from 1. - * When the parser does not know the current line number - * or can not determine it, -1 is returned (e.g. for WBXML). - * - * @return current line number or -1 if unknown. - */ - int getLineNumber(); - - /** - * Returns the current column number, starting from 0. - * When the parser does not know the current column number - * or can not determine it, -1 is returned (e.g. for WBXML). - * - * @return current column number or -1 if unknown. - */ - int getColumnNumber(); - - - // -------------------------------------------------------------------------- - // TEXT related methods - - /** - * Checks whether the current TEXT event contains only whitespace - * characters. - * For IGNORABLE_WHITESPACE, this is always true. - * For TEXT and CDSECT, false is returned when the current event text - * contains at least one non-white space character. For any other - * event type an exception is thrown. - * - * <p><b>Please note:</b> non-validating parsers are not - * able to distinguish whitespace and ignorable whitespace, - * except from whitespace outside the root element. Ignorable - * whitespace is reported as separate event, which is exposed - * via nextToken only. - * - */ - boolean isWhitespace() throws XmlPullParserException; - - /** - * Returns the text content of the current event as String. - * The value returned depends on current event type, - * for example for TEXT event it is element content - * (this is typical case when next() is used). - * - * See description of nextToken() for detailed description of - * possible returned values for different types of events. - * - * <p><strong>NOTE:</strong> in case of ENTITY_REF, this method returns - * the entity replacement text (or null if not available). This is - * the only case where - * getText() and getTextCharacters() return different values. - * - * @see #getEventType - * @see #next - * @see #nextToken - */ - String getText (); - - - /** - * Returns the buffer that contains the text of the current event, - * as well as the start offset and length relevant for the current - * event. See getText(), next() and nextToken() for description of possible returned values. - * - * <p><strong>Please note:</strong> this buffer must not - * be modified and its content MAY change after a call to - * next() or nextToken(). This method will always return the - * same value as getText(), except for ENTITY_REF. In the case - * of ENTITY ref, getText() returns the replacement text and - * this method returns the actual input buffer containing the - * entity name. - * If getText() returns null, this method returns null as well and - * the values returned in the holder array MUST be -1 (both start - * and length). - * - * @see #getText - * @see #next - * @see #nextToken - * - * @param holderForStartAndLength Must hold an 2-element int array - * into which the start offset and length values will be written. - * @return char buffer that contains the text of the current event - * (null if the current event has no text associated). - */ - char[] getTextCharacters(int [] holderForStartAndLength); - - // -------------------------------------------------------------------------- - // START_TAG / END_TAG shared methods - - /** - * Returns the namespace URI of the current element. - * The default namespace is represented - * as empty string. - * If namespaces are not enabled, an empty String ("") is always returned. - * The current event must be START_TAG or END_TAG; otherwise, - * null is returned. - */ - String getNamespace (); - - /** - * For START_TAG or END_TAG events, the (local) name of the current - * element is returned when namespaces are enabled. When namespace - * processing is disabled, the raw name is returned. - * For ENTITY_REF events, the entity name is returned. - * If the current event is not START_TAG, END_TAG, or ENTITY_REF, - * null is returned. - * <p><b>Please note:</b> To reconstruct the raw element name - * when namespaces are enabled and the prefix is not null, - * you will need to add the prefix and a colon to localName.. - * - */ - String getName(); - - /** - * Returns the prefix of the current element. - * If the element is in the default namespace (has no prefix), - * null is returned. - * If namespaces are not enabled, or the current event - * is not START_TAG or END_TAG, null is returned. - */ - String getPrefix(); - - /** - * Returns true if the current event is START_TAG and the tag - * is degenerated - * (e.g. <foobar/>). - * <p><b>NOTE:</b> if the parser is not on START_TAG, an exception - * will be thrown. - */ - boolean isEmptyElementTag() throws XmlPullParserException; - - // -------------------------------------------------------------------------- - // START_TAG Attributes retrieval methods - - /** - * Returns the number of attributes of the current start tag, or - * -1 if the current event type is not START_TAG - * - * @see #getAttributeNamespace - * @see #getAttributeName - * @see #getAttributePrefix - * @see #getAttributeValue - */ - int getAttributeCount(); - - /** - * Returns the namespace URI of the attribute - * with the given index (starts from 0). - * Returns an empty string ("") if namespaces are not enabled - * or the attribute has no namespace. - * Throws an IndexOutOfBoundsException if the index is out of range - * or the current event type is not START_TAG. - * - * <p><strong>NOTE:</strong> if FEATURE_REPORT_NAMESPACE_ATTRIBUTES is set - * then namespace attributes (xmlns:ns='...') must be reported - * with namespace - * <a href="http://www.w3.org/2000/xmlns/">http://www.w3.org/2000/xmlns/</a> - * (visit this URL for description!). - * The default namespace attribute (xmlns="...") will be reported with empty namespace. - * <p><strong>NOTE:</strong>The xml prefix is bound as defined in - * <a href="http://www.w3.org/TR/REC-xml-names/#ns-using">Namespaces in XML</a> - * specification to "http://www.w3.org/XML/1998/namespace". - * - * @param index zero based index of attribute - * @return attribute namespace, - * empty string ("") is returned if namesapces processing is not enabled or - * namespaces processing is enabled but attribute has no namespace (it has no prefix). - */ - String getAttributeNamespace (int index); - - /** - * Returns the local name of the specified attribute - * if namespaces are enabled or just attribute name if namespaces are disabled. - * Throws an IndexOutOfBoundsException if the index is out of range - * or current event type is not START_TAG. - * - * @param index zero based index of attribute - * @return attribute name (null is never returned) - */ - String getAttributeName (int index); - - /** - * Returns the prefix of the specified attribute - * Returns null if the element has no prefix. - * If namespaces are disabled it will always return null. - * Throws an IndexOutOfBoundsException if the index is out of range - * or current event type is not START_TAG. - * - * @param index zero based index of attribute - * @return attribute prefix or null if namespaces processing is not enabled. - */ - String getAttributePrefix(int index); - - /** - * Returns the type of the specified attribute - * If parser is non-validating it MUST return CDATA. - * - * @param index zero based index of attribute - * @return attribute type (null is never returned) - */ - String getAttributeType(int index); - - /** - * Returns if the specified attribute was not in input was declared in XML. - * If parser is non-validating it MUST always return false. - * This information is part of XML infoset: - * - * @param index zero based index of attribute - * @return false if attribute was in input - */ - boolean isAttributeDefault(int index); - - /** - * Returns the given attributes value. - * Throws an IndexOutOfBoundsException if the index is out of range - * or current event type is not START_TAG. - * - * <p><strong>NOTE:</strong> attribute value must be normalized - * (including entity replacement text if PROCESS_DOCDECL is false) as described in - * <a href="http://www.w3.org/TR/REC-xml#AVNormalize">XML 1.0 section - * 3.3.3 Attribute-Value Normalization</a> - * - * @see #defineEntityReplacementText - * - * @param index zero based index of attribute - * @return value of attribute (null is never returned) - */ - String getAttributeValue(int index); - - /** - * Returns the attributes value identified by namespace URI and namespace localName. - * If namespaces are disabled namespace must be null. - * If current event type is not START_TAG then IndexOutOfBoundsException will be thrown. - * - * <p><strong>NOTE:</strong> attribute value must be normalized - * (including entity replacement text if PROCESS_DOCDECL is false) as described in - * <a href="http://www.w3.org/TR/REC-xml#AVNormalize">XML 1.0 section - * 3.3.3 Attribute-Value Normalization</a> - * - * @see #defineEntityReplacementText - * - * @param namespace Namespace of the attribute if namespaces are enabled otherwise must be null - * @param name If namespaces enabled local name of attribute otherwise just attribute name - * @return value of attribute or null if attribute with given name does not exist - */ - String getAttributeValue(String namespace, - String name); - - // -------------------------------------------------------------------------- - // actual parsing methods - - /** - * Returns the type of the current event (START_TAG, END_TAG, TEXT, etc.) - * - * @see #next() - * @see #nextToken() - */ - int getEventType() - throws XmlPullParserException; - - /** - * Get next parsing event - element content wil be coalesced and only one - * TEXT event must be returned for whole element content - * (comments and processing instructions will be ignored and emtity references - * must be expanded or exception mus be thrown if entity reerence can not be exapnded). - * If element content is empty (content is "") then no TEXT event will be reported. - * - * <p><b>NOTE:</b> empty element (such as <tag/>) will be reported - * with two separate events: START_TAG, END_TAG - it must be so to preserve - * parsing equivalency of empty element to <tag></tag>. - * (see isEmptyElementTag ()) - * - * @see #isEmptyElementTag - * @see #START_TAG - * @see #TEXT - * @see #END_TAG - * @see #END_DOCUMENT - */ - - int next() - throws XmlPullParserException, IOException; - - - /** - * This method works similarly to next() but will expose - * additional event types (COMMENT, CDSECT, DOCDECL, ENTITY_REF, PROCESSING_INSTRUCTION, or - * IGNORABLE_WHITESPACE) if they are available in input. - * - * <p>If special feature - * <a href="http://xmlpull.org/v1/doc/features.html#xml-roundtrip">FEATURE_XML_ROUNDTRIP</a> - * (identified by URI: http://xmlpull.org/v1/doc/features.html#xml-roundtrip) - * is enabled it is possible to do XML document round trip ie. reproduce - * exectly on output the XML input using getText(): - * returned content is always unnormalized (exactly as in input). - * Otherwise returned content is end-of-line normalized as described - * <a href="http://www.w3.org/TR/REC-xml#sec-line-ends">XML 1.0 End-of-Line Handling</a> - * and. Also when this feature is enabled exact content of START_TAG, END_TAG, - * DOCDECL and PROCESSING_INSTRUCTION is available. - * - * <p>Here is the list of tokens that can be returned from nextToken() - * and what getText() and getTextCharacters() returns:<dl> - * <dt>START_DOCUMENT<dd>null - * <dt>END_DOCUMENT<dd>null - * <dt>START_TAG<dd>null unless FEATURE_XML_ROUNDTRIP - * enabled and then returns XML tag, ex: <tag attr='val'> - * <dt>END_TAG<dd>null unless FEATURE_XML_ROUNDTRIP - * id enabled and then returns XML tag, ex: </tag> - * <dt>TEXT<dd>return element content. - * <br>Note: that element content may be delivered in multiple consecutive TEXT events. - * <dt>IGNORABLE_WHITESPACE<dd>return characters that are determined to be ignorable white - * space. If the FEATURE_XML_ROUNDTRIP is enabled all whitespace content outside root - * element will always reported as IGNORABLE_WHITESPACE otherise rteporting is optional. - * <br>Note: that element content may be delevered in multiple consecutive IGNORABLE_WHITESPACE events. - * <dt>CDSECT<dd> - * return text <em>inside</em> CDATA - * (ex. 'fo<o' from <!CDATA[fo<o]]>) - * <dt>PROCESSING_INSTRUCTION<dd> - * if FEATURE_XML_ROUNDTRIP is true - * return exact PI content ex: 'pi foo' from <?pi foo?> - * otherwise it may be exact PI content or concatenation of PI target, - * space and data so for example for - * <?target data?> string "target data" may - * be returned if FEATURE_XML_ROUNDTRIP is false. - * <dt>COMMENT<dd>return comment content ex. 'foo bar' from <!--foo bar--> - * <dt>ENTITY_REF<dd>getText() MUST return entity replacement text if PROCESS_DOCDECL is false - * otherwise getText() MAY return null, - * additionally getTextCharacters() MUST return entity name - * (for example 'entity_name' for &entity_name;). - * <br><b>NOTE:</b> this is the only place where value returned from getText() and - * getTextCharacters() <b>are different</b> - * <br><b>NOTE:</b> it is user responsibility to resolve entity reference - * if PROCESS_DOCDECL is false and there is no entity replacement text set in - * defineEntityReplacementText() method (getText() will be null) - * <br><b>NOTE:</b> character entities (ex. &#32;) and standard entities such as - * &amp; &lt; &gt; &quot; &apos; are reported as well - * and are <b>not</b> reported as TEXT tokens but as ENTITY_REF tokens! - * This requirement is added to allow to do roundtrip of XML documents! - * <dt>DOCDECL<dd> - * if FEATURE_XML_ROUNDTRIP is true or PROCESS_DOCDECL is false - * then return what is inside of DOCDECL for example it returns:<pre> - * " titlepage SYSTEM "http://www.foo.bar/dtds/typo.dtd" - * [<!ENTITY % active.links "INCLUDE">]"</pre> - * <p>for input document that contained:<pre> - * <!DOCTYPE titlepage SYSTEM "http://www.foo.bar/dtds/typo.dtd" - * [<!ENTITY % active.links "INCLUDE">]></pre> - * otherwise if FEATURE_XML_ROUNDTRIP is false and PROCESS_DOCDECL is true - * then what is returned is undefined (it may be even null) - * </dd> - * </dl> - * - * <p><strong>NOTE:</strong> there is no gurantee that there will only one TEXT or - * IGNORABLE_WHITESPACE event from nextToken() as parser may chose to deliver element content in - * multiple tokens (dividing element content into chunks) - * - * <p><strong>NOTE:</strong> whether returned text of token is end-of-line normalized - * is depending on FEATURE_XML_ROUNDTRIP. - * - * <p><strong>NOTE:</strong> XMLDecl (<?xml ...?>) is not reported but its content - * is available through optional properties (see class description above). - * - * @see #next - * @see #START_TAG - * @see #TEXT - * @see #END_TAG - * @see #END_DOCUMENT - * @see #COMMENT - * @see #DOCDECL - * @see #PROCESSING_INSTRUCTION - * @see #ENTITY_REF - * @see #IGNORABLE_WHITESPACE - */ - int nextToken() - throws XmlPullParserException, IOException; - - //----------------------------------------------------------------------------- - // utility methods to mak XML parsing easier ... - - /** - * Test if the current event is of the given type and if the - * namespace and name do match. null will match any namespace - * and any name. If the test is not passed, an exception is - * thrown. The exception text indicates the parser position, - * the expected event and the current event that is not meeting the - * requirement. - * - * <p>Essentially it does this - * <pre> - * if (type != getEventType() - * || (namespace != null && !namespace.equals( getNamespace () ) ) - * || (name != null && !name.equals( getName() ) ) ) - * throw new XmlPullParserException( "expected "+ TYPES[ type ]+getPositionDescription()); - * </pre> - */ - void require(int type, String namespace, String name) - throws XmlPullParserException, IOException; - - /** - * If current event is START_TAG then if next element is TEXT then element content is returned - * or if next event is END_TAG then empty string is returned, otherwise exception is thrown. - * After calling this function successfully parser will be positioned on END_TAG. - * - * <p>The motivation for this function is to allow to parse consistently both - * empty elements and elements that has non empty content, for example for input: <ol> - * <li><tag>foo</tag> - * <li><tag></tag> (which is equivalent to <tag/> - * both input can be parsed with the same code: - * <pre> - * p.nextTag() - * p.requireEvent(p.START_TAG, "", "tag"); - * String content = p.nextText(); - * p.requireEvent(p.END_TAG, "", "tag"); - * </pre> - * This function together with nextTag make it very easy to parse XML that has - * no mixed content. - * - * - * <p>Essentially it does this - * <pre> - * if(getEventType() != START_TAG) { - * throw new XmlPullParserException( - * "parser must be on START_TAG to read next text", this, null); - * } - * int eventType = next(); - * if(eventType == TEXT) { - * String result = getText(); - * eventType = next(); - * if(eventType != END_TAG) { - * throw new XmlPullParserException( - * "event TEXT it must be immediately followed by END_TAG", this, null); - * } - * return result; - * } else if(eventType == END_TAG) { - * return ""; - * } else { - * throw new XmlPullParserException( - * "parser must be on START_TAG or TEXT to read text", this, null); - * } - * </pre> - */ - String nextText() throws XmlPullParserException, IOException; - - /** - * Call next() and return event if it is START_TAG or END_TAG - * otherwise throw an exception. - * It will skip whitespace TEXT before actual tag if any. - * - * <p>essentially it does this - * <pre> - * int eventType = next(); - * if(eventType == TEXT && isWhitespace()) { // skip whitespace - * eventType = next(); - * } - * if (eventType != START_TAG && eventType != END_TAG) { - * throw new XmlPullParserException("expected start or end tag", this, null); - * } - * return eventType; - * </pre> - */ - int nextTag() throws XmlPullParserException, IOException; - -} - diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,329 +0,0 @@ -/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/ -// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/) - -package org.codehaus.plexus.util.xml.pull; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; - -/** - * Define an interface to serialization of XML Infoset. - * This interface abstracts away if serialized XML is XML 1.0 compatible text or - * other formats of XML 1.0 serializations (such as binary XML for example with WBXML). - * - * <p><b>PLEASE NOTE:</b> This interface will be part of XmlPull 1.2 API. - * It is included as basis for discussion. It may change in any way. - * - * <p>Exceptions that may be thrown are: IOException or runtime exception - * (more runtime exceptions can be thrown but are not declared and as such - * have no semantics defined for this interface): - * <ul> - * <li><em>IllegalArgumentException</em> - for almost all methods to signal that - * argument is illegal - * <li><em>IllegalStateException</em> - to signal that call has good arguments but - * is not expected here (violation of contract) and for features/properties - * when requesting setting unimplemented feature/property - * (UnsupportedOperationException would be better but it is not in MIDP) - * </ul> - * - * <p><b>NOTE:</b> writing CDSECT, ENTITY_REF, IGNORABLE_WHITESPACE, - * PROCESSING_INSTRUCTION, COMMENT, and DOCDECL in some implementations - * may not be supported (for example when serializing to WBXML). - * In such case IllegalStateException will be thrown and it is recommended - * to use an optional feature to signal that implementation is not - * supporting this kind of output. - */ -@Deprecated -public interface XmlSerializer { - - /** - * Set feature identified by name (recommended to be URI for uniqueness). - * Some well known optional features are defined in - * <a href="http://www.xmlpull.org/v1/doc/features.html"> - * http://www.xmlpull.org/v1/doc/features.html</a>. - * - * If feature is not recognized or can not be set - * then IllegalStateException MUST be thrown. - * - * @exception IllegalStateException If the feature is not supported or can not be set - */ - void setFeature(String name, - boolean state) - throws IllegalArgumentException, IllegalStateException; - - - /** - * Return the current value of the feature with given name. - * <p><strong>NOTE:</strong> unknown properties are <strong>always</strong> returned as null - * - * @param name The name of feature to be retrieved. - * @return The value of named feature. - * @exception IllegalArgumentException if feature string is null - */ - boolean getFeature(String name); - - - /** - * Set the value of a property. - * (the property name is recommended to be URI for uniqueness). - * Some well known optional properties are defined in - * <a href="http://www.xmlpull.org/v1/doc/properties.html"> - * http://www.xmlpull.org/v1/doc/properties.html</a>. - * - * If property is not recognized or can not be set - * then IllegalStateException MUST be thrown. - * - * @exception IllegalStateException if the property is not supported or can not be set - */ - void setProperty(String name, - Object value) - throws IllegalArgumentException, IllegalStateException; - - /** - * Look up the value of a property. - * - * The property name is any fully-qualified URI. I - * <p><strong>NOTE:</strong> unknown properties are <string>always</strong> returned as null - * - * @param name The name of property to be retrieved. - * @return The value of named property. - */ - Object getProperty(String name); - - /** - * Set to use binary output stream with given encoding. - */ - void setOutput (OutputStream os, String encoding) - throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Set the output to the given writer. - * <p><b>WARNING</b> no information about encoding is available! - */ - void setOutput (Writer writer) - throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Write <?xml declaration with encoding (if encoding not null) - * and standalone flag (if standalone not null) - * This method can only be called just after setOutput. - */ - void startDocument (String encoding, Boolean standalone) - throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Finish writing. All unclosed start tags will be closed and output - * will be flushed. After calling this method no more output can be - * serialized until next call to setOutput() - */ - void endDocument () - throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Binds the given prefix to the given namespace. - * This call is valid for the next element including child elements. - * The prefix and namespace MUST be always declared even if prefix - * is not used in element (startTag() or attribute()) - for XML 1.0 - * it must result in declaring <code>xmlns:prefix='namespace'</code> - * (or <code>xmlns:prefix="namespace"</code> depending what character is used - * to quote attribute value). - * - * <p><b>NOTE:</b> this method MUST be called directly before startTag() - * and if anything but startTag() or setPrefix() is called next there will be exception. - * <p><b>NOTE:</b> prefixes "xml" and "xmlns" are already bound - * and can not be redefined see: - * <a href="http://www.w3.org/XML/xml-names-19990114-errata#NE05">Namespaces in XML Errata</a>. - * <p><b>NOTE:</b> to set default namespace use as prefix empty string. - * - * @param prefix must be not null (or IllegalArgumentException is thrown) - * @param namespace must be not null - */ - void setPrefix (String prefix, String namespace) - throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Return namespace that corresponds to given prefix - * If there is no prefix bound to this namespace return null - * but if generatePrefix is false then return generated prefix. - * - * <p><b>NOTE:</b> if the prefix is empty string "" and default namespace is bound - * to this prefix then empty string ("") is returned. - * - * <p><b>NOTE:</b> prefixes "xml" and "xmlns" are already bound - * will have values as defined - * <a href="http://www.w3.org/TR/REC-xml-names/">Namespaces in XML specification</a> - */ - String getPrefix (String namespace, boolean generatePrefix) - throws IllegalArgumentException; - - /** - * Returns the current depth of the element. - * Outside the root element, the depth is 0. The - * depth is incremented by 1 when startTag() is called. - * The depth is decremented after the call to endTag() - * event was observed. - * - * <pre> - * <!-- outside --> 0 - * <root> 1 - * sometext 1 - * <foobar> 2 - * </foobar> 2 - * </root> 1 - * <!-- outside --> 0 - * </pre> - */ - int getDepth(); - - /** - * Returns the namespace URI of the current element as set by startTag(). - * - * <p><b>NOTE:</b> that means in particular that: <ul> - * <li>if there was startTag("", ...) then getNamespace() returns "" - * <li>if there was startTag(null, ...) then getNamespace() returns null - * </ul> - * - * @return namespace set by startTag() that is currently in scope - */ - String getNamespace (); - - /** - * Returns the name of the current element as set by startTag(). - * It can only be null before first call to startTag() - * or when last endTag() is called to close first startTag(). - * - * @return namespace set by startTag() that is currently in scope - */ - String getName(); - - /** - * Writes a start tag with the given namespace and name. - * If there is no prefix defined for the given namespace, - * a prefix will be defined automatically. - * The explicit prefixes for namespaces can be established by calling setPrefix() - * immediately before this method. - * If namespace is null no namespace prefix is printed but just name. - * If namespace is empty string then serializer will make sure that - * default empty namespace is declared (in XML 1.0 xmlns='') - * or throw IllegalStateException if default namespace is already bound - * to non-empty string. - */ - XmlSerializer startTag (String namespace, String name) - throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Write an attribute. Calls to attribute() MUST follow a call to - * startTag() immediately. If there is no prefix defined for the - * given namespace, a prefix will be defined automatically. - * If namespace is null or empty string - * no namespace prefix is printed but just name. - */ - XmlSerializer attribute (String namespace, String name, String value) - throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Write end tag. Repetition of namespace and name is just for avoiding errors. - * <p><b>Background:</b> in kXML endTag had no arguments, and non matching tags were - * very difficult to find... - * If namespace is null no namespace prefix is printed but just name. - * If namespace is empty string then serializer will make sure that - * default empty namespace is declared (in XML 1.0 xmlns=''). - */ - XmlSerializer endTag (String namespace, String name) - throws IOException, IllegalArgumentException, IllegalStateException; - - - // /** - // * Writes a start tag with the given namespace and name. - // * <br />If there is no prefix defined (prefix == null) for the given namespace, - // * a prefix will be defined automatically. - // * <br />If explicit prefixes is passed (prefix != null) then it will be used - // *and namespace declared if not already declared or - // * throw IllegalStateException the same prefix was already set on this - // * element (setPrefix()) and was bound to different namespace. - // * <br />If namespace is null then prefix must be null too or IllegalStateException is thrown. - // * <br />If namespace is null then no namespace prefix is printed but just name. - // * <br />If namespace is empty string then serializer will make sure that - // * default empty namespace is declared (in XML 1.0 xmlns='') - // * or throw IllegalStateException if default namespace is already bound - // * to non-empty string. - // */ - // XmlSerializer startTag (String prefix, String namespace, String name) - // throws IOException, IllegalArgumentException, IllegalStateException; - // - // /** - // * Write an attribute. Calls to attribute() MUST follow a call to - // * startTag() immediately. - // * <br />If there is no prefix defined (prefix == null) for the given namespace, - // * a prefix will be defined automatically. - // * <br />If explicit prefixes is passed (prefix != null) then it will be used - // * and namespace declared if not already declared or - // * throw IllegalStateException the same prefix was already set on this - // * element (setPrefix()) and was bound to different namespace. - // * <br />If namespace is null then prefix must be null too or IllegalStateException is thrown. - // * <br />If namespace is null then no namespace prefix is printed but just name. - // * <br />If namespace is empty string then serializer will make sure that - // * default empty namespace is declared (in XML 1.0 xmlns='') - // * or throw IllegalStateException if default namespace is already bound - // * to non-empty string. - // */ - // XmlSerializer attribute (String prefix, String namespace, String name, String value) - // throws IOException, IllegalArgumentException, IllegalStateException; - // - // /** - // * Write end tag. Repetition of namespace, prefix, and name is just for avoiding errors. - // * <br />If namespace or name arguments are different from corresponding startTag call - // * then IllegalArgumentException is thrown, if prefix argument is not null and is different - // * from corresponding starTag then IllegalArgumentException is thrown. - // * <br />If namespace is null then prefix must be null too or IllegalStateException is thrown. - // * <br />If namespace is null then no namespace prefix is printed but just name. - // * <br />If namespace is empty string then serializer will make sure that - // * default empty namespace is declared (in XML 1.0 xmlns=''). - // * <p><b>Background:</b> in kXML endTag had no arguments, and non matching tags were - // * very difficult to find...</p> - // */ - // ALEK: This is really optional as prefix in end tag MUST correspond to start tag but good for error checking - // XmlSerializer endTag (String prefix, String namespace, String name) - // throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Writes text, where special XML chars are escaped automatically - */ - XmlSerializer text (String text) - throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Writes text, where special XML chars are escaped automatically - */ - XmlSerializer text (char [] buf, int start, int len) - throws IOException, IllegalArgumentException, IllegalStateException; - - void cdsect (String text) - throws IOException, IllegalArgumentException, IllegalStateException; - void entityRef (String text) throws IOException, - IllegalArgumentException, IllegalStateException; - void processingInstruction (String text) - throws IOException, IllegalArgumentException, IllegalStateException; - void comment (String text) - throws IOException, IllegalArgumentException, IllegalStateException; - void docdecl (String text) - throws IOException, IllegalArgumentException, IllegalStateException; - void ignorableWhitespace (String text) - throws IOException, IllegalArgumentException, IllegalStateException; - - /** - * Write all pending output to the stream. - * If method startTag() or attribute() was called then start tag is closed (final >) - * before flush() is called on underlying output stream. - * - * <p><b>NOTE:</b> if there is need to close start tag - * (so no more attribute() calls are allowed) but without flushing output - * call method text() with empty string (text("")). - * - */ - void flush () - throws IOException; - -} - diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlReaderException.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlReaderException.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlReaderException.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlReaderException.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,179 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.codehaus.plexus.util.xml; - -import java.io.InputStream; -import java.io.IOException; - -/** - * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding can not be determined - * according to the XML 1.0 specification and RFC 3023. - * <p> - * The exception returns the unconsumed InputStream to allow the application to do an alternate processing with the - * stream. Note that the original InputStream given to the XmlReader cannot be used as that one has been already read. - * <p> - * - * @author Alejandro Abdelnur - * @version revision 1.1 taken on 26/06/2007 from Rome (see https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java) - */ -@Deprecated -public class XmlReaderException extends IOException -{ - private String _bomEncoding; - - private String _xmlGuessEncoding; - - private String _xmlEncoding; - - private String _contentTypeMime; - - private String _contentTypeEncoding; - - private InputStream _is; - - /** - * Creates an exception instance if the charset encoding could not be determined. - * <p> - * Instances of this exception are thrown by the XmlReader. - * <p> - * - * @param msg - * message describing the reason for the exception. - * @param bomEnc - * BOM encoding. - * @param xmlGuessEnc - * XML guess encoding. - * @param xmlEnc - * XML prolog encoding. - * @param is - * the unconsumed InputStream. - * - */ - public XmlReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) - { - this( msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is ); - } - - /** - * Creates an exception instance if the charset encoding could not be determined. - * <p> - * Instances of this exception are thrown by the XmlReader. - * <p> - * - * @param msg - * message describing the reason for the exception. - * @param ctMime - * MIME type in the content-type. - * @param ctEnc - * encoding in the content-type. - * @param bomEnc - * BOM encoding. - * @param xmlGuessEnc - * XML guess encoding. - * @param xmlEnc - * XML prolog encoding. - * @param is - * the unconsumed InputStream. - * - */ - public XmlReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, - String xmlEnc, InputStream is ) - { - super( msg ); - _contentTypeMime = ctMime; - _contentTypeEncoding = ctEnc; - _bomEncoding = bomEnc; - _xmlGuessEncoding = xmlGuessEnc; - _xmlEncoding = xmlEnc; - _is = is; - } - - /** - * Returns the BOM encoding found in the InputStream. - * <p> - * - * @return the BOM encoding, null if none. - * - */ - public String getBomEncoding() - { - return _bomEncoding; - } - - /** - * Returns the encoding guess based on the first bytes of the InputStream. - * <p> - * - * @return the encoding guess, null if it couldn't be guessed. - * - */ - public String getXmlGuessEncoding() - { - return _xmlGuessEncoding; - } - - /** - * Returns the encoding found in the XML prolog of the InputStream. - * <p> - * - * @return the encoding of the XML prolog, null if none. - * - */ - public String getXmlEncoding() - { - return _xmlEncoding; - } - - /** - * Returns the MIME type in the content-type used to attempt determining the encoding. - * <p> - * - * @return the MIME type in the content-type, null if there was not content-type or the encoding detection did not - * involve HTTP. - * - */ - public String getContentTypeMime() - { - return _contentTypeMime; - } - - /** - * Returns the encoding in the content-type used to attempt determining the encoding. - * <p> - * - * @return the encoding in the content-type, null if there was not content-type, no encoding in it or the encoding - * detection did not involve HTTP. - * - */ - public String getContentTypeEncoding() - { - return _contentTypeEncoding; - } - - /** - * Returns the unconsumed InputStream to allow the application to do an alternate encoding detection on the - * InputStream. - * <p> - * - * @return the unconsumed InputStream. - * - */ - public InputStream getInputStream() - { - return _is; - } -} diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,787 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.codehaus.plexus.util.xml; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.net.URL; -import java.net.URLConnection; -import java.net.HttpURLConnection; -import java.util.Locale; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import java.text.MessageFormat; - -/** - * Character stream that handles (or at least attemtps to) all the necessary Voodo to figure out the charset encoding of - * the XML document within the stream. - * <p> - * IMPORTANT: This class is not related in any way to the org.xml.sax.XMLReader. This one IS a character stream. - * <p> - * All this has to be done without consuming characters from the stream, if not the XML parser will not recognized the - * document as a valid XML. This is not 100% true, but it's close enough (UTF-8 BOM is not handled by all parsers right - * now, XmlReader handles it and things work in all parsers). - * <p> - * The XmlReader class handles the charset encoding of XML documents in Files, raw streams and HTTP streams by offering - * a wide set of constructors. - * <P> - * By default the charset encoding detection is lenient, the constructor with the lenient flag can be used for an script - * (following HTTP MIME and XML specifications). All this is nicely explained by Mark Pilgrim in his blog, <a - * href="http://diveintomark.org/archives/2004/02/13/xml-media-types"> Determining the character encoding of a feed</a>. - * <p> - * - * @author Alejandro Abdelnur - * @version revision 1.17 taken on 26/06/2007 from Rome (see https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReader.java) - * @deprecated use XmlStreamReader - * @since 1.4.3 - */ -@Deprecated -public class XmlReader extends Reader -{ - private static final int BUFFER_SIZE = 4096; - - private static final String UTF_8 = "UTF-8"; - - private static final String US_ASCII = "US-ASCII"; - - private static final String UTF_16BE = "UTF-16BE"; - - private static final String UTF_16LE = "UTF-16LE"; - - private static final String UTF_16 = "UTF-16"; - - private static final String EBCDIC = "CP1047"; - - private static String _staticDefaultEncoding = null; - - private Reader _reader; - - private String _encoding; - - private String _defaultEncoding; - - /** - * Sets the default encoding to use if none is set in HTTP content-type, XML prolog and the rules based on - * content-type are not adequate. <p/> If it is set to NULL the content-type based rules are used. <p/> By default - * it is NULL. <p/> - * - * @param encoding - * charset encoding to default to. - */ - public static void setDefaultEncoding( String encoding ) - { - _staticDefaultEncoding = encoding; - } - - /** - * Returns the default encoding to use if none is set in HTTP content-type, XML prolog and the rules based on - * content-type are not adequate. <p/> If it is NULL the content-type based rules are used. <p/> - * - * @return the default encoding to use. - */ - public static String getDefaultEncoding() - { - return _staticDefaultEncoding; - } - - /** - * Creates a Reader for a File. - * <p> - * It looks for the UTF-8 BOM first, if none sniffs the XML prolog charset, if this is also missing defaults to - * UTF-8. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param file - * File to create a Reader from. - * @throws IOException - * thrown if there is a problem reading the file. - * - */ - public XmlReader( File file ) throws IOException - { - this( new FileInputStream( file ) ); - } - - /** - * Creates a Reader for a raw InputStream. - * <p> - * It follows the same logic used for files. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param is - * InputStream to create a Reader from. - * @throws IOException - * thrown if there is a problem reading the stream. - * - */ - public XmlReader( InputStream is ) throws IOException - { - this( is, true ); - } - - /** - * Creates a Reader for a raw InputStream. - * <p> - * It follows the same logic used for files. - * <p> - * If lenient detection is indicated and the detection above fails as per specifications it then attempts the - * following: - * <p> - * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. - * <p> - * Else if the XML prolog had a charset encoding that encoding is used. - * <p> - * Else if the content type had a charset encoding that encoding is used. - * <p> - * Else 'UTF-8' is used. - * <p> - * If lenient detection is indicated an XmlStreamReaderException is never thrown. - * <p> - * - * @param is - * InputStream to create a Reader from. - * @param lenient - * indicates if the charset encoding detection should be relaxed. - * @throws IOException - * thrown if there is a problem reading the stream. - * @throws XmlStreamReaderException - * thrown if the charset encoding could not be determined according to the specs. - * - */ - public XmlReader( InputStream is, boolean lenient ) throws IOException, XmlStreamReaderException - { - _defaultEncoding = _staticDefaultEncoding; - try - { - doRawStream( is, lenient ); - } - catch ( XmlStreamReaderException ex ) - { - if ( !lenient ) - { - throw ex; - } - else - { - doLenientDetection( null, ex ); - } - } - } - - /** - * Creates a Reader using the InputStream of a URL. - * <p> - * If the URL is not of type HTTP and there is not 'content-type' header in the fetched data it uses the same logic - * used for Files. - * <p> - * If the URL is a HTTP Url or there is a 'content-type' header in the fetched data it uses the same logic used for - * an InputStream with content-type. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param url - * URL to create a Reader from. - * @throws IOException - * thrown if there is a problem reading the stream of the URL. - * - */ - public XmlReader( URL url ) throws IOException - { - this( url.openConnection() ); - } - - /** - * Creates a Reader using the InputStream of a URLConnection. - * <p> - * If the URLConnection is not of type HttpURLConnection and there is not 'content-type' header in the fetched data - * it uses the same logic used for files. - * <p> - * If the URLConnection is a HTTP Url or there is a 'content-type' header in the fetched data it uses the same logic - * used for an InputStream with content-type. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param conn - * URLConnection to create a Reader from. - * @throws IOException - * thrown if there is a problem reading the stream of the URLConnection. - * - */ - public XmlReader( URLConnection conn ) throws IOException - { - _defaultEncoding = _staticDefaultEncoding; - boolean lenient = true; - if ( conn instanceof HttpURLConnection ) - { - try - { - doHttpStream( conn.getInputStream(), conn.getContentType(), lenient ); - } - catch ( XmlStreamReaderException ex ) - { - doLenientDetection( conn.getContentType(), ex ); - } - } - else if ( conn.getContentType() != null ) - { - try - { - doHttpStream( conn.getInputStream(), conn.getContentType(), lenient ); - } - catch ( XmlStreamReaderException ex ) - { - doLenientDetection( conn.getContentType(), ex ); - } - } - else - { - try - { - doRawStream( conn.getInputStream(), lenient ); - } - catch ( XmlStreamReaderException ex ) - { - doLenientDetection( null, ex ); - } - } - } - - /** - * Creates a Reader using an InputStream an the associated content-type header. - * <p> - * First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. If there is not - * content-type encoding checks the XML prolog encoding. If there is not XML prolog encoding uses the default - * encoding mandated by the content-type MIME type. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param is - * InputStream to create the reader from. - * @param httpContentType - * content-type header to use for the resolution of the charset encoding. - * @throws IOException - * thrown if there is a problem reading the file. - * - */ - public XmlReader( InputStream is, String httpContentType ) throws IOException - { - this( is, httpContentType, true ); - } - - /** - * Creates a Reader using an InputStream an the associated content-type header. This constructor is lenient - * regarding the encoding detection. - * <p> - * First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. If there is not - * content-type encoding checks the XML prolog encoding. If there is not XML prolog encoding uses the default - * encoding mandated by the content-type MIME type. - * <p> - * If lenient detection is indicated and the detection above fails as per specifications it then attempts the - * following: - * <p> - * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. - * <p> - * Else if the XML prolog had a charset encoding that encoding is used. - * <p> - * Else if the content type had a charset encoding that encoding is used. - * <p> - * Else 'UTF-8' is used. - * <p> - * If lenient detection is indicated an XmlStreamReaderException is never thrown. - * <p> - * - * @param is - * InputStream to create the reader from. - * @param httpContentType - * content-type header to use for the resolution of the charset encoding. - * @param lenient - * indicates if the charset encoding detection should be relaxed. - * @throws IOException - * thrown if there is a problem reading the file. - * @throws XmlStreamReaderException - * thrown if the charset encoding could not be determined according to the specs. - * - */ - public XmlReader( InputStream is, String httpContentType, boolean lenient, String defaultEncoding ) - throws IOException, XmlStreamReaderException - { - _defaultEncoding = ( defaultEncoding == null ) ? _staticDefaultEncoding : defaultEncoding; - try - { - doHttpStream( is, httpContentType, lenient ); - } - catch ( XmlStreamReaderException ex ) - { - if ( !lenient ) - { - throw ex; - } - else - { - doLenientDetection( httpContentType, ex ); - } - } - } - - /** - * Creates a Reader using an InputStream an the associated content-type header. This constructor is lenient - * regarding the encoding detection. - * <p> - * First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. If there is not - * content-type encoding checks the XML prolog encoding. If there is not XML prolog encoding uses the default - * encoding mandated by the content-type MIME type. - * <p> - * If lenient detection is indicated and the detection above fails as per specifications it then attempts the - * following: - * <p> - * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. - * <p> - * Else if the XML prolog had a charset encoding that encoding is used. - * <p> - * Else if the content type had a charset encoding that encoding is used. - * <p> - * Else 'UTF-8' is used. - * <p> - * If lenient detection is indicated an XmlStreamReaderException is never thrown. - * <p> - * - * @param is - * InputStream to create the reader from. - * @param httpContentType - * content-type header to use for the resolution of the charset encoding. - * @param lenient - * indicates if the charset encoding detection should be relaxed. - * @throws IOException - * thrown if there is a problem reading the file. - * @throws XmlStreamReaderException - * thrown if the charset encoding could not be determined according to the specs. - * - */ - public XmlReader( InputStream is, String httpContentType, boolean lenient ) throws IOException, XmlStreamReaderException - { - this( is, httpContentType, lenient, null ); - } - - private void doLenientDetection( String httpContentType, XmlStreamReaderException ex ) throws IOException - { - if ( httpContentType != null ) - { - if ( httpContentType.startsWith( "text/html" ) ) - { - httpContentType = httpContentType.substring( "text/html".length() ); - httpContentType = "text/xml" + httpContentType; - try - { - doHttpStream( ex.getInputStream(), httpContentType, true ); - ex = null; - } - catch ( XmlStreamReaderException ex2 ) - { - ex = ex2; - } - } - } - if ( ex != null ) - { - String encoding = ex.getXmlEncoding(); - if ( encoding == null ) - { - encoding = ex.getContentTypeEncoding(); - } - if ( encoding == null ) - { - encoding = ( _defaultEncoding == null ) ? UTF_8 : _defaultEncoding; - } - prepareReader( ex.getInputStream(), encoding ); - } - } - - /** - * Returns the charset encoding of the XmlReader. - * <p> - * - * @return charset encoding. - * - */ - public String getEncoding() - { - return _encoding; - } - - public int read( char[] buf, int offset, int len ) throws IOException - { - return _reader.read( buf, offset, len ); - } - - /** - * Closes the XmlReader stream. - * <p> - * - * @throws IOException - * thrown if there was a problem closing the stream. - * - */ - public void close() throws IOException - { - _reader.close(); - } - - private void doRawStream( InputStream is, boolean lenient ) throws IOException - { - BufferedInputStream pis = new BufferedInputStream( is, BUFFER_SIZE ); - String bomEnc = getBOMEncoding( pis ); - String xmlGuessEnc = getXMLGuessEncoding( pis ); - String xmlEnc = getXmlProlog( pis, xmlGuessEnc ); - String encoding = calculateRawEncoding( bomEnc, xmlGuessEnc, xmlEnc, pis ); - prepareReader( pis, encoding ); - } - - private void doHttpStream( InputStream is, String httpContentType, boolean lenient ) throws IOException - { - BufferedInputStream pis = new BufferedInputStream( is, BUFFER_SIZE ); - String cTMime = getContentTypeMime( httpContentType ); - String cTEnc = getContentTypeEncoding( httpContentType ); - String bomEnc = getBOMEncoding( pis ); - String xmlGuessEnc = getXMLGuessEncoding( pis ); - String xmlEnc = getXmlProlog( pis, xmlGuessEnc ); - String encoding = calculateHttpEncoding( cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, pis, lenient ); - prepareReader( pis, encoding ); - } - - private void prepareReader( InputStream is, String encoding ) throws IOException - { - _reader = new InputStreamReader( is, encoding ); - _encoding = encoding; - } - - // InputStream is passed for XmlStreamReaderException creation only - private String calculateRawEncoding( String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) - throws IOException - { - String encoding; - if ( bomEnc == null ) - { - if ( xmlGuessEnc == null || xmlEnc == null ) - { - encoding = ( _defaultEncoding == null ) ? UTF_8 : _defaultEncoding; - } - else if ( xmlEnc.equals( UTF_16 ) && ( xmlGuessEnc.equals( UTF_16BE ) || xmlGuessEnc.equals( UTF_16LE ) ) ) - { - encoding = xmlGuessEnc; - } - else - { - encoding = xmlEnc; - } - } - else if ( bomEnc.equals( UTF_8 ) ) - { - if ( xmlGuessEnc != null && !xmlGuessEnc.equals( UTF_8 ) ) - { - throw new XmlStreamReaderException( RAW_EX_1.format( new Object[] { bomEnc, xmlGuessEnc, xmlEnc } ), bomEnc, - xmlGuessEnc, xmlEnc, is ); - } - if ( xmlEnc != null && !xmlEnc.equals( UTF_8 ) ) - { - throw new XmlStreamReaderException( RAW_EX_1.format( new Object[] { bomEnc, xmlGuessEnc, xmlEnc } ), bomEnc, - xmlGuessEnc, xmlEnc, is ); - } - encoding = UTF_8; - } - else if ( bomEnc.equals( UTF_16BE ) || bomEnc.equals( UTF_16LE ) ) - { - if ( xmlGuessEnc != null && !xmlGuessEnc.equals( bomEnc ) ) - { - throw new IOException( RAW_EX_1.format( new Object[] { bomEnc, xmlGuessEnc, xmlEnc } ) ); - } - if ( xmlEnc != null && !xmlEnc.equals( UTF_16 ) && !xmlEnc.equals( bomEnc ) ) - { - throw new XmlStreamReaderException( RAW_EX_1.format( new Object[] { bomEnc, xmlGuessEnc, xmlEnc } ), bomEnc, - xmlGuessEnc, xmlEnc, is ); - } - encoding = bomEnc; - } - else - { - throw new XmlStreamReaderException( RAW_EX_2.format( new Object[] { bomEnc, xmlGuessEnc, xmlEnc } ), bomEnc, - xmlGuessEnc, xmlEnc, is ); - } - return encoding; - } - - // InputStream is passed for XmlStreamReaderException creation only - private String calculateHttpEncoding( String cTMime, String cTEnc, String bomEnc, String xmlGuessEnc, - String xmlEnc, InputStream is, boolean lenient ) throws IOException - { - String encoding; - if ( lenient & xmlEnc != null ) - { - encoding = xmlEnc; - } - else - { - boolean appXml = isAppXml( cTMime ); - boolean textXml = isTextXml( cTMime ); - if ( appXml || textXml ) - { - if ( cTEnc == null ) - { - if ( appXml ) - { - encoding = calculateRawEncoding( bomEnc, xmlGuessEnc, xmlEnc, is ); - } - else - { - encoding = ( _defaultEncoding == null ) ? US_ASCII : _defaultEncoding; - } - } - else if ( bomEnc != null && ( cTEnc.equals( UTF_16BE ) || cTEnc.equals( UTF_16LE ) ) ) - { - throw new XmlStreamReaderException( HTTP_EX_1.format( new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, - xmlEnc } ), cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, is ); - } - else if ( cTEnc.equals( UTF_16 ) ) - { - if ( bomEnc != null && bomEnc.startsWith( UTF_16 ) ) - { - encoding = bomEnc; - } - else - { - throw new XmlStreamReaderException( HTTP_EX_2.format( new Object[] { cTMime, cTEnc, bomEnc, - xmlGuessEnc, xmlEnc } ), cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, is ); - } - } - else - { - encoding = cTEnc; - } - } - else - { - throw new XmlStreamReaderException( HTTP_EX_3.format( new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, - xmlEnc } ), cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, is ); - } - } - return encoding; - } - - // returns MIME type or NULL if httpContentType is NULL - private static String getContentTypeMime( String httpContentType ) - { - String mime = null; - if ( httpContentType != null ) - { - int i = httpContentType.indexOf( ";" ); - mime = ( ( i == -1 ) ? httpContentType : httpContentType.substring( 0, i ) ).trim(); - } - return mime; - } - - private static final Pattern CHARSET_PATTERN = Pattern.compile( "charset=([.[^; ]]*)" ); - - // returns charset parameter value, NULL if not present, NULL if httpContentType is NULL - private static String getContentTypeEncoding( String httpContentType ) - { - String encoding = null; - if ( httpContentType != null ) - { - int i = httpContentType.indexOf( ";" ); - if ( i > -1 ) - { - String postMime = httpContentType.substring( i + 1 ); - Matcher m = CHARSET_PATTERN.matcher( postMime ); - encoding = ( m.find() ) ? m.group( 1 ) : null; - encoding = ( encoding != null ) ? encoding.toUpperCase( Locale.ENGLISH ) : null; - } - } - return encoding; - } - - // returns the BOM in the stream, NULL if not present, - // if there was BOM the in the stream it is consumed - private static String getBOMEncoding( BufferedInputStream is ) throws IOException - { - String encoding = null; - int[] bytes = new int[3]; - is.mark( 3 ); - bytes[0] = is.read(); - bytes[1] = is.read(); - bytes[2] = is.read(); - - if ( bytes[0] == 0xFE && bytes[1] == 0xFF ) - { - encoding = UTF_16BE; - is.reset(); - is.read(); - is.read(); - } - else if ( bytes[0] == 0xFF && bytes[1] == 0xFE ) - { - encoding = UTF_16LE; - is.reset(); - is.read(); - is.read(); - } - else if ( bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF ) - { - encoding = UTF_8; - } - else - { - is.reset(); - } - return encoding; - } - - // returns the best guess for the encoding by looking the first bytes of the stream, '<?' - private static String getXMLGuessEncoding( BufferedInputStream is ) throws IOException - { - String encoding = null; - int[] bytes = new int[4]; - is.mark( 4 ); - bytes[0] = is.read(); - bytes[1] = is.read(); - bytes[2] = is.read(); - bytes[3] = is.read(); - is.reset(); - - if ( bytes[0] == 0x00 && bytes[1] == 0x3C && bytes[2] == 0x00 && bytes[3] == 0x3F ) - { - encoding = UTF_16BE; - } - else if ( bytes[0] == 0x3C && bytes[1] == 0x00 && bytes[2] == 0x3F && bytes[3] == 0x00 ) - { - encoding = UTF_16LE; - } - else if ( bytes[0] == 0x3C && bytes[1] == 0x3F && bytes[2] == 0x78 && bytes[3] == 0x6D ) - { - encoding = UTF_8; - } - else if ( bytes[0] == 0x4C && bytes[1] == 0x6F && bytes[2] == 0xA7 && bytes[3] == 0x94 ) - { - encoding = EBCDIC; - } - return encoding; - } - - static final Pattern ENCODING_PATTERN = - Pattern.compile( "<\\?xml.*encoding[\\s]*=[\\s]*((?:\".[^\"]*\")|(?:'.[^']*'))", Pattern.MULTILINE ); - - // returns the encoding declared in the <?xml encoding=...?>, NULL if none - private static String getXmlProlog( BufferedInputStream is, String guessedEnc ) throws IOException - { - String encoding = null; - if ( guessedEnc != null ) - { - byte[] bytes = new byte[BUFFER_SIZE]; - is.mark( BUFFER_SIZE ); - int offset = 0; - int max = BUFFER_SIZE; - int c = is.read( bytes, offset, max ); - int firstGT = -1; - String xmlProlog = null; - while ( c != -1 && firstGT == -1 && offset < BUFFER_SIZE ) - { - offset += c; - max -= c; - c = is.read( bytes, offset, max ); - xmlProlog = new String( bytes, 0, offset, guessedEnc ); - firstGT = xmlProlog.indexOf( '>' ); - } - if ( firstGT == -1 ) - { - if ( c == -1 ) - { - throw new IOException( "Unexpected end of XML stream" ); - } - else - { - throw new IOException( "XML prolog or ROOT element not found on first " + offset + " bytes" ); - } - } - int bytesRead = offset; - if ( bytesRead > 0 ) - { - is.reset(); - BufferedReader bReader = new BufferedReader( new StringReader( xmlProlog.substring( 0, firstGT + 1 ) ) ); - StringBuffer prolog = new StringBuffer(); - String line = bReader.readLine(); - while ( line != null ) - { - prolog.append( line ); - line = bReader.readLine(); - } - Matcher m = ENCODING_PATTERN.matcher( prolog ); - if ( m.find() ) - { - encoding = m.group( 1 ).toUpperCase( Locale.ENGLISH ); - encoding = encoding.substring( 1, encoding.length() - 1 ); - } - } - } - return encoding; - } - - // indicates if the MIME type belongs to the APPLICATION XML family - private static boolean isAppXml( String mime ) - { - return mime != null - && ( mime.equals( "application/xml" ) || mime.equals( "application/xml-dtd" ) - || mime.equals( "application/xml-external-parsed-entity" ) || ( mime.startsWith( "application/" ) && mime.endsWith( "+xml" ) ) ); - } - - // indicates if the MIME type belongs to the TEXT XML family - private static boolean isTextXml( String mime ) - { - return mime != null - && ( mime.equals( "text/xml" ) || mime.equals( "text/xml-external-parsed-entity" ) || ( mime.startsWith( "text/" ) && mime.endsWith( "+xml" ) ) ); - } - - private static final MessageFormat RAW_EX_1 = - new MessageFormat( "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch" ); - - private static final MessageFormat RAW_EX_2 = - new MessageFormat( "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM" ); - - private static final MessageFormat HTTP_EX_1 = - new MessageFormat( - "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL" ); - - private static final MessageFormat HTTP_EX_2 = - new MessageFormat( - "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch" ); - - private static final MessageFormat HTTP_EX_3 = - new MessageFormat( - "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], Invalid MIME" ); - -} diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReaderException.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReaderException.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReaderException.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReaderException.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,85 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.codehaus.plexus.util.xml; - -import java.io.InputStream; - -/** - * The XmlStreamReaderException is thrown by the XmlStreamReader constructors if the charset encoding can not be determined - * according to the XML 1.0 specification and RFC 3023. - * <p> - * The exception returns the unconsumed InputStream to allow the application to do an alternate processing with the - * stream. Note that the original InputStream given to the XmlStreamReader cannot be used as that one has been already read. - * <p> - * - * @author Alejandro Abdelnur - * @version revision 1.1 taken on 26/06/2007 from Rome (see https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java) - */ -@Deprecated -public class XmlStreamReaderException extends XmlReaderException -{ - /** - * Creates an exception instance if the charset encoding could not be determined. - * <p> - * Instances of this exception are thrown by the XmlReader. - * <p> - * - * @param msg - * message describing the reason for the exception. - * @param bomEnc - * BOM encoding. - * @param xmlGuessEnc - * XML guess encoding. - * @param xmlEnc - * XML prolog encoding. - * @param is - * the unconsumed InputStream. - * - */ - public XmlStreamReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) - { - super( msg, bomEnc, xmlGuessEnc, xmlEnc, is ); - } - - /** - * Creates an exception instance if the charset encoding could not be determined. - * <p> - * Instances of this exception are thrown by the XmlReader. - * <p> - * - * @param msg - * message describing the reason for the exception. - * @param ctMime - * MIME type in the content-type. - * @param ctEnc - * encoding in the content-type. - * @param bomEnc - * BOM encoding. - * @param xmlGuessEnc - * XML guess encoding. - * @param xmlEnc - * XML prolog encoding. - * @param is - * the unconsumed InputStream. - * - */ - public XmlStreamReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, - String xmlEnc, InputStream is ) - { - super( msg, ctMime, ctEnc, bomEnc, xmlGuessEnc, xmlEnc, is ); - } -} diff -Nru gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java --- gshell-2.6.5/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java 2011-12-28 20:41:12.000000000 +0100 +++ gshell-2.6.5-gil/gshell-util/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java 1970-01-01 01:00:00.000000000 +0100 @@ -1,271 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.codehaus.plexus.util.xml; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; - -/** - * Character stream that handles (or at least attemtps to) all the necessary Voodo to figure out the charset encoding of - * the XML document within the stream. - * <p> - * IMPORTANT: This class is not related in any way to the org.xml.sax.XMLReader. This one IS a character stream. - * <p> - * All this has to be done without consuming characters from the stream, if not the XML parser will not recognized the - * document as a valid XML. This is not 100% true, but it's close enough (UTF-8 BOM is not handled by all parsers right - * now, XmlReader handles it and things work in all parsers). - * <p> - * The XmlReader class handles the charset encoding of XML documents in Files, raw streams and HTTP streams by offering - * a wide set of constructors. - * <P> - * By default the charset encoding detection is lenient, the constructor with the lenient flag can be used for an script - * (following HTTP MIME and XML specifications). All this is nicely explained by Mark Pilgrim in his blog, <a - * href="http://diveintomark.org/archives/2004/02/13/xml-media-types"> Determining the character encoding of a feed</a>. - * <p> - * - * @author Alejandro Abdelnur - * @version revision 1.17 taken on 26/06/2007 from Rome (see https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReader.java) - * @since 1.4.4 - */ -@Deprecated -public class XmlStreamReader -extends XmlReader -{ - /** - * Creates a Reader for a File. - * <p> - * It looks for the UTF-8 BOM first, if none sniffs the XML prolog charset, if this is also missing defaults to - * UTF-8. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param file - * File to create a Reader from. - * @throws IOException - * thrown if there is a problem reading the file. - * - */ - public XmlStreamReader( File file ) throws IOException - { - super( file ); - } - - /** - * Creates a Reader for a raw InputStream. - * <p> - * It follows the same logic used for files. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param is - * InputStream to create a Reader from. - * @throws IOException - * thrown if there is a problem reading the stream. - * - */ - public XmlStreamReader( InputStream is ) throws IOException - { - super( is ); - } - - /** - * Creates a Reader for a raw InputStream. - * <p> - * It follows the same logic used for files. - * <p> - * If lenient detection is indicated and the detection above fails as per specifications it then attempts the - * following: - * <p> - * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. - * <p> - * Else if the XML prolog had a charset encoding that encoding is used. - * <p> - * Else if the content type had a charset encoding that encoding is used. - * <p> - * Else 'UTF-8' is used. - * <p> - * If lenient detection is indicated an XmlStreamReaderException is never thrown. - * <p> - * - * @param is - * InputStream to create a Reader from. - * @param lenient - * indicates if the charset encoding detection should be relaxed. - * @throws IOException - * thrown if there is a problem reading the stream. - * @throws XmlStreamReaderException - * thrown if the charset encoding could not be determined according to the specs. - * - */ - public XmlStreamReader( InputStream is, boolean lenient ) throws IOException, XmlStreamReaderException - { - super( is, lenient ); - } - - /** - * Creates a Reader using the InputStream of a URL. - * <p> - * If the URL is not of type HTTP and there is not 'content-type' header in the fetched data it uses the same logic - * used for Files. - * <p> - * If the URL is a HTTP Url or there is a 'content-type' header in the fetched data it uses the same logic used for - * an InputStream with content-type. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param url - * URL to create a Reader from. - * @throws IOException - * thrown if there is a problem reading the stream of the URL. - * - */ - public XmlStreamReader( URL url ) throws IOException - { - super( url ); - } - - /** - * Creates a Reader using the InputStream of a URLConnection. - * <p> - * If the URLConnection is not of type HttpURLConnection and there is not 'content-type' header in the fetched data - * it uses the same logic used for files. - * <p> - * If the URLConnection is a HTTP Url or there is a 'content-type' header in the fetched data it uses the same logic - * used for an InputStream with content-type. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param conn - * URLConnection to create a Reader from. - * @throws IOException - * thrown if there is a problem reading the stream of the URLConnection. - * - */ - public XmlStreamReader( URLConnection conn ) throws IOException - { - super( conn ); - } - - /** - * Creates a Reader using an InputStream an the associated content-type header. - * <p> - * First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. If there is not - * content-type encoding checks the XML prolog encoding. If there is not XML prolog encoding uses the default - * encoding mandated by the content-type MIME type. - * <p> - * It does a lenient charset encoding detection, check the constructor with the lenient parameter for details. - * <p> - * - * @param is - * InputStream to create the reader from. - * @param httpContentType - * content-type header to use for the resolution of the charset encoding. - * @throws IOException - * thrown if there is a problem reading the file. - * - */ - public XmlStreamReader( InputStream is, String httpContentType ) throws IOException - { - super( is, httpContentType ); - } - - /** - * Creates a Reader using an InputStream an the associated content-type header. This constructor is lenient - * regarding the encoding detection. - * <p> - * First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. If there is not - * content-type encoding checks the XML prolog encoding. If there is not XML prolog encoding uses the default - * encoding mandated by the content-type MIME type. - * <p> - * If lenient detection is indicated and the detection above fails as per specifications it then attempts the - * following: - * <p> - * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. - * <p> - * Else if the XML prolog had a charset encoding that encoding is used. - * <p> - * Else if the content type had a charset encoding that encoding is used. - * <p> - * Else 'UTF-8' is used. - * <p> - * If lenient detection is indicated an XmlStreamReaderException is never thrown. - * <p> - * - * @param is - * InputStream to create the reader from. - * @param httpContentType - * content-type header to use for the resolution of the charset encoding. - * @param lenient - * indicates if the charset encoding detection should be relaxed. - * @throws IOException - * thrown if there is a problem reading the file. - * @throws XmlStreamReaderException - * thrown if the charset encoding could not be determined according to the specs. - * - */ - public XmlStreamReader( InputStream is, String httpContentType, boolean lenient, String defaultEncoding ) - throws IOException, XmlStreamReaderException - { - super( is, httpContentType, lenient, defaultEncoding ); - } - - /** - * Creates a Reader using an InputStream an the associated content-type header. This constructor is lenient - * regarding the encoding detection. - * <p> - * First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. If there is not - * content-type encoding checks the XML prolog encoding. If there is not XML prolog encoding uses the default - * encoding mandated by the content-type MIME type. - * <p> - * If lenient detection is indicated and the detection above fails as per specifications it then attempts the - * following: - * <p> - * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. - * <p> - * Else if the XML prolog had a charset encoding that encoding is used. - * <p> - * Else if the content type had a charset encoding that encoding is used. - * <p> - * Else 'UTF-8' is used. - * <p> - * If lenient detection is indicated an XmlStreamReaderException is never thrown. - * <p> - * - * @param is - * InputStream to create the reader from. - * @param httpContentType - * content-type header to use for the resolution of the charset encoding. - * @param lenient - * indicates if the charset encoding detection should be relaxed. - * @throws IOException - * thrown if there is a problem reading the file. - * @throws XmlStreamReaderException - * thrown if the charset encoding could not be determined according to the specs. - * - */ - public XmlStreamReader( InputStream is, String httpContentType, boolean lenient ) throws IOException, XmlStreamReaderException - { - super( is, httpContentType, lenient ); - } -}