Mozilla/mozilla/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp
peterv%netscape.com 77250f9370 Rename Transformiix string API to be in synch with Mozilla's. Part of bug 74786 (String cleanup). r=sicking, rs=jst.
git-svn-id: svn://10.0.0.236/trunk@135523 18797224-902f-48f8-a5cc-f745e15eee43
2002-12-20 15:18:35 +00:00

73 lines
2.4 KiB
C++

#include "txIXPathContext.h"
#include "txAtoms.h"
#include "XMLUtils.h"
#include "XSLTFunctions.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(Node* aQNameResolveNode)
: mQNameResolveNode(aQNameResolveNode)
{
}
/**
* 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 = NULL;
if (requireParams(1, 1, aContext)) {
txListIterator iter(&params);
Expr* param = (Expr*)iter.next();
ExprResult* exprResult = param->evaluate(aContext);
if (exprResult->getResultType() == ExprResult::STRING) {
String property;
exprResult->stringValue(property);
txExpandedName qname;
nsresult rv = qname.init(property, mQNameResolveNode, 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 {
String err(NS_LITERAL_STRING("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(txAtom** aAtom)
{
*aAtom = txXSLTAtoms::systemProperty;
TX_ADDREF_ATOM(*aAtom);
return NS_OK;
}