com.sun.xml.internal.fastinfoset.EncodingConstants Java Examples

The following examples show how to use com.sun.xml.internal.fastinfoset.EncodingConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParserVocabulary.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void convertVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) {
    final StringIntMap prefixMap = new FixedEntryStringIntMap(
            EncodingConstants.XML_NAMESPACE_PREFIX, 8);
    final StringIntMap namespaceNameMap = new FixedEntryStringIntMap(
            EncodingConstants.XML_NAMESPACE_NAME, 8);
    final StringIntMap localNameMap = new StringIntMap();

    addToTable(v.restrictedAlphabets.iterator(), restrictedAlphabet);
    addToTable(v.encodingAlgorithms.iterator(), encodingAlgorithm);
    addToTable(v.prefixes.iterator(), prefix, prefixMap);
    addToTable(v.namespaceNames.iterator(), namespaceName, namespaceNameMap);
    addToTable(v.localNames.iterator(), localName, localNameMap);
    addToTable(v.otherNCNames.iterator(), otherNCName);
    addToTable(v.otherURIs.iterator(), otherURI);
    addToTable(v.attributeValues.iterator(), attributeValue);
    addToTable(v.otherStrings.iterator(), otherString);
    addToTable(v.characterContentChunks.iterator(), characterContentChunk);
    addToTable(v.elements.iterator(), elementName, false,
            prefixMap, namespaceNameMap, localNameMap);
    addToTable(v.attributes.iterator(), attributeName, true,
            prefixMap, namespaceNameMap, localNameMap);
}
 
Example #2
Source File: StAXDocumentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected final void processCIIEncodingAlgorithm(boolean addToTable) throws FastInfosetException, IOException {
    _algorithmData = _octetBuffer;
    _algorithmDataOffset = _octetBufferStart;
    _algorithmDataLength = _octetBufferLength;
    _isAlgorithmDataCloned = false;

    if (_algorithmId >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        _algorithmURI = _v.encodingAlgorithm.get(_algorithmId - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
        if (_algorithmURI == null) {
            throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent", new Object[]{Integer.valueOf(_identifier)}));
        }
    } else if (_algorithmId > EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        // Reserved built-in algorithms for future use
        // TODO should use sax property to decide if event will be
        // reported, allows for support through handler if required.
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved"));
    }

    if (addToTable) {
        convertEncodingAlgorithmDataToCharacters();
        _characterContentChunkTable.add(_characters, _characters.length);
    }
}
 
Example #3
Source File: StAXDocumentSerializer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void writeNamespace(String prefix, String namespaceURI)
    throws XMLStreamException
{
    if (prefix == null || prefix.length() == 0 || prefix.equals(EncodingConstants.XMLNS_NAMESPACE_PREFIX)) {
        writeDefaultNamespace(namespaceURI);
    }
    else {
        if (!_inStartElement) {
            throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
        }

        if (_namespacesArrayIndex == _namespacesArray.length) {
            final String[] namespacesArray = new String[_namespacesArrayIndex * 2];
            System.arraycopy(_namespacesArray, 0, namespacesArray, 0, _namespacesArrayIndex);
            _namespacesArray = namespacesArray;
        }

        _namespacesArray[_namespacesArrayIndex++] = prefix;
        _namespacesArray[_namespacesArrayIndex++] = namespaceURI;
        setPrefix(prefix, namespaceURI);
    }
}
 
Example #4
Source File: DOMDocumentParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected String convertEncodingAlgorithmDataToCharacters(boolean isAttributeValue) throws FastInfosetException, IOException {
    StringBuffer buffer = new StringBuffer();
    if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).
                decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
        BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array,  buffer);
    } else if (_identifier == EncodingAlgorithmIndexes.CDATA) {
        if (!isAttributeValue) {
            // Set back buffer position to start of encoded string
            _octetBufferOffset -= _octetBufferLength;
            return decodeUtf8StringAsString();
        }
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
    } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
        final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
        if (ea != null) {
            final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
            ea.convertToCharacters(data, buffer);
        } else {
            throw new EncodingAlgorithmException(
                    CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported"));
        }
    }
    return buffer.toString();
}
 
