zongaro 2002/09/17 14:08:56
Modified: java/src/org/apache/xalan/xsltc/dom Tag: XSLTC_DTM
LoadDocument.java
Log:
After creating a new SAXImpl object, it should be passed to the translet's
prepassDocument method to give the translet a chance to extract information
from the document prior to transformation.
Revision Changes Path
No revision
No revision
1.11.10.5 +70 -69
xml-xalan/java/src/org/apache/xalan/xsltc/dom/LoadDocument.java
Index: LoadDocument.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/LoadDocument.java,v
retrieving revision 1.11.10.4
retrieving revision 1.11.10.5
diff -u -r1.11.10.4 -r1.11.10.5
--- LoadDocument.java 12 Sep 2002 16:06:09 -0000 1.11.10.4
+++ LoadDocument.java 17 Sep 2002 21:08:56 -0000 1.11.10.5
@@ -101,91 +101,92 @@
AbstractTranslet translet, DOM dom)
throws Exception
{
- final String originalUri = uri;
- MultiDOM multiplexer = (MultiDOM)dom;
+ final String originalUri = uri;
+ MultiDOM multiplexer = (MultiDOM)dom;
- // Return an empty iterator if the URI is clearly invalid
- // (to prevent some unncessary MalformedURL exceptions).
- if (uri == null || uri.equals("")) {
- return(new SingletonIterator(DTM.NULL,true));
- }
-
- // Prepend URI base to URI (from context)
- if (base != null && !base.equals("")) {
- if (!uri.startsWith(base) && // unless URI contains base
- !uri.startsWith("/") && // unless URI is abs. file path
- !uri.startsWith("http:/") && // unless URI is abs. http URL
- !uri.startsWith("file:/")) { // unless URI is abs. file URL
- uri = base + uri;
- }
- }
-
- // Check if this is a local file name
- final File file = new File(uri);
- if (file.exists()) {
- uri = file.toURL().toExternalForm();
- }
+ // Return an empty iterator if the URI is clearly invalid
+ // (to prevent some unncessary MalformedURL exceptions).
+ if (uri == null || uri.equals("")) {
+ return(new SingletonIterator(DTM.NULL,true));
+ }
+
+ // Prepend URI base to URI (from context)
+ if (base != null && !base.equals("")) {
+ if (!uri.startsWith(base) && // unless URI contains base
+ !uri.startsWith("/") && // unless URI is abs. file
path
+ !uri.startsWith("http:/") && // unless URI is abs. http URL
+ !uri.startsWith("file:/")) { // unless URI is abs. file URL
+ uri = base + uri;
+ }
+ }
+
+ // Check if this is a local file name
+ final File file = new File(uri);
+ if (file.exists()) {
+ uri = file.toURL().toExternalForm();
+ }
- // Check if this DOM has already been added to the multiplexer
- int mask = multiplexer.getDocumentMask(uri);
- if (mask != -1) {
- DOM newDom = ((DOMAdapter)multiplexer.getDOMAdapter(uri))
+ // Check if this DOM has already been added to the multiplexer
+ int mask = multiplexer.getDocumentMask(uri);
+ if (mask != -1) {
+ DOM newDom = ((DOMAdapter)multiplexer.getDOMAdapter(uri))
.getDOMImpl();
if (newDom instanceof SAXImpl) {
- return new SingletonIterator(((SAXImpl)newDom).getDocument(),
+ return new SingletonIterator(((SAXImpl)newDom).getDocument(),
true);
} else {
- return new SingletonIterator(((DOMImpl)newDom).getDocument(),
+ return new SingletonIterator(((DOMImpl)newDom).getDocument(),
true);
}
- }
+ }
- // Check if we can get the DOM from a DOMCache
- DOMCache cache = translet.getDOMCache();
- DOM newdom;
-
- mask = multiplexer.nextMask(); // peek
-
- if (cache != null) {
- newdom = cache.retrieveDocument(originalUri, mask, translet);
- if (newdom == null) {
- final Exception e = new FileNotFoundException(originalUri);
- throw new TransletException(e);
- }
- }
- else {
- // Parse the input document and construct DOM object
- // Create a SAX parser and get the XMLReader object it uses
- final SAXParserFactory factory = SAXParserFactory.newInstance();
- try {
- factory.setFeature(NAMESPACE_FEATURE,true);
- }
- catch (Exception e) {
- factory.setNamespaceAware(true);
- }
- final SAXParser parser = factory.newSAXParser();
- final XMLReader reader = parser.getXMLReader();
-
- // Set the DOM's DOM builder as the XMLReader's SAX2 content handler
- DTMManager dtmManager =
- ((DTMDefaultBase)((DOMAdapter)multiplexer.getMain())
+ // Check if we can get the DOM from a DOMCache
+ DOMCache cache = translet.getDOMCache();
+ DOM newdom;
+
+ mask = multiplexer.nextMask(); // peek
+
+ if (cache != null) {
+ newdom = cache.retrieveDocument(originalUri, mask, translet);
+ if (newdom == null) {
+ final Exception e = new FileNotFoundException(originalUri);
+ throw new TransletException(e);
+ }
+ } else {
+ // Parse the input document and construct DOM object
+ // Create a SAX parser and get the XMLReader object it uses
+ final SAXParserFactory factory = SAXParserFactory.newInstance();
+ try {
+ factory.setFeature(NAMESPACE_FEATURE,true);
+ }
+ catch (Exception e) {
+ factory.setNamespaceAware(true);
+ }
+ final SAXParser parser = factory.newSAXParser();
+ final XMLReader reader = parser.getXMLReader();
+
+ // Set the DOM's DOM builder as the XMLReader's SAX2 content
handler
+ DTMManager dtmManager =
+ ((DTMDefaultBase)((DOMAdapter)multiplexer.getMain())
.getDOMImpl()).m_mgr;
newdom = (SAXImpl)dtmManager.getDTM(
new SAXSource(reader, new InputSource(uri)),
false, null, true, true);
- ((SAXImpl)newdom).setDocumentURI(uri);
- }
+ translet.prepassDocument(newdom);
+
+ ((SAXImpl)newdom).setDocumentURI(uri);
+ }
- // Wrap the DOM object in a DOM adapter and add to multiplexer
- final DOMAdapter domAdapter = translet.makeDOMAdapter(newdom);
- mask = multiplexer.addDOMAdapter(domAdapter);
+ // Wrap the DOM object in a DOM adapter and add to multiplexer
+ final DOMAdapter domAdapter = translet.makeDOMAdapter(newdom);
+ mask = multiplexer.addDOMAdapter(domAdapter);
- // Create index for any key elements
- translet.buildKeys(newdom, null, null, ((SAXImpl)newdom).getDocument());
+ // Create index for any key elements
+ translet.buildKeys(newdom, null, null,
((SAXImpl)newdom).getDocument());
- // Return a singleton iterator containing the root node
- return new SingletonIterator(((SAXImpl)newdom).getDocument(), true);
+ // Return a singleton iterator containing the root node
+ return new SingletonIterator(((SAXImpl)newdom).getDocument(), true);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]