sicking%bigfoot.com 64ce860e2a Compiled XSLT stylesheets. Improves speed, implements forwards-compatible-parsing and handling of unknown extension-elements. Also fixes some random edgecasebugs such as recursive merged named-attribute-sets and empty strings in copy-of.
Patch mainly by sicking, but large parts also by Pike and peterv.

Tracker is bug 185797. r=Pike/sicking rs=peterv.


git-svn-id: svn://10.0.0.236/trunk@140310 18797224-902f-48f8-a5cc-f745e15eee43
2003-03-26 01:10:14 +00:00

143 lines
4.8 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* Portions created by Olivier Gerardin are Copyright (C) 2000,
* Olivier Gerardin. All rights reserved.
*
* Portions created by Keith Visco are Copyright (C) 2000, Keith Visco.
* All rights reserved.
*
* Contributor(s):
* Olivier Gerardin, ogerardin@vo.lu
* -- original author.
*
* Keith Visco, kvisco@ziplink.net
* -- patched compilation error on due to improper usage of the
* 3rd argument (error message) for URIUtils::getInputStream,
* in method DocumentFunctionCall::retrieveDocument
*/
/*
* DocumentFunctionCall
* A representation of the XSLT additional function: document()
*/
#include "txAtoms.h"
#include "txIXPathContext.h"
#include "XMLDOMUtils.h"
#include "XSLTFunctions.h"
#include "txExecutionState.h"
/*
* Creates a new DocumentFunctionCall.
*/
DocumentFunctionCall::DocumentFunctionCall(const nsAString& aBaseURI)
: mBaseURI(aBaseURI)
{
}
/*
* 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
* second argument (base URI)
* @param context the context node for evaluation of this Expr
* @return the result of the evaluation
*/
ExprResult* DocumentFunctionCall::evaluate(txIEvalContext* aContext)
{
txExecutionState* es =
NS_STATIC_CAST(txExecutionState*, aContext->getPrivateContext());
NodeSet* nodeSet = new NodeSet();
NS_ENSURE_TRUE(nodeSet, nsnull);
// document(object, node-set?)
if (requireParams(1, 2, aContext)) {
txListIterator iter(&params);
Expr* param1 = (Expr*)iter.next();
ExprResult* exprResult1 = param1->evaluate(aContext);
nsAutoString baseURI;
MBool baseURISet = MB_FALSE;
if (iter.hasNext()) {
// We have 2 arguments, get baseURI from the first node
// in the resulting nodeset
Expr* param2 = (Expr*)iter.next();
ExprResult* exprResult2 = param2->evaluate(aContext);
if (exprResult2->getResultType() != ExprResult::NODESET) {
nsAutoString err(NS_LITERAL_STRING("node-set expected as second argument to document(): "));
toString(err);
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
delete exprResult1;
delete exprResult2;
return nodeSet;
}
// 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
// absolute URLs, the base URI doesn't matter
baseURISet = MB_TRUE;
NodeSet* nodeSet2 = (NodeSet*) exprResult2;
if (!nodeSet2->isEmpty()) {
nodeSet2->get(0)->getBaseURI(baseURI);
}
delete exprResult2;
}
if (exprResult1->getResultType() == ExprResult::NODESET) {
// The first argument is a NodeSet, iterate on its nodes
NodeSet* nodeSet1 = (NodeSet*) exprResult1;
int i;
for (i = 0; i < nodeSet1->size(); i++) {
Node* node = nodeSet1->get(i);
nsAutoString uriStr;
XMLDOMUtils::getNodeValue(node, uriStr);
if (!baseURISet) {
// if the second argument wasn't specified, use
// the baseUri of node itself
node->getBaseURI(baseURI);
}
Node* loadNode = es->retrieveDocument(uriStr, baseURI);
if (loadNode) {
nodeSet->add(loadNode);
}
}
}
else {
// The first argument is not a NodeSet
nsAutoString uriStr;
exprResult1->stringValue(uriStr);
Node* loadNode =
es->retrieveDocument(uriStr, baseURISet ? baseURI : mBaseURI);
if (loadNode) {
nodeSet->add(loadNode);
}
}
delete exprResult1;
}
return nodeSet;
}
nsresult DocumentFunctionCall::getNameAtom(nsIAtom** aAtom)
{
*aAtom = txXSLTAtoms::document;
NS_ADDREF(*aAtom);
return NS_OK;
}