sboag 00/08/10 22:36:17
Modified: src/org/apache/xalan/xpath/dtm DTMLiaison.java
src/org/apache/xalan/xpath/xml XMLParserLiaison.java
XMLParserLiaisonDefault.java
src/org/apache/xalan/xslt FuncDocument.java
StylesheetHandler.java XSLTEngineImpl.java
Log:
Added use of EntityResolver as per Norman Walsh's note on 07/31/2000 12:26
PM, only I handled the nested stack stuff a bit differently. Attribution to:
Norman Walsh <[EMAIL PROTECTED]>
Revision Changes Path
1.19 +1 -0 xml-xalan/src/org/apache/xalan/xpath/dtm/DTMLiaison.java
Index: DTMLiaison.java
===================================================================
RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/dtm/DTMLiaison.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- DTMLiaison.java 2000/07/23 17:01:35 1.18
+++ DTMLiaison.java 2000/08/11 05:36:10 1.19
@@ -245,6 +245,7 @@
if(m_doThreading)
{
+ // System.out.println("id: "+source.getSystemId());
parser.parse(source);
}
else
1.7 +6 -0
xml-xalan/src/org/apache/xalan/xpath/xml/XMLParserLiaison.java
Index: XMLParserLiaison.java
===================================================================
RCS file:
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/XMLParserLiaison.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XMLParserLiaison.java 2000/03/06 20:13:45 1.6
+++ XMLParserLiaison.java 2000/08/11 05:36:12 1.7
@@ -61,6 +61,7 @@
import org.xml.sax.DocumentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.Parser;
+import org.xml.sax.EntityResolver;
import java.net.URL;
import org.apache.xalan.xpath.*; // temp
@@ -91,6 +92,11 @@
* Reset for new run.
*/
void reset();
+
+ /**
+ * Get the EntityResolver for this liaison.
+ */
+ public EntityResolver getEntityResolver();
/**
* <meta name="usage" content="advanced"/>
1.37 +19 -1
xml-xalan/src/org/apache/xalan/xpath/xml/XMLParserLiaisonDefault.java
Index: XMLParserLiaisonDefault.java
===================================================================
RCS file:
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/XMLParserLiaisonDefault.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- XMLParserLiaisonDefault.java 2000/07/23 17:04:48 1.36
+++ XMLParserLiaisonDefault.java 2000/08/11 05:36:12 1.37
@@ -212,6 +212,14 @@
protected EntityResolver m_entityResolver = null;
/**
+ * Get the EntityResolver for this liaison.
+ */
+ public EntityResolver getEntityResolver()
+ {
+ return m_entityResolver;
+ }
+
+ /**
* The DTD event handler to be used with parsing.
*/
protected DTDHandler m_DTDHandler = null;
@@ -501,7 +509,17 @@
public void parse (String systemId)
throws SAXException, IOException
{
- InputSource source = new InputSource(systemId);
+ InputSource source = null;
+
+ // Attribution to: Norman Walsh <[EMAIL PROTECTED]>
+ if (null != m_entityResolver)
+ {
+ source = m_entityResolver.resolveEntity(null, systemId);
+ }
+ if (null == source)
+ {
+ source = new InputSource(systemId);
+ }
parse(source);
try
{
1.15 +4 -2 xml-xalan/src/org/apache/xalan/xslt/FuncDocument.java
Index: FuncDocument.java
===================================================================
RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/FuncDocument.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- FuncDocument.java 2000/08/04 12:41:37 1.14
+++ FuncDocument.java 2000/08/11 05:36:13 1.15
@@ -218,8 +218,10 @@
urlString = "file:///"+urlString;
}
*/
- XSLTInputSource inputSource = new XSLTInputSource(urlString);
- parserLiaison.parse(inputSource);
+
+ // Attribution to: Norman Walsh <[EMAIL PROTECTED]>
+ parserLiaison.parse(url.toString());
+
newDoc = parserLiaison.getDocument();
}
else
1.29 +71 -1
xml-xalan/src/org/apache/xalan/xslt/StylesheetHandler.java
Index: StylesheetHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/src/org/apache/xalan/xslt/StylesheetHandler.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- StylesheetHandler.java 2000/04/07 19:18:24 1.28
+++ StylesheetHandler.java 2000/08/11 05:36:15 1.29
@@ -74,7 +74,7 @@
* it is not for the faint-of-heart, due to the state tracking
* that has to be done due to the SAX event model.
*/
-public class StylesheetHandler implements DocumentHandler
+public class StylesheetHandler implements DocumentHandler, EntityResolver
{
/**
* The XSLT Processor for needed services.
@@ -1198,6 +1198,49 @@
}
return elem;
}
+
+ private EntityResolver m_resolver = null;
+ private boolean m_isInclude;
+
+ /**
+ * Catch the entity resolving, and fix up the stack.
+ */
+ public InputSource resolveEntity (String publicId,
+ String systemId)
+ throws SAXException, IOException
+ {
+ InputSource is;
+ if((null != m_resolver) && (null != systemId))
+ {
+ is = m_resolver.resolveEntity(publicId, systemId);
+
+ // fix it back up as quick as can be.
+ m_processor.getXMLProcessorLiaison().setEntityResolver(m_resolver);
+ m_resolver = null;
+
+ if(null != is)
+ {
+ URL newHrefURL = new URL(is.getSystemId());
+
+ if(m_isInclude)
+ m_stylesheet.m_includeStack.pop();
+ else
+ m_stylesheet.m_stylesheetRoot.m_importStack.pop();
+
+ if(m_isInclude)
+ m_stylesheet.m_includeStack.push(newHrefURL);
+ else
+ m_stylesheet.m_stylesheetRoot.m_importStack.push(newHrefURL);
+ }
+ }
+ else
+ {
+ // we should never be here, but...
+ is = new InputSource(systemId);
+ is.setPublicId(publicId);
+ }
+ return is;
+ }
/**
* Process xsl:import.
@@ -1240,6 +1283,12 @@
importedStylesheet.m_baseIdent = hrefUrl.toExternalForm();
+ m_resolver
+ = m_processor.getXMLProcessorLiaison().getEntityResolver();
+ if(null != m_resolver)
+ m_processor.getXMLProcessorLiaison().setEntityResolver(this);
+ m_isInclude = false;
+
m_processor.parseXML(hrefUrl,
tp, importedStylesheet);
@@ -1260,6 +1309,14 @@
{
throw new
SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_IOEXCEPTION, new
Object[] {atts.getValue(i)}), ioe); //"Had IO Exception with stylesheet file:
"+atts.getValue(i), ioe);
}
+ finally
+ {
+ if(null != m_resolver)
+ {
+
m_processor.getXMLProcessorLiaison().setEntityResolver(m_resolver);
+ m_resolver = null;
+ }
+ }
m_stylesheet.m_stylesheetRoot.m_importStack.pop();
@@ -1345,12 +1402,25 @@
try
{
+ m_resolver
+ = m_processor.getXMLProcessorLiaison().getEntityResolver();
+ if(null != m_resolver)
+ m_processor.getXMLProcessorLiaison().setEntityResolver(this);
+ m_isInclude = true;
m_processor.parseXML(hrefUrl,
this, m_stylesheet);
}
catch(IOException ioe)
{
throw new
SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESSINCLUDE_ERROR,
null), ioe);//"StylesheetHandler.processInclude error", ioe);
+ }
+ finally
+ {
+ if(null != m_resolver)
+ {
+
m_processor.getXMLProcessorLiaison().setEntityResolver(m_resolver);
+ m_resolver = null;
+ }
}
m_stylesheet.m_includeStack.pop();
1.66 +30 -4 xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java
Index: XSLTEngineImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- XSLTEngineImpl.java 2000/08/08 01:33:33 1.65
+++ XSLTEngineImpl.java 2000/08/11 05:36:15 1.66
@@ -830,6 +830,31 @@
}
else
{
+ /* I don't think we need or want this code? -sb
+ XMLParserLiaison liaison = getXMLProcessorLiaison();
+ EntityResolver resolver = liaison.getEntityResolver();
+ String sysID = inputSource.getSystemId();
+ if((null != resolver) && (null != sysID))
+ {
+ XSLTInputSource newInputSource = resolver.resolveEntity(null, sysID);
+ if(null != newInputSource)
+ {
+ // The code below has some dangers if the entity resolver
+ // meant to have these fields nulled.
+ if(null != newInputSource.getByteStream())
+ newInputSource.setByteStream(inputSource.getByteStream());
+ if(null != newInputSource.getCharacterStream())
+
newInputSource.setCharacterStream(inputSource.getCharacterStream());
+ if(null != newInputSource.getEncoding())
+ newInputSource.setEncoding(inputSource.getEncoding());
+ if(null != newInputSource.getPublicId())
+ newInputSource.setPublicId(inputSource.getPublicId());
+ inputSource = newInputSource;
+ }
+ }
+ */
+
+
// In case we have a fragment identifier, go ahead and
// try and parse the XML here.
try
@@ -880,12 +905,14 @@
}
Document doc;
- XSLTInputSource inputSource = new XSLTInputSource(url.toString());
+
if(null != docHandler)
{
m_parserLiaison.setDocumentHandler(docHandler);
}
- m_parserLiaison.parse(inputSource);
+
+ // Attribution to: Norman Walsh <[EMAIL PROTECTED]>
+ m_parserLiaison.parse(url.toString());
if(null == docHandler)
{
doc = m_parserLiaison.getDocument();
@@ -1166,9 +1193,8 @@
URL xslURL = getURLFromString(xslURLString, xmlBaseIdent);
- XSLTInputSource inputSource = new XSLTInputSource(xslURL.toString());
m_parserLiaison.setDocumentHandler(stylesheetProcessor);
- m_parserLiaison.parse(inputSource);
+ m_parserLiaison.parse(xslURL.toString());
displayDuration("Parsing and init of "+xslURLString, xslURLString);
}