zongaro 2002/08/24 04:33:17
Modified: java/src/org/apache/xalan/xsltc/cmdline Tag: XSLTC_DTM
Transform.java
java/src/org/apache/xalan/xsltc/compiler Tag: XSLTC_DTM
UnparsedEntityUriCall.java
java/src/org/apache/xalan/xsltc/dom Tag: XSLTC_DTM
DocumentCache.java ExtendedSAX.java
java/src/org/apache/xalan/xsltc Tag: XSLTC_DTM DOMCache.java
java/src/org/apache/xalan/xsltc/runtime Tag: XSLTC_DTM
AbstractTranslet.java
java/src/org/apache/xalan/xsltc/trax Tag: XSLTC_DTM
TransformerHandlerImpl.java TransformerImpl.java
XSLTCSource.java
Log:
Eliminated use of DTDMonitor in building an XSLTC DOM object. Instead, the
nested DOMBuilderImpl classes of DOMImpl and SAXImpl now implement the
DTDHandler and DeclHandler SAX interfaces (and the ExtendedSAX interface now
extends them). With these changes, we now use DOMImpl to build an XSLTC DOM
from a DOMSource object, rather than using DOM2SAX to build the XSLTC DOM from
SAX events.
DTDMonitor was responsible for capturing information from SAX events relating
to unparsed entities and ID attribute values, and gave that information to the
translet, where it was ultimately stored. With this change, DOMImpl and
SAXImpl
are responsible for capturing this information; in the case of ID attribute
values, the information is again given back to the translet, which treats them
in the same manner as xsl:key elements. So the XSLTC DOM interface (and the
classes that implement it) now add a getUnparsedEntityURI method and a
getElementsWithID method.
Revision Changes Path
No revision
No revision
1.15.10.3 +6 -33
xml-xalan/java/src/org/apache/xalan/xsltc/cmdline/Transform.java
Index: Transform.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/cmdline/Transform.java,v
retrieving revision 1.15.10.2
retrieving revision 1.15.10.3
diff -u -r1.15.10.2 -r1.15.10.3
--- Transform.java 29 Jul 2002 00:01:21 -0000 1.15.10.2
+++ Transform.java 24 Aug 2002 11:33:16 -0000 1.15.10.3
@@ -168,44 +168,17 @@
final SAXParser parser = factory.newSAXParser();
final XMLReader reader = parser.getXMLReader();
- // Create a DTD monitor and pass it to the XMLReader object
- final DTDMonitor dtdMonitor = new DTDMonitor(reader);
-
// Set the DOM's DOM builder as the XMLReader's SAX2 content handler
- DTMManager dtmManager = XSLTCDTMManager.newInstance(
+ DTMManager dtmManager = XSLTCDTMManager.newInstance(
org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
- final SAXImpl dom = (SAXImpl)dtmManager.getDTM(new SAXSource(reader,
new InputSource(_fileName)), false, null, true, true);
- //final DOMImpl dom = new DOMImpl();
-/* DOMBuilder builder = dom.getBuilder();
- reader.setContentHandler(builder);
-
- try {
- String prop = "http://xml.org/sax/properties/lexical-handler";
- reader.setProperty(prop, builder);
- }
- catch (SAXException e) {
- // quitely ignored
- } */
-
-
-
- // Create a DTD monitor and pass it to the XMLReader object
- // final DTDMonitor dtdMonitor = new DTDMonitor(reader);
+ final SAXImpl dom = (SAXImpl)dtmManager.getDTM(
+ new SAXSource(reader, new
InputSource(_fileName)),
+ false, null, true, true);
AbstractTranslet _translet = (AbstractTranslet)translet;
dom.setDocumentURI(_fileName);
-/* if (_uri)
- reader.parse(_fileName);
- else
- reader.parse(new File(_fileName).toURL().toExternalForm());
-
- builder = null; */
-
- // If there are any elements with ID attributes, build an index
- dtdMonitor.buildIdIndex(dom, 0, _translet);
- // Pass unparsed entity descriptions to the translet
- _translet.setDTDMonitor(dtdMonitor);
+ _translet.prepassDocument(dom);
// Pass global parameters
int n = _params.size();
No revision
No revision
1.2.6.1 +20 -19
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnparsedEntityUriCall.java
Index: UnparsedEntityUriCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnparsedEntityUriCall.java,v
retrieving revision 1.2
retrieving revision 1.2.6.1
diff -u -r1.2 -r1.2.6.1
--- UnparsedEntityUriCall.java 1 Feb 2002 20:07:09 -0000 1.2
+++ UnparsedEntityUriCall.java 24 Aug 2002 11:33:16 -0000 1.2.6.1
@@ -74,29 +74,30 @@
private Expression _entity;
public UnparsedEntityUriCall(QName fname, Vector arguments) {
- super(fname, arguments);
- _entity = argument();
+ super(fname, arguments);
+ _entity = argument();
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
- final Type entity = _entity.typeCheck(stable);
- if (entity instanceof StringType == false) {
- _entity = new CastExpr(_entity, Type.String);
- }
- return _type = Type.String;
+ final Type entity = _entity.typeCheck(stable);
+ if (entity instanceof StringType == false) {
+ _entity = new CastExpr(_entity, Type.String);
+ }
+ return _type = Type.String;
}
public void translate(ClassGenerator classGen, MethodGenerator
methodGen) {
- final ConstantPoolGen cpg = classGen.getConstantPool();
- final InstructionList il = methodGen.getInstructionList();
- // Feck the this pointer on the stack...
- il.append(classGen.loadTranslet());
- // ...then the entity name...
- _entity.translate(classGen, methodGen);
- // ...to get the value from the hashtable in AbstractTranslet.
- il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
- "getUnparsedEntity",
- "(Ljava/lang/String;)"+
- "Ljava/lang/String;")));
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+ // Feck the this pointer on the stack...
+ il.append(methodGen.loadDOM());
+ // ...then the entity name...
+ _entity.translate(classGen, methodGen);
+ // ...to get the URI from the DOM object.
+ il.append(new INVOKEINTERFACE(
+ cpg.addInterfaceMethodref(DOM_INTF,
+ GET_UNPARSED_ENTITY_URI,
+
GET_UNPARSED_ENTITY_URI_SIG),
+ 2));
}
}
No revision
No revision
1.6.10.2 +9 -23
xml-xalan/java/src/org/apache/xalan/xsltc/dom/DocumentCache.java
Index: DocumentCache.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DocumentCache.java,v
retrieving revision 1.6.10.1
retrieving revision 1.6.10.2
diff -u -r1.6.10.1 -r1.6.10.2
--- DocumentCache.java 17 Apr 2002 18:13:44 -0000 1.6.10.1
+++ DocumentCache.java 24 Aug 2002 11:33:16 -0000 1.6.10.2
@@ -84,7 +84,6 @@
import org.apache.xalan.xsltc.DOMCache;
import org.apache.xalan.xsltc.Translet;
import org.apache.xalan.xsltc.dom.DOMImpl;
-import org.apache.xalan.xsltc.dom.DTDMonitor;
import org.apache.xalan.xsltc.runtime.AbstractTranslet;
import org.apache.xalan.xsltc.runtime.Constants;
@@ -119,7 +118,6 @@
// DOM and DTD handler references
private SAXImpl _dom = null;
- private DTDMonitor _dtdMonitor = null;
/**
* Constructor - load document and initialise statistics
@@ -140,18 +138,13 @@
*/
public void loadDocument(String uri) {
- DTMManager dtmManager = XSLTCDTMManager.newInstance(
+ DTMManager dtmManager = XSLTCDTMManager.newInstance(
org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
- //_dom = new DOMImpl();
- _dtdMonitor = new DTDMonitor();
-
try {
final long stamp = System.currentTimeMillis();
- _dtdMonitor.handleDTD(_reader);
- //_reader.setContentHandler(_dom.getBuilder());
- _dom = (SAXImpl)dtmManager.getDTM(new SAXSource(_reader, new
InputSource(uri)), false, null, true, true);
-
- //_reader.parse(uri);
+ _dom = (SAXImpl)dtmManager.getDTM(
+ new SAXSource(_reader, new
InputSource(uri)),
+ false, null, true, true);
_dom.setDocumentURI(uri);
// The build time can be used for statistics for a better
@@ -164,14 +157,11 @@
}
catch (Exception e) {
_dom = null;
- _dtdMonitor = null;
}
}
public DOM getDocument() { return(_dom); }
- public DTDMonitor getDTDMonitor() { return(_dtdMonitor); }
-
public long getFirstReferenced() { return(_firstReferenced); }
public long getLastReferenced() { return(_lastReferenced); }
@@ -322,8 +312,7 @@
}
// Get the references to the actual DOM and DTD handler
- final DOM dom = doc.getDocument();
- final DTDMonitor dtd = doc.getDTDMonitor();
+ final DOM dom = doc.getDocument();
// The dom reference may be null if the URL pointed to a
// non-existing document
@@ -333,12 +322,9 @@
final AbstractTranslet translet = (AbstractTranslet)trs;
- // Set minimum needed size for key/id indices in the translet
- translet.setIndexSize(dom.getSize());
- // Create index for any ID attributes defined in the document DTD
- dtd.buildIdIndex(dom, mask, translet);
- // Pass all unparsed entities to the translet
- translet.setUnparsedEntityURIs(dtd.getUnparsedEntityURIs());
+ // Give the translet an early opportunity to extract any
+ // information from the DOM object that it would like.
+ translet.prepassDocument(dom);
return(doc.getDocument());
}
1.1.4.2 +6 -2
xml-xalan/java/src/org/apache/xalan/xsltc/dom/ExtendedSAX.java
Index: ExtendedSAX.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/ExtendedSAX.java,v
retrieving revision 1.1.4.1
retrieving revision 1.1.4.2
diff -u -r1.1.4.1 -r1.1.4.2
--- ExtendedSAX.java 29 Jul 2002 00:01:27 -0000 1.1.4.1
+++ ExtendedSAX.java 24 Aug 2002 11:33:16 -0000 1.1.4.2
@@ -62,8 +62,12 @@
package org.apache.xalan.xsltc.dom;
import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.ext.DeclHandler;
-public interface ExtendedSAX extends ContentHandler, LexicalHandler {
+public interface ExtendedSAX extends ContentHandler, LexicalHandler,
DTDHandler,
+ DeclHandler
+{
public boolean setEscaping(boolean escape);
}
No revision
No revision
1.2.10.2 +6 -11 xml-xalan/java/src/org/apache/xalan/xsltc/DOMCache.java
Index: DOMCache.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/DOMCache.java,v
retrieving revision 1.2.10.1
retrieving revision 1.2.10.2
diff -u -r1.2.10.1 -r1.2.10.2
--- DOMCache.java 17 Apr 2002 18:13:41 -0000 1.2.10.1
+++ DOMCache.java 24 Aug 2002 11:33:16 -0000 1.2.10.2
@@ -75,20 +75,15 @@
* Parser _parser = new Parser();
* DOMImpl _dom = new DOMImpl();
* _parser.setDocumentHandler(_dom.getBuilder());
+ * _parser.setDTDHandler(_dom.getBuilder());
* _parser.parse(uri);
*
- * (2) building indicies for all ID elements (declared in DTD):
+ * (2) giving the translet an early opportunity to extract anything from
+ * the DOMImpl that it would like
*
- * DTDMonitor _dtdMonitor = new DTDMonitor();
- * _parser.setDTDHandler(_dtdMonitor);
- * translet.setIndexSize(dom.getSize());
- * dtd.buildIdIndex(dom, mask, translet);
+ * translet.documentPrepass(_dom);
*
- * (3) passing unparsed entity URI elements from DTD to translet:
- *
- * translet.setUnparsedEntityURIs(dtd.getUnparsedEntityURIs());
- *
- * (4) setting the document URI:
+ * (3) setting the document URI:
*
* _dom.setDocumentURI(uri);
*/
No revision
No revision
1.33.2.3 +51 -48
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java
Index: AbstractTranslet.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java,v
retrieving revision 1.33.2.2
retrieving revision 1.33.2.3
diff -u -r1.33.2.2 -r1.33.2.3
--- AbstractTranslet.java 29 Jul 2002 00:01:28 -0000 1.33.2.2
+++ AbstractTranslet.java 24 Aug 2002 11:33:16 -0000 1.33.2.3
@@ -76,7 +76,6 @@
import org.apache.xalan.xsltc.dom.DOMImpl;
import org.apache.xalan.xsltc.dom.SAXImpl;
import org.apache.xalan.xsltc.dom.KeyIndex;
-import org.apache.xalan.xsltc.dom.DTDMonitor;
import org.apache.xalan.xsltc.util.IntegerArray;
import org.apache.xalan.xsltc.runtime.output.*;
@@ -108,6 +107,9 @@
// Use one empty string instead of constantly instanciating String("");
private final static String EMPTYSTRING = "";
+ // This is the name of the index used for ID attributes
+ private final static String ID_INDEX_NAME = "##id";
+
/************************************************************************
* Debugging
@@ -347,56 +349,57 @@
return(null);
}
- /************************************************************************
- * Unparsed entity URI handling - implements unparsed-entity-uri()
-
************************************************************************/
-
- // Keeps all unparsed entity URIs specified in the XML input
- public Hashtable _unparsedEntities = null;
-
- /**
- * Get the value of an unparsed entity URI.
- * This method is used by the compiler/UnparsedEntityUriCall class.
- */
- public final String getUnparsedEntity(String name) {
- final String uri = (String)_unparsedEntities.get(name);
- return uri == null ? EMPTYSTRING : uri;
- }
-
/**
- * Add an unparsed entity URI. The URI/value pairs are passed from the
- * DOM builder to the translet.
- */
- public final void addUnparsedEntity(String name, String uri) {
- if (_unparsedEntities == null)
- _unparsedEntities = new Hashtable();
- if (_unparsedEntities.containsKey(name) == false)
- _unparsedEntities.put(name, uri);
- }
-
- /**
- * Add an unparsed entity URI. The URI/value pairs are passed from the
- * DOM builder to the translet.
- */
- public final void setUnparsedEntityURIs(Hashtable table) {
- if (_unparsedEntities == null)
- _unparsedEntities = table;
- else {
- Enumeration keys = table.keys();
- while (keys.hasMoreElements()) {
- String name = (String)keys.nextElement();
- _unparsedEntities.put(name,table.get(name));
- }
- }
+ * Give the translet an opportunity to perform a prepass on the document
+ * to extract any information that it can store in an optimized form.
+ *
+ * Currently, it only extracts information about attributes of type ID.
+ */
+ public final void prepassDocument(DOM document) {
+ setIndexSize(document.getSize());
+ buildIDIndex(document);
}
/**
- * The DTD monitor used by the DOM builder scans the input document DTD
- * for unparsed entity URIs. These are passed to the translet using
- * this method.
- */
- public final void setDTDMonitor(DTDMonitor monitor) {
- setUnparsedEntityURIs(monitor.getUnparsedEntityURIs());
+ * Leverages the Key Class to implement the XSLT id() function.
+ * buildIdIndex creates the index (##id) that Key Class uses.
+ * The index contains the element node index (int) and Id value (String).
+ */
+ private final void buildIDIndex(DOM document) {
+ // %HZ% %REVISIT% This works fine when the document is built from
+ // %HZ% %REVISIT% SAX events, but if it is built from a W3C DOM,
+ // %HZ% %REVISIT% the only means of associating ID's with elements
is
+ // %HZ% %REVISIT% the getElementById method. There's no way of
+ // %HZ% %REVISIT% knowing a priori which ID values are in the DOM,
+ // %HZ% %REVISIT% which elements have attributes of type ID, nor
+ // %HZ% %REVISIT% even which attributes are of type ID. Not
+ // %HZ% %REVISIT% surprisingly, the old DOMImpl didn't correctly
+ // %HZ% %REVISIT% handle the id() function. We'll probably need to
+ // %HZ% %REVISIT% build KeyIndex objects that operate on the DOM
+ // %HZ% %REVISIT% directly to solve this problem.
+ final Hashtable elementsByID = document.getElementsWithIDs();
+
+ if (elementsByID == null) {
+ return;
+ }
+
+ // Given a Hashtable of DTM nodes indexed by ID attribute values,
+ // loop through the table copying information to a KeyIndex
+ // for the mapping from ID attribute value to DTM node
+ final Enumeration idValues = elementsByID.keys();
+ boolean hasIDValues = false;
+
+ while (idValues.hasMoreElements()) {
+ final Object idValue = idValues.nextElement();
+ final int element =
((Integer)elementsByID.get(idValue)).intValue();
+
+ buildKeyIndex(ID_INDEX_NAME, element, idValue);
+ hasIDValues = true;
+ }
+
+ if (hasIDValues) {
+ setKeyIndexDom(ID_INDEX_NAME, document);
+ }
}
/************************************************************************
No revision
No revision
1.6.10.5 +14 -13
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerHandlerImpl.java
Index: TransformerHandlerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerHandlerImpl.java,v
retrieving revision 1.6.10.4
retrieving revision 1.6.10.5
diff -u -r1.6.10.4 -r1.6.10.5
--- TransformerHandlerImpl.java 13 Aug 2002 21:21:14 -0000 1.6.10.4
+++ TransformerHandlerImpl.java 24 Aug 2002 11:33:16 -0000 1.6.10.5
@@ -78,7 +78,6 @@
import org.apache.xalan.xsltc.dom.DOMImpl;
import org.apache.xalan.xsltc.dom.SAXImpl;
import org.apache.xalan.xsltc.dom.DOMBuilder;
-import org.apache.xalan.xsltc.dom.DTDMonitor;
import org.apache.xalan.xsltc.dom.XSLTCDTMManager;
import org.apache.xalan.xsltc.runtime.AbstractTranslet;
import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
@@ -94,7 +93,8 @@
private SAXImpl _dom = null;
private ContentHandler _handler = null;
private LexicalHandler _lexHandler = null;
- private DTDMonitor _dtd = null;
+ private DTDHandler _dtdHandler = null;
+ private DeclHandler _declHandler = null;
private Result _result = null;
private Locator _locator = null;
@@ -121,9 +121,6 @@
else {
// Get a reference to the translet wrapped inside the transformer
_translet = _transformer.getTranslet();
-
- // Create a new DTD monitor
- _dtd = new DTDMonitor();
}
}
@@ -176,6 +173,8 @@
_handler = new SAX2TO(outputHandler);
_lexHandler = (LexicalHandler) _handler;
+ _dtdHandler = (DTDHandler) _handler;
+ _declHandler = (DeclHandler) _handler;
}
catch (TransformerException e) {
_result = null;
@@ -224,6 +223,9 @@
_dom = (SAXImpl)dtmManager.getDTM(null, false, null, true, true);
_handler = _dom.getBuilder();
_lexHandler = (LexicalHandler) _handler;
+ _dtdHandler = (DTDHandler) _handler;
+ _declHandler = (DeclHandler) _handler;
+
// Set document URI
_dom.setDocumentURI(_systemId);
}
@@ -250,7 +252,6 @@
if (_result != null) {
try {
_transformer.setDOM(_dom);
- _transformer.setDTDMonitor(_dtd); // for id/key
_transformer.transform(null, _result);
}
catch (TransformerException e) {
@@ -418,7 +419,7 @@
public void unparsedEntityDecl(String name, String publicId,
String systemId, String notationName) throws SAXException
{
- _dtd.unparsedEntityDecl(name, publicId, systemId, notationName);
+ _dtdHandler.unparsedEntityDecl(name, publicId, systemId, notationName);
}
/**
@@ -427,7 +428,7 @@
public void notationDecl(String name, String publicId, String systemId)
throws SAXException
{
- _dtd.notationDecl(name, publicId, systemId);
+ _dtdHandler.notationDecl(name, publicId, systemId);
}
/**
@@ -436,7 +437,7 @@
public void attributeDecl(String eName, String aName, String type,
String valueDefault, String value) throws SAXException
{
- _dtd.attributeDecl(eName, aName, type, valueDefault, value);
+ _declHandler.attributeDecl(eName, aName, type, valueDefault, value);
}
/**
@@ -445,7 +446,7 @@
public void elementDecl(String name, String model)
throws SAXException
{
- _dtd.elementDecl(name, model);
+ _declHandler.elementDecl(name, model);
}
/**
@@ -454,7 +455,7 @@
public void externalEntityDecl(String name, String publicId, String
systemId)
throws SAXException
{
- _dtd.externalEntityDecl(name, publicId, systemId);
+ _declHandler.externalEntityDecl(name, publicId, systemId);
}
/**
@@ -463,6 +464,6 @@
public void internalEntityDecl(String name, String value)
throws SAXException
{
- _dtd.internalEntityDecl(name, value);
+ _declHandler.internalEntityDecl(name, value);
}
}
1.37.2.4 +8 -51
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java,v
retrieving revision 1.37.2.3
retrieving revision 1.37.2.4
diff -u -r1.37.2.3 -r1.37.2.4
--- TransformerImpl.java 13 Aug 2002 21:19:08 -0000 1.37.2.3
+++ TransformerImpl.java 24 Aug 2002 11:33:16 -0000 1.37.2.4
@@ -164,11 +164,6 @@
private DOM _dom = null;
/**
- * DTD monitor needed for id()/key().
- */
- private DTDMonitor _dtdMonitor = null;
-
- /**
* Number of indent spaces to add when indentation is on.
*/
private int _indentNumber;
@@ -378,20 +373,12 @@
}
/**
- * Set the internal DTD Monitor to use for the next transformation
- */
- protected void setDTDMonitor(DTDMonitor dtdMonitor) {
- _dtdMonitor = dtdMonitor;
- }
-
- /**
* Builds an internal DOM from a TrAX Source object
*/
private DOM getDOM(Source source, int mask)
throws TransformerException {
try {
DOM dom = null;
- DTDMonitor dtd = null;
// Get systemId from source
if (source != null) {
@@ -409,10 +396,6 @@
reader = _tfactory.getXMLReader();
}
- // Create a DTD monitor to trap all DTD/declarative events
- dtd = new DTDMonitor();
- dtd.handleDTD(reader);
-
// Create a new internal DOM and set up its builder to trap
// all content/lexical events
DTMManager dtmManager = XSLTCDTMManager.newInstance(
@@ -427,34 +410,19 @@
// quitely ignored
}
reader.setContentHandler(builder);
+ reader.setDTDHandler(builder);
((SAXImpl)dom).setDocumentURI(_sourceSystemId);
}
else if (source instanceof DOMSource) {
- // %HZ% - Need to change following - it's wrapping DOM with
- // SAX to get to DTM. Should wrap DOM with DTM directly!
final DOMSource domsrc = (DOMSource) source;
- final org.w3c.dom.Node node = domsrc.getNode();
- final DOM2SAX dom2sax = new DOM2SAX(node);
- final boolean isComplete =
- (node.getNodeType() == org.w3c.dom.Node.DOCUMENT_NODE);
-
- // Create a DTD monitor to trap all DTD/declarative events
- dtd = new DTDMonitor();
- dtd.handleDTD(dom2sax);
- // Create a new internal DOM and set up its builder to trap
- // all content/lexical events
+ // Create a new internal DTM and build it directly from DOM
DTMManager dtmManager = XSLTCDTMManager.newInstance(
org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
- dom = (SAXImpl)dtmManager.getDTM(null, false, null, true,
+ dom = (DOMImpl)dtmManager.getDTM(domsrc, false, null, true,
true);
- final DOMBuilder builder = ((SAXImpl)dom).getBuilder();
- dom2sax.setContentHandler(builder);
-
- dom2sax.parse();
-
- ((SAXImpl)dom).setDocumentURI(_sourceSystemId);
+ ((DOMImpl)dom).setDocumentURI(_sourceSystemId);
}
// Handle StreamSource input
else if (source instanceof StreamSource) {
@@ -464,10 +432,6 @@
final Reader streamReader = stream.getReader();
final XMLReader reader = _tfactory.getXMLReader();
- // Create a DTD monitor to trap all DTD/declarative events
- dtd = new DTDMonitor();
- dtd.handleDTD(reader);
-
// Create a new internal DOM and set up its builder to trap
// all content/lexical events
DTMManager dtmManager = XSLTCDTMManager.newInstance(
@@ -490,27 +454,20 @@
}
else if (source instanceof XSLTCSource) {
final XSLTCSource xsltcsrc = (XSLTCSource)source;
- dtd = xsltcsrc.getDTD();
dom = xsltcsrc.getDOM();
}
// DOM already set via a call to setDOM()
else if (_dom != null) {
- dtd = _dtdMonitor; // must be set via setDTDMonitor()
dom = _dom; _dom = null; // use only once, so reset to 'null'
}
else {
return null;
}
- // Set size of key/id indices
if (!_isIdentity) {
- _translet.setIndexSize(dom.getSize());
-
- // If there are any elements with ID attributes, build an index
- dtd.buildIdIndex(dom, mask, _translet);
-
- // Pass unparsed entity URIs to the translet
- _translet.setDTDMonitor(dtd);
+ // Give the translet the opportunity to make a prepass of
+ // the document, in case it can extract useful information
early
+ _translet.prepassDocument(dom);
}
return dom;
1.3.10.2 +17 -32
xml-xalan/java/src/org/apache/xalan/xsltc/trax/XSLTCSource.java
Index: XSLTCSource.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/XSLTCSource.java,v
retrieving revision 1.3.10.1
retrieving revision 1.3.10.2
diff -u -r1.3.10.1 -r1.3.10.2
--- XSLTCSource.java 17 Apr 2002 18:13:47 -0000 1.3.10.1
+++ XSLTCSource.java 24 Aug 2002 11:33:17 -0000 1.3.10.2
@@ -90,7 +90,6 @@
private String _systemId = null;
private DOM _dom = null;
- private DTDMonitor _dtd = null;
private final static String LEXICAL_HANDLER_PROPERTY =
"http://xml.org/sax/properties/lexical-handler";
@@ -102,15 +101,14 @@
*/
public XSLTCSource(int size)
{
- DTMManager dtmManager = XSLTCDTMManager.newInstance(
-
org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
+ DTMManager dtmManager =
+ XSLTCDTMManager.newInstance(org.apache.xpath.objects
+
.XMLStringFactoryImpl.getFactory());
int dtmPos = ((DTMManagerDefault)dtmManager).getFirstFreeDTMID();
int documentID = dtmPos << DTMManager.IDENT_DTM_NODE_BITS;
- _dom = (DOM)new SAXImpl(dtmManager, this, documentID, null,
dtmManager.getXMLStringFactory(), true, size);
+ _dom = (DOM)new SAXImpl(dtmManager, this, documentID, null,
+ dtmManager.getXMLStringFactory(), true, size);
((DTMManagerDefault)dtmManager).addDTM((DTM)_dom, dtmPos);
- //((XSLTCDTMManager)dtmManager).getDTM(this, false, null,
true, true, size);
- //_dom = new DOMImpl(size);
- _dtd = new DTDMonitor();
}
/**
@@ -118,15 +116,14 @@
*/
public XSLTCSource()
{
- DTMManager dtmManager = XSLTCDTMManager.newInstance(
-
org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
+ DTMManager dtmManager =
+ XSLTCDTMManager.newInstance(org.apache.xpath.objects
+
.XMLStringFactoryImpl.getFactory());
int dtmPos = ((DTMManagerDefault)dtmManager).getFirstFreeDTMID();
int documentID = dtmPos << DTMManager.IDENT_DTM_NODE_BITS;
- _dom = (DOM)new SAXImpl(dtmManager, this, documentID, null,
dtmManager.getXMLStringFactory(), true);
+ _dom = (DOM)new SAXImpl(dtmManager, this, documentID, null,
+ dtmManager.getXMLStringFactory(), true);
((DTMManagerDefault)dtmManager).addDTM((DTM)_dom, dtmPos);
- //(DOM)dtmManager.getDTM(this, false, null, true, true);
- //_dom = new DOMImpl();
- _dtd = new DTDMonitor();
}
/**
@@ -143,7 +140,7 @@
else
_systemId = systemId;
- ((SAXImpl)_dom).setDocumentURI(_systemId);
+ ((SAXImpl)_dom).setDocumentURI(_systemId);
}
/**
@@ -179,20 +176,16 @@
// parser before we know that we actually have some valid input.
InputSource input = new InputSource(systemId);
- // Set out DTD monitor up to receive all DTD and declarative
- // events from the SAX parser. This is necessary to properly
- // build the index used for the id() function
- _dtd.handleDTD(reader);
-
DOMBuilder builder;
// Can we assume we're dealing with SAX here and therefore use
SAXIMPL??
- // if (_dom instanceof DOMImpl)
- // builder = ((DOMImpl)_dom).getBuilder();
- // else
- builder = ((SAXImpl)_dom).getBuilder();
+ // if (_dom instanceof DOMImpl)
+ // builder = ((DOMImpl)_dom).getBuilder();
+ // else
+ builder = ((SAXImpl)_dom).getBuilder();
// Set the DOM builder up to receive content and lexical events
reader.setContentHandler(builder);
+ reader.setDTDHandler(builder);
try {
reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);
}
@@ -251,12 +244,4 @@
protected DOM getDOM() {
return(_dom);
}
-
- /**
- * Returns the internal DTD that is encapsulated in this Source
- */
- protected DTDMonitor getDTD() {
- return(_dtd);
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]