first commit

This commit is contained in:
2025-07-28 13:56:49 +05:30
commit e9eb805edb
3438 changed files with 520990 additions and 0 deletions

View File

@@ -0,0 +1,752 @@
package org.apache.xerces.parsers;
import java.io.IOException;
import java.util.Locale;
import org.apache.xerces.impl.xs.psvi.PSVIProvider;
import org.apache.xerces.util.EntityResolverWrapper;
import org.apache.xerces.util.ErrorHandlerWrapper;
import org.apache.xerces.util.SymbolHash;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XMLResourceIdentifier;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLConfigurationException;
import org.apache.xerces.xni.parser.XMLEntityResolver;
import org.apache.xerces.xni.parser.XMLErrorHandler;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.xni.parser.XMLParseException;
import org.apache.xerces.xni.parser.XMLParserConfiguration;
import org.apache.xerces.xni.psvi.AttributePSVI;
import org.apache.xerces.xni.psvi.ElementPSVI;
import org.xml.sax.AttributeList;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.DocumentHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.Parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.LocatorImpl;
public abstract class AbstractSAXParser extends AbstractXMLDocumentParser implements PSVIProvider, Parser, XMLReader {
protected static final String NAMESPACES = "http://xml.org/sax/features/namespaces";
protected static final String NAMESPACE_PREFIXES = "http://xml.org/sax/features/namespace-prefixes";
protected static final String STRING_INTERNING = "http://xml.org/sax/features/string-interning";
private static final String[] RECOGNIZED_FEATURES = new String[] { "http://xml.org/sax/features/namespaces", "http://xml.org/sax/features/namespace-prefixes", "http://xml.org/sax/features/string-interning" };
protected static final String LEXICAL_HANDLER = "http://xml.org/sax/properties/lexical-handler";
protected static final String DECLARATION_HANDLER = "http://xml.org/sax/properties/declaration-handler";
protected static final String DOM_NODE = "http://xml.org/sax/properties/dom-node";
private static final String[] RECOGNIZED_PROPERTIES = new String[] { "http://xml.org/sax/properties/lexical-handler", "http://xml.org/sax/properties/declaration-handler", "http://xml.org/sax/properties/dom-node" };
protected boolean fNamespaces;
protected boolean fNamespacePrefixes = false;
protected ContentHandler fContentHandler;
protected DocumentHandler fDocumentHandler;
protected NamespaceContext fNamespaceContext;
protected DTDHandler fDTDHandler;
protected DeclHandler fDeclHandler;
protected LexicalHandler fLexicalHandler;
protected QName fQName = new QName();
protected boolean fParseInProgress = false;
private final AttributesProxy fAttributesProxy = new AttributesProxy();
private Augmentations fAugmentations = null;
private static final int BUFFER_SIZE = 20;
private char[] fCharBuffer = new char[20];
protected SymbolHash fDeclaredAttrs = null;
protected AbstractSAXParser(XMLParserConfiguration config) {
super(config);
config.addRecognizedFeatures(RECOGNIZED_FEATURES);
config.addRecognizedProperties(RECOGNIZED_PROPERTIES);
}
public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException {
this.fNamespaceContext = namespaceContext;
try {
if (this.fDocumentHandler != null) {
if (locator != null)
this.fDocumentHandler.setDocumentLocator(new LocatorProxy(locator));
this.fDocumentHandler.startDocument();
}
if (this.fContentHandler != null) {
if (locator != null)
this.fContentHandler.setDocumentLocator(new LocatorProxy(locator));
this.fContentHandler.startDocument();
}
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void doctypeDecl(String rootElement, String publicId, String systemId, Augmentations augs) throws XNIException {
this.fInDTD = true;
try {
if (this.fLexicalHandler != null)
this.fLexicalHandler.startDTD(rootElement, publicId, systemId);
} catch (SAXException e) {
throw new XNIException(e);
}
if (this.fDeclHandler != null)
this.fDeclaredAttrs = new SymbolHash();
}
public void startGeneralEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs) throws XNIException {
startParameterEntity(name, identifier, encoding, augs);
}
public void endGeneralEntity(String name, Augmentations augs) throws XNIException {
endParameterEntity(name, augs);
}
public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
try {
if (this.fDocumentHandler != null) {
this.fAttributesProxy.setAttributes(attributes);
this.fDocumentHandler.startElement(element.rawname, this.fAttributesProxy);
}
if (this.fContentHandler != null) {
startNamespaceMapping();
this.fAugmentations = augs;
int len = attributes.getLength();
for (int i = len - 1; i >= 0; i--) {
attributes.getName(i, this.fQName);
if ((this.fQName.prefix != null && this.fQName.prefix.equals("xmlns")) || this.fQName.rawname.equals("xmlns")) {
if (!this.fNamespacePrefixes)
attributes.removeAttributeAt(i);
if (this.fNamespaces && this.fNamespacePrefixes) {
this.fQName.prefix = "";
this.fQName.uri = "";
this.fQName.localpart = "";
attributes.setName(i, this.fQName);
}
}
}
String uri = (element.uri != null) ? element.uri : "";
String localpart = this.fNamespaces ? element.localpart : "";
this.fAttributesProxy.setAttributes(attributes);
this.fContentHandler.startElement(uri, localpart, element.rawname, this.fAttributesProxy);
}
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void characters(XMLString text, Augmentations augs) throws XNIException {
if (text.length == 0)
return;
try {
if (this.fDocumentHandler != null)
this.fDocumentHandler.characters(text.ch, text.offset, text.length);
if (this.fContentHandler != null)
this.fContentHandler.characters(text.ch, text.offset, text.length);
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException {
try {
if (this.fDocumentHandler != null)
this.fDocumentHandler.ignorableWhitespace(text.ch, text.offset, text.length);
if (this.fContentHandler != null)
this.fContentHandler.ignorableWhitespace(text.ch, text.offset, text.length);
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void endElement(QName element, Augmentations augs) throws XNIException {
try {
if (this.fDocumentHandler != null)
this.fDocumentHandler.endElement(element.rawname);
if (this.fContentHandler != null) {
this.fAugmentations = augs;
String uri = (element.uri != null) ? element.uri : "";
String localpart = this.fNamespaces ? element.localpart : "";
this.fContentHandler.endElement(uri, localpart, element.rawname);
endNamespaceMapping();
}
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void startCDATA(Augmentations augs) throws XNIException {
try {
if (this.fLexicalHandler != null)
this.fLexicalHandler.startCDATA();
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void endCDATA(Augmentations augs) throws XNIException {
try {
if (this.fLexicalHandler != null)
this.fLexicalHandler.endCDATA();
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void comment(XMLString text, Augmentations augs) throws XNIException {
try {
if (this.fLexicalHandler != null)
this.fLexicalHandler.comment(text.ch, 0, text.length);
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException {
try {
if (this.fDocumentHandler != null)
this.fDocumentHandler.processingInstruction(target, data.toString());
if (this.fContentHandler != null)
this.fContentHandler.processingInstruction(target, data.toString());
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void endDocument(Augmentations augs) throws XNIException {
try {
if (this.fDocumentHandler != null)
this.fDocumentHandler.endDocument();
if (this.fContentHandler != null)
this.fContentHandler.endDocument();
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void startExternalSubset(XMLResourceIdentifier identifier, Augmentations augs) throws XNIException {
startParameterEntity("[dtd]", (XMLResourceIdentifier)null, (String)null, augs);
}
public void endExternalSubset(Augmentations augs) throws XNIException {
endParameterEntity("[dtd]", augs);
}
public void startParameterEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs) throws XNIException {
try {
if (this.fLexicalHandler != null)
this.fLexicalHandler.startEntity(name);
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void endParameterEntity(String name, Augmentations augs) throws XNIException {
try {
if (this.fLexicalHandler != null)
this.fLexicalHandler.endEntity(name);
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void elementDecl(String name, String contentModel, Augmentations augs) throws XNIException {
try {
if (this.fDeclHandler != null)
this.fDeclHandler.elementDecl(name, contentModel);
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void attributeDecl(String elementName, String attributeName, String type, String[] enumeration, String defaultType, XMLString defaultValue, XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException {
try {
if (this.fDeclHandler != null) {
String elemAttr = elementName + "<" + attributeName;
if (this.fDeclaredAttrs.get(elemAttr) != null)
return;
this.fDeclaredAttrs.put(elemAttr, Boolean.TRUE);
if (type.equals("NOTATION") || type.equals("ENUMERATION")) {
StringBuffer str = new StringBuffer();
if (type.equals("NOTATION")) {
str.append(type);
str.append(" (");
} else {
str.append("(");
}
for (int i = 0; i < enumeration.length; i++) {
str.append(enumeration[i]);
if (i < enumeration.length - 1)
str.append('|');
}
str.append(')');
type = str.toString();
}
String value = (defaultValue == null) ? null : defaultValue.toString();
this.fDeclHandler.attributeDecl(elementName, attributeName, type, defaultType, value);
}
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void internalEntityDecl(String name, XMLString text, XMLString nonNormalizedText, Augmentations augs) throws XNIException {
try {
if (this.fDeclHandler != null)
this.fDeclHandler.internalEntityDecl(name, text.toString());
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void externalEntityDecl(String name, XMLResourceIdentifier identifier, Augmentations augs) throws XNIException {
String publicId = identifier.getPublicId();
String literalSystemId = identifier.getLiteralSystemId();
try {
if (this.fDeclHandler != null)
this.fDeclHandler.externalEntityDecl(name, publicId, literalSystemId);
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void unparsedEntityDecl(String name, XMLResourceIdentifier identifier, String notation, Augmentations augs) throws XNIException {
String publicId = identifier.getPublicId();
String expandedSystemId = identifier.getExpandedSystemId();
try {
if (this.fDTDHandler != null)
this.fDTDHandler.unparsedEntityDecl(name, publicId, expandedSystemId, notation);
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void notationDecl(String name, XMLResourceIdentifier identifier, Augmentations augs) throws XNIException {
String publicId = identifier.getPublicId();
String expandedSystemId = identifier.getExpandedSystemId();
try {
if (this.fDTDHandler != null)
this.fDTDHandler.notationDecl(name, publicId, expandedSystemId);
} catch (SAXException e) {
throw new XNIException(e);
}
}
public void endDTD(Augmentations augs) throws XNIException {
this.fInDTD = false;
try {
if (this.fLexicalHandler != null)
this.fLexicalHandler.endDTD();
} catch (SAXException e) {
throw new XNIException(e);
}
if (this.fDeclaredAttrs != null)
this.fDeclaredAttrs.clear();
}
public void parse(String systemId) throws SAXException, IOException {
XMLInputSource source = new XMLInputSource(null, systemId, null);
try {
parse(source);
} catch (XMLParseException e) {
Exception ex = e.getException();
if (ex == null) {
LocatorImpl locatorImpl = new LocatorImpl();
locatorImpl.setPublicId(e.getPublicId());
locatorImpl.setSystemId(e.getExpandedSystemId());
locatorImpl.setLineNumber(e.getLineNumber());
locatorImpl.setColumnNumber(e.getColumnNumber());
throw new SAXParseException(e.getMessage(), locatorImpl);
}
if (ex instanceof SAXException)
throw (SAXException)ex;
if (ex instanceof IOException)
throw (IOException)ex;
throw new SAXException(ex);
} catch (XNIException e) {
Exception ex = e.getException();
if (ex == null)
throw new SAXException(e.getMessage());
if (ex instanceof SAXException)
throw (SAXException)ex;
if (ex instanceof IOException)
throw (IOException)ex;
throw new SAXException(ex);
}
}
public void parse(InputSource inputSource) throws SAXException, IOException {
try {
XMLInputSource xmlInputSource = new XMLInputSource(inputSource.getPublicId(), inputSource.getSystemId(), null);
xmlInputSource.setByteStream(inputSource.getByteStream());
xmlInputSource.setCharacterStream(inputSource.getCharacterStream());
xmlInputSource.setEncoding(inputSource.getEncoding());
parse(xmlInputSource);
} catch (XMLParseException e) {
Exception ex = e.getException();
if (ex == null) {
LocatorImpl locatorImpl = new LocatorImpl();
locatorImpl.setPublicId(e.getPublicId());
locatorImpl.setSystemId(e.getExpandedSystemId());
locatorImpl.setLineNumber(e.getLineNumber());
locatorImpl.setColumnNumber(e.getColumnNumber());
throw new SAXParseException(e.getMessage(), locatorImpl);
}
if (ex instanceof SAXException)
throw (SAXException)ex;
if (ex instanceof IOException)
throw (IOException)ex;
throw new SAXException(ex);
} catch (XNIException e) {
Exception ex = e.getException();
if (ex == null)
throw new SAXException(e.getMessage());
if (ex instanceof SAXException)
throw (SAXException)ex;
if (ex instanceof IOException)
throw (IOException)ex;
throw new SAXException(ex);
}
}
public void setEntityResolver(EntityResolver resolver) {
if (resolver == null)
throw new NullPointerException();
try {
this.fConfiguration.setProperty("http://apache.org/xml/properties/internal/entity-resolver", new EntityResolverWrapper(resolver));
} catch (XMLConfigurationException e) {}
}
public EntityResolver getEntityResolver() {
EntityResolver entityResolver = null;
try {
XMLEntityResolver xmlEntityResolver = (XMLEntityResolver)this.fConfiguration.getProperty("http://apache.org/xml/properties/internal/entity-resolver");
if (xmlEntityResolver != null && xmlEntityResolver instanceof EntityResolverWrapper)
entityResolver = ((EntityResolverWrapper)xmlEntityResolver).getEntityResolver();
} catch (XMLConfigurationException e) {}
return entityResolver;
}
public void setErrorHandler(ErrorHandler errorHandler) {
if (errorHandler == null)
throw new NullPointerException();
try {
this.fConfiguration.setProperty("http://apache.org/xml/properties/internal/error-handler", new ErrorHandlerWrapper(errorHandler));
} catch (XMLConfigurationException e) {}
}
public ErrorHandler getErrorHandler() {
ErrorHandler errorHandler = null;
try {
XMLErrorHandler xmlErrorHandler = (XMLErrorHandler)this.fConfiguration.getProperty("http://apache.org/xml/properties/internal/error-handler");
if (xmlErrorHandler != null && xmlErrorHandler instanceof ErrorHandlerWrapper)
errorHandler = ((ErrorHandlerWrapper)xmlErrorHandler).getErrorHandler();
} catch (XMLConfigurationException e) {}
return errorHandler;
}
public void setLocale(Locale locale) throws SAXException {
this.fConfiguration.setLocale(locale);
}
public void setDTDHandler(DTDHandler dtdHandler) {
if (dtdHandler == null)
throw new NullPointerException();
this.fDTDHandler = dtdHandler;
}
public void setDocumentHandler(DocumentHandler documentHandler) {
this.fDocumentHandler = documentHandler;
}
public void setContentHandler(ContentHandler contentHandler) {
if (contentHandler == null)
throw new NullPointerException();
this.fContentHandler = contentHandler;
}
public ContentHandler getContentHandler() {
return this.fContentHandler;
}
public DTDHandler getDTDHandler() {
return this.fDTDHandler;
}
public void setFeature(String featureId, boolean state) throws SAXNotRecognizedException, SAXNotSupportedException {
try {
if (featureId.startsWith("http://xml.org/sax/features/")) {
String feature = featureId.substring("http://xml.org/sax/features/".length());
if (feature.equals("namespaces")) {
this.fConfiguration.setFeature(featureId, state);
this.fNamespaces = state;
return;
}
if (feature.equals("namespace-prefixes")) {
this.fConfiguration.setFeature(featureId, state);
this.fNamespacePrefixes = state;
return;
}
if (feature.equals("string-interning")) {
if (!state)
throw new SAXNotSupportedException("PAR018 " + state + " state for feature \"" + featureId + "\" is not supported.\n" + state + '\t' + featureId);
return;
}
}
this.fConfiguration.setFeature(featureId, state);
} catch (XMLConfigurationException e) {
String message = e.getMessage();
if (e.getType() == 0)
throw new SAXNotRecognizedException(message);
throw new SAXNotSupportedException(message);
}
}
public boolean getFeature(String featureId) throws SAXNotRecognizedException, SAXNotSupportedException {
try {
if (featureId.startsWith("http://xml.org/sax/features/")) {
String feature = featureId.substring("http://xml.org/sax/features/".length());
if (feature.equals("namespace-prefixes")) {
boolean state = this.fConfiguration.getFeature(featureId);
return state;
}
if (feature.equals("string-interning"))
return true;
}
return this.fConfiguration.getFeature(featureId);
} catch (XMLConfigurationException e) {
String message = e.getMessage();
if (e.getType() == 0)
throw new SAXNotRecognizedException(message);
throw new SAXNotSupportedException(message);
}
}
public void setProperty(String propertyId, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
try {
if (propertyId.startsWith("http://xml.org/sax/properties/")) {
String property = propertyId.substring("http://xml.org/sax/properties/".length());
if (property.equals("lexical-handler")) {
try {
setLexicalHandler((LexicalHandler)value);
} catch (ClassCastException e) {
throw new SAXNotSupportedException("PAR012 For propertyID \"" + propertyId + "\", the value \"" + value + "\" cannot be cast to LexicalHandler." + '\n' + propertyId + '\t' + value + "\tLexicalHandler");
}
return;
}
if (property.equals("declaration-handler")) {
try {
setDeclHandler((DeclHandler)value);
} catch (ClassCastException e) {
throw new SAXNotSupportedException("PAR012 For propertyID \"" + propertyId + "\", the value \"" + value + "\" cannot be cast to DeclHandler." + '\n' + propertyId + '\t' + value + "\tDeclHandler");
}
return;
}
if (property.equals("dom-node"))
throw new SAXNotSupportedException("PAR013 Property \"" + propertyId + "\" is read only." + '\n' + propertyId);
}
this.fConfiguration.setProperty(propertyId, value);
} catch (XMLConfigurationException e) {
String message = e.getMessage();
if (e.getType() == 0)
throw new SAXNotRecognizedException(message);
throw new SAXNotSupportedException(message);
}
}
public Object getProperty(String propertyId) throws SAXNotRecognizedException, SAXNotSupportedException {
try {
if (propertyId.startsWith("http://xml.org/sax/properties/")) {
String property = propertyId.substring("http://xml.org/sax/properties/".length());
if (property.equals("lexical-handler"))
return getLexicalHandler();
if (property.equals("declaration-handler"))
return getDeclHandler();
if (property.equals("dom-node"))
throw new SAXNotSupportedException("PAR014 Cannot getProperty(\"" + propertyId + "\". No DOM Tree exists.\n" + propertyId);
}
return this.fConfiguration.getProperty(propertyId);
} catch (XMLConfigurationException e) {
String message = e.getMessage();
if (e.getType() == 0)
throw new SAXNotRecognizedException(message);
throw new SAXNotSupportedException(message);
}
}
protected void setDeclHandler(DeclHandler handler) throws SAXNotRecognizedException, SAXNotSupportedException {
if (this.fParseInProgress)
throw new SAXNotSupportedException("PAR011 Feature: http://xml.org/sax/properties/declaration-handler is not supported during parse.\nhttp://xml.org/sax/properties/declaration-handler");
this.fDeclHandler = handler;
}
protected DeclHandler getDeclHandler() throws SAXNotRecognizedException, SAXNotSupportedException {
return this.fDeclHandler;
}
protected void setLexicalHandler(LexicalHandler handler) throws SAXNotRecognizedException, SAXNotSupportedException {
if (this.fParseInProgress)
throw new SAXNotSupportedException("PAR011 Feature: http://xml.org/sax/properties/lexical-handler is not supported during parse.\nhttp://xml.org/sax/properties/lexical-handler");
this.fLexicalHandler = handler;
}
protected LexicalHandler getLexicalHandler() throws SAXNotRecognizedException, SAXNotSupportedException {
return this.fLexicalHandler;
}
protected final void startNamespaceMapping() throws SAXException {
int count = this.fNamespaceContext.getDeclaredPrefixCount();
if (count > 0) {
String prefix = null;
String uri = null;
for (int i = 0; i < count; i++) {
prefix = this.fNamespaceContext.getDeclaredPrefixAt(i);
uri = this.fNamespaceContext.getURI(prefix);
this.fContentHandler.startPrefixMapping(prefix, (uri == null) ? "" : uri);
}
}
}
protected final void endNamespaceMapping() throws SAXException {
int count = this.fNamespaceContext.getDeclaredPrefixCount();
if (count > 0)
for (int i = 0; i < count; i++)
this.fContentHandler.endPrefixMapping(this.fNamespaceContext.getDeclaredPrefixAt(i));
}
public void reset() throws XNIException {
super.reset();
this.fInDTD = false;
this.fNamespaces = this.fConfiguration.getFeature("http://xml.org/sax/features/namespaces");
this.fNamespacePrefixes = this.fConfiguration.getFeature("http://xml.org/sax/features/namespace-prefixes");
this.fAugmentations = null;
this.fDeclaredAttrs = null;
}
protected static class LocatorProxy implements Locator {
protected XMLLocator fLocator;
public LocatorProxy(XMLLocator locator) {
this.fLocator = locator;
}
public String getPublicId() {
return this.fLocator.getPublicId();
}
public String getSystemId() {
return this.fLocator.getExpandedSystemId();
}
public int getLineNumber() {
return this.fLocator.getLineNumber();
}
public int getColumnNumber() {
return this.fLocator.getColumnNumber();
}
}
protected static final class AttributesProxy implements AttributeList, Attributes {
protected XMLAttributes fAttributes;
public void setAttributes(XMLAttributes attributes) {
this.fAttributes = attributes;
}
public int getLength() {
return this.fAttributes.getLength();
}
public String getName(int i) {
return this.fAttributes.getQName(i);
}
public String getQName(int index) {
return this.fAttributes.getQName(index);
}
public String getURI(int index) {
String uri = this.fAttributes.getURI(index);
return (uri != null) ? uri : "";
}
public String getLocalName(int index) {
return this.fAttributes.getLocalName(index);
}
public String getType(int i) {
return this.fAttributes.getType(i);
}
public String getType(String name) {
return this.fAttributes.getType(name);
}
public String getType(String uri, String localName) {
return uri.equals("") ? this.fAttributes.getType(null, localName) : this.fAttributes.getType(uri, localName);
}
public String getValue(int i) {
return this.fAttributes.getValue(i);
}
public String getValue(String name) {
return this.fAttributes.getValue(name);
}
public String getValue(String uri, String localName) {
return uri.equals("") ? this.fAttributes.getValue(null, localName) : this.fAttributes.getValue(uri, localName);
}
public int getIndex(String qName) {
return this.fAttributes.getIndex(qName);
}
public int getIndex(String uri, String localPart) {
return uri.equals("") ? this.fAttributes.getIndex(null, localPart) : this.fAttributes.getIndex(uri, localPart);
}
}
public ElementPSVI getElementPSVI() {
return (this.fAugmentations != null) ? (ElementPSVI)this.fAugmentations.getItem("ELEMENT_PSVI") : null;
}
public AttributePSVI getAttributePSVI(int index) {
return (AttributePSVI)this.fAttributesProxy.fAttributes.getAugmentations(index).getItem("ATTRIBUTE_PSVI");
}
public AttributePSVI getAttributePSVIByName(String uri, String localname) {
return (AttributePSVI)this.fAttributesProxy.fAttributes.getAugmentations(uri, localname).getItem("ATTRIBUTE_PSVI");
}
}

View File

@@ -0,0 +1,156 @@
package org.apache.xerces.parsers;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XMLDTDContentModelHandler;
import org.apache.xerces.xni.XMLDTDHandler;
import org.apache.xerces.xni.XMLDocumentHandler;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XMLResourceIdentifier;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLDTDContentModelSource;
import org.apache.xerces.xni.parser.XMLDTDSource;
import org.apache.xerces.xni.parser.XMLDocumentSource;
import org.apache.xerces.xni.parser.XMLParserConfiguration;
public abstract class AbstractXMLDocumentParser extends XMLParser implements XMLDocumentHandler, XMLDTDHandler, XMLDTDContentModelHandler {
protected boolean fInDTD;
protected XMLDocumentSource fDocumentSource;
protected XMLDTDSource fDTDSource;
protected XMLDTDContentModelSource fDTDContentModelSource;
protected AbstractXMLDocumentParser(XMLParserConfiguration config) {
super(config);
config.setDocumentHandler(this);
config.setDTDHandler(this);
config.setDTDContentModelHandler(this);
}
public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException {}
public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) throws XNIException {}
public void doctypeDecl(String rootElement, String publicId, String systemId, Augmentations augs) throws XNIException {}
public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {}
public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
startElement(element, attributes, augs);
endElement(element, augs);
}
public void characters(XMLString text, Augmentations augs) throws XNIException {}
public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException {}
public void endElement(QName element, Augmentations augs) throws XNIException {}
public void startCDATA(Augmentations augs) throws XNIException {}
public void endCDATA(Augmentations augs) throws XNIException {}
public void endDocument(Augmentations augs) throws XNIException {}
public void startGeneralEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs) throws XNIException {}
public void textDecl(String version, String encoding, Augmentations augs) throws XNIException {}
public void endGeneralEntity(String name, Augmentations augs) throws XNIException {}
public void comment(XMLString text, Augmentations augs) throws XNIException {}
public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException {}
public void setDocumentSource(XMLDocumentSource source) {
this.fDocumentSource = source;
}
public XMLDocumentSource getDocumentSource() {
return this.fDocumentSource;
}
public void startDTD(XMLLocator locator, Augmentations augs) throws XNIException {
this.fInDTD = true;
}
public void startExternalSubset(XMLResourceIdentifier identifier, Augmentations augmentations) throws XNIException {}
public void endExternalSubset(Augmentations augmentations) throws XNIException {}
public void startParameterEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs) throws XNIException {}
public void endParameterEntity(String name, Augmentations augs) throws XNIException {}
public void ignoredCharacters(XMLString text, Augmentations augs) throws XNIException {}
public void elementDecl(String name, String contentModel, Augmentations augs) throws XNIException {}
public void startAttlist(String elementName, Augmentations augs) throws XNIException {}
public void attributeDecl(String elementName, String attributeName, String type, String[] enumeration, String defaultType, XMLString defaultValue, XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException {}
public void endAttlist(Augmentations augs) throws XNIException {}
public void internalEntityDecl(String name, XMLString text, XMLString nonNormalizedText, Augmentations augs) throws XNIException {}
public void externalEntityDecl(String name, XMLResourceIdentifier identifier, Augmentations augs) throws XNIException {}
public void unparsedEntityDecl(String name, XMLResourceIdentifier identifier, String notation, Augmentations augs) throws XNIException {}
public void notationDecl(String name, XMLResourceIdentifier identifier, Augmentations augs) throws XNIException {}
public void startConditional(short type, Augmentations augs) throws XNIException {}
public void endConditional(Augmentations augs) throws XNIException {}
public void endDTD(Augmentations augs) throws XNIException {
this.fInDTD = false;
}
public void setDTDSource(XMLDTDSource source) {
this.fDTDSource = source;
}
public XMLDTDSource getDTDSource() {
return this.fDTDSource;
}
public void startContentModel(String elementName, Augmentations augs) throws XNIException {}
public void any(Augmentations augs) throws XNIException {}
public void empty(Augmentations augs) throws XNIException {}
public void startGroup(Augmentations augs) throws XNIException {}
public void pcdata(Augmentations augs) throws XNIException {}
public void element(String elementName, Augmentations augs) throws XNIException {}
public void separator(short separator, Augmentations augs) throws XNIException {}
public void occurrence(short occurrence, Augmentations augs) throws XNIException {}
public void endGroup(Augmentations augs) throws XNIException {}
public void endContentModel(Augmentations augs) throws XNIException {}
public void setDTDContentModelSource(XMLDTDContentModelSource source) {
this.fDTDContentModelSource = source;
}
public XMLDTDContentModelSource getDTDContentModelSource() {
return this.fDTDContentModelSource;
}
protected void reset() throws XNIException {
super.reset();
this.fInDTD = false;
}
}

View File

@@ -0,0 +1,189 @@
package org.apache.xerces.parsers;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
class ObjectFactory {
private static final String DEFAULT_PROPERTIES_FILENAME = "xerces.properties";
private static final boolean DEBUG = false;
private static Properties fXercesProperties = null;
private static long fLastModified = -1L;
static Object createObject(String factoryId, String fallbackClassName) throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
}
public static Object createObject(String factoryId, String propertiesFilename, String fallbackClassName) throws ConfigurationError {
debugPrintln("debug is on");
SecuritySupport ss = SecuritySupport.getInstance();
ClassLoader cl = findClassLoader();
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
debugPrintln("found system property, value=" + systemProp);
return newInstance(systemProp, cl, true);
}
} catch (SecurityException se) {}
String factoryClassName = null;
if (propertiesFilename == null) {
String javah = ss.getSystemProperty("java.home");
propertiesFilename = javah + File.separator + "lib" + File.separator + "xerces.properties";
File propertiesFile = new File(propertiesFilename);
boolean propertiesFileExists = ss.getFileExists(propertiesFile);
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
if (fLastModified >= 0L) {
if (propertiesFileExists && fLastModified < (fLastModified = ss.getLastModified(propertiesFile))) {
loadProperties = true;
} else if (!propertiesFileExists) {
fLastModified = -1L;
fXercesProperties = null;
}
} else if (propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
}
if (loadProperties)
try {
fXercesProperties = new Properties();
FileInputStream fis = ss.getFileInputStream(propertiesFile);
fXercesProperties.load(fis);
fis.close();
} catch (Exception x) {
fXercesProperties = null;
fLastModified = -1L;
}
}
if (fXercesProperties != null)
factoryClassName = fXercesProperties.getProperty(factoryId);
} else {
try {
FileInputStream fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
fis.close();
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {}
}
if (factoryClassName != null) {
debugPrintln("found in " + propertiesFilename + ", value=" + factoryClassName);
return newInstance(factoryClassName, cl, true);
}
Object provider = findJarServiceProvider(factoryId);
if (provider != null)
return provider;
if (fallbackClassName == null)
throw new ConfigurationError("Provider for " + factoryId + " cannot be found", null);
debugPrintln("using fallback, value=" + fallbackClassName);
return newInstance(fallbackClassName, cl, true);
}
private static void debugPrintln(String msg) {}
static ClassLoader findClassLoader() throws ConfigurationError {
SecuritySupport ss = SecuritySupport.getInstance();
ClassLoader cl = ss.getContextClassLoader();
if (cl == null)
cl = ObjectFactory.class.getClassLoader();
return cl;
}
static Object newInstance(String className, ClassLoader cl, boolean doFallback) throws ConfigurationError {
try {
Class providerClass = findProviderClass(className, cl, doFallback);
Object instance = providerClass.newInstance();
debugPrintln("created new instance of " + providerClass + " using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
throw new ConfigurationError("Provider " + className + " not found", x);
} catch (Exception x) {
throw new ConfigurationError("Provider " + className + " could not be instantiated: " + x, x);
}
}
static Class findProviderClass(String className, ClassLoader cl, boolean doFallback) throws ClassNotFoundException, ConfigurationError {
Class providerClass;
SecurityManager security = System.getSecurityManager();
try {
if (security != null)
security.checkPackageAccess(className);
} catch (SecurityException e) {
throw e;
}
if (cl == null) {
providerClass = Class.forName(className);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
cl = ObjectFactory.class.getClassLoader();
providerClass = cl.loadClass(className);
} else {
throw x;
}
}
}
return providerClass;
}
private static Object findJarServiceProvider(String factoryId) throws ConfigurationError {
BufferedReader rd;
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = "META-INF/services/" + factoryId;
InputStream is = null;
ClassLoader cl = ss.getContextClassLoader();
if (cl != null) {
is = ss.getResourceAsStream(cl, serviceId);
if (is == null) {
cl = ObjectFactory.class.getClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
}
} else {
cl = ObjectFactory.class.getClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
}
if (is == null)
return null;
debugPrintln("found jar resource=" + serviceId + " using ClassLoader: " + cl);
try {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = null;
try {
factoryClassName = rd.readLine();
rd.close();
} catch (IOException x) {
return null;
}
if (factoryClassName != null && !"".equals(factoryClassName)) {
debugPrintln("found in resource, value=" + factoryClassName);
return newInstance(factoryClassName, cl, false);
}
return null;
}
static class ConfigurationError extends Error {
private Exception exception;
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
}
Exception getException() {
return this.exception;
}
}
}

View File

@@ -0,0 +1,40 @@
package org.apache.xerces.parsers;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.xni.grammars.XMLGrammarPool;
import org.apache.xerces.xni.parser.XMLParserConfiguration;
public class SAXParser extends AbstractSAXParser {
protected static final String NOTIFY_BUILTIN_REFS = "http://apache.org/xml/features/scanner/notify-builtin-refs";
private static final String[] RECOGNIZED_FEATURES = new String[] { "http://apache.org/xml/features/scanner/notify-builtin-refs" };
protected static final String SYMBOL_TABLE = "http://apache.org/xml/properties/internal/symbol-table";
protected static final String XMLGRAMMAR_POOL = "http://apache.org/xml/properties/internal/grammar-pool";
private static final String[] RECOGNIZED_PROPERTIES = new String[] { "http://apache.org/xml/properties/internal/symbol-table", "http://apache.org/xml/properties/internal/grammar-pool" };
public SAXParser(XMLParserConfiguration config) {
super(config);
}
public SAXParser() {
this(null, null);
}
public SAXParser(SymbolTable symbolTable) {
this(symbolTable, null);
}
public SAXParser(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
super((XMLParserConfiguration)ObjectFactory.createObject("org.apache.xerces.xni.parser.XMLParserConfiguration", "org.apache.xerces.parsers.IntegratedParserConfiguration"));
this.fConfiguration.addRecognizedFeatures(RECOGNIZED_FEATURES);
this.fConfiguration.setFeature("http://apache.org/xml/features/scanner/notify-builtin-refs", true);
this.fConfiguration.addRecognizedProperties(RECOGNIZED_PROPERTIES);
if (symbolTable != null)
this.fConfiguration.setProperty("http://apache.org/xml/properties/internal/symbol-table", symbolTable);
if (grammarPool != null)
this.fConfiguration.setProperty("http://apache.org/xml/properties/internal/grammar-pool", grammarPool);
}
}

View File

@@ -0,0 +1,58 @@
package org.apache.xerces.parsers;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
class SecuritySupport {
private static final Object securitySupport;
static {
SecuritySupport ss = null;
try {
Class c = Class.forName("java.security.AccessController");
ss = new SecuritySupport12();
} catch (Exception ex) {
} finally {
if (ss == null)
ss = new SecuritySupport();
securitySupport = ss;
}
}
static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
ClassLoader getContextClassLoader() {
return null;
}
String getSystemProperty(String propName) {
return System.getProperty(propName);
}
FileInputStream getFileInputStream(File file) throws FileNotFoundException {
return new FileInputStream(file);
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
boolean getFileExists(File f) {
return f.exists();
}
long getLastModified(File f) {
return f.lastModified();
}
}

View File

@@ -0,0 +1,98 @@
package org.apache.xerces.parsers;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
class SecuritySupport12 extends SecuritySupport {
ClassLoader getContextClassLoader() {
return AccessController.<ClassLoader>doPrivileged(new PrivilegedAction(this) {
private final SecuritySupport12 this$0;
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) {}
return cl;
}
});
}
String getSystemProperty(String propName) {
return AccessController.<String>doPrivileged(new PrivilegedAction(this, propName) {
private final String val$propName;
private final SecuritySupport12 this$0;
public Object run() {
return System.getProperty(this.val$propName);
}
});
}
FileInputStream getFileInputStream(File file) throws FileNotFoundException {
try {
return AccessController.<FileInputStream>doPrivileged(new PrivilegedExceptionAction(this, file) {
private final File val$file;
private final SecuritySupport12 this$0;
public Object run() throws FileNotFoundException {
return new FileInputStream(this.val$file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
return AccessController.<InputStream>doPrivileged(new PrivilegedAction(this, cl, name) {
private final ClassLoader val$cl;
private final String val$name;
private final SecuritySupport12 this$0;
public Object run() {
InputStream ris;
if (this.val$cl == null) {
ris = ClassLoader.getSystemResourceAsStream(this.val$name);
} else {
ris = this.val$cl.getResourceAsStream(this.val$name);
}
return ris;
}
});
}
boolean getFileExists(File f) {
return ((Boolean)AccessController.<Boolean>doPrivileged(new PrivilegedAction(this, f) {
private final File val$f;
private final SecuritySupport12 this$0;
public Object run() {
return new Boolean(this.val$f.exists());
}
})).booleanValue();
}
long getLastModified(File f) {
return ((Long)AccessController.<Long>doPrivileged(new PrivilegedAction(this, f) {
private final File val$f;
private final SecuritySupport12 this$0;
public Object run() {
return new Long(this.val$f.lastModified());
}
})).longValue();
}
}

View File

@@ -0,0 +1,28 @@
package org.apache.xerces.parsers;
import java.io.IOException;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.xni.parser.XMLParserConfiguration;
public abstract class XMLParser {
protected static final String ENTITY_RESOLVER = "http://apache.org/xml/properties/internal/entity-resolver";
protected static final String ERROR_HANDLER = "http://apache.org/xml/properties/internal/error-handler";
private static final String[] RECOGNIZED_PROPERTIES = new String[] { "http://apache.org/xml/properties/internal/entity-resolver", "http://apache.org/xml/properties/internal/error-handler" };
protected XMLParserConfiguration fConfiguration;
protected XMLParser(XMLParserConfiguration config) {
this.fConfiguration = config;
this.fConfiguration.addRecognizedProperties(RECOGNIZED_PROPERTIES);
}
public void parse(XMLInputSource inputSource) throws XNIException, IOException {
reset();
this.fConfiguration.parse(inputSource);
}
protected void reset() throws XNIException {}
}