Example #5
Source File: StAXDocumentSerializer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void writeNamespace(String prefix, String namespaceURI)
    throws XMLStreamException
{
    if (prefix == null || prefix.length() == 0 || prefix.equals(EncodingConstants.XMLNS_NAMESPACE_PREFIX)) {
        writeDefaultNamespace(namespaceURI);
    }
    else {
        if (!_inStartElement) {
            throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
        }

        if (_namespacesArrayIndex == _namespacesArray.length) {
            final String[] namespacesArray = new String[_namespacesArrayIndex * 2];
            System.arraycopy(_namespacesArray, 0, namespacesArray, 0, _namespacesArrayIndex);
            _namespacesArray = namespacesArray;
        }

        _namespacesArray[_namespacesArrayIndex++] = prefix;
        _namespacesArray[_namespacesArrayIndex++] = namespaceURI;
        setPrefix(prefix, namespaceURI);
    }
}
 
Example #6
Source File: FastInfosetStreamWriterOutput.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void beginStartTag(Name name) throws IOException {
    fiout.writeLowLevelTerminationAndMark();

    if (nsContext.getCurrent().count() == 0) {
        final int qNameIndex = tables.elementIndexes[name.qNameIndex] - tables.indexOffset;
        final int prefixIndex = nsUriIndex2prefixIndex[name.nsUriIndex];

        if (qNameIndex >= 0 &&
                tables.elementIndexPrefixes[name.qNameIndex] == prefixIndex) {
            fiout.writeLowLevelStartElementIndexed(EncodingConstants.ELEMENT, qNameIndex);
        } else {
            tables.elementIndexes[name.qNameIndex] = fiout.getNextElementIndex() + tables.indexOffset;
            tables.elementIndexPrefixes[name.qNameIndex] = prefixIndex;
            writeLiteral(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_LITERAL_QNAME_FLAG,
                    name,
                    nsContext.getPrefix(prefixIndex),
                    nsContext.getNamespaceURI(prefixIndex));
        }
    } else {
        beginStartTagWithNamespaces(name);
    }
}
 
Example #7
Source File: DOMDocumentParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected String convertEncodingAlgorithmDataToCharacters(boolean isAttributeValue) throws FastInfosetException, IOException {
    StringBuffer buffer = new StringBuffer();
    if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).
                decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
        BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array,  buffer);
    } else if (_identifier == EncodingAlgorithmIndexes.CDATA) {
        if (!isAttributeValue) {
            // Set back buffer position to start of encoded string
            _octetBufferOffset -= _octetBufferLength;
            return decodeUtf8StringAsString();
        }
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
    } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
        final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
        if (ea != null) {
            final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
            ea.convertToCharacters(data, buffer);
        } else {
            throw new EncodingAlgorithmException(
                    CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported"));
        }
    }
    return buffer.toString();
}
 
Example #8
Source File: DOMDocumentParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected String convertEncodingAlgorithmDataToCharacters(boolean isAttributeValue) throws FastInfosetException, IOException {
    StringBuffer buffer = new StringBuffer();
    if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).
                decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
        BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array,  buffer);
    } else if (_identifier == EncodingAlgorithmIndexes.CDATA) {
        if (!isAttributeValue) {
            // Set back buffer position to start of encoded string
            _octetBufferOffset -= _octetBufferLength;
            return decodeUtf8StringAsString();
        }
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
    } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
        final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
        if (ea != null) {
            final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
            ea.convertToCharacters(data, buffer);
        } else {
            throw new EncodingAlgorithmException(
                    CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported"));
        }
    }
    return buffer.toString();
}
 
Example #9
Source File: SAXDocumentSerializer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void startPrefixMapping(String prefix, String uri) throws SAXException {
    try {
        if (_elementHasNamespaces == false) {
            encodeTermination();

            // Mark the current buffer position to flag attributes if necessary
            mark();
            _elementHasNamespaces = true;

            // Write out Element byte with namespaces
            write(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
        }

        encodeNamespaceAttribute(prefix, uri);
    } catch (IOException e) {
        throw new SAXException("startElement", e);
    }
}
 
Example #10
Source File: ParserVocabulary.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void convertVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) {
    final StringIntMap prefixMap = new FixedEntryStringIntMap(
            EncodingConstants.XML_NAMESPACE_PREFIX, 8);
    final StringIntMap namespaceNameMap = new FixedEntryStringIntMap(
            EncodingConstants.XML_NAMESPACE_NAME, 8);
    final StringIntMap localNameMap = new StringIntMap();

    addToTable(v.restrictedAlphabets.iterator(), restrictedAlphabet);
    addToTable(v.encodingAlgorithms.iterator(), encodingAlgorithm);
    addToTable(v.prefixes.iterator(), prefix, prefixMap);
    addToTable(v.namespaceNames.iterator(), namespaceName, namespaceNameMap);
    addToTable(v.localNames.iterator(), localName, localNameMap);
    addToTable(v.otherNCNames.iterator(), otherNCName);
    addToTable(v.otherURIs.iterator(), otherURI);
    addToTable(v.attributeValues.iterator(), attributeValue);
    addToTable(v.otherStrings.iterator(), otherString);
    addToTable(v.characterContentChunks.iterator(), characterContentChunk);
    addToTable(v.elements.iterator(), elementName, false,
            prefixMap, namespaceNameMap, localNameMap);
    addToTable(v.attributes.iterator(), attributeName, true,
            prefixMap, namespaceNameMap, localNameMap);
}
 
