You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mk...@apache.org on 2003/04/01 23:19:06 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/trax DOM2SAX.java DOM2TO.java TemplatesHandlerImpl.java TransformerHandlerImpl.java TransformerImpl.java XSLTCSource.java SAX2TO.java
mkwan 2003/04/01 13:19:06
Modified: java/src/org/apache/xalan/xsltc/trax DOM2SAX.java
DOM2TO.java TemplatesHandlerImpl.java
TransformerHandlerImpl.java TransformerImpl.java
XSLTCSource.java
Removed: java/src/org/apache/xalan/xsltc/trax SAX2TO.java
Log:
Merging XSLTC_DTM and common serializer to the head
Changes in org.apache.xalan.xsltc.trax.
Revision Changes Path
1.20 +13 -2 xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2SAX.java
Index: DOM2SAX.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2SAX.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- DOM2SAX.java 30 Jan 2003 18:46:14 -0000 1.19
+++ DOM2SAX.java 1 Apr 2003 21:19:06 -0000 1.20
@@ -83,6 +83,7 @@
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
+import org.apache.xalan.xsltc.dom.SAXImpl;
public class DOM2SAX implements XMLReader, Locator {
@@ -92,6 +93,7 @@
private Node _dom = null;
private ContentHandler _sax = null;
private LexicalHandler _lex = null;
+ private SAXImpl _saxImpl = null;
private Hashtable _nsPrefixes = new Hashtable();
public DOM2SAX(Node root) {
@@ -109,6 +111,10 @@
if (handler instanceof LexicalHandler) {
_lex = (LexicalHandler) handler;
}
+
+ if (handler instanceof SAXImpl) {
+ _saxImpl = (SAXImpl)handler;
+ }
}
/**
@@ -310,7 +316,12 @@
}
// Generate SAX event to start element
- _sax.startElement(uri, localName, qname, attrs);
+ if (_saxImpl != null) {
+ _saxImpl.startElement(uri, localName, qname, attrs, node);
+ }
+ else {
+ _sax.startElement(uri, localName, qname, attrs);
+ }
// Traverse all child nodes of the element (if any)
next = node.getFirstChild();
1.6 +9 -10 xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2TO.java
Index: DOM2TO.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2TO.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DOM2TO.java 30 Jan 2003 18:46:14 -0000 1.5
+++ DOM2TO.java 1 Apr 2003 21:19:06 -0000 1.6
@@ -64,11 +64,10 @@
import java.io.IOException;
-import org.apache.xalan.xsltc.TransletOutputHandler;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-
+import org.apache.xml.serializer.SerializationHandler;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
@@ -93,9 +92,9 @@
/**
* A reference to the output handler receiving the events.
*/
- private TransletOutputHandler _handler;
+ private SerializationHandler _handler;
- public DOM2TO(Node root, TransletOutputHandler handler) {
+ public DOM2TO(Node root, SerializationHandler handler) {
_dom = root;
_handler = handler;
}
@@ -176,7 +175,7 @@
case Node.ELEMENT_NODE:
// Generate SAX event to start element
final String qname = node.getNodeName();
- _handler.startElement(qname);
+ _handler.startElement(null, null, qname);
String prefix;
final NamedNodeMap map = node.getAttributes();
final int length = map.getLength();
@@ -192,7 +191,7 @@
colon = qnameAttr.lastIndexOf(':');
prefix = (colon > 0) ? qnameAttr.substring(colon + 1)
: EMPTYSTRING;
- _handler.namespace(prefix, uriAttr);
+ _handler.namespaceAfterStartElement(prefix, uriAttr);
}
else {
final String uriAttr = attr.getNamespaceURI();
@@ -201,9 +200,9 @@
colon = qnameAttr.lastIndexOf(':');
prefix = (colon > 0) ? qnameAttr.substring(0, colon)
: EMPTYSTRING;
- _handler.namespace(prefix, uriAttr);
+ _handler.namespaceAfterStartElement(prefix, uriAttr);
}
- _handler.attribute(qnameAttr, attr.getNodeValue());
+ _handler.addAttribute(qnameAttr, attr.getNodeValue());
}
}
@@ -214,7 +213,7 @@
if (uri != null) {
final int colon = qname.lastIndexOf(':');
prefix = (colon > 0) ? qname.substring(0, colon) : EMPTYSTRING;
- _handler.namespace(prefix, uri);
+ _handler.namespaceAfterStartElement(prefix, uri);
}
// Traverse all child nodes of the element (if any)
1.21 +7 -6 xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
Index: TemplatesHandlerImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- TemplatesHandlerImpl.java 31 Mar 2003 13:13:09 -0000 1.20
+++ TemplatesHandlerImpl.java 1 Apr 2003 21:19:06 -0000 1.21
@@ -85,7 +85,7 @@
/**
* Implementation of a JAXP1.1 TemplatesHandler
*/
-public class TemplatesHandlerImpl
+public class TemplatesHandlerImpl
implements ContentHandler, TemplatesHandler, SourceLoader
{
/**
@@ -108,7 +108,7 @@
* object belongs to.
*/
private TransformerFactoryImpl _tfactory = null;
-
+
/**
* A reference to XSLTC's parser object.
*/
@@ -122,7 +122,7 @@
{
_indentNumber = indentNumber;
_tfactory = tfactory;
-
+
// Initialize a parser object
XSLTC xsltc = new XSLTC();
xsltc.init();
@@ -202,13 +202,14 @@
// Set it as top-level in the XSLTC object
xsltc.setStylesheet(stylesheet);
- // Create AST under the Stylesheet element
+ // Create AST under the Stylesheet element
_parser.createAST(stylesheet);
}
// Generate the bytecodes and output the translet class(es)
if (!_parser.errorsFound() && stylesheet != null) {
stylesheet.setMultiDocument(xsltc.isMultiDocument());
+ stylesheet.setHasIdCall(xsltc.hasIdCall());
// Class synchronization is needed for BCEL
synchronized (xsltc.getClass()) {
@@ -260,7 +261,7 @@
}
return null;
}
-
+
// -- ContentHandler --------------------------------------------------
/**
1.15 +69 -30 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- TransformerHandlerImpl.java 30 Jan 2003 18:46:14 -0000 1.14
+++ TransformerHandlerImpl.java 1 Apr 2003 21:19:06 -0000 1.15
@@ -67,14 +67,18 @@
import javax.xml.transform.TransformerException;
import javax.xml.transform.sax.TransformerHandler;
-import org.apache.xalan.xsltc.TransletOutputHandler;
+import org.apache.xalan.xsltc.StripFilter;
import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
-import org.apache.xalan.xsltc.dom.DOMImpl;
-import org.apache.xalan.xsltc.dom.DTDMonitor;
+import org.apache.xalan.xsltc.dom.DOMWSFilter;
+import org.apache.xalan.xsltc.dom.SAXImpl;
+import org.apache.xalan.xsltc.dom.XSLTCDTMManager;
import org.apache.xalan.xsltc.runtime.AbstractTranslet;
+import org.apache.xml.dtm.DTMWSFilter;
+import org.apache.xml.serializer.SerializationHandler;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DeclHandler;
@@ -89,11 +93,13 @@
private TransformerImpl _transformer;
private AbstractTranslet _translet = null;
private String _systemId;
- private DOMImpl _dom = null;
+ 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;
private boolean _done = false; // Set in endDocument()
@@ -118,14 +124,6 @@
else {
// Get a reference to the translet wrapped inside the transformer
_translet = _transformer.getTranslet();
-
- // Create a DOMBuilder object and get the handler
- _dom = new DOMImpl();
- _handler = _dom.getBuilder();
- _lexHandler = (LexicalHandler) _handler;
-
- // Create a new DTD monitor
- _dtd = new DTDMonitor();
}
}
@@ -172,12 +170,12 @@
if (_isIdentity) {
try {
// Connect this object with output system directly
- TransletOutputHandler outputHandler =
+ SerializationHandler outputHandler =
_transformer.getOutputHandler(result);
_transformer.transferOutputProperties(outputHandler);
- _handler = new SAX2TO(outputHandler);
- _lexHandler = (LexicalHandler) _handler;
+ _handler = outputHandler;
+ _lexHandler = outputHandler;
}
catch (TransformerException e) {
_result = null;
@@ -217,10 +215,35 @@
throw new SAXException(err.toString());
}
- if (!_isIdentity) {
- // Set document URI
- _dom.setDocumentURI(_systemId);
- }
+ if (!_isIdentity) {
+ boolean hasIdCall = (_translet != null) ? _translet.hasIdCall() : false;
+
+ // Create an internal DOM (not W3C) and get SAX2 input handler
+ XSLTCDTMManager dtmManager = XSLTCDTMManager.newInstance();
+
+ DTMWSFilter wsFilter;
+ if (_translet != null && _translet instanceof StripFilter) {
+ wsFilter = new DOMWSFilter(_translet);
+ } else {
+ wsFilter = null;
+ }
+
+ // Construct the DTM using the SAX events that come through
+ _dom = (SAXImpl)dtmManager.getDTM(null, false, wsFilter, true, false, hasIdCall);
+
+ _handler = _dom.getBuilder();
+ _lexHandler = (LexicalHandler) _handler;
+ _dtdHandler = (DTDHandler) _handler;
+ _declHandler = (DeclHandler) _handler;
+
+
+ // Set document URI
+ _dom.setDocumentURI(_systemId);
+
+ if (_locator != null) {
+ _handler.setDocumentLocator(_locator);
+ }
+ }
// Proxy call
_handler.startDocument();
@@ -239,14 +262,13 @@
if (_result != null) {
try {
_transformer.setDOM(_dom);
- _transformer.setDTDMonitor(_dtd); // for id/key
_transformer.transform(null, _result);
}
catch (TransformerException e) {
throw new SAXException(e);
}
}
- // Signal that the internal DOM is build (see 'setResult()').
+ // Signal that the internal DOM is built (see 'setResult()').
_done = true;
// Set this DOM as the transformer's DOM
@@ -331,7 +353,11 @@
* Receive an object for locating the origin of SAX document events.
*/
public void setDocumentLocator(Locator locator) {
- _handler.setDocumentLocator(locator);
+ _locator = locator;
+
+ if (_handler != null) {
+ _handler.setDocumentLocator(locator);
+ }
}
/**
@@ -403,7 +429,10 @@
public void unparsedEntityDecl(String name, String publicId,
String systemId, String notationName) throws SAXException
{
- _dtd.unparsedEntityDecl(name, publicId, systemId, notationName);
+ if (_dtdHandler != null) {
+ _dtdHandler.unparsedEntityDecl(name, publicId, systemId,
+ notationName);
+ }
}
/**
@@ -412,7 +441,9 @@
public void notationDecl(String name, String publicId, String systemId)
throws SAXException
{
- _dtd.notationDecl(name, publicId, systemId);
+ if (_dtdHandler != null) {
+ _dtdHandler.notationDecl(name, publicId, systemId);
+ }
}
/**
@@ -421,7 +452,9 @@
public void attributeDecl(String eName, String aName, String type,
String valueDefault, String value) throws SAXException
{
- _dtd.attributeDecl(eName, aName, type, valueDefault, value);
+ if (_declHandler != null) {
+ _declHandler.attributeDecl(eName, aName, type, valueDefault, value);
+ }
}
/**
@@ -430,7 +463,9 @@
public void elementDecl(String name, String model)
throws SAXException
{
- _dtd.elementDecl(name, model);
+ if (_declHandler != null) {
+ _declHandler.elementDecl(name, model);
+ }
}
/**
@@ -439,7 +474,9 @@
public void externalEntityDecl(String name, String publicId, String systemId)
throws SAXException
{
- _dtd.externalEntityDecl(name, publicId, systemId);
+ if (_declHandler != null) {
+ _declHandler.externalEntityDecl(name, publicId, systemId);
+ }
}
/**
@@ -448,6 +485,8 @@
public void internalEntityDecl(String name, String value)
throws SAXException
{
- _dtd.internalEntityDecl(name, value);
+ if (_declHandler != null) {
+ _declHandler.internalEntityDecl(name, value);
+ }
}
}
1.65 +129 -128 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.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- TransformerImpl.java 26 Mar 2003 16:33:09 -0000 1.64
+++ TransformerImpl.java 1 Apr 2003 21:19:06 -0000 1.65
@@ -65,21 +65,19 @@
package org.apache.xalan.xsltc.trax;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
-import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
-import java.net.UnknownHostException;
import java.net.UnknownServiceException;
import java.util.Enumeration;
import java.util.Properties;
import java.util.StringTokenizer;
+import java.util.Vector;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.ErrorListener;
@@ -96,17 +94,20 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import org.apache.xalan.xsltc.DOM;
import org.apache.xalan.xsltc.DOMCache;
+import org.apache.xalan.xsltc.StripFilter;
import org.apache.xalan.xsltc.Translet;
import org.apache.xalan.xsltc.TransletException;
-import org.apache.xalan.xsltc.TransletOutputHandler;
+import org.apache.xml.serializer.SerializationHandler;
import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
-import org.apache.xalan.xsltc.dom.DOMBuilder;
-import org.apache.xalan.xsltc.dom.DOMImpl;
-import org.apache.xalan.xsltc.dom.DTDMonitor;
+import org.apache.xalan.xsltc.dom.DOMWSFilter;
+import org.apache.xalan.xsltc.dom.SAXImpl;
+import org.apache.xalan.xsltc.dom.XSLTCDTMManager;
import org.apache.xalan.xsltc.runtime.AbstractTranslet;
import org.apache.xalan.xsltc.runtime.Hashtable;
import org.apache.xalan.xsltc.runtime.output.TransletOutputHandlerFactory;
+import org.apache.xml.dtm.DTMWSFilter;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -115,7 +116,7 @@
import org.xml.sax.ext.LexicalHandler;
public final class TransformerImpl extends Transformer
- implements DOMCache, ErrorListener
+ implements DOMCache, ErrorListener
{
private final static String EMPTY_STRING = "";
private final static String NO_STRING = "no";
@@ -170,12 +171,7 @@
/**
* A reference to a internal DOM represenation of the input.
*/
- private DOMImpl _dom = null;
-
- /**
- * DTD monitor needed for id()/key().
- */
- private DTDMonitor _dtdMonitor = null;
+ private DOM _dom = null;
/**
* Number of indent spaces to add when indentation is on.
@@ -187,6 +183,11 @@
* object belongs to.
*/
private TransformerFactoryImpl _tfactory = null;
+
+ /**
+ * A flag indicating whether we use incremental building of the DTM.
+ */
+ //private boolean _isIncremental = false;
/**
* A flag indicating whether this transformer implements the identity
@@ -245,6 +246,7 @@
_propertiesClone = (Properties) _properties.clone();
_indentNumber = indentNumber;
_tfactory = tfactory;
+ //_isIncremental = tfactory._incremental;
}
/**
@@ -278,7 +280,7 @@
transferOutputProperties(_translet);
}
- final TransletOutputHandler toHandler = getOutputHandler(result);
+ final SerializationHandler toHandler = getOutputHandler(result);
if (toHandler == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_HANDLER_ERR);
throw new TransformerException(err.toString());
@@ -305,7 +307,7 @@
* the type and contents of the TrAX Result object passed to the
* transform() method.
*/
- public TransletOutputHandler getOutputHandler(Result result)
+ public SerializationHandler getOutputHandler(Result result)
throws TransformerException
{
// Get output method using get() to ignore defaults
@@ -337,12 +339,12 @@
_tohFactory.setLexicalHandler((LexicalHandler) handler);
}
_tohFactory.setOutputType(TransletOutputHandlerFactory.SAX);
- return _tohFactory.getTransletOutputHandler();
+ return _tohFactory.getSerializationHandler();
}
else if (result instanceof DOMResult) {
_tohFactory.setNode(((DOMResult) result).getNode());
_tohFactory.setOutputType(TransletOutputHandlerFactory.DOM);
- return _tohFactory.getTransletOutputHandler();
+ return _tohFactory.getSerializationHandler();
}
else if (result instanceof StreamResult) {
// Get StreamResult
@@ -358,14 +360,14 @@
final Writer writer = target.getWriter();
if (writer != null) {
_tohFactory.setWriter(writer);
- return _tohFactory.getTransletOutputHandler();
+ return _tohFactory.getSerializationHandler();
}
// or try to get an OutputStream from Result object
final OutputStream ostream = target.getOutputStream();
if (ostream != null) {
_tohFactory.setOutputStream(ostream);
- return _tohFactory.getTransletOutputHandler();
+ return _tohFactory.getSerializationHandler();
}
// or try to get just a systemId string from Result object
@@ -383,20 +385,20 @@
url = new URL(systemId);
_tohFactory.setOutputStream(
new FileOutputStream(url.getFile()));
- return _tohFactory.getTransletOutputHandler();
+ return _tohFactory.getSerializationHandler();
}
else if (systemId.startsWith("http:")) {
url = new URL(systemId);
final URLConnection connection = url.openConnection();
_tohFactory.setOutputStream(connection.getOutputStream());
- return _tohFactory.getTransletOutputHandler();
+ return _tohFactory.getSerializationHandler();
}
else {
// system id is just a filename
url = new File(systemId).toURL();
_tohFactory.setOutputStream(
new FileOutputStream(url.getFile()));
- return _tohFactory.getTransletOutputHandler();
+ return _tohFactory.getSerializationHandler();
}
}
}
@@ -415,29 +417,29 @@
}
/**
- * Set the internal DOMImpl that will be used for the next transformation
+ * Set the internal DOM that will be used for the next transformation
*/
- protected void setDOM(DOMImpl dom) {
+ protected void setDOM(DOM dom) {
_dom = dom;
}
/**
- * Set the internal DOMImpl that will be used for the next transformation
- */
- protected void setDTDMonitor(DTDMonitor dtdMonitor) {
- _dtdMonitor = dtdMonitor;
- }
-
- /**
* Builds an internal DOM from a TrAX Source object
*/
- private DOMImpl getDOM(Source source, int mask)
- throws TransformerException
- {
+ private DOM getDOM(Source source, int mask)
+ throws TransformerException {
try {
- DOMImpl dom = null;
- DTDMonitor dtd = null;
-
+ DOM dom = null;
+ SAXImpl saxImpl = null;
+ DTMWSFilter wsfilter;
+ if (_translet != null && _translet instanceof StripFilter) {
+ wsfilter = new DOMWSFilter(_translet);
+ } else {
+ wsfilter = null;
+ }
+
+ boolean hasIdCall = (_translet != null) ? _translet.hasIdCall()
+ : false;
// Get systemId from source
if (source != null) {
_sourceSystemId = source.getSystemId();
@@ -448,50 +450,41 @@
final SAXSource sax = (SAXSource)source;
XMLReader reader = sax.getXMLReader();
final InputSource input = sax.getInputSource();
+ final boolean hasUserReader = reader != null;
// Create a reader if not set by user
if (reader == null) {
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
- dom = new DOMImpl();
- final DOMBuilder builder = dom.getBuilder();
+ // Create a new internal DOM and set up its builder to trap
+ // all content/lexical events
+ XSLTCDTMManager dtmManager = XSLTCDTMManager.newInstance();
+
+ //dtmManager.setIncremental(_isIncremental);
+ saxImpl = (SAXImpl)dtmManager.getDTM(sax, false, wsfilter, true, false,
+ hasUserReader, 0, hasIdCall);
+ //final DOMBuilder builder = ((SAXImpl)dom).getBuilder();
try {
- reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);
+ reader.setProperty(LEXICAL_HANDLER_PROPERTY, saxImpl);
}
catch (SAXException e) {
// quitely ignored
}
- reader.setContentHandler(builder);
-
- // Parse the input and build the internal DOM
- reader.parse(input);
- dom.setDocumentURI(_sourceSystemId);
+ reader.setContentHandler(saxImpl);
+ reader.setDTDHandler(saxImpl);
+ saxImpl.setDocumentURI(_sourceSystemId);
}
else if (source instanceof DOMSource) {
- final DOMSource domsrc = (DOMSource) source;
- final org.w3c.dom.Node node = domsrc.getNode();
- final DOM2SAX dom2sax = new DOM2SAX(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
- dom = new DOMImpl();
- final DOMBuilder builder = dom.getBuilder();
- dom2sax.setContentHandler(builder);
-
- // Parse the input and build the internal DOM
- dom2sax.parse();
- dom.setDocumentURI(_sourceSystemId);
+ // Create a new internal DTM and build it directly from DOM
+ XSLTCDTMManager dtmManager = XSLTCDTMManager.newInstance();
+
+ //dtmManager.setIncremental(_isIncremental);
+ saxImpl = (SAXImpl)dtmManager.getDTM(source, false, wsfilter, true,
+ false, hasIdCall);
+ saxImpl.setDocumentURI(_sourceSystemId);
}
+ // Handle StreamSource input
else if (source instanceof StreamSource) {
// Get all info from the input StreamSource object
final StreamSource stream = (StreamSource)source;
@@ -499,89 +492,76 @@
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
- dom = new DOMImpl();
- final DOMBuilder builder = dom.getBuilder();
- try {
- reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);
- }
- catch (SAXException e) {
- // quitely ignored
- }
- reader.setContentHandler(builder);
+ XSLTCDTMManager dtmManager = XSLTCDTMManager.newInstance();
+ //dtmManager.setIncremental(_isIncremental);
+
InputSource input;
if (streamInput != null) {
input = new InputSource(streamInput);
- input.setSystemId(_sourceSystemId);
- }
+ input.setSystemId(_sourceSystemId);
+ }
else if (streamReader != null) {
input = new InputSource(streamReader);
- input.setSystemId(_sourceSystemId);
- }
- else if (_sourceSystemId != null) {
+ input.setSystemId(_sourceSystemId);
+ }
+ else if (_sourceSystemId != null)
input = new InputSource(_sourceSystemId);
- }
else {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR);
throw new TransformerException(err.toString());
}
-
- // Parse the input and build the internal DOM
- reader.parse(input);
- dom.setDocumentURI(_sourceSystemId);
+ saxImpl = (SAXImpl)dtmManager.getDTM(new SAXSource(reader, input),
+ false, wsfilter, true,
+ false, hasIdCall);
+ saxImpl.setDocumentURI(_sourceSystemId);
}
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 (saxImpl != null) {
+ dom = saxImpl;
+ }
+
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;
}
- catch (FileNotFoundException e) {
- if (_errorListener != null) postErrorToListener(e.getMessage());
- throw new TransformerException(e);
- }
- catch (MalformedURLException e) {
- if (_errorListener != null) postErrorToListener(e.getMessage());
- throw new TransformerException(e);
- }
- catch (UnknownHostException e) {
- if (_errorListener != null) postErrorToListener(e.getMessage());
- throw new TransformerException(e);
- }
+ //catch (FileNotFoundException e) {
+// if (_errorListener != null) postErrorToListener(e.getMessage());
+// throw new TransformerException(e);
+// }
+ //catch (MalformedURLException e) {
+// if (_errorListener != null) postErrorToListener(e.getMessage());
+// throw new TransformerException(e);
+// }
+// catch (UnknownHostException e) {
+// if (_errorListener != null) postErrorToListener(e.getMessage());
+// throw new TransformerException(e);
+// }
catch (Exception e) {
if (_errorListener != null) postErrorToListener(e.getMessage());
throw new TransformerException(e);
}
}
- private void transformIdentity(Source source, TransletOutputHandler handler)
+ private void transformIdentity(Source source, SerializationHandler handler)
throws Exception
{
// Get systemId from source
@@ -602,7 +582,7 @@
catch (SAXException e) {
// Falls through
}
- reader.setContentHandler(new SAX2TO(handler));
+ reader.setContentHandler(handler);
// Create input source from source
InputSource input;
@@ -642,7 +622,7 @@
catch (SAXException e) {
// Falls through
}
- reader.setContentHandler(new SAX2TO(handler));
+ reader.setContentHandler(handler);
// Start pushing SAX events
reader.parse(input);
@@ -652,8 +632,8 @@
new DOM2TO(domsrc.getNode(), handler).parse();
}
else if (source instanceof XSLTCSource) {
- final DOMImpl dom = ((XSLTCSource) source).getDOM();
- dom.copy(handler);
+ final DOM dom = ((XSLTCSource) source).getDOM();
+ ((SAXImpl)dom).copy(handler);
}
else {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR);
@@ -664,7 +644,7 @@
/**
* Internal transformation method - uses the internal APIs of XSLTC
*/
- private void transform(Source source, TransletOutputHandler handler,
+ private void transform(Source source, SerializationHandler handler,
String encoding) throws TransformerException
{
try {
@@ -925,7 +905,7 @@
* This method is used to pass any properties to the output handler
* when running the identity transform.
*/
- public void transferOutputProperties(TransletOutputHandler handler)
+ public void transferOutputProperties(SerializationHandler handler)
{
// Return right now if no properties are set
if (_properties == null) return;
@@ -960,7 +940,7 @@
handler.setVersion(value);
}
else if (name.equals(OutputKeys.OMIT_XML_DECLARATION)) {
- handler.omitHeader(
+ handler.setOmitXMLDeclaration(
value != null && value.toLowerCase().equals("yes"));
}
else if (name.equals(OutputKeys.INDENT)) {
@@ -969,13 +949,34 @@
}
else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
if (value != null) {
- Hashtable table = new Hashtable();
StringTokenizer e = new StringTokenizer(value);
+ Vector uriAndLocalNames = null;
while (e.hasMoreTokens()) {
final String token = e.nextToken();
- table.put(token, token);
- }
- handler.setCdataElements(table);
+
+ // look for the last colon, as the String may be
+ // something like "http://abc.com:local"
+ int lastcolon = token.lastIndexOf(':');
+ String uri;
+ String localName;
+ if (lastcolon > 0) {
+ uri = token.substring(0, lastcolon);
+ localName = token.substring(lastcolon+1);
+ } else {
+ // no colon at all, lets hope this is the
+ // local name itself then
+ uri = null;
+ localName = token;
+ }
+
+ if (uriAndLocalNames == null) {
+ uriAndLocalNames = new Vector();
+ }
+ // add the uri/localName as a pair, in that order
+ uriAndLocalNames.addElement(uri);
+ uriAndLocalNames.addElement(localName);
+ }
+ handler.setCdataSectionElements(uriAndLocalNames);
}
}
}
@@ -1144,7 +1145,7 @@
* @param mask Contains a document ID (passed from the translet)
* @param translet A reference to the translet requesting the document
*/
- public DOMImpl retrieveDocument(String uri, int mask, Translet translet) {
+ public DOM retrieveDocument(String uri, int mask, Translet translet) {
try {
return getDOM(_uriResolver.resolve(uri, _sourceSystemId), mask);
}
@@ -1154,7 +1155,7 @@
return(null);
}
}
-
+
/**
* Receive notification of a recoverable error.
* The transformer must continue to provide normal parsing events after
1.6 +35 -27 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XSLTCSource.java 30 Jan 2003 18:46:14 -0000 1.5
+++ XSLTCSource.java 1 Apr 2003 21:19:06 -0000 1.6
@@ -71,10 +71,13 @@
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Source;
+import org.apache.xalan.xsltc.DOM;
import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
import org.apache.xalan.xsltc.dom.DOMBuilder;
-import org.apache.xalan.xsltc.dom.DOMImpl;
-import org.apache.xalan.xsltc.dom.DTDMonitor;
+import org.apache.xalan.xsltc.dom.SAXImpl;
+import org.apache.xalan.xsltc.dom.XSLTCDTMManager;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMManager;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -83,8 +86,7 @@
public final class XSLTCSource implements Source {
private String _systemId = null;
- private DOMImpl _dom = null;
- private DTDMonitor _dtd = null;
+ private DOM _dom = null;
private final static String LEXICAL_HANDLER_PROPERTY =
"http://xml.org/sax/properties/lexical-handler";
@@ -94,17 +96,29 @@
* @param size The estimated node-count for this DOM. A good guess here
* speeds up the DOM build process.
*/
- public XSLTCSource(int size) {
- _dom = new DOMImpl(size);
- _dtd = new DTDMonitor();
+ public XSLTCSource(int size)
+ {
+ XSLTCDTMManager dtmManager =
+ XSLTCDTMManager.newInstance();
+ int dtmPos = dtmManager.getFirstFreeDTMID();
+ int documentID = dtmPos << DTMManager.IDENT_DTM_NODE_BITS;
+ _dom = (DOM)new SAXImpl(dtmManager, this, documentID, null,
+ null, false, size, true);
+ dtmManager.addDTM((DTM)_dom, dtmPos);
}
/**
* Create a new XSLTC-specific DOM source
*/
- public XSLTCSource() {
- _dom = new DOMImpl();
- _dtd = new DTDMonitor();
+ public XSLTCSource()
+ {
+ XSLTCDTMManager dtmManager =
+ XSLTCDTMManager.newInstance();
+ int dtmPos = dtmManager.getFirstFreeDTMID();
+ int documentID = dtmPos << DTMManager.IDENT_DTM_NODE_BITS;
+ _dom = (DOM)new SAXImpl(dtmManager, this, documentID, null,
+ null, false, true);
+ dtmManager.addDTM((DTM)_dom, dtmPos);
}
/**
@@ -120,7 +134,8 @@
_systemId = "file:"+systemId;
else
_systemId = systemId;
- _dom.setDocumentURI(_systemId);
+
+ ((SAXImpl)_dom).setDocumentURI(_systemId);
}
/**
@@ -156,15 +171,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 = _dom.getBuilder();
+ 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();
// Set the DOM builder up to receive content and lexical events
reader.setContentHandler(builder);
+ reader.setDTDHandler(builder);
try {
reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);
}
@@ -220,15 +236,7 @@
/**
* Returns the internal DOM that is encapsulated in this Source
*/
- protected DOMImpl getDOM() {
+ protected DOM getDOM() {
return(_dom);
}
-
- /**
- * Returns the internal DTD that is encapsulated in this Source
- */
- protected DTDMonitor getDTD() {
- return(_dtd);
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org