feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.fastinfoset.sax;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
|
||||
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmAttributes;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class AttributesHolder implements EncodingAlgorithmAttributes {
|
||||
private static final int DEFAULT_CAPACITY = 8;
|
||||
|
||||
private Map _registeredEncodingAlgorithms;
|
||||
|
||||
private int _attributeCount;
|
||||
|
||||
private QualifiedName[] _names;
|
||||
private String[] _values;
|
||||
|
||||
private String[] _algorithmURIs;
|
||||
private int[] _algorithmIds;
|
||||
private Object[] _algorithmData;
|
||||
|
||||
public AttributesHolder() {
|
||||
_names = new QualifiedName[DEFAULT_CAPACITY];
|
||||
_values = new String[DEFAULT_CAPACITY];
|
||||
|
||||
_algorithmURIs = new String[DEFAULT_CAPACITY];
|
||||
_algorithmIds = new int[DEFAULT_CAPACITY];
|
||||
_algorithmData = new Object[DEFAULT_CAPACITY];
|
||||
}
|
||||
|
||||
public AttributesHolder(Map registeredEncodingAlgorithms) {
|
||||
this();
|
||||
_registeredEncodingAlgorithms = registeredEncodingAlgorithms;
|
||||
}
|
||||
|
||||
// org.xml.sax.Attributes
|
||||
|
||||
public final int getLength() {
|
||||
return _attributeCount;
|
||||
}
|
||||
|
||||
public final String getLocalName(int index) {
|
||||
return _names[index].localName;
|
||||
}
|
||||
|
||||
public final String getQName(int index) {
|
||||
return _names[index].getQNameString();
|
||||
}
|
||||
|
||||
public final String getType(int index) {
|
||||
return "CDATA";
|
||||
}
|
||||
|
||||
public final String getURI(int index) {
|
||||
return _names[index].namespaceName;
|
||||
}
|
||||
|
||||
public final String getValue(int index) {
|
||||
final String value = _values[index];
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (_algorithmData[index] == null ||
|
||||
(_algorithmIds[index] >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START &&
|
||||
_registeredEncodingAlgorithms == null)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return _values[index] = convertEncodingAlgorithmDataToString(
|
||||
_algorithmIds[index],
|
||||
_algorithmURIs[index],
|
||||
_algorithmData[index]).toString();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} catch (FastInfosetException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final int getIndex(String qName) {
|
||||
int i = qName.indexOf(':');
|
||||
String prefix = "";
|
||||
String localName = qName;
|
||||
if (i >= 0) {
|
||||
prefix = qName.substring(0, i);
|
||||
localName = qName.substring(i + 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < _attributeCount; i++) {
|
||||
QualifiedName name = _names[i];
|
||||
if (localName.equals(name.localName) &&
|
||||
prefix.equals(name.prefix)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public final String getType(String qName) {
|
||||
int index = getIndex(qName);
|
||||
if (index >= 0) {
|
||||
return "CDATA";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final String getValue(String qName) {
|
||||
int index = getIndex(qName);
|
||||
if (index >= 0) {
|
||||
return _values[index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final int getIndex(String uri, String localName) {
|
||||
for (int i = 0; i < _attributeCount; i++) {
|
||||
QualifiedName name = _names[i];
|
||||
if (localName.equals(name.localName) &&
|
||||
uri.equals(name.namespaceName)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public final String getType(String uri, String localName) {
|
||||
int index = getIndex(uri, localName);
|
||||
if (index >= 0) {
|
||||
return "CDATA";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final String getValue(String uri, String localName) {
|
||||
int index = getIndex(uri, localName);
|
||||
if (index >= 0) {
|
||||
return _values[index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
for (int i = 0; i < _attributeCount; i++) {
|
||||
_values[i] = null;
|
||||
_algorithmData[i] = null;
|
||||
}
|
||||
_attributeCount = 0;
|
||||
}
|
||||
|
||||
// EncodingAlgorithmAttributes
|
||||
|
||||
public final String getAlgorithmURI(int index) {
|
||||
return _algorithmURIs[index];
|
||||
}
|
||||
|
||||
public final int getAlgorithmIndex(int index) {
|
||||
return _algorithmIds[index];
|
||||
}
|
||||
|
||||
public final Object getAlgorithmData(int index) {
|
||||
return _algorithmData[index];
|
||||
}
|
||||
|
||||
public String getAlpababet(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getToIndex(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
public final void addAttribute(QualifiedName name, String value) {
|
||||
if (_attributeCount == _names.length) {
|
||||
resize();
|
||||
}
|
||||
_names[_attributeCount] = name;
|
||||
_values[_attributeCount++] = value;
|
||||
}
|
||||
|
||||
public final void addAttributeWithAlgorithmData(QualifiedName name, String URI, int id, Object data) {
|
||||
if (_attributeCount == _names.length) {
|
||||
resize();
|
||||
}
|
||||
_names[_attributeCount] = name;
|
||||
_values[_attributeCount] = null;
|
||||
|
||||
_algorithmURIs[_attributeCount] = URI;
|
||||
_algorithmIds[_attributeCount] = id;
|
||||
_algorithmData[_attributeCount++] = data;
|
||||
}
|
||||
|
||||
public final QualifiedName getQualifiedName(int index) {
|
||||
return _names[index];
|
||||
}
|
||||
|
||||
public final String getPrefix(int index) {
|
||||
return _names[index].prefix;
|
||||
}
|
||||
|
||||
private final void resize() {
|
||||
final int newLength = _attributeCount * 3 / 2 + 1;
|
||||
|
||||
QualifiedName[] names = new QualifiedName[newLength];
|
||||
String[] values = new String[newLength];
|
||||
|
||||
String[] algorithmURIs = new String[newLength];
|
||||
int[] algorithmIds = new int[newLength];
|
||||
Object[] algorithmData = new Object[newLength];
|
||||
|
||||
System.arraycopy(_names, 0, names, 0, _attributeCount);
|
||||
System.arraycopy(_values, 0, values, 0, _attributeCount);
|
||||
|
||||
System.arraycopy(_algorithmURIs, 0, algorithmURIs, 0, _attributeCount);
|
||||
System.arraycopy(_algorithmIds, 0, algorithmIds, 0, _attributeCount);
|
||||
System.arraycopy(_algorithmData, 0, algorithmData, 0, _attributeCount);
|
||||
|
||||
_names = names;
|
||||
_values = values;
|
||||
|
||||
_algorithmURIs = algorithmURIs;
|
||||
_algorithmIds = algorithmIds;
|
||||
_algorithmData = algorithmData;
|
||||
}
|
||||
|
||||
private final StringBuffer convertEncodingAlgorithmDataToString(int identifier, String URI, Object data) throws FastInfosetException, IOException {
|
||||
EncodingAlgorithm ea = null;
|
||||
if (identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
|
||||
ea = BuiltInEncodingAlgorithmFactory.getAlgorithm(identifier);
|
||||
} else if (identifier == EncodingAlgorithmIndexes.CDATA) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
|
||||
} else if (identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
|
||||
if (URI == null) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent") + identifier);
|
||||
}
|
||||
|
||||
ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
|
||||
if (ea == null) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.algorithmNotRegistered") + URI);
|
||||
}
|
||||
} else {
|
||||
// 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"));
|
||||
}
|
||||
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
ea.convertToCharacters(data, sb);
|
||||
return sb;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.fastinfoset.sax;
|
||||
|
||||
public class Features {
|
||||
public static final String NAMESPACES_FEATURE =
|
||||
"http://xml.org/sax/features/namespaces";
|
||||
public static final String NAMESPACE_PREFIXES_FEATURE =
|
||||
"http://xml.org/sax/features/namespace-prefixes";
|
||||
public static final String STRING_INTERNING_FEATURE =
|
||||
"http://xml.org/sax/features/string-interning";
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.fastinfoset.sax;
|
||||
|
||||
public class Properties {
|
||||
public static final String LEXICAL_HANDLER_PROPERTY =
|
||||
"http://xml.org/sax/properties/lexical-handler";
|
||||
public static final String DTD_DECLARATION_HANDLER_PROPERTY =
|
||||
"http://xml.org/sax/properties/declaration-handler";
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,597 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.fastinfoset.sax;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.Encoder;
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.sax.FastInfosetWriter;
|
||||
import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
|
||||
import java.io.IOException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.RestrictedAlphabet;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmAttributes;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
/**
|
||||
* The Fast Infoset SAX serializer.
|
||||
* <p>
|
||||
* Instantiate this serializer to serialize a fast infoset document in accordance
|
||||
* with the SAX API.
|
||||
* <p>
|
||||
* This utilizes the SAX API in a reverse manner to that of parsing. It is the
|
||||
* responsibility of the client to call the appropriate event methods on the
|
||||
* SAX handlers, and to ensure that such a sequence of methods calls results
|
||||
* in the production well-formed fast infoset documents. The
|
||||
* SAXDocumentSerializer performs no well-formed checks.
|
||||
*
|
||||
* <p>
|
||||
* More than one fast infoset document may be encoded to the
|
||||
* {@link java.io.OutputStream}.
|
||||
*/
|
||||
public class SAXDocumentSerializer extends Encoder implements FastInfosetWriter {
|
||||
protected boolean _elementHasNamespaces = false;
|
||||
|
||||
protected boolean _charactersAsCDATA = false;
|
||||
|
||||
protected SAXDocumentSerializer(boolean v) {
|
||||
super(v);
|
||||
}
|
||||
|
||||
public SAXDocumentSerializer() {
|
||||
}
|
||||
|
||||
|
||||
public void reset() {
|
||||
super.reset();
|
||||
|
||||
_elementHasNamespaces = false;
|
||||
_charactersAsCDATA = false;
|
||||
}
|
||||
|
||||
// ContentHandler
|
||||
|
||||
public final void startDocument() throws SAXException {
|
||||
try {
|
||||
reset();
|
||||
encodeHeader(false);
|
||||
encodeInitialVocabulary();
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startDocument", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void endDocument() throws SAXException {
|
||||
try {
|
||||
encodeDocumentTermination();
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("endDocument", e);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public final void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
|
||||
// TODO consider using buffer for encoding of attributes, then pre-counting is not necessary
|
||||
final int attributeCount = (atts != null && atts.getLength() > 0)
|
||||
? countAttributes(atts) : 0;
|
||||
try {
|
||||
if (_elementHasNamespaces) {
|
||||
_elementHasNamespaces = false;
|
||||
|
||||
if (attributeCount > 0) {
|
||||
// Flag the marked byte with attributes
|
||||
_octetBuffer[_markIndex] |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
|
||||
}
|
||||
resetMark();
|
||||
|
||||
write(EncodingConstants.TERMINATOR);
|
||||
|
||||
_b = 0;
|
||||
} else {
|
||||
encodeTermination();
|
||||
|
||||
_b = EncodingConstants.ELEMENT;
|
||||
if (attributeCount > 0) {
|
||||
_b |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
encodeElement(namespaceURI, qName, localName);
|
||||
|
||||
if (attributeCount > 0) {
|
||||
encodeAttributes(atts);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startElement", e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException("startElement", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void endElement(String namespaceURI, String localName, String qName) throws SAXException {
|
||||
try {
|
||||
encodeElementTermination();
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("endElement", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(ch, start, length)) return;
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
if (!_charactersAsCDATA) {
|
||||
encodeCharacters(ch, start, length);
|
||||
} else {
|
||||
encodeCIIBuiltInAlgorithmDataAsCDATA(ch, start, length);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
||||
if (getIgnoreWhiteSpaceTextContent()) return;
|
||||
|
||||
characters(ch, start, length);
|
||||
}
|
||||
|
||||
public final void processingInstruction(String target, String data) throws SAXException {
|
||||
try {
|
||||
if (getIgnoreProcesingInstructions()) return;
|
||||
|
||||
if (target.length() == 0) {
|
||||
throw new SAXException(CommonResourceBundle.getInstance().
|
||||
getString("message.processingInstructionTargetIsEmpty"));
|
||||
}
|
||||
encodeTermination();
|
||||
|
||||
encodeProcessingInstruction(target, data);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("processingInstruction", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void setDocumentLocator(org.xml.sax.Locator locator) {
|
||||
}
|
||||
|
||||
public final void skippedEntity(String name) throws SAXException {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// LexicalHandler
|
||||
|
||||
public final void comment(char[] ch, int start, int length) throws SAXException {
|
||||
try {
|
||||
if (getIgnoreComments()) return;
|
||||
|
||||
encodeTermination();
|
||||
|
||||
encodeComment(ch, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startElement", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void startCDATA() throws SAXException {
|
||||
_charactersAsCDATA = true;
|
||||
}
|
||||
|
||||
public final void endCDATA() throws SAXException {
|
||||
_charactersAsCDATA = false;
|
||||
}
|
||||
|
||||
public final void startDTD(String name, String publicId, String systemId) throws SAXException {
|
||||
if (getIgnoreDTD()) return;
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeDocumentTypeDeclaration(publicId, systemId);
|
||||
encodeElementTermination();
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startDTD", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void endDTD() throws SAXException {
|
||||
}
|
||||
|
||||
public final void startEntity(String name) throws SAXException {
|
||||
}
|
||||
|
||||
public final void endEntity(String name) throws SAXException {
|
||||
}
|
||||
|
||||
|
||||
// EncodingAlgorithmContentHandler
|
||||
|
||||
public final void octets(String URI, int id, byte[] b, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeNonIdentifyingStringOnThirdBit(URI, id, b, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void object(String URI, int id, Object data) throws SAXException {
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeNonIdentifyingStringOnThirdBit(URI, id, data);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PrimitiveTypeContentHandler
|
||||
|
||||
public final void bytes(byte[] b, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIOctetAlgorithmData(EncodingAlgorithmIndexes.BASE64, b, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void shorts(short[] s, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.SHORT, s, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void ints(int[] i, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.INT, i, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void longs(long[] l, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.LONG, l, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void booleans(boolean[] b, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.BOOLEAN, b, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void floats(float[] f, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.FLOAT, f, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void doubles(double[] d, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.DOUBLE, d, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void uuids(long[] msblsb, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.UUID, msblsb, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// RestrictedAlphabetContentHandler
|
||||
|
||||
public void numericCharacters(char ch[], int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
final boolean addToTable = isCharacterContentChunkLengthMatchesLimit(length);
|
||||
encodeNumericFourBitCharacters(ch, start, length, addToTable);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void dateTimeCharacters(char ch[], int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
final boolean addToTable = isCharacterContentChunkLengthMatchesLimit(length);
|
||||
encodeDateTimeFourBitCharacters(ch, start, length, addToTable);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void alphabetCharacters(String alphabet, char ch[], int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
final boolean addToTable = isCharacterContentChunkLengthMatchesLimit(length);
|
||||
encodeAlphabetCharacters(alphabet, ch, start, length, addToTable);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// ExtendedContentHandler
|
||||
|
||||
public void characters(char[] ch, int start, int length, boolean index) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(ch, start, length)) return;
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
if (!_charactersAsCDATA) {
|
||||
encodeNonIdentifyingStringOnThirdBit(ch, start, length, _v.characterContentChunk, index, true);
|
||||
} else {
|
||||
encodeCIIBuiltInAlgorithmDataAsCDATA(ch, start, length);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected final int countAttributes(Attributes atts) {
|
||||
// Count attributes ignoring any in the XMLNS namespace
|
||||
// Note, such attributes may be produced when transforming from a DOM node
|
||||
int count = 0;
|
||||
for (int i = 0; i < atts.getLength(); i++) {
|
||||
final String uri = atts.getURI(i);
|
||||
if (uri == "http://www.w3.org/2000/xmlns/" || uri.equals("http://www.w3.org/2000/xmlns/")) {
|
||||
continue;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
protected void encodeAttributes(Attributes atts) throws IOException, FastInfosetException {
|
||||
boolean addToTable;
|
||||
boolean mustBeAddedToTable;
|
||||
String value;
|
||||
if (atts instanceof EncodingAlgorithmAttributes) {
|
||||
final EncodingAlgorithmAttributes eAtts = (EncodingAlgorithmAttributes)atts;
|
||||
Object data;
|
||||
String alphabet;
|
||||
for (int i = 0; i < eAtts.getLength(); i++) {
|
||||
if (encodeAttribute(atts.getURI(i), atts.getQName(i), atts.getLocalName(i))) {
|
||||
data = eAtts.getAlgorithmData(i);
|
||||
// If data is null then there is no algorithm data
|
||||
if (data == null) {
|
||||
value = eAtts.getValue(i);
|
||||
addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
mustBeAddedToTable = eAtts.getToIndex(i);
|
||||
|
||||
alphabet = eAtts.getAlpababet(i);
|
||||
if (alphabet == null) {
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustBeAddedToTable);
|
||||
} else if (alphabet == RestrictedAlphabet.DATE_TIME_CHARACTERS) {
|
||||
encodeDateTimeNonIdentifyingStringOnFirstBit(
|
||||
value, addToTable, mustBeAddedToTable);
|
||||
} else if (alphabet == RestrictedAlphabet.NUMERIC_CHARACTERS) {
|
||||
encodeNumericNonIdentifyingStringOnFirstBit(
|
||||
value, addToTable, mustBeAddedToTable);
|
||||
} else {
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustBeAddedToTable);
|
||||
}
|
||||
} else {
|
||||
encodeNonIdentifyingStringOnFirstBit(eAtts.getAlgorithmURI(i),
|
||||
eAtts.getAlgorithmIndex(i), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < atts.getLength(); i++) {
|
||||
if (encodeAttribute(atts.getURI(i), atts.getQName(i), atts.getLocalName(i))) {
|
||||
value = atts.getValue(i);
|
||||
addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
_b = EncodingConstants.TERMINATOR;
|
||||
_terminate = true;
|
||||
}
|
||||
|
||||
protected void encodeElement(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.elementName.obtainEntry(qName);
|
||||
if (entry._valueIndex > 0) {
|
||||
QualifiedName[] names = entry._value;
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
final QualifiedName n = names[i];
|
||||
if ((namespaceURI == n.namespaceName || namespaceURI.equals(n.namespaceName))) {
|
||||
encodeNonZeroIntegerOnThirdBit(names[i].index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
encodeLiteralElementQualifiedNameOnThirdBit(namespaceURI, getPrefixFromQualifiedName(qName),
|
||||
localName, entry);
|
||||
}
|
||||
|
||||
protected boolean encodeAttribute(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.attributeName.obtainEntry(qName);
|
||||
if (entry._valueIndex > 0) {
|
||||
QualifiedName[] names = entry._value;
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
if ((namespaceURI == names[i].namespaceName || namespaceURI.equals(names[i].namespaceName))) {
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitZero(names[i].index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return encodeLiteralAttributeQualifiedNameOnSecondBit(namespaceURI, getPrefixFromQualifiedName(qName),
|
||||
localName, entry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.fastinfoset.sax;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.util.KeyIntMap;
|
||||
import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
|
||||
import com.sun.xml.internal.fastinfoset.util.StringIntMap;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import org.xml.sax.SAXException;
|
||||
import java.util.Map;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.RestrictedAlphabet;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmAttributes;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
* The Fast Infoset SAX serializer that maps prefixes to user specified prefixes
|
||||
* that are specified in a namespace URI to prefix map.
|
||||
* <p>
|
||||
* This serializer will not preserve the original prefixes and this serializer
|
||||
* should not be used when prefixes need to be preserved, such as the case
|
||||
* when there are qualified names in content.
|
||||
* <p>
|
||||
* A namespace URI to prefix map is utilized such that the prefixes
|
||||
* in the map are utilized rather than the prefixes specified in
|
||||
* the qualified name for elements and attributes.
|
||||
* <p>
|
||||
* Any namespace declarations with a namespace URI that is not present in
|
||||
* the map are added.
|
||||
* <p>
|
||||
*/
|
||||
public class SAXDocumentSerializerWithPrefixMapping extends SAXDocumentSerializer {
|
||||
protected Map _namespaceToPrefixMapping;
|
||||
protected Map _prefixToPrefixMapping;
|
||||
protected String _lastCheckedNamespace;
|
||||
protected String _lastCheckedPrefix;
|
||||
|
||||
protected StringIntMap _declaredNamespaces;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public final 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);
|
||||
|
||||
_declaredNamespaces.clear();
|
||||
_declaredNamespaces.obtainIndex(uri);
|
||||
} else {
|
||||
if (_declaredNamespaces.obtainIndex(uri) != KeyIntMap.NOT_PRESENT) {
|
||||
final String p = getPrefix(uri);
|
||||
if (p != null) {
|
||||
_prefixToPrefixMapping.put(prefix, p);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final String p = getPrefix(uri);
|
||||
if (p != null) {
|
||||
encodeNamespaceAttribute(p, uri);
|
||||
_prefixToPrefixMapping.put(prefix, p);
|
||||
} else {
|
||||
putPrefix(uri, prefix);
|
||||
encodeNamespaceAttribute(prefix, uri);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startElement", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void encodeElement(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.elementName.obtainEntry(localName);
|
||||
if (entry._valueIndex > 0) {
|
||||
if (encodeElementMapEntry(entry, namespaceURI)) return;
|
||||
// Check the entry is a member of the read only map
|
||||
if (_v.elementName.isQNameFromReadOnlyMap(entry._value[0])) {
|
||||
entry = _v.elementName.obtainDynamicEntry(localName);
|
||||
if (entry._valueIndex > 0) {
|
||||
if (encodeElementMapEntry(entry, namespaceURI)) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
encodeLiteralElementQualifiedNameOnThirdBit(namespaceURI, getPrefix(namespaceURI),
|
||||
localName, entry);
|
||||
}
|
||||
|
||||
protected boolean encodeElementMapEntry(LocalNameQualifiedNamesMap.Entry entry, String namespaceURI) throws IOException {
|
||||
QualifiedName[] names = entry._value;
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
if ((namespaceURI == names[i].namespaceName || namespaceURI.equals(names[i].namespaceName))) {
|
||||
encodeNonZeroIntegerOnThirdBit(names[i].index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected final void encodeAttributes(Attributes atts) throws IOException, FastInfosetException {
|
||||
boolean addToTable;
|
||||
boolean mustToBeAddedToTable;
|
||||
String value;
|
||||
if (atts instanceof EncodingAlgorithmAttributes) {
|
||||
final EncodingAlgorithmAttributes eAtts = (EncodingAlgorithmAttributes)atts;
|
||||
Object data;
|
||||
String alphabet;
|
||||
for (int i = 0; i < eAtts.getLength(); i++) {
|
||||
final String uri = atts.getURI(i);
|
||||
if (encodeAttribute(uri, atts.getQName(i), atts.getLocalName(i))) {
|
||||
data = eAtts.getAlgorithmData(i);
|
||||
// If data is null then there is no algorithm data
|
||||
if (data == null) {
|
||||
value = eAtts.getValue(i);
|
||||
addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
mustToBeAddedToTable = eAtts.getToIndex(i);
|
||||
alphabet = eAtts.getAlpababet(i);
|
||||
if (alphabet == null) {
|
||||
if (uri == "http://www.w3.org/2001/XMLSchema-instance" ||
|
||||
uri.equals("http://www.w3.org/2001/XMLSchema-instance")) {
|
||||
value = convertQName(value);
|
||||
}
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustToBeAddedToTable);
|
||||
} else if (alphabet == RestrictedAlphabet.DATE_TIME_CHARACTERS) {
|
||||
encodeDateTimeNonIdentifyingStringOnFirstBit(
|
||||
value, addToTable, mustToBeAddedToTable);
|
||||
} else if (alphabet == RestrictedAlphabet.NUMERIC_CHARACTERS) {
|
||||
encodeNumericNonIdentifyingStringOnFirstBit(
|
||||
value, addToTable, mustToBeAddedToTable);
|
||||
} else {
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustToBeAddedToTable);
|
||||
}
|
||||
} else {
|
||||
encodeNonIdentifyingStringOnFirstBit(eAtts.getAlgorithmURI(i),
|
||||
eAtts.getAlgorithmIndex(i), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < atts.getLength(); i++) {
|
||||
final String uri = atts.getURI(i);
|
||||
if (encodeAttribute(atts.getURI(i), atts.getQName(i), atts.getLocalName(i))) {
|
||||
value = atts.getValue(i);
|
||||
addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
|
||||
if (uri == "http://www.w3.org/2001/XMLSchema-instance" ||
|
||||
uri.equals("http://www.w3.org/2001/XMLSchema-instance")) {
|
||||
value = convertQName(value);
|
||||
}
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
_b = EncodingConstants.TERMINATOR;
|
||||
_terminate = true;
|
||||
}
|
||||
|
||||
private String convertQName(String qName) {
|
||||
int i = qName.indexOf(':');
|
||||
String prefix = "";
|
||||
String localName = qName;
|
||||
if (i != -1) {
|
||||
prefix = qName.substring(0, i);
|
||||
localName = qName.substring(i + 1);
|
||||
}
|
||||
|
||||
String p = (String)_prefixToPrefixMapping.get(prefix);
|
||||
if (p != null) {
|
||||
if (p.length() == 0)
|
||||
return localName;
|
||||
else
|
||||
return p + ":" + localName;
|
||||
} else {
|
||||
return qName;
|
||||
}
|
||||
}
|
||||
|
||||
protected final boolean encodeAttribute(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.attributeName.obtainEntry(localName);
|
||||
if (entry._valueIndex > 0) {
|
||||
if (encodeAttributeMapEntry(entry, namespaceURI)) return true;
|
||||
// Check the entry is a member of the read only map
|
||||
if (_v.attributeName.isQNameFromReadOnlyMap(entry._value[0])) {
|
||||
entry = _v.attributeName.obtainDynamicEntry(localName);
|
||||
if (entry._valueIndex > 0) {
|
||||
if (encodeAttributeMapEntry(entry, namespaceURI)) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return encodeLiteralAttributeQualifiedNameOnSecondBit(namespaceURI, getPrefix(namespaceURI),
|
||||
localName, entry);
|
||||
}
|
||||
|
||||
protected boolean encodeAttributeMapEntry(LocalNameQualifiedNamesMap.Entry entry, String namespaceURI) throws IOException {
|
||||
QualifiedName[] names = entry._value;
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
if ((namespaceURI == names[i].namespaceName || namespaceURI.equals(names[i].namespaceName))) {
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitZero(names[i].index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected final String getPrefix(String namespaceURI) {
|
||||
if (_lastCheckedNamespace == namespaceURI) return _lastCheckedPrefix;
|
||||
|
||||
_lastCheckedNamespace = namespaceURI;
|
||||
return _lastCheckedPrefix = (String)_namespaceToPrefixMapping.get(namespaceURI);
|
||||
}
|
||||
|
||||
protected final void putPrefix(String namespaceURI, String prefix) {
|
||||
_namespaceToPrefixMapping.put(namespaceURI, prefix);
|
||||
|
||||
_lastCheckedNamespace = namespaceURI;
|
||||
_lastCheckedPrefix = prefix;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.fastinfoset.sax;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class SystemIdResolver {
|
||||
|
||||
public SystemIdResolver() {
|
||||
}
|
||||
|
||||
public static String getAbsoluteURIFromRelative(String localPath) {
|
||||
if (localPath == null || localPath.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String absolutePath = localPath;
|
||||
if (!isAbsolutePath(localPath)) {
|
||||
try {
|
||||
absolutePath = getAbsolutePathFromRelativePath(localPath);
|
||||
}
|
||||
catch (SecurityException se) {
|
||||
return "file:" + localPath;
|
||||
}
|
||||
}
|
||||
|
||||
String urlString;
|
||||
if (null != absolutePath) {
|
||||
urlString = absolutePath.startsWith(File.separator) ?
|
||||
("file://" + absolutePath) :
|
||||
("file:///" + absolutePath);
|
||||
}
|
||||
else {
|
||||
urlString = "file:" + localPath;
|
||||
}
|
||||
|
||||
return replaceChars(urlString);
|
||||
}
|
||||
|
||||
private static String getAbsolutePathFromRelativePath(String relativePath) {
|
||||
return new File(relativePath).getAbsolutePath();
|
||||
}
|
||||
|
||||
public static boolean isAbsoluteURI(String systemId) {
|
||||
if (systemId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isWindowsAbsolutePath(systemId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final int fragmentIndex = systemId.indexOf('#');
|
||||
final int queryIndex = systemId.indexOf('?');
|
||||
final int slashIndex = systemId.indexOf('/');
|
||||
final int colonIndex = systemId.indexOf(':');
|
||||
|
||||
int index = systemId.length() -1;
|
||||
if (fragmentIndex > 0) {
|
||||
index = fragmentIndex;
|
||||
}
|
||||
if (queryIndex > 0 && queryIndex < index) {
|
||||
index = queryIndex;
|
||||
}
|
||||
if (slashIndex > 0 && slashIndex <index) {
|
||||
index = slashIndex;
|
||||
}
|
||||
return (colonIndex > 0) && (colonIndex < index);
|
||||
}
|
||||
|
||||
public static boolean isAbsolutePath(String systemId) {
|
||||
if(systemId == null)
|
||||
return false;
|
||||
final File file = new File(systemId);
|
||||
return file.isAbsolute();
|
||||
|
||||
}
|
||||
|
||||
private static boolean isWindowsAbsolutePath(String systemId) {
|
||||
if(!isAbsolutePath(systemId))
|
||||
return false;
|
||||
if (systemId.length() > 2
|
||||
&& systemId.charAt(1) == ':'
|
||||
&& Character.isLetter(systemId.charAt(0))
|
||||
&& (systemId.charAt(2) == '\\' || systemId.charAt(2) == '/'))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String replaceChars(String str) {
|
||||
StringBuffer buf = new StringBuffer(str);
|
||||
int length = buf.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
char currentChar = buf.charAt(i);
|
||||
// Replace space with "%20"
|
||||
if (currentChar == ' ') {
|
||||
buf.setCharAt(i, '%');
|
||||
buf.insert(i+1, "20");
|
||||
length = length + 2;
|
||||
i = i + 2;
|
||||
}
|
||||
// Replace backslash with forward slash
|
||||
else if (currentChar == '\\') {
|
||||
buf.setCharAt(i, '/');
|
||||
}
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String getAbsoluteURI(String systemId) {
|
||||
String absoluteURI = systemId;
|
||||
if (isAbsoluteURI(systemId)) {
|
||||
if (systemId.startsWith("file:")) {
|
||||
String str = systemId.substring(5);
|
||||
|
||||
if (str != null && str.startsWith("/")) {
|
||||
if (str.startsWith("///") || !str.startsWith("//")) {
|
||||
int secondColonIndex = systemId.indexOf(':', 5);
|
||||
if (secondColonIndex > 0) {
|
||||
String localPath = systemId.substring(secondColonIndex-1);
|
||||
try {
|
||||
if (!isAbsolutePath(localPath))
|
||||
absoluteURI = systemId.substring(0, secondColonIndex-1) +
|
||||
getAbsolutePathFromRelativePath(localPath);
|
||||
}
|
||||
catch (SecurityException se) {
|
||||
return systemId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return getAbsoluteURIFromRelative(systemId.substring(5));
|
||||
}
|
||||
|
||||
return replaceChars(absoluteURI);
|
||||
}
|
||||
else {
|
||||
return systemId;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return getAbsoluteURIFromRelative(systemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user