src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/stax/StAXDocumentParser.java

Wed, 12 Jun 2013 14:47:09 +0100

author
mkos
date
Wed, 12 Jun 2013 14:47:09 +0100
changeset 384
8f2986ff0235
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
8003542: Improve processing of MTOM attachments
8005432: Update access to JAX-WS
Reviewed-by: mullan

ohair@286 1 /*
mkos@384 2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 *
ohair@286 25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
ohair@286 26 */
ohair@286 27
ohair@286 28 package com.sun.xml.internal.fastinfoset.stax;
ohair@286 29
ohair@286 30 import com.sun.xml.internal.fastinfoset.Decoder;
ohair@286 31 import com.sun.xml.internal.fastinfoset.DecoderStateTables;
ohair@286 32 import com.sun.xml.internal.fastinfoset.EncodingConstants;
ohair@286 33 import com.sun.xml.internal.fastinfoset.OctetBufferListener;
ohair@286 34 import com.sun.xml.internal.fastinfoset.QualifiedName;
ohair@286 35 import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory;
ohair@286 36 import com.sun.xml.internal.fastinfoset.sax.AttributesHolder;
ohair@286 37 import com.sun.xml.internal.fastinfoset.util.CharArray;
ohair@286 38 import com.sun.xml.internal.fastinfoset.util.CharArrayString;
ohair@286 39 import java.io.IOException;
ohair@286 40 import java.io.InputStream;
ohair@286 41 import java.util.Iterator;
ohair@286 42 import java.util.NoSuchElementException;
ohair@286 43 import javax.xml.namespace.NamespaceContext;
ohair@286 44 import javax.xml.namespace.QName;
ohair@286 45 import javax.xml.stream.Location;
ohair@286 46 import javax.xml.stream.XMLStreamException;
ohair@286 47 import javax.xml.stream.XMLStreamReader;
ohair@286 48 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm;
ohair@286 49 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
ohair@286 50 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
ohair@286 51 import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
ohair@286 52 import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
ohair@286 53 import com.sun.xml.internal.fastinfoset.org.apache.xerces.util.XMLChar;
ohair@286 54 import com.sun.xml.internal.fastinfoset.util.DuplicateAttributeVerifier;
ohair@286 55 import java.util.logging.Level;
ohair@286 56 import java.util.logging.Logger;
ohair@286 57 import com.sun.xml.internal.org.jvnet.fastinfoset.stax.FastInfosetStreamReader;
ohair@286 58
ohair@286 59 /**
ohair@286 60 * The Fast Infoset StAX parser.
ohair@286 61 * <p>
ohair@286 62 * Instantiate this parser to parse a fast infoset document in accordance
ohair@286 63 * with the StAX API.
ohair@286 64 *
ohair@286 65 * <p>
ohair@286 66 * More than one fast infoset document may be decoded from the
ohair@286 67 * {@link java.io.InputStream}.
ohair@286 68 */
ohair@286 69 public class StAXDocumentParser extends Decoder
ohair@286 70 implements XMLStreamReader, FastInfosetStreamReader, OctetBufferListener {
ohair@286 71 private static final Logger logger = Logger.getLogger(StAXDocumentParser.class.getName());
ohair@286 72
ohair@286 73 protected static final int INTERNAL_STATE_START_DOCUMENT = 0;
ohair@286 74 protected static final int INTERNAL_STATE_START_ELEMENT_TERMINATE = 1;
ohair@286 75 protected static final int INTERNAL_STATE_SINGLE_TERMINATE_ELEMENT_WITH_NAMESPACES = 2;
ohair@286 76 protected static final int INTERNAL_STATE_DOUBLE_TERMINATE_ELEMENT = 3;
ohair@286 77 protected static final int INTERNAL_STATE_END_DOCUMENT = 4;
ohair@286 78 protected static final int INTERNAL_STATE_VOID = -1;
ohair@286 79
ohair@286 80 protected int _internalState;
ohair@286 81
ohair@286 82 /**
ohair@286 83 * Current event
ohair@286 84 */
ohair@286 85 protected int _eventType;
ohair@286 86
ohair@286 87 /**
ohair@286 88 * Stack of qualified names and namespaces
ohair@286 89 */
ohair@286 90 protected QualifiedName[] _qNameStack = new QualifiedName[32];
ohair@286 91 protected int[] _namespaceAIIsStartStack = new int[32];
ohair@286 92 protected int[] _namespaceAIIsEndStack = new int[32];
ohair@286 93 protected int _stackCount = -1;
ohair@286 94
ohair@286 95 protected String[] _namespaceAIIsPrefix = new String[32];
ohair@286 96 protected String[] _namespaceAIIsNamespaceName = new String[32];
ohair@286 97 protected int[] _namespaceAIIsPrefixIndex = new int[32];
ohair@286 98 protected int _namespaceAIIsIndex;
ohair@286 99
ohair@286 100 /**
ohair@286 101 * Namespaces associated with START_ELEMENT or END_ELEMENT
ohair@286 102 */
ohair@286 103 protected int _currentNamespaceAIIsStart;
ohair@286 104 protected int _currentNamespaceAIIsEnd;
ohair@286 105
ohair@286 106 /**
ohair@286 107 * Qualified name associated with START_ELEMENT or END_ELEMENT.
ohair@286 108 */
ohair@286 109 protected QualifiedName _qualifiedName;
ohair@286 110
ohair@286 111 /**
ohair@286 112 * List of attributes
ohair@286 113 */
ohair@286 114 protected AttributesHolder _attributes = new AttributesHolder();
ohair@286 115
ohair@286 116 protected boolean _clearAttributes = false;
ohair@286 117
ohair@286 118 /**
ohair@286 119 * Characters associated with event.
ohair@286 120 */
ohair@286 121 protected char[] _characters;
ohair@286 122 protected int _charactersOffset;
ohair@286 123
ohair@286 124 protected String _algorithmURI;
ohair@286 125 protected int _algorithmId;
ohair@286 126 protected boolean _isAlgorithmDataCloned;
ohair@286 127 protected byte[] _algorithmData;
ohair@286 128 protected int _algorithmDataOffset;
ohair@286 129 protected int _algorithmDataLength;
ohair@286 130
ohair@286 131 /**
ohair@286 132 * State for processing instruction
ohair@286 133 */
ohair@286 134 protected String _piTarget;
ohair@286 135 protected String _piData;
ohair@286 136
ohair@286 137 protected NamespaceContextImpl _nsContext = new NamespaceContextImpl();
ohair@286 138
ohair@286 139 protected String _characterEncodingScheme;
ohair@286 140
ohair@286 141 protected StAXManager _manager;
ohair@286 142
ohair@286 143 public StAXDocumentParser() {
ohair@286 144 reset();
ohair@286 145 _manager = new StAXManager(StAXManager.CONTEXT_READER);
ohair@286 146 }
ohair@286 147
ohair@286 148 public StAXDocumentParser(InputStream s) {
ohair@286 149 this();
ohair@286 150 setInputStream(s);
ohair@286 151 _manager = new StAXManager(StAXManager.CONTEXT_READER);
ohair@286 152 }
ohair@286 153
ohair@286 154 public StAXDocumentParser(InputStream s, StAXManager manager) {
ohair@286 155 this(s);
ohair@286 156 _manager = manager;
ohair@286 157 }
ohair@286 158
ohair@286 159 @Override
ohair@286 160 public void setInputStream(InputStream s) {
ohair@286 161 super.setInputStream(s);
ohair@286 162 reset();
ohair@286 163 }
ohair@286 164
ohair@286 165 @Override
ohair@286 166 public void reset() {
ohair@286 167 super.reset();
ohair@286 168 if (_internalState != INTERNAL_STATE_START_DOCUMENT &&
ohair@286 169 _internalState != INTERNAL_STATE_END_DOCUMENT) {
ohair@286 170
ohair@286 171 for (int i = _namespaceAIIsIndex - 1; i >= 0; i--) {
ohair@286 172 _prefixTable.popScopeWithPrefixEntry(_namespaceAIIsPrefixIndex[i]);
ohair@286 173 }
ohair@286 174
ohair@286 175 _stackCount = -1;
ohair@286 176
ohair@286 177 _namespaceAIIsIndex = 0;
ohair@286 178 _characters = null;
ohair@286 179 _algorithmData = null;
ohair@286 180 }
ohair@286 181
ohair@286 182 _characterEncodingScheme = "UTF-8";
ohair@286 183 _eventType = START_DOCUMENT;
ohair@286 184 _internalState = INTERNAL_STATE_START_DOCUMENT;
ohair@286 185 }
ohair@286 186
ohair@286 187 protected void resetOnError() {
ohair@286 188 super.reset();
ohair@286 189
ohair@286 190 if (_v != null) {
ohair@286 191 _prefixTable.clearCompletely();
ohair@286 192 }
ohair@286 193 _duplicateAttributeVerifier.clear();
ohair@286 194
ohair@286 195 _stackCount = -1;
ohair@286 196
ohair@286 197 _namespaceAIIsIndex = 0;
ohair@286 198 _characters = null;
ohair@286 199 _algorithmData = null;
ohair@286 200
ohair@286 201 _eventType = START_DOCUMENT;
ohair@286 202 _internalState = INTERNAL_STATE_START_DOCUMENT;
ohair@286 203 }
ohair@286 204
ohair@286 205 // -- XMLStreamReader Interface -------------------------------------------
ohair@286 206
ohair@286 207 public Object getProperty(java.lang.String name)
ohair@286 208 throws java.lang.IllegalArgumentException {
ohair@286 209 if (_manager != null) {
ohair@286 210 return _manager.getProperty(name);
ohair@286 211 }
ohair@286 212 return null;
ohair@286 213 }
ohair@286 214
ohair@286 215 public int next() throws XMLStreamException {
ohair@286 216 try {
ohair@286 217 if (_internalState != INTERNAL_STATE_VOID) {
ohair@286 218 switch (_internalState) {
ohair@286 219 case INTERNAL_STATE_START_DOCUMENT:
ohair@286 220 decodeHeader();
ohair@286 221 processDII();
ohair@286 222
ohair@286 223 _internalState = INTERNAL_STATE_VOID;
ohair@286 224 break;
ohair@286 225 case INTERNAL_STATE_START_ELEMENT_TERMINATE:
ohair@286 226 if (_currentNamespaceAIIsEnd > 0) {
ohair@286 227 for (int i = _currentNamespaceAIIsEnd - 1; i >= _currentNamespaceAIIsStart; i--) {
ohair@286 228 _prefixTable.popScopeWithPrefixEntry(_namespaceAIIsPrefixIndex[i]);
ohair@286 229 }
ohair@286 230 _namespaceAIIsIndex = _currentNamespaceAIIsStart;
ohair@286 231 }
ohair@286 232
ohair@286 233 // Pop information off the stack
ohair@286 234 popStack();
ohair@286 235
ohair@286 236 _internalState = INTERNAL_STATE_VOID;
ohair@286 237 return _eventType = END_ELEMENT;
ohair@286 238 case INTERNAL_STATE_SINGLE_TERMINATE_ELEMENT_WITH_NAMESPACES:
ohair@286 239 // Undeclare namespaces
ohair@286 240 for (int i = _currentNamespaceAIIsEnd - 1; i >= _currentNamespaceAIIsStart; i--) {
ohair@286 241 _prefixTable.popScopeWithPrefixEntry(_namespaceAIIsPrefixIndex[i]);
ohair@286 242 }
ohair@286 243 _namespaceAIIsIndex = _currentNamespaceAIIsStart;
ohair@286 244 _internalState = INTERNAL_STATE_VOID;
ohair@286 245 break;
ohair@286 246 case INTERNAL_STATE_DOUBLE_TERMINATE_ELEMENT:
ohair@286 247 // Undeclare namespaces
ohair@286 248 if (_currentNamespaceAIIsEnd > 0) {
ohair@286 249 for (int i = _currentNamespaceAIIsEnd - 1; i >= _currentNamespaceAIIsStart; i--) {
ohair@286 250 _prefixTable.popScopeWithPrefixEntry(_namespaceAIIsPrefixIndex[i]);
ohair@286 251 }
ohair@286 252 _namespaceAIIsIndex = _currentNamespaceAIIsStart;
ohair@286 253 }
ohair@286 254
ohair@286 255 if (_stackCount == -1) {
ohair@286 256 _internalState = INTERNAL_STATE_END_DOCUMENT;
ohair@286 257 return _eventType = END_DOCUMENT;
ohair@286 258 }
ohair@286 259
ohair@286 260 // Pop information off the stack
ohair@286 261 popStack();
ohair@286 262
ohair@286 263 _internalState = (_currentNamespaceAIIsEnd > 0) ?
ohair@286 264 INTERNAL_STATE_SINGLE_TERMINATE_ELEMENT_WITH_NAMESPACES :
ohair@286 265 INTERNAL_STATE_VOID;
ohair@286 266 return _eventType = END_ELEMENT;
ohair@286 267 case INTERNAL_STATE_END_DOCUMENT:
ohair@286 268 throw new NoSuchElementException(CommonResourceBundle.getInstance().getString("message.noMoreEvents"));
ohair@286 269 }
ohair@286 270 }
ohair@286 271
ohair@286 272 // Reset internal state
ohair@286 273 _characters = null;
ohair@286 274 _algorithmData = null;
ohair@286 275 _currentNamespaceAIIsEnd = 0;
ohair@286 276
ohair@286 277 // Process information item
ohair@286 278 final int b = read();
ohair@286 279 switch(DecoderStateTables.EII(b)) {
ohair@286 280 case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
ohair@286 281 processEII(_elementNameTable._array[b], false);
ohair@286 282 return _eventType;
ohair@286 283 case DecoderStateTables.EII_AIIS_INDEX_SMALL:
ohair@286 284 processEII(_elementNameTable._array[b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true);
ohair@286 285 return _eventType;
ohair@286 286 case DecoderStateTables.EII_INDEX_MEDIUM:
ohair@286 287 processEII(processEIIIndexMedium(b), (b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
ohair@286 288 return _eventType;
ohair@286 289 case DecoderStateTables.EII_INDEX_LARGE:
ohair@286 290 processEII(processEIIIndexLarge(b), (b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
ohair@286 291 return _eventType;
ohair@286 292 case DecoderStateTables.EII_LITERAL:
ohair@286 293 {
ohair@286 294 final QualifiedName qn = processLiteralQualifiedName(
ohair@286 295 b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
ohair@286 296 _elementNameTable.getNext());
ohair@286 297 _elementNameTable.add(qn);
ohair@286 298 processEII(qn, (b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
ohair@286 299 return _eventType;
ohair@286 300 }
ohair@286 301 case DecoderStateTables.EII_NAMESPACES:
ohair@286 302 processEIIWithNamespaces((b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
ohair@286 303 return _eventType;
ohair@286 304 case DecoderStateTables.CII_UTF8_SMALL_LENGTH:
ohair@286 305 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK)
ohair@286 306 + 1;
ohair@286 307 processUtf8CharacterString(b);
ohair@286 308 return _eventType = CHARACTERS;
ohair@286 309 case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH:
ohair@286 310 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT;
ohair@286 311 processUtf8CharacterString(b);
ohair@286 312 return _eventType = CHARACTERS;
ohair@286 313 case DecoderStateTables.CII_UTF8_LARGE_LENGTH:
ohair@286 314 _octetBufferLength = ((read() << 24) |
ohair@286 315 (read() << 16) |
ohair@286 316 (read() << 8) |
ohair@286 317 read())
ohair@286 318 + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT;
ohair@286 319 processUtf8CharacterString(b);
ohair@286 320 return _eventType = CHARACTERS;
ohair@286 321 case DecoderStateTables.CII_UTF16_SMALL_LENGTH:
ohair@286 322 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK)
ohair@286 323 + 1;
ohair@286 324 processUtf16CharacterString(b);
ohair@286 325 return _eventType = CHARACTERS;
ohair@286 326 case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH:
ohair@286 327 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT;
ohair@286 328 processUtf16CharacterString(b);
ohair@286 329 return _eventType = CHARACTERS;
ohair@286 330 case DecoderStateTables.CII_UTF16_LARGE_LENGTH:
ohair@286 331 _octetBufferLength = ((read() << 24) |
ohair@286 332 (read() << 16) |
ohair@286 333 (read() << 8) |
ohair@286 334 read())
ohair@286 335 + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT;
ohair@286 336 processUtf16CharacterString(b);
ohair@286 337 return _eventType = CHARACTERS;
ohair@286 338 case DecoderStateTables.CII_RA:
ohair@286 339 {
ohair@286 340 final boolean addToTable = (b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0;
ohair@286 341
ohair@286 342 _identifier = (b & 0x02) << 6;
ohair@286 343 final int b2 = read();
ohair@286 344 _identifier |= (b2 & 0xFC) >> 2;
ohair@286 345
ohair@286 346 decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(b2);
ohair@286 347
ohair@286 348 decodeRestrictedAlphabetAsCharBuffer();
ohair@286 349
ohair@286 350 if (addToTable) {
ohair@286 351 _charactersOffset = _characterContentChunkTable.add(_charBuffer, _charBufferLength);
ohair@286 352 _characters = _characterContentChunkTable._array;
ohair@286 353 } else {
ohair@286 354 _characters = _charBuffer;
ohair@286 355 _charactersOffset = 0;
ohair@286 356 }
ohair@286 357 return _eventType = CHARACTERS;
ohair@286 358 }
ohair@286 359 case DecoderStateTables.CII_EA:
ohair@286 360 {
ohair@286 361 final boolean addToTable = (b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0;
ohair@286 362 // Decode encoding algorithm integer
ohair@286 363 _algorithmId = (b & 0x02) << 6;
ohair@286 364 final int b2 = read();
ohair@286 365 _algorithmId |= (b2 & 0xFC) >> 2;
ohair@286 366
ohair@286 367 decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(b2);
ohair@286 368 processCIIEncodingAlgorithm(addToTable);
ohair@286 369
ohair@286 370 if (_algorithmId == EncodingAlgorithmIndexes.CDATA) {
ohair@286 371 return _eventType = CDATA;
ohair@286 372 }
ohair@286 373
ohair@286 374 return _eventType = CHARACTERS;
ohair@286 375 }
ohair@286 376 case DecoderStateTables.CII_INDEX_SMALL:
ohair@286 377 {
ohair@286 378 final int index = b & EncodingConstants.INTEGER_4TH_BIT_SMALL_MASK;
ohair@286 379 _characterContentChunkTable._cachedIndex = index;
ohair@286 380
ohair@286 381 _characters = _characterContentChunkTable._array;
ohair@286 382 _charactersOffset = _characterContentChunkTable._offset[index];
ohair@286 383 _charBufferLength = _characterContentChunkTable._length[index];
ohair@286 384 return _eventType = CHARACTERS;
ohair@286 385 }
ohair@286 386 case DecoderStateTables.CII_INDEX_MEDIUM:
ohair@286 387 {
ohair@286 388 final int index = (((b & EncodingConstants.INTEGER_4TH_BIT_MEDIUM_MASK) << 8) | read())
ohair@286 389 + EncodingConstants.INTEGER_4TH_BIT_SMALL_LIMIT;
ohair@286 390 _characterContentChunkTable._cachedIndex = index;
ohair@286 391
ohair@286 392 _characters = _characterContentChunkTable._array;
ohair@286 393 _charactersOffset = _characterContentChunkTable._offset[index];
ohair@286 394 _charBufferLength = _characterContentChunkTable._length[index];
ohair@286 395 return _eventType = CHARACTERS;
ohair@286 396 }
ohair@286 397 case DecoderStateTables.CII_INDEX_LARGE:
ohair@286 398 {
ohair@286 399 final int index = (((b & EncodingConstants.INTEGER_4TH_BIT_LARGE_MASK) << 16) |
ohair@286 400 (read() << 8) |
ohair@286 401 read())
ohair@286 402 + EncodingConstants.INTEGER_4TH_BIT_MEDIUM_LIMIT;
ohair@286 403 _characterContentChunkTable._cachedIndex = index;
ohair@286 404
ohair@286 405 _characters = _characterContentChunkTable._array;
ohair@286 406 _charactersOffset = _characterContentChunkTable._offset[index];
ohair@286 407 _charBufferLength = _characterContentChunkTable._length[index];
ohair@286 408 return _eventType = CHARACTERS;
ohair@286 409 }
ohair@286 410 case DecoderStateTables.CII_INDEX_LARGE_LARGE:
ohair@286 411 {
ohair@286 412 final int index = ((read() << 16) |
ohair@286 413 (read() << 8) |
ohair@286 414 read())
ohair@286 415 + EncodingConstants.INTEGER_4TH_BIT_LARGE_LIMIT;
ohair@286 416 _characterContentChunkTable._cachedIndex = index;
ohair@286 417
ohair@286 418 _characters = _characterContentChunkTable._array;
ohair@286 419 _charactersOffset = _characterContentChunkTable._offset[index];
ohair@286 420 _charBufferLength = _characterContentChunkTable._length[index];
ohair@286 421 return _eventType = CHARACTERS;
ohair@286 422 }
ohair@286 423 case DecoderStateTables.COMMENT_II:
ohair@286 424 processCommentII();
ohair@286 425 return _eventType;
ohair@286 426 case DecoderStateTables.PROCESSING_INSTRUCTION_II:
ohair@286 427 processProcessingII();
ohair@286 428 return _eventType;
ohair@286 429 case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II:
ohair@286 430 {
ohair@286 431 processUnexpandedEntityReference(b);
ohair@286 432 // Skip the reference
ohair@286 433 return next();
ohair@286 434 }
ohair@286 435 case DecoderStateTables.TERMINATOR_DOUBLE:
ohair@286 436 if (_stackCount != -1) {
ohair@286 437 // Pop information off the stack
ohair@286 438 popStack();
ohair@286 439
ohair@286 440 _internalState = INTERNAL_STATE_DOUBLE_TERMINATE_ELEMENT;
ohair@286 441 return _eventType = END_ELEMENT;
ohair@286 442 }
ohair@286 443
ohair@286 444 _internalState = INTERNAL_STATE_END_DOCUMENT;
ohair@286 445 return _eventType = END_DOCUMENT;
ohair@286 446 case DecoderStateTables.TERMINATOR_SINGLE:
ohair@286 447 if (_stackCount != -1) {
ohair@286 448 // Pop information off the stack
ohair@286 449 popStack();
ohair@286 450
ohair@286 451 if (_currentNamespaceAIIsEnd > 0) {
ohair@286 452 _internalState = INTERNAL_STATE_SINGLE_TERMINATE_ELEMENT_WITH_NAMESPACES;
ohair@286 453 }
ohair@286 454 return _eventType = END_ELEMENT;
ohair@286 455 }
ohair@286 456
ohair@286 457 _internalState = INTERNAL_STATE_END_DOCUMENT;
ohair@286 458 return _eventType = END_DOCUMENT;
ohair@286 459 default:
ohair@286 460 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEII"));
ohair@286 461 }
ohair@286 462 } catch (IOException e) {
ohair@286 463 resetOnError();
ohair@286 464 logger.log(Level.FINE, "next() exception", e);
ohair@286 465 throw new XMLStreamException(e);
ohair@286 466 } catch (FastInfosetException e) {
ohair@286 467 resetOnError();
ohair@286 468 logger.log(Level.FINE, "next() exception", e);
ohair@286 469 throw new XMLStreamException(e);
ohair@286 470 } catch (RuntimeException e) {
ohair@286 471 resetOnError();
ohair@286 472 logger.log(Level.FINE, "next() exception", e);
ohair@286 473 throw e;
ohair@286 474 }
ohair@286 475 }
ohair@286 476
ohair@286 477 private final void processUtf8CharacterString(final int b) throws IOException {
ohair@286 478 if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
ohair@286 479 _characterContentChunkTable.ensureSize(_octetBufferLength);
ohair@286 480 _characters = _characterContentChunkTable._array;
ohair@286 481 _charactersOffset = _characterContentChunkTable._arrayIndex;
ohair@286 482 decodeUtf8StringAsCharBuffer(_characterContentChunkTable._array, _charactersOffset);
ohair@286 483 _characterContentChunkTable.add(_charBufferLength);
ohair@286 484 } else {
ohair@286 485 decodeUtf8StringAsCharBuffer();
ohair@286 486 _characters = _charBuffer;
ohair@286 487 _charactersOffset = 0;
ohair@286 488 }
ohair@286 489 }
ohair@286 490
ohair@286 491 private final void processUtf16CharacterString(final int b) throws IOException {
ohair@286 492 decodeUtf16StringAsCharBuffer();
ohair@286 493 if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
ohair@286 494 _charactersOffset = _characterContentChunkTable.add(_charBuffer, _charBufferLength);
ohair@286 495 _characters = _characterContentChunkTable._array;
ohair@286 496 } else {
ohair@286 497 _characters = _charBuffer;
ohair@286 498 _charactersOffset = 0;
ohair@286 499 }
ohair@286 500 }
ohair@286 501
mkos@384 502 private void popStack() {
ohair@286 503 // Pop information off the stack
ohair@286 504 _qualifiedName = _qNameStack[_stackCount];
ohair@286 505 _currentNamespaceAIIsStart = _namespaceAIIsStartStack[_stackCount];
ohair@286 506 _currentNamespaceAIIsEnd = _namespaceAIIsEndStack[_stackCount];
ohair@286 507 _qNameStack[_stackCount--] = null;
ohair@286 508 }
ohair@286 509
ohair@286 510 /** Test if the current event is of the given type and if the namespace and name match the current namespace and name of the current event.
ohair@286 511 * If the namespaceURI is null it is not checked for equality, if the localName is null it is not checked for equality.
ohair@286 512 * @param type the event type
ohair@286 513 * @param namespaceURI the uri of the event, may be null
ohair@286 514 * @param localName the localName of the event, may be null
ohair@286 515 * @throws XMLStreamException if the required values are not matched.
ohair@286 516 */
ohair@286 517 public final void require(int type, String namespaceURI, String localName)
ohair@286 518 throws XMLStreamException {
ohair@286 519 if( type != _eventType)
ohair@286 520 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.eventTypeNotMatch", new Object[]{getEventTypeString(type)}));
ohair@286 521 if( namespaceURI != null && !namespaceURI.equals(getNamespaceURI()) )
ohair@286 522 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.namespaceURINotMatch", new Object[]{namespaceURI}));
ohair@286 523 if(localName != null && !localName.equals(getLocalName()))
ohair@286 524 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.localNameNotMatch", new Object[]{localName}));
ohair@286 525 }
ohair@286 526
ohair@286 527 /** Reads the content of a text-only element. Precondition:
ohair@286 528 * the current event is START_ELEMENT. Postcondition:
ohair@286 529 * The current event is the corresponding END_ELEMENT.
ohair@286 530 * @throws XMLStreamException if the current event is not a START_ELEMENT or if
ohair@286 531 * a non text element is encountered
ohair@286 532 */
ohair@286 533 public final String getElementText() throws XMLStreamException {
ohair@286 534
ohair@286 535 if(getEventType() != START_ELEMENT) {
ohair@286 536 throw new XMLStreamException(
ohair@286 537 CommonResourceBundle.getInstance().getString("message.mustBeOnSTARTELEMENT"), getLocation());
ohair@286 538 }
ohair@286 539 //current is StartElement, move to the next
ohair@286 540 next();
ohair@286 541 return getElementText(true);
ohair@286 542 }
ohair@286 543 /**
ohair@286 544 * @param startElementRead flag if start element has already been read
ohair@286 545 */
ohair@286 546 public final String getElementText(boolean startElementRead) throws XMLStreamException {
ohair@286 547 if (!startElementRead) {
ohair@286 548 throw new XMLStreamException(
ohair@286 549 CommonResourceBundle.getInstance().getString("message.mustBeOnSTARTELEMENT"), getLocation());
ohair@286 550 }
ohair@286 551 int eventType = getEventType();
mkos@384 552 StringBuilder content = new StringBuilder();
ohair@286 553 while(eventType != END_ELEMENT ) {
ohair@286 554 if(eventType == CHARACTERS
ohair@286 555 || eventType == CDATA
ohair@286 556 || eventType == SPACE
ohair@286 557 || eventType == ENTITY_REFERENCE) {
ohair@286 558 content.append(getText());
ohair@286 559 } else if(eventType == PROCESSING_INSTRUCTION
ohair@286 560 || eventType == COMMENT) {
ohair@286 561 // skipping
ohair@286 562 } else if(eventType == END_DOCUMENT) {
ohair@286 563 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.unexpectedEOF"));
ohair@286 564 } else if(eventType == START_ELEMENT) {
ohair@286 565 throw new XMLStreamException(
ohair@286 566 CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"), getLocation());
ohair@286 567 } else {
ohair@286 568 throw new XMLStreamException(
ohair@286 569 CommonResourceBundle.getInstance().getString("message.unexpectedEventType")+ getEventTypeString(eventType), getLocation());
ohair@286 570 }
ohair@286 571 eventType = next();
ohair@286 572 }
ohair@286 573 return content.toString();
ohair@286 574 }
ohair@286 575
ohair@286 576 /** Skips any white space (isWhiteSpace() returns true), COMMENT,
ohair@286 577 * or PROCESSING_INSTRUCTION,
ohair@286 578 * until a START_ELEMENT or END_ELEMENT is reached.
ohair@286 579 * If other than white space characters, COMMENT, PROCESSING_INSTRUCTION, START_ELEMENT, END_ELEMENT
ohair@286 580 * are encountered, an exception is thrown. This method should
ohair@286 581 * be used when processing element-only content seperated by white space.
ohair@286 582 * This method should
ohair@286 583 * be used when processing element-only content because
ohair@286 584 * the parser is not able to recognize ignorable whitespace if
ohair@286 585 * then DTD is missing or not interpreted.
ohair@286 586 * @return the event type of the element read
ohair@286 587 * @throws XMLStreamException if the current event is not white space
ohair@286 588 */
ohair@286 589 public final int nextTag() throws XMLStreamException {
ohair@286 590 next();
ohair@286 591 return nextTag(true);
ohair@286 592 }
ohair@286 593 /** if the current tag has already read, such as in the case EventReader's
ohair@286 594 * peek() has been called, the current cursor should not move before the loop
ohair@286 595 */
ohair@286 596 public final int nextTag(boolean currentTagRead) throws XMLStreamException {
ohair@286 597 int eventType = getEventType();
ohair@286 598 if (!currentTagRead) {
ohair@286 599 eventType = next();
ohair@286 600 }
ohair@286 601 while((eventType == CHARACTERS && isWhiteSpace()) // skip whitespace
ohair@286 602 || (eventType == CDATA && isWhiteSpace())
ohair@286 603 || eventType == SPACE
ohair@286 604 || eventType == PROCESSING_INSTRUCTION
ohair@286 605 || eventType == COMMENT) {
ohair@286 606 eventType = next();
ohair@286 607 }
ohair@286 608 if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
ohair@286 609 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.expectedStartOrEnd"), getLocation());
ohair@286 610 }
ohair@286 611 return eventType;
ohair@286 612 }
ohair@286 613
ohair@286 614 public final boolean hasNext() throws XMLStreamException {
ohair@286 615 return (_eventType != END_DOCUMENT);
ohair@286 616 }
ohair@286 617
ohair@286 618 public void close() throws XMLStreamException {
ohair@286 619 try {
ohair@286 620 super.closeIfRequired();
ohair@286 621 } catch (IOException ex) {
ohair@286 622 }
ohair@286 623 }
ohair@286 624
ohair@286 625 public final String getNamespaceURI(String prefix) {
ohair@286 626 String namespace = getNamespaceDecl(prefix);
ohair@286 627 if (namespace == null) {
ohair@286 628 if (prefix == null) {
ohair@286 629 throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.nullPrefix"));
ohair@286 630 }
ohair@286 631 return null; // unbound
ohair@286 632 }
ohair@286 633 return namespace;
ohair@286 634 }
ohair@286 635
ohair@286 636 public final boolean isStartElement() {
ohair@286 637 return (_eventType == START_ELEMENT);
ohair@286 638 }
ohair@286 639
ohair@286 640 public final boolean isEndElement() {
ohair@286 641 return (_eventType == END_ELEMENT);
ohair@286 642 }
ohair@286 643
ohair@286 644 public final boolean isCharacters() {
ohair@286 645 return (_eventType == CHARACTERS);
ohair@286 646 }
ohair@286 647
ohair@286 648 /**
ohair@286 649 * Returns true if the cursor points to a character data event that consists of all whitespace
ohair@286 650 * Application calling this method needs to cache the value and avoid calling this method again
ohair@286 651 * for the same event.
ohair@286 652 * @return true if the cursor points to all whitespace, false otherwise
ohair@286 653 */
ohair@286 654 public final boolean isWhiteSpace() {
ohair@286 655 if(isCharacters() || (_eventType == CDATA)){
ohair@286 656 char [] ch = this.getTextCharacters();
ohair@286 657 int start = this.getTextStart();
ohair@286 658 int length = this.getTextLength();
ohair@286 659 for (int i = start; i < start + length; i++){
ohair@286 660 if(!XMLChar.isSpace(ch[i])){
ohair@286 661 return false;
ohair@286 662 }
ohair@286 663 }
ohair@286 664 return true;
ohair@286 665 }
ohair@286 666 return false;
ohair@286 667 }
ohair@286 668
ohair@286 669 public final String getAttributeValue(String namespaceURI, String localName) {
ohair@286 670 if (_eventType != START_ELEMENT) {
ohair@286 671 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue"));
ohair@286 672 }
ohair@286 673
ohair@286 674 if (localName == null)
ohair@286 675 throw new IllegalArgumentException();
ohair@286 676
ohair@286 677 // Search for the attributes in _attributes
ohair@286 678 if (namespaceURI != null) {
ohair@286 679 for (int i = 0; i < _attributes.getLength(); i++) {
ohair@286 680 if (_attributes.getLocalName(i).equals(localName) &&
ohair@286 681 _attributes.getURI(i).equals(namespaceURI)) {
ohair@286 682 return _attributes.getValue(i);
ohair@286 683 }
ohair@286 684 }
ohair@286 685 } else {
ohair@286 686 for (int i = 0; i < _attributes.getLength(); i++) {
ohair@286 687 if (_attributes.getLocalName(i).equals(localName)) {
ohair@286 688 return _attributes.getValue(i);
ohair@286 689 }
ohair@286 690 }
ohair@286 691 }
ohair@286 692
ohair@286 693 return null;
ohair@286 694 }
ohair@286 695
ohair@286 696 public final int getAttributeCount() {
ohair@286 697 if (_eventType != START_ELEMENT) {
ohair@286 698 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue"));
ohair@286 699 }
ohair@286 700
ohair@286 701 return _attributes.getLength();
ohair@286 702 }
ohair@286 703
ohair@286 704 public final javax.xml.namespace.QName getAttributeName(int index) {
ohair@286 705 if (_eventType != START_ELEMENT) {
ohair@286 706 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue"));
ohair@286 707 }
ohair@286 708 return _attributes.getQualifiedName(index).getQName();
ohair@286 709 }
ohair@286 710
ohair@286 711 public final String getAttributeNamespace(int index) {
ohair@286 712 if (_eventType != START_ELEMENT) {
ohair@286 713 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue"));
ohair@286 714 }
ohair@286 715
ohair@286 716 return _attributes.getURI(index);
ohair@286 717 }
ohair@286 718
ohair@286 719 public final String getAttributeLocalName(int index) {
ohair@286 720 if (_eventType != START_ELEMENT) {
ohair@286 721 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue"));
ohair@286 722 }
ohair@286 723 return _attributes.getLocalName(index);
ohair@286 724 }
ohair@286 725
ohair@286 726 public final String getAttributePrefix(int index) {
ohair@286 727 if (_eventType != START_ELEMENT) {
ohair@286 728 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue"));
ohair@286 729 }
ohair@286 730 return _attributes.getPrefix(index);
ohair@286 731 }
ohair@286 732
ohair@286 733 public final String getAttributeType(int index) {
ohair@286 734 if (_eventType != START_ELEMENT) {
ohair@286 735 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue"));
ohair@286 736 }
ohair@286 737 return _attributes.getType(index);
ohair@286 738 }
ohair@286 739
ohair@286 740 public final String getAttributeValue(int index) {
ohair@286 741 if (_eventType != START_ELEMENT) {
ohair@286 742 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue"));
ohair@286 743 }
ohair@286 744 return _attributes.getValue(index);
ohair@286 745 }
ohair@286 746
ohair@286 747 public final boolean isAttributeSpecified(int index) {
ohair@286 748 return false; // non-validating parser
ohair@286 749 }
ohair@286 750
ohair@286 751 public final int getNamespaceCount() {
ohair@286 752 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
ohair@286 753 return (_currentNamespaceAIIsEnd > 0) ? (_currentNamespaceAIIsEnd - _currentNamespaceAIIsStart) : 0;
ohair@286 754 } else {
ohair@286 755 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetNamespaceCount"));
ohair@286 756 }
ohair@286 757 }
ohair@286 758
ohair@286 759 public final String getNamespacePrefix(int index) {
ohair@286 760 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
ohair@286 761 return _namespaceAIIsPrefix[_currentNamespaceAIIsStart + index];
ohair@286 762 } else {
ohair@286 763 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetNamespacePrefix"));
ohair@286 764 }
ohair@286 765 }
ohair@286 766
ohair@286 767 public final String getNamespaceURI(int index) {
ohair@286 768 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
ohair@286 769 return _namespaceAIIsNamespaceName[_currentNamespaceAIIsStart + index];
ohair@286 770 } else {
ohair@286 771 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetNamespacePrefix"));
ohair@286 772 }
ohair@286 773 }
ohair@286 774
ohair@286 775 public final NamespaceContext getNamespaceContext() {
ohair@286 776 return _nsContext;
ohair@286 777 }
ohair@286 778
ohair@286 779 public final int getEventType() {
ohair@286 780 return _eventType;
ohair@286 781 }
ohair@286 782
ohair@286 783 public final String getText() {
ohair@286 784 if (_characters == null) {
ohair@286 785 checkTextState();
ohair@286 786 }
ohair@286 787
ohair@286 788 if (_characters == _characterContentChunkTable._array) {
ohair@286 789 return _characterContentChunkTable.getString(_characterContentChunkTable._cachedIndex);
ohair@286 790 } else {
ohair@286 791 return new String(_characters, _charactersOffset, _charBufferLength);
ohair@286 792 }
ohair@286 793 }
ohair@286 794
ohair@286 795 public final char[] getTextCharacters() {
ohair@286 796 if (_characters == null) {
ohair@286 797 checkTextState();
ohair@286 798 }
ohair@286 799
ohair@286 800 return _characters;
ohair@286 801 }
ohair@286 802
ohair@286 803 public final int getTextStart() {
ohair@286 804 if (_characters == null) {
ohair@286 805 checkTextState();
ohair@286 806 }
ohair@286 807
ohair@286 808 return _charactersOffset;
ohair@286 809 }
ohair@286 810
ohair@286 811 public final int getTextLength() {
ohair@286 812 if (_characters == null) {
ohair@286 813 checkTextState();
ohair@286 814 }
ohair@286 815
ohair@286 816 return _charBufferLength;
ohair@286 817 }
ohair@286 818
ohair@286 819 public final int getTextCharacters(int sourceStart, char[] target,
ohair@286 820 int targetStart, int length) throws XMLStreamException {
ohair@286 821 if (_characters == null) {
ohair@286 822 checkTextState();
ohair@286 823 }
ohair@286 824
ohair@286 825 try {
ohair@286 826 int bytesToCopy = Math.min(_charBufferLength, length);
ohair@286 827 System.arraycopy(_characters, _charactersOffset + sourceStart,
ohair@286 828 target, targetStart, bytesToCopy);
ohair@286 829 return bytesToCopy;
ohair@286 830 } catch (IndexOutOfBoundsException e) {
ohair@286 831 throw new XMLStreamException(e);
ohair@286 832 }
ohair@286 833 }
ohair@286 834
ohair@286 835 protected final void checkTextState() {
ohair@286 836 if (_algorithmData == null) {
ohair@286 837 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.InvalidStateForText"));
ohair@286 838 }
ohair@286 839
ohair@286 840 try {
ohair@286 841 convertEncodingAlgorithmDataToCharacters();
ohair@286 842 } catch (Exception e) {
ohair@286 843 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.InvalidStateForText"));
ohair@286 844 }
ohair@286 845 }
ohair@286 846
ohair@286 847 public final String getEncoding() {
ohair@286 848 return _characterEncodingScheme;
ohair@286 849 }
ohair@286 850
ohair@286 851 public final boolean hasText() {
ohair@286 852 return (_characters != null);
ohair@286 853 }
ohair@286 854
ohair@286 855 public final Location getLocation() {
ohair@286 856 //location should be created in next()
ohair@286 857 //returns a nil location for now
ohair@286 858 return EventLocation.getNilLocation();
ohair@286 859 }
ohair@286 860
ohair@286 861 public final QName getName() {
ohair@286 862 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
ohair@286 863 return _qualifiedName.getQName();
ohair@286 864 } else {
ohair@286 865 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetName"));
ohair@286 866 }
ohair@286 867 }
ohair@286 868
ohair@286 869 public final String getLocalName() {
ohair@286 870 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
ohair@286 871 return _qualifiedName.localName;
ohair@286 872 } else {
ohair@286 873 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetLocalName"));
ohair@286 874 }
ohair@286 875 }
ohair@286 876
ohair@286 877 public final boolean hasName() {
ohair@286 878 return (_eventType == START_ELEMENT || _eventType == END_ELEMENT);
ohair@286 879 }
ohair@286 880
ohair@286 881 public final String getNamespaceURI() {
ohair@286 882 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
ohair@286 883 return _qualifiedName.namespaceName;
ohair@286 884 } else {
ohair@286 885 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetNamespaceURI"));
ohair@286 886 }
ohair@286 887 }
ohair@286 888
ohair@286 889 public final String getPrefix() {
ohair@286 890 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
ohair@286 891 return _qualifiedName.prefix;
ohair@286 892 } else {
ohair@286 893 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetPrefix"));
ohair@286 894 }
ohair@286 895 }
ohair@286 896
ohair@286 897 public final String getVersion() {
ohair@286 898 return null;
ohair@286 899 }
ohair@286 900
ohair@286 901 public final boolean isStandalone() {
ohair@286 902 return false;
ohair@286 903 }
ohair@286 904
ohair@286 905 public final boolean standaloneSet() {
ohair@286 906 return false;
ohair@286 907 }
ohair@286 908
ohair@286 909 public final String getCharacterEncodingScheme() {
ohair@286 910 return null;
ohair@286 911 }
ohair@286 912
ohair@286 913 public final String getPITarget() {
ohair@286 914 if (_eventType != PROCESSING_INSTRUCTION) {
ohair@286 915 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetPITarget"));
ohair@286 916 }
ohair@286 917
ohair@286 918 return _piTarget;
ohair@286 919 }
ohair@286 920
ohair@286 921 public final String getPIData() {
ohair@286 922 if (_eventType != PROCESSING_INSTRUCTION) {
ohair@286 923 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetPIData"));
ohair@286 924 }
ohair@286 925
ohair@286 926 return _piData;
ohair@286 927 }
ohair@286 928
ohair@286 929
ohair@286 930
ohair@286 931
ohair@286 932 public final String getNameString() {
ohair@286 933 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
ohair@286 934 return _qualifiedName.getQNameString();
ohair@286 935 } else {
ohair@286 936 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetName"));
ohair@286 937 }
ohair@286 938 }
ohair@286 939
ohair@286 940 public final String getAttributeNameString(int index) {
ohair@286 941 if (_eventType != START_ELEMENT) {
ohair@286 942 throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue"));
ohair@286 943 }
ohair@286 944 return _attributes.getQualifiedName(index).getQNameString();
ohair@286 945 }
ohair@286 946
ohair@286 947
ohair@286 948 public final String getTextAlgorithmURI() {
ohair@286 949 return _algorithmURI;
ohair@286 950 }
ohair@286 951
ohair@286 952 public final int getTextAlgorithmIndex() {
ohair@286 953 return _algorithmId;
ohair@286 954 }
ohair@286 955
ohair@286 956 public final boolean hasTextAlgorithmBytes() {
ohair@286 957 return _algorithmData != null;
ohair@286 958 }
ohair@286 959
ohair@286 960
ohair@286 961 /**
ohair@286 962 * Returns the byte[], which represents text algorithms.
ohair@286 963 * @deprecated was deprecated due to security reasons. Now the method return cloned byte[].
ohair@286 964 *
ohair@286 965 * @return
ohair@286 966 */
ohair@286 967 public final byte[] getTextAlgorithmBytes() {
ohair@286 968 // Do not return the actual _algorithmData due to security reasons
ohair@286 969 // return _algorithmData;
ohair@286 970 if (_algorithmData == null) {
ohair@286 971 return null;
ohair@286 972 }
ohair@286 973
ohair@286 974 final byte[] algorithmData = new byte[_algorithmData.length];
ohair@286 975 System.arraycopy(_algorithmData, 0, algorithmData, 0, _algorithmData.length);
ohair@286 976 return algorithmData;
ohair@286 977 }
ohair@286 978
ohair@286 979 public final byte[] getTextAlgorithmBytesClone() {
ohair@286 980 if (_algorithmData == null) {
ohair@286 981 return null;
ohair@286 982 }
ohair@286 983
ohair@286 984 byte[] algorithmData = new byte[_algorithmDataLength];
ohair@286 985 System.arraycopy(_algorithmData, _algorithmDataOffset, algorithmData, 0, _algorithmDataLength);
ohair@286 986 return algorithmData;
ohair@286 987 }
ohair@286 988
ohair@286 989 public final int getTextAlgorithmStart() {
ohair@286 990 return _algorithmDataOffset;
ohair@286 991 }
ohair@286 992
ohair@286 993 public final int getTextAlgorithmLength() {
ohair@286 994 return _algorithmDataLength;
ohair@286 995 }
ohair@286 996
ohair@286 997 public final int getTextAlgorithmBytes(int sourceStart, byte[] target,
ohair@286 998 int targetStart, int length) throws XMLStreamException {
ohair@286 999 try {
ohair@286 1000 System.arraycopy(_algorithmData, sourceStart, target,
ohair@286 1001 targetStart, length);
ohair@286 1002 return length;
ohair@286 1003 } catch (IndexOutOfBoundsException e) {
ohair@286 1004 throw new XMLStreamException(e);
ohair@286 1005 }
ohair@286 1006 }
ohair@286 1007
ohair@286 1008 // FastInfosetStreamReader impl
ohair@286 1009
ohair@286 1010 public final int peekNext() throws XMLStreamException {
ohair@286 1011 try {
ohair@286 1012 switch(DecoderStateTables.EII(peek(this))) {
ohair@286 1013 case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
ohair@286 1014 case DecoderStateTables.EII_AIIS_INDEX_SMALL:
ohair@286 1015 case DecoderStateTables.EII_INDEX_MEDIUM:
ohair@286 1016 case DecoderStateTables.EII_INDEX_LARGE:
ohair@286 1017 case DecoderStateTables.EII_LITERAL:
ohair@286 1018 case DecoderStateTables.EII_NAMESPACES:
ohair@286 1019 return START_ELEMENT;
ohair@286 1020 case DecoderStateTables.CII_UTF8_SMALL_LENGTH:
ohair@286 1021 case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH:
ohair@286 1022 case DecoderStateTables.CII_UTF8_LARGE_LENGTH:
ohair@286 1023 case DecoderStateTables.CII_UTF16_SMALL_LENGTH:
ohair@286 1024 case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH:
ohair@286 1025 case DecoderStateTables.CII_UTF16_LARGE_LENGTH:
ohair@286 1026 case DecoderStateTables.CII_RA:
ohair@286 1027 case DecoderStateTables.CII_EA:
ohair@286 1028 case DecoderStateTables.CII_INDEX_SMALL:
ohair@286 1029 case DecoderStateTables.CII_INDEX_MEDIUM:
ohair@286 1030 case DecoderStateTables.CII_INDEX_LARGE:
ohair@286 1031 case DecoderStateTables.CII_INDEX_LARGE_LARGE:
ohair@286 1032 return CHARACTERS;
ohair@286 1033 case DecoderStateTables.COMMENT_II:
ohair@286 1034 return COMMENT;
ohair@286 1035 case DecoderStateTables.PROCESSING_INSTRUCTION_II:
ohair@286 1036 return PROCESSING_INSTRUCTION;
ohair@286 1037 case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II:
ohair@286 1038 return ENTITY_REFERENCE;
ohair@286 1039 case DecoderStateTables.TERMINATOR_DOUBLE:
ohair@286 1040 case DecoderStateTables.TERMINATOR_SINGLE:
ohair@286 1041 return (_stackCount != -1) ? END_ELEMENT : END_DOCUMENT;
ohair@286 1042 default:
ohair@286 1043 throw new FastInfosetException(
ohair@286 1044 CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEII"));
ohair@286 1045 }
ohair@286 1046 } catch (IOException e) {
ohair@286 1047 throw new XMLStreamException(e);
ohair@286 1048 } catch (FastInfosetException e) {
ohair@286 1049 throw new XMLStreamException(e);
ohair@286 1050 }
ohair@286 1051 }
ohair@286 1052
ohair@286 1053 public void onBeforeOctetBufferOverwrite() {
ohair@286 1054 if (_algorithmData != null) {
ohair@286 1055 _algorithmData = getTextAlgorithmBytesClone();
ohair@286 1056 _algorithmDataOffset = 0;
ohair@286 1057 _isAlgorithmDataCloned = true;
ohair@286 1058 }
ohair@286 1059 }
ohair@286 1060
ohair@286 1061 // Faster access methods without checks
ohair@286 1062
ohair@286 1063 public final int accessNamespaceCount() {
ohair@286 1064 return (_currentNamespaceAIIsEnd > 0) ? (_currentNamespaceAIIsEnd - _currentNamespaceAIIsStart) : 0;
ohair@286 1065 }
ohair@286 1066
ohair@286 1067 public final String accessLocalName() {
ohair@286 1068 return _qualifiedName.localName;
ohair@286 1069 }
ohair@286 1070
ohair@286 1071 public final String accessNamespaceURI() {
ohair@286 1072 return _qualifiedName.namespaceName;
ohair@286 1073 }
ohair@286 1074
ohair@286 1075 public final String accessPrefix() {
ohair@286 1076 return _qualifiedName.prefix;
ohair@286 1077 }
ohair@286 1078
ohair@286 1079 public final char[] accessTextCharacters() {
ohair@286 1080 if (_characters == null) return null;
ohair@286 1081
ohair@286 1082 // we return a cloned version of _characters
ohair@286 1083 final char[] clonedCharacters = new char[_characters.length];
ohair@286 1084 System.arraycopy(_characters, 0, clonedCharacters, 0, _characters.length);
ohair@286 1085 return clonedCharacters;
ohair@286 1086 }
ohair@286 1087
ohair@286 1088 public final int accessTextStart() {
ohair@286 1089 return _charactersOffset;
ohair@286 1090 }
ohair@286 1091
ohair@286 1092 public final int accessTextLength() {
ohair@286 1093 return _charBufferLength;
ohair@286 1094 }
ohair@286 1095
ohair@286 1096 //
ohair@286 1097
ohair@286 1098 protected final void processDII() throws FastInfosetException, IOException {
ohair@286 1099 final int b = read();
ohair@286 1100 if (b > 0) {
ohair@286 1101 processDIIOptionalProperties(b);
ohair@286 1102 }
ohair@286 1103 }
ohair@286 1104
ohair@286 1105 protected final void processDIIOptionalProperties(int b) throws FastInfosetException, IOException {
ohair@286 1106 // Optimize for the most common case
ohair@286 1107 if (b == EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) {
ohair@286 1108 decodeInitialVocabulary();
ohair@286 1109 return;
ohair@286 1110 }
ohair@286 1111
ohair@286 1112 if ((b & EncodingConstants.DOCUMENT_ADDITIONAL_DATA_FLAG) > 0) {
ohair@286 1113 decodeAdditionalData();
ohair@286 1114 /*
ohair@286 1115 * TODO
ohair@286 1116 * how to report the additional data?
ohair@286 1117 */
ohair@286 1118 }
ohair@286 1119
ohair@286 1120 if ((b & EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) > 0) {
ohair@286 1121 decodeInitialVocabulary();
ohair@286 1122 }
ohair@286 1123
ohair@286 1124 if ((b & EncodingConstants.DOCUMENT_NOTATIONS_FLAG) > 0) {
ohair@286 1125 decodeNotations();
ohair@286 1126 /*
ohair@286 1127 try {
ohair@286 1128 _dtdHandler.notationDecl(name, public_identifier, system_identifier);
ohair@286 1129 } catch (SAXException e) {
ohair@286 1130 throw new IOException("NotationsDeclarationII");
ohair@286 1131 }
ohair@286 1132 */
ohair@286 1133 }
ohair@286 1134
ohair@286 1135 if ((b & EncodingConstants.DOCUMENT_UNPARSED_ENTITIES_FLAG) > 0) {
ohair@286 1136 decodeUnparsedEntities();
ohair@286 1137 /*
ohair@286 1138 try {
ohair@286 1139 _dtdHandler.unparsedEntityDecl(name, public_identifier, system_identifier, notation_name);
ohair@286 1140 } catch (SAXException e) {
ohair@286 1141 throw new IOException("UnparsedEntitiesII");
ohair@286 1142 }
ohair@286 1143 */
ohair@286 1144 }
ohair@286 1145
ohair@286 1146 if ((b & EncodingConstants.DOCUMENT_CHARACTER_ENCODING_SCHEME) > 0) {
ohair@286 1147 _characterEncodingScheme = decodeCharacterEncodingScheme();
ohair@286 1148 }
ohair@286 1149
ohair@286 1150 if ((b & EncodingConstants.DOCUMENT_STANDALONE_FLAG) > 0) {
ohair@286 1151 boolean standalone = (read() > 0) ? true : false ;
ohair@286 1152 /*
ohair@286 1153 * TODO
ohair@286 1154 * how to report the standalone flag?
ohair@286 1155 */
ohair@286 1156 }
ohair@286 1157
ohair@286 1158 if ((b & EncodingConstants.DOCUMENT_VERSION_FLAG) > 0) {
ohair@286 1159 decodeVersion();
ohair@286 1160 /*
ohair@286 1161 * TODO
ohair@286 1162 * how to report the standalone flag?
ohair@286 1163 */
ohair@286 1164 }
ohair@286 1165 }
ohair@286 1166
ohair@286 1167
ohair@286 1168 protected final void resizeNamespaceAIIs() {
ohair@286 1169 final String[] namespaceAIIsPrefix = new String[_namespaceAIIsIndex * 2];
ohair@286 1170 System.arraycopy(_namespaceAIIsPrefix, 0, namespaceAIIsPrefix, 0, _namespaceAIIsIndex);
ohair@286 1171 _namespaceAIIsPrefix = namespaceAIIsPrefix;
ohair@286 1172
ohair@286 1173 final String[] namespaceAIIsNamespaceName = new String[_namespaceAIIsIndex * 2];
ohair@286 1174 System.arraycopy(_namespaceAIIsNamespaceName, 0, namespaceAIIsNamespaceName, 0, _namespaceAIIsIndex);
ohair@286 1175 _namespaceAIIsNamespaceName = namespaceAIIsNamespaceName;
ohair@286 1176
ohair@286 1177 final int[] namespaceAIIsPrefixIndex = new int[_namespaceAIIsIndex * 2];
ohair@286 1178 System.arraycopy(_namespaceAIIsPrefixIndex, 0, namespaceAIIsPrefixIndex, 0, _namespaceAIIsIndex);
ohair@286 1179 _namespaceAIIsPrefixIndex = namespaceAIIsPrefixIndex;
ohair@286 1180 }
ohair@286 1181
ohair@286 1182 protected final void processEIIWithNamespaces(boolean hasAttributes) throws FastInfosetException, IOException {
ohair@286 1183 if (++_prefixTable._declarationId == Integer.MAX_VALUE) {
ohair@286 1184 _prefixTable.clearDeclarationIds();
ohair@286 1185 }
ohair@286 1186
ohair@286 1187 _currentNamespaceAIIsStart = _namespaceAIIsIndex;
ohair@286 1188 String prefix = "", namespaceName = "";
ohair@286 1189 int b = read();
ohair@286 1190 while ((b & EncodingConstants.NAMESPACE_ATTRIBUTE_MASK) == EncodingConstants.NAMESPACE_ATTRIBUTE) {
ohair@286 1191 if (_namespaceAIIsIndex == _namespaceAIIsPrefix.length) {
ohair@286 1192 resizeNamespaceAIIs();
ohair@286 1193 }
ohair@286 1194
ohair@286 1195 switch (b & EncodingConstants.NAMESPACE_ATTRIBUTE_PREFIX_NAME_MASK) {
ohair@286 1196 // no prefix, no namespace
ohair@286 1197 // Undeclaration of default namespace
ohair@286 1198 case 0:
ohair@286 1199 prefix = namespaceName =
ohair@286 1200 _namespaceAIIsPrefix[_namespaceAIIsIndex] =
ohair@286 1201 _namespaceAIIsNamespaceName[_namespaceAIIsIndex] = "";
ohair@286 1202
ohair@286 1203 _namespaceNameIndex = _prefixIndex = _namespaceAIIsPrefixIndex[_namespaceAIIsIndex++] = -1;
ohair@286 1204 break;
ohair@286 1205 // no prefix, namespace
ohair@286 1206 // Declaration of default namespace
ohair@286 1207 case 1:
ohair@286 1208 prefix = _namespaceAIIsPrefix[_namespaceAIIsIndex] = "";
ohair@286 1209 namespaceName = _namespaceAIIsNamespaceName[_namespaceAIIsIndex] =
ohair@286 1210 decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(false);
ohair@286 1211
ohair@286 1212 _prefixIndex = _namespaceAIIsPrefixIndex[_namespaceAIIsIndex++] = -1;
ohair@286 1213 break;
ohair@286 1214 // prefix, no namespace
ohair@286 1215 // Undeclaration of namespace
ohair@286 1216 case 2:
ohair@286 1217 prefix = _namespaceAIIsPrefix[_namespaceAIIsIndex] =
ohair@286 1218 decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(false);
ohair@286 1219 namespaceName = _namespaceAIIsNamespaceName[_namespaceAIIsIndex] = "";
ohair@286 1220
ohair@286 1221 _namespaceNameIndex = -1;
ohair@286 1222 _namespaceAIIsPrefixIndex[_namespaceAIIsIndex++] = _prefixIndex;
ohair@286 1223 break;
ohair@286 1224 // prefix, namespace
ohair@286 1225 // Declaration of prefixed namespace
ohair@286 1226 case 3:
ohair@286 1227 prefix = _namespaceAIIsPrefix[_namespaceAIIsIndex] =
ohair@286 1228 decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(true);
ohair@286 1229 namespaceName = _namespaceAIIsNamespaceName[_namespaceAIIsIndex] =
ohair@286 1230 decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(true);
ohair@286 1231
ohair@286 1232 _namespaceAIIsPrefixIndex[_namespaceAIIsIndex++] = _prefixIndex;
ohair@286 1233 break;
ohair@286 1234 }
ohair@286 1235
ohair@286 1236 // Push namespace declarations onto the stack
ohair@286 1237 _prefixTable.pushScopeWithPrefixEntry(prefix, namespaceName, _prefixIndex, _namespaceNameIndex);
ohair@286 1238
ohair@286 1239 b = read();
ohair@286 1240 }
ohair@286 1241 if (b != EncodingConstants.TERMINATOR) {
ohair@286 1242 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.EIInamespaceNameNotTerminatedCorrectly"));
ohair@286 1243 }
ohair@286 1244 _currentNamespaceAIIsEnd = _namespaceAIIsIndex;
ohair@286 1245
ohair@286 1246 b = read();
ohair@286 1247 switch(DecoderStateTables.EII(b)) {
ohair@286 1248 case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
ohair@286 1249 processEII(_elementNameTable._array[b], hasAttributes);
ohair@286 1250 break;
ohair@286 1251 case DecoderStateTables.EII_INDEX_MEDIUM:
ohair@286 1252 processEII(processEIIIndexMedium(b), hasAttributes);
ohair@286 1253 break;
ohair@286 1254 case DecoderStateTables.EII_INDEX_LARGE:
ohair@286 1255 processEII(processEIIIndexLarge(b), hasAttributes);
ohair@286 1256 break;
ohair@286 1257 case DecoderStateTables.EII_LITERAL:
ohair@286 1258 {
ohair@286 1259 final QualifiedName qn = processLiteralQualifiedName(
ohair@286 1260 b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
ohair@286 1261 _elementNameTable.getNext());
ohair@286 1262 _elementNameTable.add(qn);
ohair@286 1263 processEII(qn, hasAttributes);
ohair@286 1264 break;
ohair@286 1265 }
ohair@286 1266 default:
ohair@286 1267 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEIIAfterAIIs"));
ohair@286 1268 }
ohair@286 1269 }
ohair@286 1270
ohair@286 1271 protected final void processEII(QualifiedName name, boolean hasAttributes) throws FastInfosetException, IOException {
ohair@286 1272 if (_prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) {
ohair@286 1273 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qnameOfEIINotInScope"));
ohair@286 1274 }
ohair@286 1275
ohair@286 1276 _eventType = START_ELEMENT;
ohair@286 1277 _qualifiedName = name;
ohair@286 1278
ohair@286 1279 if (_clearAttributes) {
ohair@286 1280 _attributes.clear();
ohair@286 1281 _clearAttributes = false;
ohair@286 1282 }
ohair@286 1283
ohair@286 1284 if (hasAttributes) {
ohair@286 1285 processAIIs();
ohair@286 1286 }
ohair@286 1287
ohair@286 1288 // Push element holder onto the stack
ohair@286 1289 _stackCount++;
ohair@286 1290 if (_stackCount == _qNameStack.length) {
ohair@286 1291 QualifiedName[] qNameStack = new QualifiedName[_qNameStack.length * 2];
ohair@286 1292 System.arraycopy(_qNameStack, 0, qNameStack, 0, _qNameStack.length);
ohair@286 1293 _qNameStack = qNameStack;
ohair@286 1294
ohair@286 1295 int[] namespaceAIIsStartStack = new int[_namespaceAIIsStartStack.length * 2];
ohair@286 1296 System.arraycopy(_namespaceAIIsStartStack, 0, namespaceAIIsStartStack, 0, _namespaceAIIsStartStack.length);
ohair@286 1297 _namespaceAIIsStartStack = namespaceAIIsStartStack;
ohair@286 1298
ohair@286 1299 int[] namespaceAIIsEndStack = new int[_namespaceAIIsEndStack.length * 2];
ohair@286 1300 System.arraycopy(_namespaceAIIsEndStack, 0, namespaceAIIsEndStack, 0, _namespaceAIIsEndStack.length);
ohair@286 1301 _namespaceAIIsEndStack = namespaceAIIsEndStack;
ohair@286 1302 }
ohair@286 1303 _qNameStack[_stackCount] = _qualifiedName;
ohair@286 1304 _namespaceAIIsStartStack[_stackCount] = _currentNamespaceAIIsStart;
ohair@286 1305 _namespaceAIIsEndStack[_stackCount] = _currentNamespaceAIIsEnd;
ohair@286 1306 }
ohair@286 1307
ohair@286 1308 protected final void processAIIs() throws FastInfosetException, IOException {
ohair@286 1309 QualifiedName name;
ohair@286 1310 int b;
ohair@286 1311 String value;
ohair@286 1312
ohair@286 1313 if (++_duplicateAttributeVerifier._currentIteration == Integer.MAX_VALUE) {
ohair@286 1314 _duplicateAttributeVerifier.clear();
ohair@286 1315 }
ohair@286 1316
ohair@286 1317 _clearAttributes = true;
ohair@286 1318 boolean terminate = false;
ohair@286 1319 do {
ohair@286 1320 // AII qualified name
ohair@286 1321 b = read();
ohair@286 1322 switch (DecoderStateTables.AII(b)) {
ohair@286 1323 case DecoderStateTables.AII_INDEX_SMALL:
ohair@286 1324 name = _attributeNameTable._array[b];
ohair@286 1325 break;
ohair@286 1326 case DecoderStateTables.AII_INDEX_MEDIUM:
ohair@286 1327 {
ohair@286 1328 final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read())
ohair@286 1329 + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT;
ohair@286 1330 name = _attributeNameTable._array[i];
ohair@286 1331 break;
ohair@286 1332 }
ohair@286 1333 case DecoderStateTables.AII_INDEX_LARGE:
ohair@286 1334 {
ohair@286 1335 final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read())
ohair@286 1336 + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT;
ohair@286 1337 name = _attributeNameTable._array[i];
ohair@286 1338 break;
ohair@286 1339 }
ohair@286 1340 case DecoderStateTables.AII_LITERAL:
ohair@286 1341 name = processLiteralQualifiedName(
ohair@286 1342 b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
ohair@286 1343 _attributeNameTable.getNext());
ohair@286 1344 name.createAttributeValues(DuplicateAttributeVerifier.MAP_SIZE);
ohair@286 1345 _attributeNameTable.add(name);
ohair@286 1346 break;
ohair@286 1347 case DecoderStateTables.AII_TERMINATOR_DOUBLE:
ohair@286 1348 _internalState = INTERNAL_STATE_START_ELEMENT_TERMINATE;
ohair@286 1349 case DecoderStateTables.AII_TERMINATOR_SINGLE:
ohair@286 1350 terminate = true;
ohair@286 1351 // AIIs have finished break out of loop
ohair@286 1352 continue;
ohair@286 1353 default:
ohair@286 1354 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingAIIs"));
ohair@286 1355 }
ohair@286 1356
ohair@286 1357 // [normalized value] of AII
ohair@286 1358
ohair@286 1359 if (name.prefixIndex > 0 && _prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) {
ohair@286 1360 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.AIIqNameNotInScope"));
ohair@286 1361 }
ohair@286 1362
ohair@286 1363 _duplicateAttributeVerifier.checkForDuplicateAttribute(name.attributeHash, name.attributeId);
ohair@286 1364
ohair@286 1365 b = read();
ohair@286 1366 switch(DecoderStateTables.NISTRING(b)) {
ohair@286 1367 case DecoderStateTables.NISTRING_UTF8_SMALL_LENGTH:
ohair@286 1368 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1;
ohair@286 1369 value = decodeUtf8StringAsString();
ohair@286 1370 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
ohair@286 1371 _attributeValueTable.add(value);
ohair@286 1372 }
ohair@286 1373
ohair@286 1374 _attributes.addAttribute(name, value);
ohair@286 1375 break;
ohair@286 1376 case DecoderStateTables.NISTRING_UTF8_MEDIUM_LENGTH:
ohair@286 1377 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT;
ohair@286 1378 value = decodeUtf8StringAsString();
ohair@286 1379 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
ohair@286 1380 _attributeValueTable.add(value);
ohair@286 1381 }
ohair@286 1382
ohair@286 1383 _attributes.addAttribute(name, value);
ohair@286 1384 break;
ohair@286 1385 case DecoderStateTables.NISTRING_UTF8_LARGE_LENGTH:
ohair@286 1386 _octetBufferLength = ((read() << 24) |
ohair@286 1387 (read() << 16) |
ohair@286 1388 (read() << 8) |
ohair@286 1389 read())
ohair@286 1390 + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT;
ohair@286 1391 value = decodeUtf8StringAsString();
ohair@286 1392 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
ohair@286 1393 _attributeValueTable.add(value);
ohair@286 1394 }
ohair@286 1395
ohair@286 1396 _attributes.addAttribute(name, value);
ohair@286 1397 break;
ohair@286 1398 case DecoderStateTables.NISTRING_UTF16_SMALL_LENGTH:
ohair@286 1399 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1;
ohair@286 1400 value = decodeUtf16StringAsString();
ohair@286 1401 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
ohair@286 1402 _attributeValueTable.add(value);
ohair@286 1403 }
ohair@286 1404
ohair@286 1405 _attributes.addAttribute(name, value);
ohair@286 1406 break;
ohair@286 1407 case DecoderStateTables.NISTRING_UTF16_MEDIUM_LENGTH:
ohair@286 1408 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT;
ohair@286 1409 value = decodeUtf16StringAsString();
ohair@286 1410 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
ohair@286 1411 _attributeValueTable.add(value);
ohair@286 1412 }
ohair@286 1413
ohair@286 1414 _attributes.addAttribute(name, value);
ohair@286 1415 break;
ohair@286 1416 case DecoderStateTables.NISTRING_UTF16_LARGE_LENGTH:
ohair@286 1417 _octetBufferLength = ((read() << 24) |
ohair@286 1418 (read() << 16) |
ohair@286 1419 (read() << 8) |
ohair@286 1420 read())
ohair@286 1421 + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT;
ohair@286 1422 value = decodeUtf16StringAsString();
ohair@286 1423 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
ohair@286 1424 _attributeValueTable.add(value);
ohair@286 1425 }
ohair@286 1426
ohair@286 1427 _attributes.addAttribute(name, value);
ohair@286 1428 break;
ohair@286 1429 case DecoderStateTables.NISTRING_RA:
ohair@286 1430 {
ohair@286 1431 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
ohair@286 1432 // Decode resitricted alphabet integer
ohair@286 1433 _identifier = (b & 0x0F) << 4;
ohair@286 1434 b = read();
ohair@286 1435 _identifier |= (b & 0xF0) >> 4;
ohair@286 1436
ohair@286 1437 decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b);
ohair@286 1438
ohair@286 1439 value = decodeRestrictedAlphabetAsString();
ohair@286 1440 if (addToTable) {
ohair@286 1441 _attributeValueTable.add(value);
ohair@286 1442 }
ohair@286 1443
ohair@286 1444 _attributes.addAttribute(name, value);
ohair@286 1445 break;
ohair@286 1446 }
ohair@286 1447 case DecoderStateTables.NISTRING_EA:
ohair@286 1448 {
ohair@286 1449 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
ohair@286 1450 // Decode encoding algorithm integer
ohair@286 1451 _identifier = (b & 0x0F) << 4;
ohair@286 1452 b = read();
ohair@286 1453 _identifier |= (b & 0xF0) >> 4;
ohair@286 1454
ohair@286 1455 decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b);
ohair@286 1456 processAIIEncodingAlgorithm(name, addToTable);
ohair@286 1457 break;
ohair@286 1458 }
ohair@286 1459 case DecoderStateTables.NISTRING_INDEX_SMALL:
ohair@286 1460 _attributes.addAttribute(name,
ohair@286 1461 _attributeValueTable._array[b & EncodingConstants.INTEGER_2ND_BIT_SMALL_MASK]);
ohair@286 1462 break;
ohair@286 1463 case DecoderStateTables.NISTRING_INDEX_MEDIUM:
ohair@286 1464 {
ohair@286 1465 final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read())
ohair@286 1466 + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT;
ohair@286 1467
ohair@286 1468 _attributes.addAttribute(name,
ohair@286 1469 _attributeValueTable._array[index]);
ohair@286 1470 break;
ohair@286 1471 }
ohair@286 1472 case DecoderStateTables.NISTRING_INDEX_LARGE:
ohair@286 1473 {
ohair@286 1474 final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read())
ohair@286 1475 + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT;
ohair@286 1476
ohair@286 1477 _attributes.addAttribute(name,
ohair@286 1478 _attributeValueTable._array[index]);
ohair@286 1479 break;
ohair@286 1480 }
ohair@286 1481 case DecoderStateTables.NISTRING_EMPTY:
ohair@286 1482 _attributes.addAttribute(name, "");
ohair@286 1483 break;
ohair@286 1484 default:
ohair@286 1485 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingAIIValue"));
ohair@286 1486 }
ohair@286 1487
ohair@286 1488 } while (!terminate);
ohair@286 1489
ohair@286 1490 // Reset duplication attribute verfifier
ohair@286 1491 _duplicateAttributeVerifier._poolCurrent = _duplicateAttributeVerifier._poolHead;
ohair@286 1492 }
ohair@286 1493
ohair@286 1494 protected final QualifiedName processEIIIndexMedium(int b) throws FastInfosetException, IOException {
ohair@286 1495 final int i = (((b & EncodingConstants.INTEGER_3RD_BIT_MEDIUM_MASK) << 8) | read())
ohair@286 1496 + EncodingConstants.INTEGER_3RD_BIT_SMALL_LIMIT;
ohair@286 1497 return _elementNameTable._array[i];
ohair@286 1498 }
ohair@286 1499
ohair@286 1500 protected final QualifiedName processEIIIndexLarge(int b) throws FastInfosetException, IOException {
ohair@286 1501 int i;
ohair@286 1502 if ((b & EncodingConstants.INTEGER_3RD_BIT_LARGE_LARGE_FLAG) == 0x20) {
ohair@286 1503 // EII large index
ohair@286 1504 i = (((b & EncodingConstants.INTEGER_3RD_BIT_LARGE_MASK) << 16) | (read() << 8) | read())
ohair@286 1505 + EncodingConstants.INTEGER_3RD_BIT_MEDIUM_LIMIT;
ohair@286 1506 } else {
ohair@286 1507 // EII large large index
ohair@286 1508 i = (((read() & EncodingConstants.INTEGER_3RD_BIT_LARGE_LARGE_MASK) << 16) | (read() << 8) | read())
ohair@286 1509 + EncodingConstants.INTEGER_3RD_BIT_LARGE_LIMIT;
ohair@286 1510 }
ohair@286 1511 return _elementNameTable._array[i];
ohair@286 1512 }
ohair@286 1513
ohair@286 1514 protected final QualifiedName processLiteralQualifiedName(int state, QualifiedName q)
ohair@286 1515 throws FastInfosetException, IOException {
ohair@286 1516 if (q == null) q = new QualifiedName();
ohair@286 1517
ohair@286 1518 switch (state) {
ohair@286 1519 // no prefix, no namespace
ohair@286 1520 case 0:
ohair@286 1521 return q.set(
ohair@286 1522 "",
ohair@286 1523 "",
ohair@286 1524 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
ohair@286 1525 "",
ohair@286 1526 0,
ohair@286 1527 -1,
ohair@286 1528 -1,
ohair@286 1529 _identifier);
ohair@286 1530 // no prefix, namespace
ohair@286 1531 case 1:
ohair@286 1532 return q.set(
ohair@286 1533 "",
ohair@286 1534 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(false),
ohair@286 1535 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
ohair@286 1536 "",
ohair@286 1537 0,
ohair@286 1538 -1,
ohair@286 1539 _namespaceNameIndex,
ohair@286 1540 _identifier);
ohair@286 1541 // prefix, no namespace
ohair@286 1542 case 2:
ohair@286 1543 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qNameMissingNamespaceName"));
ohair@286 1544 // prefix, namespace
ohair@286 1545 case 3:
ohair@286 1546 return q.set(
ohair@286 1547 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsPrefix(true),
ohair@286 1548 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(true),
ohair@286 1549 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
ohair@286 1550 "",
ohair@286 1551 0,
ohair@286 1552 _prefixIndex,
ohair@286 1553 _namespaceNameIndex,
ohair@286 1554 _identifier);
ohair@286 1555 default:
ohair@286 1556 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingEII"));
ohair@286 1557 }
ohair@286 1558 }
ohair@286 1559
ohair@286 1560 protected final void processCommentII() throws FastInfosetException, IOException {
ohair@286 1561 _eventType = COMMENT;
ohair@286 1562
ohair@286 1563 switch(decodeNonIdentifyingStringOnFirstBit()) {
ohair@286 1564 case NISTRING_STRING:
ohair@286 1565 if (_addToTable) {
ohair@286 1566 _v.otherString.add(new CharArray(_charBuffer, 0, _charBufferLength, true));
ohair@286 1567 }
ohair@286 1568
ohair@286 1569 _characters = _charBuffer;
ohair@286 1570 _charactersOffset = 0;
ohair@286 1571 break;
ohair@286 1572 case NISTRING_ENCODING_ALGORITHM:
ohair@286 1573 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.commentIIAlgorithmNotSupported"));
ohair@286 1574 case NISTRING_INDEX:
ohair@286 1575 final CharArray ca = _v.otherString.get(_integer);
ohair@286 1576
ohair@286 1577 _characters = ca.ch;
ohair@286 1578 _charactersOffset = ca.start;
ohair@286 1579 _charBufferLength = ca.length;
ohair@286 1580 break;
ohair@286 1581 case NISTRING_EMPTY_STRING:
ohair@286 1582 _characters = _charBuffer;
ohair@286 1583 _charactersOffset = 0;
ohair@286 1584 _charBufferLength = 0;
ohair@286 1585 break;
ohair@286 1586 }
ohair@286 1587 }
ohair@286 1588
ohair@286 1589 protected final void processProcessingII() throws FastInfosetException, IOException {
ohair@286 1590 _eventType = PROCESSING_INSTRUCTION;
ohair@286 1591
ohair@286 1592 _piTarget = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName);
ohair@286 1593
ohair@286 1594 switch(decodeNonIdentifyingStringOnFirstBit()) {
ohair@286 1595 case NISTRING_STRING:
ohair@286 1596 _piData = new String(_charBuffer, 0, _charBufferLength);
ohair@286 1597 if (_addToTable) {
ohair@286 1598 _v.otherString.add(new CharArrayString(_piData));
ohair@286 1599 }
ohair@286 1600 break;
ohair@286 1601 case NISTRING_ENCODING_ALGORITHM:
ohair@286 1602 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.processingIIWithEncodingAlgorithm"));
ohair@286 1603 case NISTRING_INDEX:
ohair@286 1604 _piData = _v.otherString.get(_integer).toString();
ohair@286 1605 break;
ohair@286 1606 case NISTRING_EMPTY_STRING:
ohair@286 1607 _piData = "";
ohair@286 1608 break;
ohair@286 1609 }
ohair@286 1610 }
ohair@286 1611
ohair@286 1612 protected final void processUnexpandedEntityReference(final int b) throws FastInfosetException, IOException {
ohair@286 1613 _eventType = ENTITY_REFERENCE;
ohair@286 1614
ohair@286 1615 /*
ohair@286 1616 * TODO
ohair@286 1617 * How does StAX report such events?
ohair@286 1618 */
ohair@286 1619 String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName);
ohair@286 1620
ohair@286 1621 String system_identifier = ((b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0)
ohair@286 1622 ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : "";
ohair@286 1623 String public_identifier = ((b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0)
ohair@286 1624 ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : "";
mkos@384 1625
mkos@384 1626 if (logger.isLoggable(Level.FINEST)) {
mkos@384 1627 logger.log(Level.FINEST, "processUnexpandedEntityReference: entity_reference_name={0} system_identifier={1}public_identifier={2}",
mkos@384 1628 new Object[]{entity_reference_name, system_identifier, public_identifier});
mkos@384 1629 }
ohair@286 1630 }
ohair@286 1631
ohair@286 1632 protected final void processCIIEncodingAlgorithm(boolean addToTable) throws FastInfosetException, IOException {
ohair@286 1633 _algorithmData = _octetBuffer;
ohair@286 1634 _algorithmDataOffset = _octetBufferStart;
ohair@286 1635 _algorithmDataLength = _octetBufferLength;
ohair@286 1636 _isAlgorithmDataCloned = false;
ohair@286 1637
ohair@286 1638 if (_algorithmId >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
ohair@286 1639 _algorithmURI = _v.encodingAlgorithm.get(_algorithmId - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
ohair@286 1640 if (_algorithmURI == null) {
ohair@286 1641 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent", new Object[]{Integer.valueOf(_identifier)}));
ohair@286 1642 }
ohair@286 1643 } else if (_algorithmId > EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
ohair@286 1644 // Reserved built-in algorithms for future use
ohair@286 1645 // TODO should use sax property to decide if event will be
ohair@286 1646 // reported, allows for support through handler if required.
ohair@286 1647 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved"));
ohair@286 1648 }
ohair@286 1649
ohair@286 1650 if (addToTable) {
ohair@286 1651 convertEncodingAlgorithmDataToCharacters();
ohair@286 1652 _characterContentChunkTable.add(_characters, _characters.length);
ohair@286 1653 }
ohair@286 1654 }
ohair@286 1655
ohair@286 1656 protected final void processAIIEncodingAlgorithm(QualifiedName name, boolean addToTable) throws FastInfosetException, IOException {
ohair@286 1657 EncodingAlgorithm ea = null;
ohair@286 1658 String URI = null;
ohair@286 1659 if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
ohair@286 1660 URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
ohair@286 1661 if (URI == null) {
ohair@286 1662 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent", new Object[]{Integer.valueOf(_identifier)}));
ohair@286 1663 } else if (_registeredEncodingAlgorithms != null) {
ohair@286 1664 ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
ohair@286 1665 }
ohair@286 1666 } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
ohair@286 1667 if (_identifier == EncodingAlgorithmIndexes.CDATA) {
ohair@286 1668 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
ohair@286 1669 }
ohair@286 1670
ohair@286 1671 // Reserved built-in algorithms for future use
ohair@286 1672 // TODO should use sax property to decide if event will be
ohair@286 1673 // reported, allows for support through handler if required.
ohair@286 1674 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved"));
ohair@286 1675 } else {
ohair@286 1676 ea = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier);
ohair@286 1677 }
ohair@286 1678
ohair@286 1679 Object algorithmData;
ohair@286 1680
ohair@286 1681 if (ea != null) {
ohair@286 1682 algorithmData = ea.decodeFromBytes(_octetBuffer, _octetBufferStart,
ohair@286 1683 _octetBufferLength);
ohair@286 1684 } else {
ohair@286 1685 final byte[] data = new byte[_octetBufferLength];
ohair@286 1686 System.arraycopy(_octetBuffer, _octetBufferStart, data, 0,
ohair@286 1687 _octetBufferLength);
ohair@286 1688 algorithmData = data;
ohair@286 1689 }
ohair@286 1690
ohair@286 1691 _attributes.addAttributeWithAlgorithmData(name, URI, _identifier,
ohair@286 1692 algorithmData);
ohair@286 1693 if (addToTable) {
ohair@286 1694 _attributeValueTable.add(_attributes.getValue(_attributes.getIndex(name.qName)));
ohair@286 1695 }
ohair@286 1696 }
ohair@286 1697
ohair@286 1698 protected final void convertEncodingAlgorithmDataToCharacters() throws FastInfosetException, IOException {
ohair@286 1699 StringBuffer buffer = new StringBuffer();
ohair@286 1700 if (_algorithmId == EncodingAlgorithmIndexes.BASE64) {
ohair@286 1701 convertBase64AlorithmDataToCharacters(buffer);
ohair@286 1702 } else if (_algorithmId < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
ohair@286 1703 Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_algorithmId).
ohair@286 1704 decodeFromBytes(_algorithmData, _algorithmDataOffset, _algorithmDataLength);
ohair@286 1705 BuiltInEncodingAlgorithmFactory.getAlgorithm(_algorithmId).convertToCharacters(array, buffer);
ohair@286 1706 } else if (_algorithmId == EncodingAlgorithmIndexes.CDATA) {
ohair@286 1707 _octetBufferOffset -= _octetBufferLength;
ohair@286 1708 decodeUtf8StringIntoCharBuffer();
ohair@286 1709
ohair@286 1710 _characters = _charBuffer;
ohair@286 1711 _charactersOffset = 0;
ohair@286 1712 return;
ohair@286 1713 } else if (_algorithmId >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
ohair@286 1714 final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(_algorithmURI);
ohair@286 1715 if (ea != null) {
ohair@286 1716 final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
ohair@286 1717 ea.convertToCharacters(data, buffer);
ohair@286 1718 } else {
ohair@286 1719 throw new EncodingAlgorithmException(
ohair@286 1720 CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported"));
ohair@286 1721 }
ohair@286 1722 }
ohair@286 1723
ohair@286 1724 _characters = new char[buffer.length()];
ohair@286 1725 buffer.getChars(0, buffer.length(), _characters, 0);
ohair@286 1726 _charactersOffset = 0;
ohair@286 1727 _charBufferLength = _characters.length;
ohair@286 1728 }
ohair@286 1729
ohair@286 1730 /* If base64 data comes is chunks, bytes, which were cut to align 3,
ohair@286 1731 * from prev. base64 chunk are stored in this buffer */
ohair@286 1732 private byte[] base64TaleBytes = new byte[3];
ohair@286 1733 private int base64TaleLength;
ohair@286 1734 /*
ohair@286 1735 * Method converts _algorithmData to base64 encoded String
ohair@286 1736 * Counts with base64 data coming in chunks, aligning input chunks by 3,
ohair@286 1737 * avoiding double cloning, happening after possible peek, peek2 cloning by Base64 algorithm
ohair@286 1738 */
ohair@286 1739 protected void convertBase64AlorithmDataToCharacters(StringBuffer buffer) throws EncodingAlgorithmException, IOException {
ohair@286 1740 // How much new came data was serialized with prev. tale
ohair@286 1741 int afterTaleOffset = 0;
ohair@286 1742
ohair@286 1743 if (base64TaleLength > 0) {
ohair@286 1744 // Serialize tale left from prev. chunk
ohair@286 1745 int bytesToCopy = Math.min(3 - base64TaleLength, _algorithmDataLength);
ohair@286 1746 System.arraycopy(_algorithmData, _algorithmDataOffset, base64TaleBytes, base64TaleLength, bytesToCopy);
ohair@286 1747 if (base64TaleLength + bytesToCopy == 3) {
ohair@286 1748 base64DecodeWithCloning(buffer, base64TaleBytes, 0, 3);
ohair@286 1749 } else if (!isBase64Follows()) {
ohair@286 1750 // End of text was read to temp array
ohair@286 1751 base64DecodeWithCloning(buffer, base64TaleBytes, 0, base64TaleLength + bytesToCopy);
ohair@286 1752 return;
ohair@286 1753 } else {
ohair@286 1754 // If the end of chunk fit to tmp array, but next chunk is expected
ohair@286 1755 base64TaleLength += bytesToCopy;
ohair@286 1756 return;
ohair@286 1757 }
ohair@286 1758
ohair@286 1759 afterTaleOffset = bytesToCopy;
ohair@286 1760 base64TaleLength = 0;
ohair@286 1761 }
ohair@286 1762
ohair@286 1763 int taleBytesRemaining = isBase64Follows() ? (_algorithmDataLength - afterTaleOffset) % 3 : 0;
ohair@286 1764
ohair@286 1765 if (_isAlgorithmDataCloned) {
ohair@286 1766 base64DecodeWithoutCloning(buffer, _algorithmData, _algorithmDataOffset + afterTaleOffset,
ohair@286 1767 _algorithmDataLength - afterTaleOffset - taleBytesRemaining);
ohair@286 1768 } else {
ohair@286 1769 base64DecodeWithCloning(buffer, _algorithmData, _algorithmDataOffset + afterTaleOffset,
ohair@286 1770 _algorithmDataLength - afterTaleOffset - taleBytesRemaining);
ohair@286 1771 }
ohair@286 1772
ohair@286 1773 if (taleBytesRemaining > 0) {
ohair@286 1774 System.arraycopy(_algorithmData, _algorithmDataOffset + _algorithmDataLength - taleBytesRemaining,
ohair@286 1775 base64TaleBytes, 0, taleBytesRemaining);
ohair@286 1776 base64TaleLength = taleBytesRemaining;
ohair@286 1777 }
ohair@286 1778 }
ohair@286 1779
ohair@286 1780 /*
ohair@286 1781 * Encodes incoming data to Base64 string.
ohair@286 1782 * Method performs additional input data cloning
ohair@286 1783 */
ohair@286 1784 private void base64DecodeWithCloning(StringBuffer dstBuffer, byte[] data, int offset, int length) throws EncodingAlgorithmException {
ohair@286 1785 Object array = BuiltInEncodingAlgorithmFactory.base64EncodingAlgorithm.
ohair@286 1786 decodeFromBytes(data, offset, length);
ohair@286 1787 BuiltInEncodingAlgorithmFactory.base64EncodingAlgorithm.convertToCharacters(array, dstBuffer);
ohair@286 1788 }
ohair@286 1789
ohair@286 1790 /*
ohair@286 1791 * Encodes incoming data to Base64 string.
ohair@286 1792 * Avoids input data cloning
ohair@286 1793 */
ohair@286 1794 private void base64DecodeWithoutCloning(StringBuffer dstBuffer, byte[] data, int offset, int length) throws EncodingAlgorithmException {
ohair@286 1795 BuiltInEncodingAlgorithmFactory.base64EncodingAlgorithm.convertToCharacters(data, offset, length, dstBuffer);
ohair@286 1796 }
ohair@286 1797
ohair@286 1798
ohair@286 1799 /*
ohair@286 1800 * Looks ahead in InputStream, whether next data is Base64 chunk
ohair@286 1801 */
ohair@286 1802 public boolean isBase64Follows() throws IOException {
ohair@286 1803 // Process information item
ohair@286 1804 int b = peek(this);
ohair@286 1805 switch (DecoderStateTables.EII(b)) {
ohair@286 1806 case DecoderStateTables.CII_EA:
ohair@286 1807 int algorithmId = (b & 0x02) << 6;
ohair@286 1808 int b2 = peek2(this);
ohair@286 1809 algorithmId |= (b2 & 0xFC) >> 2;
ohair@286 1810
ohair@286 1811 return algorithmId == EncodingAlgorithmIndexes.BASE64;
ohair@286 1812 default:
ohair@286 1813 return false;
ohair@286 1814 }
ohair@286 1815 }
ohair@286 1816
ohair@286 1817 protected class NamespaceContextImpl implements NamespaceContext {
ohair@286 1818 public final String getNamespaceURI(String prefix) {
ohair@286 1819 return _prefixTable.getNamespaceFromPrefix(prefix);
ohair@286 1820 }
ohair@286 1821
ohair@286 1822 public final String getPrefix(String namespaceURI) {
ohair@286 1823 return _prefixTable.getPrefixFromNamespace(namespaceURI);
ohair@286 1824 }
ohair@286 1825
ohair@286 1826 public final Iterator getPrefixes(String namespaceURI) {
ohair@286 1827 return _prefixTable.getPrefixesFromNamespace(namespaceURI);
ohair@286 1828 }
ohair@286 1829 }
ohair@286 1830
ohair@286 1831 public final String getNamespaceDecl(String prefix) {
ohair@286 1832 return _prefixTable.getNamespaceFromPrefix(prefix);
ohair@286 1833 }
ohair@286 1834
ohair@286 1835 public final String getURI(String prefix) {
ohair@286 1836 return getNamespaceDecl(prefix);
ohair@286 1837 }
ohair@286 1838
ohair@286 1839 public final Iterator getPrefixes() {
ohair@286 1840 return _prefixTable.getPrefixes();
ohair@286 1841 }
ohair@286 1842
ohair@286 1843 public final AttributesHolder getAttributesHolder() {
ohair@286 1844 return _attributes;
ohair@286 1845 }
ohair@286 1846
ohair@286 1847 public final void setManager(StAXManager manager) {
ohair@286 1848 _manager = manager;
ohair@286 1849 }
ohair@286 1850
ohair@286 1851 final static String getEventTypeString(int eventType) {
ohair@286 1852 switch (eventType){
ohair@286 1853 case START_ELEMENT:
ohair@286 1854 return "START_ELEMENT";
ohair@286 1855 case END_ELEMENT:
ohair@286 1856 return "END_ELEMENT";
ohair@286 1857 case PROCESSING_INSTRUCTION:
ohair@286 1858 return "PROCESSING_INSTRUCTION";
ohair@286 1859 case CHARACTERS:
ohair@286 1860 return "CHARACTERS";
ohair@286 1861 case COMMENT:
ohair@286 1862 return "COMMENT";
ohair@286 1863 case START_DOCUMENT:
ohair@286 1864 return "START_DOCUMENT";
ohair@286 1865 case END_DOCUMENT:
ohair@286 1866 return "END_DOCUMENT";
ohair@286 1867 case ENTITY_REFERENCE:
ohair@286 1868 return "ENTITY_REFERENCE";
ohair@286 1869 case ATTRIBUTE:
ohair@286 1870 return "ATTRIBUTE";
ohair@286 1871 case DTD:
ohair@286 1872 return "DTD";
ohair@286 1873 case CDATA:
ohair@286 1874 return "CDATA";
ohair@286 1875 }
ohair@286 1876 return "UNKNOWN_EVENT_TYPE";
ohair@286 1877 }
ohair@286 1878 }

mercurial