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/10/03 01:19:19 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/xni XMLEntityHandler.java
andyc 00/10/02 16:19:18
Modified: java/src/org/apache/xerces/impl Tag: xerces_j_2 Version.java
XMLDTDScanner.java XMLDocumentScanner.java
XMLEntityScanner.java XMLEntityManager.java
XMLValidator.java
java/src/org/apache/xerces/parsers Tag: xerces_j_2
XMLDocumentParser.java
java/src/org/apache/xerces/xni Tag: xerces_j_2
XMLEntityHandler.java
Log:
Added the auto-detected encoding to the parameter list for
XMLEntityHandler#startEntity. This allows us to communicate
original encoding of the external entity. Also updated all
implementors of that interface to comply.
Revision Changes Path
No revision
No revision
1.1.2.3 +2 -2 xml-xerces/java/src/org/apache/xerces/impl/Attic/Version.java
Index: Version.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/Version.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- Version.java 2000/10/02 00:40:02 1.1.2.2
+++ Version.java 2000/10/02 23:19:09 1.1.2.3
@@ -60,7 +60,7 @@
/**
* This class defines the version number of the parser.
*
- * @version
+ * @version $Id: Version.java,v 1.1.2.3 2000/10/02 23:19:09 andyc Exp $
*/
public class Version {
@@ -69,7 +69,7 @@
//
/** Version string. */
- public static String fVersion = "Xerces 2.0.0 (pre-alpha)";
+ public static String fVersion = "Xerces 2.0.0 (m2)";
//
// MAIN
1.1.2.4 +35 -4 xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDTDScanner.java
Index: XMLDTDScanner.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDTDScanner.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- XMLDTDScanner.java 2000/10/02 01:29:50 1.1.2.3
+++ XMLDTDScanner.java 2000/10/02 23:19:09 1.1.2.4
@@ -58,26 +58,32 @@
package org.apache.xerces.impl;
import java.io.IOException;
+
import org.apache.xerces.impl.XMLEntityManager;
+import org.apache.xerces.impl.XMLErrorReporter;
import org.apache.xerces.impl.validation.GrammarPool;
+
+import org.apache.xerces.util.SymbolTable;
+
import org.apache.xerces.xni.XMLComponent;
import org.apache.xerces.xni.XMLComponentManager;
import org.apache.xerces.xni.XMLDTDContentModelHandler;
import org.apache.xerces.xni.XMLDTDContentModelSource;
import org.apache.xerces.xni.XMLDTDHandler;
import org.apache.xerces.xni.XMLDTDSource;
-import org.apache.xerces.util.SymbolTable;
-import org.apache.xerces.impl.XMLErrorReporter;
+import org.apache.xerces.xni.XMLEntityHandler;
+
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
/**
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
- * @version $Id: XMLDTDScanner.java,v 1.1.2.3 2000/10/02 01:29:50 lehors Exp $
+ * @version $Id: XMLDTDScanner.java,v 1.1.2.4 2000/10/02 23:19:09 andyc Exp $
*/
public class XMLDTDScanner
- implements XMLComponent, XMLDTDSource, XMLDTDContentModelSource {
+ implements XMLComponent, XMLDTDSource, XMLDTDContentModelSource,
+ XMLEntityHandler {
//
// Data
@@ -207,5 +213,30 @@
*/
public void setDTDContentModelHandler(XMLDTDContentModelHandler dtdContentModelHandler) {
} // setDTDContentModelHandler
+
+ //
+ // XMLEntityHandler methods
+ //
+
+ /**
+ * startEntity
+ *
+ * @param name
+ * @param publicId
+ * @param systemId
+ * @param encoding
+ */
+ public void startEntity(String name, String publicId, String systemId,
+ String encoding) throws SAXException {
+ } // startEntity(String,String,String,String)
+
+ /**
+ * endEntity
+ *
+ * @param name
+ */
+ public void endEntity(String name)
+ throws SAXException {
+ } // endEntity(String)
} // class XMLDTDScanner
1.1.2.4 +6 -6 xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDocumentScanner.java
Index: XMLDocumentScanner.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDocumentScanner.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- XMLDocumentScanner.java 2000/10/02 01:29:51 1.1.2.3
+++ XMLDocumentScanner.java 2000/10/02 23:19:10 1.1.2.4
@@ -99,7 +99,7 @@
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
* @author Andy Clark, IBM
*
- * @version $Id: XMLDocumentScanner.java,v 1.1.2.3 2000/10/02 01:29:51 lehors Exp $
+ * @version $Id: XMLDocumentScanner.java,v 1.1.2.4 2000/10/02 23:19:10 andyc Exp $
*/
public class XMLDocumentScanner
implements XMLComponent, XMLDocumentSource, XMLEntityHandler {
@@ -363,8 +363,8 @@
/***/
// initialize scanner
+ fEntityManager.setEntityHandler(this);
fEntityScanner = fEntityManager.getEntityScanner();
- fEntityScanner.setEntityHandler(this);
// initialize vars
fEntityStack.removeAllElements();
@@ -454,8 +454,8 @@
* @param publicId
* @param systemId
*/
- public void startEntity(String name, String publicId, String systemId)
- throws SAXException {
+ public void startEntity(String name, String publicId, String systemId,
+ String encoding) throws SAXException {
// keep track of this entity
Entity entity = new Entity(name, publicId, systemId, fElementDepth);
@@ -463,10 +463,10 @@
// call handler
if (!fScanningAttribute && fDocumentHandler != null) {
- fDocumentHandler.startEntity(name, publicId, systemId);
+ fDocumentHandler.startEntity(name, publicId, systemId, encoding);
}
- } // startEntity(String,String,String)
+ } // startEntity(String,String,String,String)
/**
* endEntity
1.1.2.3 +27 -450 xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLEntityScanner.java
Index: XMLEntityScanner.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLEntityScanner.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- XMLEntityScanner.java 2000/10/02 00:40:03 1.1.2.2
+++ XMLEntityScanner.java 2000/10/02 23:19:10 1.1.2.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,471 +57,48 @@
package org.apache.xerces.impl;
-import java.io.EOFException;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.IOException;
-import java.io.PushbackReader;
-import java.io.Reader;
import org.apache.xerces.xni.QName;
-import org.apache.xerces.xni.XMLEntityHandler;
import org.apache.xerces.xni.XMLString;
-import org.apache.xerces.util.SymbolTable;
-import org.apache.xerces.util.XMLChar;
-import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/**
+ * This class allows various parser scanners to scan basic XML constructs
+ * from entities. This class works directly with the entity manager to
+ * provide this functionality.
+ * <p>
+ * There is only one entity scanner and entity manager per parser. The
+ * entity manager <em>could</em> implement the methods to perform entity
+ * scanning, but the entity scanner class allows a cleaner separation
+ * between entity management API and entity scanning.
+ *
* @author Stubs generated by DesignDoc on Mon Sep 18 18:23:16 PDT 2000
- * @version $Id: XMLEntityScanner.java,v 1.1.2.2 2000/10/02 00:40:03 lehors Exp $
+ * @author Andy Clark, IBM
+ *
+ * @version $Id: XMLEntityScanner.java,v 1.1.2.3 2000/10/02 23:19:10 andyc Exp $
+ *
+ * @see XMLEntityManager
*/
-public class XMLEntityScanner
+public abstract class XMLEntityScanner
implements Locator {
//
- // Constants
- //
-
- // debugging
-
- /** Debugging. */
- private static final boolean DEBUG = false;
-
- //
- // Data
- //
-
- /** fEntityHandler */
- protected XMLEntityHandler fEntityHandler;
-
- /** fInputSource */
- protected InputSource fInputSource;
-
- /** fLineNumber */
- protected int fLineNumber;
-
- /** fColumnNumber */
- protected int fColumnNumber;
-
- /** fBytePosition */
- protected long fBytePosition;
-
- /** fCharPosition */
- protected long fCharPosition;
-
- /** Symbol table. */
- protected SymbolTable fSymbolTable;
-
- // private
-
- /** Reader. */
- private PushbackReader fReader;
-
- /** Character buffer. */
- private char[] fBuffer = new char[1024];
-
- /** Buffer length. */
- private int fLength;
-
- //
- // Constructors
- //
-
- /**
- *
- */
- public XMLEntityScanner() {
- }
-
- //
// Public methods
//
-
- /**
- * setEntityHandler
- *
- * @param entityHandler
- */
- public void setEntityHandler(XMLEntityHandler entityHandler) {
- fEntityHandler = entityHandler;
- } // setEntityHandler(XMLEntityHandler)
-
- /**
- * getBytePosition
- *
- * @return
- */
- public long getBytePosition() {
- return -1;
- } // getBytePosition
-
- /**
- * getCharPosition
- *
- * @return
- */
- public long getCharPosition() {
- return -1;
- } // getCharPosition
-
- /**
- * peekChar
- *
- * @return
- */
- public int peekChar() throws IOException {
- if (DEBUG) System.out.println("#peekChar()");
- return peek();
- } // peekChar
-
- /**
- * scanChar
- *
- * @return
- */
- public int scanChar() throws IOException, SAXException {
- if (DEBUG) System.out.println("#scanChar()");
- int c = read();
- if (c == -1) {
- endEntity();
- }
- return c;
- } // scanChar
-
- /**
- * scanNmtoken
- *
- * @return
- */
- public String scanNmtoken() throws IOException, SAXException {
- if (DEBUG) System.out.println("#scanNmtoken()");
-
- fLength = 0;
- boolean nmtoken = false;
- while (XMLChar.isName(peek())) {
- nmtoken = true;
- fBuffer[fLength++] = (char)read();
- }
-
- String symbol = null;
- if (nmtoken) {
- symbol = fSymbolTable.addSymbol(fBuffer, 0, fLength);
- }
- return symbol;
-
- } // scanNmtoken
-
- /**
- * scanName
- *
- * @return
- */
- public String scanName() throws IOException, SAXException {
- if (DEBUG) System.out.println("#scanName()");
-
- fLength = 0;
- boolean name = false;
- if (XMLChar.isNameStart(peek())) {
- name = true;
- fBuffer[fLength++] = (char)read();
- while (XMLChar.isName(peek())) {
- fBuffer[fLength++] = (char)read();
- }
- }
-
- String symbol = null;
- if (name) {
- symbol = fSymbolTable.addSymbol(fBuffer, 0, fLength);
- }
- return symbol;
-
- } // scanName
-
- /**
- * scanQName
- *
- * @param qname
- */
- public boolean scanQName(QName qname) throws IOException, SAXException {
- if (DEBUG) System.out.println("#scanQName()");
-
- String prefix = null;
- String localpart = null;
- String rawname = null;
-
- fLength = 0;
- int colons = -1;
- int index = 0;
- if (XMLChar.isNameStart(peek())) {
- colons = 0;
- fBuffer[fLength++] = (char)read();
- int c = -1;
- while (XMLChar.isName(c = peek())) {
- if (c == ':') {
- colons++;
- if (colons == 1) {
- index = fLength + 1;
- prefix = fSymbolTable.addSymbol(fBuffer, 0, fLength);
- }
- }
- fBuffer[fLength++] = (char)read();
- }
- localpart = fSymbolTable.addSymbol(fBuffer, index, fLength - index);
- rawname = fSymbolTable.addSymbol(fBuffer, 0, fLength);
- }
-
- if (colons >= 0 && colons < 2) {
- qname.setValues(prefix, localpart, rawname, null);
- return true;
- }
-
- return false;
-
- } // scanQName
-
- /**
- * scanContent
- *
- * @param content
- */
- public int scanContent(XMLString content)
- throws IOException, SAXException {
-
- fLength = 0;
- while (peek() != '<' && peek() != '&') {
- fBuffer[fLength++] = (char)read();
- if (fLength == fBuffer.length) {
- break;
- }
- }
- content.setValues(fBuffer, 0, fLength);
-
- return peek();
-
- } // scanContent
-
- /**
- * scanAttContent
- *
- * @param quote
- * @param content
- */
- public int scanAttContent(int quote, XMLString content)
- throws IOException, SAXException {
-
- fLength = 0;
- while (peek() != quote) {
- fBuffer[fLength++] = (char)read();
- if (fLength == fBuffer.length) {
- break;
- }
- }
- content.setValues(fBuffer, 0, fLength);
-
- return peek();
-
- } // scanAttContent
-
- /**
- * scanData
- *
- * @param delimiter
- * @param data
- */
- public boolean scanData(String delimiter, XMLString data)
- throws IOException, SAXException {
- // TODO
- throw new RuntimeException("not implemented");
- } // scanData(String,XMLString)
-
- /**
- * skipChar
- *
- * @param c
- */
- public boolean skipChar(int c) throws IOException, SAXException {
- int pc = read();
- if (pc != c) {
- unread(pc);
- }
- return pc == c;
- }
-
- /**
- * skipSpaces
- */
- public boolean skipSpaces() throws IOException, SAXException {
- if (DEBUG) System.out.println("#skipSpaces()");
-
- boolean spaces = false;
- while (XMLChar.isSpace(peek())) {
- spaces = true;
- read();
- }
-
- return spaces;
-
- } // skipSpaces
-
- /**
- * skipString
- *
- * @param s
- */
- public boolean skipString(String s) throws IOException, SAXException {
- if (DEBUG) System.out.println("#skipString(\""+s+"\")");
-
- int length = s.length();
- for (int i = 0; i < length; i++) {
- int c = read();
- if (c != s.charAt(i)) {
- unread(c);
- if (i > 0) {
- char[] ch = new char[i];
- s.getChars(0, i, ch, 0);
- unread(ch, 0, ch.length);
- }
- return false;
- }
- }
-
- return true;
-
- } // skipString
-
- //
- // Locator methods
- //
-
- /**
- * getPublicId
- *
- * @return
- */
- public String getPublicId() {
- return null;
- } // getPublicId
-
- /**
- * getSystemId
- *
- * @return
- */
- public String getSystemId() {
- return null;
- } // getSystemId
-
- /**
- * getLineNumber
- *
- * @return
- */
- public int getLineNumber() {
- return -1;
- } // getLineNumber
-
- /**
- * getColumnNumber
- *
- * @return
- */
- public int getColumnNumber() {
- return -1;
- } // getColumnNumber
-
- //
- // Package methods
- //
-
- void startEntity(InputSource inputSource)
- throws IOException, SAXException {
-
- fInputSource = inputSource;
-
- Reader reader = inputSource.getCharacterStream();
- if (reader != null) {
- fReader = new PushbackReader(reader, 32);
- startEntity();
- return;
- }
-
- InputStream stream = inputSource.getByteStream();
- if (stream != null) {
- reader = new InputStreamReader(stream);
- fReader = new PushbackReader(reader, 32);
- startEntity();
- return;
- }
-
- String systemId = inputSource.getSystemId();
- if (systemId != null) {
- stream = new FileInputStream(systemId);
- reader = new InputStreamReader(stream);
- fReader = new PushbackReader(reader, 32);
- startEntity();
- return;
- }
-
- throw new FileNotFoundException(systemId);
-
- } // startEntity(InputSource)
-
- /** Starts an entity. */
- void startEntity() throws SAXException {
- if (fEntityHandler != null) {
- fEntityHandler.startEntity("name", "publicId", "systemId");
- }
- }
-
- /** Ends an entity. */
- void endEntity() throws SAXException {
- if (fEntityHandler != null) {
- fEntityHandler.endEntity("entityName");
- }
- }
-
- void setSymbolTable(SymbolTable symbolTable) {
- fSymbolTable = symbolTable;
- }
-
- //
- // Private methods
- //
-
- /** Peeks the next character. */
- private final int peek() throws IOException {
- int c = fReader.read();
- if (c == -1) {
- throw new EOFException();
- }
- if (DEBUG) System.out.println("?"+(char)c);
- fReader.unread(c);
- return c;
- }
-
- /** Reads the next character. */
- private int read() throws IOException {
- int c = fReader.read();
- if (c == -1) {
- throw new EOFException();
- }
- if (DEBUG) System.out.println("+"+(char)c);
- return c;
- }
-
- private void unread(int c) throws IOException {
- if (DEBUG) System.out.println("-"+(char)c);
- fReader.unread(c);
- }
- private void unread(char[] ch, int offset, int length) throws IOException {
- if (DEBUG) System.out.println("-"+new String(ch, offset, length));
- fReader.unread(ch, offset, length);
- }
+ public abstract int peekChar() throws IOException, SAXException;
+ public abstract int scanChar() throws IOException, SAXException;
+ public abstract String scanNmtoken() throws IOException, SAXException;
+ public abstract String scanName() throws IOException, SAXException;
+ public abstract boolean scanQName(QName qname) throws IOException, SAXException;
+ public abstract int scanContent(XMLString content) throws IOException, SAXException;
+ public abstract int scanAttContent(int quote, XMLString content) throws IOException, SAXException;
+ public abstract boolean scanData(String delimiter, XMLString data) throws IOException, SAXException;
+ public abstract boolean skipChar(int c) throws IOException, SAXException;
+ public abstract boolean skipSpaces() throws IOException, SAXException;
+ public abstract boolean skipString(String s) throws IOException, SAXException;
} // class XMLEntityScanner
1.1.2.3 +640 -25 xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLEntityManager.java
Index: XMLEntityManager.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLEntityManager.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- XMLEntityManager.java 2000/10/02 00:40:03 1.1.2.2
+++ XMLEntityManager.java 2000/10/02 23:19:11 1.1.2.3
@@ -57,12 +57,25 @@
package org.apache.xerces.impl;
+import java.io.EOFException;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.IOException;
+import java.io.PushbackReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Hashtable;
+import java.util.Stack;
import org.apache.xerces.util.SymbolTable;
+import org.apache.xerces.util.XMLChar;
+
+import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLComponent;
import org.apache.xerces.xni.XMLComponentManager;
import org.apache.xerces.xni.XMLEntityHandler;
+import org.apache.xerces.xni.XMLString;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
@@ -88,7 +101,7 @@
* @author Stubs generated by DesignDoc on Mon Sep 18 18:23:16 PDT 2000
* @author Andy Clark, IBM
*
- * @version $Id: XMLEntityManager.java,v 1.1.2.2 2000/10/02 00:40:03 lehors Exp $
+ * @version $Id: XMLEntityManager.java,v 1.1.2.3 2000/10/02 23:19:11 andyc Exp $
*/
public class XMLEntityManager
implements XMLComponent {
@@ -113,25 +126,63 @@
/** Symbol table property id. */
protected static final String SYMBOL_TABLE_PROPERTY = "internal/symbol-table";
+ // debugging
+
+ /** Debugging. */
+ private static final boolean DEBUG = false;
+
//
// Data
//
- /** Entity scanner. */
- protected XMLEntityScanner fEntityScanner;
-
// properties
/** Entity resolver. */
protected EntityResolver fEntityResolver;
+ /** Symbol table. */
+ protected SymbolTable fSymbolTable;
+
+ // handlers
+
+ /** Entity handler. */
+ protected XMLEntityHandler fEntityHandler;
+
+ // scanner
+
+ /** Entity scanner. */
+ protected XMLEntityScanner fEntityScanner;
+
+ /** General entities. */
+ protected Hashtable fGeneralEntities = new Hashtable();
+
+ /** Parameter entities. */
+ protected Hashtable fParameterEntities = new Hashtable();
+
+ /** Entity stack. */
+ protected Stack fEntityStack = new Stack();
+
+ /** Current entity. */
+ protected Entity fEntity;
+
+ // private
+
+ /** Reader. */
+ private PushbackReader fReader;
+
+ /** Character buffer. */
+ private char[] fBuffer = new char[1024];
+
+ /** Buffer length. */
+ private int fLength;
+
//
// Constructors
//
/** Default constructor. */
public XMLEntityManager() {
- fEntityScanner = new XMLEntityScanner();
+ fEntityScanner = new EntityScanner();
}
//
@@ -139,6 +190,15 @@
//
/**
+ * setEntityHandler
+ *
+ * @param entityHandler The new entity handler.
+ */
+ public void setEntityHandler(XMLEntityHandler entityHandler) {
+ fEntityHandler = entityHandler;
+ }
+
+ /**
* addGeneralEntity
*
* @param name
@@ -147,7 +207,8 @@
* @param baseSystemId
*/
public void addGeneralEntity(String name, String publicId, String systemId, String baseSystemId) {
- throw new RuntimeException("XMLEntityManager#addGeneralEntity(String,String,String,String) not implemented");
+ Entity entity = new ExternalEntity(name, publicId, systemId, baseSystemId);
+ fGeneralEntities.put(name, entity);
} // addGeneralEntity(String,String,String,String)
/**
@@ -157,7 +218,8 @@
* @param text
*/
public void addGeneralEntity(String name, String text) {
- throw new RuntimeException("XMLEntityManager#addGeneralEntity(String,String) not implemented");
+ Entity entity = new InternalEntity(name, text);
+ fGeneralEntities.put(name, entity);
} // addGeneralEntity(String,String)
/**
@@ -169,7 +231,8 @@
* @param baseSystemId
*/
public void addParameterEntity(String name, String publicId, String systemId, String baseSystemId) {
- throw new RuntimeException("XMLEntityManager#addParameterEntity(String,String,String,String) not implemented");
+ Entity entity = new ExternalEntity(name, publicId, systemId, baseSystemId);
+ fParameterEntities.put(name, entity);
} // addParameterEntity(String,String,String,String)
/**
@@ -179,7 +242,8 @@
* @param text
*/
public void addParameterEntity(String name, String text) {
- throw new RuntimeException("XMLEntityManager#addParameterEntity(String,String) not implemented");
+ Entity entity = new InternalEntity(name, text);
+ fParameterEntities.put(name, entity);
} // addParameterEntity(String,String)
/**
@@ -202,9 +266,31 @@
* @param entityName
* @param parameter
*/
- public void startGeneralEntity(String entityName) {
- throw new RuntimeException("XMLEntityManager#startGeneralEntity(String) not implemented");
- } // startGeneralEntity
+ public void startGeneralEntity(String entityName)
+ throws IOException, SAXException {
+
+ // resolve external entity
+ Entity entity = (Entity)fGeneralEntities.get(entityName);
+ InputSource inputSource = null;
+ if (entity.isExternal()) {
+ ExternalEntity externalEntity = (ExternalEntity)entity;
+ String publicId = externalEntity.publicId;
+ String systemId = externalEntity.systemId;
+ String baseSystemId = externalEntity.baseSystemId;
+ inputSource = resolveEntity(publicId, systemId, baseSystemId);
+ }
+
+ // wrap internal entity
+ else {
+ InternalEntity internalEntity = (InternalEntity)entity;
+ Reader reader = new StringReader(internalEntity.text);
+ inputSource = new InputSource(reader);
+ }
+
+ // start the entity
+ startEntity(entityName, inputSource);
+
+ } // startGeneralEntity(String)
/**
* startParameterEntity
@@ -212,21 +298,53 @@
* @param entityName
* @param parameter
*/
- public void startParameterEntity(String entityName) {
- throw new RuntimeException("XMLEntityManager#startParameterEntity(String) not implemented");
- } // startParameterEntity
+ public void startParameterEntity(String entityName)
+ throws IOException, SAXException {
+
+ // resolve external entity
+ Entity entity = (Entity)fParameterEntities.get(entityName);
+ InputSource inputSource = null;
+ if (entity.isExternal()) {
+ ExternalEntity externalEntity = (ExternalEntity)entity;
+ String publicId = externalEntity.publicId;
+ String systemId = externalEntity.systemId;
+ String baseSystemId = externalEntity.baseSystemId;
+ inputSource = resolveEntity(publicId, systemId, baseSystemId);
+ }
+ // wrap internal entity
+ else {
+ InternalEntity internalEntity = (InternalEntity)entity;
+ Reader reader = new StringReader(internalEntity.text);
+ inputSource = new InputSource(reader);
+ }
+
+ // start the entity
+ startEntity("%"+entityName, inputSource);
+
+ } // startParameterEntity(String)
+
/**
- * startEntity
+ * startDocumentEntity
*
* @param inputSource
*/
- public void startEntity(InputSource inputSource)
+ public void startDocumentEntity(InputSource inputSource)
throws IOException, SAXException {
- fEntityScanner.startEntity(inputSource);
- } // startEntity
+ startEntity("[xml]", inputSource);
+ } // startDocumentEntity(InputSource)
/**
+ * startDTDEntity
+ *
+ * @param inputSource
+ */
+ public void startDTDEntity(InputSource inputSource)
+ throws IOException, SAXException {
+ startEntity("[dtd]", inputSource);
+ } // startDTDEntity(InputSource)
+
+ /**
* getEntityScanner
*
* @return
@@ -247,15 +365,20 @@
public void reset(XMLComponentManager componentManager)
throws SAXException {
- // save information
+ // Xerces properties
final String ENTITY_RESOLVER = XERCES_PROPERTY_PREFIX + ENTITY_RESOLVER_PROPERTY;
fEntityResolver = (EntityResolver)componentManager.getProperty(ENTITY_RESOLVER);
-
- // set symbol table on scanner
final String SYMBOL_TABLE = XERCES_PROPERTY_PREFIX + SYMBOL_TABLE_PROPERTY;
- SymbolTable symboTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);
- fEntityScanner.setSymbolTable(symboTable);
+ fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);
+
+ // initialize state
+ fGeneralEntities.clear();
+ fParameterEntities.clear();
+ fEntityStack.removeAllElements();
+ // initialize scanner info
+ fReader = null;
+
} // reset(XMLComponentManager)
/**
@@ -285,11 +408,503 @@
return;
}
if (property.equals(SYMBOL_TABLE_PROPERTY)) {
- fEntityScanner.setSymbolTable((SymbolTable)value);
+ fSymbolTable = (SymbolTable)value;
return;
}
}
} // setProperty(String,Object)
+
+ //
+ // Protected methods
+ //
+
+ /**
+ * Starts an entity.
+ */
+ protected void startEntity(String name, InputSource inputSource)
+ throws IOException, SAXException {
+
+ // get information
+ String publicId = inputSource.getPublicId();
+ String systemId = inputSource.getSystemId();
+ String encoding = inputSource.getEncoding();
+
+ // create reader
+ Reader reader = inputSource.getCharacterStream();
+ if (reader == null) {
+ InputStream stream = inputSource.getByteStream();
+ if (stream == null) {
+ // REVISIT: open system identifier
+ stream = new FileInputStream(systemId);
+ }
+ reader = new InputStreamReader(stream);
+ }
+ fReader = new PushbackReader(reader, 32);
+
+ // push entity on stack
+ Entity entity = new ExternalEntity(name, publicId, systemId, encoding);
+ fEntityStack.push(entity);
+
+ // call handler
+ if (fEntityHandler != null) {
+ fEntityHandler.startEntity(name, publicId, systemId, encoding);
+ }
+
+ } // startEntity(String,InputSource)
+
+ /**
+ * Ends an entity.
+ */
+ protected void endEntity() throws IOException, SAXException {
+
+ // pop stack
+ Entity entity = (Entity)fEntityStack.pop();
+
+ // call handler
+ if (fEntityHandler != null) {
+ fEntityHandler.endEntity(entity.name);
+ }
+
+ } // endEntity(String)
+
+ //
+ // Classes
+ //
+
+ /**
+ * Entity information.
+ *
+ * @author Andy Clark, IBM
+ */
+ protected static abstract class Entity {
+
+ //
+ // Data
+ //
+
+ /** Entity name. */
+ public String name;
+
+ //
+ // Constructors
+ //
+
+ /** Constructs an entity. */
+ public Entity(String name) {
+ this.name = name;
+ } // <init>(String)
+
+ //
+ // Public methods
+ //
+
+ /** Returns true if this is an external entity. */
+ public abstract boolean isExternal();
+
+ } // class Entity
+
+ /**
+ * Internal entity.
+ *
+ * @author Andy Clark, IBM
+ */
+ protected static class InternalEntity
+ extends Entity {
+
+ //
+ // Data
+ //
+
+ /** Text value of entity. */
+ public String text;
+
+ //
+ // Constructors
+ //
+
+ /** Constructs an internal entity. */
+ public InternalEntity(String name, String text) {
+ super(name);
+ this.text = text;
+ } // <init>(String,String)
+
+ //
+ // Entity methods
+ //
+
+ /** Returns true if this is an external entity. */
+ public final boolean isExternal() {
+ return false;
+ } // isExternal():boolean
+
+ } // class InternalEntity
+
+ /**
+ * External entity.
+ *
+ * @author Andy Clark, IBM
+ */
+ protected static class ExternalEntity
+ extends Entity {
+
+ //
+ // Data
+ //
+
+ /** Public identifier. */
+ public String publicId;
+
+ /** System identifier. */
+ public String systemId;
+
+ /** Base system identifier. */
+ public String baseSystemId;
+
+ //
+ // Constructors
+ //
+
+ /** Constructs an internal entity. */
+ public ExternalEntity(String name, String publicId, String systemId,
+ String baseSystemId) {
+ super(name);
+ this.publicId = publicId;
+ this.systemId = systemId;
+ this.baseSystemId = baseSystemId;
+ } // <init>(String,String,String,String)
+
+ //
+ // Entity methods
+ //
+
+ /** Returns true if this is an external entity. */
+ public final boolean isExternal() {
+ return true;
+ } // isExternal():boolean
+
+ } // class ExternalEntity
+
+ /**
+ * Implements the entity scanner methods.
+ *
+ * @author Andy Clark, IBM
+ */
+ private class EntityScanner
+ extends XMLEntityScanner {
+
+ //
+ // Constructors
+ //
+
+ /** Default constructor. */
+ public EntityScanner() {
+ }
+
+ //
+ // XMLEntityScanner methods
+ //
+
+ /**
+ * peekChar
+ *
+ * @return
+ */
+ public int peekChar() throws IOException {
+ if (DEBUG) System.out.println("#peekChar()");
+ return peek();
+ } // peekChar():int
+
+ /**
+ * scanChar
+ *
+ * @return
+ */
+ public int scanChar() throws IOException, SAXException {
+ if (DEBUG) System.out.println("#scanChar()");
+ int c = read();
+ if (c == -1) {
+ endEntity();
+ }
+ return c;
+ } // scanChar():int
+
+ /**
+ * scanNmtoken
+ *
+ * @return
+ */
+ public String scanNmtoken() throws IOException, SAXException {
+ if (DEBUG) System.out.println("#scanNmtoken()");
+
+ fLength = 0;
+ boolean nmtoken = false;
+ while (XMLChar.isName(peek())) {
+ nmtoken = true;
+ fBuffer[fLength++] = (char)read();
+ }
+
+ String symbol = null;
+ if (nmtoken) {
+ symbol = fSymbolTable.addSymbol(fBuffer, 0, fLength);
+ }
+ return symbol;
+
+ } // scanNmtoken
+
+ /**
+ * scanName
+ *
+ * @return
+ */
+ public String scanName() throws IOException, SAXException {
+ if (DEBUG) System.out.println("#scanName()");
+
+ fLength = 0;
+ boolean name = false;
+ if (XMLChar.isNameStart(peek())) {
+ name = true;
+ fBuffer[fLength++] = (char)read();
+ while (XMLChar.isName(peek())) {
+ fBuffer[fLength++] = (char)read();
+ }
+ }
+
+ String symbol = null;
+ if (name) {
+ symbol = fSymbolTable.addSymbol(fBuffer, 0, fLength);
+ }
+ return symbol;
+
+ } // scanName
+
+ /**
+ * scanQName
+ *
+ * @param qname
+ */
+ public boolean scanQName(QName qname) throws IOException, SAXException {
+ if (DEBUG) System.out.println("#scanQName()");
+
+ String prefix = null;
+ String localpart = null;
+ String rawname = null;
+
+ fLength = 0;
+ int colons = -1;
+ int index = 0;
+ if (XMLChar.isNameStart(peek())) {
+ colons = 0;
+ fBuffer[fLength++] = (char)read();
+ int c = -1;
+ while (XMLChar.isName(c = peek())) {
+ if (c == ':') {
+ colons++;
+ if (colons == 1) {
+ index = fLength + 1;
+ prefix = fSymbolTable.addSymbol(fBuffer, 0, fLength);
+ }
+ }
+ fBuffer[fLength++] = (char)read();
+ }
+ localpart = fSymbolTable.addSymbol(fBuffer, index, fLength - index);
+ rawname = fSymbolTable.addSymbol(fBuffer, 0, fLength);
+ }
+
+ if (colons >= 0 && colons < 2) {
+ qname.setValues(prefix, localpart, rawname, null);
+ return true;
+ }
+
+ return false;
+
+ } // scanQName
+
+ /**
+ * scanContent
+ *
+ * @param content
+ */
+ public int scanContent(XMLString content)
+ throws IOException, SAXException {
+
+ fLength = 0;
+ while (peek() != '<' && peek() != '&') {
+ fBuffer[fLength++] = (char)read();
+ if (fLength == fBuffer.length) {
+ break;
+ }
+ }
+ content.setValues(fBuffer, 0, fLength);
+
+ return peek();
+
+ } // scanContent
+
+ /**
+ * scanAttContent
+ *
+ * @param quote
+ * @param content
+ */
+ public int scanAttContent(int quote, XMLString content)
+ throws IOException, SAXException {
+
+ fLength = 0;
+ while (peek() != quote) {
+ fBuffer[fLength++] = (char)read();
+ if (fLength == fBuffer.length) {
+ break;
+ }
+ }
+ content.setValues(fBuffer, 0, fLength);
+
+ return peek();
+
+ } // scanAttContent
+
+ /**
+ * scanData
+ *
+ * @param delimiter
+ * @param data
+ */
+ public boolean scanData(String delimiter, XMLString data)
+ throws IOException, SAXException {
+ // TODO
+ throw new RuntimeException("not implemented");
+ } // scanData(String,XMLString)
+
+ /**
+ * skipChar
+ *
+ * @param c
+ */
+ public boolean skipChar(int c) throws IOException, SAXException {
+ int pc = read();
+ if (pc != c) {
+ unread(pc);
+ }
+ return pc == c;
+ }
+
+ /**
+ * skipSpaces
+ */
+ public boolean skipSpaces() throws IOException, SAXException {
+ if (DEBUG) System.out.println("#skipSpaces()");
+
+ boolean spaces = false;
+ while (XMLChar.isSpace(peek())) {
+ spaces = true;
+ read();
+ }
+
+ return spaces;
+
+ } // skipSpaces
+
+ /**
+ * skipString
+ *
+ * @param s
+ */
+ public boolean skipString(String s) throws IOException, SAXException {
+ if (DEBUG) System.out.println("#skipString(\""+s+"\")");
+
+ int length = s.length();
+ for (int i = 0; i < length; i++) {
+ int c = read();
+ if (c != s.charAt(i)) {
+ unread(c);
+ if (i > 0) {
+ char[] ch = new char[i];
+ s.getChars(0, i, ch, 0);
+ unread(ch, 0, ch.length);
+ }
+ return false;
+ }
+ }
+
+ return true;
+
+ } // skipString
+
+ //
+ // Locator methods
+ //
+
+ /**
+ * getPublicId
+ *
+ * @return
+ */
+ public String getPublicId() {
+ throw new RuntimeException("getPublicId not implemented");
+ } // getPublicId():String
+
+ /**
+ * getSystemId
+ *
+ * @return
+ */
+ public String getSystemId() {
+ throw new RuntimeException("getSystemId not implemented");
+ } // getSystemId():String
+
+ /**
+ * getLineNumber
+ *
+ * @return
+ */
+ public int getLineNumber() {
+ throw new RuntimeException("getLineNumber not implemented");
+ } // getLineNumber():int
+
+ /**
+ * getColumnNumber
+ *
+ * @return
+ */
+ public int getColumnNumber() {
+ throw new RuntimeException("getColumnNumber not implemented");
+ } // getColumnNumber():int
+
+ //
+ // Private methods
+ //
+
+ /** Peeks the next character. */
+ private final int peek() throws IOException {
+ int c = fReader.read();
+ if (c == -1) {
+ throw new EOFException();
+ }
+ if (DEBUG) System.out.println("?"+(char)c);
+ fReader.unread(c);
+ return c;
+ }
+
+ /** Reads the next character. */
+ private int read() throws IOException {
+ int c = fReader.read();
+ if (c == -1) {
+ throw new EOFException();
+ }
+ if (DEBUG) System.out.println("+"+(char)c);
+ return c;
+ }
+
+ private void unread(int c) throws IOException {
+ if (DEBUG) System.out.println("-"+(char)c);
+ fReader.unread(c);
+ }
+
+ private void unread(char[] ch, int offset, int length) throws IOException {
+ if (DEBUG) System.out.println("-"+new String(ch, offset, length));
+ fReader.unread(ch, offset, length);
+ }
+
+ } // class EntityScanner
} // class XMLEntityManager
1.1.2.4 +9 -7 xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLValidator.java
Index: XMLValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLValidator.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- XMLValidator.java 2000/10/02 01:29:52 1.1.2.3
+++ XMLValidator.java 2000/10/02 23:19:11 1.1.2.4
@@ -58,25 +58,26 @@
package org.apache.xerces.impl;
import org.apache.xerces.impl.validation.GrammarPool;
+import org.apache.xerces.impl.XMLErrorReporter;
+import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLComponent;
import org.apache.xerces.xni.XMLComponentManager;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XMLDocumentFilter;
import org.apache.xerces.xni.XMLDocumentHandler;
-import org.apache.xerces.xni.XMLDocumentSource;
-import org.apache.xerces.util.SymbolTable;
-import org.apache.xerces.impl.XMLErrorReporter;
+
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
/**
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
- * @version $Id: XMLValidator.java,v 1.1.2.3 2000/10/02 01:29:52 lehors Exp $
+ * @version $Id: XMLValidator.java,v 1.1.2.4 2000/10/02 23:19:11 andyc Exp $
*/
public class XMLValidator
- implements XMLComponent, XMLDocumentSource, XMLDocumentHandler {
+ implements XMLComponent, XMLDocumentFilter {
//
// Data
@@ -168,9 +169,10 @@
* @param name
* @param publicId
* @param systemId
+ * @param encoding
*/
- public void startEntity(String name, String publicId, String systemId)
- throws SAXException {
+ public void startEntity(String name, String publicId, String systemId,
+ String encoding) throws SAXException {
}
/**
No revision
No revision
1.1.2.11 +7 -6 xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLDocumentParser.java
Index: XMLDocumentParser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLDocumentParser.java,v
retrieving revision 1.1.2.10
retrieving revision 1.1.2.11
diff -u -r1.1.2.10 -r1.1.2.11
--- XMLDocumentParser.java 2000/10/02 00:40:13 1.1.2.10
+++ XMLDocumentParser.java 2000/10/02 23:19:14 1.1.2.11
@@ -77,7 +77,7 @@
/**
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
* @author Arnaud Le Hors, IBM
- * @version $Id: XMLDocumentParser.java,v 1.1.2.10 2000/10/02 00:40:13 lehors Exp $
+ * @version $Id: XMLDocumentParser.java,v 1.1.2.11 2000/10/02 23:19:14 andyc Exp $
*/
public abstract class XMLDocumentParser
extends XMLParser
@@ -174,10 +174,11 @@
* @param name
* @param publicId
* @param systemId
+ * @param encoding
*/
- public void startEntity(String name, String publicId, String systemId)
- throws SAXException {
- } // startEntity
+ public void startEntity(String name, String publicId, String systemId,
+ String encoding) throws SAXException {
+ } // startEntity(String,String,String,String)
/**
* endEntity
@@ -185,7 +186,7 @@
* @param name
*/
public void endEntity(String name) throws SAXException {
- } // endEntity
+ } // endEntity(String)
//
// XMLDocumentHandler methods
@@ -389,7 +390,7 @@
try {
reset();
- fEntityManager.startEntity(source);
+ fEntityManager.startDocumentEntity(source);
fScanner.scanDocument(true);
fParseInProgress = false;
} catch (SAXException ex) {
No revision
No revision
1.1.2.3 +4 -3 xml-xerces/java/src/org/apache/xerces/xni/Attic/XMLEntityHandler.java
Index: XMLEntityHandler.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xni/Attic/XMLEntityHandler.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- XMLEntityHandler.java 2000/10/02 00:40:17 1.1.2.2
+++ XMLEntityHandler.java 2000/10/02 23:19:17 1.1.2.3
@@ -60,7 +60,7 @@
/**
* @author Stubs generated by DesignDoc on Mon Sep 18 18:23:16 PDT 2000
- * @version $Id: XMLEntityHandler.java,v 1.1.2.2 2000/10/02 00:40:17 lehors Exp $
+ * @version $Id: XMLEntityHandler.java,v 1.1.2.3 2000/10/02 23:19:17 andyc Exp $
*/
public interface XMLEntityHandler {
@@ -74,9 +74,10 @@
* @param name
* @param publicId
* @param systemId
+ * @param encoding
*/
- public void startEntity(String name, String publicId, String systemId)
- throws SAXException;
+ public void startEntity(String name, String publicId, String systemId,
+ String encoding) throws SAXException;
/**
* endEntity