Example #11
Source File: FastInfosetStreamWriterOutput.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void beginStartTag(Name name) throws IOException {
    fiout.writeLowLevelTerminationAndMark();

    if (nsContext.getCurrent().count() == 0) {
        final int qNameIndex = tables.elementIndexes[name.qNameIndex] - tables.indexOffset;
        final int prefixIndex = nsUriIndex2prefixIndex[name.nsUriIndex];

        if (qNameIndex >= 0 &&
                tables.elementIndexPrefixes[name.qNameIndex] == prefixIndex) {
            fiout.writeLowLevelStartElementIndexed(EncodingConstants.ELEMENT, qNameIndex);
        } else {
            tables.elementIndexes[name.qNameIndex] = fiout.getNextElementIndex() + tables.indexOffset;
            tables.elementIndexPrefixes[name.qNameIndex] = prefixIndex;
            writeLiteral(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_LITERAL_QNAME_FLAG,
                    name,
                    nsContext.getPrefix(prefixIndex),
                    nsContext.getNamespaceURI(prefixIndex));
        }
    } else {
        beginStartTagWithNamespaces(name);
    }
}
 
Example #12
Source File: SAXDocumentSerializer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void startPrefixMapping(String prefix, String uri) throws SAXException {
    try {
        if (_elementHasNamespaces == false) {
            encodeTermination();

            // Mark the current buffer position to flag attributes if necessary
            mark();
            _elementHasNamespaces = true;

            // Write out Element byte with namespaces
            write(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
        }

        encodeNamespaceAttribute(prefix, uri);
    } catch (IOException e) {
        throw new SAXException("startElement", e);
    }
}
 
Example #13
Source File: ParserVocabulary.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void convertVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) {
    final StringIntMap prefixMap = new FixedEntryStringIntMap(
            EncodingConstants.XML_NAMESPACE_PREFIX, 8);
    final StringIntMap namespaceNameMap = new FixedEntryStringIntMap(
            EncodingConstants.XML_NAMESPACE_NAME, 8);
    final StringIntMap localNameMap = new StringIntMap();

    addToTable(v.restrictedAlphabets.iterator(), restrictedAlphabet);
    addToTable(v.encodingAlgorithms.iterator(), encodingAlgorithm);
    addToTable(v.prefixes.iterator(), prefix, prefixMap);
    addToTable(v.namespaceNames.iterator(), namespaceName, namespaceNameMap);
    addToTable(v.localNames.iterator(), localName, localNameMap);
    addToTable(v.otherNCNames.iterator(), otherNCName);
    addToTable(v.otherURIs.iterator(), otherURI);
    addToTable(v.attributeValues.iterator(), attributeValue);
    addToTable(v.otherStrings.iterator(), otherString);
    addToTable(v.characterContentChunks.iterator(), characterContentChunk);
    addToTable(v.elements.iterator(), elementName, false,
            prefixMap, namespaceNameMap, localNameMap);
    addToTable(v.attributes.iterator(), attributeName, true,
            prefixMap, namespaceNameMap, localNameMap);
}
 
