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/04/04 23:14:26 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/readers Makefile StreamingCharReader.java StringReader.java UCSReader.java UTF8Reader.java XCatalog.java XMLEntityHandler.java XMLEntityReader.java
andyc 00/04/04 14:14:26
Modified: java/src/org/apache/xerces/framework Makefile
XMLAttrList.java XMLContentSpec.java
XMLDTDScanner.java XMLDocumentHandler.java
XMLDocumentScanner.java XMLErrorReporter.java
XMLParser.java
java/src/org/apache/xerces/msg ExceptionMessages.java
SchemaMessages.java
java/src/org/apache/xerces/parsers DOMParser.java
SAXParser.java
java/src/org/apache/xerces/readers Makefile
StreamingCharReader.java StringReader.java
UCSReader.java UTF8Reader.java XCatalog.java
XMLEntityHandler.java XMLEntityReader.java
Log:
PHASE2: Merge changes.
Revision Changes Path
1.4 +3 -3 xml-xerces/java/src/org/apache/xerces/framework/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile 2000/02/29 02:02:18 1.3
+++ Makefile 2000/04/04 21:14:20 1.4
@@ -3,12 +3,12 @@
TARGETS=\
Version.class\
XMLAttrList.class\
- XMLContentSpecNode.class\
+ XMLContentSpec.class\
+ XMLDocumentHandler.class\
XMLDocumentScanner.class\
XMLDTDScanner.class\
XMLErrorReporter.class\
- XMLParser.class\
- XMLValidator.class
+ XMLParser.class
DIRS =
1.2 +8 -20 xml-xerces/java/src/org/apache/xerces/framework/XMLAttrList.java
Index: XMLAttrList.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/XMLAttrList.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLAttrList.java 1999/11/09 01:12:55 1.1
+++ XMLAttrList.java 2000/04/04 21:14:20 1.2
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -72,31 +72,28 @@
* are bundled up together before being presented to the application, we don't
* have a way to build up an attribute value from pieces, most notably entity
* references.
- *
+ * <p>
* There is typically one instance of this class for each instance of a
* parser. The parser may either use this object to hold the attributes
* of a single element, calling releaseAttrList() before each new element,
* or it may use this object to hold the attributes of all of the elements
* in the document.
- *
+ * <p>
* To start saving a new set of attributes, the startAttrList() method is
* called, returning a handle for the attribute list. All addAttr() calls
- * will be added to the set until a call is made to endAttrList(). Anytime
- * after the call to startAttrList(), and before the call to endAttrList(),
- * the attrListHandle() method may be called to get the handle of the set
- * of attributes currently in progress. A handle of -1 is used to indicate
- * that there are no attributes in the set.
- *
+ * will be added to the set until a call is made to endAttrList(). A handle
+ * of -1 is used to indicate that there are no attributes in the set.
+ * <p>
* When an attribute is added to the set, the type of the attribute and an
* indicator of whether it was specified explicitly or through a default is
* provided.
- *
+ * <p>
* The attributes in the set may be accessed either through the getFirstAttr()
* and getNextAttr() iteration interface, or the getAttributeList() method
* may be used to access the attribute list through the SAX <code>AttributeList</code>
* interface.
*
- * @version
+ * @version $Id: XMLAttrList.java,v 1.2 2000/04/04 21:14:20 andyc Exp $
*/
public final class XMLAttrList implements AttributeList {
//
@@ -184,15 +181,6 @@
fAttType[chunk][index] = attType;
fAttFlags[chunk][index] = (byte)(specified ? ATTFLAG_SPECIFIED : 0);
return fAttrCount++;
- }
-
- /**
- * Get the handle for the set of attributes.
- *
- * @return The handle for the current set of attributes.
- */
- public int attrListHandle() {
- return fCurrentHandle;
}
/**
1.2 +7 -7 xml-xerces/java/src/org/apache/xerces/framework/XMLContentSpec.java
Index: XMLContentSpec.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/XMLContentSpec.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLContentSpec.java 2000/04/04 18:34:55 1.1
+++ XMLContentSpec.java 2000/04/04 21:14:20 1.2
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -60,7 +60,7 @@
/**
* ContentSpec really exists to aid the parser classes in implementing
* access to the grammar.
- *
+ * <p>
* This class is used by the DTD scanner and the validator classes,
* allowing them to be used separately or together. This "struct"
* class is used to build content models for validation, where it
@@ -70,14 +70,14 @@
* without a DTD scanner (i.e. a schema validator) and a DTD scanner
* without a validator (non-validating processor), this class can be
* used by each without requiring the presence of the other.
- *
+ * <p>
* When processing element declarations, the DTD scanner will build
* up a representation of the content model using the node types that
* are defined here. Since a non-validating processor only needs to
* remember the type of content model declared (i.e. ANY, EMPTY, MIXED,
* or CHILDREN), it is free to discard the specific details of the
* MIXED and CHILDREN content models described using this class.
- *
+ * <p>
* In the typical case of a validating processor reading the grammar
* of the document from a DTD, the information about the content model
* declared will be preserved and later "compiled" into an efficient
@@ -87,7 +87,7 @@
* A leaf node has a "value" that is either an index in the string
* pool of the element type of that leaf, or a value of -1 to indicate
* the special "#PCDATA" leaf type used in a mixed content model.
- *
+ * <p>
* For a mixed content model, the content spec will be made up of
* leaf and choice content spec nodes, with an optional "zero or more"
* node. For example, the mixed content declaration "(#PCDATA)" would
@@ -101,13 +101,13 @@
* there will be more corresponding choice and leaf nodes, the choice
* nodes will be chained together through the "value" field with each
* leaf node referenced by the "otherValue" field.
- *
+ * <p>
* For element content models, there are sequence nodes and also "zero or
* one" and "one or more" nodes. The leaf nodes would always have a valid
* string pool index, as the "#PCDATA" leaf is not used in the declarations
* for element content models.
*
- * @version
+ * @version $Id: XMLContentSpec.java,v 1.2 2000/04/04 21:14:20 andyc Exp $
*/
public interface XMLContentSpec {
1.6 +186 -171 xml-xerces/java/src/org/apache/xerces/framework/XMLDTDScanner.java
Index: XMLDTDScanner.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/XMLDTDScanner.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLDTDScanner.java 2000/04/04 00:40:00 1.5
+++ XMLDTDScanner.java 2000/04/04 21:14:20 1.6
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -66,11 +66,11 @@
/**
* Default implementation of an XML DTD scanner.
- *
+ * <p>
* Clients who wish to scan a DTD should implement
* XMLDTDScanner.EventHandler to provide the desired behavior
* when various DTD components are encountered.
- *
+ * <p>
* To process the DTD, the client application should follow the
* following sequence:
* <ol>
@@ -81,7 +81,7 @@
* </ol>
*
* @see XMLDTDScanner.EventHandler
- * @version
+ * @version $Id: XMLDTDScanner.java,v 1.6 2000/04/04 21:14:20 andyc Exp $
*/
public final class XMLDTDScanner {
//
@@ -181,9 +181,9 @@
private int fReaderId = -1;
private int fSystemLiteral = -1;
private int fPubidLiteral = -1;
- private int[] opStack = null;
- private int[] nodeIndexStack = null;
- private int[] prevNodeIndexStack = null;
+ private int[] fOpStack = null;
+ private int[] fNodeIndexStack = null;
+ private int[] fPrevNodeIndexStack = null;
private int fScannerState = SCANNER_STATE_INVALID;
private int fIncludeSectDepth = 0;
private int fDoctypeReader = -1;
@@ -221,22 +221,26 @@
//
// Constructors
//
- public XMLDTDScanner(EventHandler eventHandler,
- StringPool stringPool,
+ public XMLDTDScanner(StringPool stringPool,
XMLErrorReporter errorReporter,
XMLEntityHandler entityHandler,
XMLEntityHandler.CharBuffer literalData) {
- fEventHandler = eventHandler;
fStringPool = stringPool;
fErrorReporter = errorReporter;
fEntityHandler = entityHandler;
fLiteralData = literalData;
init();
}
- //
- //
- //
+
/**
+ * Set the event handler
+ *
+ * @param eventHandler The place to send our callbacks.
+ */
+ public void setEventHandler(XMLDTDScanner.EventHandler eventHandler) {
+ fEventHandler = eventHandler;
+ }
+ /**
* Is the XMLDTDScanner reading from an external entity?
*
* This will be true, in particular if there was an external subset
@@ -306,9 +310,9 @@
fReaderId = -1;
fSystemLiteral = -1;
fPubidLiteral = -1;
- opStack = null;
- nodeIndexStack = null;
- prevNodeIndexStack = null;
+ fOpStack = null;
+ fNodeIndexStack = null;
+ fPrevNodeIndexStack = null;
fScannerState = SCANNER_STATE_INVALID;
fIncludeSectDepth = 0;
fDoctypeReader = -1;
@@ -359,13 +363,6 @@
*/
public interface EventHandler {
/**
- * REVISIT - does this really do anything -- can we kill it?
- *
- * @return the current location
- * @exception java.lang.Exception
- */
- public int saveCurrentLocation() throws Exception;
- /**
* Determine whether a string is a valid XML version number
*
* @param version string to be checked
@@ -390,6 +387,14 @@
*/
public int validPublicId(String publicId) throws Exception;
/**
+ * Signal the Text declaration of an external entity.
+ *
+ * @param version the handle in the string pool for the version number
+ * @param encoding the handle in the string pool for the encoding
+ * @exception java.lang.Exception
+ */
+ public void callTextDecl(int version, int encoding) throws Exception;
+ /**
* Called when the doctype decl is scanned
*
* @param rootElementType handle of the rootElement
@@ -444,50 +449,62 @@
*/
public int addAttDef(int elementIndex, int attName, int attType, int enumeration, int attDefaultType, int attDefaultValue) throws Exception;
/**
- * create an XMLContentSpecNode for a leaf
+ * create an XMLContentSpec.Node for a leaf
*
* @param nameIndex StringPool handle to the name (Element) for the node
- * @return handle to the newly create XMLContentSpecNode
+ * @return handle to the newly create XMLContentSpec.Node
* @exception java.lang.Exception
*/
public int addUniqueLeafNode(int nameIndex) throws Exception;
/**
- * Create an XMLContentSpecNode for a single non-leaf
+ * Create an XMLContentSpec.Node for a single non-leaf
*
- * @param nodeType the type of XMLContentSpecNode to create - from XMLContentSpecNode.CONTENTSPECNODE_*
- * @param nodeValue handle to an XMLContentSpecNode
- * @return handle to the newly create XMLContentSpecNode
+ * @param nodeType the type of XMLContentSpec.Node to create - from XMLContentSpec.CONTENTSPECNODE_*
+ * @param nodeValue handle to an XMLContentSpec.Node
+ * @return handle to the newly create XMLContentSpec.Node
* @exception java.lang.Exception
*/
public int addContentSpecNode(int nodeType, int nodeValue) throws Exception;
/**
- * Create an XMLContentSpecNode for a two child leaf
+ * Create an XMLContentSpec.Node for a two child leaf
*
- * @param nodeType the type of XMLContentSpecNode to create - from XMLContentSpecNode.CONTENTSPECNODE_*
- * @param leftNodeIndex handle to an XMLContentSpecNode
- * @param rightNodeIndex handle to an XMLContentSpecNode
- * @return handle to the newly create XMLContentSpecNode
+ * @param nodeType the type of XMLContentSpec.Node to create - from XMLContentSpec.CONTENTSPECNODE_*
+ * @param leftNodeIndex handle to an XMLContentSpec.Node
+ * @param rightNodeIndex handle to an XMLContentSpec.Node
+ * @return handle to the newly create XMLContentSpec.Node
* @exception java.lang.Exception
*/
public int addContentSpecNode(int nodeType, int leftNodeIndex, int rightNodeIndex) throws Exception;
/**
- * Create a string representation of an XMLContentSpecNode tree
+ * Create a string representation of an XMLContentSpec.Node tree
*
- * @param handle to an XMLContentSpecNode
+ * @param handle to an XMLContentSpec.Node
* @return String representation of the content spec tree
* @exception java.lang.Exception
*/
public String getContentSpecNodeAsString(int nodeIndex) throws Exception;
/**
+ * Start the scope of an entity declaration.
+ *
+ * @return <code>true</code> on success; otherwise
+ * <code>false</code> if the entity declaration is recursive.
+ * @exception java.lang.Exception
+ */
+ public boolean startEntityDecl(boolean isPE, int entityName) throws Exception;
+ /**
+ * End the scope of an entity declaration.
+ * @exception java.lang.Exception
+ */
+ public void endEntityDecl() throws Exception;
+ /**
* Add a declaration for an internal parameter entity
*
* @param name StringPool handle of the parameter entity name
* @param value StringPool handle of the parameter entity value
- * @param location location in the containing entity
* @return handle to the parameter entity declaration
* @exception java.lang.Exception
*/
- public int addInternalPEDecl(int name, int value, int location) throws Exception;
+ public int addInternalPEDecl(int name, int value) throws Exception;
/**
* Add a declaration for an external parameter entity
*
@@ -503,11 +520,10 @@
*
* @param name StringPool handle of the entity name
* @param value StringPool handle of the entity value
- * @param location location in the containing entity
* @return handle to the entity declaration
* @exception java.lang.Exception
*/
- public int addInternalEntityDecl(int name, int value, int location) throws Exception;
+ public int addInternalEntityDecl(int name, int value) throws Exception;
/**
* Add a declaration for an entity
*
@@ -648,12 +664,11 @@
* @exception java.lang.Exception
*/
public int scanDefaultAttValue(int elementType, int attrName, int attType, int enumeration) throws Exception;
-
/**
* Supports DOM Level 2 internalSubset additions.
* Called when the internal subset is completely scanned.
*/
- public void internalSubset(int internalSubset);
+ public void internalSubset(int internalSubset) throws Exception;
}
//
//
@@ -1198,26 +1213,6 @@
}
if (dataok) {
fSystemLiteral = fEntityReader.addString(offset, fEntityReader.currentOffset() - offset);
-
- //
- // ndw@nwalsh.com
- // An fSystemLiteral value from an entity declaration may be
- // a relative URI. If so, it's important that we make it
- // absolute with respect to the context of the document that
- // we are currently reading. If we don't, the XMLParser will
- // make it absolute with respect to the point of *reference*,
- // before attempting to read it. That's definitely wrong.
- //
-
- String litSystemId = fStringPool.toString(fSystemLiteral);
- String absSystemId = fEntityHandler.expandSystemId(litSystemId);
- if (!absSystemId.equals(litSystemId)) {
- // REVISIT - Is it kosher to touch fStringPool directly?
- // Is there a better way? fEntityReader doesn't seem to
- // have an addString method that takes a literal string.
- fSystemLiteral = fStringPool.addString(absSystemId);
- }
-
if (fragment) {
// NOTE: RECOVERABLE ERROR
Object[] args = { fStringPool.toString(fSystemLiteral) };
@@ -1369,11 +1364,10 @@
int prevState = setScannerState(SCANNER_STATE_MARKUP_DECL);
while (fScannerState == SCANNER_STATE_MARKUP_DECL) {
boolean newParseTextDecl = false;
- if (!extSubset && fEntityReader.lookingAtChar(']', true)) {
- fEventHandler.internalSubset(
- fEntityReader.addString(subsetOffset,
- (fEntityReader.currentOffset()-subsetOffset)-1));
-
+ if (!extSubset && fEntityReader.lookingAtChar(']', false)) {
+ int subsetLength = fEntityReader.currentOffset() - subsetOffset;
+ fEventHandler.internalSubset(fEntityReader.addString(subsetOffset, subsetLength));
+ fEntityReader.lookingAtChar(']', true);
restoreScannerState(prevState);
return;
}
@@ -1462,7 +1456,7 @@
fEntityReader.addString(nameOffset, nameLength));
} else {
int peNameIndex = fEntityReader.addSymbol(nameOffset, nameLength);
- newParseTextDecl = fEntityHandler.startReadingFromEntity(peNameIndex, markupDepth(), XMLEntityHandler.CONTEXT_IN_DTD_AS_MARKUP);
+ newParseTextDecl = fEntityHandler.startReadingFromEntity(peNameIndex, markupDepth(), XMLEntityHandler.ENTITYREF_IN_DTD_AS_MARKUP);
}
} else if (fIncludeSectDepth > 0 && fEntityReader.lookingAtChar(']', true)) {
if (!fEntityReader.lookingAtChar(']', true) || !fEntityReader.lookingAtChar('>', true)) {
@@ -1497,12 +1491,6 @@
}
if (extSubset)
fEventHandler.stopReadingFromExternalSubset();
- else
- fEventHandler.internalSubset(
- fEntityReader.addString(subsetOffset,
- (fEntityReader.currentOffset()-subsetOffset)));
-
-
}
//
// [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*
@@ -1555,6 +1543,8 @@
// [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
//
private void scanTextDecl() throws Exception {
+ int version = -1;
+ int encoding = -1;
final int TEXTDECL_START = 0;
final int TEXTDECL_VERSION = 1;
final int TEXTDECL_ENCODING = 2;
@@ -1586,8 +1576,8 @@
return;
}
fEntityReader.skipPastSpaces();
- int index = fEntityReader.scanStringLiteral();
- switch (index) {
+ int result = fEntityReader.scanStringLiteral();
+ switch (result) {
case XMLEntityHandler.STRINGLIT_RESULT_QUOTE_REQUIRED:
{
int minorCode = state == TEXTDECL_VERSION ?
@@ -1620,17 +1610,18 @@
//
// version="..."
//
- String version = fStringPool.toString(index);
- if (!"1.0".equals(version)) {
- if (!fEventHandler.validVersionNum(version)) {
+ version = result;
+ String versionString = fStringPool.toString(version);
+ if (!"1.0".equals(versionString)) {
+ if (!fEventHandler.validVersionNum(versionString)) {
abortMarkup(XMLMessages.MSG_VERSIONINFO_INVALID,
XMLMessages.P26_INVALID_VALUE,
- version);
+ versionString);
restoreScannerState(prevState);
return;
}
// NOTE: RECOVERABLE ERROR
- Object[] args = { version };
+ Object[] args = { versionString };
fErrorReporter.reportError(fErrorReporter.getLocator(),
XMLMessages.XML_DOMAIN,
XMLMessages.MSG_VERSION_NOT_SUPPORTED,
@@ -1652,11 +1643,12 @@
//
// encoding = "..."
//
- String encoding = fStringPool.toString(index);
- if (!fEventHandler.validEncName(encoding)) {
+ encoding = result;
+ String encodingString = fStringPool.toString(encoding);
+ if (!fEventHandler.validEncName(encodingString)) {
abortMarkup(XMLMessages.MSG_ENCODINGDECL_INVALID,
XMLMessages.P81_INVALID_VALUE,
- encoding);
+ encodingString);
restoreScannerState(prevState);
return;
}
@@ -1672,6 +1664,7 @@
return;
}
decreaseMarkupDepth();
+ fEventHandler.callTextDecl(version, encoding);
restoreScannerState(prevState);
}
//
@@ -1770,10 +1763,10 @@
if (nodeIndex == -1) {
nodeIndex = prevNodeIndex;
} else if (prevNodeIndex != -1) {
- nodeIndex = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_CHOICE, prevNodeIndex, nodeIndex);
+ nodeIndex = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE, prevNodeIndex, nodeIndex);
}
if (fEntityReader.lookingAtChar('*', true)) {
- nodeIndex = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_ZERO_OR_MORE, nodeIndex);
+ nodeIndex = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE, nodeIndex);
} else if (starRequired) {
reportFatalXMLError(XMLMessages.MSG_MIXED_CONTENT_UNTERMINATED,
XMLMessages.P51_UNTERMINATED,
@@ -1785,7 +1778,7 @@
}
if (nodeIndex != -1) {
if (prevNodeIndex != -1) {
- nodeIndex = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_CHOICE, prevNodeIndex, nodeIndex);
+ nodeIndex = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE, prevNodeIndex, nodeIndex);
}
prevNodeIndex = nodeIndex;
}
@@ -1825,29 +1818,29 @@
elementType);
return -1;
}
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_LEAF, valueIndex);
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_LEAF, valueIndex);
if (fEntityReader.lookingAtChar('?', true)) {
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_ZERO_OR_ONE, nodeIndexStack[depth]);
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE, fNodeIndexStack[depth]);
} else if (fEntityReader.lookingAtChar('*', true)) {
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_ZERO_OR_MORE, nodeIndexStack[depth]);
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE, fNodeIndexStack[depth]);
} else if (fEntityReader.lookingAtChar('+', true)) {
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_ONE_OR_MORE, nodeIndexStack[depth]);
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE, fNodeIndexStack[depth]);
}
while (true) {
checkForPEReference(false);
- if (opStack[depth] != XMLContentSpecNode.CONTENTSPECNODE_SEQ && fEntityReader.lookingAtChar('|', true)) {
- if (prevNodeIndexStack[depth] != -1) {
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(opStack[depth], prevNodeIndexStack[depth], nodeIndexStack[depth]);
+ if (fOpStack[depth] != XMLContentSpec.CONTENTSPECNODE_SEQ && fEntityReader.lookingAtChar('|', true)) {
+ if (fPrevNodeIndexStack[depth] != -1) {
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(fOpStack[depth], fPrevNodeIndexStack[depth], fNodeIndexStack[depth]);
}
- prevNodeIndexStack[depth] = nodeIndexStack[depth];
- opStack[depth] = XMLContentSpecNode.CONTENTSPECNODE_CHOICE;
+ fPrevNodeIndexStack[depth] = fNodeIndexStack[depth];
+ fOpStack[depth] = XMLContentSpec.CONTENTSPECNODE_CHOICE;
break;
- } else if (opStack[depth] != XMLContentSpecNode.CONTENTSPECNODE_CHOICE && fEntityReader.lookingAtChar(',', true)) {
- if (prevNodeIndexStack[depth] != -1) {
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(opStack[depth], prevNodeIndexStack[depth], nodeIndexStack[depth]);
+ } else if (fOpStack[depth] != XMLContentSpec.CONTENTSPECNODE_CHOICE && fEntityReader.lookingAtChar(',', true)) {
+ if (fPrevNodeIndexStack[depth] != -1) {
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(fOpStack[depth], fPrevNodeIndexStack[depth], fNodeIndexStack[depth]);
}
- prevNodeIndexStack[depth] = nodeIndexStack[depth];
- opStack[depth] = XMLContentSpecNode.CONTENTSPECNODE_SEQ;
+ fPrevNodeIndexStack[depth] = fNodeIndexStack[depth];
+ fOpStack[depth] = XMLContentSpec.CONTENTSPECNODE_SEQ;
break;
} else {
if (!fEntityReader.lookingAtChar(')', true)) {
@@ -1856,20 +1849,20 @@
elementType);
}
decreaseParenDepth();
- if (prevNodeIndexStack[depth] != -1) {
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(opStack[depth], prevNodeIndexStack[depth], nodeIndexStack[depth]);
+ if (fPrevNodeIndexStack[depth] != -1) {
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(fOpStack[depth], fPrevNodeIndexStack[depth], fNodeIndexStack[depth]);
}
- int nodeIndex = nodeIndexStack[depth--];
- nodeIndexStack[depth] = nodeIndex;
+ int nodeIndex = fNodeIndexStack[depth--];
+ fNodeIndexStack[depth] = nodeIndex;
if (fEntityReader.lookingAtChar('?', true)) {
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_ZERO_OR_ONE, nodeIndexStack[depth]);
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE, fNodeIndexStack[depth]);
} else if (fEntityReader.lookingAtChar('*', true)) {
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_ZERO_OR_MORE, nodeIndexStack[depth]);
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE, fNodeIndexStack[depth]);
} else if (fEntityReader.lookingAtChar('+', true)) {
- nodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpecNode.CONTENTSPECNODE_ONE_OR_MORE, nodeIndexStack[depth]);
+ fNodeIndexStack[depth] = fEventHandler.addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE, fNodeIndexStack[depth]);
}
if (depth == 0) {
- return nodeIndexStack[0];
+ return fNodeIndexStack[0];
}
}
}
@@ -1895,24 +1888,28 @@
return;
}
int elementIndex = fEventHandler.addElementDecl(elementTypeIndex);
- while (true) {
- boolean sawSpace = checkForPEReference(true);
- if (fEntityReader.lookingAtChar('>', true)) {
- decreaseMarkupDepth();
- return;
- }
- // REVISIT - review this code...
- if (!sawSpace) {
- if (fEntityReader.lookingAtSpace(true)) {
- fEntityReader.skipPastSpaces();
- } else
- reportFatalXMLError(XMLMessages.MSG_SPACE_REQUIRED_BEFORE_ATTRIBUTE_NAME_IN_ATTDEF,
- XMLMessages.P53_SPACE_REQUIRED);
- } else {
- if (fEntityReader.lookingAtSpace(true)) {
- fEntityReader.skipPastSpaces();
- }
+ boolean sawSpace = checkForPEReference(true);
+ if (fEntityReader.lookingAtChar('>', true)) {
+ decreaseMarkupDepth();
+ return;
+ }
+ // REVISIT - review this code...
+ if (!sawSpace) {
+ if (fEntityReader.lookingAtSpace(true)) {
+ fEntityReader.skipPastSpaces();
+ } else
+ reportFatalXMLError(XMLMessages.MSG_SPACE_REQUIRED_BEFORE_ATTRIBUTE_NAME_IN_ATTDEF,
+ XMLMessages.P53_SPACE_REQUIRED);
+ } else {
+ if (fEntityReader.lookingAtSpace(true)) {
+ fEntityReader.skipPastSpaces();
}
+ }
+ if (fEntityReader.lookingAtChar('>', true)) {
+ decreaseMarkupDepth();
+ return;
+ }
+ while (true) {
int attDefName = fEventHandler.checkForAttributeNameWithPEReference(fEntityReader, ' ');
if (attDefName == -1) {
abortMarkup(XMLMessages.MSG_ATTRIBUTE_NAME_REQUIRED_IN_ATTDEF,
@@ -2023,12 +2020,9 @@
if (attDefType == fENUMERATION) {
int index = attDefEnumeration;
if (index != -1) {
- ok = (fStringPool.stringListLength(index) == 1 &&
- (fStringPool.stringInList(index, fDefault) ||
- fStringPool.stringInList(index, fPreserve))) ||
- (fStringPool.stringListLength(index) == 2 &&
+ ok = fStringPool.stringListLength(index) == 2 &&
fStringPool.stringInList(index, fDefault) &&
- fStringPool.stringInList(index, fPreserve));
+ fStringPool.stringInList(index, fPreserve);
}
}
if (!ok) {
@@ -2037,6 +2031,29 @@
elementTypeIndex);
}
}
+ sawSpace = checkForPEReference(true);
+ if (fEntityReader.lookingAtChar('>', true)) {
+ int attDefIndex = fEventHandler.addAttDef(elementIndex, attDefName, attDefType, attDefEnumeration, attDefDefaultType, attDefDefaultValue);
+ decreaseMarkupDepth();
+ return;
+ }
+ // REVISIT - review this code...
+ if (!sawSpace) {
+ if (fEntityReader.lookingAtSpace(true)) {
+ fEntityReader.skipPastSpaces();
+ } else
+ reportFatalXMLError(XMLMessages.MSG_SPACE_REQUIRED_BEFORE_ATTRIBUTE_NAME_IN_ATTDEF,
+ XMLMessages.P53_SPACE_REQUIRED);
+ } else {
+ if (fEntityReader.lookingAtSpace(true)) {
+ fEntityReader.skipPastSpaces();
+ }
+ }
+ if (fEntityReader.lookingAtChar('>', true)) {
+ int attDefIndex = fEventHandler.addAttDef(elementIndex, attDefName, attDefType, attDefEnumeration, attDefDefaultType, attDefDefaultValue);
+ decreaseMarkupDepth();
+ return;
+ }
int attDefIndex = fEventHandler.addAttDef(elementIndex, attDefName, attDefType, attDefEnumeration, attDefDefaultType, attDefDefaultValue);
}
}
@@ -2176,7 +2193,7 @@
fEntityReader.addString(nameOffset, nameLength));
} else {
int entityNameIndex = fEntityReader.addSymbol(nameOffset, nameLength);
- fEntityHandler.startReadingFromEntity(entityNameIndex, markupDepth(), XMLEntityHandler.CONTEXT_IN_DEFAULTATTVALUE);
+ fEntityHandler.startReadingFromEntity(entityNameIndex, markupDepth(), XMLEntityHandler.ENTITYREF_IN_DEFAULTATTVALUE);
}
}
continue;
@@ -2335,7 +2352,7 @@
} else {
int peNameIndex = fEntityReader.addSymbol(nameOffset, nameLength);
int readerDepth = (fScannerState == SCANNER_STATE_CONTENTSPEC) ? parenDepth() : markupDepth();
- fEntityHandler.startReadingFromEntity(peNameIndex, readerDepth, XMLEntityHandler.CONTEXT_IN_DTD_WITHIN_MARKUP);
+ fEntityHandler.startReadingFromEntity(peNameIndex, readerDepth, XMLEntityHandler.ENTITYREF_IN_DTD_WITHIN_MARKUP);
}
fEntityReader.skipPastSpaces();
if (!fEntityReader.lookingAtChar('%', true))
@@ -2356,7 +2373,7 @@
XMLMessages.P70_REQUIRED_NAME);
return;
}
- if (!fEntityHandler.startEntityDecl(isPEDecl, entityName)) {
+ if (!fEventHandler.startEntityDecl(isPEDecl, entityName)) {
skipPastEndOfCurrentMarkup();
return;
}
@@ -2364,17 +2381,16 @@
abortMarkup(XMLMessages.MSG_SPACE_REQUIRED_AFTER_ENTITY_NAME_IN_ENTITYDECL,
XMLMessages.P70_REQUIRED_SPACE,
entityName);
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
if (isPEDecl) {
boolean single;
if ((single = fEntityReader.lookingAtChar('\'', true)) || fEntityReader.lookingAtChar('\"', true)) {
- int location = fEventHandler.saveCurrentLocation();
int value = scanEntityValue(single);
if (value == -1) {
skipPastEndOfCurrentMarkup();
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
checkForPEReference(false);
@@ -2382,16 +2398,16 @@
abortMarkup(XMLMessages.MSG_ENTITYDECL_UNTERMINATED,
XMLMessages.P72_UNTERMINATED,
entityName);
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
decreaseMarkupDepth();
- fEntityHandler.endEntityDecl();
- int entityIndex = fEventHandler.addInternalPEDecl(entityName, value, location);
+ fEventHandler.endEntityDecl();
+ int entityIndex = fEventHandler.addInternalPEDecl(entityName, value);
} else {
if (!scanExternalID(false)) {
skipPastEndOfCurrentMarkup();
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
checkForPEReference(false);
@@ -2399,21 +2415,20 @@
abortMarkup(XMLMessages.MSG_ENTITYDECL_UNTERMINATED,
XMLMessages.P72_UNTERMINATED,
entityName);
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
decreaseMarkupDepth();
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
int entityIndex = fEventHandler.addExternalPEDecl(entityName, fPubidLiteral, fSystemLiteral);
}
} else {
boolean single;
if ((single = fEntityReader.lookingAtChar('\'', true)) || fEntityReader.lookingAtChar('\"', true)) {
- int location = fEventHandler.saveCurrentLocation();
int value = scanEntityValue(single);
if (value == -1) {
skipPastEndOfCurrentMarkup();
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
checkForPEReference(false);
@@ -2421,16 +2436,16 @@
abortMarkup(XMLMessages.MSG_ENTITYDECL_UNTERMINATED,
XMLMessages.P71_UNTERMINATED,
entityName);
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
decreaseMarkupDepth();
- fEntityHandler.endEntityDecl();
- int entityIndex = fEventHandler.addInternalEntityDecl(entityName, value, location);
+ fEventHandler.endEntityDecl();
+ int entityIndex = fEventHandler.addInternalEntityDecl(entityName, value);
} else {
if (!scanExternalID(false)) {
skipPastEndOfCurrentMarkup();
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
boolean unparsed = false;
@@ -2444,18 +2459,18 @@
abortMarkup(XMLMessages.MSG_ENTITYDECL_UNTERMINATED,
XMLMessages.P72_UNTERMINATED,
entityName);
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
decreaseMarkupDepth();
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
int entityIndex = fEventHandler.addExternalEntityDecl(entityName, fPubidLiteral, fSystemLiteral);
} else {
if (!fEntityReader.lookingAtSpace(true)) {
abortMarkup(XMLMessages.MSG_SPACE_REQUIRED_BEFORE_NOTATION_NAME_IN_UNPARSED_ENTITYDECL,
XMLMessages.P76_SPACE_REQUIRED,
entityName);
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
fEntityReader.skipPastSpaces();
@@ -2466,7 +2481,7 @@
abortMarkup(XMLMessages.MSG_NOTATION_NAME_REQUIRED_FOR_UNPARSED_ENTITYDECL,
XMLMessages.P76_REQUIRED,
entityName);
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
int notationName = fEntityReader.addSymbol(ndataOffset, ndataLength);
@@ -2475,11 +2490,11 @@
abortMarkup(XMLMessages.MSG_ENTITYDECL_UNTERMINATED,
XMLMessages.P72_UNTERMINATED,
entityName);
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
return;
}
decreaseMarkupDepth();
- fEntityHandler.endEntityDecl();
+ fEventHandler.endEntityDecl();
int entityIndex = fEventHandler.addUnparsedEntityDecl(entityName, fPubidLiteral, fSystemLiteral, notationName);
}
}
@@ -2590,7 +2605,7 @@
fEntityReader.addString(nameOffset, nameLength));
} else {
int peNameIndex = fEntityReader.addSymbol(nameOffset, nameLength);
- fEntityHandler.startReadingFromEntity(peNameIndex, markupDepth(), XMLEntityHandler.CONTEXT_IN_ENTITYVALUE);
+ fEntityHandler.startReadingFromEntity(peNameIndex, markupDepth(), XMLEntityHandler.ENTITYREF_IN_ENTITYVALUE);
}
fEntityValueMark = fEntityReader.currentOffset();
break;
@@ -2647,7 +2662,7 @@
} else {
int peNameIndex = fEntityReader.addSymbol(nameOffset, nameLength);
int readerDepth = (fScannerState == SCANNER_STATE_CONTENTSPEC) ? parenDepth() : markupDepth();
- fEntityHandler.startReadingFromEntity(peNameIndex, readerDepth, XMLEntityHandler.CONTEXT_IN_DTD_WITHIN_MARKUP);
+ fEntityHandler.startReadingFromEntity(peNameIndex, readerDepth, XMLEntityHandler.ENTITYREF_IN_DTD_WITHIN_MARKUP);
}
fEntityReader.skipPastSpaces();
if (!fEntityReader.lookingAtChar('%', true))
@@ -2658,23 +2673,23 @@
// content model stack
//
private void initializeContentModelStack(int depth) {
- if (opStack == null) {
- opStack = new int[8];
- nodeIndexStack = new int[8];
- prevNodeIndexStack = new int[8];
- } else if (depth == opStack.length) {
+ if (fOpStack == null) {
+ fOpStack = new int[8];
+ fNodeIndexStack = new int[8];
+ fPrevNodeIndexStack = new int[8];
+ } else if (depth == fOpStack.length) {
int[] newStack = new int[depth * 2];
- System.arraycopy(opStack, 0, newStack, 0, depth);
- opStack = newStack;
+ System.arraycopy(fOpStack, 0, newStack, 0, depth);
+ fOpStack = newStack;
newStack = new int[depth * 2];
- System.arraycopy(nodeIndexStack, 0, newStack, 0, depth);
- nodeIndexStack = newStack;
+ System.arraycopy(fNodeIndexStack, 0, newStack, 0, depth);
+ fNodeIndexStack = newStack;
newStack = new int[depth * 2];
- System.arraycopy(prevNodeIndexStack, 0, newStack, 0, depth);
- prevNodeIndexStack = newStack;
+ System.arraycopy(fPrevNodeIndexStack, 0, newStack, 0, depth);
+ fPrevNodeIndexStack = newStack;
}
- opStack[depth] = -1;
- nodeIndexStack[depth] = -1;
- prevNodeIndexStack[depth] = -1;
+ fOpStack[depth] = -1;
+ fNodeIndexStack[depth] = -1;
+ fPrevNodeIndexStack[depth] = -1;
}
}
1.2 +3 -4 xml-xerces/java/src/org/apache/xerces/framework/XMLDocumentHandler.java
Index: XMLDocumentHandler.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/XMLDocumentHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLDocumentHandler.java 2000/04/04 18:34:55 1.1
+++ XMLDocumentHandler.java 2000/04/04 21:14:21 1.2
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,19 +58,18 @@
package org.apache.xerces.framework;
/**
- *
* XMLValidator defines the interface that XMLDocumentScanner and XML
* EntityHandler have with an object that serves as a pluggable validator.
* This abstraction allows validators for XML grammar languages to be
* plugged in and queried for validity checks as the scanner processes
* a document.
- *
+ * <p>
* The document scanner and entity handler need to ask the validator object
* for this information because the validator object is responsible for reading
* the grammar specification file (which contains markup declarations and entity
* declarations)
*
- * @version
+ * @version $Id: XMLDocumentHandler.java,v 1.2 2000/04/04 21:14:21 andyc Exp $
*/
public interface XMLDocumentHandler {
1.3 +61 -41 xml-xerces/java/src/org/apache/xerces/framework/XMLDocumentScanner.java
Index: XMLDocumentScanner.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/XMLDocumentScanner.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLDocumentScanner.java 2000/02/08 01:54:45 1.2
+++ XMLDocumentScanner.java 2000/04/04 21:14:21 1.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -76,7 +76,7 @@
* "connecting" that method to the corresponding method provided
* by the XMLDTDScanner class.
*
- * @version
+ * @version $Id: XMLDocumentScanner.java,v 1.3 2000/04/04 21:14:21 andyc Exp $
*/
public final class XMLDocumentScanner {
//
@@ -220,18 +220,32 @@
/**
* Signal the start of a document
*
+ * @exception java.lang.Exception
+ */
+ public void callStartDocument() throws Exception;
+ /**
+ * Signal the end of a document
+ *
+ * @exception java.lang.Exception
+ */
+ public void callEndDocument() throws Exception;
+ /**
+ * Signal the XML declaration of a document
+ *
* @param version the handle in the string pool for the version number
* @param encoding the handle in the string pool for the encoding
* @param standalong the handle in the string pool for the standalone value
* @exception java.lang.Exception
*/
- public void callStartDocument(int version, int encoding, int standalone) throws Exception;
+ public void callXMLDecl(int version, int encoding, int standalone) throws Exception;
/**
- * Signal the end of a document
+ * Signal the Text declaration of an external entity.
*
+ * @param version the handle in the string pool for the version number
+ * @param encoding the handle in the string pool for the encoding
* @exception java.lang.Exception
*/
- public void callEndDocument() throws Exception;
+ public void callTextDecl(int version, int encoding) throws Exception;
/**
* signal the scanning of a start element tag
*
@@ -245,7 +259,7 @@
* @param readerId the Id of the reader being used to scan the end tag.
* @exception java.lang.Exception
*/
- public boolean callEndElement(int readerId) throws Exception;
+ public void callEndElement(int readerId) throws Exception;
/**
* Check for a valid XML version number
*
@@ -266,12 +280,12 @@
* Signal the start of a CDATA section
* @exception java.lang.Exception
*/
- public void startCDATA() throws Exception;
+ public void callStartCDATA() throws Exception;
/**
* Signal the end of a CDATA section
* @exception java.lang.Exception
*/
- public void endCDATA() throws Exception;
+ public void callEndCDATA() throws Exception;
/**
* Report the scanning of character data
*
@@ -319,12 +333,10 @@
/**
* Constructor
*/
- public XMLDocumentScanner(EventHandler eventHandler,
- StringPool stringPool,
+ public XMLDocumentScanner(StringPool stringPool,
XMLErrorReporter errorReporter,
XMLEntityHandler entityHandler,
XMLEntityHandler.CharBuffer literalData) {
- fEventHandler = eventHandler;
fStringPool = stringPool;
fErrorReporter = errorReporter;
fEntityHandler = entityHandler;
@@ -333,11 +345,20 @@
}
/**
+ * Set the event handler
+ *
+ * @param eventHandler The place to send our callbacks.
+ */
+ public void setEventHandler(XMLDocumentScanner.EventHandler eventHandler) {
+ fEventHandler = eventHandler;
+ }
+
+ /**
* reset the parser so that the instance can be reused
*
* @param stringPool the string pool instance to be used by the reset parser
*/
- public void reset(StringPool stringPool, XMLEntityHandler.CharBuffer literalData) throws Exception {
+ public void reset(StringPool stringPool, XMLEntityHandler.CharBuffer literalData) {
fStringPool = stringPool;
fLiteralData = literalData;
fParseTextDecl = false;
@@ -509,7 +530,7 @@
fEntityReader.addString(nameOffset, nameLength));
} else {
int entityName = fEntityReader.addSymbol(nameOffset, nameLength);
- fEntityHandler.startReadingFromEntity(entityName, fScannerMarkupDepth, XMLEntityHandler.CONTEXT_IN_ATTVALUE);
+ fEntityHandler.startReadingFromEntity(entityName, fScannerMarkupDepth, XMLEntityHandler.ENTITYREF_IN_ATTVALUE);
}
}
} else if (fEntityReader.lookingAtChar('<', true)) {
@@ -728,6 +749,7 @@
}
final class XMLDeclDispatcher implements ScannerDispatcher {
public boolean dispatch(boolean keepgoing) throws Exception {
+ fEventHandler.callStartDocument();
if (fEntityReader.lookingAtChar('<', true)) {
fScannerMarkupDepth++;
setScannerState(SCANNER_STATE_START_OF_MARKUP);
@@ -744,15 +766,12 @@
XMLMessages.P17_RESERVED_PITARGET);
}
} else { // PI
- fEventHandler.callStartDocument(-1, -1, -1);
scanPI(piTarget);
}
- fEventHandler.callStartDocument(-1, -1, -1);
fDispatcher = new PrologDispatcher();
restoreScannerState(SCANNER_STATE_PROLOG);
return true;
}
- fEventHandler.callStartDocument(-1, -1, -1);
if (fEntityReader.lookingAtChar('!', true)) {
if (fEntityReader.lookingAtChar('-', true)) { // comment ?
if (fEntityReader.lookingAtChar('-', true)) {
@@ -781,7 +800,6 @@
return true;
}
} else {
- fEventHandler.callStartDocument(-1, -1, -1);
if (fEntityReader.lookingAtSpace(true)) {
fEntityReader.skipPastSpaces();
} else if (!fEntityReader.lookingAtValidChar(false)) {
@@ -941,10 +959,13 @@
}
}
}
+ int fCurrentElementType = -1;
+ public int getCurrentElementType() {
+ return fCurrentElementType;
+ }
final class ContentDispatcher implements ScannerDispatcher {
private int fContentReader = -1;
private int fElementDepth = 0;
- private int fCurrentElementType = -1;
private int[] fElementTypeStack = new int[8];
void popElementType() {
@@ -1049,7 +1070,7 @@
} else {
if (fEntityReader.skippedString(cdata_string)) {
fEntityReader.setInCDSect(true);
- fEventHandler.startCDATA();
+ fEventHandler.callStartCDATA();
} else {
abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_CONTENT,
XMLMessages.P43_NOT_RECOGNIZED);
@@ -1074,16 +1095,15 @@
}
}
fScannerMarkupDepth--;
- if (fEventHandler.callEndElement(fReaderId)) {
- fDispatcher = new TrailingMiscDispatcher();
- restoreScannerState(SCANNER_STATE_TRAILING_MISC);
- return true;
- }
+ fEventHandler.callEndElement(fReaderId);
if (fElementDepth-- == 0) {
throw new RuntimeException("FWK002 popElementType: fElementDepth-- == 0.");
}
if (fElementDepth == 0) {
fCurrentElementType = - 1;
+ fDispatcher = new TrailingMiscDispatcher();
+ restoreScannerState(SCANNER_STATE_TRAILING_MISC);
+ return true;
} else {
fCurrentElementType = fElementTypeStack[fElementDepth - 1];
}
@@ -1164,7 +1184,7 @@
fScannerMarkupDepth++;
fParseTextDecl = false;
fEntityReader.setInCDSect(true);
- fEventHandler.startCDATA();
+ fEventHandler.callStartCDATA();
break;
case XMLEntityHandler.CONTENT_RESULT_START_OF_ETAG:
fScannerMarkupDepth++;
@@ -1186,16 +1206,15 @@
}
}
fScannerMarkupDepth--;
- if (fEventHandler.callEndElement(fReaderId)) {
- fDispatcher = new TrailingMiscDispatcher();
- restoreScannerState(SCANNER_STATE_TRAILING_MISC);
- return true;
- }
+ fEventHandler.callEndElement(fReaderId);
if (fElementDepth-- == 0) {
throw new RuntimeException("FWK002 popElementType: fElementDepth-- == 0.");
}
if (fElementDepth == 0) {
fCurrentElementType = - 1;
+ fDispatcher = new TrailingMiscDispatcher();
+ restoreScannerState(SCANNER_STATE_TRAILING_MISC);
+ return true;
} else {
fCurrentElementType = fElementTypeStack[fElementDepth - 1];
}
@@ -1242,18 +1261,17 @@
case XMLEntityHandler.CONTENT_RESULT_MATCHING_ETAG:
{
fParseTextDecl = false;
- if (fEventHandler.callEndElement(fReaderId)) {
- if (fScannerState != SCANNER_STATE_END_OF_INPUT) {
- fDispatcher = new TrailingMiscDispatcher();
- fScannerState = SCANNER_STATE_TRAILING_MISC;
- }
- return true;
- }
+ fEventHandler.callEndElement(fReaderId);
if (fElementDepth-- == 0) {
throw new RuntimeException("FWK002 popElementType: fElementDepth-- == 0.");
}
if (fElementDepth == 0) {
fCurrentElementType = - 1;
+ if (fScannerState != SCANNER_STATE_END_OF_INPUT) {
+ fDispatcher = new TrailingMiscDispatcher();
+ fScannerState = SCANNER_STATE_TRAILING_MISC;
+ }
+ return true;
} else {
fCurrentElementType = fElementTypeStack[fElementDepth - 1];
}
@@ -1303,7 +1321,7 @@
} else {
restoreScannerState(SCANNER_STATE_CONTENT);
int entityName = fEntityReader.addSymbol(nameOffset, nameLength);
- fParseTextDecl = fEntityHandler.startReadingFromEntity(entityName, fElementDepth, XMLEntityHandler.CONTEXT_IN_CONTENT);
+ fParseTextDecl = fEntityHandler.startReadingFromEntity(entityName, fElementDepth, XMLEntityHandler.ENTITYREF_IN_CONTENT);
}
break;
case XMLEntityHandler.CONTENT_RESULT_END_OF_CDSECT:
@@ -1314,7 +1332,7 @@
//
if (fEntityReader.getInCDSect()) {
fEntityReader.setInCDSect(false);
- fEventHandler.endCDATA();
+ fEventHandler.callEndCDATA();
fScannerMarkupDepth--;
} else {
reportFatalXMLError(XMLMessages.MSG_CDEND_IN_CONTENT,
@@ -1733,12 +1751,14 @@
return;
}
fScannerMarkupDepth--;
- if (!scanningTextDecl) {
+ if (scanningTextDecl) {
+ fEventHandler.callTextDecl(version, encoding);
+ } else {
//
// Now that we have hit '?>' we are done with XML decl. Call the
// handler before returning.
//
- fEventHandler.callStartDocument(version, encoding, standalone);
+ fEventHandler.callXMLDecl(version, encoding, standalone);
}
}
//
1.2 +2 -7 xml-xerces/java/src/org/apache/xerces/framework/XMLErrorReporter.java
Index: XMLErrorReporter.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/XMLErrorReporter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLErrorReporter.java 1999/11/09 01:12:57 1.1
+++ XMLErrorReporter.java 2000/04/04 21:14:21 1.2
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -62,7 +62,7 @@
/**
* Error handling
*
- * @version
+ * @version $Id: XMLErrorReporter.java,v 1.2 2000/04/04 21:14:21 andyc Exp $
*/
public interface XMLErrorReporter {
//
@@ -77,11 +77,6 @@
/** Fatal error type. */
public static final int ERRORTYPE_FATAL_ERROR = 2;
-
- /**
- * Set the default locator to use when reporting errors.
- */
- public void setLocator(Locator locator);
/**
* Get the default locator to use when reporting errors.
1.15 +57 -1648 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- XMLParser.java 2000/03/11 01:07:58 1.14
+++ XMLParser.java 2000/04/04 21:14:21 1.15
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,59 +58,40 @@
package org.apache.xerces.framework;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.IOException;
-import java.io.FileNotFoundException;
import java.io.Reader;
-import java.net.URL;
-import java.net.MalformedURLException;
import java.util.Locale;
-import java.util.Hashtable;
-import java.util.ResourceBundle;
-import java.util.Stack;
-import java.util.ListResourceBundle;
-import org.apache.xerces.readers.DefaultReaderFactory;
+import org.apache.xerces.readers.DefaultEntityHandler;
import org.apache.xerces.readers.XMLDeclRecognizer;
import org.apache.xerces.readers.XMLEntityHandler;
import org.apache.xerces.readers.XMLEntityReaderFactory;
-import org.apache.xerces.utils.ChunkyByteArray;
import org.apache.xerces.utils.ChunkyCharArray;
-import org.apache.xerces.utils.NamespacesScope;
import org.apache.xerces.utils.StringPool;
-import org.apache.xerces.utils.XMLCharacterProperties;
+
import org.apache.xerces.utils.XMLMessageProvider;
import org.apache.xerces.utils.XMLMessages;
import org.apache.xerces.utils.ImplementationMessages;
-
-// REVISIT - use component factory
-import org.apache.xerces.validators.dtd.DTDValidator;
-import org.apache.xerces.validators.schema.XSchemaValidator;
import org.apache.xerces.validators.datatype.DatatypeMessageProvider;
import org.apache.xerces.validators.schema.SchemaMessageProvider;
+import org.apache.xerces.validators.common.XMLValidator;
+
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.helpers.LocatorImpl;
/**
* This is the base class of all standard parsers.
*
- * @version
+ * @version $Id: XMLParser.java,v 1.15 2000/04/04 21:14:21 andyc Exp $
*/
-public abstract class XMLParser
- implements XMLErrorReporter,
- XMLEntityHandler,
- XMLDocumentScanner.EventHandler,
- DTDValidator.EventHandler,
- Locator {
+public class XMLParser implements XMLErrorReporter {
//
// Constants
@@ -169,49 +150,22 @@
// state
- private XMLAttrList fAttrList = null;
protected boolean fParseInProgress = false;
private boolean fNeedReset = false;
// features
/** Continue after fatal error. */
- private boolean fContinueAfterFatalError;
+ private boolean fContinueAfterFatalError = false;
// properties
/** Error handler. */
- private ErrorHandler fErrorHandler;
-
- // literal strings
-
- private char[] fCharRefData = null;
- private int[] fElementTypeStack = new int[8];
- private int[] fElementEntityStack = new int[8];
- private boolean fCalledStartDocument = false;
- private int fXMLLang = -1;
- protected String fNamespaceSep = "";
-
- // validators
-
- protected XMLValidator fValidator = null;
- protected DTDValidator fDTDValidator = null;
- protected XSchemaValidator fSchemaValidator = null;
- private boolean fCheckedForSchema = false;
+ private ErrorHandler fErrorHandler = null;
// other
- private Locator fLocator = null;
private Locale fLocale = null;
- private LocatorImpl fAttrNameLocator = null;
- private boolean fSeenRootElement = false;
- private boolean fStandaloneDocument = false;
- private int fCDATASymbol = -1;
- protected boolean fNamespacesEnabled = false;//JR- fix defect 48
- private boolean fSendCharDataAsCharArray = false;
- private boolean fValidating = false;
- private boolean fScanningDTD = false;
- private StringPool.CharArrayRange fCurrentElementCharArrayRange = null;
// error information
@@ -223,15 +177,11 @@
//
//
//
- protected XMLDocumentScanner fScanner = null;
protected StringPool fStringPool = null;
protected XMLErrorReporter fErrorReporter = null;
- protected XMLEntityHandler fEntityHandler = null;
- protected XMLEntityReaderFactory fReaderFactory = null;
- protected int fElementDepth = 0;
- protected int fCurrentElementType = -1;
- protected int fCurrentElementEntity = -1;
- protected boolean fInElementContent = false;
+ protected DefaultEntityHandler fEntityHandler = null;
+ protected XMLDocumentScanner fScanner = null;
+ protected XMLValidator fValidator = null;
//
// Constructors
@@ -241,30 +191,22 @@
* Constructor
*/
protected XMLParser() {
-
fStringPool = new StringPool();
fErrorReporter = this;
- fEntityHandler = this;
-
- // set framework properties
- fScanner = new XMLDocumentScanner(/*XMLDocumentScanner.EventHandler*/this, fStringPool, fErrorReporter, fEntityHandler, new ChunkyCharArray(fStringPool));
-
- // other inits
- XMLCharacterProperties.initCharFlags();
- fAttrList = new XMLAttrList(fStringPool);
- fLocator = this;
- fReaderFactory = new DefaultReaderFactory();
-
- // REVISIT - add all other instance variables...
-
- fCDATASymbol = fStringPool.addSymbol("CDATA");
- fDTDValidator = new DTDValidator(/*DTDValidator.EventHandler*/this, fStringPool, fErrorReporter, fEntityHandler);
-
- // set features
- try { setContinueAfterFatalError(false); }
- catch (SAXException e) {} // ignore
+ fEntityHandler = new DefaultEntityHandler(fStringPool, fErrorReporter);
+ fScanner = new XMLDocumentScanner(fStringPool, fErrorReporter, fEntityHandler, new ChunkyCharArray(fStringPool));
+ fValidator = new XMLValidator(fStringPool, fErrorReporter, fEntityHandler, fScanner);
+ }
- } // <init>()
+ /**
+ * Set char data processing preference and handlers.
+ */
+ protected void initHandlers(boolean sendCharDataAsCharArray,
+ XMLDocumentHandler docHandler,
+ XMLDocumentHandler.DTDHandler dtdHandler)
+ {
+ fValidator.initHandlers(sendCharDataAsCharArray, docHandler, dtdHandler);
+ }
//
// Public methods
@@ -364,336 +306,40 @@
/** Reset parser instance so that it can be reused. */
public void reset() throws Exception {
fStringPool.reset();
- fAttrList.reset(fStringPool);
- resetCommon();
-
- } // reset()
+ fEntityHandler.reset(fStringPool);
+ fScanner.reset(fStringPool, new ChunkyCharArray(fStringPool));
+ fValidator.reset(fStringPool);
+ fNeedReset = false;
+ }
// properties (the normal kind)
/**
- * Sets the locator.
- *
- * @param locator The new locator.
- */
- public void setLocator(Locator locator) {
- fLocator = locator;
- }
-
- /**
* return the locator being used by the parser
*
* @return the parser's active locator
*/
public final Locator getLocator() {
- return fLocator;
+ return fEntityHandler;
}
/**
* Set the reader factory.
*/
public void setReaderFactory(XMLEntityReaderFactory readerFactory) {
- fReaderFactory = readerFactory;
- fReaderFactory.setSendCharDataAsCharArray(fSendCharDataAsCharArray);
+ fEntityHandler.setReaderFactory(readerFactory);
}
- // DTD callbacks
-
/**
- * Callback for processing instruction in DTD.
- *
- * @param target the string pool index of the PI's target
- * @param data the string pool index of the PI's data
- * @exception java.lang.Exception
- */
- public void processingInstructionInDTD(int target, int data) throws Exception {
- fStringPool.releaseString(target);
- fStringPool.releaseString(data);
- }
-
- /**
- * Callback for comment in DTD.
+ * Adds a recognizer.
*
- * @param comment the string pool index of the comment text
- * @exception java.lang.Exception
+ * @param recognizer The XML recognizer to add.
*/
- public void commentInDTD(int comment) throws Exception {
- fStringPool.releaseString(comment);
+ public void addRecognizer(XMLDeclRecognizer recognizer) {
+ fEntityHandler.addRecognizer(recognizer);
}
//
- // Public abstract methods
- //
-
- // document callbacks
-
- /**
- * Callback for start of document
- *
- * If the there is no version info, encoding info, or standalone info,
- * the corresponding argument will be set to -1.
- *
- * @param version string pool index of the version attribute's value
- * @param encoding string pool index of the encoding attribute's value
- * @param standAlone string pool index of the standalone attribute's value
- * @exception java.lang.Exception
- */
- public abstract void startDocument(int version, int encoding, int standAlone) throws Exception;
-
- /**
- * callback for the end of document.
- *
- * @exception java.lang.Exception
- */
- public abstract void endDocument() throws Exception;
-
- /**
- * callback for the start of a namespace declaration scope.
- *
- * @param prefix string pool index of the namespace prefix being declared
- * @param uri string pool index of the namespace uri begin bound
- * @param java.lang.Exception
- */
- public abstract void startNamespaceDeclScope(int prefix, int uri) throws Exception;
-
- /**
- * callback for the end a namespace declaration scope.
- *
- * @param prefix string pool index of the namespace prefix being declared
- * @exception java.lang.Exception
- */
- public abstract void endNamespaceDeclScope(int prefix) throws Exception;
-
- /**
- * Supports DOM Level 2 internalSubset additions.
- * Called when the internal subset is completely scanned.
- */
- public abstract void internalSubset(int internalSubset);
-
-
- /**
- * callback for the start of element.
- *
- * @param elementType element handle for the element being scanned
- * @param attrList attrList containing the attributes of the element
- * @param attrListHandle handle into attrList. Allows attributes to be retreived.
- * @exception java.lang.Exception
- */
- public abstract void startElement(int elementType, XMLAttrList attrList, int attrListHandle) throws Exception;
-
- /**
- * callback for end of element.
- *
- * @param elementType element handle for the element being scanned
- * @exception java.lang.Exception
- */
- public abstract void endElement(int elementType) throws Exception;
-
- /**
- * callback for start of entity reference.
- *
- * @param entityName string pool index of the entity name
- * @param entityType the XMLEntityHandler.ENTITYTYPE_* type
- * @see org.apache.xerces.readers.XMLEntityHandler
- * @param entityContext the XMLEntityHandler.CONTEXT_* type for where
- * the entity reference appears
- * @see org.apache.xerces.readers.XMLEntityHandler
- * @exception java.lang.Exception
- */
- public abstract void startEntityReference(int entityName, int entityType, int entityContext) throws Exception;
-
- /**
- * callback for end of entity reference.
- *
- * @param entityName string pool index of the entity anem
- * @param entityType the XMLEntityHandler.ENTITYTYPE_* type
- * @see org.apache.xerces.readers.XMLEntityHandler
- * @param entityContext the XMLEntityHandler.CONTEXT_* type for where
- * the entity reference appears
- * @see org.apache.xerces.readers.XMLEntityHandler
- * @exception java.lang.Exception
- */
- public abstract void endEntityReference(int entityName, int entityType, int entityContext) throws Exception;
-
- /**
- * callback for start of CDATA section.
- * this callback marks the start of a CDATA section
- *
- * @exception java.lang.Exception
- */
- public abstract void startCDATA() throws Exception;
-
- /**
- * callback for end of CDATA section.
- * this callback marks the end of a CDATA section
- *
- * @exception java.lang.Exception
- */
- public abstract void endCDATA() throws Exception;
-
- /**
- * callback for processing instruction.
- *
- * @param target string pool index of the PI target
- * @param data string pool index of the PI data
- * @exception java.lang.Exception
- */
- public abstract void processingInstruction(int target, int data) throws Exception;
-
- /**
- * callback for comment.
- *
- * @param comment string pool index of the comment text
- * @exception java.lang.Exception
- */
- public abstract void comment(int comment) throws Exception;
-
- /**
- * callback for characters (string pool form).
- *
- * @param data string pool index of the characters that were scanned
- * @exception java.lang.Exception
- */
- public abstract void characters(int data) throws Exception;
-
- /**
- * callback for characters.
- *
- * @param ch character array containing the characters that were scanned
- * @param start offset in ch where scanned characters begin
- * @param length length of scanned characters in ch
- * @exception java.lang.Exception
- */
- public abstract void characters(char ch[], int start, int length) throws Exception;
-
- /**
- * callback for ignorable whitespace.
- *
- * @param data string pool index of ignorable whitespace
- * @exception java.lang.Exception
- */
- public abstract void ignorableWhitespace(int data) throws Exception;
-
- /**
- * callback for ignorable whitespace.
- *
- * @param ch character array containing the whitespace that was scanned
- * @param start offset in ch where scanned whitespace begins
- * @param length length of scanned whitespace in ch
- * @exception java.lang.Exception
- */
- public abstract void ignorableWhitespace(char ch[], int start, int length) throws Exception;
-
- // DTD callbacks
-
- /**
- * callback for the start of the DTD
- * This function will be called when a <!DOCTYPE...> declaration is
- * encountered.
- *
- * @param rootElementType element handle for the root element of the document
- * @param publicId string pool index of the DTD's public ID
- * @param systemId string pool index of the DTD's system ID
- * @exception java.lang.Exception
- */
- public abstract void startDTD(int rootElementType, int publicId, int systemId) throws Exception;
-
- /**
- * callback for the end of the DTD
- * This function will be called at the end of the DTD.
- */
- public abstract void endDTD() throws Exception;
-
- /**
- * callback for an element declaration.
- *
- * @param elementType element handle of the element being declared
- * @param contentSpec contentSpec for the element being declared
- * @see XMLValidator.ContentSpec
- * @exception java.lang.Exception
- */
- public abstract void elementDecl(int elementType, XMLValidator.ContentSpec contentSpec) throws Exception;
-
- /**
- * callback for an attribute list declaration.
- *
- * @param elementType element handle for the attribute's element
- * @param attrName string pool index of the attribute name
- * @param attType type of attribute
- * @param enumString String representing the values of the enumeration,
- * if the attribute is of enumerated type, or null if it is not.
- * @param attDefaultType an integer value denoting the DefaultDecl value
- * @param attDefaultValue string pool index of this attribute's default value
- * or -1 if there is no defaultvalue
- * @exception java.lang.Exception
- */
- public abstract void attlistDecl(int elementType,
- int attrName, int attType,
- String enumString,
- int attDefaultType,
- int attDefaultValue) throws Exception;
-
- /**
- * callback for an internal parameter entity declaration.
- *
- * @param entityName string pool index of the entity name
- * @param entityValue string pool index of the entity replacement text
- * @exception java.lang.Exception
- */
- public abstract void internalPEDecl(int entityName, int entityValue) throws Exception;
-
- /**
- * callback for an external parameter entity declaration.
- *
- * @param entityName string pool index of the entity name
- * @param publicId string pool index of the entity's public id.
- * @param systemId string pool index of the entity's system id.
- * @exception java.lang.Exception
- */
- public abstract void externalPEDecl(int entityName, int publicId, int systemId) throws Exception;
-
- /**
- * callback for internal general entity declaration.
- *
- * @param entityName string pool index of the entity name
- * @param entityValue string pool index of the entity replacement text
- * @exception java.lang.Exception
- */
- public abstract void internalEntityDecl(int entityName, int entityValue) throws Exception;
-
- /**
- * callback for external general entity declaration.
- *
- * @param entityName string pool index of the entity name
- * @param publicId string pool index of the entity's public id.
- * @param systemId string pool index of the entity's system id.
- * @exception java.lang.Exception
- */
- public abstract void externalEntityDecl(int entityName, int publicId, int systemId) throws Exception;
-
- /**
- * callback for an unparsed entity declaration.
- *
- * @param entityName string pool index of the entity name
- * @param publicId string pool index of the entity's public id.
- * @param systemId string pool index of the entity's system id.
- * @param notationName string pool index of the notation name.
- * @exception java.lang.Exception
- */
- public abstract void unparsedEntityDecl(int entityName, int publicId, int systemId,
- int notationName) throws Exception;
-
- /**
- * callback for a notation declaration.
- *
- * @param notationName string pool index of the notation name
- * @param publicId string pool index of the notation's public id.
- * @param systemId string pool index of the notation's system id.
- * @exception java.lang.Exception
- */
- public abstract void notationDecl(int notationName, int publicId, int systemId) throws Exception;
-
- //
// Protected methods
//
@@ -719,8 +365,7 @@
"http://xml.org/sax/features/validation");
}
try {
- fDTDValidator.setValidationEnabled(validate);
- getSchemaValidator().setValidationEnabled(validate);
+ fValidator.setValidationEnabled(validate);
}
catch (Exception ex) {
throw new SAXNotSupportedException(ex.getMessage());
@@ -734,7 +379,7 @@
*/
protected boolean getValidation()
throws SAXNotRecognizedException, SAXNotSupportedException {
- return fDTDValidator.getValidationEnabled();
+ return fValidator.getValidationEnabled();
}
/**
@@ -825,7 +470,7 @@
* This method is the equivalent to the feature:
* <pre>
* http://xml.org/sax/features/namespaces
- * </pre>
+ * <pre>
*
* @param process True to process namespaces; false to not process.
*
@@ -838,9 +483,7 @@
throw new SAXNotSupportedException("PAR004 Cannot setFeature(http://xml.org/sax/features/namespaces): parse is in progress.\n"+
"http://xml.org/sax/features/namespaces");
}
- fNamespacesEnabled = process;
- fDTDValidator.setNamespacesEnabled(process);
- getSchemaValidator().setNamespacesEnabled(process);
+ fValidator.setNamespacesEnabled(process);
}
/**
@@ -850,7 +493,7 @@
*/
protected boolean getNamespaces()
throws SAXNotRecognizedException, SAXNotSupportedException {
- return fNamespacesEnabled;
+ return fValidator.getNamespacesEnabled();
}
// Xerces features
@@ -874,12 +517,10 @@
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");
}
try {
- fDTDValidator.setDynamicValidationEnabled(dynamic);
- getSchemaValidator().setDynamicValidationEnabled(dynamic);
+ fValidator.setDynamicValidationEnabled(dynamic);
}
catch (Exception ex) {
throw new SAXNotSupportedException(ex.getMessage());
@@ -894,7 +535,7 @@
*/
protected boolean getValidationDynamic()
throws SAXNotRecognizedException, SAXNotSupportedException {
- return fDTDValidator.getDynamicValidationEnabled();
+ return fValidator.getDynamicValidationEnabled();
}
/**
@@ -913,8 +554,7 @@
*/
protected void setValidationWarnOnDuplicateAttdef(boolean warn)
throws SAXNotRecognizedException, SAXNotSupportedException {
- fDTDValidator.setWarningOnDuplicateAttDef(warn);
- getSchemaValidator().setWarningOnDuplicateAttDef(warn);
+ fValidator.setWarningOnDuplicateAttDef(warn);
}
/**
@@ -925,7 +565,7 @@
*/
protected boolean getValidationWarnOnDuplicateAttdef()
throws SAXNotRecognizedException, SAXNotSupportedException {
- return fDTDValidator.getWarningOnDuplicateAttDef();
+ return fValidator.getWarningOnDuplicateAttDef();
}
/**
@@ -945,8 +585,7 @@
*/
protected void setValidationWarnOnUndeclaredElemdef(boolean warn)
throws SAXNotRecognizedException, SAXNotSupportedException {
- fDTDValidator.setWarningOnUndeclaredElements(warn);
- getSchemaValidator().setWarningOnUndeclaredElements(warn);
+ fValidator.setWarningOnUndeclaredElements(warn);
}
/**
@@ -957,7 +596,7 @@
*/
protected boolean getValidationWarnOnUndeclaredElemdef()
throws SAXNotRecognizedException, SAXNotSupportedException {
- return fDTDValidator.getWarningOnUndeclaredElements();
+ return fValidator.getWarningOnUndeclaredElements();
}
/**
@@ -976,7 +615,7 @@
*/
protected void setAllowJavaEncodings(boolean allow)
throws SAXNotRecognizedException, SAXNotSupportedException {
- fReaderFactory.setAllowJavaEncodingName(allow);
+ fEntityHandler.setAllowJavaEncodings(allow);
}
/**
@@ -986,7 +625,7 @@
*/
protected boolean getAllowJavaEncodings()
throws SAXNotRecognizedException, SAXNotSupportedException {
- return fReaderFactory.getAllowJavaEncodingName();
+ return fEntityHandler.getAllowJavaEncodings();
}
/**
@@ -1046,7 +685,6 @@
// REVISIT: Ask someone what it could possibly hurt to allow
// the application to change this in mid-parse.
if (fParseInProgress) {
- // REVISIT: Localize this message.
throw new SAXNotSupportedException("http://xml.org/sax/properties/namespace-sep: parse is in progress");
}
fNamespaceSep = separator;
@@ -1066,10 +704,6 @@
/***/
/**
- * <b>Note: This property is currently not supported because it is
- * not well defined.</b> Querying its value will throw a
- * SAXNotSupportedException.
- * <p>
* This method is the equivalent to the property:
* <pre>
* http://xml.org/sax/properties/xml-string
@@ -1077,12 +711,10 @@
*
* @see #getProperty
*/
- /***
protected String getXMLString()
throws SAXNotRecognizedException, SAXNotSupportedException {
throw new SAXNotSupportedException("http://xml.org/sax/properties/xml-string");
}
- /***/
// resetting
@@ -1092,50 +724,12 @@
*/
protected void resetOrCopy() throws Exception {
fStringPool = new StringPool();
- fAttrList = new XMLAttrList(fStringPool);
- resetCommon();
- } // resetOrCopy()
-
- private void resetCommon() throws Exception {
+ fEntityHandler.reset(fStringPool);
fScanner.reset(fStringPool, new ChunkyCharArray(fStringPool));
- fValidating = false;
- fScanningDTD = false;
- resetEntityHandler();
- fValidator = null;
- fDTDValidator.reset(fStringPool);
- if (fSchemaValidator != null)
- fSchemaValidator.reset(fStringPool, fErrorReporter, fEntityHandler);
- fCheckedForSchema = false;
+ fValidator.resetOrCopy(fStringPool);
fNeedReset = false;
- fCalledStartDocument = false;
- fSeenRootElement = false;
- fStandaloneDocument = false;
- fCDATASymbol = fStringPool.addSymbol("CDATA");
- fXMLLang = -1;
- // REVISIT - add all other instance variables...
- fElementDepth = 0;
- fCurrentElementType = -1;
- fCurrentElementEntity = -1;
- fInElementContent = false;
}
- // properties
-
- /** Returns the XML Schema validator. */
- protected XSchemaValidator getSchemaValidator() {
- if (fSchemaValidator == null)
- fSchemaValidator = new XSchemaValidator(fStringPool, fErrorReporter, fEntityHandler);
- return fSchemaValidator;
- }
-
- /**
- * Set char data processing preference.
- */
- protected void setSendCharDataAsCharArray(boolean flag) {
- fSendCharDataAsCharArray = flag;
- fReaderFactory.setSendCharDataAsCharArray(fSendCharDataAsCharArray);
- }
-
//
// Parser/XMLReader methods
//
@@ -1152,7 +746,7 @@
* uninstall the currently installed resolver.
*/
public void setEntityResolver(EntityResolver resolver) {
- fEntityResolver = resolver;
+ fEntityHandler.setEntityResolver(resolver);
}
/**
@@ -1163,7 +757,7 @@
* @see #setEntityResolver
*/
public EntityResolver getEntityResolver() {
- return fEntityResolver;
+ return fEntityHandler.getEntityResolver();
}
/**
@@ -1287,8 +881,6 @@
} // setLocale(Locale)
- // resolver
-
//
// XMLErrorReporter methods
//
@@ -1356,13 +948,8 @@
} // reportError(Locator,String,int,int,Object[],int)
- //
- // 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
+ // XMLReader methods
//
/**
@@ -1724,18 +1311,6 @@
}
//
- // SAX2 Handlers
- //
-
- /*
- else if (propertyId.startsWith(SAX2_HANDLERS_PREFIX)) {
- //
- // No handlers defined yet that are common to all parsers.
- //
- }
- */
-
- //
// Xerces Properties
//
@@ -1768,7 +1343,7 @@
* 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
+ * @see org.xml.sax.XMLReader#getProperty
*/
public Object getProperty(String propertyId)
throws SAXNotRecognizedException, SAXNotSupportedException {
@@ -1804,11 +1379,7 @@
// way to check for availability before the parse begins).
//
if (property.equals("xml-string")) {
- //return getXMLString();
- throw new SAXNotSupportedException(
- "PAR019 Property, \"http://xml.org/sax/properties/xml-string\", is not supported.\n"+
- "http://xml.org/sax/properties/xml-string"
- );
+ return getXMLString();
}
//
// Not recognized
@@ -1816,18 +1387,6 @@
}
//
- // SAX2 Handlers
- //
-
- /*
- else if (propertyId.startsWith(SAX2_HANDLERS_PREFIX)) {
- //
- // No handlers defined yet that are common to all parsers.
- //
- }
- */
-
- //
// Xerces Properties
//
@@ -1846,1155 +1405,5 @@
throw new SAXNotRecognizedException(propertyId);
} // getProperty(String):Object
-
- //
- // XMLDocumentScanner methods
- //
-
- /**
- * Returns true if the specified version is valid.
- *
- */
- public boolean validVersionNum(String version) {
- return XMLCharacterProperties.validVersionNum(version);
- }
-
- /**
- * Returns true if the specified encoding is valid.
- *
- */
- public boolean validEncName(String encoding) {
- return XMLCharacterProperties.validEncName(encoding);
- }
-
- // callbacks
-
- /**
- * Call the start document callback.
- */
- public void callStartDocument(int version, int encoding, int standalone) throws Exception {
- if (!fCalledStartDocument) {
- startDocument(version, encoding, standalone);
- fCalledStartDocument = true;
- }
- }
-
- /**
- * Call the end document callback.
- */
- public void callEndDocument() throws Exception {
- if (fCalledStartDocument)
- endDocument();
- }
-
- /** Call the start element callback. */
- public void callStartElement(int elementType) throws Exception {
-
- //
- // Check after all specified attrs are scanned
- // (1) report error for REQUIRED attrs that are missing (V_TAGc)
- // (2) add default attrs (FIXED and NOT_FIXED)
- //
- if (!fSeenRootElement) {
- fSeenRootElement = true;
- if (fValidator == null) {
- fValidator = fDTDValidator;
- }
- fValidator.rootElementSpecified(elementType);
- fStringPool.resetShuffleCount();
- }
- fInElementContent = fValidator.startElement(elementType, fAttrList);
- int attrListHandle = fAttrList.attrListHandle();
- if (attrListHandle != -1) {
- fAttrList.endAttrList();
- // REVISIT - we should check for this more efficiently...
- if (fXMLLang == -1)
- fXMLLang = fStringPool.addSymbol("xml:lang");
- int index = fAttrList.getFirstAttr(attrListHandle);
- while (index != -1) {
- if (fStringPool.equalNames(fAttrList.getAttrName(index), fXMLLang)) {
- fScanner.checkXMLLangAttributeValue(fAttrList.getAttValue(index));
- break;
- }
- index = fAttrList.getNextAttr(index);
- }
- }
- startElement(elementType, fAttrList, attrListHandle);
- int elementEntity = fEntityHandler.getReaderId();
- if (fElementDepth == fElementTypeStack.length) {
- int[] newStack = new int[fElementDepth * 2];
- System.arraycopy(fElementTypeStack, 0, newStack, 0, fElementDepth);
- fElementTypeStack = newStack;
- newStack = new int[fElementDepth * 2];
- System.arraycopy(fElementEntityStack, 0, newStack, 0, fElementDepth);
- fElementEntityStack = newStack;
- }
- fCurrentElementType = elementType;
- fCurrentElementEntity = elementEntity;
- fElementTypeStack[fElementDepth] = elementType;
- fElementEntityStack[fElementDepth] = elementEntity;
- fElementDepth++;
- } // callStartElement(int)
-
- /** Call the end element callback. */
- public boolean callEndElement(int readerId) throws Exception {
- int elementType = fCurrentElementType;
- if (fCurrentElementEntity != readerId) {
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_ELEMENT_ENTITY_MISMATCH,
- XMLMessages.P78_NOT_WELLFORMED,
- new Object[] { fStringPool.toString(elementType) },
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- }
- endElement(elementType);
- fInElementContent = fValidator.endElement(elementType);
- if (fElementDepth-- == 0) {
- throw new RuntimeException("FWK008 Element stack underflow");
- }
- if (fElementDepth == 0) {
- fCurrentElementType = - 1;
- fCurrentElementEntity = -1;
- return true;
- }
- fCurrentElementType = fElementTypeStack[fElementDepth - 1];
- fCurrentElementEntity = fElementEntityStack[fElementDepth - 1];
- return false;
- }
-
- /** Call the processing instruction callback. */
- public void callProcessingInstruction(int target, int data)
- throws Exception {
- processingInstruction(target, data);
- }
-
- /** Call the comment callback. */
- public void callComment(int comment) throws Exception {
- comment(comment);
- }
-
- /** Call the characters callback. */
- public void callCharacters(int ch) throws Exception {
- if (fCharRefData == null)
- fCharRefData = new char[2];
- int count = (ch < 0x10000) ? 1 : 2;
- if (count == 1)
- fCharRefData[0] = (char)ch;
- else {
- fCharRefData[0] = (char)(((ch-0x00010000)>>10)+0xd800);
- fCharRefData[1] = (char)(((ch-0x00010000)&0x3ff)+0xdc00);
- }
- if (fSendCharDataAsCharArray) {
- if (!fInElementContent)
- fValidator.characters(fCharRefData, 0, count);
- characters(fCharRefData, 0, count);
- }
- else {
- int index = fStringPool.addString(new String(fCharRefData, 0, count));
- if (!fInElementContent)
- fValidator.characters(index);
- characters(index);
- }
- }
-
- // scanning
-
- /**
- * Scan an attribute value.
- *
- * @param elementType
- * @param attrName
- * @return XMLDocumentScanner.RESULT_SUCCESS if the attribute was created,
- * XMLDocumentScanner.RESULT_NOT_WELL_FORMED if the scan failed, or
- * XMLDocumentScanner.RESULT_DUPLICATE_ATTR if the attribute is a duplicate.
- * @exception java.lang.Exception
- */
- public int scanAttValue(int elementType, int attrName) throws Exception {
-
- fAttrNameLocator = getLocatorImpl(fAttrNameLocator);
- int attValue = fScanner.scanAttValue(elementType, attrName, fValidating/* && attType != fCDATASymbol*/);
- if (attValue == -1) {
- return XMLDocumentScanner.RESULT_FAILURE;
- }
- if (!fCheckedForSchema) {
- fCheckedForSchema = true;
- if (getValidation() == true && // default namespacedecl
- attrName == fStringPool.addSymbol("xmlns")) {
- fValidator = getSchemaValidator();
- String fs =
- fEntityHandler.expandSystemId(fStringPool.toString(attValue));
- InputSource is = fEntityResolver == null ?
- null : fEntityResolver.resolveEntity(null, fs);
- if (is == null) {
- is = new InputSource(fs);
- }
- fSchemaValidator.loadSchema(is);
- }
- }
- if (!fValidator.attributeSpecified(elementType, fAttrList, attrName, fAttrNameLocator, attValue)) {
- return XMLDocumentScanner.RESULT_DUPLICATE_ATTR;
- }
- return XMLDocumentScanner.RESULT_SUCCESS;
-
- }
-
- /** Scans an element type. */
- public int scanElementType(XMLEntityHandler.EntityReader entityReader, char fastchar) throws Exception {
-
- if (!fNamespacesEnabled) {
- return entityReader.scanName(fastchar);
- }
- int elementType = entityReader.scanQName(fastchar);
- if (fNamespacesEnabled && entityReader.lookingAtChar(':', false)) {
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_TWO_COLONS_IN_QNAME,
- XMLMessages.P5_INVALID_CHARACTER,
- null,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- entityReader.skipPastNmtoken(' ');
- }
- return elementType;
- }
-
- /** Scans an expected element type. */
- public boolean scanExpectedElementType(XMLEntityHandler.EntityReader entityReader, char fastchar) throws Exception {
- if (fCurrentElementCharArrayRange == null)
- fCurrentElementCharArrayRange = fStringPool.createCharArrayRange();
- fStringPool.getCharArrayRange(fCurrentElementType, fCurrentElementCharArrayRange);
- return entityReader.scanExpectedName(fastchar, fCurrentElementCharArrayRange);
- }
-
- /** Scans an attribute name. */
- public int scanAttributeName(XMLEntityHandler.EntityReader entityReader, int elementType) throws Exception {
-
- if (!fSeenRootElement) {
- fSeenRootElement = true;
- if (fValidator == null) {
- fValidator = fDTDValidator;
- }
- fValidator.rootElementSpecified(elementType);
- fStringPool.resetShuffleCount();
- }
- if (!fNamespacesEnabled) {
- return entityReader.scanName('=');
- }
- int attrName = entityReader.scanQName('=');
- if (entityReader.lookingAtChar(':', false)) {
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_TWO_COLONS_IN_QNAME,
- XMLMessages.P5_INVALID_CHARACTER,
- null,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- entityReader.skipPastNmtoken(' ');
- }
- return attrName;
-
- }
-
- /** Scan doctype decl. */
- public void scanDoctypeDecl(boolean standalone) throws Exception {
- fScanningDTD = true;
- fCheckedForSchema = true;
- fStandaloneDocument = standalone;
- fValidator = fDTDValidator;
- fDTDValidator.scanDoctypeDecl(standalone);
- fScanningDTD = false;
- }
-
- /**
- * Tell the parser that we are validating
- */
- public void setValidating(boolean flag) throws Exception {
- fValidating = flag;
- }
- //
- //
- //
- private LocatorImpl getLocatorImpl(LocatorImpl fillin) {
- if (fillin == null)
- return new LocatorImpl(this);
- fillin.setPublicId(getPublicId());
- fillin.setSystemId(getSystemId());
- fillin.setLineNumber(getLineNumber());
- fillin.setColumnNumber(getColumnNumber());
- return fillin;
- }
-
- //
- // XMLEntityHandler methods
- //
-
- /**
- * Character data.
- */
- public void processCharacters(char[] chars, int offset, int length)
- throws Exception {
-
- if (fValidating && !fInElementContent)
- fValidator.characters(chars, offset, length);
- characters(chars, offset, length);
-
- }
-
- /**
- * Character data.
- */
- public void processCharacters(int data)
- throws Exception {
-
- if (fValidating && !fInElementContent)
- fValidator.characters(data);
- characters(data);
-
- }
-
- /**
- * White space.
- */
- public void processWhitespace(char[] chars, int offset, int length)
- throws Exception {
-
- if (fInElementContent) {
- if (fStandaloneDocument && fValidating)
- fValidator.ignorableWhitespace(chars, offset, length);
- ignorableWhitespace(chars, offset, length);
- } else {
- if (fValidating && !fInElementContent)
- fValidator.characters(chars, offset, length);
- characters(chars, offset, length);
- }
-
- }
-
- /**
- * White space.
- */
- public void processWhitespace(int data) throws Exception {
-
- if (fInElementContent) {
- if (fStandaloneDocument && fValidating)
- fValidator.ignorableWhitespace(data);
- ignorableWhitespace(data);
- } else {
- if (fValidating && !fInElementContent)
- fValidator.characters(data);
- characters(data);
- }
-
- }
-
- //
- // Data
- //
- private class ReaderState {
- XMLEntityHandler.EntityReader reader;
- InputSource source;
- int entityName;
- int entityType;
- int entityContext;
- String publicId;
- String systemId;
- int readerId;
- int depth;
- ReaderState nextReaderState;
- }
- private ReaderState fReaderStateFreeList = null;
- //
- //
- //
- private EntityResolver fEntityResolver = null;
- private byte[] fEntityTypeStack = null;
- private int[] fEntityNameStack = null;
- private int fEntityStackDepth = 0;
- private Stack fReaderStack = new Stack();
- private XMLEntityHandler.EntityReader fReader = null;
- private InputSource fSource = null;
- private int fEntityName = -1;
- private int fEntityType = -1;
- private int fEntityContext = -1;
- private String fPublicId = null;
- private String fSystemId = null;
- private int fReaderId = -1;
- private int fReaderDepth = -1;
- private int fNextReaderId = 0;
- private NullReader fNullReader = null;
-
- /**
- * Resets the entity handler.
- */
- private void resetEntityHandler() {
- fReaderStack.removeAllElements();
- fEntityStackDepth = 0;
- fReader = null;
- fSource = null;
- fEntityName = -1;
- fEntityType = -1;
- fEntityContext = -1;
- fPublicId = null;
- fSystemId = null;
- fReaderId = -1;
- fReaderDepth = -1;
- fNextReaderId = 0;
- }
-
- //
- //
- //
-
- /**
- * get the Entity reader.
- */
- public XMLEntityHandler.EntityReader getEntityReader() {
- return fReader;
- }
-
- /**
- * Adds a recognizer.
- *
- * @param recognizer The XML recognizer to add.
- */
- public void addRecognizer(XMLDeclRecognizer recognizer) {
- fReaderFactory.addRecognizer(recognizer);
- }
-
- /**
- * 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
- * indicates a failure to expand the id.
- *
- * @param systemId The systemId to be expanded.
- *
- * @return Returns the URL object representing the expanded system
- * identifier. A null value indicates that the given
- * system identifier is already expanded.
- *
- */
- public String expandSystemId(String systemId) {
- return expandSystemId(systemId, fSystemId);
- }
- private String expandSystemId(String systemId, String currentSystemId) {
- String id = systemId;
-
- // check for bad parameters id
- if (id == null || id.length() == 0) {
- return systemId;
- }
-
- // if id already expanded, return
- try {
- URL url = new URL(id);
- if (url != null) {
- return systemId;
- }
- }
- catch (MalformedURLException e) {
- // continue on...
- }
-
- // normalize id
- id = fixURI(id);
-
- // normalize base
- URL base = null;
- URL url = null;
- try {
- if (currentSystemId == null) {
- String dir;
- try {
- dir = fixURI(System.getProperty("user.dir"));
- }
- catch (SecurityException se) {
- dir = "";
- }
- if (!dir.endsWith("/")) {
- dir = dir + "/";
- }
- base = new URL("file", "", dir);
- }
- else {
- base = new URL(currentSystemId);
- }
-
- // expand id
- url = new URL(base, id);
- }
- catch (Exception e) {
- // let it go through
- }
- if (url == null) {
- return systemId;
- }
- return url.toString();
- }
-
- //
- // Private methods
- //
-
- /**
- * Fixes a platform dependent filename to standard URI form.
- *
- * @param str The string to fix.
- *
- * @return Returns the fixed URI string.
- */
- private static String fixURI(String str) {
-
- // handle platform dependent strings
- str = str.replace(java.io.File.separatorChar, '/');
-
- // Windows fix
- if (str.length() >= 2) {
- char ch1 = str.charAt(1);
- if (ch1 == ':') {
- char ch0 = Character.toUpperCase(str.charAt(0));
- if (ch0 >= 'A' && ch0 <= 'Z') {
- str = "/" + str;
- }
- }
- }
-
- // done
- return str;
- }
-
- //
- //
- //
- private void sendEndOfInputNotifications() throws Exception {
- boolean moreToFollow = fReaderStack.size() > 1;
- fScanner.endOfInput(fEntityName, moreToFollow);
- if (fScanningDTD)
- fDTDValidator.endOfInput(fEntityName, moreToFollow);
- }
- private void sendReaderChangeNotifications() throws Exception {
- fScanner.readerChange(fReader, fReaderId);
- if (fScanningDTD)
- fDTDValidator.readerChange(fReader, fReaderId);
- }
- private void sendStartEntityNotifications() throws Exception {
- startEntityReference(fEntityName, fEntityType, fEntityContext);
- }
- private void sendEndEntityNotifications() throws Exception {
- endEntityReference(fEntityName, fEntityType, fEntityContext);
- }
- /**
- * set up the reader stack to read from the document entity
- */
- public boolean startReadingFromDocument(InputSource source) throws Exception {
- pushEntity(false, -2); // Document Entity
- fSystemId = null;
- pushNullReader();
- fEntityName = -2; // Document Entity
- fEntityType = ENTITYTYPE_DOCUMENT;
- fEntityContext = CONTEXT_DOCUMENT;
- fReaderDepth = 0;
- fReaderId = fNextReaderId++;
- fPublicId = source.getPublicId();
- fSystemId = source.getSystemId();
- sendStartEntityNotifications();
- fSystemId = expandSystemId(fSystemId, null);
- fSource = source;
- boolean xmlDecl = true; // xmlDecl if true, textDecl if false
- try {
- fReader = fReaderFactory.createReader(fEntityHandler, fErrorReporter, source, fSystemId, xmlDecl, fStringPool);
- } catch (MalformedURLException mu) {
- fReader = null;
- String errorSystemId = fSystemId;
- sendEndEntityNotifications();
- popReader();
- popEntity();
- Object[] args = { errorSystemId };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- ImplementationMessages.XERCES_IMPLEMENTATION_DOMAIN,
- ImplementationMessages.IO0,
- 0,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- } catch (FileNotFoundException fnf) {
- fReader = null;
- String errorSystemId = fSystemId;
- sendEndEntityNotifications();
- popReader();
- popEntity();
- Object[] args = { errorSystemId };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- ImplementationMessages.XERCES_IMPLEMENTATION_DOMAIN,
- ImplementationMessages.IO0,
- 0,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- } catch (java.io.UnsupportedEncodingException uee) {
- fReader = null;
- sendEndEntityNotifications();
- popReader();
- popEntity();
- String encoding = uee.getMessage();
- if (encoding == null) {
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_ENCODING_REQUIRED,
- XMLMessages.P81_REQUIRED,
- null,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- } else if (!XMLCharacterProperties.validEncName(encoding)) {
- Object[] args = { encoding };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_ENCODINGDECL_INVALID,
- XMLMessages.P81_INVALID_VALUE,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- } else {
- Object[] args = { encoding };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_ENCODING_NOT_SUPPORTED,
- XMLMessages.P81_NOT_SUPPORTED,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- }
- }
- sendReaderChangeNotifications();
- return fReader != null;
- }
- /**
- * start reading from an external DTD subset
- */
- public void startReadingFromExternalSubset(String publicId, String systemId, int readerDepth) throws Exception {
- pushEntity(true, -1);
- pushReader();
- pushNullReader();
- fEntityName = -1; // External Subset
- fEntityType = ENTITYTYPE_EXTERNAL_SUBSET;
- fEntityContext = CONTEXT_EXTERNAL_SUBSET;
- fReaderDepth = readerDepth;
- fReaderId = fNextReaderId++;
- fPublicId = publicId;
- fSystemId = systemId;
- startReadingFromExternalEntity(false);
- }
- /**
- * stop reading from an external DTD subset
- */
- public void stopReadingFromExternalSubset() throws Exception {
- if (!(fReader instanceof NullReader))
- throw new RuntimeException("FWK004 cannot happen 18"+"\n18");
- popReader();
- sendReaderChangeNotifications();
- }
-
- /**
- * start reading from an external entity
- */
- public boolean startReadingFromEntity(int entityName, int readerDepth, int context) throws Exception {
- if (context > XMLEntityHandler.CONTEXT_IN_CONTENT)
- return startReadingFromParameterEntity(entityName, readerDepth, context);
- int entityHandle = fValidator.lookupEntity(entityName);
- if (entityHandle < 0) {
- int minorCode = XMLMessages.VC_ENTITY_DECLARED;
- int errorType = XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR;
- // REVISIT - the following test in insufficient...
- if (fEntityContext == CONTEXT_DOCUMENT || fEntityContext == CONTEXT_IN_ATTVALUE) {
- minorCode = XMLMessages.WFC_ENTITY_DECLARED;
- errorType = XMLErrorReporter.ERRORTYPE_FATAL_ERROR;
- }
- Object[] args = { fStringPool.toString(entityName) };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_ENTITY_NOT_DECLARED,
- minorCode,
- args,
- errorType);
- return false;
- }
- if (context == CONTEXT_IN_CONTENT) {
- if (fValidator.isUnparsedEntity(entityHandle)) {
- Object[] args = { fStringPool.toString(entityName) };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_REFERENCE_TO_UNPARSED_ENTITY,
- XMLMessages.WFC_PARSED_ENTITY,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- return false;
- }
- } else {
- if (fValidator.isExternalEntity(entityHandle)) {
- Object[] args = { fStringPool.toString(entityName) };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_REFERENCE_TO_EXTERNAL_ENTITY,
- XMLMessages.WFC_NO_EXTERNAL_ENTITY_REFERENCES,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- return false;
- }
- }
- if (!pushEntity(false, entityName)) {
- Object[] args = { fStringPool.toString(entityName),
- entityReferencePath(false, entityName) };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_RECURSIVE_REFERENCE,
- XMLMessages.WFC_NO_RECURSION,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- return false;
- }
- pushReader();
- fEntityName = entityName;
- fEntityContext = context;
- fReaderDepth = readerDepth;
- fReaderId = fNextReaderId++;
- if (context != CONTEXT_IN_CONTENT || !fValidator.externalReferenceInContent(entityHandle)) {
- fEntityType = ENTITYTYPE_INTERNAL;
- fPublicId = null/*"Internal Entity: " + fStringPool.toString(entityName)*/;
- fSystemId = fSystemId; // keep expandSystemId happy
- int value = -1;
- if (context == CONTEXT_IN_CONTENT || context == CONTEXT_IN_DEFAULTATTVALUE)
- value = fValidator.getEntityValue(entityHandle);
- else
- value = fValidator.valueOfReferenceInAttValue(entityHandle);
- startReadingFromInternalEntity(value, false);
- return false;
- }
- fEntityType = ENTITYTYPE_EXTERNAL;
- fPublicId = fValidator.getPublicIdOfEntity(entityHandle);
- fSystemId = fValidator.getSystemIdOfEntity(entityHandle);
- return startReadingFromExternalEntity(true);
- }
- private boolean startReadingFromParameterEntity(int peName, int readerDepth, int context) throws Exception {
- int entityHandle = fValidator.lookupParameterEntity(peName);
- if (entityHandle == -1) {
- // The error is generated by the validator (strange... it is a VC, not a WFC...)
- return false;
- }
- if (!pushEntity(true, peName)) {
- Object[] args = { fStringPool.toString(peName),
- entityReferencePath(true, peName) };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_RECURSIVE_PEREFERENCE,
- XMLMessages.WFC_NO_RECURSION,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- return false;
- }
- pushReader();
- fEntityName = peName;
- fEntityContext = context;
- fReaderDepth = readerDepth;
- fReaderId = fNextReaderId++;
- if (!fValidator.isExternalParameterEntity(entityHandle)) {
- fEntityType = ENTITYTYPE_INTERNAL_PE;
- fPublicId = null/*"Internal Entity: %" + fStringPool.toString(peName)*/;
- fSystemId = fSystemId; // keep expandSystemId happy
- int value = fValidator.getParameterEntityValue(entityHandle);
- startReadingFromInternalEntity(value, fEntityContext == CONTEXT_IN_ENTITYVALUE ? false : true);
- return false;
- }
- fEntityType = ENTITYTYPE_EXTERNAL_PE;
- fPublicId = fValidator.getPublicIdOfParameterEntity(entityHandle);
- fSystemId = fValidator.getSystemIdOfParameterEntity(entityHandle);
- return startReadingFromExternalEntity(true);
- }
- private void startReadingFromInternalEntity(int value, boolean addSpaces) throws Exception {
- if (fEntityContext == CONTEXT_IN_ENTITYVALUE) {
- //
- // REVISIT - consider optimizing the case where the entire entity value
- // consists of a single reference to a parameter entity and do not append
- // the value to fLiteralData again, but re-use the offset/length of the
- // referenced entity for the value of this entity.
- //
- }
- fSource = null;
- sendStartEntityNotifications();
- fReader = fReaderFactory.createStringReader(this, fErrorReporter, fSendCharDataAsCharArray, getLineNumber(), getColumnNumber(), value, fStringPool, addSpaces); // REVISIT - string reader needs better location support
- sendReaderChangeNotifications();
- }
- private boolean startReadingFromExternalEntity(boolean checkForTextDecl) throws Exception {
- if (fEntityContext == CONTEXT_IN_ENTITYVALUE) {
- //
- // REVISIT - Can we get the spec changed ?
- // There is a perverse edge case to handle here... We have a reference
- // to an external PE within a literal EntityValue. For the PE to be
- // well-formed, it must match the extPE production, but the code that
- // appends the replacement text to the entity value is in no position
- // to do a complete well-formedness check !!
- //
- }
- if (fEntityContext == CONTEXT_IN_DTD_WITHIN_MARKUP) {
- //
- // REVISIT - Can we get the spec changed ?
- // There is a perverse edge case to handle here... We have a reference
- // to an external PE within markup. For the PE to be well-formed, it
- // must match the extPE production, which is probably not going to be
- // very useful expanded in the middle of a markup declaration. The
- // problem is that an empty file, a file containing just whitespace or
- // another PE that is just empty or whitespace, matches extPE !!
- //
- }
- sendStartEntityNotifications();
- ReaderState rs = (ReaderState) fReaderStack.peek();
- fSystemId = expandSystemId(fSystemId, rs.systemId);
- fSource = fEntityResolver == null ? null : fEntityResolver.resolveEntity(fPublicId, fSystemId);
- if (fSource == null) {
- fSource = new InputSource(fSystemId);
- if (fPublicId != null)
- fSource.setPublicId(fPublicId);
- }
- boolean textDecl = false; // xmlDecl if true, textDecl if false
- try {
- fReader = fReaderFactory.createReader(fEntityHandler, fErrorReporter, fSource, fSystemId, textDecl, fStringPool);
- } catch (MalformedURLException mu) {
- fReader = null;
- String errorSystemId = fSystemId;
- sendEndEntityNotifications();
- popReader();
- popEntity();
- Object[] args = { errorSystemId };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- ImplementationMessages.XERCES_IMPLEMENTATION_DOMAIN,
- ImplementationMessages.IO0,
- 0,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- } catch (FileNotFoundException fnf) {
- fReader = null;
- String errorSystemId = fSystemId;
- sendEndEntityNotifications();
- popReader();
- popEntity();
- Object[] args = { errorSystemId };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- ImplementationMessages.XERCES_IMPLEMENTATION_DOMAIN,
- ImplementationMessages.IO0,
- 0,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- } catch (java.io.UnsupportedEncodingException uee) {
- fReader = null;
- sendEndEntityNotifications();
- popReader();
- popEntity();
- String encoding = uee.getMessage();
- if (encoding == null) {
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_ENCODING_REQUIRED,
- XMLMessages.P81_REQUIRED,
- null,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- } else if (!XMLCharacterProperties.validEncName(encoding)) {
- Object[] args = { encoding };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_ENCODINGDECL_INVALID,
- XMLMessages.P81_INVALID_VALUE,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- } else {
- Object[] args = { encoding };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- XMLMessages.MSG_ENCODING_NOT_SUPPORTED,
- XMLMessages.P81_NOT_SUPPORTED,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- }
- }
- if (fReader == null || !checkForTextDecl) {
- sendReaderChangeNotifications();
- return false;
- }
- int readerId = fReaderId;
- sendReaderChangeNotifications();
- boolean parseTextDecl = fReader.lookingAtChar('<', false);
- if (readerId != fReaderId)
- parseTextDecl = false;
- return parseTextDecl;
- }
-
- //
- // reader stack
- //
- private void pushNullReader() {
- ReaderState rs = fReaderStateFreeList;
- if (rs == null)
- rs = new ReaderState();
- else
- fReaderStateFreeList = rs.nextReaderState;
- if (fNullReader == null)
- fNullReader = new NullReader();
- rs.reader = fNullReader;
- rs.source = null;
- rs.entityName = -1; // Null Entity
- rs.entityType = -1; // Null Entity
- rs.entityContext = -1; // Null Entity
- rs.publicId = "Null Entity";
- rs.systemId = fSystemId;
- rs.readerId = fNextReaderId++;
- rs.depth = -1;
- rs.nextReaderState = null;
- fReaderStack.push(rs);
- }
- private void pushReader() {
- ReaderState rs = fReaderStateFreeList;
- if (rs == null)
- rs = new ReaderState();
- else
- fReaderStateFreeList = rs.nextReaderState;
- rs.reader = fReader;
- rs.source = fSource;
- rs.entityName = fEntityName;
- rs.entityType = fEntityType;
- rs.entityContext = fEntityContext;
- rs.publicId = fPublicId;
- rs.systemId = fSystemId;
- rs.readerId = fReaderId;
- rs.depth = fReaderDepth;
- rs.nextReaderState = null;
- fReaderStack.push(rs);
- }
- private void popReader() {
- if (fReaderStack.empty())
- throw new RuntimeException("FWK004 cannot happen 19"+"\n19");
- ReaderState rs = (ReaderState) fReaderStack.pop();
- fReader = rs.reader;
- fSource = rs.source;
- fEntityName = rs.entityName;
- fEntityType = rs.entityType;
- fEntityContext = rs.entityContext;
- fPublicId = rs.publicId;
- fSystemId = rs.systemId;
- fReaderId = rs.readerId;
- fReaderDepth = rs.depth;
- rs.nextReaderState = fReaderStateFreeList;
- fReaderStateFreeList = rs;
- }
-
- //
- // entity stack
- //
- /**
- * start an entity declaration
- */
- public boolean startEntityDecl(boolean isPE, int entityName) throws Exception {
- if (!pushEntity(isPE, entityName)) {
- int majorCode = isPE ? XMLMessages.MSG_RECURSIVE_PEREFERENCE : XMLMessages.MSG_RECURSIVE_REFERENCE;
- Object[] args = { fStringPool.toString(entityName),
- entityReferencePath(isPE, entityName) };
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- XMLMessages.XML_DOMAIN,
- majorCode,
- XMLMessages.WFC_NO_RECURSION,
- args,
- XMLErrorReporter.ERRORTYPE_FATAL_ERROR);
- return false;
- }
- return true;
- }
- /**
- * end an entity declaration
- */
- public void endEntityDecl() throws Exception {
- popEntity();
- }
- private boolean pushEntity(boolean isPE, int entityName) throws Exception {
- if (entityName >= 0) {
- for (int i = 0; i < fEntityStackDepth; i++) {
- if (fEntityNameStack[i] == entityName && fEntityTypeStack[i] == (isPE ? 1 : 0)) {
- return false;
- }
- }
- }
- if (fEntityTypeStack == null) {
- fEntityTypeStack = new byte[8];
- fEntityNameStack = new int[8];
- } else if (fEntityStackDepth == fEntityTypeStack.length) {
- byte[] newTypeStack = new byte[fEntityStackDepth * 2];
- System.arraycopy(fEntityTypeStack, 0, newTypeStack, 0, fEntityStackDepth);
- fEntityTypeStack = newTypeStack;
- int[] newNameStack = new int[fEntityStackDepth * 2];
- System.arraycopy(fEntityNameStack, 0, newNameStack, 0, fEntityStackDepth);
- fEntityNameStack = newNameStack;
- }
- fEntityTypeStack[fEntityStackDepth] = (byte)(isPE ? 1 : 0);
- fEntityNameStack[fEntityStackDepth] = entityName;
- fEntityStackDepth++;
- return true;
- }
- private String entityReferencePath(boolean isPE, int entityName) {
- StringBuffer sb = new StringBuffer();
- sb.append("(top-level)");
- for (int i = 0; i < fEntityStackDepth; i++) {
- if (fEntityNameStack[i] >= 0) {
- sb.append('-');
- sb.append(fEntityTypeStack[i] == 1 ? '%' : '&');
- sb.append(fStringPool.toString(fEntityNameStack[i]));
- sb.append(';');
- }
- }
- sb.append('-');
- sb.append(isPE ? '%' : '&');
- sb.append(fStringPool.toString(entityName));
- sb.append(';');
- return sb.toString();
- }
- private void popEntity() throws Exception {
- fEntityStackDepth--;
- }
-
- //
- //
- //
- /**
- * This method is provided for scanner implementations.
- */
- public int getReaderId() {
- return fReaderId;
- }
- /**
- * This method is provided for scanner implementations.
- */
- public void setReaderDepth(int depth) {
- fReaderDepth = depth;
- }
- /**
- * This method is provided for scanner implementations.
- */
- public int getReaderDepth() {
- return fReaderDepth;
- }
- /**
- * Return the public identifier of the <code>InputSource</code> that we are processing.
- *
- * @return The public identifier, or null if not provided.
- */
- public String getPublicId() {
- return fPublicId;
- }
- /**
- * Return the system identifier of the <code>InputSource</code> that we are processing.
- *
- * @return The system identifier, or null if not provided.
- */
- public String getSystemId() {
- return fSystemId;
- }
- /**
- * Return the line number of the current position within the document that we are processing.
- *
- * @return The current line number.
- */
- public int getLineNumber() {
- return fReader.getLineNumber();
- }
- /**
- * Return the column number of the current position within the document that we are processing.
- *
- * @return The current column number.
- */
- public int getColumnNumber() {
- return fReader.getColumnNumber();
- }
- /**
- * This method is called by the reader subclasses at the
- * end of input, and also by the scanner directly to force
- * a reader change during error recovery.
- */
- public XMLEntityHandler.EntityReader changeReaders() throws Exception {
- sendEndOfInputNotifications();
- sendEndEntityNotifications();
- popReader();
- sendReaderChangeNotifications();
- popEntity();
- return fReader;
- }
-
- //
- // We use the null reader after we have reached the
- // end of input for the document or external subset.
- //
- private final class NullReader implements XMLEntityHandler.EntityReader {
- //
- //
- //
- public NullReader() {
- }
- public int currentOffset() {
- return -1;
- }
- public int getLineNumber() {
- return -1;
- }
- public int getColumnNumber() {
- return -1;
- }
- public void setInCDSect(boolean inCDSect) {
- }
- public boolean getInCDSect() {
- return false;
- }
- public void append(XMLEntityHandler.CharBuffer charBuffer, int offset, int length) {
- }
- public int addString(int offset, int length) {
- return -1;
- }
- public int addSymbol(int offset, int length) {
- return -1;
- }
- public boolean lookingAtChar(char ch, boolean skipPastChar) {
- return false;
- }
- public boolean lookingAtValidChar(boolean skipPastChar) {
- return false;
- }
- public boolean lookingAtSpace(boolean skipPastChar) {
- return false;
- }
- public void skipToChar(char ch) {
- }
- public void skipPastSpaces() {
- }
- public void skipPastName(char fastcheck) {
- }
- public void skipPastNmtoken(char fastcheck) {
- }
- public boolean skippedString(char[] s) {
- return false;
- }
- public int scanInvalidChar() {
- return -1;
- }
- public int scanCharRef(boolean hex) {
- return XMLEntityHandler.CHARREF_RESULT_INVALID_CHAR;
- }
- public int scanStringLiteral() {
- return XMLEntityHandler.STRINGLIT_RESULT_QUOTE_REQUIRED;
- }
- public int scanAttValue(char qchar, boolean asSymbol) {
- return XMLEntityHandler.ATTVALUE_RESULT_INVALID_CHAR;
- }
- public int scanEntityValue(int qchar, boolean createString) {
- return XMLEntityHandler.ENTITYVALUE_RESULT_INVALID_CHAR;
- }
- public boolean scanExpectedName(char fastcheck, StringPool.CharArrayRange expectedName) {
- return false;
- }
- public int scanQName(char fastcheck) {
- return -1;
- }
- public int scanName(char fastcheck) {
- return -1;
- }
- public int scanContent(int elementType) throws Exception {
- return XMLEntityHandler.CONTENT_RESULT_INVALID_CHAR;
- }
- }
-} // class XMLParser
+}
1.11 +48 -50 xml-xerces/java/src/org/apache/xerces/msg/ExceptionMessages.java
Index: ExceptionMessages.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/msg/ExceptionMessages.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ExceptionMessages.java 2000/02/20 01:16:06 1.10
+++ ExceptionMessages.java 2000/04/04 21:14:22 1.11
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,61 +63,61 @@
* This file contains error and warning messages to be localized
* The messages are arranged in key and value tuples in a ListResourceBundle.
*
- * @version
+ * @version $Id: ExceptionMessages.java,v 1.11 2000/04/04 21:14:22 andyc Exp $
*/
public class ExceptionMessages extends ListResourceBundle {
/** The list resource bundle contents. */
public static final Object CONTENTS[][] = {
// org.apache.xerces.msg.ExceptionMessageLocalizer
- { "FMT001", "Message Formatting Error." },
+ { "FMT001", "Message Formatting Error." },
- // org.apache.html
+ // org.apache.html
- { "HTM001", "State error: startDocument fired twice on one builder." },
- { "HTM002", "State error: document never started or missing document element." },
- { "HTM003", "State error: document ended before end of document element." },
- { "HTM004", "Argument ''tagName'' is null." },
- { "HTM005", "State error: Document.getDocumentElement returns null." },
- { "HTM006", "State error: startElement called after end of document element." },
- { "HTM007", "State error: endElement called with no current node." },
- { "HTM008", "State error: mismatch in closing tag name {0}" },
- { "HTM009", "State error: character data found outside of root element." },
- { "HTM010", "State error: character data found outside of root element." },
- { "HTM011", "Argument ''topLevel'' is null." },
- { "HTM012", "Argument ''index'' is negative." },
- { "HTM013", "Argument ''name'' is null." },
- { "HTM014", "Argument ''title'' is null." },
- { "HTM015", "Tag ''{0}'' associated with an Element class that failed to construct." },
- { "HTM016", "Argument ''caption'' is not an element of type <CAPTION>." },
- { "HTM017", "Argument ''tHead'' is not an element of type <THEAD>." },
- { "HTM018", "Argument ''tFoot'' is not an element of type <TFOOT>." },
- { "HTM019", "OpenXML Error: Could not find class {0} implementing HTML element {1}" },
-
- // org.apache.xml.serialize
-
- { "SER001", "Argument ''output'' is null." },
- { "SER002", "No writer supplied for serializer" },
- { "SER003", "The resource [{0}] could not be found." },
- { "SER004", "The resource [{0}] could not load: {1}" },
- { "SER005", "The method ''{0}'' is not supported by this factory" },
-
- // org.apache.xerces.dom
-
- { "DOM001", "Modification not allowed" },
- { "DOM002", "Illegal character" },
- { "DOM003", "Namespace error" },
- { "DOM004", "Index out of bounds" },
- { "DOM005", "Wrong document" },
- { "DOM006", "Hierarchy request error" },
- { "DOM007", "Not supported" },
- { "DOM008", "Not found" },
- { "DOM009", "Attribute already in use" },
- { "DOM010", "Unspecified event type" },
- { "DOM011", "Invalid state" },
- { "DOM012", "Invalid node type" },
- { "DOM013", "Bad boundary points" },
+ { "HTM001", "State error: startDocument fired twice on one builder." },
+ { "HTM002", "State error: document never started or missing document element." },
+ { "HTM003", "State error: document ended before end of document element." },
+ { "HTM004", "Argument ''tagName'' is null." },
+ { "HTM005", "State error: Document.getDocumentElement returns null." },
+ { "HTM006", "State error: startElement called after end of document element." },
+ { "HTM007", "State error: endElement called with no current node." },
+ { "HTM008", "State error: mismatch in closing tag name {0}" },
+ { "HTM009", "State error: character data found outside of root element." },
+ { "HTM010", "State error: character data found outside of root element." },
+ { "HTM011", "Argument ''topLevel'' is null." },
+ { "HTM012", "Argument ''index'' is negative." },
+ { "HTM013", "Argument ''name'' is null." },
+ { "HTM014", "Argument ''title'' is null." },
+ { "HTM015", "Tag ''{0}'' associated with an Element class that failed to construct." },
+ { "HTM016", "Argument ''caption'' is not an element of type <CAPTION>." },
+ { "HTM017", "Argument ''tHead'' is not an element of type <THEAD>." },
+ { "HTM018", "Argument ''tFoot'' is not an element of type <TFOOT>." },
+ { "HTM019", "OpenXML Error: Could not find class {0} implementing HTML element {1}" },
+
+ // org.apache.xml.serialize
+
+ { "SER001", "Argument ''output'' is null." },
+ { "SER002", "No writer supplied for serializer" },
+ { "SER003", "The resource [{0}] could not be found." },
+ { "SER004", "The resource [{0}] could not load: {1}" },
+ { "SER005", "The method ''{0}'' is not supported by this factory" },
+
+ // org.apache.xerces.dom
+
+ { "DOM001", "Modification not allowed" },
+ { "DOM002", "Illegal character" },
+ { "DOM003", "Namespace error" },
+ { "DOM004", "Index out of bounds" },
+ { "DOM005", "Wrong document" },
+ { "DOM006", "Hierarchy request error" },
+ { "DOM007", "Not supported" },
+ { "DOM008", "Not found" },
+ { "DOM009", "Attribute already in use" },
+ { "DOM010", "Unspecified event type" },
+ { "DOM011", "Invalid state" },
+ { "DOM012", "Invalid node type" },
+ { "DOM013", "Bad boundary points" },
// org.apache.xerces.framework
{ "FWK001", "{0}] scannerState: {1}" },
@@ -131,7 +131,7 @@
// org.apache.xerces.parsers
{ "PAR001", "Fatal error constructing DOMParser." },
- { "PAR002", "Class, \"{0}\", is not of type org.w3c.dom.Document." },
+ { "PAR002", "Class, \"{0}\", is not of type org.w3c.dom" },
{ "PAR003", "Class, \"{0}\", not found." },
{ "PAR004", "Cannot setFeature({0}): parse is in progress." },
{ "PAR005", "Property, \"{0}\" is read-only." },
@@ -148,8 +148,6 @@
{ "PAR015", "startEntityReference(): ENTITYTYPE_UNPARSED" },
{ "PAR016", "endEntityReference(): ENTITYTYPE_UNPARSED" },
{ "PAR017", "cannot happen: {0}" },
- { "PAR018", "{0} state for feature \"{1}\" is not supported." },
- { "PAR019", "Property, \"{0}\", is not supported." },
// org.apache.xerces.readers
1.3 +6 -3 xml-xerces/java/src/org/apache/xerces/msg/SchemaMessages.java
Index: SchemaMessages.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/msg/SchemaMessages.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SchemaMessages.java 2000/01/29 00:26:58 1.2
+++ SchemaMessages.java 2000/04/04 21:14:22 1.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,7 +63,7 @@
* This file contains error and warning messages for the Schema validator
* The messages are arranged in key and value tuples in a ListResourceBundle.
*
- * @version
+ * @version $Id: SchemaMessages.java,v 1.3 2000/04/04 21:14:22 andyc Exp $
*/
public class SchemaMessages extends ListResourceBundle {
/** The list resource bundle contents. */
@@ -90,7 +90,10 @@
{ "IllegalAttContent", "Illegal content {0} in attribute group" },
{ "ValueNotInteger", "Value of {0} is not an integer." },
{ "DatatypeError", "Datatype error: {0}." },
- };
+ { "TypeAlreadySet", "The type of the element has already been declared." },
+ { "GenericError", "Schema error: {0}." },
+ { "UnexpectedError", "UnexpectedError" },
+ };
/** Returns the list resource bundle contents. */
public Object[][] getContents() {
1.12 +78 -79 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DOMParser.java 2000/02/21 18:56:06 1.11
+++ DOMParser.java 2000/04/04 21:14:23 1.12
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,9 +63,9 @@
import org.apache.xerces.dom.TextImpl;
import org.apache.xerces.framework.XMLAttrList;
-import org.apache.xerces.framework.XMLContentSpecNode;
+import org.apache.xerces.framework.XMLContentSpec;
+import org.apache.xerces.framework.XMLDocumentHandler;
import org.apache.xerces.framework.XMLParser;
-import org.apache.xerces.framework.XMLValidator;
import org.apache.xerces.readers.XMLEntityHandler;
import org.apache.xerces.utils.StringPool;
import org.apache.xerces.validators.schema.XUtil;
@@ -94,21 +94,18 @@
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
-// REVISIT: Change use of AttributeList to Attributes. -Ac
-import org.xml.sax.AttributeList;
-import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
-import org.xml.sax.SAXParseException;
/**
* DOMParser provides a parser which produces a W3C DOM tree as its output
*
- * @version
+ * @version $Id: DOMParser.java,v 1.12 2000/04/04 21:14:23 andyc Exp $
*/
public class DOMParser
extends XMLParser
+ implements XMLDocumentHandler, XMLDocumentHandler.DTDHandler
{
//
@@ -224,6 +221,8 @@
/** Default constructor. */
public DOMParser() {
+ initHandlers(false, this, this);
+
// setup parser state
init();
@@ -372,8 +371,6 @@
fAposIndex = fStringPool.addSymbol("apos");
fQuotIndex = fStringPool.addSymbol("quot");
- setSendCharDataAsCharArray(false);
-
fSeenRootElement = false;
fAttrList = new XMLAttrList(fStringPool);
@@ -889,19 +886,7 @@
//
/** Start document. */
- public void startDocument(int versionIndex, int encodingIndex,
- int standAloneIndex) {
-
- // clean up unused strings
- if (versionIndex != -1) {
- fStringPool.orphanString(versionIndex);
- }
- if (encodingIndex != -1) {
- fStringPool.orphanString(encodingIndex);
- }
- if (standAloneIndex != -1) {
- fStringPool.orphanString(standAloneIndex);
- }
+ public void startDocument() {
// deferred expansion
String documentClassName = null;
@@ -954,6 +939,23 @@
/** End document. */
public void endDocument() throws Exception {}
+ /** XML declaration. */
+ public void xmlDecl(int versionIndex, int encodingIndex, int standaloneIndex) throws Exception {
+
+ // release strings
+ fStringPool.releaseString(versionIndex);
+ fStringPool.releaseString(encodingIndex);
+ fStringPool.releaseString(standaloneIndex);
+ }
+
+ /** Text declaration. */
+ public void textDecl(int versionIndex, int encodingIndex) throws Exception {
+
+ // release strings
+ fStringPool.releaseString(versionIndex);
+ fStringPool.releaseString(encodingIndex);
+ }
+
/** Report the start of the scope of a namespace declaration. */
public void startNamespaceDeclScope(int prefix, int uri) throws Exception {}
@@ -988,8 +990,8 @@
// copy schema grammar, if needed
if (!fSeenRootElement) {
fSeenRootElement = true;
- if (fGrammarAccess && fValidator == fSchemaValidator) {
- Document schemaDocument = fSchemaValidator.getSchemaDocument();
+ if (fGrammarAccess) {
+ Document schemaDocument = fValidator.getSchemaDocument();
if (schemaDocument != null) {
if (fDocumentTypeIndex == -1) {
fDocumentTypeIndex = fDeferredDocumentImpl.createDocumentType(elementTypeIndex, -1, -1);
@@ -1011,7 +1013,6 @@
catch (SAXException s) {}
String elementName = fStringPool.toString(elementTypeIndex);
- AttributeList attrList = xmlAttrList.getAttributeList(attrListIndex);
Element e;
if (nsEnabled) {
e = fDocument.createElementNS(
@@ -1021,39 +1022,40 @@
} else {
e = fDocument.createElement(elementName);
}
- int attrListLength = attrList.getLength();
- for (int i = 0; i < attrListLength; i++) {
+ int attrHandle = xmlAttrList.getFirstAttr(attrListIndex);
+ while (attrHandle != -1) {
if (nsEnabled) {
- int attName = xmlAttrList.getAttrName(i);
- String attNameStr = fStringPool.toString(attName);
- int nsURIIndex = fStringPool.getURIForQName(attName);
- String namespaceURI = fStringPool.toString(nsURIIndex);
- // DOM Level 2 wants all namespace declaration attributes
- // to be bound to "http://www.w3.org/2000/xmlns/"
- // So as long as the XML parser doesn't do it, it needs to
- // done here.
- int prefixIndex = fStringPool.getPrefixForQName(attName);
- String prefix = fStringPool.toString(prefixIndex);
- if (namespaceURI == null) {
- if (prefix != null) {
- if (prefix.equals("xmlns")) {
- namespaceURI = "http://www.w3.org/2000/xmlns/";
- }
- } else if (attNameStr.equals("xmlns")) {
- namespaceURI = "http://www.w3.org/2000/xmlns/";
- }
- }
- e.setAttributeNS(namespaceURI,
- attNameStr,
- attrList.getValue(i));
+ int attName = xmlAttrList.getAttrName(attrHandle);
+ String attNameStr = fStringPool.toString(attName);
+ int nsURIIndex = fStringPool.getURIForQName(attName);
+ String namespaceURI = fStringPool.toString(nsURIIndex);
+ // DOM Level 2 wants all namespace declaration attributes
+ // to be bound to "http://www.w3.org/2000/xmlns/"
+ // So as long as the XML parser doesn't do it, it needs to
+ // done here.
+ int prefixIndex = fStringPool.getPrefixForQName(attName);
+ String prefix = fStringPool.toString(prefixIndex);
+ if (namespaceURI == null) {
+ if (prefix != null) {
+ if (prefix.equals("xmlns")) {
+ namespaceURI = "http://www.w3.org/2000/xmlns/";
+ }
+ } else if (attNameStr.equals("xmlns")) {
+ namespaceURI = "http://www.w3.org/2000/xmlns/";
+ }
+ }
+ e.setAttributeNS(namespaceURI,
+ attNameStr,
+ fStringPool.toString(xmlAttrList.getAttValue(attrHandle)));
} else {
- String attrName = attrList.getName(i);
- String attrValue = attrList.getValue(i);
+ String attrName = fStringPool.toString(xmlAttrList.getAttrName(attrHandle));
+ String attrValue = fStringPool.toString(xmlAttrList.getAttValue(attrHandle));
e.setAttribute(attrName, attrValue);
- if (fDocumentImpl != null && !xmlAttrList.isSpecified(i)) {
+ if (fDocumentImpl != null && !xmlAttrList.isSpecified(attrHandle)) {
((AttrImpl)e.getAttributeNode(attrName)).setSpecified(false);
}
}
+ attrHandle = xmlAttrList.getNextAttr(attrHandle);
}
fCurrentElementNode.appendChild(e);
fCurrentElementNode = e;
@@ -1076,15 +1078,14 @@
// copy schema grammar, if needed
if (!fSeenRootElement) {
fSeenRootElement = true;
- if (fDocumentImpl != null && fGrammarAccess && fValidator == fSchemaValidator) {
- Document schemaDocument = fSchemaValidator.getSchemaDocument();
+ if (fDocumentImpl != null && fGrammarAccess) {
+ Document schemaDocument = fValidator.getSchemaDocument();
if (schemaDocument != null) {
if (fDocumentType == null) {
String rootName = elementName;
String systemId = ""; // REVISIT: How do we get this value? -Ac
String publicId = ""; // REVISIT: How do we get this value? -Ac
- fDocumentType = fDocumentImpl.createDocumentType(rootName, publicId,
- systemId);
+ fDocumentType = fDocumentImpl.createDocumentType(rootName, publicId, systemId);
fDocument.appendChild(fDocumentType);
}
@@ -1298,7 +1299,7 @@
}
// we only support one context for entity references right now...
- if (entityContext != XMLEntityHandler.CONTEXT_IN_CONTENT) {
+ if (entityContext != XMLEntityHandler.ENTITYREF_IN_CONTENT) {
return;
}
@@ -1341,7 +1342,7 @@
}
// we only support one context for entity references right now...
- if (entityContext != XMLEntityHandler.CONTEXT_IN_CONTENT) {
+ if (entityContext != XMLEntityHandler.ENTITYREF_IN_CONTENT) {
return;
}
@@ -1432,7 +1433,7 @@
String publicString = fStringPool.toString(publicId);
String systemString = fStringPool.toString(systemId);
fDocumentType = fDocumentImpl.
- createDocumentType(rootElementName, publicString, systemString);
+ createDocumentType(rootElementName, publicString, systemString);
fDocumentImpl.appendChild(fDocumentType);
if (fGrammarAccess) {
@@ -1513,8 +1514,7 @@
/**
* <!ELEMENT Name contentspec>
*/
- public void elementDecl(int elementTypeIndex,
- XMLValidator.ContentSpec contentSpec)
+ public void elementDecl(int elementTypeIndex, XMLContentSpec contentSpec)
throws Exception {
if (DEBUG_ATTLIST_DECL) {
@@ -1583,7 +1583,7 @@
// <!ELEMENT name (#PCDATA)>
int contentType = contentSpec.getType();
String contentTypeName = fStringPool.toString(contentType);
- XMLContentSpecNode node = new XMLContentSpecNode();
+ XMLContentSpec.Node node = new XMLContentSpec.Node();
int contentSpecHandle = contentSpec.getHandle();
if (contentSpecHandle != -1) {
contentSpec.getNode(contentSpecHandle, node);
@@ -1662,7 +1662,7 @@
int elementRefIndex = fDeferredDocumentImpl.createElement(fStringPool.addSymbol("element"), fAttrList, handle);
fDeferredDocumentImpl.insertBefore(typeIndex, elementRefIndex, getFirstChildElement(typeIndex, "element"));
contentSpec.getNode(index, node);
- } while (node.type != XMLContentSpecNode.CONTENTSPECNODE_LEAF);
+ } while (node.type != XMLContentSpec.CONTENTSPECNODE_LEAF);
}
}
@@ -1699,7 +1699,7 @@
// <!ELEMENT name (#PCDATA)>
int contentType = contentSpec.getType();
String contentTypeName = fStringPool.toString(contentType);
- XMLContentSpecNode node = new XMLContentSpecNode();
+ XMLContentSpec.Node node = new XMLContentSpec.Node();
int contentSpecHandle = contentSpec.getHandle();
if (contentSpecHandle != -1) {
contentSpec.getNode(contentSpecHandle, node);
@@ -1766,7 +1766,7 @@
elementRef.setAttribute("ref", elementRefName);
type.insertBefore(elementRef, XUtil.getFirstChildElement(type, "element"));
contentSpec.getNode(index, node);
- } while (node.type != XMLContentSpecNode.CONTENTSPECNODE_LEAF);
+ } while (node.type != XMLContentSpec.CONTENTSPECNODE_LEAF);
}
}
@@ -2493,21 +2493,20 @@
* containing element, even when the content model contains a
* single element reference.
*/
- private Element createContentModel(XMLValidator.ContentSpec contentSpec,
- XMLContentSpecNode node) {
+ private Element createContentModel(XMLContentSpec contentSpec, XMLContentSpec.Node node) {
Element model = createContentModel(contentSpec, node,
new DocumentImpl(), null);
return model;
- } // createContentModel(XMLContentSpecNode):Element
+ } // createContentModel(XMLContentSpec.Node):Element
/**
* This is the real <em>createContentModel</em> method. This is a
* recursive solution.
*/
- private Element createContentModel(XMLValidator.ContentSpec contentSpec,
- XMLContentSpecNode node,
+ private Element createContentModel(XMLContentSpec contentSpec,
+ XMLContentSpec.Node node,
Document factory,
Element parent) {
@@ -2515,19 +2514,19 @@
int minOccur = 1;
int maxOccur = 1;
switch (node.type) {
- case XMLContentSpecNode.CONTENTSPECNODE_ONE_OR_MORE: {
+ case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: {
minOccur = 1;
maxOccur = -1;
contentSpec.getNode(node.value, node);
break;
}
- case XMLContentSpecNode.CONTENTSPECNODE_ZERO_OR_MORE: {
+ case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: {
minOccur = 0;
maxOccur = -1;
contentSpec.getNode(node.value, node);
break;
}
- case XMLContentSpecNode.CONTENTSPECNODE_ZERO_OR_ONE: {
+ case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: {
minOccur = 0;
maxOccur = 1;
contentSpec.getNode(node.value, node);
@@ -2540,8 +2539,8 @@
switch (nodeType) {
// CHOICE or SEQUENCE
- case XMLContentSpecNode.CONTENTSPECNODE_CHOICE:
- case XMLContentSpecNode.CONTENTSPECNODE_SEQ: {
+ case XMLContentSpec.CONTENTSPECNODE_CHOICE:
+ case XMLContentSpec.CONTENTSPECNODE_SEQ: {
// go down left side
int leftIndex = node.value;
@@ -2556,7 +2555,7 @@
factory, null);
// append left children
- String type = nodeType == XMLContentSpecNode.CONTENTSPECNODE_CHOICE
+ String type = nodeType == XMLContentSpec.CONTENTSPECNODE_CHOICE
? "choice"
: "seq";
Element model = left;
@@ -2589,7 +2588,7 @@
}
// LEAF
- case XMLContentSpecNode.CONTENTSPECNODE_LEAF: {
+ case XMLContentSpec.CONTENTSPECNODE_LEAF: {
String name = fStringPool.toString(node.value);
Element leaf = factory.createElement("element");
leaf.setAttribute("ref", name);
@@ -2604,7 +2603,7 @@
// error
return null;
- } // createContentModel(XMLContentSpecNode,Element):Element
+ } // createContentModel(XMLContentSpec.Node,Element):Element
/**
* Sets the appropriate occurrence count attributes on the specified
1.10 +110 -84 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SAXParser.java 2000/03/11 01:08:33 1.9
+++ SAXParser.java 2000/04/04 21:14:23 1.10
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,8 +58,9 @@
package org.apache.xerces.parsers;
import org.apache.xerces.framework.XMLAttrList;
+import org.apache.xerces.framework.XMLContentSpec;
+import org.apache.xerces.framework.XMLDocumentHandler;
import org.apache.xerces.framework.XMLParser;
-import org.apache.xerces.framework.XMLValidator;
import org.apache.xerces.readers.XMLEntityHandler;
import org.apache.xerces.utils.StringPool;
@@ -82,13 +83,13 @@
/**
* SAXParser provides a parser which implements the SAX1 and SAX2
- * parser APIs
+ * parser APIs.
*
- * @version
+ * @version $Id: SAXParser.java,v 1.10 2000/04/04 21:14:23 andyc Exp $
*/
public class SAXParser
extends XMLParser
- implements Parser, XMLReader {
+ implements Parser, XMLReader, XMLDocumentHandler, XMLDocumentHandler.DTDHandler {
//
// Constants
@@ -132,7 +133,7 @@
// parser/xmlreader handlers
/** DTD handler. */
- private DTDHandler fDTDHandler;
+ private org.xml.sax.DTDHandler fDTDHandler;
// xmlreader handlers
@@ -157,13 +158,14 @@
/** Default constructor. */
public SAXParser() {
- setSendCharDataAsCharArray(true);
- try{
- //setNamespaces(true ); //JR-defect 48 fix - turn on Namespaces
- setFeature( "http://xml.org/sax/features/namespaces", true );
- }catch( SAXNotRecognizedException e ){
- }catch( SAXNotSupportedException e ){
+ try {
+ //JR-defect 48 fix - turn on Namespaces
+ setNamespaces(true);
}
+ catch (Exception e) {
+ // ignore
+ }
+ initHandlers(true, this, this);
}
//
@@ -423,7 +425,7 @@
* argument is null.
* @see #getDTDHandler
*/
- public void setDTDHandler(DTDHandler handler) {
+ public void setDTDHandler(org.xml.sax.DTDHandler handler) {
fDTDHandler = handler;
}
@@ -434,7 +436,7 @@
* has been registered.
* @see #setDTDHandler
*/
- public DTDHandler getDTDHandler() {
+ public org.xml.sax.DTDHandler getDTDHandler() {
return fDTDHandler;
}
@@ -459,8 +461,6 @@
"http://xml.org/sax/features/namespace-prefixes");
}
fNamespacePrefixes = process;
- //fDTDValidator.setNamespacePrefixes(process);
- //getSchemaValidator().setNamespacePrefixes(process);
}
/**
@@ -502,29 +502,7 @@
if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
String feature = featureId.substring(SAX2_FEATURES_PREFIX.length());
- // http://xml.org/sax/features/namespace-prefixes
- // controls the reporting of raw prefixed names and Namespace
- // declarations (xmlns* attributes): when this feature is false
- // (the default), raw prefixed names may optionally be reported,
- // and xmlns* attributes must not be reported.
- //
- if (feature.equals("namespace-prefixes")) {
- setNamespacePrefixes(state);
- return;
- }
- // http://xml.org/sax/features/string-interning
- // controls the use of java.lang.String#intern() for strings
- // passed to SAX handlers.
- //
- if (feature.equals("string-interning")) {
- if (state) {
- throw new SAXNotSupportedException(
- "PAR018 "+state+" state for feature \""+featureId+"\" is not supported.\n"+
- state+'\t'+featureId
- );
- }
- return;
- }
+
/*
//
// http://xml.org/sax/features/normalize-text
@@ -548,7 +526,32 @@
return;
}
*/
+
+ // http://xml.org/sax/features/namespace-prefixes
+ // controls the reporting of raw prefixed names and Namespace
+ // declarations (xmlns* attributes): when this feature is false
+ // (the default), raw prefixed names may optionally be reported,
+ // and xmlns* attributes must not be reported.
+ //
+ if (feature.equals("namespace-prefixes")) {
+ setNamespacePrefixes(state);
+ return;
+ }
+ // http://xml.org/sax/features/string-interning
+ // controls the use of java.lang.String#intern() for strings
+ // passed to SAX handlers.
//
+ if (feature.equals("string-interning")) {
+ if (state) {
+ throw new SAXNotSupportedException(
+ "PAR018 "+state+" state for feature \""+featureId+"\" is not supported.\n"+
+ state+'\t'+featureId
+ );
+ }
+ return;
+ }
+
+ //
// Drop through and perform default processing
//
}
@@ -597,23 +600,7 @@
if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
String feature = featureId.substring(SAX2_FEATURES_PREFIX.length());
- // http://xml.org/sax/features/namespace-prefixes
- // controls the reporting of raw prefixed names and Namespace
- // declarations (xmlns* attributes): when this feature is false
- // (the default), raw prefixed names may optionally be reported,
- // and xmlns* attributes must not be reported.
- //
- if (feature.equals("namespace-prefixes")) {
- return getNamespacePrefixes();
- }
- // http://xml.org/sax/features/string-interning
- // controls the use of java.lang.String#intern() for strings
- // passed to SAX handlers.
- //
- if (feature.equals("string-interning")) {
- // NOTE: This is the only value supported by the parser. -Ac
- return false;
- }
+
/*
//
// http://xml.org/sax/features/normalize-text
@@ -635,7 +622,25 @@
return getUseLocator();
}
*/
+
+ // http://xml.org/sax/features/namespace-prefixes
+ // controls the reporting of raw prefixed names and Namespace
+ // declarations (xmlns* attributes): when this feature is false
+ // (the default), raw prefixed names may optionally be reported,
+ // and xmlns* attributes must not be reported.
//
+ if (feature.equals("namespace-prefixes")) {
+ return getNamespacePrefixes();
+ }
+ // http://xml.org/sax/features/string-interning
+ // controls the use of java.lang.String#intern() for strings
+ // passed to SAX handlers.
+ //
+ if (feature.equals("string-interning")) {
+ return false;
+ }
+
+ //
// Drop through and perform default processing
//
}
@@ -930,7 +935,7 @@
* @param model The content model as a normalized string.
* @exception SAXException The application may raise an exception.
*/
- public void elementDecl(int elementType, XMLValidator.ContentSpec contentSpec) throws Exception {
+ public void elementDecl(int elementType, XMLContentSpec contentSpec) throws Exception {
if (fDeclHandler != null || DEBUG_CALLBACKS) {
@@ -1145,20 +1150,12 @@
}
/** Start document. */
- public void startDocument(int versionIndex, int encodingIndex, int standaloneIndex)
- throws Exception {
+ public void startDocument() throws Exception {
// perform callbacks
if (DEBUG_CALLBACKS) {
System.err.println("setDocumentLocator(<locator>)");
- String notes = "";
- if (versionIndex != -1)
- notes += " version='" + fStringPool.toString(versionIndex) + "'";
- if (encodingIndex != -1)
- notes += " encoding='" + fStringPool.toString(encodingIndex) + "'";
- if (standaloneIndex != -1)
- notes += " standalone='" + fStringPool.toString(standaloneIndex) + "'";
- System.err.println("startDocument()" + notes);
+ System.err.println("startDocument()");
}
if (fDocumentHandler != null) {
fDocumentHandler.setDocumentLocator(getLocator());
@@ -1169,13 +1166,8 @@
fContentHandler.startDocument();
}
- // release strings
- fStringPool.releaseString(versionIndex);
- fStringPool.releaseString(encodingIndex);
- fStringPool.releaseString(standaloneIndex);
+ } // startDocument()
- } // startDocument(int,int,int)
-
/** End document. */
public void endDocument() throws Exception {
@@ -1192,6 +1184,46 @@
} // endDocument()
+ /** XML declaration. */
+ public void xmlDecl(int versionIndex, int encodingIndex, int standaloneIndex) throws Exception {
+
+ // perform callbacks
+ if (DEBUG_CALLBACKS) {
+ String notes = "";
+ if (versionIndex != -1)
+ notes += " version='" + fStringPool.toString(versionIndex) + "'";
+ if (encodingIndex != -1)
+ notes += " encoding='" + fStringPool.toString(encodingIndex) + "'";
+ if (standaloneIndex != -1)
+ notes += " standalone='" + fStringPool.toString(standaloneIndex) + "'";
+ System.err.println("xmlDecl(<?xml" + notes + "?>)");
+ }
+
+ // release strings
+ fStringPool.releaseString(versionIndex);
+ fStringPool.releaseString(encodingIndex);
+ fStringPool.releaseString(standaloneIndex);
+
+ }
+
+ /** Text declaration. */
+ public void textDecl(int versionIndex, int encodingIndex) throws Exception {
+
+ // perform callbacks
+ if (DEBUG_CALLBACKS) {
+ String notes = "";
+ if (versionIndex != -1)
+ notes += " version='" + fStringPool.toString(versionIndex) + "'";
+ if (encodingIndex != -1)
+ notes += " encoding='" + fStringPool.toString(encodingIndex) + "'";
+ System.err.println("textDecl(<?xml" + notes + "?>)");
+ }
+
+ // release strings
+ fStringPool.releaseString(versionIndex);
+ fStringPool.releaseString(encodingIndex);
+ }
+
/**
* Report the start of the scope of a namespace declaration.
*/
@@ -1268,7 +1300,6 @@
? fStringPool.toString(localIndex) : "";
String raw = name;
fAttributes.clear();
- boolean namespacePrefixes = getNamespacePrefixes();
for (int attrIndex = attrList.getFirstAttr(attrListIndex);
attrIndex != -1;
attrIndex = attrList.getNextAttr(attrIndex)) {
@@ -1283,9 +1314,9 @@
String attrType = fStringPool.toString(attrList.getAttType(attrIndex));
String attrValue = fStringPool.toString(attrList.getAttValue(attrIndex));
int attrPrefix = fStringPool.getPrefixForQName(attrNameIndex);
- if (namespacePrefixes ||
- (!namespacePrefixes
- && attrPrefix != fStringPool.addSymbol("xmlns")
+ boolean namespacePrefixes = getNamespacePrefixes();
+ if (!namespaces || namespacePrefixes ||
+ (attrPrefix != fStringPool.addSymbol("xmlns")
&& attrLocalIndex != fStringPool.addSymbol("xmlns")
))
fAttributes.addAttribute(attrUri, attrLocal, attrRaw,
@@ -1316,7 +1347,8 @@
String uri = uriIndex != -1 && namespaces
? fStringPool.toString(uriIndex) : "";
int localIndex = fStringPool.getLocalPartForQName(elementType);
- String local = localIndex != -1 ? fStringPool.toString(localIndex) : "";
+ String local = localIndex != -1 && namespaces
+ ? fStringPool.toString(localIndex) : "";
String raw = fStringPool.toString(elementType);
fContentHandler.endElement(uri, local, raw);
}
@@ -1462,9 +1494,6 @@
}
}
- public void processingInstructionInDTD(int piTarget, int piData) throws Exception {
- processingInstruction(piTarget, piData);
- }
/** Comment. */
public void comment(int dataIndex) throws Exception {
@@ -1484,9 +1513,6 @@
} else {
fStringPool.releaseString(dataIndex);
}
- }
- public void commentInDTD(int dataIndex) throws Exception {
- comment(dataIndex);
}
/** Characters. */
1.5 +1 -0 xml-xerces/java/src/org/apache/xerces/readers/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/readers/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Makefile 2000/02/29 02:02:21 1.4
+++ Makefile 2000/04/04 21:14:24 1.5
@@ -3,6 +3,7 @@
TARGETS=\
AbstractCharReader.class\
CharReader.class\
+ DefaultEntityHandler.class\
DefaultReaderFactory.class\
EBCDICRecognizer.class\
MIME2Java.class\
1.3 +48 -11 xml-xerces/java/src/org/apache/xerces/readers/StreamingCharReader.java
Index: StreamingCharReader.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/readers/StreamingCharReader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StreamingCharReader.java 1999/12/18 04:21:22 1.2
+++ StreamingCharReader.java 2000/04/04 21:14:24 1.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -70,8 +70,8 @@
/**
* An reader class for applications that need to process input data as
* it arrives on the stream.
- * *
- * @version
+ *
+ * @version $Id: StreamingCharReader.java,v 1.3 2000/04/04 21:14:24 andyc Exp $
*/
public class StreamingCharReader extends XMLEntityReader {
@@ -344,6 +344,10 @@
if (XMLCharacterProperties.fgAsciiInitialNameChar[ch] == 0)
return;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
return;
}
@@ -356,6 +360,10 @@
if (XMLCharacterProperties.fgAsciiNameChar[ch] == 0)
return;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_NameCharFlag) == 0)
return;
}
@@ -374,6 +382,10 @@
if (XMLCharacterProperties.fgAsciiNameChar[ch] == 0)
return;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_NameCharFlag) == 0)
return;
}
@@ -612,6 +624,10 @@
if (XMLCharacterProperties.fgAsciiInitialNameChar[ch] == 0)
return -1;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
return -1;
}
@@ -627,6 +643,10 @@
if (XMLCharacterProperties.fgAsciiNameChar[ch] == 0)
break;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_NameCharFlag) == 0)
break;
}
@@ -660,6 +680,10 @@
if (XMLCharacterProperties.fgAsciiNameChar[ch] == 0)
return true;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_NameCharFlag) == 0)
return true;
}
@@ -678,6 +702,10 @@
if (ch == ':')
return -1;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
return -1;
}
@@ -717,6 +745,10 @@
if (XMLCharacterProperties.fgAsciiInitialNameChar[ch] == 0 || ch == ':')
lpok = false;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
lpok = false;
}
@@ -728,6 +760,10 @@
}
}
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_NameCharFlag) == 0)
break;
}
@@ -1130,9 +1166,9 @@
if (!fSendCharDataAsCharArray) {
int stringIndex = addString(offset, length);
if (isWhitespace)
- fEntityHandler.processWhitespace(stringIndex);
+ fCharDataHandler.processWhitespace(stringIndex);
else
- fEntityHandler.processCharacters(stringIndex);
+ fCharDataHandler.processCharacters(stringIndex);
return;
}
@@ -1144,9 +1180,9 @@
//
if (length != 0) {
if (isWhitespace)
- fEntityHandler.processWhitespace(dataChunk.toCharArray(), index, length);
+ fCharDataHandler.processWhitespace(dataChunk.toCharArray(), index, length);
else
- fEntityHandler.processCharacters(dataChunk.toCharArray(), index, length);
+ fCharDataHandler.processCharacters(dataChunk.toCharArray(), index, length);
}
return;
}
@@ -1157,9 +1193,9 @@
int count = length;
int nbytes = CharDataChunk.CHUNK_SIZE - index;
if (isWhitespace)
- fEntityHandler.processWhitespace(dataChunk.toCharArray(), index, nbytes);
+ fCharDataHandler.processWhitespace(dataChunk.toCharArray(), index, nbytes);
else
- fEntityHandler.processCharacters(dataChunk.toCharArray(), index, nbytes);
+ fCharDataHandler.processCharacters(dataChunk.toCharArray(), index, nbytes);
count -= nbytes;
//
@@ -1172,9 +1208,9 @@
}
nbytes = count <= CharDataChunk.CHUNK_SIZE ? count : CharDataChunk.CHUNK_SIZE;
if (isWhitespace)
- fEntityHandler.processWhitespace(dataChunk.toCharArray(), 0, nbytes);
+ fCharDataHandler.processWhitespace(dataChunk.toCharArray(), 0, nbytes);
else
- fEntityHandler.processCharacters(dataChunk.toCharArray(), 0, nbytes);
+ fCharDataHandler.processCharacters(dataChunk.toCharArray(), 0, nbytes);
count -= nbytes;
} while (count > 0);
}
@@ -1339,5 +1375,6 @@
protected char[] fMostRecentData = null;
protected int fMostRecentChar = 0;
protected int fLength = 0;
+ protected boolean fCalledCharPropInit = false;
}
1.3 +33 -8 xml-xerces/java/src/org/apache/xerces/readers/StringReader.java
Index: StringReader.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/readers/StringReader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StringReader.java 1999/11/29 18:05:03 1.2
+++ StringReader.java 2000/04/04 21:14:24 1.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -67,19 +67,19 @@
/**
* Reader for processing internal entity replacement text.
- *
+ * <p>
* This reader processes data contained within strings kept
* in the string pool. It provides the support for both
* general and parameter entities. The location support
* as we are processing the replacement text is somewhat
* poor and needs to be updated when "nested locations"
* have been implemented.
- *
+ * <p>
* For efficiency, we return instances of this class to a
* free list and reuse those instances to process other
* strings.
*
- * @version
+ * @version $Id: StringReader.java,v 1.3 2000/04/04 21:14:24 andyc Exp $
*/
final class StringReader extends XMLEntityReader {
/**
@@ -368,6 +368,10 @@
if (ch == -1 || XMLCharacterProperties.fgAsciiInitialNameChar[ch] == 0)
return;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
return;
}
@@ -379,6 +383,10 @@
if (ch == -1 || XMLCharacterProperties.fgAsciiNameChar[ch] == 0)
return;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_NameCharFlag) == 0)
return;
}
@@ -396,6 +404,10 @@
if (ch == -1 || XMLCharacterProperties.fgAsciiNameChar[ch] == 0)
return;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_NameCharFlag) == 0)
return;
}
@@ -613,6 +625,10 @@
if (ch == -1) {
return changeReaders().scanExpectedName(fastcheck, expectedName);
}
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
int nameOffset = fCurrentOffset;
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
return false;
@@ -639,6 +655,10 @@
if (ch == -1) {
return changeReaders().scanQName(fastcheck);
}
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
int nameOffset = fCurrentOffset;
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
return -1;
@@ -662,6 +682,10 @@
if (ch == -1) {
return changeReaders().scanName(fastcheck);
}
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
int nameOffset = fCurrentOffset;
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
return -1;
@@ -909,15 +933,15 @@
if (!fSendCharDataAsCharArray) {
int stringIndex = addString(offset, length);
if (isWhitespace)
- fEntityHandler.processWhitespace(stringIndex);
+ fCharDataHandler.processWhitespace(stringIndex);
else
- fEntityHandler.processCharacters(stringIndex);
+ fCharDataHandler.processCharacters(stringIndex);
return;
}
if (isWhitespace)
- fEntityHandler.processWhitespace(fData.toCharArray(), offset, length);
+ fCharDataHandler.processWhitespace(fData.toCharArray(), offset, length);
else
- fEntityHandler.processCharacters(fData.toCharArray(), offset, length);
+ fCharDataHandler.processCharacters(fData.toCharArray(), offset, length);
}
//
//
@@ -934,4 +958,5 @@
private int fMostRecentChar;
private StringReader fNextFreeReader = null;
private static StringReader fgFreeReaders = null;
+ private boolean fCalledCharPropInit = false;
}
1.3 +21 -10 xml-xerces/java/src/org/apache/xerces/readers/UCSReader.java
Index: UCSReader.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/readers/UCSReader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UCSReader.java 2000/03/06 21:12:04 1.2
+++ UCSReader.java 2000/04/04 21:14:24 1.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -67,14 +67,14 @@
/**
* Reader for UCS-2 and UCS-4 encodings.
- *
+ * <p>
* This reader is created by the UCSRecognizer class when it decides that the
* byte stream is encoded in a format supported by this class. This class
* was intended to be another example of an encoding sensitive reader that
* could take advantage of the system design to improve performance and reduce
* resource consumption, but the actual performance tuning remains to be done.
*
- * @version
+ * @version $Id: UCSReader.java,v 1.3 2000/04/04 21:14:24 andyc Exp $
*/
final class UCSReader extends XMLEntityReader implements StringPool.StringProducer {
@@ -106,6 +106,7 @@
private int fBytesPerChar = -1;
private boolean fBigEndian = true;
private ChunkyCharArray fStringCharArray = null;
+ private boolean fCalledCharPropInit = false;
//
//
//
@@ -251,7 +252,6 @@
boolean skiplf = false;
while (offset < endOffset) {
int ch = getChar(offset);
- /***/
// fix for Bug23: Element Data not normalized...
if (skiplf) {
skiplf = false;
@@ -263,22 +263,21 @@
if (ch == 0x0D) {
skiplf = true;
ch = 0x0A;
- }
- /***/
+ }
appendCharData(ch);
offset += fBytesPerChar;
}
if (fSendCharDataAsCharArray) {
if (isWhitespace)
- fEntityHandler.processWhitespace(fCharacters, 0, fCharDataLength);
+ fCharDataHandler.processWhitespace(fCharacters, 0, fCharDataLength);
else
- fEntityHandler.processCharacters(fCharacters, 0, fCharDataLength);
+ fCharDataHandler.processCharacters(fCharacters, 0, fCharDataLength);
} else {
int stringIndex = fStringPool.addString(new String(fCharacters, 0, fCharDataLength));
if (isWhitespace)
- fEntityHandler.processWhitespace(stringIndex);
+ fCharDataHandler.processWhitespace(stringIndex);
else
- fEntityHandler.processCharacters(stringIndex);
+ fCharDataHandler.processCharacters(stringIndex);
}
fCharDataLength = 0;
}
@@ -437,6 +436,10 @@
//
public void skipPastName(char fastcheck) throws Exception {
int ch = getChar(fCurrentOffset);
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
return;
while (true) {
@@ -454,6 +457,10 @@
//
public void skipPastNmtoken(char fastcheck) throws Exception {
int ch = getChar(fCurrentOffset);
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
while (true) {
if (fastcheck == ch)
return;
@@ -757,6 +764,10 @@
int ch = getChar(fCurrentOffset);
fCurrentOffset += fBytesPerChar;
byte prop;
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if (ch < 0x80) {
if (ch == -1) {
fCurrentOffset -= fBytesPerChar;
1.4 +54 -15 xml-xerces/java/src/org/apache/xerces/readers/UTF8Reader.java
Index: UTF8Reader.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/readers/UTF8Reader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UTF8Reader.java 2000/02/08 02:43:57 1.3
+++ UTF8Reader.java 2000/04/04 21:14:24 1.4
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -69,25 +69,25 @@
/**
* This is the primary reader used for UTF-8 encoded byte streams.
- *
+ * <p>
* This reader processes requests from the scanners against the
* underlying UTF-8 byte stream, avoiding when possible any up-front
* transcoding. When the StringPool handle interfaces are used,
* the information in the data stream will be added to the string
* pool and lazy-evaluated until asked for.
- *
+ * <p>
* We use the SymbolCache to match expected names (element types in
* end tags) and walk the data structures of that class directly.
- *
+ * <p>
* There is a significant amount of hand-inlining and some blatant
* voilation of good object oriented programming rules, ignoring
* boundaries of modularity, etc., in the name of good performance.
- *
+ * <p>
* There are also some places where the code here frequently crashes
* the SUN java runtime compiler (JIT) and the code here has been
* carefully "crafted" to avoid those problems.
*
- * @version
+ * @version $Id: UTF8Reader.java,v 1.4 2000/04/04 21:14:24 andyc Exp $
*/
final class UTF8Reader extends XMLEntityReader {
//
@@ -624,6 +624,10 @@
UTF8DataChunk saveChunk = fCurrentChunk;
int saveOffset = fCurrentOffset;
int saveIndex = fCurrentIndex;
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
int b1 = loadNextByte();
if ((0xe0 & b0) == 0xc0) { // 110yyyyy 10xxxxxx
if ((XMLCharacterProperties.fgCharFlags[((0x1f & b0)<<6) + (0x3f & b1)] & flag) == 0) { // yyy yyxx xxxx (0x80 to 0x7ff)
@@ -671,6 +675,10 @@
if (XMLCharacterProperties.fgAsciiInitialNameChar[b0] == 0)
return;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if (!skippedMultiByteCharWithFlag(b0, XMLCharacterProperties.E_InitialNameCharFlag))
return;
}
@@ -683,6 +691,10 @@
if (XMLCharacterProperties.fgAsciiNameChar[b0] == 0)
return;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if (!skippedMultiByteCharWithFlag(b0, XMLCharacterProperties.E_NameCharFlag))
return;
}
@@ -720,8 +732,10 @@
if (data[--index] != s[sindex])
return false;
}
+ fCurrentIndex += length;
} catch (ArrayIndexOutOfBoundsException ex) {
int i = 0;
+ index = fCurrentIndex;
while (index < UTF8DataChunk.CHUNK_SIZE) {
if (data[index++] != s[i++])
return false;
@@ -742,10 +756,10 @@
return false;
}
}
+ fCurrentIndex = index;
}
fCharacterCounter += length;
fCurrentOffset += length;
- fCurrentIndex += length;
try {
fMostRecentByte = data[fCurrentIndex] & 0xFF;
} catch (ArrayIndexOutOfBoundsException ex) {
@@ -1263,6 +1277,10 @@
if (XMLCharacterProperties.fgAsciiNameChar[ch] == 0)
return true;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_NameCharFlag) == 0)
return true;
}
@@ -1277,6 +1295,10 @@
if (ch == ':')
return -1;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
return -1;
}
@@ -1326,6 +1348,10 @@
if (XMLCharacterProperties.fgAsciiInitialNameChar[ch] == 0 || ch == ':')
lpok = false;
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_InitialNameCharFlag) == 0)
lpok = false;
}
@@ -1336,6 +1362,10 @@
}
}
} else {
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
if ((XMLCharacterProperties.fgCharFlags[ch] & XMLCharacterProperties.E_NameCharFlag) == 0)
break;
}
@@ -1356,6 +1386,10 @@
UTF8DataChunk saveChunk = fCurrentChunk;
int saveIndex = fCurrentIndex;
int saveOffset = fCurrentOffset;
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
int b1;
if (USE_OUT_OF_LINE_LOAD_NEXT_BYTE) {
b1 = loadNextByte();
@@ -1455,6 +1489,10 @@
UTF8DataChunk saveChunk = fCurrentChunk;
int saveIndex = fCurrentIndex;
int saveOffset = fCurrentOffset;
+ if (!fCalledCharPropInit) {
+ XMLCharacterProperties.initCharFlags();
+ fCalledCharPropInit = true;
+ }
int b1;
if (USE_OUT_OF_LINE_LOAD_NEXT_BYTE) {
b1 = loadNextByte();
@@ -2176,10 +2214,10 @@
case 1: // '<'
if (!fInCDSect) {
if (fSendCharDataAsCharArray) {
- fEntityHandler.processWhitespace(fCharacters, 0, fCharDataLength);
+ fCharDataHandler.processWhitespace(fCharacters, 0, fCharDataLength);
} else {
int stringIndex = addString(charDataOffset, fCurrentOffset - charDataOffset);
- fEntityHandler.processWhitespace(stringIndex);
+ fCharDataHandler.processWhitespace(stringIndex);
}
fCharacterCounter++;
if (USE_OUT_OF_LINE_LOAD_NEXT_BYTE) {
@@ -2305,10 +2343,10 @@
case 1: // '<'
if (!fInCDSect) {
if (fSendCharDataAsCharArray) {
- fEntityHandler.processCharacters(fCharacters, 0, fCharDataLength);
+ fCharDataHandler.processCharacters(fCharacters, 0, fCharDataLength);
} else {
int stringIndex = addString(charDataOffset, fCurrentOffset - charDataOffset);
- fEntityHandler.processCharacters(stringIndex);
+ fCharDataHandler.processCharacters(stringIndex);
}
fCharacterCounter++;
if (USE_OUT_OF_LINE_LOAD_NEXT_BYTE) {
@@ -2629,10 +2667,10 @@
//
if (!fSendCharDataAsCharArray) {
int stringIndex = addString(offset, endOffset - offset);
- fEntityHandler.processCharacters(stringIndex);
+ fCharDataHandler.processCharacters(stringIndex);
return;
}
- fEntityHandler.processCharacters(fCharacters, 0, fCharDataLength);
+ fCharDataHandler.processCharacters(fCharacters, 0, fCharDataLength);
}
private void whitespace(int offset, int endOffset) throws Exception {
//
@@ -2640,10 +2678,10 @@
//
if (!fSendCharDataAsCharArray) {
int stringIndex = addString(offset, endOffset - offset);
- fEntityHandler.processWhitespace(stringIndex);
+ fCharDataHandler.processWhitespace(stringIndex);
return;
}
- fEntityHandler.processWhitespace(fCharacters, 0, fCharDataLength);
+ fCharDataHandler.processWhitespace(fCharacters, 0, fCharDataLength);
}
//
//
@@ -2657,6 +2695,7 @@
private byte[] fMostRecentData = null;
private int fMostRecentByte = 0;
private int fLength = 0;
+ private boolean fCalledCharPropInit = false;
private boolean fCallClearPreviousChunk = true;
//
//
1.2 +5 -5 xml-xerces/java/src/org/apache/xerces/readers/XCatalog.java
Index: XCatalog.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/readers/XCatalog.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XCatalog.java 1999/11/09 01:12:40 1.1
+++ XCatalog.java 2000/04/04 21:14:25 1.2
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -131,7 +131,7 @@
* </ul>
*
* @author Andy Clark, IBM
- * @version
+ * @version $Id: XCatalog.java,v 1.2 2000/04/04 21:14:25 andyc Exp $
*/
public class XCatalog
extends XMLCatalogHandler
@@ -469,7 +469,7 @@
}
// expand system id
- systemId = expandSystemId(systemId);
+ systemId = fEntityHandler.expandSystemId(systemId);
// cut off the least significant part
int index = systemId.lastIndexOf('/');
@@ -547,7 +547,7 @@
if (!isURL(href)) {
href = base + href;
}
- String systemId = expandSystemId(href);
+ String systemId = fEntityHandler.expandSystemId(href);
// create delegate
XCatalog catalog = new XCatalog();
@@ -567,7 +567,7 @@
if (!isURL(href)) {
href = base + href;
}
- String systemId = expandSystemId(href);
+ String systemId = fEntityHandler.expandSystemId(href);
// create catalog
XCatalog.this.loadCatalog(new InputSource(systemId));
1.2 +135 -90 xml-xerces/java/src/org/apache/xerces/readers/XMLEntityHandler.java
Index: XMLEntityHandler.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/readers/XMLEntityHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLEntityHandler.java 1999/11/09 01:12:45 1.1
+++ XMLEntityHandler.java 2000/04/04 21:14:25 1.2
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,7 +59,9 @@
import org.apache.xerces.framework.XMLErrorReporter;
import org.apache.xerces.utils.StringPool;
+import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
import java.io.InputStream;
/**
@@ -67,9 +69,9 @@
* is typically implemented by the "parser" class to provide entity
* management services for the scanner classes.
*
- * @version
+ * @version $Id: XMLEntityHandler.java,v 1.2 2000/04/04 21:14:25 andyc Exp $
*/
-public interface XMLEntityHandler {
+public interface XMLEntityHandler extends Locator {
/**
* Special return values for scanCharRef method. The normal return
@@ -151,24 +153,24 @@
* This is an enumeration of all the defined contexts in which
* an entity reference may appear. The order is important, as
* all explicit general entity references must appear first and
- * the last of these must be CONTEXT_IN_CONTENT. This permits
- * the test "(context <= CONTEXT_IN_CONTENT)" to be used as a
+ * the last of these must be ENTITYREF_IN_CONTENT. This permits
+ * the test "(context <= ENTITYREF_IN_CONTENT)" to be used as a
* quick check for a general entity reference.
*
* @see #startReadingFromEntity
*/
public static final int
- CONTEXT_IN_ATTVALUE = 0,
- CONTEXT_IN_DEFAULTATTVALUE = 1,
- CONTEXT_IN_CONTENT = 2,
- CONTEXT_IN_DTD_AS_MARKUP = 3,
- CONTEXT_IN_ENTITYVALUE = 4,
- CONTEXT_IN_DTD_WITHIN_MARKUP = 5,
- CONTEXT_DOCUMENT = 6,
- CONTEXT_EXTERNAL_SUBSET = 7;
+ ENTITYREF_IN_ATTVALUE = 0,
+ ENTITYREF_IN_DEFAULTATTVALUE = 1,
+ ENTITYREF_IN_CONTENT = 2,
+ ENTITYREF_IN_DTD_AS_MARKUP = 3,
+ ENTITYREF_IN_ENTITYVALUE = 4,
+ ENTITYREF_IN_DTD_WITHIN_MARKUP = 5,
+ ENTITYREF_DOCUMENT = 6,
+ ENTITYREF_EXTERNAL_SUBSET = 7;
/**
- * Start reading from source.
+ * Start reading document from an InputSource.
*
* @param source The input source for the document to process.
* @return <code>true</code> if we were able to open the document source;
@@ -186,100 +188,93 @@
*
* @param entityName The entity name handle in the string pool.
* @param readerDepth The depth to associate with the reader for this entity.
- * @param context The context of the entity reference; see CONTEXT_IN_*.
+ * @param context The context of the entity reference; see ENTITYREF_IN_*.
* @return <code>true</code> if the entity might start with a TextDecl;
* <code>false</code> otherwise.
* @exception java.lang.Exception
*/
- public boolean startReadingFromEntity(int entityName, int readerDepth, int context) throws Exception;
+ public boolean startReadingFromEntity(int entityName, int readerDepth, int entityContext) throws Exception;
/**
- * Start reading from the external subset of the DTD.
+ * Expand the system identifier relative to the entity that we are processing.
*
- * @param publicId The public identifier for the external subset.
- * @param systemId The system identifier for the external subset.
- * @param readerDepth The depth to associate with the reader for the external subset.
- * @exception java.lang.Exception
- */
- public void startReadingFromExternalSubset(String publicId, String systemId, int readerDepth) throws Exception;
-
- /**
- * Finished reading from the external subset of the DTD.
- * @exception java.lang.Exception
+ * @return The expanded system identifier.
*/
- public void stopReadingFromExternalSubset() throws Exception;
+ public String expandSystemId(String systemId);
/**
- * Start the scope of an entity declaration.
- *
- * @return <code>true</code> on success; otherwise
- * <code>false</code> if the entity declaration is recursive.
- * @exception java.lang.Exception
+ * DTD specific entity handler
*/
- public boolean startEntityDecl(boolean isPE, int entityName) throws Exception;
+ public interface DTDHandler {
+ /**
+ * Start reading from the external subset of the DTD.
+ *
+ * @param publicId The public identifier for the external subset.
+ * @param systemId The system identifier for the external subset.
+ * @param readerDepth The depth to associate with the reader for the external subset.
+ * @exception java.lang.Exception
+ */
+ public void startReadingFromExternalSubset(String publicId, String systemId, int readerDepth) throws Exception;
- /**
- * End the scope of an entity declaration.
- * @exception java.lang.Exception
- */
- public void endEntityDecl() throws Exception;
+ /**
+ * Finished reading from the external subset of the DTD.
+ * @exception java.lang.Exception
+ */
+ public void stopReadingFromExternalSubset() throws Exception;
- /**
- * Return the public identifier of the entity that we are processing.
- *
- * @return The public identifier, or null if not provided.
- */
- public String getPublicId();
+ /**
+ * Start the scope of an entity declaration.
+ *
+ * @return <code>true</code> on success; otherwise
+ * <code>false</code> if the entity declaration is recursive.
+ * @exception java.lang.Exception
+ */
+ public boolean startEntityDecl(boolean isPE, int entityName) throws Exception;
- /**
- * Return the system identifier of the entity that we are processing.
- *
- * @return The system identifier, or null if not provided.
- */
- public String getSystemId();
+ /**
+ * End the scope of an entity declaration.
+ * @exception java.lang.Exception
+ */
+ public void endEntityDecl() throws Exception;
- /**
- * Expand the system identifier relative to the entity that we are processing.
- *
- * @return The expanded system identifier.
- */
- public String expandSystemId(String systemId);
+ /**
+ * Declare entities and notations.
+ */
+ public int addInternalPEDecl(int entityName, int value, boolean isExternal) throws Exception;
+ public int addExternalPEDecl(int entityName, int publicId, int systemId, boolean isExternal) throws Exception;
+ public int addInternalEntityDecl(int entityName, int value, boolean isExternal) throws Exception;
+ public int addExternalEntityDecl(int entityName, int publicId, int systemId, boolean isExternal) throws Exception;
+ public int addUnparsedEntityDecl(int entityName, int publicId, int systemId, int notationName, boolean isExternal) throws Exception;
+ public int addNotationDecl(int notationName, int publicId, int systemId, boolean isExternal) throws Exception;
- /**
- * Process character data, character array version
- *
- * @param chars character buffer to be processed
- * @param offset offset in buffer where the data starts
- * @param length length of characters to be processed
- * @exception java.lang.Exception
- */
- public void processCharacters(char[] chars, int offset, int length) throws Exception;
+ /**
+ * Check for unparsed entity.
+ *
+ * @param entityName The string handle for the entity name.
+ * @return <code>true</code> if entityName is an unparsed entity; otherwise
+ * <code>false</code> if entityName is not declared or not an unparsed entity.
+ */
+ public boolean isUnparsedEntity(int entityName);
- /**
- * Process character data, <code>StringPool</code> handle version
- *
- * @param stringHandle <code>StringPool</code> handle to the character data
- * @exception java.lang.Exception
- */
- public void processCharacters(int stringHandle) throws Exception;
+ /**
+ * Check for declared notation.
+ *
+ * @param notationName The string handle for the notation name.
+ * @return <code>true</code> if notationName is a declared notation; otherwise
+ * <code>false</code> if notationName is not declared.
+ */
+ public boolean isNotationDeclared(int entityName);
- /**
- * Process white space data, character array version
- *
- * @param chars character buffer to be processed
- * @param offset offset in buffer where the data starts
- * @param length length of whitespace to be processed
- * @exception java.lang.Exception
- */
- public void processWhitespace(char[] chars, int offset, int length) throws Exception;
+ /**
+ * Remember a required but undeclared notation.
+ */
+ public void addRequiredNotation(int notationName, Locator locator, int majorCode, int minorCode, Object[] args);
- /**
- * Process white space data, <code>StringPool</code> handle version
- *
- * @param stringHandle <code>StringPool</code> handle to the whitespace
- * @exception java.lang.Exception
- */
- public void processWhitespace(int stringHandle) throws Exception;
+ /**
+ * Check required but undeclared notations.
+ */
+ public void checkRequiredNotations() throws Exception;
+ }
/**
* Return a unique identifier for the current reader.
@@ -355,6 +350,57 @@
}
/**
+ * Set the character data handler.
+ */
+ public void setCharDataHandler(XMLEntityHandler.CharDataHandler charDataHandler);
+
+ /**
+ * Get the character data handler.
+ */
+ public XMLEntityHandler.CharDataHandler getCharDataHandler();
+
+ /**
+ * Interface for passing character data.
+ */
+ public interface CharDataHandler {
+ /**
+ * Process character data, character array version
+ *
+ * @param chars character buffer to be processed
+ * @param offset offset in buffer where the data starts
+ * @param length length of characters to be processed
+ * @exception java.lang.Exception
+ */
+ public void processCharacters(char[] chars, int offset, int length) throws Exception;
+
+ /**
+ * Process character data, <code>StringPool</code> handle version
+ *
+ * @param stringHandle <code>StringPool</code> handle to the character data
+ * @exception java.lang.Exception
+ */
+ public void processCharacters(int stringHandle) throws Exception;
+
+ /**
+ * Process white space data, character array version
+ *
+ * @param chars character buffer to be processed
+ * @param offset offset in buffer where the data starts
+ * @param length length of whitespace to be processed
+ * @exception java.lang.Exception
+ */
+ public void processWhitespace(char[] chars, int offset, int length) throws Exception;
+
+ /**
+ * Process white space data, <code>StringPool</code> handle version
+ *
+ * @param stringHandle <code>StringPool</code> handle to the whitespace
+ * @exception java.lang.Exception
+ */
+ public void processWhitespace(int stringHandle) throws Exception;
+ }
+
+ /**
* This is the interface for scanners to process input data
* from entities without needing to know the details of the
* underlying storage of those entities, or their encodings.
@@ -365,7 +411,6 @@
* processing of XML documents.
*/
public interface EntityReader {
-
/**
* Return the current offset within this reader.
*
1.2 +6 -2 xml-xerces/java/src/org/apache/xerces/readers/XMLEntityReader.java
Index: XMLEntityReader.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/readers/XMLEntityReader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLEntityReader.java 1999/11/09 01:12:47 1.1
+++ XMLEntityReader.java 2000/04/04 21:14:25 1.2
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -62,8 +62,8 @@
/**
* This is the class used by the scanner to process the XML data.
*
- * @version
* @see org.apache.xerces.framework.XMLParser
+ * @version $Id: XMLEntityReader.java,v 1.2 2000/04/04 21:14:25 andyc Exp $
*/
abstract class XMLEntityReader implements XMLEntityHandler.EntityReader {
/*
@@ -72,6 +72,7 @@
protected XMLEntityHandler fEntityHandler = null;
protected XMLErrorReporter fErrorReporter = null;
protected boolean fSendCharDataAsCharArray;
+ protected XMLEntityHandler.CharDataHandler fCharDataHandler = null;
protected boolean fInCDSect = false;
private boolean fStillActive = true;
/*
@@ -88,6 +89,7 @@
fEntityHandler = entityHandler;
fErrorReporter = errorReporter;
fSendCharDataAsCharArray = sendCharDataAsCharArray;
+ fCharDataHandler = fEntityHandler.getCharDataHandler();
}
/**
* Constructor
@@ -96,6 +98,7 @@
fEntityHandler = entityHandler;
fErrorReporter = errorReporter;
fSendCharDataAsCharArray = sendCharDataAsCharArray;
+ fCharDataHandler = fEntityHandler.getCharDataHandler();
fLinefeedCounter = lineNumber;
fCharacterCounter = columnNumber;
}
@@ -103,6 +106,7 @@
fEntityHandler = entityHandler;
fErrorReporter = errorReporter;
fSendCharDataAsCharArray = sendCharDataAsCharArray;
+ fCharDataHandler = fEntityHandler.getCharDataHandler();
fLinefeedCounter = lineNumber;
fCharacterCounter = columnNumber;
fStillActive = true;