morten 01/10/25 03:23:32
Modified: java/src/org/apache/xalan/xsltc/compiler ApplyImports.java
DocumentCall.java Stylesheet.java
SyntaxTreeNode.java
java/src/org/apache/xalan/xsltc/dom LoadDocument.java
Log:
Fixed the document() function so that it will load documents relative to
either the currently loaded document, or if that fails, relative to the
location of the original stylesheet.
PR: n/a
Obtained from: n/a
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.7 +6 -12
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyImports.java
Index: ApplyImports.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ApplyImports.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ApplyImports.java 2001/10/23 19:28:07 1.6
+++ ApplyImports.java 2001/10/25 10:23:32 1.7
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: ApplyImports.java,v 1.6 2001/10/23 19:28:07 morten Exp $
+ * @(#)$Id: ApplyImports.java,v 1.7 2001/10/25 10:23:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -103,15 +103,17 @@
* Parse the attributes and contents of an <xsl:apply-imports/> element.
*/
public void parseContents(Parser parser) {
- // Indi
+ // Indicate to the top-level stylesheet that all templates must be
+ // compiled into separate methods.
Stylesheet stylesheet = getStylesheet();
stylesheet.compileTemplatesAsMethods();
+ // Get the mode we are currently in (might not be any)
Template template = getTemplate();
_modeName = template.getModeName();
_precedence = template.getImportPrecedence();
- // instantiate Mode if needed, cache (apply temp) function name
+ // Get the method name for <xsl:apply-imports/> in this mode
stylesheet = parser.getTopLevelStylesheet();
_functionName = stylesheet.getMode(_modeName).functionName(_precedence);
@@ -139,15 +141,7 @@
// Push the arguments that are passed to applyTemplates()
il.append(classGen.loadTranslet());
il.append(methodGen.loadDOM());
-
- /*
- il.append(methodGen.loadIterator());
- // Make a clone of the current iterator (this also resets)
- final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR,
- "cloneIterator",
- "()"+NODE_ITERATOR_SIG);
- il.append(new INVOKEINTERFACE(clone, 1));
- */
+ // Wrap the current node inside an iterator
int init = cpg.addMethodref(SINGLETON_ITERATOR,
"<init>", "("+NODE_SIG+")V");
il.append(new NEW(cpg.addClass(SINGLETON_ITERATOR)));
1.9 +4 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DocumentCall.java
Index: DocumentCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DocumentCall.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DocumentCall.java 2001/08/27 09:07:19 1.8
+++ DocumentCall.java 2001/10/25 10:23:32 1.9
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DocumentCall.java,v 1.8 2001/08/27 09:07:19 morten Exp $
+ * @(#)$Id: DocumentCall.java,v 1.9 2001/10/25 10:23:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -145,7 +145,7 @@
DOM_FIELD,
DOM_INTF_SIG);
final String docParamList =
- "("+OBJECT_SIG+STRING_SIG+TRANSLET_SIG+DOM_INTF_SIG+")"+
+ "("+OBJECT_SIG+STRING_SIG+STRING_SIG+TRANSLET_SIG+DOM_INTF_SIG+")"+
NODE_ITERATOR_SIG;
final int docIdx = cpg.addMethodref(LOAD_DOCUMENT_CLASS,
"document", docParamList);
@@ -172,6 +172,7 @@
il.append(methodGen.loadContextNode());
}
il.append(new INVOKEINTERFACE(uriIdx, 2));
+ il.append(new PUSH(cpg, getStylesheet().getSystemId()));
// Feck the rest of the parameters on the stack
il.append(classGen.loadTranslet());
@@ -179,4 +180,5 @@
il.append(new GETFIELD(domField));
il.append(new INVOKESTATIC(docIdx));
}
+
}
1.24 +2 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java
Index: Stylesheet.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Stylesheet.java 2001/10/23 19:28:07 1.23
+++ Stylesheet.java 2001/10/25 10:23:32 1.24
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Stylesheet.java,v 1.23 2001/10/23 19:28:07 morten Exp $
+ * @(#)$Id: Stylesheet.java,v 1.24 2001/10/25 10:23:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -173,7 +173,7 @@
_importedFrom.setImportPrecedence(nextPrecedence);
}
}
- // Set import precedence for the stylesheet that imported this one
+ // Set import precedence for the stylesheet that included this one
else if (_includedFrom != null) {
if (_includedFrom.getImportPrecedence() != precedence)
_includedFrom.setImportPrecedence(precedence);
1.14 +4 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
Index: SyntaxTreeNode.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- SyntaxTreeNode.java 2001/10/15 09:13:22 1.13
+++ SyntaxTreeNode.java 2001/10/25 10:23:32 1.14
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: SyntaxTreeNode.java,v 1.13 2001/10/15 09:13:22 morten Exp $
+ * @(#)$Id: SyntaxTreeNode.java,v 1.14 2001/10/25 10:23:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -233,7 +233,9 @@
}
public int getImportPrecedence() {
- return getStylesheet().getImportPrecedence();
+ Stylesheet stylesheet = getStylesheet();
+ if (stylesheet == null) return -666;
+ return stylesheet.getImportPrecedence();
}
protected Template getTemplate() {
1.9 +42 -15
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- LoadDocument.java 2001/10/19 08:58:37 1.8
+++ LoadDocument.java 2001/10/25 10:23:32 1.9
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: LoadDocument.java,v 1.8 2001/10/19 08:58:37 morten Exp $
+ * @(#)$Id: LoadDocument.java,v 1.9 2001/10/25 10:23:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -178,45 +178,72 @@
* iterator containing the requested nodes. Builds a union-iterator if
* several documents are requested.
*/
- public static NodeIterator document(Object arg, String contextURI,
+ public static NodeIterator document(Object arg,String xmlURI,String
xslURI,
AbstractTranslet translet, DOM dom)
throws TransletException {
try {
- String baseURI = "";
+ // Get the base of the current DOM's URI
+ if (xmlURI != null) {
+ final int sep = xmlURI.lastIndexOf('/') + 1;
+ xmlURI = xmlURI.substring(0, sep); // could be empty string
+ }
+ else {
+ xmlURI = "";
+ }
- // Get the base of the conext URI (if any)
- if (contextURI != null) {
- final int sep = contextURI.lastIndexOf('/') + 1;
- baseURI = contextURI.substring(0, sep); // could be empty string
+ // Get the base of the current stylesheet's URI
+ if (xslURI != null) {
+ final int sep = xslURI.lastIndexOf('/') + 1;
+ xslURI = xslURI.substring(0, sep); // could be empty string
}
+ else {
+ xslURI = "";
+ }
// If the argument is just a single string (an URI) we just return
// the nodes from the one document this URI points to.
if (arg instanceof String) {
- return document((String)arg, baseURI, translet, dom);
+ // First try to load doc relative to current DOM
+ try {
+ return document((String)arg, xmlURI, translet, dom);
+ }
+ // Then try to load doc relative to original stylesheet
+ catch (java.io.FileNotFoundException e) {
+ return document((String)arg, xslURI, translet, dom);
+ }
}
// Otherwise we must create a union iterator, add the nodes from
// all the DOMs to this iterator, and return the union in the end.
- else {
+ else if (arg instanceof NodeIterator) {
UnionIterator union = new UnionIterator(dom);
NodeIterator iterator = (NodeIterator)arg;
int node;
while ((node = iterator.next()) != DOM.NULL) {
String uri = dom.getNodeValue(node);
- if ((baseURI == null) || baseURI.equals("")) {
- String base = dom.getDocumentURI(node);
- final int sep = base.lastIndexOf('/') + 1;
- baseURI = base.substring(0, sep);
+ // Get the URI from this node if no xml URI base is set
+ if ((xmlURI == null) || xmlURI.equals("")) {
+ xmlURI = dom.getDocumentURI(node);
+ final int sep = xmlURI.lastIndexOf('/') + 1;
+ xmlURI = xmlURI.substring(0, sep);
+ }
+ // First try to load doc relative to current DOM
+ try {
+ union.addIterator(document(uri, xmlURI, translet, dom));
}
- union.addIterator(document(uri, baseURI, translet, dom));
+ // Then try to load doc relative to original stylesheet
+ catch (java.io.FileNotFoundException e) {
+ union.addIterator(document(uri, xslURI, translet, dom));
+ }
}
return(union);
}
+ else {
+ throw new IllegalArgumentException("Illegal argument to
document() function");
+ }
}
catch (Exception e) {
- e.printStackTrace();
throw new TransletException(e);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]