Example #14
Source File: StAXDocumentParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected final void processCIIEncodingAlgorithm(boolean addToTable) throws FastInfosetException, IOException {
    _algorithmData = _octetBuffer;
    _algorithmDataOffset = _octetBufferStart;
    _algorithmDataLength = _octetBufferLength;
    _isAlgorithmDataCloned = false;

    if (_algorithmId >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        _algorithmURI = _v.encodingAlgorithm.get(_algorithmId - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
        if (_algorithmURI == null) {
            throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent", new Object[]{Integer.valueOf(_identifier)}));
        }
    } else if (_algorithmId > EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        // Reserved built-in algorithms for future use
        // TODO should use sax property to decide if event will be
        // reported, allows for support through handler if required.
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved"));
    }

    if (addToTable) {
        convertEncodingAlgorithmDataToCharacters();
        _characterContentChunkTable.add(_characters, _characters.length);
    }
}
 
Example #15
Source File: StAXDocumentParser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected final void processUnexpandedEntityReference(final int b) throws FastInfosetException, IOException {
    _eventType = ENTITY_REFERENCE;

    /*
     * TODO
     * How does StAX report such events?
     */
    String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName);

    String system_identifier = ((b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0)
    ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : "";
    String public_identifier = ((b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0)
    ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : "";

    if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, "processUnexpandedEntityReference: entity_reference_name={0} system_identifier={1}public_identifier={2}",
                new Object[]{entity_reference_name, system_identifier, public_identifier});
    }
}
 
Example #16
Source File: StAXDocumentParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private final void processUtf16CharacterString(final int b) throws IOException {
    decodeUtf16StringAsCharBuffer();
    if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
        _charactersOffset = _characterContentChunkTable.add(_charBuffer, _charBufferLength);
        _characters = _characterContentChunkTable._array;
    } else {
        _characters = _charBuffer;
        _charactersOffset = 0;
    }
}
 
Example #17
Source File: StAXDocumentParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected final void convertEncodingAlgorithmDataToCharacters() throws FastInfosetException, IOException {
    StringBuffer buffer = new StringBuffer();
    if (_algorithmId == EncodingAlgorithmIndexes.BASE64) {
        convertBase64AlorithmDataToCharacters(buffer);
    } else if (_algorithmId < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_algorithmId).
                decodeFromBytes(_algorithmData, _algorithmDataOffset, _algorithmDataLength);
        BuiltInEncodingAlgorithmFactory.getAlgorithm(_algorithmId).convertToCharacters(array,  buffer);
    } else if (_algorithmId == EncodingAlgorithmIndexes.CDATA) {
        _octetBufferOffset -= _octetBufferLength;
        decodeUtf8StringIntoCharBuffer();

        _characters = _charBuffer;
        _charactersOffset = 0;
        return;
    } else if (_algorithmId >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(_algorithmURI);
        if (ea != null) {
            final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
            ea.convertToCharacters(data, buffer);
        } else {
            throw new EncodingAlgorithmException(
                    CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported"));
        }
    }

    _characters = new char[buffer.length()];
    buffer.getChars(0, buffer.length(), _characters, 0);
    _charactersOffset = 0;
    _charBufferLength = _characters.length;
}
 
Example #18
Source File: DOMDocumentParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private final String processUtf8CharacterString() throws FastInfosetException, IOException {
    if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
        _characterContentChunkTable.ensureSize(_octetBufferLength);
        final int charactersOffset = _characterContentChunkTable._arrayIndex;
        decodeUtf8StringAsCharBuffer(_characterContentChunkTable._array, charactersOffset);
        _characterContentChunkTable.add(_charBufferLength);
        return _characterContentChunkTable.getString(_characterContentChunkTable._cachedIndex);
    } else {
        decodeUtf8StringAsCharBuffer();
        return new String(_charBuffer, 0, _charBufferLength);
    }
}
 
Example #19
Source File: PrefixArray.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private final void initializeEntries() {
    _inScopeNamespaces[0] = _namespacePool;
    _namespacePool = _namespacePool.next;
    _inScopeNamespaces[0].next = null;
    _inScopeNamespaces[0].prefix = "";
    _inScopeNamespaces[0].namespaceName = "";
    _inScopeNamespaces[0].namespaceIndex = _currentInScope[0] = 0;

    int index = KeyIntMap.indexFor(KeyIntMap.hashHash(_inScopeNamespaces[0].prefix.hashCode()), _prefixMap.length);
    _prefixMap[index] = _prefixPool;
    _prefixPool = _prefixPool.next;
    _prefixMap[index].next = null;
    _prefixMap[index].prefixId = 0;


    _inScopeNamespaces[1] = _namespacePool;
    _namespacePool = _namespacePool.next;
    _inScopeNamespaces[1].next = null;
    _inScopeNamespaces[1].prefix = EncodingConstants.XML_NAMESPACE_PREFIX;
    _inScopeNamespaces[1].namespaceName = EncodingConstants.XML_NAMESPACE_NAME;
    _inScopeNamespaces[1].namespaceIndex = _currentInScope[1] = 1;

    index = KeyIntMap.indexFor(KeyIntMap.hashHash(_inScopeNamespaces[1].prefix.hashCode()), _prefixMap.length);
    if (_prefixMap[index] == null) {
        _prefixMap[index] = _prefixPool;
        _prefixPool = _prefixPool.next;
        _prefixMap[index].next = null;
    } else {
        final PrefixEntry e = _prefixMap[index];
        _prefixMap[index] = _prefixPool;
        _prefixPool = _prefixPool.next;
        _prefixMap[index].next = e;
    }
    _prefixMap[index].prefixId = 1;
}
 
