You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2002/09/16 23:25:30 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl XMLEntityManager.java XMLDocumentFragmentScannerImpl.java XMLDTDScannerImpl.java
neilg 2002/09/16 14:25:30
Modified: java/src/org/apache/xerces/impl XMLEntityManager.java
XMLDocumentFragmentScannerImpl.java
XMLDTDScannerImpl.java
Log:
fixing bug 11989. Now entities in the entity manager
know whether they were declared in the internal or external subset.
Revision Changes Path
1.45 +57 -16 xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java
Index: XMLEntityManager.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- XMLEntityManager.java 13 Sep 2002 00:10:07 -0000 1.44
+++ XMLEntityManager.java 16 Sep 2002 21:25:30 -0000 1.45
@@ -297,6 +297,10 @@
*/
protected boolean fStandalone;
+ // are the entities being parsed in the external subset?
+ // NOTE: this *is not* the same as whether they're external entities!
+ protected boolean fInExternalSubset = false;
+
// handlers
/** Entity handler. */
@@ -400,7 +404,7 @@
*/
public void addInternalEntity(String name, String text) {
if (!fEntities.containsKey(name)) {
- Entity entity = new InternalEntity(name, text);
+ Entity entity = new InternalEntity(name, text, fInExternalSubset);
fEntities.put(name, entity);
}
else{
@@ -456,7 +460,7 @@
}
}
Entity entity = new ExternalEntity(name,
- new XMLResourceIdentifierImpl(publicId, literalSystemId, baseSystemId, expandSystemId(literalSystemId, baseSystemId)), null);
+ new XMLResourceIdentifierImpl(publicId, literalSystemId, baseSystemId, expandSystemId(literalSystemId, baseSystemId)), null, fInExternalSubset);
fEntities.put(name, entity);
}
else{
@@ -487,6 +491,23 @@
}
/**
+ * Checks whether the declaration of an entity given by name is
+ // in the external subset.
+ *
+ * @param entityName The name of the entity to check.
+ * @returns True if the entity was declared in the external subset, false otherwise
+ * (including when the entity is not declared).
+ */
+ public boolean isEntityDeclInExternalSubset(String entityName) {
+
+ Entity entity = (Entity)fEntities.get(entityName);
+ if (entity == null) {
+ return false;
+ }
+ return entity.isEntityDeclInExternalSubset();
+ }
+
+ /**
* Adds an unparsed entity declaration.
* <p>
* <strong>Note:</strong> This method ignores subsequent entity
@@ -506,7 +527,7 @@
String publicId, String systemId,
String baseSystemId, String notation) {
if (!fEntities.containsKey(name)) {
- Entity entity = new ExternalEntity(name, new XMLResourceIdentifierImpl(publicId, systemId, baseSystemId, null), notation);
+ Entity entity = new ExternalEntity(name, new XMLResourceIdentifierImpl(publicId, systemId, baseSystemId, null), notation, fInExternalSubset);
fEntities.put(name, entity);
}
else{
@@ -768,6 +789,16 @@
startEntity(DTDEntity, xmlInputSource, false, true);
} // startDTDEntity(XMLInputSource)
+ // indicate start of external subset so that
+ // location of entity decls can be tracked
+ public void startExternalSubset() {
+ fInExternalSubset = true;
+ }
+
+ public void endExternalSubset() {
+ fInExternalSubset = false;
+ }
+
/**
* Starts an entity.
* <p>
@@ -1677,6 +1708,10 @@
/** Entity name. */
public String name;
+ // whether this entity's declaration was found in the internal
+ // or external subset
+ public boolean inExternalSubset;
+
//
// Constructors
//
@@ -1687,14 +1722,20 @@
} // <init>()
/** Constructs an entity. */
- public Entity(String name) {
+ public Entity(String name, boolean inExternalSubset) {
this.name = name;
+ this.inExternalSubset = inExternalSubset;
} // <init>(String)
//
// Public methods
//
+ /** Returns true if this entity was declared in the external subset. */
+ public boolean isEntityDeclInExternalSubset () {
+ return inExternalSubset;
+ }
+
/** Returns true if this is an external entity. */
public abstract boolean isExternal();
@@ -1704,11 +1745,13 @@
/** Clears the entity. */
public void clear() {
name = null;
+ inExternalSubset = false;
} // clear()
/** Sets the values of the entity. */
public void setValues(Entity entity) {
name = entity.name;
+ inExternalSubset = entity.inExternalSubset;
} // setValues(Entity)
} // class Entity
@@ -1738,8 +1781,8 @@
} // <init>()
/** Constructs an internal entity. */
- public InternalEntity(String name, String text) {
- super(name);
+ public InternalEntity(String name, String text, boolean inExternalSubset) {
+ super(name,inExternalSubset);
this.text = text;
} // <init>(String,String)
@@ -1806,8 +1849,8 @@
/** Constructs an internal entity. */
public ExternalEntity(String name, XMLResourceIdentifier entityLocation,
- String notation) {
- super(name);
+ String notation, boolean inExternalSubset) {
+ super(name,inExternalSubset);
this.entityLocation = entityLocation;
this.notation = notation;
} // <init>(String,XMLResourceIdentifier, String)
@@ -1916,7 +1959,7 @@
XMLResourceIdentifier entityLocation,
InputStream stream, Reader reader,
String encoding, boolean literal, boolean mayReadChunks, boolean isExternal) {
- super(name);
+ super(name,fInExternalSubset);
this.entityLocation = entityLocation;
this.stream = stream;
this.reader = reader;
@@ -2772,12 +2815,10 @@
*/
public boolean scanData(String delimiter, XMLStringBuffer buffer)
throws IOException {
+
boolean done = false;
int delimLen = delimiter.length();
char charAt0 = delimiter.charAt(0);
- int offset = 0;
- int c = -1;
- int newlines = 0;
boolean external = fCurrentEntity.isExternal();
do {
if (DEBUG_BUFFER) {
@@ -2808,9 +2849,9 @@
}
// normalize newlines
- offset = fCurrentEntity.position;
- c = fCurrentEntity.ch[offset];
- newlines = 0;
+ int offset = fCurrentEntity.position;
+ int c = fCurrentEntity.ch[offset];
+ int newlines = 0;
if (c == '\n' || (c == '\r' && external)) {
if (DEBUG_BUFFER) {
System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": ");
1.21 +7 -1 xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java
Index: XMLDocumentFragmentScannerImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- XMLDocumentFragmentScannerImpl.java 12 Sep 2002 21:56:56 -0000 1.20
+++ XMLDocumentFragmentScannerImpl.java 16 Sep 2002 21:25:30 -0000 1.21
@@ -525,6 +525,12 @@
super.startEntity(name, identifier, encoding);
+ // WFC: entity declared in external subset in standalone doc
+ if(fStandalone && fEntityManager.isEntityDeclInExternalSubset(name)) {
+ reportFatalError("MSG_REFERENCE_TO_EXTERNALLY_DECLARED_ENTITY_WHEN_STANDALONE",
+ new Object[]{name});
+ }
+
// call handler
if (fDocumentHandler != null && !fScanningAttribute) {
if (!name.equals("[xml]")) {
1.28 +3 -1 xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java
Index: XMLDTDScannerImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- XMLDTDScannerImpl.java 26 Aug 2002 18:17:35 -0000 1.27
+++ XMLDTDScannerImpl.java 16 Sep 2002 21:25:30 -0000 1.28
@@ -472,6 +472,7 @@
fDTDHandler.startDTD(fEntityScanner, null);
}
fDTDHandler.startExternalSubset(fEntityScanner,null);
+ fEntityManager.startExternalSubset();
fExtEntityDepth++;
}
else if (name.charAt(0) == '%') {
@@ -543,6 +544,7 @@
}
fScannerState = SCANNER_STATE_END_OF_INPUT;
// call handler
+ fEntityManager.endExternalSubset();
if (fDTDHandler != null) {
fDTDHandler.endExternalSubset(null);
fDTDHandler.endDTD(null);
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org