mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-07 12:15:51 +00:00
Fix for bug 73936 (xsl:include/xsl:import/document() doesn't work). r=Pike/sicking, sr=jst.
This commit is contained in:
parent
e6db0e7b24
commit
f5041e9ea0
@ -36,7 +36,6 @@
|
|||||||
#include "TxString.h"
|
#include "TxString.h"
|
||||||
#include "primitives.h"
|
#include "primitives.h"
|
||||||
#include "ExprResult.h"
|
#include "ExprResult.h"
|
||||||
#include "baseutils.h"
|
|
||||||
#include "Expr.h"
|
#include "Expr.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
* The contents of this file are subject to the Mozilla Public
|
* The contents of this file are subject to the Mozilla Public
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
* License Version 1.1 (the "License"); you may not use this file
|
||||||
* except in compliance with the License. You may obtain a copy of
|
* except in compliance with the License. You may obtain a copy of
|
||||||
@ -30,29 +31,26 @@
|
|||||||
* in method DocumentFunctionCall::retrieveDocument
|
* in method DocumentFunctionCall::retrieveDocument
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* DocumentFunctionCall
|
* DocumentFunctionCall
|
||||||
* A representation of the XSLT additional function: document()
|
* A representation of the XSLT additional function: document()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "XSLTFunctions.h"
|
#include "XSLTFunctions.h"
|
||||||
#include "XMLParser.h"
|
#include "XMLParser.h"
|
||||||
#include "XMLDOMUtils.h"
|
#include "XMLDOMUtils.h"
|
||||||
#include "URIUtils.h"
|
#include "URIUtils.h"
|
||||||
#include "Names.h"
|
#include "Names.h"
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Creates a new DocumentFunctionCall.
|
* Creates a new DocumentFunctionCall.
|
||||||
**/
|
*/
|
||||||
DocumentFunctionCall::DocumentFunctionCall(ProcessorState* ps, Document* xslDocument) : FunctionCall(DOCUMENT_FN)
|
DocumentFunctionCall::DocumentFunctionCall(ProcessorState* aPs) : FunctionCall(DOCUMENT_FN)
|
||||||
{
|
{
|
||||||
this->processorState = ps;
|
mProcessorState = aPs;
|
||||||
this->xslDocument = xslDocument; //this is just untill we can get the actuall xsl tag
|
}
|
||||||
} //-- DocumentFunctionCall
|
|
||||||
|
|
||||||
|
/*
|
||||||
/**
|
|
||||||
* Evaluates this Expr based on the given context node and processor state
|
* Evaluates this Expr based on the given context node and processor state
|
||||||
* NOTE: the implementation is incomplete since it does not make use of the
|
* NOTE: the implementation is incomplete since it does not make use of the
|
||||||
* second argument (base URI)
|
* second argument (base URI)
|
||||||
@ -60,12 +58,13 @@ DocumentFunctionCall::DocumentFunctionCall(ProcessorState* ps, Document* xslDocu
|
|||||||
* @param ps the ContextState containing the stack information needed
|
* @param ps the ContextState containing the stack information needed
|
||||||
* for evaluation
|
* for evaluation
|
||||||
* @return the result of the evaluation
|
* @return the result of the evaluation
|
||||||
**/
|
*/
|
||||||
ExprResult* DocumentFunctionCall::evaluate(Node* context, ContextState* cs) {
|
ExprResult* DocumentFunctionCall::evaluate(Node* context, ContextState* cs)
|
||||||
|
{
|
||||||
NodeSet* nodeSet = new NodeSet();
|
NodeSet* nodeSet = new NodeSet();
|
||||||
|
|
||||||
//-- document( object, node-set? )
|
// document(object, node-set?)
|
||||||
if ( requireParams(1, 2, cs) ) {
|
if (requireParams(1, 2, cs)) {
|
||||||
ListIterator* iter = params.iterator();
|
ListIterator* iter = params.iterator();
|
||||||
Expr* param1 = (Expr*) iter->next();
|
Expr* param1 = (Expr*) iter->next();
|
||||||
ExprResult* exprResult1 = param1->evaluate(context, cs);
|
ExprResult* exprResult1 = param1->evaluate(context, cs);
|
||||||
@ -73,11 +72,11 @@ ExprResult* DocumentFunctionCall::evaluate(Node* context, ContextState* cs) {
|
|||||||
MBool baseURISet = MB_FALSE;
|
MBool baseURISet = MB_FALSE;
|
||||||
|
|
||||||
if (iter->hasNext()) {
|
if (iter->hasNext()) {
|
||||||
// we have 2 arguments, get baseURI from the first node
|
// We have 2 arguments, get baseURI from the first node
|
||||||
// in the resulting nodeset
|
// in the resulting nodeset
|
||||||
Expr* param2 = (Expr*) iter->next();
|
Expr* param2 = (Expr*) iter->next();
|
||||||
ExprResult* exprResult2 = param2->evaluate(context, cs);
|
ExprResult* exprResult2 = param2->evaluate(context, cs);
|
||||||
if ( exprResult2->getResultType() != ExprResult::NODESET ) {
|
if (exprResult2->getResultType() != ExprResult::NODESET) {
|
||||||
String err("node-set expected as second argument to document(): ");
|
String err("node-set expected as second argument to document(): ");
|
||||||
toString(err);
|
toString(err);
|
||||||
cs->recieveError(err);
|
cs->recieveError(err);
|
||||||
@ -87,21 +86,22 @@ ExprResult* DocumentFunctionCall::evaluate(Node* context, ContextState* cs) {
|
|||||||
|
|
||||||
// Make this true, even if nodeSet2 is empty. For relative URLs,
|
// Make this true, even if nodeSet2 is empty. For relative URLs,
|
||||||
// we'll fail to load the document with an empty base URI, and for
|
// we'll fail to load the document with an empty base URI, and for
|
||||||
// absolute URLs, the base URI doesn't matter.
|
// absolute URLs, the base URI doesn't matter
|
||||||
baseURISet = MB_TRUE;
|
baseURISet = MB_TRUE;
|
||||||
|
|
||||||
NodeSet* nodeSet2 = (NodeSet*) exprResult2;
|
NodeSet* nodeSet2 = (NodeSet*) exprResult2;
|
||||||
if (!nodeSet2->isEmpty()) {
|
if (!nodeSet2->isEmpty()) {
|
||||||
processorState->sortByDocumentOrder(nodeSet2);
|
mProcessorState->sortByDocumentOrder(nodeSet2);
|
||||||
baseURI = nodeSet2->get(0)->getBaseURI();
|
baseURI = nodeSet2->get(0)->getBaseURI();
|
||||||
}
|
}
|
||||||
delete exprResult2;
|
delete exprResult2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( exprResult1->getResultType() == ExprResult::NODESET ) {
|
if (exprResult1->getResultType() == ExprResult::NODESET) {
|
||||||
// The first argument is a NodeSet, iterate on its nodes
|
// The first argument is a NodeSet, iterate on its nodes
|
||||||
NodeSet* nodeSet1 = (NodeSet*) exprResult1;
|
NodeSet* nodeSet1 = (NodeSet*) exprResult1;
|
||||||
for (int i=0; i<nodeSet1->size(); i++) {
|
int i;
|
||||||
|
for (i = 0; i < nodeSet1->size(); i++) {
|
||||||
Node* node = nodeSet1->get(i);
|
Node* node = nodeSet1->get(i);
|
||||||
String uriStr;
|
String uriStr;
|
||||||
XMLDOMUtils::getNodeValue(node, &uriStr);
|
XMLDOMUtils::getNodeValue(node, &uriStr);
|
||||||
@ -110,29 +110,29 @@ ExprResult* DocumentFunctionCall::evaluate(Node* context, ContextState* cs) {
|
|||||||
// the baseUri of node itself
|
// the baseUri of node itself
|
||||||
retrieveDocument(uriStr, node->getBaseURI(), *nodeSet, cs);
|
retrieveDocument(uriStr, node->getBaseURI(), *nodeSet, cs);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
retrieveDocument(uriStr, baseURI, *nodeSet, cs);
|
retrieveDocument(uriStr, baseURI, *nodeSet, cs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
// The first argument is not a NodeSet
|
// The first argument is not a NodeSet
|
||||||
String uriStr;
|
String uriStr;
|
||||||
evaluateToString(param1, context, cs, uriStr);
|
evaluateToString(param1, context, cs, uriStr);
|
||||||
if (!baseURISet) {
|
if (!baseURISet) {
|
||||||
// XXX TODO: find the current xsl tag and get its base URI
|
Node* xsltElement = mProcessorState->peekAction();
|
||||||
// until then we use the xslDocument
|
retrieveDocument(uriStr, xsltElement->getBaseURI(), *nodeSet, cs);
|
||||||
retrieveDocument(uriStr, xslDocument->getBaseURI(), *nodeSet, cs);
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
retrieveDocument(uriStr, baseURI, *nodeSet, cs);
|
retrieveDocument(uriStr, baseURI, *nodeSet, cs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delete exprResult1;
|
delete exprResult1;
|
||||||
delete iter;
|
delete iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeSet;
|
return nodeSet;
|
||||||
} //-- evaluate
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,20 +145,33 @@ ExprResult* DocumentFunctionCall::evaluate(Node* context, ContextState* cs) {
|
|||||||
* @param resultNodeSet the NodeSet to append the document to
|
* @param resultNodeSet the NodeSet to append the document to
|
||||||
* @param cs the ContextState, used for reporting errors
|
* @param cs the ContextState, used for reporting errors
|
||||||
*/
|
*/
|
||||||
void DocumentFunctionCall::retrieveDocument(const String& uri, const String& baseUri, NodeSet& resultNodeSet, ContextState* cs)
|
void DocumentFunctionCall::retrieveDocument(const String& uri,
|
||||||
|
const String& baseUri,
|
||||||
|
NodeSet& resultNodeSet,
|
||||||
|
ContextState* cs)
|
||||||
{
|
{
|
||||||
String absUrl, frag;
|
String absUrl, frag;
|
||||||
|
Document* xmlDoc;
|
||||||
|
|
||||||
URIUtils::resolveHref(uri, baseUri, absUrl);
|
URIUtils::resolveHref(uri, baseUri, absUrl);
|
||||||
URIUtils::getFragmentIdentifier(absUrl, frag);
|
URIUtils::getFragmentIdentifier(absUrl, frag);
|
||||||
|
|
||||||
// try to get already loaded document
|
// try to get already loaded document
|
||||||
Document* xmlDoc = processorState->getLoadedDocument(absUrl);
|
xmlDoc = mProcessorState->getLoadedDocument(absUrl);
|
||||||
|
|
||||||
if(!xmlDoc) {
|
if (!xmlDoc) {
|
||||||
// open URI
|
// open URI
|
||||||
String errMsg;
|
String errMsg;
|
||||||
XMLParser xmlParser;
|
XMLParser xmlParser;
|
||||||
xmlDoc = xmlParser.getDocumentFromURI(uri, baseUri, errMsg);
|
Node* xsltElement;
|
||||||
|
|
||||||
|
xsltElement = mProcessorState->peekAction();
|
||||||
|
if (!xsltElement) {
|
||||||
|
// no xslt element
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlDoc = xmlParser.getDocumentFromURI(absUrl, "", xsltElement->getOwnerDocument(), errMsg);
|
||||||
if (!xmlDoc) {
|
if (!xmlDoc) {
|
||||||
String err("error in document() function: ");
|
String err("error in document() function: ");
|
||||||
err.append(errMsg);
|
err.append(errMsg);
|
||||||
@ -166,18 +179,17 @@ void DocumentFunctionCall::retrieveDocument(const String& uri, const String& bas
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// add to ProcessorState list of documents
|
// add to ProcessorState list of documents
|
||||||
processorState->addLoadedDocument(xmlDoc, absUrl);
|
mProcessorState->addLoadedDocument(xmlDoc, absUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// append the document or the fragment to resultNodeSet
|
||||||
// append the to resultNodeSet
|
if (frag.length() > 0) {
|
||||||
if(frag.length()) {
|
|
||||||
Node* node = xmlDoc->getElementById(frag);
|
Node* node = xmlDoc->getElementById(frag);
|
||||||
if(node)
|
if (node) {
|
||||||
resultNodeSet.add(node);
|
resultNodeSet.add(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
resultNodeSet.add(xmlDoc);
|
resultNodeSet.add(xmlDoc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Creates a new document() function call
|
* Creates a new document() function call
|
||||||
**/
|
**/
|
||||||
DocumentFunctionCall(ProcessorState* ps, Document* xslDocument);
|
DocumentFunctionCall(ProcessorState* aPs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluates this Expr based on the given context node and processor state
|
* Evaluates this Expr based on the given context node and processor state
|
||||||
@ -63,8 +63,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void retrieveDocument(const String& uri,const String& baseUri, NodeSet &resultNodeSet, ContextState* cs);
|
void retrieveDocument(const String& uri,const String& baseUri, NodeSet &resultNodeSet, ContextState* cs);
|
||||||
Document* xslDocument;
|
ProcessorState* mProcessorState;
|
||||||
ProcessorState* processorState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user