1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/sax/SAXDocumentParser.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,1791 @@ 1.4 +/* 1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + * 1.28 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. 1.29 + */ 1.30 + 1.31 +package com.sun.xml.internal.fastinfoset.sax; 1.32 + 1.33 +import com.sun.xml.internal.fastinfoset.Decoder; 1.34 +import com.sun.xml.internal.fastinfoset.DecoderStateTables; 1.35 +import com.sun.xml.internal.fastinfoset.EncodingConstants; 1.36 +import com.sun.xml.internal.fastinfoset.QualifiedName; 1.37 +import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory; 1.38 +import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmState; 1.39 +import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmContentHandler; 1.40 +import com.sun.xml.internal.org.jvnet.fastinfoset.sax.FastInfosetReader; 1.41 +import com.sun.xml.internal.org.jvnet.fastinfoset.sax.PrimitiveTypeContentHandler; 1.42 +import com.sun.xml.internal.fastinfoset.util.CharArray; 1.43 +import com.sun.xml.internal.fastinfoset.util.CharArrayString; 1.44 +import java.io.IOException; 1.45 +import java.io.InputStream; 1.46 +import java.net.URL; 1.47 +import java.util.Map; 1.48 +import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm; 1.49 +import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException; 1.50 +import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes; 1.51 +import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException; 1.52 +import org.xml.sax.ContentHandler; 1.53 +import org.xml.sax.DTDHandler; 1.54 +import org.xml.sax.EntityResolver; 1.55 +import org.xml.sax.ErrorHandler; 1.56 +import org.xml.sax.InputSource; 1.57 +import org.xml.sax.SAXException; 1.58 +import org.xml.sax.SAXNotRecognizedException; 1.59 +import org.xml.sax.SAXNotSupportedException; 1.60 +import org.xml.sax.SAXParseException; 1.61 +import org.xml.sax.ext.LexicalHandler; 1.62 +import org.xml.sax.helpers.DefaultHandler; 1.63 +import com.sun.xml.internal.fastinfoset.CommonResourceBundle; 1.64 +import java.util.logging.Level; 1.65 +import java.util.logging.Logger; 1.66 +import org.xml.sax.ext.DeclHandler; 1.67 + 1.68 +/** 1.69 + * The Fast Infoset SAX parser. 1.70 + * <p> 1.71 + * Instantiate this parser to parse a fast infoset document in accordance 1.72 + * with the SAX API. 1.73 + * 1.74 + * <p> 1.75 + * More than one fast infoset document may be decoded from the 1.76 + * {@link java.io.InputStream}. 1.77 + */ 1.78 +public class SAXDocumentParser extends Decoder implements FastInfosetReader { 1.79 + private static final Logger logger = Logger.getLogger(SAXDocumentParser.class.getName()); 1.80 + 1.81 + /* 1.82 + * Empty lexical handler used by default to report 1.83 + * lexical-based events 1.84 + */ 1.85 + private static final class LexicalHandlerImpl implements LexicalHandler { 1.86 + public void comment(char[] ch, int start, int end) { } 1.87 + 1.88 + public void startDTD(String name, String publicId, String systemId) { } 1.89 + public void endDTD() { } 1.90 + 1.91 + public void startEntity(String name) { } 1.92 + public void endEntity(String name) { } 1.93 + 1.94 + public void startCDATA() { } 1.95 + public void endCDATA() { } 1.96 + }; 1.97 + 1.98 + /* 1.99 + * Empty DTD declaration handler used by default to report 1.100 + * DTD declaration-based events 1.101 + */ 1.102 + private static final class DeclHandlerImpl implements DeclHandler { 1.103 + public void elementDecl(String name, String model) throws SAXException { 1.104 + } 1.105 + 1.106 + public void attributeDecl(String eName, String aName, 1.107 + String type, String mode, String value) throws SAXException { 1.108 + } 1.109 + 1.110 + public void internalEntityDecl(String name, 1.111 + String value) throws SAXException { 1.112 + } 1.113 + 1.114 + public void externalEntityDecl(String name, 1.115 + String publicId, String systemId) throws SAXException { 1.116 + } 1.117 + } 1.118 + 1.119 + /** 1.120 + * SAX Namespace attributes features 1.121 + */ 1.122 + protected boolean _namespacePrefixesFeature = false; 1.123 + 1.124 + /** 1.125 + * Reference to entity resolver. 1.126 + */ 1.127 + protected EntityResolver _entityResolver; 1.128 + 1.129 + /** 1.130 + * Reference to dtd handler. 1.131 + */ 1.132 + protected DTDHandler _dtdHandler; 1.133 + 1.134 + /** 1.135 + * Reference to content handler. 1.136 + */ 1.137 + protected ContentHandler _contentHandler; 1.138 + 1.139 + /** 1.140 + * Reference to error handler. 1.141 + */ 1.142 + protected ErrorHandler _errorHandler; 1.143 + 1.144 + /** 1.145 + * Reference to lexical handler. 1.146 + */ 1.147 + protected LexicalHandler _lexicalHandler; 1.148 + 1.149 + /** 1.150 + * Reference to DTD declaration handler. 1.151 + */ 1.152 + protected DeclHandler _declHandler; 1.153 + 1.154 + protected EncodingAlgorithmContentHandler _algorithmHandler; 1.155 + 1.156 + protected PrimitiveTypeContentHandler _primitiveHandler; 1.157 + 1.158 + protected BuiltInEncodingAlgorithmState builtInAlgorithmState = 1.159 + new BuiltInEncodingAlgorithmState(); 1.160 + 1.161 + protected AttributesHolder _attributes; 1.162 + 1.163 + protected int[] _namespacePrefixes = new int[16]; 1.164 + 1.165 + protected int _namespacePrefixesIndex; 1.166 + 1.167 + protected boolean _clearAttributes = false; 1.168 + 1.169 + /** Creates a new instance of DocumetParser2 */ 1.170 + public SAXDocumentParser() { 1.171 + DefaultHandler handler = new DefaultHandler(); 1.172 + _attributes = new AttributesHolder(_registeredEncodingAlgorithms); 1.173 + 1.174 + _entityResolver = handler; 1.175 + _dtdHandler = handler; 1.176 + _contentHandler = handler; 1.177 + _errorHandler = handler; 1.178 + _lexicalHandler = new LexicalHandlerImpl(); 1.179 + _declHandler = new DeclHandlerImpl(); 1.180 + } 1.181 + 1.182 + protected void resetOnError() { 1.183 + _clearAttributes = false; 1.184 + _attributes.clear(); 1.185 + _namespacePrefixesIndex = 0; 1.186 + 1.187 + if (_v != null) { 1.188 + _v.prefix.clearCompletely(); 1.189 + } 1.190 + _duplicateAttributeVerifier.clear(); 1.191 + } 1.192 + 1.193 + // XMLReader interface 1.194 + 1.195 + public boolean getFeature(String name) 1.196 + throws SAXNotRecognizedException, SAXNotSupportedException { 1.197 + if (name.equals(Features.NAMESPACES_FEATURE)) { 1.198 + return true; 1.199 + } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) { 1.200 + return _namespacePrefixesFeature; 1.201 + } else if (name.equals(Features.STRING_INTERNING_FEATURE) || 1.202 + name.equals(FastInfosetReader.STRING_INTERNING_PROPERTY)) { 1.203 + return getStringInterning(); 1.204 + } else { 1.205 + throw new SAXNotRecognizedException( 1.206 + CommonResourceBundle.getInstance().getString("message.featureNotSupported") + name); 1.207 + } 1.208 + } 1.209 + 1.210 + public void setFeature(String name, boolean value) 1.211 + throws SAXNotRecognizedException, SAXNotSupportedException { 1.212 + if (name.equals(Features.NAMESPACES_FEATURE)) { 1.213 + if (value == false) { 1.214 + throw new SAXNotSupportedException(name + ":" + value); 1.215 + } 1.216 + } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) { 1.217 + _namespacePrefixesFeature = value; 1.218 + } else if (name.equals(Features.STRING_INTERNING_FEATURE) || 1.219 + name.equals(FastInfosetReader.STRING_INTERNING_PROPERTY)) { 1.220 + setStringInterning(value); 1.221 + } else { 1.222 + throw new SAXNotRecognizedException( 1.223 + CommonResourceBundle.getInstance().getString("message.featureNotSupported") + name); 1.224 + } 1.225 + } 1.226 + 1.227 + public Object getProperty(String name) 1.228 + throws SAXNotRecognizedException, SAXNotSupportedException { 1.229 + if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) { 1.230 + return getLexicalHandler(); 1.231 + } else if (name.equals(Properties.DTD_DECLARATION_HANDLER_PROPERTY)) { 1.232 + return getDeclHandler(); 1.233 + } else if (name.equals(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY)) { 1.234 + return getExternalVocabularies(); 1.235 + } else if (name.equals(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY)) { 1.236 + return getRegisteredEncodingAlgorithms(); 1.237 + } else if (name.equals(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY)) { 1.238 + return getEncodingAlgorithmContentHandler(); 1.239 + } else if (name.equals(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY)) { 1.240 + return getPrimitiveTypeContentHandler(); 1.241 + } else { 1.242 + throw new SAXNotRecognizedException(CommonResourceBundle.getInstance(). 1.243 + getString("message.propertyNotRecognized", new Object[]{name})); 1.244 + } 1.245 + } 1.246 + 1.247 + public void setProperty(String name, Object value) 1.248 + throws SAXNotRecognizedException, SAXNotSupportedException { 1.249 + if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) { 1.250 + if (value instanceof LexicalHandler) { 1.251 + setLexicalHandler((LexicalHandler)value); 1.252 + } else { 1.253 + throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY); 1.254 + } 1.255 + } else if (name.equals(Properties.DTD_DECLARATION_HANDLER_PROPERTY)) { 1.256 + if (value instanceof DeclHandler) { 1.257 + setDeclHandler((DeclHandler)value); 1.258 + } else { 1.259 + throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY); 1.260 + } 1.261 + } else if (name.equals(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY)) { 1.262 + if (value instanceof Map) { 1.263 + setExternalVocabularies((Map)value); 1.264 + } else { 1.265 + throw new SAXNotSupportedException(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY); 1.266 + } 1.267 + } else if (name.equals(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY)) { 1.268 + if (value instanceof Map) { 1.269 + setRegisteredEncodingAlgorithms((Map)value); 1.270 + } else { 1.271 + throw new SAXNotSupportedException(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY); 1.272 + } 1.273 + } else if (name.equals(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY)) { 1.274 + if (value instanceof EncodingAlgorithmContentHandler) { 1.275 + setEncodingAlgorithmContentHandler((EncodingAlgorithmContentHandler)value); 1.276 + } else { 1.277 + throw new SAXNotSupportedException(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY); 1.278 + } 1.279 + } else if (name.equals(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY)) { 1.280 + if (value instanceof PrimitiveTypeContentHandler) { 1.281 + setPrimitiveTypeContentHandler((PrimitiveTypeContentHandler)value); 1.282 + } else { 1.283 + throw new SAXNotSupportedException(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY); 1.284 + } 1.285 + } else if (name.equals(FastInfosetReader.BUFFER_SIZE_PROPERTY)) { 1.286 + if (value instanceof Integer) { 1.287 + setBufferSize(((Integer)value).intValue()); 1.288 + } else { 1.289 + throw new SAXNotSupportedException(FastInfosetReader.BUFFER_SIZE_PROPERTY); 1.290 + } 1.291 + } else { 1.292 + throw new SAXNotRecognizedException(CommonResourceBundle.getInstance(). 1.293 + getString("message.propertyNotRecognized", new Object[]{name})); 1.294 + } 1.295 + } 1.296 + 1.297 + public void setEntityResolver(EntityResolver resolver) { 1.298 + _entityResolver = resolver; 1.299 + } 1.300 + 1.301 + public EntityResolver getEntityResolver() { 1.302 + return _entityResolver; 1.303 + } 1.304 + 1.305 + public void setDTDHandler(DTDHandler handler) { 1.306 + _dtdHandler = handler; 1.307 + } 1.308 + 1.309 + public DTDHandler getDTDHandler() { 1.310 + return _dtdHandler; 1.311 + } 1.312 + public void setContentHandler(ContentHandler handler) { 1.313 + _contentHandler = handler; 1.314 + } 1.315 + 1.316 + public ContentHandler getContentHandler() { 1.317 + return _contentHandler; 1.318 + } 1.319 + 1.320 + public void setErrorHandler(ErrorHandler handler) { 1.321 + _errorHandler = handler; 1.322 + } 1.323 + 1.324 + public ErrorHandler getErrorHandler() { 1.325 + return _errorHandler; 1.326 + } 1.327 + 1.328 + public void parse(InputSource input) throws IOException, SAXException { 1.329 + try { 1.330 + InputStream s = input.getByteStream(); 1.331 + if (s == null) { 1.332 + String systemId = input.getSystemId(); 1.333 + if (systemId == null) { 1.334 + throw new SAXException(CommonResourceBundle.getInstance().getString("message.inputSource")); 1.335 + } 1.336 + parse(systemId); 1.337 + } else { 1.338 + parse(s); 1.339 + } 1.340 + } catch (FastInfosetException e) { 1.341 + logger.log(Level.FINE, "parsing error", e); 1.342 + throw new SAXException(e); 1.343 + } 1.344 + } 1.345 + 1.346 + public void parse(String systemId) throws IOException, SAXException { 1.347 + try { 1.348 + systemId = SystemIdResolver.getAbsoluteURI(systemId); 1.349 + parse(new URL(systemId).openStream()); 1.350 + } catch (FastInfosetException e) { 1.351 + logger.log(Level.FINE, "parsing error", e); 1.352 + throw new SAXException(e); 1.353 + } 1.354 + } 1.355 + 1.356 + 1.357 + 1.358 + 1.359 + // FastInfosetReader 1.360 + 1.361 + public final void parse(InputStream s) throws IOException, FastInfosetException, SAXException { 1.362 + setInputStream(s); 1.363 + parse(); 1.364 + } 1.365 + 1.366 + public void setLexicalHandler(LexicalHandler handler) { 1.367 + _lexicalHandler = handler; 1.368 + } 1.369 + 1.370 + public LexicalHandler getLexicalHandler() { 1.371 + return _lexicalHandler; 1.372 + } 1.373 + 1.374 + public void setDeclHandler(DeclHandler handler) { 1.375 + _declHandler = handler; 1.376 + } 1.377 + 1.378 + public DeclHandler getDeclHandler() { 1.379 + return _declHandler; 1.380 + } 1.381 + 1.382 + public void setEncodingAlgorithmContentHandler(EncodingAlgorithmContentHandler handler) { 1.383 + _algorithmHandler = handler; 1.384 + } 1.385 + 1.386 + public EncodingAlgorithmContentHandler getEncodingAlgorithmContentHandler() { 1.387 + return _algorithmHandler; 1.388 + } 1.389 + 1.390 + public void setPrimitiveTypeContentHandler(PrimitiveTypeContentHandler handler) { 1.391 + _primitiveHandler = handler; 1.392 + } 1.393 + 1.394 + public PrimitiveTypeContentHandler getPrimitiveTypeContentHandler() { 1.395 + return _primitiveHandler; 1.396 + } 1.397 + 1.398 + 1.399 + 1.400 + 1.401 + public final void parse() throws FastInfosetException, IOException { 1.402 + if (_octetBuffer.length < _bufferSize) { 1.403 + _octetBuffer = new byte[_bufferSize]; 1.404 + } 1.405 + 1.406 + try { 1.407 + reset(); 1.408 + decodeHeader(); 1.409 + if (_parseFragments) 1.410 + processDIIFragment(); 1.411 + else 1.412 + processDII(); 1.413 + } catch (RuntimeException e) { 1.414 + try { 1.415 + _errorHandler.fatalError(new SAXParseException(e.getClass().getName(), null, e)); 1.416 + } catch (Exception ee) { 1.417 + } 1.418 + resetOnError(); 1.419 + // Wrap runtime exception 1.420 + throw new FastInfosetException(e); 1.421 + } catch (FastInfosetException e) { 1.422 + try { 1.423 + _errorHandler.fatalError(new SAXParseException(e.getClass().getName(), null, e)); 1.424 + } catch (Exception ee) { 1.425 + } 1.426 + resetOnError(); 1.427 + throw e; 1.428 + } catch (IOException e) { 1.429 + try { 1.430 + _errorHandler.fatalError(new SAXParseException(e.getClass().getName(), null, e)); 1.431 + } catch (Exception ee) { 1.432 + } 1.433 + resetOnError(); 1.434 + throw e; 1.435 + } 1.436 + } 1.437 + 1.438 + protected final void processDII() throws FastInfosetException, IOException { 1.439 + try { 1.440 + _contentHandler.startDocument(); 1.441 + } catch (SAXException e) { 1.442 + throw new FastInfosetException("processDII", e); 1.443 + } 1.444 + 1.445 + _b = read(); 1.446 + if (_b > 0) { 1.447 + processDIIOptionalProperties(); 1.448 + } 1.449 + 1.450 + // Decode one Document Type II, Comment IIs, PI IIs and one EII 1.451 + boolean firstElementHasOccured = false; 1.452 + boolean documentTypeDeclarationOccured = false; 1.453 + while(!_terminate || !firstElementHasOccured) { 1.454 + _b = read(); 1.455 + switch(DecoderStateTables.DII(_b)) { 1.456 + case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: 1.457 + processEII(_elementNameTable._array[_b], false); 1.458 + firstElementHasOccured = true; 1.459 + break; 1.460 + case DecoderStateTables.EII_AIIS_INDEX_SMALL: 1.461 + processEII(_elementNameTable._array[_b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true); 1.462 + firstElementHasOccured = true; 1.463 + break; 1.464 + case DecoderStateTables.EII_INDEX_MEDIUM: 1.465 + processEII(decodeEIIIndexMedium(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 1.466 + firstElementHasOccured = true; 1.467 + break; 1.468 + case DecoderStateTables.EII_INDEX_LARGE: 1.469 + processEII(decodeEIIIndexLarge(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 1.470 + firstElementHasOccured = true; 1.471 + break; 1.472 + case DecoderStateTables.EII_LITERAL: 1.473 + { 1.474 + final QualifiedName qn = decodeLiteralQualifiedName( 1.475 + _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, 1.476 + _elementNameTable.getNext()); 1.477 + _elementNameTable.add(qn); 1.478 + processEII(qn, (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 1.479 + firstElementHasOccured = true; 1.480 + break; 1.481 + } 1.482 + case DecoderStateTables.EII_NAMESPACES: 1.483 + processEIIWithNamespaces(); 1.484 + firstElementHasOccured = true; 1.485 + break; 1.486 + case DecoderStateTables.DOCUMENT_TYPE_DECLARATION_II: 1.487 + { 1.488 + if (documentTypeDeclarationOccured) { 1.489 + throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.secondOccurenceOfDTDII")); 1.490 + } 1.491 + documentTypeDeclarationOccured = true; 1.492 + 1.493 + String system_identifier = ((_b & EncodingConstants.DOCUMENT_TYPE_SYSTEM_IDENTIFIER_FLAG) > 0) 1.494 + ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; 1.495 + String public_identifier = ((_b & EncodingConstants.DOCUMENT_TYPE_PUBLIC_IDENTIFIER_FLAG) > 0) 1.496 + ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; 1.497 + 1.498 + _b = read(); 1.499 + while (_b == EncodingConstants.PROCESSING_INSTRUCTION) { 1.500 + switch(decodeNonIdentifyingStringOnFirstBit()) { 1.501 + case NISTRING_STRING: 1.502 + if (_addToTable) { 1.503 + _v.otherString.add(new CharArray(_charBuffer, 0, _charBufferLength, true)); 1.504 + } 1.505 + break; 1.506 + case NISTRING_ENCODING_ALGORITHM: 1.507 + throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.processingIIWithEncodingAlgorithm")); 1.508 + case NISTRING_INDEX: 1.509 + break; 1.510 + case NISTRING_EMPTY_STRING: 1.511 + break; 1.512 + } 1.513 + _b = read(); 1.514 + } 1.515 + if ((_b & EncodingConstants.TERMINATOR) != EncodingConstants.TERMINATOR) { 1.516 + throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.processingInstructionIIsNotTerminatedCorrectly")); 1.517 + } 1.518 + if (_b == EncodingConstants.DOUBLE_TERMINATOR) { 1.519 + _terminate = true; 1.520 + } 1.521 + 1.522 + if (_notations != null) _notations.clear(); 1.523 + if (_unparsedEntities != null) _unparsedEntities.clear(); 1.524 + /* 1.525 + * TODO 1.526 + * Report All events associated with DTD, PIs, notations etc 1.527 + */ 1.528 + break; 1.529 + } 1.530 + case DecoderStateTables.COMMENT_II: 1.531 + processCommentII(); 1.532 + break; 1.533 + case DecoderStateTables.PROCESSING_INSTRUCTION_II: 1.534 + processProcessingII(); 1.535 + break; 1.536 + case DecoderStateTables.TERMINATOR_DOUBLE: 1.537 + _doubleTerminate = true; 1.538 + case DecoderStateTables.TERMINATOR_SINGLE: 1.539 + _terminate = true; 1.540 + break; 1.541 + default: 1.542 + throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingDII")); 1.543 + } 1.544 + } 1.545 + 1.546 + // Decode any remaining Comment IIs, PI IIs 1.547 + while(!_terminate) { 1.548 + _b = read(); 1.549 + switch(DecoderStateTables.DII(_b)) { 1.550 + case DecoderStateTables.COMMENT_II: 1.551 + processCommentII(); 1.552 + break; 1.553 + case DecoderStateTables.PROCESSING_INSTRUCTION_II: 1.554 + processProcessingII(); 1.555 + break; 1.556 + case DecoderStateTables.TERMINATOR_DOUBLE: 1.557 + _doubleTerminate = true; 1.558 + case DecoderStateTables.TERMINATOR_SINGLE: 1.559 + _terminate = true; 1.560 + break; 1.561 + default: 1.562 + throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingDII")); 1.563 + } 1.564 + } 1.565 + 1.566 + try { 1.567 + _contentHandler.endDocument(); 1.568 + } catch (SAXException e) { 1.569 + throw new FastInfosetException("processDII", e); 1.570 + } 1.571 + } 1.572 + 1.573 + protected final void processDIIFragment() throws FastInfosetException, IOException { 1.574 + try { 1.575 + _contentHandler.startDocument(); 1.576 + } catch (SAXException e) { 1.577 + throw new FastInfosetException("processDII", e); 1.578 + } 1.579 + 1.580 + _b = read(); 1.581 + if (_b > 0) { 1.582 + processDIIOptionalProperties(); 1.583 + } 1.584 + 1.585 + while(!_terminate) { 1.586 + _b = read(); 1.587 + switch(DecoderStateTables.EII(_b)) { 1.588 + case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: 1.589 + processEII(_elementNameTable._array[_b], false); 1.590 + break; 1.591 + case DecoderStateTables.EII_AIIS_INDEX_SMALL: 1.592 + processEII(_elementNameTable._array[_b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true); 1.593 + break; 1.594 + case DecoderStateTables.EII_INDEX_MEDIUM: 1.595 + processEII(decodeEIIIndexMedium(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 1.596 + break; 1.597 + case DecoderStateTables.EII_INDEX_LARGE: 1.598 + processEII(decodeEIIIndexLarge(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 1.599 + break; 1.600 + case DecoderStateTables.EII_LITERAL: 1.601 + { 1.602 + final QualifiedName qn = decodeLiteralQualifiedName( 1.603 + _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, 1.604 + _elementNameTable.getNext()); 1.605 + _elementNameTable.add(qn); 1.606 + processEII(qn, (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 1.607 + break; 1.608 + } 1.609 + case DecoderStateTables.EII_NAMESPACES: 1.610 + processEIIWithNamespaces(); 1.611 + break; 1.612 + case DecoderStateTables.CII_UTF8_SMALL_LENGTH: 1.613 + _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) 1.614 + + 1; 1.615 + processUtf8CharacterString(); 1.616 + break; 1.617 + case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH: 1.618 + _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; 1.619 + processUtf8CharacterString(); 1.620 + break; 1.621 + case DecoderStateTables.CII_UTF8_LARGE_LENGTH: 1.622 + _octetBufferLength = ((read() << 24) | 1.623 + (read() << 16) | 1.624 + (read() << 8) | 1.625 + read()) 1.626 + + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; 1.627 + processUtf8CharacterString(); 1.628 + break; 1.629 + case DecoderStateTables.CII_UTF16_SMALL_LENGTH: 1.630 + _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) 1.631 + + 1; 1.632 + decodeUtf16StringAsCharBuffer(); 1.633 + if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 1.634 + _characterContentChunkTable.add(_charBuffer, _charBufferLength); 1.635 + } 1.636 + 1.637 + try { 1.638 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.639 + } catch (SAXException e) { 1.640 + throw new FastInfosetException("processCII", e); 1.641 + } 1.642 + break; 1.643 + case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH: 1.644 + _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; 1.645 + decodeUtf16StringAsCharBuffer(); 1.646 + if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 1.647 + _characterContentChunkTable.add(_charBuffer, _charBufferLength); 1.648 + } 1.649 + 1.650 + try { 1.651 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.652 + } catch (SAXException e) { 1.653 + throw new FastInfosetException("processCII", e); 1.654 + } 1.655 + break; 1.656 + case DecoderStateTables.CII_UTF16_LARGE_LENGTH: 1.657 + _octetBufferLength = ((read() << 24) | 1.658 + (read() << 16) | 1.659 + (read() << 8) | 1.660 + read()) 1.661 + + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; 1.662 + decodeUtf16StringAsCharBuffer(); 1.663 + if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 1.664 + _characterContentChunkTable.add(_charBuffer, _charBufferLength); 1.665 + } 1.666 + 1.667 + try { 1.668 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.669 + } catch (SAXException e) { 1.670 + throw new FastInfosetException("processCII", e); 1.671 + } 1.672 + break; 1.673 + case DecoderStateTables.CII_RA: 1.674 + { 1.675 + final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0; 1.676 + 1.677 + // Decode resitricted alphabet integer 1.678 + _identifier = (_b & 0x02) << 6; 1.679 + _b = read(); 1.680 + _identifier |= (_b & 0xFC) >> 2; 1.681 + 1.682 + decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b); 1.683 + 1.684 + decodeRestrictedAlphabetAsCharBuffer(); 1.685 + 1.686 + if (addToTable) { 1.687 + _characterContentChunkTable.add(_charBuffer, _charBufferLength); 1.688 + } 1.689 + 1.690 + try { 1.691 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.692 + } catch (SAXException e) { 1.693 + throw new FastInfosetException("processCII", e); 1.694 + } 1.695 + break; 1.696 + } 1.697 + case DecoderStateTables.CII_EA: 1.698 + { 1.699 + final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0; 1.700 + 1.701 + // Decode encoding algorithm integer 1.702 + _identifier = (_b & 0x02) << 6; 1.703 + _b = read(); 1.704 + _identifier |= (_b & 0xFC) >> 2; 1.705 + 1.706 + decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b); 1.707 + 1.708 + processCIIEncodingAlgorithm(addToTable); 1.709 + break; 1.710 + } 1.711 + case DecoderStateTables.CII_INDEX_SMALL: 1.712 + { 1.713 + final int index = _b & EncodingConstants.INTEGER_4TH_BIT_SMALL_MASK; 1.714 + try { 1.715 + _contentHandler.characters(_characterContentChunkTable._array, 1.716 + _characterContentChunkTable._offset[index], 1.717 + _characterContentChunkTable._length[index]); 1.718 + } catch (SAXException e) { 1.719 + throw new FastInfosetException("processCII", e); 1.720 + } 1.721 + break; 1.722 + } 1.723 + case DecoderStateTables.CII_INDEX_MEDIUM: 1.724 + { 1.725 + final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_MEDIUM_MASK) << 8) | read()) 1.726 + + EncodingConstants.INTEGER_4TH_BIT_SMALL_LIMIT; 1.727 + try { 1.728 + _contentHandler.characters(_characterContentChunkTable._array, 1.729 + _characterContentChunkTable._offset[index], 1.730 + _characterContentChunkTable._length[index]); 1.731 + } catch (SAXException e) { 1.732 + throw new FastInfosetException("processCII", e); 1.733 + } 1.734 + break; 1.735 + } 1.736 + case DecoderStateTables.CII_INDEX_LARGE: 1.737 + { 1.738 + final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_LARGE_MASK) << 16) | 1.739 + (read() << 8) | 1.740 + read()) 1.741 + + EncodingConstants.INTEGER_4TH_BIT_MEDIUM_LIMIT; 1.742 + 1.743 + try { 1.744 + _contentHandler.characters(_characterContentChunkTable._array, 1.745 + _characterContentChunkTable._offset[index], 1.746 + _characterContentChunkTable._length[index]); 1.747 + } catch (SAXException e) { 1.748 + throw new FastInfosetException("processCII", e); 1.749 + } 1.750 + break; 1.751 + } 1.752 + case DecoderStateTables.CII_INDEX_LARGE_LARGE: 1.753 + { 1.754 + final int index = ((read() << 16) | 1.755 + (read() << 8) | 1.756 + read()) 1.757 + + EncodingConstants.INTEGER_4TH_BIT_LARGE_LIMIT; 1.758 + 1.759 + try { 1.760 + _contentHandler.characters(_characterContentChunkTable._array, 1.761 + _characterContentChunkTable._offset[index], 1.762 + _characterContentChunkTable._length[index]); 1.763 + } catch (SAXException e) { 1.764 + throw new FastInfosetException("processCII", e); 1.765 + } 1.766 + break; 1.767 + } 1.768 + case DecoderStateTables.COMMENT_II: 1.769 + processCommentII(); 1.770 + break; 1.771 + case DecoderStateTables.PROCESSING_INSTRUCTION_II: 1.772 + processProcessingII(); 1.773 + break; 1.774 + case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II: 1.775 + { 1.776 + String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName); 1.777 + 1.778 + String system_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0) 1.779 + ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; 1.780 + String public_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0) 1.781 + ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; 1.782 + 1.783 + try { 1.784 + /* 1.785 + * TODO 1.786 + * Need to verify if the skippedEntity method: 1.787 + * http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/ContentHandler.html#skippedEntity(java.lang.String) 1.788 + * is the correct method to call. It appears so but a more extensive 1.789 + * check is necessary. 1.790 + */ 1.791 + _contentHandler.skippedEntity(entity_reference_name); 1.792 + } catch (SAXException e) { 1.793 + throw new FastInfosetException("processUnexpandedEntityReferenceII", e); 1.794 + } 1.795 + break; 1.796 + } 1.797 + case DecoderStateTables.TERMINATOR_DOUBLE: 1.798 + _doubleTerminate = true; 1.799 + case DecoderStateTables.TERMINATOR_SINGLE: 1.800 + _terminate = true; 1.801 + break; 1.802 + default: 1.803 + throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEII")); 1.804 + } 1.805 + } 1.806 + 1.807 + try { 1.808 + _contentHandler.endDocument(); 1.809 + } catch (SAXException e) { 1.810 + throw new FastInfosetException("processDII", e); 1.811 + } 1.812 + } 1.813 + 1.814 + protected final void processDIIOptionalProperties() throws FastInfosetException, IOException { 1.815 + // Optimize for the most common case 1.816 + if (_b == EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) { 1.817 + decodeInitialVocabulary(); 1.818 + return; 1.819 + } 1.820 + 1.821 + if ((_b & EncodingConstants.DOCUMENT_ADDITIONAL_DATA_FLAG) > 0) { 1.822 + decodeAdditionalData(); 1.823 + /* 1.824 + * TODO 1.825 + * how to report the additional data? 1.826 + */ 1.827 + } 1.828 + 1.829 + if ((_b & EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) > 0) { 1.830 + decodeInitialVocabulary(); 1.831 + } 1.832 + 1.833 + if ((_b & EncodingConstants.DOCUMENT_NOTATIONS_FLAG) > 0) { 1.834 + decodeNotations(); 1.835 + /* 1.836 + try { 1.837 + _dtdHandler.notationDecl(name, public_identifier, system_identifier); 1.838 + } catch (SAXException e) { 1.839 + throw new IOException("NotationsDeclarationII"); 1.840 + } 1.841 + */ 1.842 + } 1.843 + 1.844 + if ((_b & EncodingConstants.DOCUMENT_UNPARSED_ENTITIES_FLAG) > 0) { 1.845 + decodeUnparsedEntities(); 1.846 + /* 1.847 + try { 1.848 + _dtdHandler.unparsedEntityDecl(name, public_identifier, system_identifier, notation_name); 1.849 + } catch (SAXException e) { 1.850 + throw new IOException("UnparsedEntitiesII"); 1.851 + } 1.852 + */ 1.853 + } 1.854 + 1.855 + if ((_b & EncodingConstants.DOCUMENT_CHARACTER_ENCODING_SCHEME) > 0) { 1.856 + String characterEncodingScheme = decodeCharacterEncodingScheme(); 1.857 + /* 1.858 + * TODO 1.859 + * how to report the character encoding scheme? 1.860 + */ 1.861 + } 1.862 + 1.863 + if ((_b & EncodingConstants.DOCUMENT_STANDALONE_FLAG) > 0) { 1.864 + boolean standalone = (read() > 0) ? true : false ; 1.865 + /* 1.866 + * TODO 1.867 + * how to report the standalone flag? 1.868 + */ 1.869 + } 1.870 + 1.871 + if ((_b & EncodingConstants.DOCUMENT_VERSION_FLAG) > 0) { 1.872 + decodeVersion(); 1.873 + /* 1.874 + * TODO 1.875 + * how to report the standalone flag? 1.876 + */ 1.877 + } 1.878 + } 1.879 + 1.880 + protected final void processEII(QualifiedName name, boolean hasAttributes) throws FastInfosetException, IOException { 1.881 + if (_prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) { 1.882 + throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qNameOfEIINotInScope")); 1.883 + } 1.884 + 1.885 + if (hasAttributes) { 1.886 + processAIIs(); 1.887 + } 1.888 + 1.889 + try { 1.890 + _contentHandler.startElement(name.namespaceName, name.localName, name.qName, _attributes); 1.891 + } catch (SAXException e) { 1.892 + logger.log(Level.FINE, "processEII error", e); 1.893 + throw new FastInfosetException("processEII", e); 1.894 + } 1.895 + 1.896 + if (_clearAttributes) { 1.897 + _attributes.clear(); 1.898 + _clearAttributes = false; 1.899 + } 1.900 + 1.901 + while(!_terminate) { 1.902 + _b = read(); 1.903 + switch(DecoderStateTables.EII(_b)) { 1.904 + case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: 1.905 + processEII(_elementNameTable._array[_b], false); 1.906 + break; 1.907 + case DecoderStateTables.EII_AIIS_INDEX_SMALL: 1.908 + processEII(_elementNameTable._array[_b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true); 1.909 + break; 1.910 + case DecoderStateTables.EII_INDEX_MEDIUM: 1.911 + processEII(decodeEIIIndexMedium(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 1.912 + break; 1.913 + case DecoderStateTables.EII_INDEX_LARGE: 1.914 + processEII(decodeEIIIndexLarge(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 1.915 + break; 1.916 + case DecoderStateTables.EII_LITERAL: 1.917 + { 1.918 + final QualifiedName qn = decodeLiteralQualifiedName( 1.919 + _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, 1.920 + _elementNameTable.getNext()); 1.921 + _elementNameTable.add(qn); 1.922 + processEII(qn, (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 1.923 + break; 1.924 + } 1.925 + case DecoderStateTables.EII_NAMESPACES: 1.926 + processEIIWithNamespaces(); 1.927 + break; 1.928 + case DecoderStateTables.CII_UTF8_SMALL_LENGTH: 1.929 + _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) 1.930 + + 1; 1.931 + processUtf8CharacterString(); 1.932 + break; 1.933 + case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH: 1.934 + _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; 1.935 + processUtf8CharacterString(); 1.936 + break; 1.937 + case DecoderStateTables.CII_UTF8_LARGE_LENGTH: 1.938 + _octetBufferLength = ((read() << 24) | 1.939 + (read() << 16) | 1.940 + (read() << 8) | 1.941 + read()) 1.942 + + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; 1.943 + processUtf8CharacterString(); 1.944 + break; 1.945 + case DecoderStateTables.CII_UTF16_SMALL_LENGTH: 1.946 + _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) 1.947 + + 1; 1.948 + decodeUtf16StringAsCharBuffer(); 1.949 + if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 1.950 + _characterContentChunkTable.add(_charBuffer, _charBufferLength); 1.951 + } 1.952 + 1.953 + try { 1.954 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.955 + } catch (SAXException e) { 1.956 + throw new FastInfosetException("processCII", e); 1.957 + } 1.958 + break; 1.959 + case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH: 1.960 + _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; 1.961 + decodeUtf16StringAsCharBuffer(); 1.962 + if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 1.963 + _characterContentChunkTable.add(_charBuffer, _charBufferLength); 1.964 + } 1.965 + 1.966 + try { 1.967 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.968 + } catch (SAXException e) { 1.969 + throw new FastInfosetException("processCII", e); 1.970 + } 1.971 + break; 1.972 + case DecoderStateTables.CII_UTF16_LARGE_LENGTH: 1.973 + _octetBufferLength = ((read() << 24) | 1.974 + (read() << 16) | 1.975 + (read() << 8) | 1.976 + read()) 1.977 + + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; 1.978 + decodeUtf16StringAsCharBuffer(); 1.979 + if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 1.980 + _characterContentChunkTable.add(_charBuffer, _charBufferLength); 1.981 + } 1.982 + 1.983 + try { 1.984 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.985 + } catch (SAXException e) { 1.986 + throw new FastInfosetException("processCII", e); 1.987 + } 1.988 + break; 1.989 + case DecoderStateTables.CII_RA: 1.990 + { 1.991 + final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0; 1.992 + 1.993 + // Decode resitricted alphabet integer 1.994 + _identifier = (_b & 0x02) << 6; 1.995 + _b = read(); 1.996 + _identifier |= (_b & 0xFC) >> 2; 1.997 + 1.998 + decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b); 1.999 + 1.1000 + decodeRestrictedAlphabetAsCharBuffer(); 1.1001 + 1.1002 + if (addToTable) { 1.1003 + _characterContentChunkTable.add(_charBuffer, _charBufferLength); 1.1004 + } 1.1005 + 1.1006 + try { 1.1007 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.1008 + } catch (SAXException e) { 1.1009 + throw new FastInfosetException("processCII", e); 1.1010 + } 1.1011 + break; 1.1012 + } 1.1013 + case DecoderStateTables.CII_EA: 1.1014 + { 1.1015 + final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0; 1.1016 + // Decode encoding algorithm integer 1.1017 + _identifier = (_b & 0x02) << 6; 1.1018 + _b = read(); 1.1019 + _identifier |= (_b & 0xFC) >> 2; 1.1020 + 1.1021 + decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b); 1.1022 + 1.1023 + processCIIEncodingAlgorithm(addToTable); 1.1024 + break; 1.1025 + } 1.1026 + case DecoderStateTables.CII_INDEX_SMALL: 1.1027 + { 1.1028 + final int index = _b & EncodingConstants.INTEGER_4TH_BIT_SMALL_MASK; 1.1029 + try { 1.1030 + _contentHandler.characters(_characterContentChunkTable._array, 1.1031 + _characterContentChunkTable._offset[index], 1.1032 + _characterContentChunkTable._length[index]); 1.1033 + } catch (SAXException e) { 1.1034 + throw new FastInfosetException("processCII", e); 1.1035 + } 1.1036 + break; 1.1037 + } 1.1038 + case DecoderStateTables.CII_INDEX_MEDIUM: 1.1039 + { 1.1040 + final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_MEDIUM_MASK) << 8) | read()) 1.1041 + + EncodingConstants.INTEGER_4TH_BIT_SMALL_LIMIT; 1.1042 + try { 1.1043 + _contentHandler.characters(_characterContentChunkTable._array, 1.1044 + _characterContentChunkTable._offset[index], 1.1045 + _characterContentChunkTable._length[index]); 1.1046 + } catch (SAXException e) { 1.1047 + throw new FastInfosetException("processCII", e); 1.1048 + } 1.1049 + break; 1.1050 + } 1.1051 + case DecoderStateTables.CII_INDEX_LARGE: 1.1052 + { 1.1053 + final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_LARGE_MASK) << 16) | 1.1054 + (read() << 8) | 1.1055 + read()) 1.1056 + + EncodingConstants.INTEGER_4TH_BIT_MEDIUM_LIMIT; 1.1057 + 1.1058 + try { 1.1059 + _contentHandler.characters(_characterContentChunkTable._array, 1.1060 + _characterContentChunkTable._offset[index], 1.1061 + _characterContentChunkTable._length[index]); 1.1062 + } catch (SAXException e) { 1.1063 + throw new FastInfosetException("processCII", e); 1.1064 + } 1.1065 + break; 1.1066 + } 1.1067 + case DecoderStateTables.CII_INDEX_LARGE_LARGE: 1.1068 + { 1.1069 + final int index = ((read() << 16) | 1.1070 + (read() << 8) | 1.1071 + read()) 1.1072 + + EncodingConstants.INTEGER_4TH_BIT_LARGE_LIMIT; 1.1073 + 1.1074 + try { 1.1075 + _contentHandler.characters(_characterContentChunkTable._array, 1.1076 + _characterContentChunkTable._offset[index], 1.1077 + _characterContentChunkTable._length[index]); 1.1078 + } catch (SAXException e) { 1.1079 + throw new FastInfosetException("processCII", e); 1.1080 + } 1.1081 + break; 1.1082 + } 1.1083 + case DecoderStateTables.COMMENT_II: 1.1084 + processCommentII(); 1.1085 + break; 1.1086 + case DecoderStateTables.PROCESSING_INSTRUCTION_II: 1.1087 + processProcessingII(); 1.1088 + break; 1.1089 + case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II: 1.1090 + { 1.1091 + String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName); 1.1092 + 1.1093 + String system_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0) 1.1094 + ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; 1.1095 + String public_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0) 1.1096 + ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; 1.1097 + 1.1098 + try { 1.1099 + /* 1.1100 + * TODO 1.1101 + * Need to verify if the skippedEntity method: 1.1102 + * http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/ContentHandler.html#skippedEntity(java.lang.String) 1.1103 + * is the correct method to call. It appears so but a more extensive 1.1104 + * check is necessary. 1.1105 + */ 1.1106 + _contentHandler.skippedEntity(entity_reference_name); 1.1107 + } catch (SAXException e) { 1.1108 + throw new FastInfosetException("processUnexpandedEntityReferenceII", e); 1.1109 + } 1.1110 + break; 1.1111 + } 1.1112 + case DecoderStateTables.TERMINATOR_DOUBLE: 1.1113 + _doubleTerminate = true; 1.1114 + case DecoderStateTables.TERMINATOR_SINGLE: 1.1115 + _terminate = true; 1.1116 + break; 1.1117 + default: 1.1118 + throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEII")); 1.1119 + } 1.1120 + } 1.1121 + 1.1122 + _terminate = _doubleTerminate; 1.1123 + _doubleTerminate = false; 1.1124 + 1.1125 + try { 1.1126 + _contentHandler.endElement(name.namespaceName, name.localName, name.qName); 1.1127 + } catch (SAXException e) { 1.1128 + throw new FastInfosetException("processEII", e); 1.1129 + } 1.1130 + } 1.1131 + 1.1132 + private final void processUtf8CharacterString() throws FastInfosetException, IOException { 1.1133 + if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 1.1134 + _characterContentChunkTable.ensureSize(_octetBufferLength); 1.1135 + final int charactersOffset = _characterContentChunkTable._arrayIndex; 1.1136 + decodeUtf8StringAsCharBuffer(_characterContentChunkTable._array, charactersOffset); 1.1137 + _characterContentChunkTable.add(_charBufferLength); 1.1138 + try { 1.1139 + _contentHandler.characters(_characterContentChunkTable._array, charactersOffset, _charBufferLength); 1.1140 + } catch (SAXException e) { 1.1141 + throw new FastInfosetException("processCII", e); 1.1142 + } 1.1143 + } else { 1.1144 + decodeUtf8StringAsCharBuffer(); 1.1145 + try { 1.1146 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.1147 + } catch (SAXException e) { 1.1148 + throw new FastInfosetException("processCII", e); 1.1149 + } 1.1150 + } 1.1151 + } 1.1152 + 1.1153 + protected final void processEIIWithNamespaces() throws FastInfosetException, IOException { 1.1154 + final boolean hasAttributes = (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0; 1.1155 + 1.1156 + _clearAttributes = (_namespacePrefixesFeature) ? true : false; 1.1157 + 1.1158 + if (++_prefixTable._declarationId == Integer.MAX_VALUE) { 1.1159 + _prefixTable.clearDeclarationIds(); 1.1160 + } 1.1161 + 1.1162 + String prefix = "", namespaceName = ""; 1.1163 + final int start = _namespacePrefixesIndex; 1.1164 + int b = read(); 1.1165 + while ((b & EncodingConstants.NAMESPACE_ATTRIBUTE_MASK) == EncodingConstants.NAMESPACE_ATTRIBUTE) { 1.1166 + if (_namespacePrefixesIndex == _namespacePrefixes.length) { 1.1167 + final int[] namespaceAIIs = new int[_namespacePrefixesIndex * 3 / 2 + 1]; 1.1168 + System.arraycopy(_namespacePrefixes, 0, namespaceAIIs, 0, _namespacePrefixesIndex); 1.1169 + _namespacePrefixes = namespaceAIIs; 1.1170 + } 1.1171 + 1.1172 + switch (b & EncodingConstants.NAMESPACE_ATTRIBUTE_PREFIX_NAME_MASK) { 1.1173 + // no prefix, no namespace 1.1174 + // Undeclaration of default namespace 1.1175 + case 0: 1.1176 + prefix = namespaceName = ""; 1.1177 + _namespaceNameIndex = _prefixIndex = _namespacePrefixes[_namespacePrefixesIndex++] = -1; 1.1178 + break; 1.1179 + // no prefix, namespace 1.1180 + // Declaration of default namespace 1.1181 + case 1: 1.1182 + prefix = ""; 1.1183 + namespaceName = decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(false); 1.1184 + 1.1185 + _prefixIndex = _namespacePrefixes[_namespacePrefixesIndex++] = -1; 1.1186 + break; 1.1187 + // prefix, no namespace 1.1188 + // Undeclaration of namespace 1.1189 + case 2: 1.1190 + prefix = decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(false); 1.1191 + namespaceName = ""; 1.1192 + 1.1193 + _namespaceNameIndex = -1; 1.1194 + _namespacePrefixes[_namespacePrefixesIndex++] = _prefixIndex; 1.1195 + break; 1.1196 + // prefix, namespace 1.1197 + // Declaration of prefixed namespace 1.1198 + case 3: 1.1199 + prefix = decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(true); 1.1200 + namespaceName = decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(true); 1.1201 + 1.1202 + _namespacePrefixes[_namespacePrefixesIndex++] = _prefixIndex; 1.1203 + break; 1.1204 + } 1.1205 + 1.1206 + _prefixTable.pushScope(_prefixIndex, _namespaceNameIndex); 1.1207 + 1.1208 + if (_namespacePrefixesFeature) { 1.1209 + // Add the namespace delcaration as an attribute 1.1210 + if (prefix != "") { 1.1211 + _attributes.addAttribute(new QualifiedName( 1.1212 + EncodingConstants.XMLNS_NAMESPACE_PREFIX, 1.1213 + EncodingConstants.XMLNS_NAMESPACE_NAME, 1.1214 + prefix), 1.1215 + namespaceName); 1.1216 + } else { 1.1217 + _attributes.addAttribute(EncodingConstants.DEFAULT_NAMESPACE_DECLARATION, 1.1218 + namespaceName); 1.1219 + } 1.1220 + } 1.1221 + 1.1222 + try { 1.1223 + _contentHandler.startPrefixMapping(prefix, namespaceName); 1.1224 + } catch (SAXException e) { 1.1225 + throw new IOException("processStartNamespaceAII"); 1.1226 + } 1.1227 + 1.1228 + b = read(); 1.1229 + } 1.1230 + if (b != EncodingConstants.TERMINATOR) { 1.1231 + throw new IOException(CommonResourceBundle.getInstance().getString("message.EIInamespaceNameNotTerminatedCorrectly")); 1.1232 + } 1.1233 + final int end = _namespacePrefixesIndex; 1.1234 + 1.1235 + _b = read(); 1.1236 + switch(DecoderStateTables.EII(_b)) { 1.1237 + case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: 1.1238 + processEII(_elementNameTable._array[_b], hasAttributes); 1.1239 + break; 1.1240 + case DecoderStateTables.EII_INDEX_MEDIUM: 1.1241 + processEII(decodeEIIIndexMedium(), hasAttributes); 1.1242 + break; 1.1243 + case DecoderStateTables.EII_INDEX_LARGE: 1.1244 + processEII(decodeEIIIndexLarge(), hasAttributes); 1.1245 + break; 1.1246 + case DecoderStateTables.EII_LITERAL: 1.1247 + { 1.1248 + final QualifiedName qn = decodeLiteralQualifiedName( 1.1249 + _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, 1.1250 + _elementNameTable.getNext()); 1.1251 + _elementNameTable.add(qn); 1.1252 + processEII(qn, hasAttributes); 1.1253 + break; 1.1254 + } 1.1255 + default: 1.1256 + throw new IOException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEIIAfterAIIs")); 1.1257 + } 1.1258 + 1.1259 + try { 1.1260 + for (int i = end - 1; i >= start; i--) { 1.1261 + final int prefixIndex = _namespacePrefixes[i]; 1.1262 + _prefixTable.popScope(prefixIndex); 1.1263 + prefix = (prefixIndex > 0) ? _prefixTable.get(prefixIndex - 1) : 1.1264 + (prefixIndex == -1) ? "" : EncodingConstants.XML_NAMESPACE_PREFIX; 1.1265 + _contentHandler.endPrefixMapping(prefix); 1.1266 + } 1.1267 + _namespacePrefixesIndex = start; 1.1268 + } catch (SAXException e) { 1.1269 + throw new IOException("processStartNamespaceAII"); 1.1270 + } 1.1271 + } 1.1272 + 1.1273 + protected final void processAIIs() throws FastInfosetException, IOException { 1.1274 + QualifiedName name; 1.1275 + int b; 1.1276 + String value; 1.1277 + 1.1278 + _clearAttributes = true; 1.1279 + 1.1280 + if (++_duplicateAttributeVerifier._currentIteration == Integer.MAX_VALUE) { 1.1281 + _duplicateAttributeVerifier.clear(); 1.1282 + } 1.1283 + 1.1284 + do { 1.1285 + // AII qualified name 1.1286 + b = read(); 1.1287 + switch (DecoderStateTables.AII(b)) { 1.1288 + case DecoderStateTables.AII_INDEX_SMALL: 1.1289 + name = _attributeNameTable._array[b]; 1.1290 + break; 1.1291 + case DecoderStateTables.AII_INDEX_MEDIUM: 1.1292 + { 1.1293 + final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read()) 1.1294 + + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT; 1.1295 + name = _attributeNameTable._array[i]; 1.1296 + break; 1.1297 + } 1.1298 + case DecoderStateTables.AII_INDEX_LARGE: 1.1299 + { 1.1300 + final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read()) 1.1301 + + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT; 1.1302 + name = _attributeNameTable._array[i]; 1.1303 + break; 1.1304 + } 1.1305 + case DecoderStateTables.AII_LITERAL: 1.1306 + name = decodeLiteralQualifiedName( 1.1307 + b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, 1.1308 + _attributeNameTable.getNext()); 1.1309 + name.createAttributeValues(_duplicateAttributeVerifier.MAP_SIZE); 1.1310 + _attributeNameTable.add(name); 1.1311 + break; 1.1312 + case DecoderStateTables.AII_TERMINATOR_DOUBLE: 1.1313 + _doubleTerminate = true; 1.1314 + case DecoderStateTables.AII_TERMINATOR_SINGLE: 1.1315 + _terminate = true; 1.1316 + // AIIs have finished break out of loop 1.1317 + continue; 1.1318 + default: 1.1319 + throw new IOException(CommonResourceBundle.getInstance().getString("message.decodingAIIs")); 1.1320 + } 1.1321 + 1.1322 + if (name.prefixIndex > 0 && _prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) { 1.1323 + throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.AIIqNameNotInScope")); 1.1324 + } 1.1325 + 1.1326 + _duplicateAttributeVerifier.checkForDuplicateAttribute(name.attributeHash, name.attributeId); 1.1327 + 1.1328 + // [normalized value] of AII 1.1329 + 1.1330 + b = read(); 1.1331 + switch(DecoderStateTables.NISTRING(b)) { 1.1332 + case DecoderStateTables.NISTRING_UTF8_SMALL_LENGTH: 1.1333 + _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1; 1.1334 + value = decodeUtf8StringAsString(); 1.1335 + if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1.1336 + _attributeValueTable.add(value); 1.1337 + } 1.1338 + 1.1339 + _attributes.addAttribute(name, value); 1.1340 + break; 1.1341 + case DecoderStateTables.NISTRING_UTF8_MEDIUM_LENGTH: 1.1342 + _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT; 1.1343 + value = decodeUtf8StringAsString(); 1.1344 + if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1.1345 + _attributeValueTable.add(value); 1.1346 + } 1.1347 + 1.1348 + _attributes.addAttribute(name, value); 1.1349 + break; 1.1350 + case DecoderStateTables.NISTRING_UTF8_LARGE_LENGTH: 1.1351 + _octetBufferLength = ((read() << 24) | 1.1352 + (read() << 16) | 1.1353 + (read() << 8) | 1.1354 + read()) 1.1355 + + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT; 1.1356 + value = decodeUtf8StringAsString(); 1.1357 + if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1.1358 + _attributeValueTable.add(value); 1.1359 + } 1.1360 + 1.1361 + _attributes.addAttribute(name, value); 1.1362 + break; 1.1363 + case DecoderStateTables.NISTRING_UTF16_SMALL_LENGTH: 1.1364 + _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1; 1.1365 + value = decodeUtf16StringAsString(); 1.1366 + if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1.1367 + _attributeValueTable.add(value); 1.1368 + } 1.1369 + 1.1370 + _attributes.addAttribute(name, value); 1.1371 + break; 1.1372 + case DecoderStateTables.NISTRING_UTF16_MEDIUM_LENGTH: 1.1373 + _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT; 1.1374 + value = decodeUtf16StringAsString(); 1.1375 + if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1.1376 + _attributeValueTable.add(value); 1.1377 + } 1.1378 + 1.1379 + _attributes.addAttribute(name, value); 1.1380 + break; 1.1381 + case DecoderStateTables.NISTRING_UTF16_LARGE_LENGTH: 1.1382 + _octetBufferLength = ((read() << 24) | 1.1383 + (read() << 16) | 1.1384 + (read() << 8) | 1.1385 + read()) 1.1386 + + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT; 1.1387 + value = decodeUtf16StringAsString(); 1.1388 + if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1.1389 + _attributeValueTable.add(value); 1.1390 + } 1.1391 + 1.1392 + _attributes.addAttribute(name, value); 1.1393 + break; 1.1394 + case DecoderStateTables.NISTRING_RA: 1.1395 + { 1.1396 + final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0; 1.1397 + // Decode resitricted alphabet integer 1.1398 + _identifier = (b & 0x0F) << 4; 1.1399 + b = read(); 1.1400 + _identifier |= (b & 0xF0) >> 4; 1.1401 + 1.1402 + decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b); 1.1403 + 1.1404 + value = decodeRestrictedAlphabetAsString(); 1.1405 + if (addToTable) { 1.1406 + _attributeValueTable.add(value); 1.1407 + } 1.1408 + 1.1409 + _attributes.addAttribute(name, value); 1.1410 + break; 1.1411 + } 1.1412 + case DecoderStateTables.NISTRING_EA: 1.1413 + { 1.1414 + final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0; 1.1415 + 1.1416 + _identifier = (b & 0x0F) << 4; 1.1417 + b = read(); 1.1418 + _identifier |= (b & 0xF0) >> 4; 1.1419 + 1.1420 + decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b); 1.1421 + 1.1422 + processAIIEncodingAlgorithm(name, addToTable); 1.1423 + break; 1.1424 + } 1.1425 + case DecoderStateTables.NISTRING_INDEX_SMALL: 1.1426 + _attributes.addAttribute(name, 1.1427 + _attributeValueTable._array[b & EncodingConstants.INTEGER_2ND_BIT_SMALL_MASK]); 1.1428 + break; 1.1429 + case DecoderStateTables.NISTRING_INDEX_MEDIUM: 1.1430 + { 1.1431 + final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read()) 1.1432 + + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT; 1.1433 + 1.1434 + _attributes.addAttribute(name, 1.1435 + _attributeValueTable._array[index]); 1.1436 + break; 1.1437 + } 1.1438 + case DecoderStateTables.NISTRING_INDEX_LARGE: 1.1439 + { 1.1440 + final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read()) 1.1441 + + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT; 1.1442 + 1.1443 + _attributes.addAttribute(name, 1.1444 + _attributeValueTable._array[index]); 1.1445 + break; 1.1446 + } 1.1447 + case DecoderStateTables.NISTRING_EMPTY: 1.1448 + _attributes.addAttribute(name, ""); 1.1449 + break; 1.1450 + default: 1.1451 + throw new IOException(CommonResourceBundle.getInstance().getString("message.decodingAIIValue")); 1.1452 + } 1.1453 + 1.1454 + } while (!_terminate); 1.1455 + 1.1456 + // Reset duplication attribute verfifier 1.1457 + _duplicateAttributeVerifier._poolCurrent = _duplicateAttributeVerifier._poolHead; 1.1458 + 1.1459 + _terminate = _doubleTerminate; 1.1460 + _doubleTerminate = false; 1.1461 + } 1.1462 + 1.1463 + protected final void processCommentII() throws FastInfosetException, IOException { 1.1464 + switch(decodeNonIdentifyingStringOnFirstBit()) { 1.1465 + case NISTRING_STRING: 1.1466 + if (_addToTable) { 1.1467 + _v.otherString.add(new CharArray(_charBuffer, 0, _charBufferLength, true)); 1.1468 + } 1.1469 + 1.1470 + try { 1.1471 + _lexicalHandler.comment(_charBuffer, 0, _charBufferLength); 1.1472 + } catch (SAXException e) { 1.1473 + throw new FastInfosetException("processCommentII", e); 1.1474 + } 1.1475 + break; 1.1476 + case NISTRING_ENCODING_ALGORITHM: 1.1477 + throw new IOException(CommonResourceBundle.getInstance().getString("message.commentIIAlgorithmNotSupported")); 1.1478 + case NISTRING_INDEX: 1.1479 + final CharArray ca = _v.otherString.get(_integer); 1.1480 + 1.1481 + try { 1.1482 + _lexicalHandler.comment(ca.ch, ca.start, ca.length); 1.1483 + } catch (SAXException e) { 1.1484 + throw new FastInfosetException("processCommentII", e); 1.1485 + } 1.1486 + break; 1.1487 + case NISTRING_EMPTY_STRING: 1.1488 + try { 1.1489 + _lexicalHandler.comment(_charBuffer, 0, 0); 1.1490 + } catch (SAXException e) { 1.1491 + throw new FastInfosetException("processCommentII", e); 1.1492 + } 1.1493 + break; 1.1494 + } 1.1495 + } 1.1496 + 1.1497 + protected final void processProcessingII() throws FastInfosetException, IOException { 1.1498 + final String target = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName); 1.1499 + 1.1500 + switch(decodeNonIdentifyingStringOnFirstBit()) { 1.1501 + case NISTRING_STRING: 1.1502 + final String data = new String(_charBuffer, 0, _charBufferLength); 1.1503 + if (_addToTable) { 1.1504 + _v.otherString.add(new CharArrayString(data)); 1.1505 + } 1.1506 + try { 1.1507 + _contentHandler.processingInstruction(target, data); 1.1508 + } catch (SAXException e) { 1.1509 + throw new FastInfosetException("processProcessingII", e); 1.1510 + } 1.1511 + break; 1.1512 + case NISTRING_ENCODING_ALGORITHM: 1.1513 + throw new IOException(CommonResourceBundle.getInstance().getString("message.processingIIWithEncodingAlgorithm")); 1.1514 + case NISTRING_INDEX: 1.1515 + try { 1.1516 + _contentHandler.processingInstruction(target, _v.otherString.get(_integer).toString()); 1.1517 + } catch (SAXException e) { 1.1518 + throw new FastInfosetException("processProcessingII", e); 1.1519 + } 1.1520 + break; 1.1521 + case NISTRING_EMPTY_STRING: 1.1522 + try { 1.1523 + _contentHandler.processingInstruction(target, ""); 1.1524 + } catch (SAXException e) { 1.1525 + throw new FastInfosetException("processProcessingII", e); 1.1526 + } 1.1527 + break; 1.1528 + } 1.1529 + } 1.1530 + 1.1531 + protected final void processCIIEncodingAlgorithm(boolean addToTable) throws FastInfosetException, IOException { 1.1532 + if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) { 1.1533 + if (_primitiveHandler != null) { 1.1534 + processCIIBuiltInEncodingAlgorithmAsPrimitive(); 1.1535 + } else if (_algorithmHandler != null) { 1.1536 + Object array = processBuiltInEncodingAlgorithmAsObject(); 1.1537 + 1.1538 + try { 1.1539 + _algorithmHandler.object(null, _identifier, array); 1.1540 + } catch (SAXException e) { 1.1541 + throw new FastInfosetException(e); 1.1542 + } 1.1543 + } else { 1.1544 + StringBuffer buffer = new StringBuffer(); 1.1545 + processBuiltInEncodingAlgorithmAsCharacters(buffer); 1.1546 + 1.1547 + try { 1.1548 + _contentHandler.characters(buffer.toString().toCharArray(), 0, buffer.length()); 1.1549 + } catch (SAXException e) { 1.1550 + throw new FastInfosetException(e); 1.1551 + } 1.1552 + } 1.1553 + 1.1554 + if (addToTable) { 1.1555 + StringBuffer buffer = new StringBuffer(); 1.1556 + processBuiltInEncodingAlgorithmAsCharacters(buffer); 1.1557 + _characterContentChunkTable.add(buffer.toString().toCharArray(), buffer.length()); 1.1558 + } 1.1559 + } else if (_identifier == EncodingAlgorithmIndexes.CDATA) { 1.1560 + // Set back buffer position to start of encoded string 1.1561 + _octetBufferOffset -= _octetBufferLength; 1.1562 + decodeUtf8StringIntoCharBuffer(); 1.1563 + 1.1564 + try { 1.1565 + _lexicalHandler.startCDATA(); 1.1566 + _contentHandler.characters(_charBuffer, 0, _charBufferLength); 1.1567 + _lexicalHandler.endCDATA(); 1.1568 + } catch (SAXException e) { 1.1569 + throw new FastInfosetException(e); 1.1570 + } 1.1571 + 1.1572 + if (addToTable) { 1.1573 + _characterContentChunkTable.add(_charBuffer, _charBufferLength); 1.1574 + } 1.1575 + } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START && _algorithmHandler != null) { 1.1576 + final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START); 1.1577 + if (URI == null) { 1.1578 + throw new EncodingAlgorithmException(CommonResourceBundle.getInstance(). 1.1579 + getString("message.URINotPresent", new Object[]{Integer.valueOf(_identifier)})); 1.1580 + } 1.1581 + 1.1582 + final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI); 1.1583 + if (ea != null) { 1.1584 + final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength); 1.1585 + try { 1.1586 + _algorithmHandler.object(URI, _identifier, data); 1.1587 + } catch (SAXException e) { 1.1588 + throw new FastInfosetException(e); 1.1589 + } 1.1590 + } else { 1.1591 + try { 1.1592 + _algorithmHandler.octets(URI, _identifier, _octetBuffer, _octetBufferStart, _octetBufferLength); 1.1593 + } catch (SAXException e) { 1.1594 + throw new FastInfosetException(e); 1.1595 + } 1.1596 + } 1.1597 + if (addToTable) { 1.1598 + throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.addToTableNotSupported")); 1.1599 + } 1.1600 + } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) { 1.1601 + // TODO should have property to ignore 1.1602 + throw new EncodingAlgorithmException( 1.1603 + CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported")); 1.1604 + } else { 1.1605 + // Reserved built-in algorithms for future use 1.1606 + // TODO should use sax property to decide if event will be 1.1607 + // reported, allows for support through handler if required. 1.1608 + throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved")); 1.1609 + } 1.1610 + } 1.1611 + 1.1612 + protected final void processCIIBuiltInEncodingAlgorithmAsPrimitive() throws FastInfosetException, IOException { 1.1613 + try { 1.1614 + int length; 1.1615 + switch(_identifier) { 1.1616 + case EncodingAlgorithmIndexes.HEXADECIMAL: 1.1617 + case EncodingAlgorithmIndexes.BASE64: 1.1618 + _primitiveHandler.bytes(_octetBuffer, _octetBufferStart, _octetBufferLength); 1.1619 + break; 1.1620 + case EncodingAlgorithmIndexes.SHORT: 1.1621 + length = BuiltInEncodingAlgorithmFactory.shortEncodingAlgorithm. 1.1622 + getPrimtiveLengthFromOctetLength(_octetBufferLength); 1.1623 + if (length > builtInAlgorithmState.shortArray.length) { 1.1624 + final short[] array = new short[length * 3 / 2 + 1]; 1.1625 + System.arraycopy(builtInAlgorithmState.shortArray, 0, 1.1626 + array, 0, builtInAlgorithmState.shortArray.length); 1.1627 + builtInAlgorithmState.shortArray = array; 1.1628 + } 1.1629 + 1.1630 + BuiltInEncodingAlgorithmFactory.shortEncodingAlgorithm. 1.1631 + decodeFromBytesToShortArray(builtInAlgorithmState.shortArray, 0, 1.1632 + _octetBuffer, _octetBufferStart, _octetBufferLength); 1.1633 + _primitiveHandler.shorts(builtInAlgorithmState.shortArray, 0, length); 1.1634 + break; 1.1635 + case EncodingAlgorithmIndexes.INT: 1.1636 + length = BuiltInEncodingAlgorithmFactory.intEncodingAlgorithm. 1.1637 + getPrimtiveLengthFromOctetLength(_octetBufferLength); 1.1638 + if (length > builtInAlgorithmState.intArray.length) { 1.1639 + final int[] array = new int[length * 3 / 2 + 1]; 1.1640 + System.arraycopy(builtInAlgorithmState.intArray, 0, 1.1641 + array, 0, builtInAlgorithmState.intArray.length); 1.1642 + builtInAlgorithmState.intArray = array; 1.1643 + } 1.1644 + 1.1645 + BuiltInEncodingAlgorithmFactory.intEncodingAlgorithm. 1.1646 + decodeFromBytesToIntArray(builtInAlgorithmState.intArray, 0, 1.1647 + _octetBuffer, _octetBufferStart, _octetBufferLength); 1.1648 + _primitiveHandler.ints(builtInAlgorithmState.intArray, 0, length); 1.1649 + break; 1.1650 + case EncodingAlgorithmIndexes.LONG: 1.1651 + length = BuiltInEncodingAlgorithmFactory.longEncodingAlgorithm. 1.1652 + getPrimtiveLengthFromOctetLength(_octetBufferLength); 1.1653 + if (length > builtInAlgorithmState.longArray.length) { 1.1654 + final long[] array = new long[length * 3 / 2 + 1]; 1.1655 + System.arraycopy(builtInAlgorithmState.longArray, 0, 1.1656 + array, 0, builtInAlgorithmState.longArray.length); 1.1657 + builtInAlgorithmState.longArray = array; 1.1658 + } 1.1659 + 1.1660 + BuiltInEncodingAlgorithmFactory.longEncodingAlgorithm. 1.1661 + decodeFromBytesToLongArray(builtInAlgorithmState.longArray, 0, 1.1662 + _octetBuffer, _octetBufferStart, _octetBufferLength); 1.1663 + _primitiveHandler.longs(builtInAlgorithmState.longArray, 0, length); 1.1664 + break; 1.1665 + case EncodingAlgorithmIndexes.BOOLEAN: 1.1666 + length = BuiltInEncodingAlgorithmFactory.booleanEncodingAlgorithm. 1.1667 + getPrimtiveLengthFromOctetLength(_octetBufferLength, _octetBuffer[_octetBufferStart] & 0xFF); 1.1668 + if (length > builtInAlgorithmState.booleanArray.length) { 1.1669 + final boolean[] array = new boolean[length * 3 / 2 + 1]; 1.1670 + System.arraycopy(builtInAlgorithmState.booleanArray, 0, 1.1671 + array, 0, builtInAlgorithmState.booleanArray.length); 1.1672 + builtInAlgorithmState.booleanArray = array; 1.1673 + } 1.1674 + 1.1675 + BuiltInEncodingAlgorithmFactory.booleanEncodingAlgorithm. 1.1676 + decodeFromBytesToBooleanArray( 1.1677 + builtInAlgorithmState.booleanArray, 0, length, 1.1678 + _octetBuffer, _octetBufferStart, _octetBufferLength); 1.1679 + _primitiveHandler.booleans(builtInAlgorithmState.booleanArray, 0, length); 1.1680 + break; 1.1681 + case EncodingAlgorithmIndexes.FLOAT: 1.1682 + length = BuiltInEncodingAlgorithmFactory.floatEncodingAlgorithm. 1.1683 + getPrimtiveLengthFromOctetLength(_octetBufferLength); 1.1684 + if (length > builtInAlgorithmState.floatArray.length) { 1.1685 + final float[] array = new float[length * 3 / 2 + 1]; 1.1686 + System.arraycopy(builtInAlgorithmState.floatArray, 0, 1.1687 + array, 0, builtInAlgorithmState.floatArray.length); 1.1688 + builtInAlgorithmState.floatArray = array; 1.1689 + } 1.1690 + 1.1691 + BuiltInEncodingAlgorithmFactory.floatEncodingAlgorithm. 1.1692 + decodeFromBytesToFloatArray(builtInAlgorithmState.floatArray, 0, 1.1693 + _octetBuffer, _octetBufferStart, _octetBufferLength); 1.1694 + _primitiveHandler.floats(builtInAlgorithmState.floatArray, 0, length); 1.1695 + break; 1.1696 + case EncodingAlgorithmIndexes.DOUBLE: 1.1697 + length = BuiltInEncodingAlgorithmFactory.doubleEncodingAlgorithm. 1.1698 + getPrimtiveLengthFromOctetLength(_octetBufferLength); 1.1699 + if (length > builtInAlgorithmState.doubleArray.length) { 1.1700 + final double[] array = new double[length * 3 / 2 + 1]; 1.1701 + System.arraycopy(builtInAlgorithmState.doubleArray, 0, 1.1702 + array, 0, builtInAlgorithmState.doubleArray.length); 1.1703 + builtInAlgorithmState.doubleArray = array; 1.1704 + } 1.1705 + 1.1706 + BuiltInEncodingAlgorithmFactory.doubleEncodingAlgorithm. 1.1707 + decodeFromBytesToDoubleArray(builtInAlgorithmState.doubleArray, 0, 1.1708 + _octetBuffer, _octetBufferStart, _octetBufferLength); 1.1709 + _primitiveHandler.doubles(builtInAlgorithmState.doubleArray, 0, length); 1.1710 + break; 1.1711 + case EncodingAlgorithmIndexes.UUID: 1.1712 + length = BuiltInEncodingAlgorithmFactory.uuidEncodingAlgorithm. 1.1713 + getPrimtiveLengthFromOctetLength(_octetBufferLength); 1.1714 + if (length > builtInAlgorithmState.longArray.length) { 1.1715 + final long[] array = new long[length * 3 / 2 + 1]; 1.1716 + System.arraycopy(builtInAlgorithmState.longArray, 0, 1.1717 + array, 0, builtInAlgorithmState.longArray.length); 1.1718 + builtInAlgorithmState.longArray = array; 1.1719 + } 1.1720 + 1.1721 + BuiltInEncodingAlgorithmFactory.uuidEncodingAlgorithm. 1.1722 + decodeFromBytesToLongArray(builtInAlgorithmState.longArray, 0, 1.1723 + _octetBuffer, _octetBufferStart, _octetBufferLength); 1.1724 + _primitiveHandler.uuids(builtInAlgorithmState.longArray, 0, length); 1.1725 + break; 1.1726 + case EncodingAlgorithmIndexes.CDATA: 1.1727 + throw new UnsupportedOperationException("CDATA"); 1.1728 + default: 1.1729 + throw new FastInfosetException(CommonResourceBundle.getInstance(). 1.1730 + getString("message.unsupportedAlgorithm", new Object[]{Integer.valueOf(_identifier)})); 1.1731 + } 1.1732 + } catch (SAXException e) { 1.1733 + throw new FastInfosetException(e); 1.1734 + } 1.1735 + } 1.1736 + 1.1737 + 1.1738 + protected final void processAIIEncodingAlgorithm(QualifiedName name, boolean addToTable) throws FastInfosetException, IOException { 1.1739 + if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) { 1.1740 + if (_primitiveHandler != null || _algorithmHandler != null) { 1.1741 + Object data = processBuiltInEncodingAlgorithmAsObject(); 1.1742 + _attributes.addAttributeWithAlgorithmData(name, null, _identifier, data); 1.1743 + } else { 1.1744 + StringBuffer buffer = new StringBuffer(); 1.1745 + processBuiltInEncodingAlgorithmAsCharacters(buffer); 1.1746 + _attributes.addAttribute(name, buffer.toString()); 1.1747 + } 1.1748 + } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START && _algorithmHandler != null) { 1.1749 + final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START); 1.1750 + if (URI == null) { 1.1751 + throw new EncodingAlgorithmException(CommonResourceBundle.getInstance(). 1.1752 + getString("message.URINotPresent", new Object[]{Integer.valueOf(_identifier)})); 1.1753 + } 1.1754 + 1.1755 + final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI); 1.1756 + if (ea != null) { 1.1757 + final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength); 1.1758 + _attributes.addAttributeWithAlgorithmData(name, URI, _identifier, data); 1.1759 + } else { 1.1760 + final byte[] data = new byte[_octetBufferLength]; 1.1761 + System.arraycopy(_octetBuffer, _octetBufferStart, data, 0, _octetBufferLength); 1.1762 + _attributes.addAttributeWithAlgorithmData(name, URI, _identifier, data); 1.1763 + } 1.1764 + } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) { 1.1765 + // TODO should have property to ignore 1.1766 + throw new EncodingAlgorithmException( 1.1767 + CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported")); 1.1768 + } else if (_identifier == EncodingAlgorithmIndexes.CDATA) { 1.1769 + throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported")); 1.1770 + } else { 1.1771 + // Reserved built-in algorithms for future use 1.1772 + // TODO should use sax property to decide if event will be 1.1773 + // reported, allows for support through handler if required. 1.1774 + throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved")); 1.1775 + } 1.1776 + 1.1777 + if (addToTable) { 1.1778 + _attributeValueTable.add(_attributes.getValue(_attributes.getIndex(name.qName))); 1.1779 + } 1.1780 + } 1.1781 + 1.1782 + protected final void processBuiltInEncodingAlgorithmAsCharacters(StringBuffer buffer) throws FastInfosetException, IOException { 1.1783 + // TODO not very efficient, need to reuse buffers 1.1784 + Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier). 1.1785 + decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength); 1.1786 + 1.1787 + BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array, buffer); 1.1788 + } 1.1789 + 1.1790 + protected final Object processBuiltInEncodingAlgorithmAsObject() throws FastInfosetException, IOException { 1.1791 + return BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier). 1.1792 + decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength); 1.1793 + } 1.1794 +}