Mozilla/mozilla/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp
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

74 lines
2.4 KiB
C++

#include "txIXPathContext.h"
#include "txAtoms.h"
#include "XMLUtils.h"
#include "XSLTFunctions.h"
#include "ExprResult.h"
/*
Implementation of XSLT 1.0 extension function: system-property
*/
/**
* Creates a new system-property function call
* aNode is the Element in the stylesheet containing the
* Expr and is used for namespaceID resolution
**/
SystemPropertyFunctionCall::SystemPropertyFunctionCall(txNamespaceMap* aMappings)
: mMappings(aMappings)
{
}
/**
* Evaluates this Expr based on the given context node and processor state
* @param context the context node for evaluation of this Expr
* @param cs the ContextState containing the stack information needed
* for evaluation
* @return the result of the evaluation
* @see FunctionCall.h
**/
ExprResult* SystemPropertyFunctionCall::evaluate(txIEvalContext* aContext)
{
ExprResult* result = nsnull;
if (requireParams(1, 1, aContext)) {
txListIterator iter(&params);
Expr* param = (Expr*)iter.next();
ExprResult* exprResult = param->evaluate(aContext);
if (exprResult->getResultType() == ExprResult::STRING) {
nsAutoString property;
exprResult->stringValue(property);
txExpandedName qname;
nsresult rv = qname.init(property, mMappings, MB_TRUE);
if (NS_SUCCEEDED(rv) &&
qname.mNamespaceID == kNameSpaceID_XSLT) {
if (qname.mLocalName == txXSLTAtoms::version) {
result = new NumberResult(1.0);
}
else if (qname.mLocalName == txXSLTAtoms::vendor) {
result = new StringResult(NS_LITERAL_STRING("Transformiix"));
}
else if (qname.mLocalName == txXSLTAtoms::vendorUrl) {
result = new StringResult(NS_LITERAL_STRING("http://www.mozilla.org/projects/xslt/"));
}
}
}
else {
NS_NAMED_LITERAL_STRING(err, "Invalid argument passed to system-property(), expecting String");
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
result = new StringResult(err);
}
}
if (!result) {
result = new StringResult();
}
return result;
}
nsresult SystemPropertyFunctionCall::getNameAtom(nsIAtom** aAtom)
{
*aAtom = txXSLTAtoms::systemProperty;
NS_ADDREF(*aAtom);
return NS_OK;
}