Example #20
Source File: StAXDocumentSerializer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void encodeLiteralHeader(int type, String namespaceURI, String prefix) throws IOException {
    if (namespaceURI != "") {
        type |= EncodingConstants.LITERAL_QNAME_NAMESPACE_NAME_FLAG;
        if (prefix != "")
            type |= EncodingConstants.LITERAL_QNAME_PREFIX_FLAG;

        write(type);
        if (prefix != "")
            encodeNonZeroIntegerOnSecondBitFirstBitOne(_v.prefix.get(prefix));
        encodeNonZeroIntegerOnSecondBitFirstBitOne(_v.namespaceName.get(namespaceURI));
    } else
        write(type);
}
 
Example #21
Source File: StAXDocumentSerializer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public final void writeLowLevelEndStartElement() throws IOException {
    if (hasMark()) {
        resetMark();
    } else {
        // Terminate the attributes
        _b = EncodingConstants.TERMINATOR;
        _terminate = true;
    }
}
 
Example #22
Source File: SerializerVocabulary.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public SerializerVocabulary() {
    tables[RESTRICTED_ALPHABET] = restrictedAlphabet = new StringIntMap(4);
    tables[ENCODING_ALGORITHM] = encodingAlgorithm = new StringIntMap(4);
    tables[PREFIX] = prefix = new FixedEntryStringIntMap(EncodingConstants.XML_NAMESPACE_PREFIX, 8);
    tables[NAMESPACE_NAME] = namespaceName = new FixedEntryStringIntMap(EncodingConstants.XML_NAMESPACE_NAME, 8);
    tables[LOCAL_NAME] = localName = new StringIntMap();
    tables[OTHER_NCNAME] = otherNCName = new StringIntMap(4);
    tables[OTHER_URI] = otherURI = new StringIntMap(4);
    tables[ATTRIBUTE_VALUE] = attributeValue = new StringIntMap();
    tables[OTHER_STRING] = otherString = new CharArrayIntMap(4);
    tables[CHARACTER_CONTENT_CHUNK] = characterContentChunk = new CharArrayIntMap();
    tables[ELEMENT_NAME] = elementName = new LocalNameQualifiedNamesMap();
    tables[ATTRIBUTE_NAME] = attributeName = new LocalNameQualifiedNamesMap();
}
 
Example #23
Source File: StAXDocumentSerializer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public final boolean writeLowLevelAttribute(String prefix, String namespaceURI, String localName) throws IOException {
    final boolean isIndexed = encodeAttribute(namespaceURI, prefix, localName);

    if (!isIndexed)
        encodeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG,
                namespaceURI, prefix, localName);

    return isIndexed;
}
 
Example #24
Source File: StAXDocumentSerializer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void encodeLiteralHeader(int type, String namespaceURI, String prefix) throws IOException {
    if (namespaceURI != "") {
        type |= EncodingConstants.LITERAL_QNAME_NAMESPACE_NAME_FLAG;
        if (prefix != "")
            type |= EncodingConstants.LITERAL_QNAME_PREFIX_FLAG;

        write(type);
        if (prefix != "")
            encodeNonZeroIntegerOnSecondBitFirstBitOne(_v.prefix.get(prefix));
        encodeNonZeroIntegerOnSecondBitFirstBitOne(_v.namespaceName.get(namespaceURI));
    } else
        write(type);
}
 
