[prev in list] [next in list] [prev in thread] [next in thread]
List: xerces-cvs
Subject: cvs commit: xml-xerces/java/src/org/apache/xerces/parsers AbstractDOMParser.java
From: andyc () apache ! org
Date: 2001-12-22 23:25:49
[Download RAW message or body]
andyc 01/12/22 15:25:49
Modified: java/docs releases.xml
java/samples/dom Writer.java
java/src/org/apache/xerces/parsers AbstractDOMParser.java
Log:
Added internal subset string to DOM.
Revision Changes Path
1.95 +12 -2 xml-xerces/java/docs/releases.xml
Index: releases.xml
===================================================================
RCS file: /home/cvs/xml-xerces/java/docs/releases.xml,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- releases.xml 2001/12/18 16:57:12 1.94
+++ releases.xml 2001/12/22 23:25:48 1.95
@@ -1,8 +1,18 @@
<?xml version='1.0' encoding='UTF-8'?>
-<!-- $Id: releases.xml,v 1.94 2001/12/18 16:57:12 neilg Exp $ -->
+<!-- $Id: releases.xml,v 1.95 2001/12/22 23:25:48 andyc Exp $ -->
<!DOCTYPE releases SYSTEM 'dtd/releases.dtd'>
<releases>
- <release version='Xerces 2.0.0 Beta 4 (Dec. 17, 2001)'>
+ <release version='NOT YET RELEASED'>
+ <desc>
+ </desc>
+ <changes>
+ <add>
+ <note>Added internal subset string to DOM.</note>
+ <submitter name='Andy Clark'/>
+ </add>
+ </changes>
+ </release>
+ <release version='Xerces 2.0.0 (beta4)'>
<desc>
This release fixes a number of bugs, introduces more changes to the Xerces
Native Interface, provides partial experimental DOM Level 3 implementation,
1.5 +32 -3 xml-xerces/java/samples/dom/Writer.java
Index: Writer.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/samples/dom/Writer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Writer.java 2001/12/13 23:11:16 1.4
+++ Writer.java 2001/12/22 23:25:49 1.5
@@ -64,6 +64,7 @@
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -77,7 +78,7 @@
*
* @author Andy Clark, IBM
*
- * @version $Id: Writer.java,v 1.4 2001/12/13 23:11:16 elena Exp $
+ * @version $Id: Writer.java,v 1.5 2001/12/22 23:25:49 andyc Exp $
*/
public class Writer {
@@ -187,13 +188,41 @@
short type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE: {
+ Document document = (Document)node;
if (!fCanonical) {
fOut.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
fOut.flush();
+ write(document.getDoctype());
}
-
- Document document = (Document)node;
write(document.getDocumentElement());
+ break;
+ }
+
+ case Node.DOCUMENT_TYPE_NODE: {
+ DocumentType doctype = (DocumentType)node;
+ fOut.print("<!DOCTYPE ");
+ fOut.print(doctype.getName());
+ String publicId = doctype.getPublicId();
+ String systemId = doctype.getSystemId();
+ if (publicId != null) {
+ fOut.print(" PUBLIC '");
+ fOut.print(publicId);
+ fOut.print("' '");
+ fOut.print(systemId);
+ fOut.print('\'');
+ }
+ else {
+ fOut.print(" SYSTEM '");
+ fOut.print(systemId);
+ fOut.print('\'');
+ }
+ String internalSubset = doctype.getInternalSubset();
+ if (internalSubset != null) {
+ fOut.println(" [");
+ fOut.print(internalSubset);
+ fOut.print(']');
+ }
+ fOut.println('>');
break;
}
1.24 +229 -1 xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java
Index: AbstractDOMParser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- AbstractDOMParser.java 2001/12/21 17:29:47 1.23
+++ AbstractDOMParser.java 2001/12/22 23:25:49 1.24
@@ -102,7 +102,7 @@
* @author Andy Clark, IBM
* @author Elena Litani, IBM
*
- * @version $Id: AbstractDOMParser.java,v 1.23 2001/12/21 17:29:47 elena Exp $
+ * @version $Id: AbstractDOMParser.java,v 1.24 2001/12/22 23:25:49 andyc Exp $
*/
public abstract class AbstractDOMParser
extends AbstractXMLDocumentParser {
@@ -189,7 +189,11 @@
protected Node fCurrentNode;
protected CDATASection fCurrentCDATASection;
+ // internal subset
+ /** Internal subset buffer. */
+ protected StringBuffer fInternalSubset;
+
// deferred expansion data
protected boolean fDeferNodeExpansion;
@@ -202,6 +206,9 @@
// state
+ /** True if inside DTD external subset. */
+ protected boolean fInDTDExternalSubset;
+
/** True if inside document. */
protected boolean fInDocument;
@@ -352,6 +359,7 @@
// reset state information
fInDocument = false;
fInDTD = false;
+ fInDTDExternalSubset = false;
fInCDATASection = false;
fCurrentCDATASection = null;
fCurrentCDATASectionIndex = -1;
@@ -1002,6 +1010,82 @@
//
/**
+ * The start of the DTD.
+ *
+ * @throws XNIException Thrown by handler to signal an error.
+ */
+ public void startDTD(XMLLocator locator) throws XNIException {
+ super.startDTD(locator);
+ if (fDeferNodeExpansion || fDocumentImpl != null) {
+ fInternalSubset = new StringBuffer(1024);
+ }
+ } // startDTD(XMLLocator)
+
+ /**
+ * The end of the DTD.
+ *
+ * @throws XNIException Thrown by handler to signal an error.
+ */
+ public void endDTD() throws XNIException {
+ super.endDTD();
+ String internalSubset = fInternalSubset != null && fInternalSubset.length() > 0
+ ? fInternalSubset.toString() : null;
+ if (fDeferNodeExpansion) {
+ if (internalSubset != null) {
+ fDeferredDocumentImpl.setInternalSubset(fDocumentTypeIndex, internalSubset);
+ }
+ }
+ else if (fDocumentImpl != null) {
+ if (internalSubset != null) {
+ ((DocumentTypeImpl)fDocumentType).setInternalSubset(internalSubset);
+ }
+ }
+ } // endDTD()
+
+ /**
+ * This method notifies of the start of an entity. The DTD has the
+ * pseudo-name of "[dtd]" and parameter entity names start with '%'.
+ * <p>
+ *
+ * @param name The name of the entity.
+ * @param publicId The public identifier of the entity if the entity
+ * is external, null otherwise.
+ * @param systemId The system identifier of the entity if the entity
+ * is external, null otherwise.
+ * @param baseSystemId The base system identifier of the entity if
+ * the entity is external, null otherwise.
+ * @param encoding The auto-detected IANA encoding name of the entity
+ * stream. This value will be null in those situations
+ * where the entity encoding is not auto-detected (e.g.
+ * internal parameter entities).
+ *
+ * @throws XNIException Thrown by handler to signal an error.
+ */
+ public void startEntity(String name,
+ String publicId, String systemId,
+ String baseSystemId,
+ String encoding) throws XNIException {
+ if (name.equals("[dtd]")) {
+ fInDTDExternalSubset = true;
+ }
+ } // startEntity(String,String,String,String,String)
+
+ /**
+ * This method notifies the end of an entity. The DTD has the pseudo-name
+ * of "[dtd]" and parameter entity names start with '%'.
+ * <p>
+ *
+ * @param name The name of the entity.
+ *
+ * @throws XNIException Thrown by handler to signal an error.
+ */
+ public void endEntity(String name) throws XNIException {
+ if (name.equals("[dtd]")) {
+ fInDTDExternalSubset = false;
+ }
+ } // endEntity(String)
+
+ /**
* An internal entity declaration.
*
* @param name The name of the entity. Parameter entity names start with
@@ -1019,6 +1103,25 @@
XMLString nonNormalizedText)
throws XNIException {
+ // internal subset string
+ if (fInternalSubset != null && !fInDTDExternalSubset) {
+ fInternalSubset.append("<!ENTITY ");
+ if (name.startsWith("%")) {
+ fInternalSubset.append("% ");
+ fInternalSubset.append(name.substring(1));
+ }
+ else {
+ fInternalSubset.append(name);
+ }
+ fInternalSubset.append(' ');
+ String value = nonNormalizedText.toString();
+ boolean singleQuote = value.indexOf('\'') == -1;
+ fInternalSubset.append(singleQuote ? '\'' : '"');
+ fInternalSubset.append(value);
+ fInternalSubset.append(singleQuote ? '\'' : '"');
+ fInternalSubset.append(">\n");
+ }
+
// NOTE: We only know how to create these nodes for the Xerces
// DOM implementation because DOM Level 2 does not specify
// that functionality. -Ac
@@ -1078,6 +1181,29 @@
String publicId, String systemId,
String baseSystemId) throws XNIException {
+ // internal subset string
+ if (fInternalSubset != null && !fInDTDExternalSubset) {
+ fInternalSubset.append("<!ENTITY ");
+ if (name.startsWith("%")) {
+ fInternalSubset.append("% ");
+ fInternalSubset.append(name.substring(1));
+ }
+ else {
+ fInternalSubset.append(name);
+ }
+ fInternalSubset.append(' ');
+ if (publicId != null) {
+ fInternalSubset.append("PUBLIC '");
+ fInternalSubset.append(publicId);
+ fInternalSubset.append("' '");
+ }
+ else {
+ fInternalSubset.append("SYSTEM '");
+ }
+ fInternalSubset.append(systemId);
+ fInternalSubset.append("'>\n");
+ }
+
// NOTE: We only know how to create these nodes for the Xerces
// DOM implementation because DOM Level 2 does not specify
// that functionality. -Ac
@@ -1137,6 +1263,28 @@
String publicId, String systemId,
String notation) throws XNIException {
+ // internal subset string
+ if (fInternalSubset != null && !fInDTDExternalSubset) {
+ fInternalSubset.append("<!ENTITY ");
+ fInternalSubset.append(name);
+ fInternalSubset.append(' ');
+ if (publicId != null) {
+ fInternalSubset.append("PUBLIC '");
+ fInternalSubset.append(publicId);
+ if (systemId != null) {
+ fInternalSubset.append("' '");
+ fInternalSubset.append(systemId);
+ }
+ }
+ else {
+ fInternalSubset.append("SYSTEM '");
+ fInternalSubset.append(systemId);
+ }
+ fInternalSubset.append("' NDATA ");
+ fInternalSubset.append(notation);
+ fInternalSubset.append(">\n");
+ }
+
// NOTE: We only know how to create these nodes for the Xerces
// DOM implementation because DOM Level 2 does not specify
// that functionality. -Ac
@@ -1192,6 +1340,24 @@
public void notationDecl(String name, String publicId, String systemId)
throws XNIException {
+ // internal subset string
+ if (fInternalSubset != null && !fInDTDExternalSubset) {
+ fInternalSubset.append("<!NOTATION ");
+ if (publicId != null) {
+ fInternalSubset.append("PUBLIC '");
+ fInternalSubset.append(publicId);
+ if (systemId != null) {
+ fInternalSubset.append("' '");
+ fInternalSubset.append(systemId);
+ }
+ }
+ else {
+ fInternalSubset.append("SYSTEM '");
+ fInternalSubset.append(systemId);
+ }
+ fInternalSubset.append("'>\n");
+ }
+
// NOTE: We only know how to create these nodes for the Xerces
// DOM implementation because DOM Level 2 does not specify
// that functionality. -Ac
@@ -1232,6 +1398,28 @@
} // notationDecl(String,String,String)
/**
+ * An element declaration.
+ *
+ * @param name The name of the element.
+ * @param contentModel The element content model.
+ *
+ * @throws XNIException Thrown by handler to signal an error.
+ */
+ public void elementDecl(String name, String contentModel)
+ throws XNIException {
+
+ // internal subset string
+ if (fInternalSubset != null && !fInDTDExternalSubset) {
+ fInternalSubset.append("<!ELEMENT ");
+ fInternalSubset.append(name);
+ fInternalSubset.append(' ');
+ fInternalSubset.append(contentModel);
+ fInternalSubset.append(">\n");
+ }
+
+ } // elementDecl(String,String)
+
+ /**
* An attribute declaration.
*
* @param elementName The name of the element that this attribute
@@ -1256,6 +1444,46 @@
String type, String[] enumeration,
String defaultType, XMLString defaultValue)
throws XNIException {
+
+ // internal subset string
+ if (fInternalSubset != null && !fInDTDExternalSubset) {
+ fInternalSubset.append("<!ATTLIST ");
+ fInternalSubset.append(elementName);
+ fInternalSubset.append(' ');
+ fInternalSubset.append(attributeName);
+ fInternalSubset.append(' ');
+ if (type.equals("ENUMERATION")) {
+ fInternalSubset.append('(');
+ for (int i = 0; i < enumeration.length; i++) {
+ if (i > 0) {
+ fInternalSubset.append('|');
+ }
+ fInternalSubset.append(enumeration[i]);
+ }
+ fInternalSubset.append(')');
+ }
+ else {
+ fInternalSubset.append(type);
+ }
+ if (defaultType != null) {
+ fInternalSubset.append(' ');
+ fInternalSubset.append(defaultType);
+ }
+ if (defaultValue != null) {
+ fInternalSubset.append(" '");
+ for (int i = 0; i < defaultValue.length; i++) {
+ char c = defaultValue.ch[defaultValue.offset + i];
+ if (c == '\'') {
+ fInternalSubset.append("'");
+ }
+ else {
+ fInternalSubset.append(c);
+ }
+ }
+ fInternalSubset.append('\'');
+ }
+ fInternalSubset.append(">\n");
+ }
// deferred expansion
if (fDeferredDocumentImpl != null) {
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic