Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | * |
aoqi@0 | 25 | * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. |
aoqi@0 | 26 | */ |
aoqi@0 | 27 | |
aoqi@0 | 28 | package com.sun.xml.internal.fastinfoset.sax; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import com.sun.xml.internal.fastinfoset.Decoder; |
aoqi@0 | 31 | import com.sun.xml.internal.fastinfoset.DecoderStateTables; |
aoqi@0 | 32 | import com.sun.xml.internal.fastinfoset.EncodingConstants; |
aoqi@0 | 33 | import com.sun.xml.internal.fastinfoset.QualifiedName; |
aoqi@0 | 34 | import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory; |
aoqi@0 | 35 | import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmState; |
aoqi@0 | 36 | import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmContentHandler; |
aoqi@0 | 37 | import com.sun.xml.internal.org.jvnet.fastinfoset.sax.FastInfosetReader; |
aoqi@0 | 38 | import com.sun.xml.internal.org.jvnet.fastinfoset.sax.PrimitiveTypeContentHandler; |
aoqi@0 | 39 | import com.sun.xml.internal.fastinfoset.util.CharArray; |
aoqi@0 | 40 | import com.sun.xml.internal.fastinfoset.util.CharArrayString; |
aoqi@0 | 41 | import java.io.IOException; |
aoqi@0 | 42 | import java.io.InputStream; |
aoqi@0 | 43 | import java.net.URL; |
aoqi@0 | 44 | import java.util.Map; |
aoqi@0 | 45 | import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm; |
aoqi@0 | 46 | import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException; |
aoqi@0 | 47 | import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes; |
aoqi@0 | 48 | import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException; |
aoqi@0 | 49 | import org.xml.sax.ContentHandler; |
aoqi@0 | 50 | import org.xml.sax.DTDHandler; |
aoqi@0 | 51 | import org.xml.sax.EntityResolver; |
aoqi@0 | 52 | import org.xml.sax.ErrorHandler; |
aoqi@0 | 53 | import org.xml.sax.InputSource; |
aoqi@0 | 54 | import org.xml.sax.SAXException; |
aoqi@0 | 55 | import org.xml.sax.SAXNotRecognizedException; |
aoqi@0 | 56 | import org.xml.sax.SAXNotSupportedException; |
aoqi@0 | 57 | import org.xml.sax.SAXParseException; |
aoqi@0 | 58 | import org.xml.sax.ext.LexicalHandler; |
aoqi@0 | 59 | import org.xml.sax.helpers.DefaultHandler; |
aoqi@0 | 60 | import com.sun.xml.internal.fastinfoset.CommonResourceBundle; |
aoqi@0 | 61 | import java.util.logging.Level; |
aoqi@0 | 62 | import java.util.logging.Logger; |
aoqi@0 | 63 | import org.xml.sax.ext.DeclHandler; |
aoqi@0 | 64 | |
aoqi@0 | 65 | /** |
aoqi@0 | 66 | * The Fast Infoset SAX parser. |
aoqi@0 | 67 | * <p> |
aoqi@0 | 68 | * Instantiate this parser to parse a fast infoset document in accordance |
aoqi@0 | 69 | * with the SAX API. |
aoqi@0 | 70 | * |
aoqi@0 | 71 | * <p> |
aoqi@0 | 72 | * More than one fast infoset document may be decoded from the |
aoqi@0 | 73 | * {@link java.io.InputStream}. |
aoqi@0 | 74 | */ |
aoqi@0 | 75 | public class SAXDocumentParser extends Decoder implements FastInfosetReader { |
aoqi@0 | 76 | private static final Logger logger = Logger.getLogger(SAXDocumentParser.class.getName()); |
aoqi@0 | 77 | |
aoqi@0 | 78 | /* |
aoqi@0 | 79 | * Empty lexical handler used by default to report |
aoqi@0 | 80 | * lexical-based events |
aoqi@0 | 81 | */ |
aoqi@0 | 82 | private static final class LexicalHandlerImpl implements LexicalHandler { |
aoqi@0 | 83 | public void comment(char[] ch, int start, int end) { } |
aoqi@0 | 84 | |
aoqi@0 | 85 | public void startDTD(String name, String publicId, String systemId) { } |
aoqi@0 | 86 | public void endDTD() { } |
aoqi@0 | 87 | |
aoqi@0 | 88 | public void startEntity(String name) { } |
aoqi@0 | 89 | public void endEntity(String name) { } |
aoqi@0 | 90 | |
aoqi@0 | 91 | public void startCDATA() { } |
aoqi@0 | 92 | public void endCDATA() { } |
aoqi@0 | 93 | }; |
aoqi@0 | 94 | |
aoqi@0 | 95 | /* |
aoqi@0 | 96 | * Empty DTD declaration handler used by default to report |
aoqi@0 | 97 | * DTD declaration-based events |
aoqi@0 | 98 | */ |
aoqi@0 | 99 | private static final class DeclHandlerImpl implements DeclHandler { |
aoqi@0 | 100 | public void elementDecl(String name, String model) throws SAXException { |
aoqi@0 | 101 | } |
aoqi@0 | 102 | |
aoqi@0 | 103 | public void attributeDecl(String eName, String aName, |
aoqi@0 | 104 | String type, String mode, String value) throws SAXException { |
aoqi@0 | 105 | } |
aoqi@0 | 106 | |
aoqi@0 | 107 | public void internalEntityDecl(String name, |
aoqi@0 | 108 | String value) throws SAXException { |
aoqi@0 | 109 | } |
aoqi@0 | 110 | |
aoqi@0 | 111 | public void externalEntityDecl(String name, |
aoqi@0 | 112 | String publicId, String systemId) throws SAXException { |
aoqi@0 | 113 | } |
aoqi@0 | 114 | } |
aoqi@0 | 115 | |
aoqi@0 | 116 | /** |
aoqi@0 | 117 | * SAX Namespace attributes features |
aoqi@0 | 118 | */ |
aoqi@0 | 119 | protected boolean _namespacePrefixesFeature = false; |
aoqi@0 | 120 | |
aoqi@0 | 121 | /** |
aoqi@0 | 122 | * Reference to entity resolver. |
aoqi@0 | 123 | */ |
aoqi@0 | 124 | protected EntityResolver _entityResolver; |
aoqi@0 | 125 | |
aoqi@0 | 126 | /** |
aoqi@0 | 127 | * Reference to dtd handler. |
aoqi@0 | 128 | */ |
aoqi@0 | 129 | protected DTDHandler _dtdHandler; |
aoqi@0 | 130 | |
aoqi@0 | 131 | /** |
aoqi@0 | 132 | * Reference to content handler. |
aoqi@0 | 133 | */ |
aoqi@0 | 134 | protected ContentHandler _contentHandler; |
aoqi@0 | 135 | |
aoqi@0 | 136 | /** |
aoqi@0 | 137 | * Reference to error handler. |
aoqi@0 | 138 | */ |
aoqi@0 | 139 | protected ErrorHandler _errorHandler; |
aoqi@0 | 140 | |
aoqi@0 | 141 | /** |
aoqi@0 | 142 | * Reference to lexical handler. |
aoqi@0 | 143 | */ |
aoqi@0 | 144 | protected LexicalHandler _lexicalHandler; |
aoqi@0 | 145 | |
aoqi@0 | 146 | /** |
aoqi@0 | 147 | * Reference to DTD declaration handler. |
aoqi@0 | 148 | */ |
aoqi@0 | 149 | protected DeclHandler _declHandler; |
aoqi@0 | 150 | |
aoqi@0 | 151 | protected EncodingAlgorithmContentHandler _algorithmHandler; |
aoqi@0 | 152 | |
aoqi@0 | 153 | protected PrimitiveTypeContentHandler _primitiveHandler; |
aoqi@0 | 154 | |
aoqi@0 | 155 | protected BuiltInEncodingAlgorithmState builtInAlgorithmState = |
aoqi@0 | 156 | new BuiltInEncodingAlgorithmState(); |
aoqi@0 | 157 | |
aoqi@0 | 158 | protected AttributesHolder _attributes; |
aoqi@0 | 159 | |
aoqi@0 | 160 | protected int[] _namespacePrefixes = new int[16]; |
aoqi@0 | 161 | |
aoqi@0 | 162 | protected int _namespacePrefixesIndex; |
aoqi@0 | 163 | |
aoqi@0 | 164 | protected boolean _clearAttributes = false; |
aoqi@0 | 165 | |
aoqi@0 | 166 | /** Creates a new instance of DocumetParser2 */ |
aoqi@0 | 167 | public SAXDocumentParser() { |
aoqi@0 | 168 | DefaultHandler handler = new DefaultHandler(); |
aoqi@0 | 169 | _attributes = new AttributesHolder(_registeredEncodingAlgorithms); |
aoqi@0 | 170 | |
aoqi@0 | 171 | _entityResolver = handler; |
aoqi@0 | 172 | _dtdHandler = handler; |
aoqi@0 | 173 | _contentHandler = handler; |
aoqi@0 | 174 | _errorHandler = handler; |
aoqi@0 | 175 | _lexicalHandler = new LexicalHandlerImpl(); |
aoqi@0 | 176 | _declHandler = new DeclHandlerImpl(); |
aoqi@0 | 177 | } |
aoqi@0 | 178 | |
aoqi@0 | 179 | protected void resetOnError() { |
aoqi@0 | 180 | _clearAttributes = false; |
aoqi@0 | 181 | _attributes.clear(); |
aoqi@0 | 182 | _namespacePrefixesIndex = 0; |
aoqi@0 | 183 | |
aoqi@0 | 184 | if (_v != null) { |
aoqi@0 | 185 | _v.prefix.clearCompletely(); |
aoqi@0 | 186 | } |
aoqi@0 | 187 | _duplicateAttributeVerifier.clear(); |
aoqi@0 | 188 | } |
aoqi@0 | 189 | |
aoqi@0 | 190 | // XMLReader interface |
aoqi@0 | 191 | |
aoqi@0 | 192 | public boolean getFeature(String name) |
aoqi@0 | 193 | throws SAXNotRecognizedException, SAXNotSupportedException { |
aoqi@0 | 194 | if (name.equals(Features.NAMESPACES_FEATURE)) { |
aoqi@0 | 195 | return true; |
aoqi@0 | 196 | } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) { |
aoqi@0 | 197 | return _namespacePrefixesFeature; |
aoqi@0 | 198 | } else if (name.equals(Features.STRING_INTERNING_FEATURE) || |
aoqi@0 | 199 | name.equals(FastInfosetReader.STRING_INTERNING_PROPERTY)) { |
aoqi@0 | 200 | return getStringInterning(); |
aoqi@0 | 201 | } else { |
aoqi@0 | 202 | throw new SAXNotRecognizedException( |
aoqi@0 | 203 | CommonResourceBundle.getInstance().getString("message.featureNotSupported") + name); |
aoqi@0 | 204 | } |
aoqi@0 | 205 | } |
aoqi@0 | 206 | |
aoqi@0 | 207 | public void setFeature(String name, boolean value) |
aoqi@0 | 208 | throws SAXNotRecognizedException, SAXNotSupportedException { |
aoqi@0 | 209 | if (name.equals(Features.NAMESPACES_FEATURE)) { |
aoqi@0 | 210 | if (value == false) { |
aoqi@0 | 211 | throw new SAXNotSupportedException(name + ":" + value); |
aoqi@0 | 212 | } |
aoqi@0 | 213 | } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) { |
aoqi@0 | 214 | _namespacePrefixesFeature = value; |
aoqi@0 | 215 | } else if (name.equals(Features.STRING_INTERNING_FEATURE) || |
aoqi@0 | 216 | name.equals(FastInfosetReader.STRING_INTERNING_PROPERTY)) { |
aoqi@0 | 217 | setStringInterning(value); |
aoqi@0 | 218 | } else { |
aoqi@0 | 219 | throw new SAXNotRecognizedException( |
aoqi@0 | 220 | CommonResourceBundle.getInstance().getString("message.featureNotSupported") + name); |
aoqi@0 | 221 | } |
aoqi@0 | 222 | } |
aoqi@0 | 223 | |
aoqi@0 | 224 | public Object getProperty(String name) |
aoqi@0 | 225 | throws SAXNotRecognizedException, SAXNotSupportedException { |
aoqi@0 | 226 | if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) { |
aoqi@0 | 227 | return getLexicalHandler(); |
aoqi@0 | 228 | } else if (name.equals(Properties.DTD_DECLARATION_HANDLER_PROPERTY)) { |
aoqi@0 | 229 | return getDeclHandler(); |
aoqi@0 | 230 | } else if (name.equals(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY)) { |
aoqi@0 | 231 | return getExternalVocabularies(); |
aoqi@0 | 232 | } else if (name.equals(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY)) { |
aoqi@0 | 233 | return getRegisteredEncodingAlgorithms(); |
aoqi@0 | 234 | } else if (name.equals(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY)) { |
aoqi@0 | 235 | return getEncodingAlgorithmContentHandler(); |
aoqi@0 | 236 | } else if (name.equals(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY)) { |
aoqi@0 | 237 | return getPrimitiveTypeContentHandler(); |
aoqi@0 | 238 | } else { |
aoqi@0 | 239 | throw new SAXNotRecognizedException(CommonResourceBundle.getInstance(). |
aoqi@0 | 240 | getString("message.propertyNotRecognized", new Object[]{name})); |
aoqi@0 | 241 | } |
aoqi@0 | 242 | } |
aoqi@0 | 243 | |
aoqi@0 | 244 | public void setProperty(String name, Object value) |
aoqi@0 | 245 | throws SAXNotRecognizedException, SAXNotSupportedException { |
aoqi@0 | 246 | if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) { |
aoqi@0 | 247 | if (value instanceof LexicalHandler) { |
aoqi@0 | 248 | setLexicalHandler((LexicalHandler)value); |
aoqi@0 | 249 | } else { |
aoqi@0 | 250 | throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY); |
aoqi@0 | 251 | } |
aoqi@0 | 252 | } else if (name.equals(Properties.DTD_DECLARATION_HANDLER_PROPERTY)) { |
aoqi@0 | 253 | if (value instanceof DeclHandler) { |
aoqi@0 | 254 | setDeclHandler((DeclHandler)value); |
aoqi@0 | 255 | } else { |
aoqi@0 | 256 | throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY); |
aoqi@0 | 257 | } |
aoqi@0 | 258 | } else if (name.equals(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY)) { |
aoqi@0 | 259 | if (value instanceof Map) { |
aoqi@0 | 260 | setExternalVocabularies((Map)value); |
aoqi@0 | 261 | } else { |
aoqi@0 | 262 | throw new SAXNotSupportedException(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY); |
aoqi@0 | 263 | } |
aoqi@0 | 264 | } else if (name.equals(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY)) { |
aoqi@0 | 265 | if (value instanceof Map) { |
aoqi@0 | 266 | setRegisteredEncodingAlgorithms((Map)value); |
aoqi@0 | 267 | } else { |
aoqi@0 | 268 | throw new SAXNotSupportedException(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY); |
aoqi@0 | 269 | } |
aoqi@0 | 270 | } else if (name.equals(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY)) { |
aoqi@0 | 271 | if (value instanceof EncodingAlgorithmContentHandler) { |
aoqi@0 | 272 | setEncodingAlgorithmContentHandler((EncodingAlgorithmContentHandler)value); |
aoqi@0 | 273 | } else { |
aoqi@0 | 274 | throw new SAXNotSupportedException(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY); |
aoqi@0 | 275 | } |
aoqi@0 | 276 | } else if (name.equals(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY)) { |
aoqi@0 | 277 | if (value instanceof PrimitiveTypeContentHandler) { |
aoqi@0 | 278 | setPrimitiveTypeContentHandler((PrimitiveTypeContentHandler)value); |
aoqi@0 | 279 | } else { |
aoqi@0 | 280 | throw new SAXNotSupportedException(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY); |
aoqi@0 | 281 | } |
aoqi@0 | 282 | } else if (name.equals(FastInfosetReader.BUFFER_SIZE_PROPERTY)) { |
aoqi@0 | 283 | if (value instanceof Integer) { |
aoqi@0 | 284 | setBufferSize(((Integer)value).intValue()); |
aoqi@0 | 285 | } else { |
aoqi@0 | 286 | throw new SAXNotSupportedException(FastInfosetReader.BUFFER_SIZE_PROPERTY); |
aoqi@0 | 287 | } |
aoqi@0 | 288 | } else { |
aoqi@0 | 289 | throw new SAXNotRecognizedException(CommonResourceBundle.getInstance(). |
aoqi@0 | 290 | getString("message.propertyNotRecognized", new Object[]{name})); |
aoqi@0 | 291 | } |
aoqi@0 | 292 | } |
aoqi@0 | 293 | |
aoqi@0 | 294 | public void setEntityResolver(EntityResolver resolver) { |
aoqi@0 | 295 | _entityResolver = resolver; |
aoqi@0 | 296 | } |
aoqi@0 | 297 | |
aoqi@0 | 298 | public EntityResolver getEntityResolver() { |
aoqi@0 | 299 | return _entityResolver; |
aoqi@0 | 300 | } |
aoqi@0 | 301 | |
aoqi@0 | 302 | public void setDTDHandler(DTDHandler handler) { |
aoqi@0 | 303 | _dtdHandler = handler; |
aoqi@0 | 304 | } |
aoqi@0 | 305 | |
aoqi@0 | 306 | public DTDHandler getDTDHandler() { |
aoqi@0 | 307 | return _dtdHandler; |
aoqi@0 | 308 | } |
aoqi@0 | 309 | public void setContentHandler(ContentHandler handler) { |
aoqi@0 | 310 | _contentHandler = handler; |
aoqi@0 | 311 | } |
aoqi@0 | 312 | |
aoqi@0 | 313 | public ContentHandler getContentHandler() { |
aoqi@0 | 314 | return _contentHandler; |
aoqi@0 | 315 | } |
aoqi@0 | 316 | |
aoqi@0 | 317 | public void setErrorHandler(ErrorHandler handler) { |
aoqi@0 | 318 | _errorHandler = handler; |
aoqi@0 | 319 | } |
aoqi@0 | 320 | |
aoqi@0 | 321 | public ErrorHandler getErrorHandler() { |
aoqi@0 | 322 | return _errorHandler; |
aoqi@0 | 323 | } |
aoqi@0 | 324 | |
aoqi@0 | 325 | public void parse(InputSource input) throws IOException, SAXException { |
aoqi@0 | 326 | try { |
aoqi@0 | 327 | InputStream s = input.getByteStream(); |
aoqi@0 | 328 | if (s == null) { |
aoqi@0 | 329 | String systemId = input.getSystemId(); |
aoqi@0 | 330 | if (systemId == null) { |
aoqi@0 | 331 | throw new SAXException(CommonResourceBundle.getInstance().getString("message.inputSource")); |
aoqi@0 | 332 | } |
aoqi@0 | 333 | parse(systemId); |
aoqi@0 | 334 | } else { |
aoqi@0 | 335 | parse(s); |
aoqi@0 | 336 | } |
aoqi@0 | 337 | } catch (FastInfosetException e) { |
aoqi@0 | 338 | logger.log(Level.FINE, "parsing error", e); |
aoqi@0 | 339 | throw new SAXException(e); |
aoqi@0 | 340 | } |
aoqi@0 | 341 | } |
aoqi@0 | 342 | |
aoqi@0 | 343 | public void parse(String systemId) throws IOException, SAXException { |
aoqi@0 | 344 | try { |
aoqi@0 | 345 | systemId = SystemIdResolver.getAbsoluteURI(systemId); |
aoqi@0 | 346 | parse(new URL(systemId).openStream()); |
aoqi@0 | 347 | } catch (FastInfosetException e) { |
aoqi@0 | 348 | logger.log(Level.FINE, "parsing error", e); |
aoqi@0 | 349 | throw new SAXException(e); |
aoqi@0 | 350 | } |
aoqi@0 | 351 | } |
aoqi@0 | 352 | |
aoqi@0 | 353 | |
aoqi@0 | 354 | |
aoqi@0 | 355 | |
aoqi@0 | 356 | // FastInfosetReader |
aoqi@0 | 357 | |
aoqi@0 | 358 | public final void parse(InputStream s) throws IOException, FastInfosetException, SAXException { |
aoqi@0 | 359 | setInputStream(s); |
aoqi@0 | 360 | parse(); |
aoqi@0 | 361 | } |
aoqi@0 | 362 | |
aoqi@0 | 363 | public void setLexicalHandler(LexicalHandler handler) { |
aoqi@0 | 364 | _lexicalHandler = handler; |
aoqi@0 | 365 | } |
aoqi@0 | 366 | |
aoqi@0 | 367 | public LexicalHandler getLexicalHandler() { |
aoqi@0 | 368 | return _lexicalHandler; |
aoqi@0 | 369 | } |
aoqi@0 | 370 | |
aoqi@0 | 371 | public void setDeclHandler(DeclHandler handler) { |
aoqi@0 | 372 | _declHandler = handler; |
aoqi@0 | 373 | } |
aoqi@0 | 374 | |
aoqi@0 | 375 | public DeclHandler getDeclHandler() { |
aoqi@0 | 376 | return _declHandler; |
aoqi@0 | 377 | } |
aoqi@0 | 378 | |
aoqi@0 | 379 | public void setEncodingAlgorithmContentHandler(EncodingAlgorithmContentHandler handler) { |
aoqi@0 | 380 | _algorithmHandler = handler; |
aoqi@0 | 381 | } |
aoqi@0 | 382 | |
aoqi@0 | 383 | public EncodingAlgorithmContentHandler getEncodingAlgorithmContentHandler() { |
aoqi@0 | 384 | return _algorithmHandler; |
aoqi@0 | 385 | } |
aoqi@0 | 386 | |
aoqi@0 | 387 | public void setPrimitiveTypeContentHandler(PrimitiveTypeContentHandler handler) { |
aoqi@0 | 388 | _primitiveHandler = handler; |
aoqi@0 | 389 | } |
aoqi@0 | 390 | |
aoqi@0 | 391 | public PrimitiveTypeContentHandler getPrimitiveTypeContentHandler() { |
aoqi@0 | 392 | return _primitiveHandler; |
aoqi@0 | 393 | } |
aoqi@0 | 394 | |
aoqi@0 | 395 | |
aoqi@0 | 396 | |
aoqi@0 | 397 | |
aoqi@0 | 398 | public final void parse() throws FastInfosetException, IOException { |
aoqi@0 | 399 | if (_octetBuffer.length < _bufferSize) { |
aoqi@0 | 400 | _octetBuffer = new byte[_bufferSize]; |
aoqi@0 | 401 | } |
aoqi@0 | 402 | |
aoqi@0 | 403 | try { |
aoqi@0 | 404 | reset(); |
aoqi@0 | 405 | decodeHeader(); |
aoqi@0 | 406 | if (_parseFragments) |
aoqi@0 | 407 | processDIIFragment(); |
aoqi@0 | 408 | else |
aoqi@0 | 409 | processDII(); |
aoqi@0 | 410 | } catch (RuntimeException e) { |
aoqi@0 | 411 | try { |
aoqi@0 | 412 | _errorHandler.fatalError(new SAXParseException(e.getClass().getName(), null, e)); |
aoqi@0 | 413 | } catch (Exception ee) { |
aoqi@0 | 414 | } |
aoqi@0 | 415 | resetOnError(); |
aoqi@0 | 416 | // Wrap runtime exception |
aoqi@0 | 417 | throw new FastInfosetException(e); |
aoqi@0 | 418 | } catch (FastInfosetException e) { |
aoqi@0 | 419 | try { |
aoqi@0 | 420 | _errorHandler.fatalError(new SAXParseException(e.getClass().getName(), null, e)); |
aoqi@0 | 421 | } catch (Exception ee) { |
aoqi@0 | 422 | } |
aoqi@0 | 423 | resetOnError(); |
aoqi@0 | 424 | throw e; |
aoqi@0 | 425 | } catch (IOException e) { |
aoqi@0 | 426 | try { |
aoqi@0 | 427 | _errorHandler.fatalError(new SAXParseException(e.getClass().getName(), null, e)); |
aoqi@0 | 428 | } catch (Exception ee) { |
aoqi@0 | 429 | } |
aoqi@0 | 430 | resetOnError(); |
aoqi@0 | 431 | throw e; |
aoqi@0 | 432 | } |
aoqi@0 | 433 | } |
aoqi@0 | 434 | |
aoqi@0 | 435 | protected final void processDII() throws FastInfosetException, IOException { |
aoqi@0 | 436 | try { |
aoqi@0 | 437 | _contentHandler.startDocument(); |
aoqi@0 | 438 | } catch (SAXException e) { |
aoqi@0 | 439 | throw new FastInfosetException("processDII", e); |
aoqi@0 | 440 | } |
aoqi@0 | 441 | |
aoqi@0 | 442 | _b = read(); |
aoqi@0 | 443 | if (_b > 0) { |
aoqi@0 | 444 | processDIIOptionalProperties(); |
aoqi@0 | 445 | } |
aoqi@0 | 446 | |
aoqi@0 | 447 | // Decode one Document Type II, Comment IIs, PI IIs and one EII |
aoqi@0 | 448 | boolean firstElementHasOccured = false; |
aoqi@0 | 449 | boolean documentTypeDeclarationOccured = false; |
aoqi@0 | 450 | while(!_terminate || !firstElementHasOccured) { |
aoqi@0 | 451 | _b = read(); |
aoqi@0 | 452 | switch(DecoderStateTables.DII(_b)) { |
aoqi@0 | 453 | case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: |
aoqi@0 | 454 | processEII(_elementNameTable._array[_b], false); |
aoqi@0 | 455 | firstElementHasOccured = true; |
aoqi@0 | 456 | break; |
aoqi@0 | 457 | case DecoderStateTables.EII_AIIS_INDEX_SMALL: |
aoqi@0 | 458 | processEII(_elementNameTable._array[_b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true); |
aoqi@0 | 459 | firstElementHasOccured = true; |
aoqi@0 | 460 | break; |
aoqi@0 | 461 | case DecoderStateTables.EII_INDEX_MEDIUM: |
aoqi@0 | 462 | processEII(decodeEIIIndexMedium(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); |
aoqi@0 | 463 | firstElementHasOccured = true; |
aoqi@0 | 464 | break; |
aoqi@0 | 465 | case DecoderStateTables.EII_INDEX_LARGE: |
aoqi@0 | 466 | processEII(decodeEIIIndexLarge(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); |
aoqi@0 | 467 | firstElementHasOccured = true; |
aoqi@0 | 468 | break; |
aoqi@0 | 469 | case DecoderStateTables.EII_LITERAL: |
aoqi@0 | 470 | { |
aoqi@0 | 471 | final QualifiedName qn = decodeLiteralQualifiedName( |
aoqi@0 | 472 | _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, |
aoqi@0 | 473 | _elementNameTable.getNext()); |
aoqi@0 | 474 | _elementNameTable.add(qn); |
aoqi@0 | 475 | processEII(qn, (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); |
aoqi@0 | 476 | firstElementHasOccured = true; |
aoqi@0 | 477 | break; |
aoqi@0 | 478 | } |
aoqi@0 | 479 | case DecoderStateTables.EII_NAMESPACES: |
aoqi@0 | 480 | processEIIWithNamespaces(); |
aoqi@0 | 481 | firstElementHasOccured = true; |
aoqi@0 | 482 | break; |
aoqi@0 | 483 | case DecoderStateTables.DOCUMENT_TYPE_DECLARATION_II: |
aoqi@0 | 484 | { |
aoqi@0 | 485 | if (documentTypeDeclarationOccured) { |
aoqi@0 | 486 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.secondOccurenceOfDTDII")); |
aoqi@0 | 487 | } |
aoqi@0 | 488 | documentTypeDeclarationOccured = true; |
aoqi@0 | 489 | |
aoqi@0 | 490 | String system_identifier = ((_b & EncodingConstants.DOCUMENT_TYPE_SYSTEM_IDENTIFIER_FLAG) > 0) |
aoqi@0 | 491 | ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; |
aoqi@0 | 492 | String public_identifier = ((_b & EncodingConstants.DOCUMENT_TYPE_PUBLIC_IDENTIFIER_FLAG) > 0) |
aoqi@0 | 493 | ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; |
aoqi@0 | 494 | |
aoqi@0 | 495 | _b = read(); |
aoqi@0 | 496 | while (_b == EncodingConstants.PROCESSING_INSTRUCTION) { |
aoqi@0 | 497 | switch(decodeNonIdentifyingStringOnFirstBit()) { |
aoqi@0 | 498 | case NISTRING_STRING: |
aoqi@0 | 499 | if (_addToTable) { |
aoqi@0 | 500 | _v.otherString.add(new CharArray(_charBuffer, 0, _charBufferLength, true)); |
aoqi@0 | 501 | } |
aoqi@0 | 502 | break; |
aoqi@0 | 503 | case NISTRING_ENCODING_ALGORITHM: |
aoqi@0 | 504 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.processingIIWithEncodingAlgorithm")); |
aoqi@0 | 505 | case NISTRING_INDEX: |
aoqi@0 | 506 | break; |
aoqi@0 | 507 | case NISTRING_EMPTY_STRING: |
aoqi@0 | 508 | break; |
aoqi@0 | 509 | } |
aoqi@0 | 510 | _b = read(); |
aoqi@0 | 511 | } |
aoqi@0 | 512 | if ((_b & EncodingConstants.TERMINATOR) != EncodingConstants.TERMINATOR) { |
aoqi@0 | 513 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.processingInstructionIIsNotTerminatedCorrectly")); |
aoqi@0 | 514 | } |
aoqi@0 | 515 | if (_b == EncodingConstants.DOUBLE_TERMINATOR) { |
aoqi@0 | 516 | _terminate = true; |
aoqi@0 | 517 | } |
aoqi@0 | 518 | |
aoqi@0 | 519 | if (_notations != null) _notations.clear(); |
aoqi@0 | 520 | if (_unparsedEntities != null) _unparsedEntities.clear(); |
aoqi@0 | 521 | /* |
aoqi@0 | 522 | * TODO |
aoqi@0 | 523 | * Report All events associated with DTD, PIs, notations etc |
aoqi@0 | 524 | */ |
aoqi@0 | 525 | break; |
aoqi@0 | 526 | } |
aoqi@0 | 527 | case DecoderStateTables.COMMENT_II: |
aoqi@0 | 528 | processCommentII(); |
aoqi@0 | 529 | break; |
aoqi@0 | 530 | case DecoderStateTables.PROCESSING_INSTRUCTION_II: |
aoqi@0 | 531 | processProcessingII(); |
aoqi@0 | 532 | break; |
aoqi@0 | 533 | case DecoderStateTables.TERMINATOR_DOUBLE: |
aoqi@0 | 534 | _doubleTerminate = true; |
aoqi@0 | 535 | case DecoderStateTables.TERMINATOR_SINGLE: |
aoqi@0 | 536 | _terminate = true; |
aoqi@0 | 537 | break; |
aoqi@0 | 538 | default: |
aoqi@0 | 539 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingDII")); |
aoqi@0 | 540 | } |
aoqi@0 | 541 | } |
aoqi@0 | 542 | |
aoqi@0 | 543 | // Decode any remaining Comment IIs, PI IIs |
aoqi@0 | 544 | while(!_terminate) { |
aoqi@0 | 545 | _b = read(); |
aoqi@0 | 546 | switch(DecoderStateTables.DII(_b)) { |
aoqi@0 | 547 | case DecoderStateTables.COMMENT_II: |
aoqi@0 | 548 | processCommentII(); |
aoqi@0 | 549 | break; |
aoqi@0 | 550 | case DecoderStateTables.PROCESSING_INSTRUCTION_II: |
aoqi@0 | 551 | processProcessingII(); |
aoqi@0 | 552 | break; |
aoqi@0 | 553 | case DecoderStateTables.TERMINATOR_DOUBLE: |
aoqi@0 | 554 | _doubleTerminate = true; |
aoqi@0 | 555 | case DecoderStateTables.TERMINATOR_SINGLE: |
aoqi@0 | 556 | _terminate = true; |
aoqi@0 | 557 | break; |
aoqi@0 | 558 | default: |
aoqi@0 | 559 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingDII")); |
aoqi@0 | 560 | } |
aoqi@0 | 561 | } |
aoqi@0 | 562 | |
aoqi@0 | 563 | try { |
aoqi@0 | 564 | _contentHandler.endDocument(); |
aoqi@0 | 565 | } catch (SAXException e) { |
aoqi@0 | 566 | throw new FastInfosetException("processDII", e); |
aoqi@0 | 567 | } |
aoqi@0 | 568 | } |
aoqi@0 | 569 | |
aoqi@0 | 570 | protected final void processDIIFragment() throws FastInfosetException, IOException { |
aoqi@0 | 571 | try { |
aoqi@0 | 572 | _contentHandler.startDocument(); |
aoqi@0 | 573 | } catch (SAXException e) { |
aoqi@0 | 574 | throw new FastInfosetException("processDII", e); |
aoqi@0 | 575 | } |
aoqi@0 | 576 | |
aoqi@0 | 577 | _b = read(); |
aoqi@0 | 578 | if (_b > 0) { |
aoqi@0 | 579 | processDIIOptionalProperties(); |
aoqi@0 | 580 | } |
aoqi@0 | 581 | |
aoqi@0 | 582 | while(!_terminate) { |
aoqi@0 | 583 | _b = read(); |
aoqi@0 | 584 | switch(DecoderStateTables.EII(_b)) { |
aoqi@0 | 585 | case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: |
aoqi@0 | 586 | processEII(_elementNameTable._array[_b], false); |
aoqi@0 | 587 | break; |
aoqi@0 | 588 | case DecoderStateTables.EII_AIIS_INDEX_SMALL: |
aoqi@0 | 589 | processEII(_elementNameTable._array[_b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true); |
aoqi@0 | 590 | break; |
aoqi@0 | 591 | case DecoderStateTables.EII_INDEX_MEDIUM: |
aoqi@0 | 592 | processEII(decodeEIIIndexMedium(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); |
aoqi@0 | 593 | break; |
aoqi@0 | 594 | case DecoderStateTables.EII_INDEX_LARGE: |
aoqi@0 | 595 | processEII(decodeEIIIndexLarge(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); |
aoqi@0 | 596 | break; |
aoqi@0 | 597 | case DecoderStateTables.EII_LITERAL: |
aoqi@0 | 598 | { |
aoqi@0 | 599 | final QualifiedName qn = decodeLiteralQualifiedName( |
aoqi@0 | 600 | _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, |
aoqi@0 | 601 | _elementNameTable.getNext()); |
aoqi@0 | 602 | _elementNameTable.add(qn); |
aoqi@0 | 603 | processEII(qn, (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); |
aoqi@0 | 604 | break; |
aoqi@0 | 605 | } |
aoqi@0 | 606 | case DecoderStateTables.EII_NAMESPACES: |
aoqi@0 | 607 | processEIIWithNamespaces(); |
aoqi@0 | 608 | break; |
aoqi@0 | 609 | case DecoderStateTables.CII_UTF8_SMALL_LENGTH: |
aoqi@0 | 610 | _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) |
aoqi@0 | 611 | + 1; |
aoqi@0 | 612 | processUtf8CharacterString(); |
aoqi@0 | 613 | break; |
aoqi@0 | 614 | case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH: |
aoqi@0 | 615 | _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; |
aoqi@0 | 616 | processUtf8CharacterString(); |
aoqi@0 | 617 | break; |
aoqi@0 | 618 | case DecoderStateTables.CII_UTF8_LARGE_LENGTH: |
aoqi@0 | 619 | _octetBufferLength = ((read() << 24) | |
aoqi@0 | 620 | (read() << 16) | |
aoqi@0 | 621 | (read() << 8) | |
aoqi@0 | 622 | read()) |
aoqi@0 | 623 | + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; |
aoqi@0 | 624 | processUtf8CharacterString(); |
aoqi@0 | 625 | break; |
aoqi@0 | 626 | case DecoderStateTables.CII_UTF16_SMALL_LENGTH: |
aoqi@0 | 627 | _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) |
aoqi@0 | 628 | + 1; |
aoqi@0 | 629 | decodeUtf16StringAsCharBuffer(); |
aoqi@0 | 630 | if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 631 | _characterContentChunkTable.add(_charBuffer, _charBufferLength); |
aoqi@0 | 632 | } |
aoqi@0 | 633 | |
aoqi@0 | 634 | try { |
aoqi@0 | 635 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 636 | } catch (SAXException e) { |
aoqi@0 | 637 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 638 | } |
aoqi@0 | 639 | break; |
aoqi@0 | 640 | case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH: |
aoqi@0 | 641 | _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; |
aoqi@0 | 642 | decodeUtf16StringAsCharBuffer(); |
aoqi@0 | 643 | if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 644 | _characterContentChunkTable.add(_charBuffer, _charBufferLength); |
aoqi@0 | 645 | } |
aoqi@0 | 646 | |
aoqi@0 | 647 | try { |
aoqi@0 | 648 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 649 | } catch (SAXException e) { |
aoqi@0 | 650 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 651 | } |
aoqi@0 | 652 | break; |
aoqi@0 | 653 | case DecoderStateTables.CII_UTF16_LARGE_LENGTH: |
aoqi@0 | 654 | _octetBufferLength = ((read() << 24) | |
aoqi@0 | 655 | (read() << 16) | |
aoqi@0 | 656 | (read() << 8) | |
aoqi@0 | 657 | read()) |
aoqi@0 | 658 | + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; |
aoqi@0 | 659 | decodeUtf16StringAsCharBuffer(); |
aoqi@0 | 660 | if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 661 | _characterContentChunkTable.add(_charBuffer, _charBufferLength); |
aoqi@0 | 662 | } |
aoqi@0 | 663 | |
aoqi@0 | 664 | try { |
aoqi@0 | 665 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 666 | } catch (SAXException e) { |
aoqi@0 | 667 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 668 | } |
aoqi@0 | 669 | break; |
aoqi@0 | 670 | case DecoderStateTables.CII_RA: |
aoqi@0 | 671 | { |
aoqi@0 | 672 | final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0; |
aoqi@0 | 673 | |
aoqi@0 | 674 | // Decode resitricted alphabet integer |
aoqi@0 | 675 | _identifier = (_b & 0x02) << 6; |
aoqi@0 | 676 | _b = read(); |
aoqi@0 | 677 | _identifier |= (_b & 0xFC) >> 2; |
aoqi@0 | 678 | |
aoqi@0 | 679 | decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b); |
aoqi@0 | 680 | |
aoqi@0 | 681 | decodeRestrictedAlphabetAsCharBuffer(); |
aoqi@0 | 682 | |
aoqi@0 | 683 | if (addToTable) { |
aoqi@0 | 684 | _characterContentChunkTable.add(_charBuffer, _charBufferLength); |
aoqi@0 | 685 | } |
aoqi@0 | 686 | |
aoqi@0 | 687 | try { |
aoqi@0 | 688 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 689 | } catch (SAXException e) { |
aoqi@0 | 690 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 691 | } |
aoqi@0 | 692 | break; |
aoqi@0 | 693 | } |
aoqi@0 | 694 | case DecoderStateTables.CII_EA: |
aoqi@0 | 695 | { |
aoqi@0 | 696 | final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0; |
aoqi@0 | 697 | |
aoqi@0 | 698 | // Decode encoding algorithm integer |
aoqi@0 | 699 | _identifier = (_b & 0x02) << 6; |
aoqi@0 | 700 | _b = read(); |
aoqi@0 | 701 | _identifier |= (_b & 0xFC) >> 2; |
aoqi@0 | 702 | |
aoqi@0 | 703 | decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b); |
aoqi@0 | 704 | |
aoqi@0 | 705 | processCIIEncodingAlgorithm(addToTable); |
aoqi@0 | 706 | break; |
aoqi@0 | 707 | } |
aoqi@0 | 708 | case DecoderStateTables.CII_INDEX_SMALL: |
aoqi@0 | 709 | { |
aoqi@0 | 710 | final int index = _b & EncodingConstants.INTEGER_4TH_BIT_SMALL_MASK; |
aoqi@0 | 711 | try { |
aoqi@0 | 712 | _contentHandler.characters(_characterContentChunkTable._array, |
aoqi@0 | 713 | _characterContentChunkTable._offset[index], |
aoqi@0 | 714 | _characterContentChunkTable._length[index]); |
aoqi@0 | 715 | } catch (SAXException e) { |
aoqi@0 | 716 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 717 | } |
aoqi@0 | 718 | break; |
aoqi@0 | 719 | } |
aoqi@0 | 720 | case DecoderStateTables.CII_INDEX_MEDIUM: |
aoqi@0 | 721 | { |
aoqi@0 | 722 | final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_MEDIUM_MASK) << 8) | read()) |
aoqi@0 | 723 | + EncodingConstants.INTEGER_4TH_BIT_SMALL_LIMIT; |
aoqi@0 | 724 | try { |
aoqi@0 | 725 | _contentHandler.characters(_characterContentChunkTable._array, |
aoqi@0 | 726 | _characterContentChunkTable._offset[index], |
aoqi@0 | 727 | _characterContentChunkTable._length[index]); |
aoqi@0 | 728 | } catch (SAXException e) { |
aoqi@0 | 729 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 730 | } |
aoqi@0 | 731 | break; |
aoqi@0 | 732 | } |
aoqi@0 | 733 | case DecoderStateTables.CII_INDEX_LARGE: |
aoqi@0 | 734 | { |
aoqi@0 | 735 | final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_LARGE_MASK) << 16) | |
aoqi@0 | 736 | (read() << 8) | |
aoqi@0 | 737 | read()) |
aoqi@0 | 738 | + EncodingConstants.INTEGER_4TH_BIT_MEDIUM_LIMIT; |
aoqi@0 | 739 | |
aoqi@0 | 740 | try { |
aoqi@0 | 741 | _contentHandler.characters(_characterContentChunkTable._array, |
aoqi@0 | 742 | _characterContentChunkTable._offset[index], |
aoqi@0 | 743 | _characterContentChunkTable._length[index]); |
aoqi@0 | 744 | } catch (SAXException e) { |
aoqi@0 | 745 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 746 | } |
aoqi@0 | 747 | break; |
aoqi@0 | 748 | } |
aoqi@0 | 749 | case DecoderStateTables.CII_INDEX_LARGE_LARGE: |
aoqi@0 | 750 | { |
aoqi@0 | 751 | final int index = ((read() << 16) | |
aoqi@0 | 752 | (read() << 8) | |
aoqi@0 | 753 | read()) |
aoqi@0 | 754 | + EncodingConstants.INTEGER_4TH_BIT_LARGE_LIMIT; |
aoqi@0 | 755 | |
aoqi@0 | 756 | try { |
aoqi@0 | 757 | _contentHandler.characters(_characterContentChunkTable._array, |
aoqi@0 | 758 | _characterContentChunkTable._offset[index], |
aoqi@0 | 759 | _characterContentChunkTable._length[index]); |
aoqi@0 | 760 | } catch (SAXException e) { |
aoqi@0 | 761 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 762 | } |
aoqi@0 | 763 | break; |
aoqi@0 | 764 | } |
aoqi@0 | 765 | case DecoderStateTables.COMMENT_II: |
aoqi@0 | 766 | processCommentII(); |
aoqi@0 | 767 | break; |
aoqi@0 | 768 | case DecoderStateTables.PROCESSING_INSTRUCTION_II: |
aoqi@0 | 769 | processProcessingII(); |
aoqi@0 | 770 | break; |
aoqi@0 | 771 | case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II: |
aoqi@0 | 772 | { |
aoqi@0 | 773 | String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName); |
aoqi@0 | 774 | |
aoqi@0 | 775 | String system_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0) |
aoqi@0 | 776 | ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; |
aoqi@0 | 777 | String public_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0) |
aoqi@0 | 778 | ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; |
aoqi@0 | 779 | |
aoqi@0 | 780 | try { |
aoqi@0 | 781 | /* |
aoqi@0 | 782 | * TODO |
aoqi@0 | 783 | * Need to verify if the skippedEntity method: |
aoqi@0 | 784 | * http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/ContentHandler.html#skippedEntity(java.lang.String) |
aoqi@0 | 785 | * is the correct method to call. It appears so but a more extensive |
aoqi@0 | 786 | * check is necessary. |
aoqi@0 | 787 | */ |
aoqi@0 | 788 | _contentHandler.skippedEntity(entity_reference_name); |
aoqi@0 | 789 | } catch (SAXException e) { |
aoqi@0 | 790 | throw new FastInfosetException("processUnexpandedEntityReferenceII", e); |
aoqi@0 | 791 | } |
aoqi@0 | 792 | break; |
aoqi@0 | 793 | } |
aoqi@0 | 794 | case DecoderStateTables.TERMINATOR_DOUBLE: |
aoqi@0 | 795 | _doubleTerminate = true; |
aoqi@0 | 796 | case DecoderStateTables.TERMINATOR_SINGLE: |
aoqi@0 | 797 | _terminate = true; |
aoqi@0 | 798 | break; |
aoqi@0 | 799 | default: |
aoqi@0 | 800 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEII")); |
aoqi@0 | 801 | } |
aoqi@0 | 802 | } |
aoqi@0 | 803 | |
aoqi@0 | 804 | try { |
aoqi@0 | 805 | _contentHandler.endDocument(); |
aoqi@0 | 806 | } catch (SAXException e) { |
aoqi@0 | 807 | throw new FastInfosetException("processDII", e); |
aoqi@0 | 808 | } |
aoqi@0 | 809 | } |
aoqi@0 | 810 | |
aoqi@0 | 811 | protected final void processDIIOptionalProperties() throws FastInfosetException, IOException { |
aoqi@0 | 812 | // Optimize for the most common case |
aoqi@0 | 813 | if (_b == EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) { |
aoqi@0 | 814 | decodeInitialVocabulary(); |
aoqi@0 | 815 | return; |
aoqi@0 | 816 | } |
aoqi@0 | 817 | |
aoqi@0 | 818 | if ((_b & EncodingConstants.DOCUMENT_ADDITIONAL_DATA_FLAG) > 0) { |
aoqi@0 | 819 | decodeAdditionalData(); |
aoqi@0 | 820 | /* |
aoqi@0 | 821 | * TODO |
aoqi@0 | 822 | * how to report the additional data? |
aoqi@0 | 823 | */ |
aoqi@0 | 824 | } |
aoqi@0 | 825 | |
aoqi@0 | 826 | if ((_b & EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) > 0) { |
aoqi@0 | 827 | decodeInitialVocabulary(); |
aoqi@0 | 828 | } |
aoqi@0 | 829 | |
aoqi@0 | 830 | if ((_b & EncodingConstants.DOCUMENT_NOTATIONS_FLAG) > 0) { |
aoqi@0 | 831 | decodeNotations(); |
aoqi@0 | 832 | /* |
aoqi@0 | 833 | try { |
aoqi@0 | 834 | _dtdHandler.notationDecl(name, public_identifier, system_identifier); |
aoqi@0 | 835 | } catch (SAXException e) { |
aoqi@0 | 836 | throw new IOException("NotationsDeclarationII"); |
aoqi@0 | 837 | } |
aoqi@0 | 838 | */ |
aoqi@0 | 839 | } |
aoqi@0 | 840 | |
aoqi@0 | 841 | if ((_b & EncodingConstants.DOCUMENT_UNPARSED_ENTITIES_FLAG) > 0) { |
aoqi@0 | 842 | decodeUnparsedEntities(); |
aoqi@0 | 843 | /* |
aoqi@0 | 844 | try { |
aoqi@0 | 845 | _dtdHandler.unparsedEntityDecl(name, public_identifier, system_identifier, notation_name); |
aoqi@0 | 846 | } catch (SAXException e) { |
aoqi@0 | 847 | throw new IOException("UnparsedEntitiesII"); |
aoqi@0 | 848 | } |
aoqi@0 | 849 | */ |
aoqi@0 | 850 | } |
aoqi@0 | 851 | |
aoqi@0 | 852 | if ((_b & EncodingConstants.DOCUMENT_CHARACTER_ENCODING_SCHEME) > 0) { |
aoqi@0 | 853 | /*String characterEncodingScheme = */decodeCharacterEncodingScheme(); |
aoqi@0 | 854 | /* |
aoqi@0 | 855 | * TODO |
aoqi@0 | 856 | * how to report the character encoding scheme? |
aoqi@0 | 857 | */ |
aoqi@0 | 858 | } |
aoqi@0 | 859 | |
aoqi@0 | 860 | if ((_b & EncodingConstants.DOCUMENT_STANDALONE_FLAG) > 0) { |
aoqi@0 | 861 | /*boolean standalone = (*/read()/* > 0) ? true : false*/ ; |
aoqi@0 | 862 | /* |
aoqi@0 | 863 | * TODO |
aoqi@0 | 864 | * how to report the standalone flag? |
aoqi@0 | 865 | */ |
aoqi@0 | 866 | } |
aoqi@0 | 867 | |
aoqi@0 | 868 | if ((_b & EncodingConstants.DOCUMENT_VERSION_FLAG) > 0) { |
aoqi@0 | 869 | decodeVersion(); |
aoqi@0 | 870 | /* |
aoqi@0 | 871 | * TODO |
aoqi@0 | 872 | * how to report the standalone flag? |
aoqi@0 | 873 | */ |
aoqi@0 | 874 | } |
aoqi@0 | 875 | } |
aoqi@0 | 876 | |
aoqi@0 | 877 | protected final void processEII(QualifiedName name, boolean hasAttributes) throws FastInfosetException, IOException { |
aoqi@0 | 878 | if (_prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) { |
aoqi@0 | 879 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qNameOfEIINotInScope")); |
aoqi@0 | 880 | } |
aoqi@0 | 881 | |
aoqi@0 | 882 | if (hasAttributes) { |
aoqi@0 | 883 | processAIIs(); |
aoqi@0 | 884 | } |
aoqi@0 | 885 | |
aoqi@0 | 886 | try { |
aoqi@0 | 887 | _contentHandler.startElement(name.namespaceName, name.localName, name.qName, _attributes); |
aoqi@0 | 888 | } catch (SAXException e) { |
aoqi@0 | 889 | logger.log(Level.FINE, "processEII error", e); |
aoqi@0 | 890 | throw new FastInfosetException("processEII", e); |
aoqi@0 | 891 | } |
aoqi@0 | 892 | |
aoqi@0 | 893 | if (_clearAttributes) { |
aoqi@0 | 894 | _attributes.clear(); |
aoqi@0 | 895 | _clearAttributes = false; |
aoqi@0 | 896 | } |
aoqi@0 | 897 | |
aoqi@0 | 898 | while(!_terminate) { |
aoqi@0 | 899 | _b = read(); |
aoqi@0 | 900 | switch(DecoderStateTables.EII(_b)) { |
aoqi@0 | 901 | case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: |
aoqi@0 | 902 | processEII(_elementNameTable._array[_b], false); |
aoqi@0 | 903 | break; |
aoqi@0 | 904 | case DecoderStateTables.EII_AIIS_INDEX_SMALL: |
aoqi@0 | 905 | processEII(_elementNameTable._array[_b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true); |
aoqi@0 | 906 | break; |
aoqi@0 | 907 | case DecoderStateTables.EII_INDEX_MEDIUM: |
aoqi@0 | 908 | processEII(decodeEIIIndexMedium(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); |
aoqi@0 | 909 | break; |
aoqi@0 | 910 | case DecoderStateTables.EII_INDEX_LARGE: |
aoqi@0 | 911 | processEII(decodeEIIIndexLarge(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); |
aoqi@0 | 912 | break; |
aoqi@0 | 913 | case DecoderStateTables.EII_LITERAL: |
aoqi@0 | 914 | { |
aoqi@0 | 915 | final QualifiedName qn = decodeLiteralQualifiedName( |
aoqi@0 | 916 | _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, |
aoqi@0 | 917 | _elementNameTable.getNext()); |
aoqi@0 | 918 | _elementNameTable.add(qn); |
aoqi@0 | 919 | processEII(qn, (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); |
aoqi@0 | 920 | break; |
aoqi@0 | 921 | } |
aoqi@0 | 922 | case DecoderStateTables.EII_NAMESPACES: |
aoqi@0 | 923 | processEIIWithNamespaces(); |
aoqi@0 | 924 | break; |
aoqi@0 | 925 | case DecoderStateTables.CII_UTF8_SMALL_LENGTH: |
aoqi@0 | 926 | _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) |
aoqi@0 | 927 | + 1; |
aoqi@0 | 928 | processUtf8CharacterString(); |
aoqi@0 | 929 | break; |
aoqi@0 | 930 | case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH: |
aoqi@0 | 931 | _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; |
aoqi@0 | 932 | processUtf8CharacterString(); |
aoqi@0 | 933 | break; |
aoqi@0 | 934 | case DecoderStateTables.CII_UTF8_LARGE_LENGTH: |
aoqi@0 | 935 | _octetBufferLength = ((read() << 24) | |
aoqi@0 | 936 | (read() << 16) | |
aoqi@0 | 937 | (read() << 8) | |
aoqi@0 | 938 | read()) |
aoqi@0 | 939 | + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; |
aoqi@0 | 940 | processUtf8CharacterString(); |
aoqi@0 | 941 | break; |
aoqi@0 | 942 | case DecoderStateTables.CII_UTF16_SMALL_LENGTH: |
aoqi@0 | 943 | _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) |
aoqi@0 | 944 | + 1; |
aoqi@0 | 945 | decodeUtf16StringAsCharBuffer(); |
aoqi@0 | 946 | if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 947 | _characterContentChunkTable.add(_charBuffer, _charBufferLength); |
aoqi@0 | 948 | } |
aoqi@0 | 949 | |
aoqi@0 | 950 | try { |
aoqi@0 | 951 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 952 | } catch (SAXException e) { |
aoqi@0 | 953 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 954 | } |
aoqi@0 | 955 | break; |
aoqi@0 | 956 | case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH: |
aoqi@0 | 957 | _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; |
aoqi@0 | 958 | decodeUtf16StringAsCharBuffer(); |
aoqi@0 | 959 | if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 960 | _characterContentChunkTable.add(_charBuffer, _charBufferLength); |
aoqi@0 | 961 | } |
aoqi@0 | 962 | |
aoqi@0 | 963 | try { |
aoqi@0 | 964 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 965 | } catch (SAXException e) { |
aoqi@0 | 966 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 967 | } |
aoqi@0 | 968 | break; |
aoqi@0 | 969 | case DecoderStateTables.CII_UTF16_LARGE_LENGTH: |
aoqi@0 | 970 | _octetBufferLength = ((read() << 24) | |
aoqi@0 | 971 | (read() << 16) | |
aoqi@0 | 972 | (read() << 8) | |
aoqi@0 | 973 | read()) |
aoqi@0 | 974 | + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; |
aoqi@0 | 975 | decodeUtf16StringAsCharBuffer(); |
aoqi@0 | 976 | if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 977 | _characterContentChunkTable.add(_charBuffer, _charBufferLength); |
aoqi@0 | 978 | } |
aoqi@0 | 979 | |
aoqi@0 | 980 | try { |
aoqi@0 | 981 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 982 | } catch (SAXException e) { |
aoqi@0 | 983 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 984 | } |
aoqi@0 | 985 | break; |
aoqi@0 | 986 | case DecoderStateTables.CII_RA: |
aoqi@0 | 987 | { |
aoqi@0 | 988 | final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0; |
aoqi@0 | 989 | |
aoqi@0 | 990 | // Decode resitricted alphabet integer |
aoqi@0 | 991 | _identifier = (_b & 0x02) << 6; |
aoqi@0 | 992 | _b = read(); |
aoqi@0 | 993 | _identifier |= (_b & 0xFC) >> 2; |
aoqi@0 | 994 | |
aoqi@0 | 995 | decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b); |
aoqi@0 | 996 | |
aoqi@0 | 997 | decodeRestrictedAlphabetAsCharBuffer(); |
aoqi@0 | 998 | |
aoqi@0 | 999 | if (addToTable) { |
aoqi@0 | 1000 | _characterContentChunkTable.add(_charBuffer, _charBufferLength); |
aoqi@0 | 1001 | } |
aoqi@0 | 1002 | |
aoqi@0 | 1003 | try { |
aoqi@0 | 1004 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 1005 | } catch (SAXException e) { |
aoqi@0 | 1006 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 1007 | } |
aoqi@0 | 1008 | break; |
aoqi@0 | 1009 | } |
aoqi@0 | 1010 | case DecoderStateTables.CII_EA: |
aoqi@0 | 1011 | { |
aoqi@0 | 1012 | final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0; |
aoqi@0 | 1013 | // Decode encoding algorithm integer |
aoqi@0 | 1014 | _identifier = (_b & 0x02) << 6; |
aoqi@0 | 1015 | _b = read(); |
aoqi@0 | 1016 | _identifier |= (_b & 0xFC) >> 2; |
aoqi@0 | 1017 | |
aoqi@0 | 1018 | decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b); |
aoqi@0 | 1019 | |
aoqi@0 | 1020 | processCIIEncodingAlgorithm(addToTable); |
aoqi@0 | 1021 | break; |
aoqi@0 | 1022 | } |
aoqi@0 | 1023 | case DecoderStateTables.CII_INDEX_SMALL: |
aoqi@0 | 1024 | { |
aoqi@0 | 1025 | final int index = _b & EncodingConstants.INTEGER_4TH_BIT_SMALL_MASK; |
aoqi@0 | 1026 | try { |
aoqi@0 | 1027 | _contentHandler.characters(_characterContentChunkTable._array, |
aoqi@0 | 1028 | _characterContentChunkTable._offset[index], |
aoqi@0 | 1029 | _characterContentChunkTable._length[index]); |
aoqi@0 | 1030 | } catch (SAXException e) { |
aoqi@0 | 1031 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 1032 | } |
aoqi@0 | 1033 | break; |
aoqi@0 | 1034 | } |
aoqi@0 | 1035 | case DecoderStateTables.CII_INDEX_MEDIUM: |
aoqi@0 | 1036 | { |
aoqi@0 | 1037 | final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_MEDIUM_MASK) << 8) | read()) |
aoqi@0 | 1038 | + EncodingConstants.INTEGER_4TH_BIT_SMALL_LIMIT; |
aoqi@0 | 1039 | try { |
aoqi@0 | 1040 | _contentHandler.characters(_characterContentChunkTable._array, |
aoqi@0 | 1041 | _characterContentChunkTable._offset[index], |
aoqi@0 | 1042 | _characterContentChunkTable._length[index]); |
aoqi@0 | 1043 | } catch (SAXException e) { |
aoqi@0 | 1044 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 1045 | } |
aoqi@0 | 1046 | break; |
aoqi@0 | 1047 | } |
aoqi@0 | 1048 | case DecoderStateTables.CII_INDEX_LARGE: |
aoqi@0 | 1049 | { |
aoqi@0 | 1050 | final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_LARGE_MASK) << 16) | |
aoqi@0 | 1051 | (read() << 8) | |
aoqi@0 | 1052 | read()) |
aoqi@0 | 1053 | + EncodingConstants.INTEGER_4TH_BIT_MEDIUM_LIMIT; |
aoqi@0 | 1054 | |
aoqi@0 | 1055 | try { |
aoqi@0 | 1056 | _contentHandler.characters(_characterContentChunkTable._array, |
aoqi@0 | 1057 | _characterContentChunkTable._offset[index], |
aoqi@0 | 1058 | _characterContentChunkTable._length[index]); |
aoqi@0 | 1059 | } catch (SAXException e) { |
aoqi@0 | 1060 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 1061 | } |
aoqi@0 | 1062 | break; |
aoqi@0 | 1063 | } |
aoqi@0 | 1064 | case DecoderStateTables.CII_INDEX_LARGE_LARGE: |
aoqi@0 | 1065 | { |
aoqi@0 | 1066 | final int index = ((read() << 16) | |
aoqi@0 | 1067 | (read() << 8) | |
aoqi@0 | 1068 | read()) |
aoqi@0 | 1069 | + EncodingConstants.INTEGER_4TH_BIT_LARGE_LIMIT; |
aoqi@0 | 1070 | |
aoqi@0 | 1071 | try { |
aoqi@0 | 1072 | _contentHandler.characters(_characterContentChunkTable._array, |
aoqi@0 | 1073 | _characterContentChunkTable._offset[index], |
aoqi@0 | 1074 | _characterContentChunkTable._length[index]); |
aoqi@0 | 1075 | } catch (SAXException e) { |
aoqi@0 | 1076 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 1077 | } |
aoqi@0 | 1078 | break; |
aoqi@0 | 1079 | } |
aoqi@0 | 1080 | case DecoderStateTables.COMMENT_II: |
aoqi@0 | 1081 | processCommentII(); |
aoqi@0 | 1082 | break; |
aoqi@0 | 1083 | case DecoderStateTables.PROCESSING_INSTRUCTION_II: |
aoqi@0 | 1084 | processProcessingII(); |
aoqi@0 | 1085 | break; |
aoqi@0 | 1086 | case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II: |
aoqi@0 | 1087 | { |
aoqi@0 | 1088 | String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName); |
aoqi@0 | 1089 | |
aoqi@0 | 1090 | String system_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0) |
aoqi@0 | 1091 | ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; |
aoqi@0 | 1092 | String public_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0) |
aoqi@0 | 1093 | ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; |
aoqi@0 | 1094 | |
aoqi@0 | 1095 | try { |
aoqi@0 | 1096 | /* |
aoqi@0 | 1097 | * TODO |
aoqi@0 | 1098 | * Need to verify if the skippedEntity method: |
aoqi@0 | 1099 | * http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/ContentHandler.html#skippedEntity(java.lang.String) |
aoqi@0 | 1100 | * is the correct method to call. It appears so but a more extensive |
aoqi@0 | 1101 | * check is necessary. |
aoqi@0 | 1102 | */ |
aoqi@0 | 1103 | _contentHandler.skippedEntity(entity_reference_name); |
aoqi@0 | 1104 | } catch (SAXException e) { |
aoqi@0 | 1105 | throw new FastInfosetException("processUnexpandedEntityReferenceII", e); |
aoqi@0 | 1106 | } |
aoqi@0 | 1107 | break; |
aoqi@0 | 1108 | } |
aoqi@0 | 1109 | case DecoderStateTables.TERMINATOR_DOUBLE: |
aoqi@0 | 1110 | _doubleTerminate = true; |
aoqi@0 | 1111 | case DecoderStateTables.TERMINATOR_SINGLE: |
aoqi@0 | 1112 | _terminate = true; |
aoqi@0 | 1113 | break; |
aoqi@0 | 1114 | default: |
aoqi@0 | 1115 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEII")); |
aoqi@0 | 1116 | } |
aoqi@0 | 1117 | } |
aoqi@0 | 1118 | |
aoqi@0 | 1119 | _terminate = _doubleTerminate; |
aoqi@0 | 1120 | _doubleTerminate = false; |
aoqi@0 | 1121 | |
aoqi@0 | 1122 | try { |
aoqi@0 | 1123 | _contentHandler.endElement(name.namespaceName, name.localName, name.qName); |
aoqi@0 | 1124 | } catch (SAXException e) { |
aoqi@0 | 1125 | throw new FastInfosetException("processEII", e); |
aoqi@0 | 1126 | } |
aoqi@0 | 1127 | } |
aoqi@0 | 1128 | |
aoqi@0 | 1129 | private final void processUtf8CharacterString() throws FastInfosetException, IOException { |
aoqi@0 | 1130 | if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 1131 | _characterContentChunkTable.ensureSize(_octetBufferLength); |
aoqi@0 | 1132 | final int charactersOffset = _characterContentChunkTable._arrayIndex; |
aoqi@0 | 1133 | decodeUtf8StringAsCharBuffer(_characterContentChunkTable._array, charactersOffset); |
aoqi@0 | 1134 | _characterContentChunkTable.add(_charBufferLength); |
aoqi@0 | 1135 | try { |
aoqi@0 | 1136 | _contentHandler.characters(_characterContentChunkTable._array, charactersOffset, _charBufferLength); |
aoqi@0 | 1137 | } catch (SAXException e) { |
aoqi@0 | 1138 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 1139 | } |
aoqi@0 | 1140 | } else { |
aoqi@0 | 1141 | decodeUtf8StringAsCharBuffer(); |
aoqi@0 | 1142 | try { |
aoqi@0 | 1143 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 1144 | } catch (SAXException e) { |
aoqi@0 | 1145 | throw new FastInfosetException("processCII", e); |
aoqi@0 | 1146 | } |
aoqi@0 | 1147 | } |
aoqi@0 | 1148 | } |
aoqi@0 | 1149 | |
aoqi@0 | 1150 | protected final void processEIIWithNamespaces() throws FastInfosetException, IOException { |
aoqi@0 | 1151 | final boolean hasAttributes = (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0; |
aoqi@0 | 1152 | |
aoqi@0 | 1153 | _clearAttributes = (_namespacePrefixesFeature) ? true : false; |
aoqi@0 | 1154 | |
aoqi@0 | 1155 | if (++_prefixTable._declarationId == Integer.MAX_VALUE) { |
aoqi@0 | 1156 | _prefixTable.clearDeclarationIds(); |
aoqi@0 | 1157 | } |
aoqi@0 | 1158 | |
aoqi@0 | 1159 | String prefix = "", namespaceName = ""; |
aoqi@0 | 1160 | final int start = _namespacePrefixesIndex; |
aoqi@0 | 1161 | int b = read(); |
aoqi@0 | 1162 | while ((b & EncodingConstants.NAMESPACE_ATTRIBUTE_MASK) == EncodingConstants.NAMESPACE_ATTRIBUTE) { |
aoqi@0 | 1163 | if (_namespacePrefixesIndex == _namespacePrefixes.length) { |
aoqi@0 | 1164 | final int[] namespaceAIIs = new int[_namespacePrefixesIndex * 3 / 2 + 1]; |
aoqi@0 | 1165 | System.arraycopy(_namespacePrefixes, 0, namespaceAIIs, 0, _namespacePrefixesIndex); |
aoqi@0 | 1166 | _namespacePrefixes = namespaceAIIs; |
aoqi@0 | 1167 | } |
aoqi@0 | 1168 | |
aoqi@0 | 1169 | switch (b & EncodingConstants.NAMESPACE_ATTRIBUTE_PREFIX_NAME_MASK) { |
aoqi@0 | 1170 | // no prefix, no namespace |
aoqi@0 | 1171 | // Undeclaration of default namespace |
aoqi@0 | 1172 | case 0: |
aoqi@0 | 1173 | prefix = namespaceName = ""; |
aoqi@0 | 1174 | _namespaceNameIndex = _prefixIndex = _namespacePrefixes[_namespacePrefixesIndex++] = -1; |
aoqi@0 | 1175 | break; |
aoqi@0 | 1176 | // no prefix, namespace |
aoqi@0 | 1177 | // Declaration of default namespace |
aoqi@0 | 1178 | case 1: |
aoqi@0 | 1179 | prefix = ""; |
aoqi@0 | 1180 | namespaceName = decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(false); |
aoqi@0 | 1181 | |
aoqi@0 | 1182 | _prefixIndex = _namespacePrefixes[_namespacePrefixesIndex++] = -1; |
aoqi@0 | 1183 | break; |
aoqi@0 | 1184 | // prefix, no namespace |
aoqi@0 | 1185 | // Undeclaration of namespace |
aoqi@0 | 1186 | case 2: |
aoqi@0 | 1187 | prefix = decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(false); |
aoqi@0 | 1188 | namespaceName = ""; |
aoqi@0 | 1189 | |
aoqi@0 | 1190 | _namespaceNameIndex = -1; |
aoqi@0 | 1191 | _namespacePrefixes[_namespacePrefixesIndex++] = _prefixIndex; |
aoqi@0 | 1192 | break; |
aoqi@0 | 1193 | // prefix, namespace |
aoqi@0 | 1194 | // Declaration of prefixed namespace |
aoqi@0 | 1195 | case 3: |
aoqi@0 | 1196 | prefix = decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(true); |
aoqi@0 | 1197 | namespaceName = decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(true); |
aoqi@0 | 1198 | |
aoqi@0 | 1199 | _namespacePrefixes[_namespacePrefixesIndex++] = _prefixIndex; |
aoqi@0 | 1200 | break; |
aoqi@0 | 1201 | } |
aoqi@0 | 1202 | |
aoqi@0 | 1203 | _prefixTable.pushScope(_prefixIndex, _namespaceNameIndex); |
aoqi@0 | 1204 | |
aoqi@0 | 1205 | if (_namespacePrefixesFeature) { |
aoqi@0 | 1206 | // Add the namespace delcaration as an attribute |
aoqi@0 | 1207 | if (prefix != "") { |
aoqi@0 | 1208 | _attributes.addAttribute(new QualifiedName( |
aoqi@0 | 1209 | EncodingConstants.XMLNS_NAMESPACE_PREFIX, |
aoqi@0 | 1210 | EncodingConstants.XMLNS_NAMESPACE_NAME, |
aoqi@0 | 1211 | prefix), |
aoqi@0 | 1212 | namespaceName); |
aoqi@0 | 1213 | } else { |
aoqi@0 | 1214 | _attributes.addAttribute(EncodingConstants.DEFAULT_NAMESPACE_DECLARATION, |
aoqi@0 | 1215 | namespaceName); |
aoqi@0 | 1216 | } |
aoqi@0 | 1217 | } |
aoqi@0 | 1218 | |
aoqi@0 | 1219 | try { |
aoqi@0 | 1220 | _contentHandler.startPrefixMapping(prefix, namespaceName); |
aoqi@0 | 1221 | } catch (SAXException e) { |
aoqi@0 | 1222 | throw new IOException("processStartNamespaceAII"); |
aoqi@0 | 1223 | } |
aoqi@0 | 1224 | |
aoqi@0 | 1225 | b = read(); |
aoqi@0 | 1226 | } |
aoqi@0 | 1227 | if (b != EncodingConstants.TERMINATOR) { |
aoqi@0 | 1228 | throw new IOException(CommonResourceBundle.getInstance().getString("message.EIInamespaceNameNotTerminatedCorrectly")); |
aoqi@0 | 1229 | } |
aoqi@0 | 1230 | final int end = _namespacePrefixesIndex; |
aoqi@0 | 1231 | |
aoqi@0 | 1232 | _b = read(); |
aoqi@0 | 1233 | switch(DecoderStateTables.EII(_b)) { |
aoqi@0 | 1234 | case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: |
aoqi@0 | 1235 | processEII(_elementNameTable._array[_b], hasAttributes); |
aoqi@0 | 1236 | break; |
aoqi@0 | 1237 | case DecoderStateTables.EII_INDEX_MEDIUM: |
aoqi@0 | 1238 | processEII(decodeEIIIndexMedium(), hasAttributes); |
aoqi@0 | 1239 | break; |
aoqi@0 | 1240 | case DecoderStateTables.EII_INDEX_LARGE: |
aoqi@0 | 1241 | processEII(decodeEIIIndexLarge(), hasAttributes); |
aoqi@0 | 1242 | break; |
aoqi@0 | 1243 | case DecoderStateTables.EII_LITERAL: |
aoqi@0 | 1244 | { |
aoqi@0 | 1245 | final QualifiedName qn = decodeLiteralQualifiedName( |
aoqi@0 | 1246 | _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, |
aoqi@0 | 1247 | _elementNameTable.getNext()); |
aoqi@0 | 1248 | _elementNameTable.add(qn); |
aoqi@0 | 1249 | processEII(qn, hasAttributes); |
aoqi@0 | 1250 | break; |
aoqi@0 | 1251 | } |
aoqi@0 | 1252 | default: |
aoqi@0 | 1253 | throw new IOException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEIIAfterAIIs")); |
aoqi@0 | 1254 | } |
aoqi@0 | 1255 | |
aoqi@0 | 1256 | try { |
aoqi@0 | 1257 | for (int i = end - 1; i >= start; i--) { |
aoqi@0 | 1258 | final int prefixIndex = _namespacePrefixes[i]; |
aoqi@0 | 1259 | _prefixTable.popScope(prefixIndex); |
aoqi@0 | 1260 | prefix = (prefixIndex > 0) ? _prefixTable.get(prefixIndex - 1) : |
aoqi@0 | 1261 | (prefixIndex == -1) ? "" : EncodingConstants.XML_NAMESPACE_PREFIX; |
aoqi@0 | 1262 | _contentHandler.endPrefixMapping(prefix); |
aoqi@0 | 1263 | } |
aoqi@0 | 1264 | _namespacePrefixesIndex = start; |
aoqi@0 | 1265 | } catch (SAXException e) { |
aoqi@0 | 1266 | throw new IOException("processStartNamespaceAII"); |
aoqi@0 | 1267 | } |
aoqi@0 | 1268 | } |
aoqi@0 | 1269 | |
aoqi@0 | 1270 | protected final void processAIIs() throws FastInfosetException, IOException { |
aoqi@0 | 1271 | QualifiedName name; |
aoqi@0 | 1272 | int b; |
aoqi@0 | 1273 | String value; |
aoqi@0 | 1274 | |
aoqi@0 | 1275 | _clearAttributes = true; |
aoqi@0 | 1276 | |
aoqi@0 | 1277 | if (++_duplicateAttributeVerifier._currentIteration == Integer.MAX_VALUE) { |
aoqi@0 | 1278 | _duplicateAttributeVerifier.clear(); |
aoqi@0 | 1279 | } |
aoqi@0 | 1280 | |
aoqi@0 | 1281 | do { |
aoqi@0 | 1282 | // AII qualified name |
aoqi@0 | 1283 | b = read(); |
aoqi@0 | 1284 | switch (DecoderStateTables.AII(b)) { |
aoqi@0 | 1285 | case DecoderStateTables.AII_INDEX_SMALL: |
aoqi@0 | 1286 | name = _attributeNameTable._array[b]; |
aoqi@0 | 1287 | break; |
aoqi@0 | 1288 | case DecoderStateTables.AII_INDEX_MEDIUM: |
aoqi@0 | 1289 | { |
aoqi@0 | 1290 | final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read()) |
aoqi@0 | 1291 | + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT; |
aoqi@0 | 1292 | name = _attributeNameTable._array[i]; |
aoqi@0 | 1293 | break; |
aoqi@0 | 1294 | } |
aoqi@0 | 1295 | case DecoderStateTables.AII_INDEX_LARGE: |
aoqi@0 | 1296 | { |
aoqi@0 | 1297 | final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read()) |
aoqi@0 | 1298 | + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT; |
aoqi@0 | 1299 | name = _attributeNameTable._array[i]; |
aoqi@0 | 1300 | break; |
aoqi@0 | 1301 | } |
aoqi@0 | 1302 | case DecoderStateTables.AII_LITERAL: |
aoqi@0 | 1303 | name = decodeLiteralQualifiedName( |
aoqi@0 | 1304 | b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK, |
aoqi@0 | 1305 | _attributeNameTable.getNext()); |
aoqi@0 | 1306 | name.createAttributeValues(_duplicateAttributeVerifier.MAP_SIZE); |
aoqi@0 | 1307 | _attributeNameTable.add(name); |
aoqi@0 | 1308 | break; |
aoqi@0 | 1309 | case DecoderStateTables.AII_TERMINATOR_DOUBLE: |
aoqi@0 | 1310 | _doubleTerminate = true; |
aoqi@0 | 1311 | case DecoderStateTables.AII_TERMINATOR_SINGLE: |
aoqi@0 | 1312 | _terminate = true; |
aoqi@0 | 1313 | // AIIs have finished break out of loop |
aoqi@0 | 1314 | continue; |
aoqi@0 | 1315 | default: |
aoqi@0 | 1316 | throw new IOException(CommonResourceBundle.getInstance().getString("message.decodingAIIs")); |
aoqi@0 | 1317 | } |
aoqi@0 | 1318 | |
aoqi@0 | 1319 | if (name.prefixIndex > 0 && _prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) { |
aoqi@0 | 1320 | throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.AIIqNameNotInScope")); |
aoqi@0 | 1321 | } |
aoqi@0 | 1322 | |
aoqi@0 | 1323 | _duplicateAttributeVerifier.checkForDuplicateAttribute(name.attributeHash, name.attributeId); |
aoqi@0 | 1324 | |
aoqi@0 | 1325 | // [normalized value] of AII |
aoqi@0 | 1326 | |
aoqi@0 | 1327 | b = read(); |
aoqi@0 | 1328 | switch(DecoderStateTables.NISTRING(b)) { |
aoqi@0 | 1329 | case DecoderStateTables.NISTRING_UTF8_SMALL_LENGTH: |
aoqi@0 | 1330 | _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1; |
aoqi@0 | 1331 | value = decodeUtf8StringAsString(); |
aoqi@0 | 1332 | if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 1333 | _attributeValueTable.add(value); |
aoqi@0 | 1334 | } |
aoqi@0 | 1335 | |
aoqi@0 | 1336 | _attributes.addAttribute(name, value); |
aoqi@0 | 1337 | break; |
aoqi@0 | 1338 | case DecoderStateTables.NISTRING_UTF8_MEDIUM_LENGTH: |
aoqi@0 | 1339 | _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT; |
aoqi@0 | 1340 | value = decodeUtf8StringAsString(); |
aoqi@0 | 1341 | if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 1342 | _attributeValueTable.add(value); |
aoqi@0 | 1343 | } |
aoqi@0 | 1344 | |
aoqi@0 | 1345 | _attributes.addAttribute(name, value); |
aoqi@0 | 1346 | break; |
aoqi@0 | 1347 | case DecoderStateTables.NISTRING_UTF8_LARGE_LENGTH: |
aoqi@0 | 1348 | _octetBufferLength = ((read() << 24) | |
aoqi@0 | 1349 | (read() << 16) | |
aoqi@0 | 1350 | (read() << 8) | |
aoqi@0 | 1351 | read()) |
aoqi@0 | 1352 | + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT; |
aoqi@0 | 1353 | value = decodeUtf8StringAsString(); |
aoqi@0 | 1354 | if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 1355 | _attributeValueTable.add(value); |
aoqi@0 | 1356 | } |
aoqi@0 | 1357 | |
aoqi@0 | 1358 | _attributes.addAttribute(name, value); |
aoqi@0 | 1359 | break; |
aoqi@0 | 1360 | case DecoderStateTables.NISTRING_UTF16_SMALL_LENGTH: |
aoqi@0 | 1361 | _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1; |
aoqi@0 | 1362 | value = decodeUtf16StringAsString(); |
aoqi@0 | 1363 | if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 1364 | _attributeValueTable.add(value); |
aoqi@0 | 1365 | } |
aoqi@0 | 1366 | |
aoqi@0 | 1367 | _attributes.addAttribute(name, value); |
aoqi@0 | 1368 | break; |
aoqi@0 | 1369 | case DecoderStateTables.NISTRING_UTF16_MEDIUM_LENGTH: |
aoqi@0 | 1370 | _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT; |
aoqi@0 | 1371 | value = decodeUtf16StringAsString(); |
aoqi@0 | 1372 | if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 1373 | _attributeValueTable.add(value); |
aoqi@0 | 1374 | } |
aoqi@0 | 1375 | |
aoqi@0 | 1376 | _attributes.addAttribute(name, value); |
aoqi@0 | 1377 | break; |
aoqi@0 | 1378 | case DecoderStateTables.NISTRING_UTF16_LARGE_LENGTH: |
aoqi@0 | 1379 | _octetBufferLength = ((read() << 24) | |
aoqi@0 | 1380 | (read() << 16) | |
aoqi@0 | 1381 | (read() << 8) | |
aoqi@0 | 1382 | read()) |
aoqi@0 | 1383 | + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT; |
aoqi@0 | 1384 | value = decodeUtf16StringAsString(); |
aoqi@0 | 1385 | if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { |
aoqi@0 | 1386 | _attributeValueTable.add(value); |
aoqi@0 | 1387 | } |
aoqi@0 | 1388 | |
aoqi@0 | 1389 | _attributes.addAttribute(name, value); |
aoqi@0 | 1390 | break; |
aoqi@0 | 1391 | case DecoderStateTables.NISTRING_RA: |
aoqi@0 | 1392 | { |
aoqi@0 | 1393 | final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0; |
aoqi@0 | 1394 | // Decode resitricted alphabet integer |
aoqi@0 | 1395 | _identifier = (b & 0x0F) << 4; |
aoqi@0 | 1396 | b = read(); |
aoqi@0 | 1397 | _identifier |= (b & 0xF0) >> 4; |
aoqi@0 | 1398 | |
aoqi@0 | 1399 | decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b); |
aoqi@0 | 1400 | |
aoqi@0 | 1401 | value = decodeRestrictedAlphabetAsString(); |
aoqi@0 | 1402 | if (addToTable) { |
aoqi@0 | 1403 | _attributeValueTable.add(value); |
aoqi@0 | 1404 | } |
aoqi@0 | 1405 | |
aoqi@0 | 1406 | _attributes.addAttribute(name, value); |
aoqi@0 | 1407 | break; |
aoqi@0 | 1408 | } |
aoqi@0 | 1409 | case DecoderStateTables.NISTRING_EA: |
aoqi@0 | 1410 | { |
aoqi@0 | 1411 | final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0; |
aoqi@0 | 1412 | |
aoqi@0 | 1413 | _identifier = (b & 0x0F) << 4; |
aoqi@0 | 1414 | b = read(); |
aoqi@0 | 1415 | _identifier |= (b & 0xF0) >> 4; |
aoqi@0 | 1416 | |
aoqi@0 | 1417 | decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b); |
aoqi@0 | 1418 | |
aoqi@0 | 1419 | processAIIEncodingAlgorithm(name, addToTable); |
aoqi@0 | 1420 | break; |
aoqi@0 | 1421 | } |
aoqi@0 | 1422 | case DecoderStateTables.NISTRING_INDEX_SMALL: |
aoqi@0 | 1423 | _attributes.addAttribute(name, |
aoqi@0 | 1424 | _attributeValueTable._array[b & EncodingConstants.INTEGER_2ND_BIT_SMALL_MASK]); |
aoqi@0 | 1425 | break; |
aoqi@0 | 1426 | case DecoderStateTables.NISTRING_INDEX_MEDIUM: |
aoqi@0 | 1427 | { |
aoqi@0 | 1428 | final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read()) |
aoqi@0 | 1429 | + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT; |
aoqi@0 | 1430 | |
aoqi@0 | 1431 | _attributes.addAttribute(name, |
aoqi@0 | 1432 | _attributeValueTable._array[index]); |
aoqi@0 | 1433 | break; |
aoqi@0 | 1434 | } |
aoqi@0 | 1435 | case DecoderStateTables.NISTRING_INDEX_LARGE: |
aoqi@0 | 1436 | { |
aoqi@0 | 1437 | final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read()) |
aoqi@0 | 1438 | + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT; |
aoqi@0 | 1439 | |
aoqi@0 | 1440 | _attributes.addAttribute(name, |
aoqi@0 | 1441 | _attributeValueTable._array[index]); |
aoqi@0 | 1442 | break; |
aoqi@0 | 1443 | } |
aoqi@0 | 1444 | case DecoderStateTables.NISTRING_EMPTY: |
aoqi@0 | 1445 | _attributes.addAttribute(name, ""); |
aoqi@0 | 1446 | break; |
aoqi@0 | 1447 | default: |
aoqi@0 | 1448 | throw new IOException(CommonResourceBundle.getInstance().getString("message.decodingAIIValue")); |
aoqi@0 | 1449 | } |
aoqi@0 | 1450 | |
aoqi@0 | 1451 | } while (!_terminate); |
aoqi@0 | 1452 | |
aoqi@0 | 1453 | // Reset duplication attribute verfifier |
aoqi@0 | 1454 | _duplicateAttributeVerifier._poolCurrent = _duplicateAttributeVerifier._poolHead; |
aoqi@0 | 1455 | |
aoqi@0 | 1456 | _terminate = _doubleTerminate; |
aoqi@0 | 1457 | _doubleTerminate = false; |
aoqi@0 | 1458 | } |
aoqi@0 | 1459 | |
aoqi@0 | 1460 | protected final void processCommentII() throws FastInfosetException, IOException { |
aoqi@0 | 1461 | switch(decodeNonIdentifyingStringOnFirstBit()) { |
aoqi@0 | 1462 | case NISTRING_STRING: |
aoqi@0 | 1463 | if (_addToTable) { |
aoqi@0 | 1464 | _v.otherString.add(new CharArray(_charBuffer, 0, _charBufferLength, true)); |
aoqi@0 | 1465 | } |
aoqi@0 | 1466 | |
aoqi@0 | 1467 | try { |
aoqi@0 | 1468 | _lexicalHandler.comment(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 1469 | } catch (SAXException e) { |
aoqi@0 | 1470 | throw new FastInfosetException("processCommentII", e); |
aoqi@0 | 1471 | } |
aoqi@0 | 1472 | break; |
aoqi@0 | 1473 | case NISTRING_ENCODING_ALGORITHM: |
aoqi@0 | 1474 | throw new IOException(CommonResourceBundle.getInstance().getString("message.commentIIAlgorithmNotSupported")); |
aoqi@0 | 1475 | case NISTRING_INDEX: |
aoqi@0 | 1476 | final CharArray ca = _v.otherString.get(_integer); |
aoqi@0 | 1477 | |
aoqi@0 | 1478 | try { |
aoqi@0 | 1479 | _lexicalHandler.comment(ca.ch, ca.start, ca.length); |
aoqi@0 | 1480 | } catch (SAXException e) { |
aoqi@0 | 1481 | throw new FastInfosetException("processCommentII", e); |
aoqi@0 | 1482 | } |
aoqi@0 | 1483 | break; |
aoqi@0 | 1484 | case NISTRING_EMPTY_STRING: |
aoqi@0 | 1485 | try { |
aoqi@0 | 1486 | _lexicalHandler.comment(_charBuffer, 0, 0); |
aoqi@0 | 1487 | } catch (SAXException e) { |
aoqi@0 | 1488 | throw new FastInfosetException("processCommentII", e); |
aoqi@0 | 1489 | } |
aoqi@0 | 1490 | break; |
aoqi@0 | 1491 | } |
aoqi@0 | 1492 | } |
aoqi@0 | 1493 | |
aoqi@0 | 1494 | protected final void processProcessingII() throws FastInfosetException, IOException { |
aoqi@0 | 1495 | final String target = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName); |
aoqi@0 | 1496 | |
aoqi@0 | 1497 | switch(decodeNonIdentifyingStringOnFirstBit()) { |
aoqi@0 | 1498 | case NISTRING_STRING: |
aoqi@0 | 1499 | final String data = new String(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 1500 | if (_addToTable) { |
aoqi@0 | 1501 | _v.otherString.add(new CharArrayString(data)); |
aoqi@0 | 1502 | } |
aoqi@0 | 1503 | try { |
aoqi@0 | 1504 | _contentHandler.processingInstruction(target, data); |
aoqi@0 | 1505 | } catch (SAXException e) { |
aoqi@0 | 1506 | throw new FastInfosetException("processProcessingII", e); |
aoqi@0 | 1507 | } |
aoqi@0 | 1508 | break; |
aoqi@0 | 1509 | case NISTRING_ENCODING_ALGORITHM: |
aoqi@0 | 1510 | throw new IOException(CommonResourceBundle.getInstance().getString("message.processingIIWithEncodingAlgorithm")); |
aoqi@0 | 1511 | case NISTRING_INDEX: |
aoqi@0 | 1512 | try { |
aoqi@0 | 1513 | _contentHandler.processingInstruction(target, _v.otherString.get(_integer).toString()); |
aoqi@0 | 1514 | } catch (SAXException e) { |
aoqi@0 | 1515 | throw new FastInfosetException("processProcessingII", e); |
aoqi@0 | 1516 | } |
aoqi@0 | 1517 | break; |
aoqi@0 | 1518 | case NISTRING_EMPTY_STRING: |
aoqi@0 | 1519 | try { |
aoqi@0 | 1520 | _contentHandler.processingInstruction(target, ""); |
aoqi@0 | 1521 | } catch (SAXException e) { |
aoqi@0 | 1522 | throw new FastInfosetException("processProcessingII", e); |
aoqi@0 | 1523 | } |
aoqi@0 | 1524 | break; |
aoqi@0 | 1525 | } |
aoqi@0 | 1526 | } |
aoqi@0 | 1527 | |
aoqi@0 | 1528 | protected final void processCIIEncodingAlgorithm(boolean addToTable) throws FastInfosetException, IOException { |
aoqi@0 | 1529 | if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) { |
aoqi@0 | 1530 | if (_primitiveHandler != null) { |
aoqi@0 | 1531 | processCIIBuiltInEncodingAlgorithmAsPrimitive(); |
aoqi@0 | 1532 | } else if (_algorithmHandler != null) { |
aoqi@0 | 1533 | Object array = processBuiltInEncodingAlgorithmAsObject(); |
aoqi@0 | 1534 | |
aoqi@0 | 1535 | try { |
aoqi@0 | 1536 | _algorithmHandler.object(null, _identifier, array); |
aoqi@0 | 1537 | } catch (SAXException e) { |
aoqi@0 | 1538 | throw new FastInfosetException(e); |
aoqi@0 | 1539 | } |
aoqi@0 | 1540 | } else { |
aoqi@0 | 1541 | StringBuffer buffer = new StringBuffer(); |
aoqi@0 | 1542 | processBuiltInEncodingAlgorithmAsCharacters(buffer); |
aoqi@0 | 1543 | |
aoqi@0 | 1544 | try { |
aoqi@0 | 1545 | _contentHandler.characters(buffer.toString().toCharArray(), 0, buffer.length()); |
aoqi@0 | 1546 | } catch (SAXException e) { |
aoqi@0 | 1547 | throw new FastInfosetException(e); |
aoqi@0 | 1548 | } |
aoqi@0 | 1549 | } |
aoqi@0 | 1550 | |
aoqi@0 | 1551 | if (addToTable) { |
aoqi@0 | 1552 | StringBuffer buffer = new StringBuffer(); |
aoqi@0 | 1553 | processBuiltInEncodingAlgorithmAsCharacters(buffer); |
aoqi@0 | 1554 | _characterContentChunkTable.add(buffer.toString().toCharArray(), buffer.length()); |
aoqi@0 | 1555 | } |
aoqi@0 | 1556 | } else if (_identifier == EncodingAlgorithmIndexes.CDATA) { |
aoqi@0 | 1557 | // Set back buffer position to start of encoded string |
aoqi@0 | 1558 | _octetBufferOffset -= _octetBufferLength; |
aoqi@0 | 1559 | decodeUtf8StringIntoCharBuffer(); |
aoqi@0 | 1560 | |
aoqi@0 | 1561 | try { |
aoqi@0 | 1562 | _lexicalHandler.startCDATA(); |
aoqi@0 | 1563 | _contentHandler.characters(_charBuffer, 0, _charBufferLength); |
aoqi@0 | 1564 | _lexicalHandler.endCDATA(); |
aoqi@0 | 1565 | } catch (SAXException e) { |
aoqi@0 | 1566 | throw new FastInfosetException(e); |
aoqi@0 | 1567 | } |
aoqi@0 | 1568 | |
aoqi@0 | 1569 | if (addToTable) { |
aoqi@0 | 1570 | _characterContentChunkTable.add(_charBuffer, _charBufferLength); |
aoqi@0 | 1571 | } |
aoqi@0 | 1572 | } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START && _algorithmHandler != null) { |
aoqi@0 | 1573 | final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START); |
aoqi@0 | 1574 | if (URI == null) { |
aoqi@0 | 1575 | throw new EncodingAlgorithmException(CommonResourceBundle.getInstance(). |
aoqi@0 | 1576 | getString("message.URINotPresent", new Object[]{Integer.valueOf(_identifier)})); |
aoqi@0 | 1577 | } |
aoqi@0 | 1578 | |
aoqi@0 | 1579 | final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI); |
aoqi@0 | 1580 | if (ea != null) { |
aoqi@0 | 1581 | final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1582 | try { |
aoqi@0 | 1583 | _algorithmHandler.object(URI, _identifier, data); |
aoqi@0 | 1584 | } catch (SAXException e) { |
aoqi@0 | 1585 | throw new FastInfosetException(e); |
aoqi@0 | 1586 | } |
aoqi@0 | 1587 | } else { |
aoqi@0 | 1588 | try { |
aoqi@0 | 1589 | _algorithmHandler.octets(URI, _identifier, _octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1590 | } catch (SAXException e) { |
aoqi@0 | 1591 | throw new FastInfosetException(e); |
aoqi@0 | 1592 | } |
aoqi@0 | 1593 | } |
aoqi@0 | 1594 | if (addToTable) { |
aoqi@0 | 1595 | throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.addToTableNotSupported")); |
aoqi@0 | 1596 | } |
aoqi@0 | 1597 | } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) { |
aoqi@0 | 1598 | // TODO should have property to ignore |
aoqi@0 | 1599 | throw new EncodingAlgorithmException( |
aoqi@0 | 1600 | CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported")); |
aoqi@0 | 1601 | } else { |
aoqi@0 | 1602 | // Reserved built-in algorithms for future use |
aoqi@0 | 1603 | // TODO should use sax property to decide if event will be |
aoqi@0 | 1604 | // reported, allows for support through handler if required. |
aoqi@0 | 1605 | throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved")); |
aoqi@0 | 1606 | } |
aoqi@0 | 1607 | } |
aoqi@0 | 1608 | |
aoqi@0 | 1609 | protected final void processCIIBuiltInEncodingAlgorithmAsPrimitive() throws FastInfosetException, IOException { |
aoqi@0 | 1610 | try { |
aoqi@0 | 1611 | int length; |
aoqi@0 | 1612 | switch(_identifier) { |
aoqi@0 | 1613 | case EncodingAlgorithmIndexes.HEXADECIMAL: |
aoqi@0 | 1614 | case EncodingAlgorithmIndexes.BASE64: |
aoqi@0 | 1615 | _primitiveHandler.bytes(_octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1616 | break; |
aoqi@0 | 1617 | case EncodingAlgorithmIndexes.SHORT: |
aoqi@0 | 1618 | length = BuiltInEncodingAlgorithmFactory.shortEncodingAlgorithm. |
aoqi@0 | 1619 | getPrimtiveLengthFromOctetLength(_octetBufferLength); |
aoqi@0 | 1620 | if (length > builtInAlgorithmState.shortArray.length) { |
aoqi@0 | 1621 | final short[] array = new short[length * 3 / 2 + 1]; |
aoqi@0 | 1622 | System.arraycopy(builtInAlgorithmState.shortArray, 0, |
aoqi@0 | 1623 | array, 0, builtInAlgorithmState.shortArray.length); |
aoqi@0 | 1624 | builtInAlgorithmState.shortArray = array; |
aoqi@0 | 1625 | } |
aoqi@0 | 1626 | |
aoqi@0 | 1627 | BuiltInEncodingAlgorithmFactory.shortEncodingAlgorithm. |
aoqi@0 | 1628 | decodeFromBytesToShortArray(builtInAlgorithmState.shortArray, 0, |
aoqi@0 | 1629 | _octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1630 | _primitiveHandler.shorts(builtInAlgorithmState.shortArray, 0, length); |
aoqi@0 | 1631 | break; |
aoqi@0 | 1632 | case EncodingAlgorithmIndexes.INT: |
aoqi@0 | 1633 | length = BuiltInEncodingAlgorithmFactory.intEncodingAlgorithm. |
aoqi@0 | 1634 | getPrimtiveLengthFromOctetLength(_octetBufferLength); |
aoqi@0 | 1635 | if (length > builtInAlgorithmState.intArray.length) { |
aoqi@0 | 1636 | final int[] array = new int[length * 3 / 2 + 1]; |
aoqi@0 | 1637 | System.arraycopy(builtInAlgorithmState.intArray, 0, |
aoqi@0 | 1638 | array, 0, builtInAlgorithmState.intArray.length); |
aoqi@0 | 1639 | builtInAlgorithmState.intArray = array; |
aoqi@0 | 1640 | } |
aoqi@0 | 1641 | |
aoqi@0 | 1642 | BuiltInEncodingAlgorithmFactory.intEncodingAlgorithm. |
aoqi@0 | 1643 | decodeFromBytesToIntArray(builtInAlgorithmState.intArray, 0, |
aoqi@0 | 1644 | _octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1645 | _primitiveHandler.ints(builtInAlgorithmState.intArray, 0, length); |
aoqi@0 | 1646 | break; |
aoqi@0 | 1647 | case EncodingAlgorithmIndexes.LONG: |
aoqi@0 | 1648 | length = BuiltInEncodingAlgorithmFactory.longEncodingAlgorithm. |
aoqi@0 | 1649 | getPrimtiveLengthFromOctetLength(_octetBufferLength); |
aoqi@0 | 1650 | if (length > builtInAlgorithmState.longArray.length) { |
aoqi@0 | 1651 | final long[] array = new long[length * 3 / 2 + 1]; |
aoqi@0 | 1652 | System.arraycopy(builtInAlgorithmState.longArray, 0, |
aoqi@0 | 1653 | array, 0, builtInAlgorithmState.longArray.length); |
aoqi@0 | 1654 | builtInAlgorithmState.longArray = array; |
aoqi@0 | 1655 | } |
aoqi@0 | 1656 | |
aoqi@0 | 1657 | BuiltInEncodingAlgorithmFactory.longEncodingAlgorithm. |
aoqi@0 | 1658 | decodeFromBytesToLongArray(builtInAlgorithmState.longArray, 0, |
aoqi@0 | 1659 | _octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1660 | _primitiveHandler.longs(builtInAlgorithmState.longArray, 0, length); |
aoqi@0 | 1661 | break; |
aoqi@0 | 1662 | case EncodingAlgorithmIndexes.BOOLEAN: |
aoqi@0 | 1663 | length = BuiltInEncodingAlgorithmFactory.booleanEncodingAlgorithm. |
aoqi@0 | 1664 | getPrimtiveLengthFromOctetLength(_octetBufferLength, _octetBuffer[_octetBufferStart] & 0xFF); |
aoqi@0 | 1665 | if (length > builtInAlgorithmState.booleanArray.length) { |
aoqi@0 | 1666 | final boolean[] array = new boolean[length * 3 / 2 + 1]; |
aoqi@0 | 1667 | System.arraycopy(builtInAlgorithmState.booleanArray, 0, |
aoqi@0 | 1668 | array, 0, builtInAlgorithmState.booleanArray.length); |
aoqi@0 | 1669 | builtInAlgorithmState.booleanArray = array; |
aoqi@0 | 1670 | } |
aoqi@0 | 1671 | |
aoqi@0 | 1672 | BuiltInEncodingAlgorithmFactory.booleanEncodingAlgorithm. |
aoqi@0 | 1673 | decodeFromBytesToBooleanArray( |
aoqi@0 | 1674 | builtInAlgorithmState.booleanArray, 0, length, |
aoqi@0 | 1675 | _octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1676 | _primitiveHandler.booleans(builtInAlgorithmState.booleanArray, 0, length); |
aoqi@0 | 1677 | break; |
aoqi@0 | 1678 | case EncodingAlgorithmIndexes.FLOAT: |
aoqi@0 | 1679 | length = BuiltInEncodingAlgorithmFactory.floatEncodingAlgorithm. |
aoqi@0 | 1680 | getPrimtiveLengthFromOctetLength(_octetBufferLength); |
aoqi@0 | 1681 | if (length > builtInAlgorithmState.floatArray.length) { |
aoqi@0 | 1682 | final float[] array = new float[length * 3 / 2 + 1]; |
aoqi@0 | 1683 | System.arraycopy(builtInAlgorithmState.floatArray, 0, |
aoqi@0 | 1684 | array, 0, builtInAlgorithmState.floatArray.length); |
aoqi@0 | 1685 | builtInAlgorithmState.floatArray = array; |
aoqi@0 | 1686 | } |
aoqi@0 | 1687 | |
aoqi@0 | 1688 | BuiltInEncodingAlgorithmFactory.floatEncodingAlgorithm. |
aoqi@0 | 1689 | decodeFromBytesToFloatArray(builtInAlgorithmState.floatArray, 0, |
aoqi@0 | 1690 | _octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1691 | _primitiveHandler.floats(builtInAlgorithmState.floatArray, 0, length); |
aoqi@0 | 1692 | break; |
aoqi@0 | 1693 | case EncodingAlgorithmIndexes.DOUBLE: |
aoqi@0 | 1694 | length = BuiltInEncodingAlgorithmFactory.doubleEncodingAlgorithm. |
aoqi@0 | 1695 | getPrimtiveLengthFromOctetLength(_octetBufferLength); |
aoqi@0 | 1696 | if (length > builtInAlgorithmState.doubleArray.length) { |
aoqi@0 | 1697 | final double[] array = new double[length * 3 / 2 + 1]; |
aoqi@0 | 1698 | System.arraycopy(builtInAlgorithmState.doubleArray, 0, |
aoqi@0 | 1699 | array, 0, builtInAlgorithmState.doubleArray.length); |
aoqi@0 | 1700 | builtInAlgorithmState.doubleArray = array; |
aoqi@0 | 1701 | } |
aoqi@0 | 1702 | |
aoqi@0 | 1703 | BuiltInEncodingAlgorithmFactory.doubleEncodingAlgorithm. |
aoqi@0 | 1704 | decodeFromBytesToDoubleArray(builtInAlgorithmState.doubleArray, 0, |
aoqi@0 | 1705 | _octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1706 | _primitiveHandler.doubles(builtInAlgorithmState.doubleArray, 0, length); |
aoqi@0 | 1707 | break; |
aoqi@0 | 1708 | case EncodingAlgorithmIndexes.UUID: |
aoqi@0 | 1709 | length = BuiltInEncodingAlgorithmFactory.uuidEncodingAlgorithm. |
aoqi@0 | 1710 | getPrimtiveLengthFromOctetLength(_octetBufferLength); |
aoqi@0 | 1711 | if (length > builtInAlgorithmState.longArray.length) { |
aoqi@0 | 1712 | final long[] array = new long[length * 3 / 2 + 1]; |
aoqi@0 | 1713 | System.arraycopy(builtInAlgorithmState.longArray, 0, |
aoqi@0 | 1714 | array, 0, builtInAlgorithmState.longArray.length); |
aoqi@0 | 1715 | builtInAlgorithmState.longArray = array; |
aoqi@0 | 1716 | } |
aoqi@0 | 1717 | |
aoqi@0 | 1718 | BuiltInEncodingAlgorithmFactory.uuidEncodingAlgorithm. |
aoqi@0 | 1719 | decodeFromBytesToLongArray(builtInAlgorithmState.longArray, 0, |
aoqi@0 | 1720 | _octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1721 | _primitiveHandler.uuids(builtInAlgorithmState.longArray, 0, length); |
aoqi@0 | 1722 | break; |
aoqi@0 | 1723 | case EncodingAlgorithmIndexes.CDATA: |
aoqi@0 | 1724 | throw new UnsupportedOperationException("CDATA"); |
aoqi@0 | 1725 | default: |
aoqi@0 | 1726 | throw new FastInfosetException(CommonResourceBundle.getInstance(). |
aoqi@0 | 1727 | getString("message.unsupportedAlgorithm", new Object[]{Integer.valueOf(_identifier)})); |
aoqi@0 | 1728 | } |
aoqi@0 | 1729 | } catch (SAXException e) { |
aoqi@0 | 1730 | throw new FastInfosetException(e); |
aoqi@0 | 1731 | } |
aoqi@0 | 1732 | } |
aoqi@0 | 1733 | |
aoqi@0 | 1734 | |
aoqi@0 | 1735 | protected final void processAIIEncodingAlgorithm(QualifiedName name, boolean addToTable) throws FastInfosetException, IOException { |
aoqi@0 | 1736 | if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) { |
aoqi@0 | 1737 | if (_primitiveHandler != null || _algorithmHandler != null) { |
aoqi@0 | 1738 | Object data = processBuiltInEncodingAlgorithmAsObject(); |
aoqi@0 | 1739 | _attributes.addAttributeWithAlgorithmData(name, null, _identifier, data); |
aoqi@0 | 1740 | } else { |
aoqi@0 | 1741 | StringBuffer buffer = new StringBuffer(); |
aoqi@0 | 1742 | processBuiltInEncodingAlgorithmAsCharacters(buffer); |
aoqi@0 | 1743 | _attributes.addAttribute(name, buffer.toString()); |
aoqi@0 | 1744 | } |
aoqi@0 | 1745 | } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START && _algorithmHandler != null) { |
aoqi@0 | 1746 | final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START); |
aoqi@0 | 1747 | if (URI == null) { |
aoqi@0 | 1748 | throw new EncodingAlgorithmException(CommonResourceBundle.getInstance(). |
aoqi@0 | 1749 | getString("message.URINotPresent", new Object[]{Integer.valueOf(_identifier)})); |
aoqi@0 | 1750 | } |
aoqi@0 | 1751 | |
aoqi@0 | 1752 | final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI); |
aoqi@0 | 1753 | if (ea != null) { |
aoqi@0 | 1754 | final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1755 | _attributes.addAttributeWithAlgorithmData(name, URI, _identifier, data); |
aoqi@0 | 1756 | } else { |
aoqi@0 | 1757 | final byte[] data = new byte[_octetBufferLength]; |
aoqi@0 | 1758 | System.arraycopy(_octetBuffer, _octetBufferStart, data, 0, _octetBufferLength); |
aoqi@0 | 1759 | _attributes.addAttributeWithAlgorithmData(name, URI, _identifier, data); |
aoqi@0 | 1760 | } |
aoqi@0 | 1761 | } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) { |
aoqi@0 | 1762 | // TODO should have property to ignore |
aoqi@0 | 1763 | throw new EncodingAlgorithmException( |
aoqi@0 | 1764 | CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported")); |
aoqi@0 | 1765 | } else if (_identifier == EncodingAlgorithmIndexes.CDATA) { |
aoqi@0 | 1766 | throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported")); |
aoqi@0 | 1767 | } else { |
aoqi@0 | 1768 | // Reserved built-in algorithms for future use |
aoqi@0 | 1769 | // TODO should use sax property to decide if event will be |
aoqi@0 | 1770 | // reported, allows for support through handler if required. |
aoqi@0 | 1771 | throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved")); |
aoqi@0 | 1772 | } |
aoqi@0 | 1773 | |
aoqi@0 | 1774 | if (addToTable) { |
aoqi@0 | 1775 | _attributeValueTable.add(_attributes.getValue(_attributes.getIndex(name.qName))); |
aoqi@0 | 1776 | } |
aoqi@0 | 1777 | } |
aoqi@0 | 1778 | |
aoqi@0 | 1779 | protected final void processBuiltInEncodingAlgorithmAsCharacters(StringBuffer buffer) throws FastInfosetException, IOException { |
aoqi@0 | 1780 | // TODO not very efficient, need to reuse buffers |
aoqi@0 | 1781 | Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier). |
aoqi@0 | 1782 | decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1783 | |
aoqi@0 | 1784 | BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array, buffer); |
aoqi@0 | 1785 | } |
aoqi@0 | 1786 | |
aoqi@0 | 1787 | protected final Object processBuiltInEncodingAlgorithmAsObject() throws FastInfosetException, IOException { |
aoqi@0 | 1788 | return BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier). |
aoqi@0 | 1789 | decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength); |
aoqi@0 | 1790 | } |
aoqi@0 | 1791 | } |