dbertoni 01/09/24 09:54:42
Modified: c/src/XSLT FunctionDocument.cpp
Log:
Make sure to use the proper resolver for relative URIs. Fixes reluri11.
Revision Changes Path
1.27 +109 -36 xml-xalan/c/src/XSLT/FunctionDocument.cpp
Index: FunctionDocument.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XSLT/FunctionDocument.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- FunctionDocument.cpp 2001/09/20 18:05:14 1.26
+++ FunctionDocument.cpp 2001/09/24 16:54:42 1.27
@@ -87,12 +87,16 @@
}
+typedef XPathExecutionContext::BorrowReturnMutableNodeRefList
BorrowReturnMutableNodeRefList;
-static XalanDocument*
+
+
+static void
getDoc(
- XPathExecutionContext& executionContext,
- const XalanDOMString& uri,
- const XalanDOMString& base)
+ XPathExecutionContext&
executionContext,
+ const XalanDOMString& uri,
+ const XalanDOMString& base,
+ BorrowReturnMutableNodeRefList& mnl)
{
XalanDOMString localURI(uri);
@@ -110,11 +114,9 @@
try
{
newDoc = executionContext.parseXML(localURI, base);
-
}
catch(...)
{
- newDoc = 0;
}
if(newDoc == 0)
@@ -133,22 +135,72 @@
executionContext.warn(theMessage);
}
}
+
+ if(newDoc != 0)
+ {
+ mnl->addNodeInDocOrder(newDoc, executionContext);
+ }
+}
- return newDoc;
+
+
+inline void
+getDoc(
+ XPathExecutionContext&
executionContext,
+ const XalanDOMString& uri,
+ BorrowReturnMutableNodeRefList& mnl)
+{
+ getDoc(executionContext, uri, XalanDOMString(), mnl);
}
+inline void
+getDoc(
+ XPathExecutionContext&
executionContext,
+ const XalanDOMString& uri,
+ const XalanNode*
resolver,
+ BorrowReturnMutableNodeRefList& mnl)
+{
+ assert(resolver != 0);
+ const XalanDocument* const ownerDocument =
XalanNode::DOCUMENT_NODE == resolver->getNodeType() ?
+#if defined(XALAN_OLD_STYLE_CASTS)
+ (const XalanDocument*)resolver :
+#else
+ static_cast<const XalanDocument*>(resolver) :
+#endif
+ resolver->getOwnerDocument();
+
+ getDoc(executionContext, uri,
executionContext.findURIFromDoc(ownerDocument), mnl);
+}
+
+
+
XObjectPtr
FunctionDocument::execute(
XPathExecutionContext& executionContext,
XalanNode* context,
const XObjectPtr arg1,
- const Locator* locator) const
+ const Locator* /* locator */) const
{
assert(arg1.null() == false);
+ if (arg1->getType() == XObject::eTypeNodeSet)
+ {
+ return doExecute(executionContext, context, arg1, 0, 1);
+ }
+ else
+ {
+ XalanDOMString base;
+
+ assert(executionContext.getPrefixResolver() != 0);
+
+ base = executionContext.getPrefixResolver()->getURI();
+
+ return doExecute(executionContext, context, arg1, &base, 1);
+ }
+#if 0
if (context == 0)
{
executionContext.error(
@@ -166,8 +218,9 @@
base = executionContext.getPrefixResolver()->getURI();
- return doExecute(executionContext, context, arg1, &base, 1);
+ return doExecute(executionContext, context, arg1, 0, 1);
}
+#endif
}
@@ -238,7 +291,7 @@
XObjectPtr
FunctionDocument::doExecute(
XPathExecutionContext& executionContext,
- XalanNode*
context,
+ XalanNode* /*
context */,
const XObjectPtr arg,
XalanDOMString* base,
int
argCount) const
@@ -250,14 +303,6 @@
const XObject::eObjectType theType = arg->getType();
- XalanDocument* const docContext = XalanNode::DOCUMENT_NODE ==
context->getNodeType() ?
-#if defined(XALAN_OLD_STYLE_CASTS)
- (XalanDocument*)context :
-#else
- static_cast<XalanDocument*>(context) :
-#endif
- context->getOwnerDocument();
-
const unsigned int nRefs = XObject::eTypeNodeSet ==
theType ?
arg->nodeset().getLength()
: 1;
@@ -266,26 +311,37 @@
{
assert(XObject::eTypeNodeSet != theType ||
arg->nodeset().item(i)
!= 0);
+
+ const XalanNode* resolver = 0;
+
+ XalanDOMString ref;
+
+ if (theType != XObject::eTypeNodeSet)
+ {
+ ref = arg->str();
+ }
+ else
+ {
+ resolver = arg->nodeset().item(i);
+ assert(resolver != 0);
- XalanDOMString ref = XObject::eTypeNodeSet == theType ?
-
DOMServices::getNodeData(*arg->nodeset().item(i)) :
-
arg->str();
+ ref = DOMServices::getNodeData(*resolver);
+ }
// This is the case where the function was called with
// an empty string, which refers to the stylesheet itself.
if (nRefs == 1 && isEmpty(ref) == true && argCount == 1)
{
- ref = *base;
+ if (base != 0)
+ {
+ clear(*base);
+ }
+
+ ref = executionContext.getPrefixResolver()->getURI();
}
if(!isEmpty(ref))
{
-
- if(docContext == 0)
- {
- executionContext.error("The context node does
not have an owner document!");
- }
-
// From http://www.ics.uci.edu/pub/ietf/uri/rfc1630.txt
// A partial form can be distinguished from an absolute
form in that the
// latter must have a colon and that colon must occur
before any slash
@@ -306,17 +362,34 @@
}
#endif
- if(indexOfColon < theLength && indexOfSlash < theLength
&& indexOfColon < indexOfSlash)
+ if(indexOfColon < theLength &&
+ indexOfSlash < theLength &&
+ indexOfColon < indexOfSlash)
{
- // The url (or filename, for that matter) is
absolute.
- clear(*base);
+ // The ref is absolute...
+ getDoc(executionContext, ref, mnl);
}
-
- XalanDocument* const newDoc =
getDoc(executionContext, ref, *base);
-
- if(newDoc != 0)
+ else
{
- mnl->addNodeInDocOrder(newDoc,
executionContext);
+ // The ref is relative. If there was a base URI
+ // provided, use that...
+ if (base != 0)
+ {
+ getDoc(executionContext, ref, *base,
mnl);
+ }
+ else
+ {
+ // If there's no resolver, then try
using the
+ // relative ref...
+ if (resolver == 0)
+ {
+ getDoc(executionContext, ref,
mnl);
+ }
+ else
+ {
+ getDoc(executionContext, ref,
resolver, mnl);
+ }
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]