Example #25
Source File: SAXDocumentSerializerWithPrefixMapping.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public SAXDocumentSerializerWithPrefixMapping(Map namespaceToPrefixMapping) {
    // Use the local name to look up elements/attributes
    super(true);
    _namespaceToPrefixMapping = new HashMap(namespaceToPrefixMapping);
    _prefixToPrefixMapping = new HashMap();

    // Empty prefix
    _namespaceToPrefixMapping.put("", "");
    // 'xml' prefix
    _namespaceToPrefixMapping.put(EncodingConstants.XML_NAMESPACE_NAME, EncodingConstants.XML_NAMESPACE_PREFIX);

    _declaredNamespaces = new StringIntMap(4);
}
 
Example #26
Source File: StAXDocumentSerializer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void writeAttribute(String prefix, String namespaceURI,
    String localName, String value) throws XMLStreamException
{
    if (!_inStartElement) {
        throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
    }

    // TODO
    // Need to check carefully the rule for the writing of
    // namespaces in StAX. Is it safe to ignore such
    // attributes, as declarations will be made using the
    // writeNamespace method
    if (namespaceURI == EncodingConstants.XMLNS_NAMESPACE_NAME ||
            namespaceURI.equals(EncodingConstants.XMLNS_NAMESPACE_NAME)) {
        return;
    }

    if (_attributesArrayIndex == _attributesArray.length) {
        final String[] attributesArray = new String[_attributesArrayIndex * 2];
        System.arraycopy(_attributesArray, 0, attributesArray, 0, _attributesArrayIndex);
        _attributesArray = attributesArray;
    }

    _attributesArray[_attributesArrayIndex++] = namespaceURI;
    _attributesArray[_attributesArrayIndex++] = prefix;
    _attributesArray[_attributesArrayIndex++] = localName;
    _attributesArray[_attributesArrayIndex++] = value;
}
 
Example #27
Source File: StAXDocumentSerializer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public final boolean writeLowLevelAttribute(String prefix, String namespaceURI, String localName) throws IOException {
    final boolean isIndexed = encodeAttribute(namespaceURI, prefix, localName);

    if (!isIndexed)
        encodeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG,
                namespaceURI, prefix, localName);

    return isIndexed;
}
 
Example #28
Source File: StAXDocumentParser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private final void processUtf16CharacterString(final int b) throws IOException {
    decodeUtf16StringAsCharBuffer();
    if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
        _charactersOffset = _characterContentChunkTable.add(_charBuffer, _charBufferLength);
        _characters = _characterContentChunkTable._array;
    } else {
        _characters = _charBuffer;
        _charactersOffset = 0;
    }
}
 
Example #29
Source File: StAXDocumentSerializer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void writeAttribute(String prefix, String namespaceURI,
    String localName, String value) throws XMLStreamException
{
    if (!_inStartElement) {
        throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
    }

    // TODO
    // Need to check carefully the rule for the writing of
    // namespaces in StAX. Is it safe to ignore such
    // attributes, as declarations will be made using the
    // writeNamespace method
    if (namespaceURI == EncodingConstants.XMLNS_NAMESPACE_NAME ||
            namespaceURI.equals(EncodingConstants.XMLNS_NAMESPACE_NAME)) {
        return;
    }

    if (_attributesArrayIndex == _attributesArray.length) {
        final String[] attributesArray = new String[_attributesArrayIndex * 2];
        System.arraycopy(_attributesArray, 0, attributesArray, 0, _attributesArrayIndex);
        _attributesArray = attributesArray;
    }

    _attributesArray[_attributesArrayIndex++] = namespaceURI;
    _attributesArray[_attributesArrayIndex++] = prefix;
    _attributesArray[_attributesArrayIndex++] = localName;
    _attributesArray[_attributesArrayIndex++] = value;
}
 
Example #30
Source File: FastInfosetStreamWriterOutput.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void attribute(Name name, String value) throws IOException {
    fiout.writeLowLevelStartAttributes();

    final int qNameIndex = tables.attributeIndexes[name.qNameIndex] - tables.indexOffset;
    if (qNameIndex >= 0) {
        fiout.writeLowLevelAttributeIndexed(qNameIndex);
    } else {
        tables.attributeIndexes[name.qNameIndex] = fiout.getNextAttributeIndex() + tables.indexOffset;

        final int namespaceURIId = name.nsUriIndex;
        if (namespaceURIId == -1) {
            writeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG,
                    name,
                    "",
                    "");
        } else {
            final int prefix = nsUriIndex2prefixIndex[namespaceURIId];
            writeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG,
                    name,
                    nsContext.getPrefix(prefix),
                    nsContext.getNamespaceURI(prefix));
        }
    }

    fiout.writeLowLevelAttributeValue(value);
}