You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@locus.apache.org on 2000/02/07 22:40:10 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/parsers DOMParser.java SAXParser.java
andyc 00/02/07 13:40:10
Modified: java/samples/sax SAXCount.java
java/src/org/apache/xerces/framework XMLParser.java
java/src/org/apache/xerces/parsers DOMParser.java
SAXParser.java
Log:
Modifications for SAX2beta.
Revision Changes Path
1.2 +5 -5 xml-xerces/java/samples/sax/SAXCount.java
Index: SAXCount.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/samples/sax/SAXCount.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SAXCount.java 1999/11/09 01:13:47 1.1
+++ SAXCount.java 2000/02/07 21:40:09 1.2
@@ -64,11 +64,11 @@
import sax.helpers.AttributeListImpl;
import org.xml.sax.AttributeList;
-import org.xml.sax.Configurable;
import org.xml.sax.HandlerBase;
import org.xml.sax.Parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
import org.xml.sax.helpers.ParserFactory;
/**
@@ -121,13 +121,13 @@
parser.setDocumentHandler(counter);
parser.setErrorHandler(counter);
try {
- if (validate && parser instanceof Configurable)
- ((Configurable)parser).setFeature("http://xml.org/sax/features/validation", true);
+ if (validate && parser instanceof XMLReader)
+ ((XMLReader)parser).setFeature("http://xml.org/sax/features/validation", true);
} catch (Exception ex) {}
if (warmup) {
- if (parser instanceof Configurable)
- ((Configurable)parser).setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
+ if (parser instanceof XMLReader)
+ ((XMLReader)parser).setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
parser.parse(uri);
warmup = false;
}
1.6 +85 -47 xml-xerces/java/src/org/apache/xerces/framework/XMLParser.java
Index: XMLParser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/XMLParser.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLParser.java 2000/01/14 22:38:17 1.5
+++ XMLParser.java 2000/02/07 21:40:09 1.6
@@ -89,7 +89,6 @@
import org.apache.xerces.validators.datatype.DatatypeMessageProvider;
import org.apache.xerces.validators.schema.SchemaMessageProvider;
-import org.xml.sax.Configurable;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
@@ -111,7 +110,6 @@
XMLEntityHandler,
XMLDocumentScanner.EventHandler,
DTDValidator.EventHandler,
- Configurable,
Locator {
//
@@ -126,9 +124,6 @@
/** SAX2 properties prefix (http://xml.org/sax/properties/). */
protected static final String SAX2_PROPERTIES_PREFIX = "http://xml.org/sax/properties/";
- /** SAX2 handlers prefix (http://xml.org/sax/handlers/). */
- protected static final String SAX2_HANDLERS_PREFIX = "http://xml.org/sax/handlers/";
-
/** Xerces features prefix (http://apache.org/xml/features/). */
protected static final String XERCES_FEATURES_PREFIX = "http://apache.org/xml/features/";
@@ -717,13 +712,14 @@
* @see #getValidation
* @see #setFeature
*/
- protected void setValidation(boolean validate) throws SAXException {
+ protected void setValidation(boolean validate)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
try {
fDTDValidator.setValidationEnabled(validate);
getSchemaValidator().setValidationEnabled(validate);
}
catch (Exception ex) {
- throw new SAXException(ex);
+ throw new SAXNotSupportedException(ex.getMessage());
}
}
@@ -732,7 +728,8 @@
*
* @see #setValidation
*/
- protected boolean getValidation() throws SAXException {
+ protected boolean getValidation()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fDTDValidator.getValidationEnabled();
}
@@ -755,7 +752,7 @@
* @see #setFeature
*/
protected void setExternalGeneralEntities(boolean expand)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
if (!expand) {
throw new SAXNotSupportedException("http://xml.org/sax/features/external-general-entities");
}
@@ -768,7 +765,8 @@
*
* @see #setExternalGeneralEntities
*/
- protected boolean getExternalGeneralEntities() throws SAXException {
+ protected boolean getExternalGeneralEntities()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return true;
}
@@ -791,7 +789,7 @@
* @see #setFeature
*/
protected void setExternalParameterEntities(boolean expand)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
if (!expand) {
throw new SAXNotSupportedException("http://xml.org/sax/features/external-parameter-entities");
}
@@ -804,7 +802,8 @@
*
* @see #setExternalParameterEntities
*/
- protected boolean getExternalParameterEntities() throws SAXException {
+ protected boolean getExternalParameterEntities()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return true;
}
@@ -821,7 +820,8 @@
* @see #getNamespaces
* @see #setFeature
*/
- protected void setNamespaces(boolean process) throws SAXException {
+ protected void setNamespaces(boolean process)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
fNamespacesEnabled = process;
fDTDValidator.setNamespacesEnabled(process);
getSchemaValidator().setNamespacesEnabled(process);
@@ -832,7 +832,8 @@
*
* @see #setNamespaces
*/
- protected boolean getNamespaces() throws SAXException {
+ protected boolean getNamespaces()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fNamespacesEnabled;
}
@@ -854,7 +855,8 @@
* @see #getValidationDynamic
* @see #setFeature
*/
- protected void setValidationDynamic(boolean dynamic) throws SAXException {
+ protected void setValidationDynamic(boolean dynamic)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
if (fParseInProgress) {
// REVISIT: Localize this message. -Ac
throw new SAXNotSupportedException("http://apache.org/xml/features/validation/dynamic: parse is in progress");
@@ -864,7 +866,7 @@
getSchemaValidator().setDynamicValidationEnabled(dynamic);
}
catch (Exception ex) {
- throw new SAXException(ex);
+ throw new SAXNotSupportedException(ex.getMessage());
}
}
@@ -874,7 +876,8 @@
*
* @see #setValidationDynamic
*/
- protected boolean getValidationDynamic() throws SAXException {
+ protected boolean getValidationDynamic()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fDTDValidator.getDynamicValidationEnabled();
}
@@ -893,7 +896,7 @@
* @see #setFeature
*/
protected void setValidationWarnOnDuplicateAttdef(boolean warn)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
fDTDValidator.setWarningOnDuplicateAttDef(warn);
getSchemaValidator().setWarningOnDuplicateAttDef(warn);
}
@@ -905,7 +908,7 @@
* @see #setValidationWarnOnDuplicateAttdef
*/
protected boolean getValidationWarnOnDuplicateAttdef()
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fDTDValidator.getWarningOnDuplicateAttDef();
}
@@ -925,7 +928,7 @@
* @see #setFeature
*/
protected void setValidationWarnOnUndeclaredElemdef(boolean warn)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
fDTDValidator.setWarningOnUndeclaredElements(warn);
getSchemaValidator().setWarningOnUndeclaredElements(warn);
}
@@ -937,7 +940,7 @@
* @see #setValidationWarnOnUndeclaredElemdef
*/
protected boolean getValidationWarnOnUndeclaredElemdef()
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fDTDValidator.getWarningOnUndeclaredElements();
}
@@ -955,7 +958,8 @@
* @see #getAllowJavaEncodings
* @see #setFeature
*/
- protected void setAllowJavaEncodings(boolean allow) throws SAXException {
+ protected void setAllowJavaEncodings(boolean allow)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
fReaderFactory.setAllowJavaEncodingName(allow);
}
@@ -964,7 +968,8 @@
*
* @see #setAllowJavaEncodings
*/
- protected boolean getAllowJavaEncodings() throws SAXException {
+ protected boolean getAllowJavaEncodings()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fReaderFactory.getAllowJavaEncodingName();
}
@@ -984,7 +989,7 @@
* @see #setFeature
*/
protected void setContinueAfterFatalError(boolean continueAfterFatalError)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
fContinueAfterFatalError = continueAfterFatalError;
}
@@ -993,7 +998,8 @@
*
* @see #setContinueAfterFatalError
*/
- protected boolean getContinueAfterFatalError() throws SAXException {
+ protected boolean getContinueAfterFatalError()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fContinueAfterFatalError;
}
@@ -1018,7 +1024,8 @@
* @see #getNamespaceSep
* @see #setProperty
*/
- protected void setNamespaceSep(String separator) throws SAXException {
+ protected void setNamespaceSep(String separator)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
// REVISIT: Ask someone what it could possibly hurt to allow
// the application to change this in mid-parse.
if (fParseInProgress) {
@@ -1033,7 +1040,8 @@
*
* @see #setNamespaceSep
*/
- protected String getNamespaceSep() throws SAXException {
+ protected String getNamespaceSep()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fNamespaceSep;
}
@@ -1049,7 +1057,8 @@
*
* @see #getProperty
*/
- protected String getXMLString() throws SAXException {
+ protected String getXMLString()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
throw new SAXNotSupportedException("http://xml.org/sax/properties/xml-string");
}
@@ -1106,7 +1115,7 @@
}
//
- // Parser methods
+ // Parser/XMLReader methods
//
// NOTE: This class does *not* implement the org.xml.sax.Parser
// interface but it does share some common methods. -Ac
@@ -1114,6 +1123,28 @@
// handlers
/**
+ * Sets the resolver used to resolve external entities. The EntityResolver
+ * interface supports resolution of public and system identifiers.
+ *
+ * @param resolver The new entity resolver. Passing a null value will
+ * uninstall the currently installed resolver.
+ */
+ public void setEntityResolver(EntityResolver resolver) {
+ fEntityResolver = resolver;
+ }
+
+ /**
+ * Return the current entity resolver.
+ *
+ * @return The current entity resolver, or null if none
+ * has been registered.
+ * @see #setEntityResolver
+ */
+ public EntityResolver getEntityResolver() {
+ return fEntityResolver;
+ }
+
+ /**
* Sets the error handler.
*
* @param handler The new error handler.
@@ -1122,6 +1153,17 @@
fErrorHandler = handler;
}
+ /**
+ * Return the current error handler.
+ *
+ * @return The current error handler, or null if none
+ * has been registered.
+ * @see #setErrorHandler
+ */
+ public ErrorHandler getErrorHandler() {
+ return fErrorHandler;
+ }
+
// parsing
/**
@@ -1298,6 +1340,11 @@
//
// Configurable methods
//
+ // This interface is no longer a part of SAX2. These methods have
+ // been added directly to the new XMLReader interface. In addition,
+ // the throws clause has changed from throws SAXException to throws
+ // SAXNotRecognizedException, SAXNotSupportedException
+ //
/**
* Set the state of a feature.
@@ -1318,7 +1365,7 @@
* problem fulfilling the request.
*/
public void setFeature(String featureId, boolean state)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 Features
@@ -1464,7 +1511,8 @@
* @exception org.xml.sax.SAXException If there is any other
* problem fulfilling the request.
*/
- public boolean getFeature(String featureId) throws SAXException {
+ public boolean getFeature(String featureId)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 Features
@@ -1606,7 +1654,7 @@
* problem fulfilling the request.
*/
public void setProperty(String propertyId, Object value)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 Properties
@@ -1700,7 +1748,8 @@
* problem fulfilling the request.
* @see org.xml.sax.Configurable#getProperty
*/
- public Object getProperty(String propertyId) throws SAXException {
+ public Object getProperty(String propertyId)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 Properties
@@ -1945,7 +1994,7 @@
if (attrName == fStringPool.addSymbol("xmlns")) { // default namespacedecl
fValidator = getSchemaValidator();
String fs = fEntityHandler.expandSystemId(fStringPool.toString(attValue));
- InputSource is = fResolver == null ? null : fResolver.resolveEntity(null, fs);
+ InputSource is = fEntityResolver == null ? null : fEntityResolver.resolveEntity(null, fs);
if (is == null) {
is = new InputSource(fs);
}
@@ -2125,7 +2174,7 @@
//
//
//
- private EntityResolver fResolver = null;
+ private EntityResolver fEntityResolver = null;
private byte[] fEntityTypeStack = null;
private int[] fEntityNameStack = null;
private int fEntityStackDepth = 0;
@@ -2181,17 +2230,6 @@
}
/**
- * Sets the resolver used to resolve external entities. The EntityResolver
- * interface supports resolution of public and system identifiers.
- *
- * @param resolver The new entity resolver. Passing a null value will
- * uninstall the currently installed resolver.
- */
- public void setEntityResolver(EntityResolver resolver) {
- fResolver = resolver;
- }
-
- /**
* Expands a system id and returns the system id as a URL, if
* it can be expanded. A return value of null means that the
* identifier is already expanded. An exception thrown
@@ -2573,7 +2611,7 @@
sendStartEntityNotifications();
ReaderState rs = (ReaderState) fReaderStack.peek();
fSystemId = expandSystemId(fSystemId, rs.systemId);
- fSource = fResolver == null ? null : fResolver.resolveEntity(fPublicId, fSystemId);
+ fSource = fEntityResolver == null ? null : fEntityResolver.resolveEntity(fPublicId, fSystemId);
if (fSource == null) {
fSource = new InputSource(fSystemId);
if (fPublicId != null)
1.5 +24 -21 xml-xerces/java/src/org/apache/xerces/parsers/DOMParser.java
Index: DOMParser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/DOMParser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DOMParser.java 2000/01/07 23:32:28 1.4
+++ DOMParser.java 2000/02/07 21:40:10 1.5
@@ -389,7 +389,8 @@
* @see #getDeferNodeExpansion
* @see #setDocumentClassName
*/
- protected void setDeferNodeExpansion(boolean deferNodeExpansion) throws SAXException {
+ protected void setDeferNodeExpansion(boolean deferNodeExpansion)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
fDeferNodeExpansion = deferNodeExpansion;
}
@@ -399,7 +400,8 @@
*
* @see #setDeferNodeExpansion
*/
- protected boolean getDeferNodeExpansion() throws SAXException {
+ protected boolean getDeferNodeExpansion()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fDeferNodeExpansion;
}
@@ -418,7 +420,8 @@
*
* @see #getCreateEntityReferenceNodes
*/
- protected void setCreateEntityReferenceNodes(boolean create) throws SAXException {
+ protected void setCreateEntityReferenceNodes(boolean create)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
fCreateEntityReferenceNodes = create;
}
@@ -428,7 +431,8 @@
*
* @see #setCreateEntityReferenceNodes
*/
- public boolean getCreateEntityReferenceNodes() throws SAXException {
+ public boolean getCreateEntityReferenceNodes()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fCreateEntityReferenceNodes;
}
@@ -451,7 +455,8 @@
*
* @see #getIncludeIgnorableWhitespace
*/
- public void setIncludeIgnorableWhitespace(boolean include) throws SAXException {
+ public void setIncludeIgnorableWhitespace(boolean include)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
fIncludeIgnorableWhitespace = include;
}
@@ -461,7 +466,8 @@
*
* @see #setIncludeIgnorableWhitespace
*/
- public boolean getIncludeIgnorableWhitespace() throws SAXException {
+ public boolean getIncludeIgnorableWhitespace()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fIncludeIgnorableWhitespace;
}
@@ -482,7 +488,8 @@
* @see #setDeferNodeExpansion
* @see #DEFAULT_DOCUMENT_CLASS_NAME
*/
- protected void setDocumentClassName(String documentClassName) throws SAXException {
+ protected void setDocumentClassName(String documentClassName)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
// normalize class name
if (documentClassName == null) {
@@ -517,7 +524,8 @@
*
* @see #setDocumentClassName
*/
- protected String getDocumentClassName() throws SAXException {
+ protected String getDocumentClassName()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fDocumentClassName;
}
@@ -528,7 +536,8 @@
* property is set to true and the document factory is set to
* the default factory.
*/
- protected Element getCurrentElementNode() throws SAXException {
+ protected Element getCurrentElementNode()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
if (fCurrentElementNode != null &&
fCurrentElementNode.getNodeType() == Node.ELEMENT_NODE) {
@@ -555,11 +564,9 @@
* @exception SAXNotSupportedException If the requested feature is
* known, but the requested state
* is not supported.
- * @exception SAXException If there is any other problem fulfilling
- * the request.
*/
public void setFeature(String featureId, boolean state)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 core features
@@ -667,10 +674,9 @@
*
* @exception SAXNotRecognizedException If the requested feature is
* not known.
- * @exception SAXException If there is any other problem fulfilling
- * the request.
*/
- public boolean getFeature(String featureId) throws SAXException {
+ public boolean getFeature(String featureId)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 core features
@@ -773,11 +779,9 @@
* @exception SAXNotSupportedException If the requested property is
* known, but the requested
* value is not supported.
- * @exception SAXException If there is any other problem fulfilling
- * the request.
*/
public void setProperty(String propertyId, Object value)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// Xerces properties
@@ -831,12 +835,11 @@
*
* @exception SAXNotRecognizedException If the requested property is
* not known.
- * @exception SAXException If there is any other problem fulfilling
- * the request.
*
* @see Configurable#getProperty
*/
- public Object getProperty(String propertyId) throws SAXException {
+ public Object getProperty(String propertyId)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// Xerces properties
1.4 +246 -162 xml-xerces/java/src/org/apache/xerces/parsers/SAXParser.java
Index: SAXParser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/SAXParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SAXParser.java 2000/01/05 01:39:23 1.3
+++ SAXParser.java 2000/02/07 21:40:10 1.4
@@ -63,16 +63,23 @@
import org.apache.xerces.readers.XMLEntityHandler;
import org.apache.xerces.utils.StringPool;
+import org.xml.sax.Attributes;
import org.xml.sax.AttributeList;
+import org.xml.sax.ContentHandler;
import org.xml.sax.DocumentHandler;
import org.xml.sax.DTDHandler;
+import org.xml.sax.EntityResolver;
import org.xml.sax.Parser;
+import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
-import org.xml.sax.misc.DeclHandler;
-import org.xml.sax.misc.LexicalHandler;
-import org.xml.sax.misc.NamespaceHandler;
+import org.xml.sax.ext.DeclHandler;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.AttributesImpl;
+// REVISIT: [SAX2beta] ContentHandler#skippedEntity(String)
+
/**
* SAXParser provides a parser which implements the SAX1 and SAX2
* parser APIs
@@ -81,7 +88,7 @@
*/
public class SAXParser
extends XMLParser
- implements Parser {
+ implements Parser, XMLReader {
//
// Constants
@@ -92,18 +99,19 @@
/** Features recognized by this parser. */
private static final String RECOGNIZED_FEATURES[] = {
// SAX2 core
- "http://xml.org/sax/features/normalize-text",
- "http://xml.org/sax/features/use-locator",
+ /*"http://xml.org/sax/features/normalize-text",*/
+ /*"http://xml.org/sax/features/use-locator",*/
+ "http://xml.org/sax/features/namespace-prefixes",
+ "http://xml.org/sax/features/string-interning",
// Xerces
};
/** Properties recognized by this parser. */
private static final String RECOGNIZED_PROPERTIES[] = {
// SAX2 core
+ "http://xml.org/sax/properties/lexical-handler",
+ "http://xml.org/sax/properties/declaration-handler",
"http://xml.org/sax/properties/dom-node",
- "http://xml.org/sax/handlers/DeclHandler",
- "http://xml.org/sax/handlers/LexicalHandler",
- "http://xml.org/sax/handlers/NamespaceHandler",
// Xerces
};
@@ -115,14 +123,21 @@
//
// Data
//
+
+ // parser handlers
+
+ /** Document handler. */
+ private DocumentHandler fDocumentHandler;
- // handlers
+ // parser/xmlreader handlers
/** DTD handler. */
private DTDHandler fDTDHandler;
- /** Document handler. */
- private DocumentHandler fDocumentHandler;
+ // xmlreader handlers
+
+ /** Content handler. */
+ private ContentHandler fContentHandler;
/** Decl handler. */
private DeclHandler fDeclHandler;
@@ -130,9 +145,10 @@
/** Lexical handler. */
private LexicalHandler fLexicalHandler;
- /** Namespace handler. */
- private NamespaceHandler fNamespaceHandler;
+ // temp
+ private transient AttributesImpl fAttributes = new AttributesImpl();
+
//
// Constructors
//
@@ -238,11 +254,14 @@
* @see #getNormalizeText
* @see #setFeature
*/
- protected void setNormalizeText(boolean normalize) throws SAXException {
+ /*
+ protected void setNormalizeText(boolean normalize)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
if (normalize) {
throw new SAXNotSupportedException("http://xml.org/sax/features/normalize-text");
}
}
+ */
/**
* <b>Note: This feature is always false.</b>
@@ -253,9 +272,12 @@
*
* @see #setNormalizeText
*/
- protected boolean getNormalizeText() throws SAXException {
+ /*
+ protected boolean getNormalizeText()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return false;
}
+ */
/**
* <b>Note: Currently, this parser always sets the locator.</b>
@@ -272,11 +294,14 @@
* @see #getUseLocator
* @see #setFeature
*/
- protected void setUseLocator(boolean use) throws SAXException {
+ /*
+ protected void setUseLocator(boolean use)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
if (!use) {
throw new SAXNotSupportedException("http://xml.org/sax/features/use-locator");
}
}
+ */
/**
* <b>Note: This feature is always true.</b>
@@ -285,9 +310,12 @@
*
* @see #setUseLocator
*/
- protected boolean getUseLocator() throws SAXException {
+ /*
+ protected boolean getUseLocator()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return true;
}
+ */
// SAX2 core properties
@@ -296,7 +324,7 @@
* <p>
* This method is the equivalent to the property:
* <pre>
- * http://xml.org/sax/handlers/DeclHandler
+ * http://xml.org/sax/properties/declaration-handler
* </pre>
*
* @param handler The new handler.
@@ -304,10 +332,11 @@
* @see #getDeclHandler
* @see #setProperty
*/
- protected void setDeclHandler(DeclHandler handler) throws SAXException {
+ protected void setDeclHandler(DeclHandler handler)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
if (fParseInProgress) {
// REVISIT: Localize this message.
- throw new SAXNotSupportedException("http://xml.org/sax/handlers/DeclHandler: parse is in progress");
+ throw new SAXNotSupportedException("http://xml.org/sax/properties/declaration-handler: parse is in progress");
}
fDeclHandler = handler;
}
@@ -317,7 +346,8 @@
*
* @see #setDeclHandler
*/
- protected DeclHandler getDeclHandler() throws SAXException {
+ protected DeclHandler getDeclHandler()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fDeclHandler;
}
@@ -326,7 +356,7 @@
* <p>
* This method is the equivalent to the property:
* <pre>
- * http://xml.org/sax/handlers/LexicalHandler
+ * http://xml.org/sax/properties/lexical-handler
* </pre>
*
* @param handler lexical event handler
@@ -335,10 +365,10 @@
* @see #setProperty
*/
protected void setLexicalHandler(LexicalHandler handler)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
if (fParseInProgress) {
// REVISIT: Localize this message.
- throw new SAXNotSupportedException("http://xml.org/sax/handlers/LexicalHandler: parse is in progress");
+ throw new SAXNotSupportedException("http://xml.org/sax/properties/lexical-handler: parse is in progress");
}
fLexicalHandler = handler;
}
@@ -348,43 +378,56 @@
*
* @see #setLexicalHandler
*/
- protected LexicalHandler getLexicalHandler() throws SAXException {
+ protected LexicalHandler getLexicalHandler()
+ throws SAXNotRecognizedException, SAXNotSupportedException {
return fLexicalHandler;
}
+ //
+ // Parser methods
+ //
+
+ /** Sets the document handler. */
+ public void setDocumentHandler(DocumentHandler handler) {
+ fDocumentHandler = handler;
+ }
+
+ //
+ // Parser/XMLReader methods
+ //
+
/**
- * Set the namespace declaration scope event handler.
- * <p>
- * This method is the equivalent to the property:
- * <pre>
- * http://xml.org/sax/handlers/NamespaceHandler
- * </pre>
+ * Allow an application to register a DTD event handler.
*
- * @param handler namespace event handler
+ * <p>If the application does not register a DTD handler, all DTD
+ * events reported by the SAX parser will be silently ignored.</p>
*
- * @see #getNamespaceHandler
- * @see #setProperty
+ * <p>Applications may register a new or different handler in the
+ * middle of a parse, and the SAX parser must begin using the new
+ * handler immediately.</p>
+ *
+ * @param handler The DTD handler.
+ * @exception java.lang.NullPointerException If the handler
+ * argument is null.
+ * @see #getDTDHandler
*/
- protected void setNamespaceHandler(NamespaceHandler handler)
- throws SAXException {
- if (fParseInProgress) {
- // REVISIT: Localize this message.
- throw new SAXNotSupportedException("http://xml.org/sax/handlers/NamespaceHandler: parse is in progress");
- }
- fNamespaceHandler = handler;
+ public void setDTDHandler(DTDHandler handler) {
+ fDTDHandler = handler;
}
/**
- * Returns the namespace declaration scope event handler.
+ * Return the current DTD handler.
*
- * @see #setNamespaceHandler
+ * @return The current DTD handler, or null if none
+ * has been registered.
+ * @see #setDTDHandler
*/
- protected NamespaceHandler getNamespaceHandler() throws SAXException {
- return fNamespaceHandler;
+ public DTDHandler getDTDHandler() {
+ return fDTDHandler;
}
//
- // Configurable methods
+ // XMLReader methods
//
/**
@@ -400,11 +443,9 @@
* @exception SAXNotSupportedException If the
* requested feature is known, but the requested
* state is not supported.
- * @exception SAXException If there is any other
- * problem fulfilling the request.
*/
public void setFeature(String featureId, boolean state)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 Features
@@ -412,6 +453,7 @@
if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
String feature = featureId.substring(SAX2_FEATURES_PREFIX.length());
+ /*
//
// http://xml.org/sax/features/normalize-text
// Ensure that all consecutive text is returned in a single callback to
@@ -422,6 +464,8 @@
setNormalizeText(state);
return;
}
+ */
+ /*
//
// http://xml.org/sax/features/use-locator
// Provide a Locator using the DocumentHandler.setDocumentLocator
@@ -431,6 +475,7 @@
setUseLocator(state);
return;
}
+ */
//
// Drop through and perform default processing
//
@@ -468,10 +513,11 @@
* @return The current state of the feature.
* @exception org.xml.sax.SAXNotRecognizedException If the
* requested feature is not known.
- * @exception org.xml.sax.SAXException If there is any other
- * problem fulfilling the request.
+ * @exception SAXNotSupportedException If the
+ * requested feature is known but not supported.
*/
- public boolean getFeature(String featureId) throws SAXException {
+ public boolean getFeature(String featureId)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 Features
@@ -479,6 +525,7 @@
if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
String feature = featureId.substring(SAX2_FEATURES_PREFIX.length());
+ /*
//
// http://xml.org/sax/features/normalize-text
// Ensure that all consecutive text is returned in a single callback to
@@ -488,6 +535,8 @@
if (feature.equals("normalize-text")) {
return getNormalizeText();
}
+ */
+ /*
//
// http://xml.org/sax/features/use-locator
// Provide a Locator using the DocumentHandler.setDocumentLocator
@@ -496,12 +545,25 @@
if (feature.equals("use-locator")) {
return getUseLocator();
}
+ */
//
// Drop through and perform default processing
//
}
//
+ // Xerces Features
+ //
+
+ /*
+ else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
+ //
+ // Drop through and perform default processing
+ //
+ }
+ */
+
+ //
// Perform default processing
//
@@ -523,11 +585,9 @@
* @exception SAXNotSupportedException If the
* requested property is known, but the requested
* value is not supported.
- * @exception SAXException If there is any other
- * problem fulfilling the request.
*/
public void setProperty(String propertyId, Object value)
- throws SAXException {
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 core properties
@@ -535,39 +595,15 @@
if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) {
String property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length());
- //
- // http://xml.org/sax/properties/dom-node
- // Value type: DOM Node
- // Access: read-only
- // Get the DOM node currently being visited, if the SAX parser is
- // iterating over a DOM tree. If the parser recognises and supports
- // this property but is not currently visiting a DOM node, it should
- // return null (this is a good way to check for availability before the
- // parse begins).
- //
- if (property.equals("dom-node")) {
- throw new SAXNotSupportedException(propertyId); // read-only property
- }
- //
- // Drop through and perform default processing
- //
- }
-
- //
- // SAX2 core handlers
- //
-
- else if (propertyId.startsWith(SAX2_HANDLERS_PREFIX)) {
- String property = propertyId.substring(SAX2_HANDLERS_PREFIX.length());
//
- // http://xml.org/sax/handlers/DeclHandler
- // Value type: org.xml.sax.misc.DeclHandler
+ // http://xml.org/sax/properties/lexical-handler
+ // Value type: org.xml.sax.ext.LexicalHandler
// Access: read/write, pre-parse only
- // Set the DTD declaration event handler.
+ // Set the lexical event handler.
//
- if (property.equals("DeclHandler")) {
+ if (property.equals("lexical-handler")) {
try {
- setDeclHandler((DeclHandler)value);
+ setLexicalHandler((LexicalHandler)value);
}
catch (ClassCastException e) {
throw new SAXNotSupportedException(propertyId);
@@ -575,14 +611,14 @@
return;
}
//
- // http://xml.org/sax/handlers/LexicalHandler
- // Value type: org.xml.sax.misc.LexicalHandler
+ // http://xml.org/sax/properties/declaration-handler
+ // Value type: org.xml.sax.ext.DeclHandler
// Access: read/write, pre-parse only
- // Set the lexical event handler.
+ // Set the DTD declaration event handler.
//
- if (property.equals("LexicalHandler")) {
+ if (property.equals("declaration-handler")) {
try {
- setLexicalHandler((LexicalHandler)value);
+ setDeclHandler((DeclHandler)value);
}
catch (ClassCastException e) {
throw new SAXNotSupportedException(propertyId);
@@ -590,19 +626,17 @@
return;
}
//
- // http://xml.org/sax/handlers/NamespaceHandler
- // Value type: org.xml.sax.misc.NamespaceHandler
- // Access: read/write, pre-parse only
- // Set the namespace declaration scope event handler.
+ // http://xml.org/sax/properties/dom-node
+ // Value type: DOM Node
+ // Access: read-only
+ // Get the DOM node currently being visited, if the SAX parser is
+ // iterating over a DOM tree. If the parser recognises and supports
+ // this property but is not currently visiting a DOM node, it should
+ // return null (this is a good way to check for availability before the
+ // parse begins).
//
- if (property.equals("NamespaceHandler")) {
- try {
- setNamespaceHandler((NamespaceHandler)value);
- }
- catch (ClassCastException e) {
- throw new SAXNotSupportedException(propertyId);
- }
- return;
+ if (property.equals("dom-node")) {
+ throw new SAXNotSupportedException(propertyId); // read-only property
}
//
// Drop through and perform default processing
@@ -640,11 +674,11 @@
* @return The current value of the property.
* @exception org.xml.sax.SAXNotRecognizedException If the
* requested property is not known.
- * @exception org.xml.sax.SAXException If there is any other
- * problem fulfilling the request.
- * @see org.xml.sax.Configurable#getProperty
+ * @exception SAXNotSupportedException If the
+ * requested property is known but not supported.
*/
- public Object getProperty(String propertyId) throws SAXException {
+ public Object getProperty(String propertyId)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
//
// SAX2 core properties
@@ -653,6 +687,24 @@
if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) {
String property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length());
//
+ // http://xml.org/sax/properties/lexical-handler
+ // Value type: org.xml.sax.ext.LexicalHandler
+ // Access: read/write, pre-parse only
+ // Set the lexical event handler.
+ //
+ if (property.equals("lexical-handler")) {
+ return getLexicalHandler();
+ }
+ //
+ // http://xml.org/sax/properties/declaration-handler
+ // Value type: org.xml.sax.ext.DeclHandler
+ // Access: read/write, pre-parse only
+ // Set the DTD declaration event handler.
+ //
+ if (property.equals("declaration-handler")) {
+ return getDeclHandler();
+ }
+ //
// http://xml.org/sax/properties/dom-node
// Value type: DOM Node
// Access: read-only
@@ -671,44 +723,6 @@
}
//
- // SAX2 core handlers
- //
-
- else if (propertyId.startsWith(SAX2_HANDLERS_PREFIX)) {
- String property = propertyId.substring(SAX2_HANDLERS_PREFIX.length());
- //
- // http://xml.org/sax/handlers/DeclHandler
- // Value type: org.xml.sax.misc.DeclHandler
- // Access: read/write, pre-parse only
- // Set the DTD declaration event handler.
- //
- if (property.equals("DeclHandler")) {
- return getDeclHandler();
- }
- //
- // http://xml.org/sax/handlers/LexicalHandler
- // Value type: org.xml.sax.misc.LexicalHandler
- // Access: read/write, pre-parse only
- // Set the lexical event handler.
- //
- if (property.equals("LexicalHandler")) {
- return getLexicalHandler();
- }
- //
- // http://xml.org/sax/handlers/NamespaceHandler
- // Value type: org.xml.sax.misc.NamespaceHandler
- // Access: read/write, pre-parse only
- // Set the namespace declaration scope event handler.
- //
- if (property.equals("NamespaceHandler")) {
- return getNamespaceHandler();
- }
- //
- // Drop through and perform default processing
- //
- }
-
- //
// Xerces properties
//
@@ -727,19 +741,39 @@
return super.getProperty(propertyId);
} // getProperty(String):Object
-
- //
- // Parser methods
- //
- /** Sets the DTD handler. */
- public void setDTDHandler(DTDHandler handler) {
- fDTDHandler = handler;
+ /**
+ * Allow an application to register a content event handler.
+ *
+ * <p>If the application does not register a content handler, all
+ * content events reported by the SAX parser will be silently
+ * ignored.</p>
+ *
+ * <p>Applications may register a new or different handler in the
+ * middle of a parse, and the SAX parser must begin using the new
+ * handler immediately.</p>
+ *
+ * @param handler The content handler.
+ * @exception java.lang.NullPointerException If the handler
+ * argument is null.
+ * @see #getContentHandler
+ */
+ public void setContentHandler(ContentHandler handler) {
+ if (handler == null) {
+ throw new NullPointerException();
+ }
+ fContentHandler = handler;
}
- /** Sets the document handler. */
- public void setDocumentHandler(DocumentHandler handler) {
- fDocumentHandler = handler;
+ /**
+ * Return the current content handler.
+ *
+ * @return The current content handler, or null if none
+ * has been registered.
+ * @see #setContentHandler
+ */
+ public ContentHandler getContentHandler() {
+ return fContentHandler;
}
//
@@ -1026,6 +1060,10 @@
fDocumentHandler.setDocumentLocator(getLocator());
fDocumentHandler.startDocument();
}
+ if (fContentHandler != null) {
+ fContentHandler.setDocumentLocator(getLocator());
+ fContentHandler.startDocument();
+ }
// release strings
fStringPool.releaseString(versionIndex);
@@ -1044,6 +1082,9 @@
if (fDocumentHandler != null) {
fDocumentHandler.endDocument();
}
+ if (fContentHandler != null) {
+ fContentHandler.endDocument();
+ }
} // endDocument()
@@ -1052,7 +1093,7 @@
*/
public void startNamespaceDeclScope(int prefix, int uri) throws Exception {
- if (fNamespaceHandler != null || DEBUG_CALLBACKS) {
+ if (fContentHandler != null || DEBUG_CALLBACKS) {
// strings
String p = fStringPool.toString(prefix);
@@ -1062,8 +1103,8 @@
if (DEBUG_CALLBACKS) {
System.err.println("startNamespaceDeclScope(" + p + ", " + ns + ")");
}
- if (fNamespaceHandler != null) {
- fNamespaceHandler.startNamespaceDeclScope(p, ns);
+ if (fContentHandler != null) {
+ fContentHandler.startPrefixMapping(p, ns);
}
}
@@ -1074,7 +1115,7 @@
*/
public void endNamespaceDeclScope(int prefix) throws Exception {
- if (fNamespaceHandler != null || DEBUG_CALLBACKS) {
+ if (fContentHandler != null || DEBUG_CALLBACKS) {
// strings
String p = fStringPool.toString(prefix);
@@ -1083,8 +1124,8 @@
if (DEBUG_CALLBACKS) {
System.err.println("endNamespaceDeclScope(" + p + ")");
}
- if (fNamespaceHandler != null) {
- fNamespaceHandler.endNamespaceDeclScope(p);
+ if (fContentHandler != null) {
+ fContentHandler.endPrefixMapping(p);
}
}
@@ -1113,6 +1154,31 @@
if (fDocumentHandler != null) {
fDocumentHandler.startElement(name, attrs);
}
+ if (fContentHandler != null) {
+ int uriIndex = fStringPool.getURIForQName(elementType);
+ String uri = uriIndex != -1 ? fStringPool.toString(uriIndex) : "";
+ int localIndex = fStringPool.getLocalPartForQName(elementType);
+ String local = localIndex != -1 ? fStringPool.toString(localIndex) : "";
+ String raw = name;
+ fAttributes.clear();
+ for (int attrIndex = attrList.getFirstAttr(attrListIndex);
+ attrIndex != -1;
+ attrIndex = attrList.getNextAttr(attrIndex)) {
+ int attrNameIndex = attrList.getAttrName(attrIndex);
+ int attrUriIndex = fStringPool.getURIForQName(attrNameIndex);
+ String attrUri = attrUriIndex != -1
+ ? fStringPool.toString(attrUriIndex) : "";
+ int attrLocalIndex = fStringPool.getLocalPartForQName(attrNameIndex);
+ String attrLocal = attrLocalIndex != -1
+ ? fStringPool.toString(attrLocalIndex) : "";
+ String attrRaw = fStringPool.toString(attrNameIndex);
+ String attrType = fStringPool.toString(attrList.getAttType(attrIndex));
+ String attrValue = fStringPool.toString(attrList.getAttValue(attrIndex));
+ fAttributes.addAttribute(attrUri, attrLocal, attrRaw,
+ attrType, attrValue);
+ }
+ fContentHandler.startElement(uri, local, raw, fAttributes);
+ }
// free attribute list
attrList.releaseAttrList(attrListIndex);
@@ -1129,6 +1195,14 @@
if (fDocumentHandler != null) {
fDocumentHandler.endElement(fStringPool.toString(elementType));
}
+ if (fContentHandler != null) {
+ int uriIndex = fStringPool.getURIForQName(elementType);
+ String uri = uriIndex != -1 ? fStringPool.toString(uriIndex) : "";
+ int localIndex = fStringPool.getLocalPartForQName(elementType);
+ String local = localIndex != -1 ? fStringPool.toString(localIndex) : "";
+ String raw = fStringPool.toString(elementType);
+ fContentHandler.endElement(uri, local, raw);
+ }
} // endElement(int)
@@ -1241,7 +1315,7 @@
/** Processing instruction. */
public void processingInstruction(int piTarget, int piData) throws Exception {
- if (fDocumentHandler != null || DEBUG_CALLBACKS) {
+ if (fDocumentHandler != null || fContentHandler != null || DEBUG_CALLBACKS) {
//
// REVISIT - I keep running into SAX apps that expect
// null data to be an empty string, which is contrary
@@ -1259,8 +1333,12 @@
if (fDocumentHandler != null) {
fDocumentHandler.processingInstruction(target, data);
}
+ if (fContentHandler != null) {
+ fContentHandler.processingInstruction(target, data);
+ }
- } else {
+ }
+ else {
fStringPool.releaseString(piTarget);
fStringPool.releaseString(piData);
}
@@ -1303,6 +1381,9 @@
if (fDocumentHandler != null) {
fDocumentHandler.characters(ch, start, length);
}
+ if (fContentHandler != null) {
+ fContentHandler.characters(ch, start, length);
+ }
}
@@ -1315,6 +1396,9 @@
}
if (fDocumentHandler != null) {
fDocumentHandler.ignorableWhitespace(ch, start, length);
+ }
+ if (fContentHandler != null) {
+ fContentHandler.ignorableWhitespace(ch, start, length);
}
}