зеркало из https://github.com/mozilla/gecko-dev.git
Landing TX_BRIDGE_1_1_BRANCH.
Rewrite pretty much all variable and parameter handling. Makes global and local variables be handled differently. Global variables are no longer part of the variables stack, and are lazily evaluated. Fixes bugs 117658, 92929 and some unfiled bugs and fixes remaining parts of bugs 83651 and 96802. Patch by sicking, r=Pike sr=bz. Fix for bug 156464: fix rounding problems in module, allow patterns without any '0's in the integer part and fix problems with grouping for standalone. Patch by sicking, r=Pike sr=bz. Fix for bug 157340 (Probable bugs in extensions/transformiix/source/base/txMozillaString.h). Patch by peterv, r=Pike, sr=bz. Fix for bug 146967 (Clean up Transformiix strings). Patch by peterv, r=sicking, sr=jst. Fix for bug 156464 (Remove static strings from Transformiix). Patch by peterv, r=Pike, sr=jst.
This commit is contained in:
Родитель
e4fef6827b
Коммит
02a354d465
|
@ -82,9 +82,8 @@ istream* URIUtils::getInputStream
|
|||
}
|
||||
else {
|
||||
// Try local files
|
||||
char* fchars = href.toCharArray();
|
||||
inStream = new ifstream(fchars, ios::in);
|
||||
delete [] fchars;
|
||||
inStream = new ifstream(NS_LossyConvertUCS2toASCII(href).get(),
|
||||
ios::in);
|
||||
}
|
||||
delete uri;
|
||||
|
||||
|
@ -142,9 +141,9 @@ void URIUtils::resolveHref(const String& href, const String& base,
|
|||
#ifndef TX_EXE
|
||||
nsCOMPtr<nsIURI> pURL;
|
||||
String resultHref;
|
||||
nsresult result = NS_NewURI(getter_AddRefs(pURL), base.getConstNSString());
|
||||
nsresult result = NS_NewURI(getter_AddRefs(pURL), base);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
NS_MakeAbsoluteURI(resultHref.getNSString(), href.getConstNSString(), pURL);
|
||||
NS_MakeAbsoluteURI(resultHref, href, pURL);
|
||||
dest.append(resultHref);
|
||||
}
|
||||
#else
|
||||
|
@ -176,12 +175,11 @@ void URIUtils::resolveHref(const String& href, const String& base,
|
|||
}
|
||||
else {
|
||||
// Try local files
|
||||
char* xHrefChars = xHref.toCharArray();
|
||||
ifstream inFile(xHrefChars, ios::in);
|
||||
ifstream inFile(NS_LossyConvertUCS2toASCII(xHref).get(),
|
||||
ios::in);
|
||||
if ( inFile ) dest.append(xHref);
|
||||
else dest.append(href);
|
||||
inFile.close();
|
||||
delete [] xHrefChars;
|
||||
}
|
||||
delete uri;
|
||||
delete newUri;
|
||||
|
@ -214,9 +212,9 @@ istream* URIUtils::openStream(ParsedURI* uri) {
|
|||
|
||||
istream* inStream = 0;
|
||||
if ( FILE_PROTOCOL.isEqual(uri->protocol) ) {
|
||||
char* fchars = uri->path.toCharArray();
|
||||
ifstream* inFile = new ifstream(fchars, ios::in);
|
||||
delete [] fchars;
|
||||
ifstream* inFile =
|
||||
new ifstream(NS_LossyConvertUCS2toASCII(uri->path).get(),
|
||||
ios::in);
|
||||
inStream = inFile;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,6 @@ OBJS =../base/ArrayList.$(OBJ_SUFFIX) \
|
|||
../xpath/UnionExpr.$(OBJ_SUFFIX) \
|
||||
../xpath/UnaryExpr.$(OBJ_SUFFIX) \
|
||||
../xpath/VariableRefExpr.$(OBJ_SUFFIX) \
|
||||
../xpath/XPathNames.$(OBJ_SUFFIX) \
|
||||
../xml/XMLUtils.$(OBJ_SUFFIX) \
|
||||
../xml/XMLDOMUtils.$(OBJ_SUFFIX) \
|
||||
../xml/parser/XMLParser.$(OBJ_SUFFIX) \
|
||||
|
@ -109,7 +108,6 @@ OBJS =../base/ArrayList.$(OBJ_SUFFIX) \
|
|||
../xslt/txXMLOutput.$(OBJ_SUFFIX) \
|
||||
../xslt/txXSLTPatterns.$(OBJ_SUFFIX) \
|
||||
../xslt/txPatternParser.$(OBJ_SUFFIX) \
|
||||
../xslt/VariableBinding.$(OBJ_SUFFIX) \
|
||||
../xslt/XSLTProcessor.$(OBJ_SUFFIX) \
|
||||
../xslt/functions/CurrentFunctionCall.$(OBJ_SUFFIX) \
|
||||
../xslt/functions/DocumentFunctionCall.$(OBJ_SUFFIX) \
|
||||
|
|
|
@ -102,18 +102,16 @@ int main(int argc, char** argv) {
|
|||
//-- open XML file
|
||||
istream* xmlInput = &cin;
|
||||
if (xmlFilename && ! xmlFilename->isEqual("-")) {
|
||||
char* chars = xmlFilename->toCharArray();
|
||||
xmlInput = new ifstream(chars, ios::in);
|
||||
delete [] chars;
|
||||
xmlInput = new ifstream(NS_LossyConvertUCS2toASCII(*xmlFilename).get(),
|
||||
ios::in);
|
||||
}
|
||||
|
||||
//-- handle output stream
|
||||
ostream* resultOutput = &cout;
|
||||
ofstream resultFileStream;
|
||||
if ( outFilename && ! outFilename->isEqual("-")) {
|
||||
char* chars = outFilename->toCharArray();
|
||||
resultFileStream.open(chars, ios::out);
|
||||
delete [] chars;
|
||||
resultFileStream.open(NS_LossyConvertUCS2toASCII(*outFilename).get(),
|
||||
ios::out);
|
||||
if ( !resultFileStream ) {
|
||||
cerr << "error opening output file: " << *xmlFilename << endl;
|
||||
return -1;
|
||||
|
@ -133,9 +131,8 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
else {
|
||||
//-- open XSLT file
|
||||
char* chars = xsltFilename->toCharArray();
|
||||
ifstream xsltInput(chars, ios::in);
|
||||
delete [] chars;
|
||||
ifstream xsltInput(NS_LossyConvertUCS2toASCII(*xsltFilename).get(),
|
||||
ios::in);
|
||||
xsltProcessor.process(*xmlInput, *xmlFilename, xsltInput, *xsltFilename, *resultOutput);
|
||||
}
|
||||
resultFileStream.close();
|
||||
|
|
|
@ -69,8 +69,7 @@ CPPSRCS = AdditiveExpr.cpp \
|
|||
txNodeSetContext.cpp \
|
||||
UnionExpr.cpp \
|
||||
UnaryExpr.cpp \
|
||||
VariableRefExpr.cpp \
|
||||
XPathNames.cpp
|
||||
VariableRefExpr.cpp
|
||||
ifndef TX_EXE
|
||||
CPPSRCS += nsXPathEvaluator.cpp \
|
||||
nsXPathException.cpp \
|
||||
|
|
|
@ -96,7 +96,7 @@ nsXPathResult::GetStringValue(nsAString &aStringValue)
|
|||
return NS_ERROR_DOM_TYPE_ERR;
|
||||
|
||||
if (mStringValue)
|
||||
aStringValue.Assign(mStringValue->getConstNSString());
|
||||
aStringValue.Assign(*mStringValue);
|
||||
else
|
||||
SetDOMStringToNull(aStringValue);
|
||||
return NS_OK;
|
||||
|
|
|
@ -37,24 +37,7 @@
|
|||
BooleanFunctionCall::BooleanFunctionCall(BooleanFunctions aType)
|
||||
: mType(aType)
|
||||
{
|
||||
switch (aType) {
|
||||
case TX_BOOLEAN :
|
||||
name = XPathNames::BOOLEAN_FN;
|
||||
break;
|
||||
case TX_LANG:
|
||||
name = XPathNames::LANG_FN;
|
||||
break;
|
||||
case TX_NOT :
|
||||
name = XPathNames::NOT_FN;
|
||||
break;
|
||||
case TX_TRUE :
|
||||
name = XPathNames::TRUE_FN;
|
||||
break;
|
||||
default:
|
||||
name = XPathNames::FALSE_FN;
|
||||
break;
|
||||
}
|
||||
} //-- BooleanFunctionCall
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates this Expr based on the given context node and processor state
|
||||
|
@ -135,3 +118,40 @@ ExprResult* BooleanFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
return new StringResult("error");
|
||||
}
|
||||
|
||||
nsresult BooleanFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
switch (mType) {
|
||||
case TX_BOOLEAN:
|
||||
{
|
||||
*aAtom = txXPathAtoms::boolean;
|
||||
break;
|
||||
}
|
||||
case TX_LANG:
|
||||
{
|
||||
*aAtom = txXPathAtoms::lang;
|
||||
break;
|
||||
}
|
||||
case TX_NOT:
|
||||
{
|
||||
*aAtom = txXPathAtoms::_not;
|
||||
break;
|
||||
}
|
||||
case TX_TRUE:
|
||||
{
|
||||
*aAtom = txXPathAtoms::_true;
|
||||
break;
|
||||
}
|
||||
case TX_FALSE:
|
||||
{
|
||||
*aAtom = txXPathAtoms::_false;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*aAtom = 0;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,11 @@ BooleanResult::BooleanResult(MBool boolean) {
|
|||
* Virtual Methods from ExprResult
|
||||
*/
|
||||
|
||||
ExprResult* BooleanResult::clone()
|
||||
{
|
||||
return new BooleanResult(value);
|
||||
}
|
||||
|
||||
short BooleanResult::getResultType() {
|
||||
return ExprResult::BOOLEAN;
|
||||
} //-- getResultType
|
||||
|
|
|
@ -99,6 +99,9 @@ public:
|
|||
TX_DECL_EVALUATE; \
|
||||
void toString(String& aDest)
|
||||
|
||||
#define TX_DECL_FUNCTION \
|
||||
TX_DECL_EVALUATE; \
|
||||
nsresult getNameAtom(txAtom** aAtom)
|
||||
|
||||
/**
|
||||
* This class represents a FunctionCall as defined by the XPath 1.0
|
||||
|
@ -117,7 +120,7 @@ public:
|
|||
* Virtual methods from Expr
|
||||
**/
|
||||
virtual ExprResult* evaluate(txIEvalContext* aContext) = 0;
|
||||
virtual void toString(String& dest);
|
||||
void toString(String& aDest);
|
||||
|
||||
/**
|
||||
* Adds the given parameter to this FunctionCall's parameter list
|
||||
|
@ -138,7 +141,6 @@ protected:
|
|||
List params;
|
||||
|
||||
FunctionCall();
|
||||
FunctionCall(const String& name);
|
||||
|
||||
/*
|
||||
* Evaluates the given Expression and converts its result to a String.
|
||||
|
@ -163,7 +165,10 @@ protected:
|
|||
*/
|
||||
NodeSet* evaluateToNodeSet(Expr* aExpr, txIEvalContext* aContext);
|
||||
|
||||
String name;
|
||||
/*
|
||||
* Returns the name of the function as an atom.
|
||||
*/
|
||||
virtual nsresult getNameAtom(txAtom** aAtom) = 0;
|
||||
}; //-- FunctionCall
|
||||
|
||||
|
||||
|
|
|
@ -44,6 +44,69 @@
|
|||
#include "txAtoms.h"
|
||||
#include "txIXPathContext.h"
|
||||
|
||||
// XXX This is ugly, but this is the last file to use them,
|
||||
// once we convert the parser to directly compare with
|
||||
// atoms we should remove these.
|
||||
class XPathNames {
|
||||
public:
|
||||
static const String BOOLEAN_FN;
|
||||
static const String CONCAT_FN;
|
||||
static const String CONTAINS_FN;
|
||||
static const String COUNT_FN ;
|
||||
static const String FALSE_FN;
|
||||
static const String ID_FN;
|
||||
static const String LANG_FN;
|
||||
static const String LAST_FN;
|
||||
static const String LOCAL_NAME_FN;
|
||||
static const String NAME_FN;
|
||||
static const String NAMESPACE_URI_FN;
|
||||
static const String NORMALIZE_SPACE_FN;
|
||||
static const String NOT_FN;
|
||||
static const String POSITION_FN;
|
||||
static const String STARTS_WITH_FN;
|
||||
static const String STRING_FN;
|
||||
static const String STRING_LENGTH_FN;
|
||||
static const String SUBSTRING_FN;
|
||||
static const String SUBSTRING_AFTER_FN;
|
||||
static const String SUBSTRING_BEFORE_FN;
|
||||
static const String SUM_FN;
|
||||
static const String TRANSLATE_FN;
|
||||
static const String TRUE_FN;
|
||||
static const String NUMBER_FN;
|
||||
static const String ROUND_FN;
|
||||
static const String CEILING_FN;
|
||||
static const String FLOOR_FN;
|
||||
};
|
||||
|
||||
const String XPathNames::BOOLEAN_FN("boolean");
|
||||
const String XPathNames::CONCAT_FN("concat");
|
||||
const String XPathNames::CONTAINS_FN("contains");
|
||||
const String XPathNames::COUNT_FN("count");
|
||||
const String XPathNames::FALSE_FN("false");
|
||||
const String XPathNames::ID_FN("id");
|
||||
const String XPathNames::LAST_FN("last");
|
||||
const String XPathNames::LOCAL_NAME_FN("local-name");
|
||||
const String XPathNames::NAME_FN("name");
|
||||
const String XPathNames::NAMESPACE_URI_FN("namespace-uri");
|
||||
const String XPathNames::NORMALIZE_SPACE_FN("normalize-space");
|
||||
const String XPathNames::NOT_FN("not");
|
||||
const String XPathNames::POSITION_FN("position");
|
||||
const String XPathNames::STARTS_WITH_FN("starts-with");
|
||||
const String XPathNames::STRING_FN("string");
|
||||
const String XPathNames::STRING_LENGTH_FN("string-length");
|
||||
const String XPathNames::SUBSTRING_FN("substring");
|
||||
const String XPathNames::SUBSTRING_AFTER_FN("substring-after");
|
||||
const String XPathNames::SUBSTRING_BEFORE_FN("substring-before");
|
||||
const String XPathNames::SUM_FN("sum");
|
||||
const String XPathNames::TRANSLATE_FN("translate");
|
||||
const String XPathNames::TRUE_FN("true");
|
||||
const String XPathNames::NUMBER_FN("number");
|
||||
const String XPathNames::ROUND_FN("round");
|
||||
const String XPathNames::CEILING_FN("ceiling");
|
||||
const String XPathNames::FLOOR_FN("floor");
|
||||
const String XPathNames::LANG_FN("lang");
|
||||
|
||||
|
||||
/**
|
||||
* Creates an Attribute Value Template using the given value
|
||||
* This should move to XSLProcessor class
|
||||
|
|
|
@ -55,6 +55,12 @@ public:
|
|||
|
||||
virtual ~ExprResult() {};
|
||||
|
||||
/*
|
||||
* Clones this ExprResult
|
||||
* @return clone of this ExprResult
|
||||
*/
|
||||
virtual ExprResult* clone() = 0;
|
||||
|
||||
/**
|
||||
* Returns the type of ExprResult represented
|
||||
* @return the type of ExprResult represented
|
||||
|
@ -88,6 +94,7 @@ public:
|
|||
BooleanResult();
|
||||
BooleanResult(MBool boolean);
|
||||
|
||||
virtual ExprResult* clone();
|
||||
virtual short getResultType();
|
||||
virtual void stringValue(String& str);
|
||||
virtual MBool booleanValue();
|
||||
|
@ -104,9 +111,7 @@ public:
|
|||
NumberResult();
|
||||
NumberResult(double dbl);
|
||||
|
||||
double getValue() const;
|
||||
MBool isNaN() const;
|
||||
|
||||
virtual ExprResult* clone();
|
||||
virtual short getResultType();
|
||||
virtual void stringValue(String& str);
|
||||
virtual MBool booleanValue();
|
||||
|
@ -126,6 +131,7 @@ public:
|
|||
StringResult(const String& str);
|
||||
StringResult(const char* str);
|
||||
|
||||
virtual ExprResult* clone();
|
||||
virtual short getResultType();
|
||||
virtual void stringValue(String& str);
|
||||
virtual MBool booleanValue();
|
||||
|
|
|
@ -36,25 +36,9 @@ const String FunctionCall::INVALID_PARAM_COUNT(
|
|||
const String FunctionCall::INVALID_PARAM_VALUE(
|
||||
"invalid parameter value for function: ");
|
||||
|
||||
//- Constructors -/
|
||||
|
||||
/**
|
||||
* Creates a new FunctionCall
|
||||
**/
|
||||
FunctionCall::FunctionCall() : name("void")
|
||||
FunctionCall::FunctionCall()
|
||||
{
|
||||
} //-- FunctionCall
|
||||
|
||||
/**
|
||||
* Creates a new FunctionCall with the given function
|
||||
* Note: The object references in parameters will be deleted when this
|
||||
* FunctionCall gets destroyed.
|
||||
**/
|
||||
FunctionCall::FunctionCall(const String& name)
|
||||
{
|
||||
//-- copy name
|
||||
this->name = name;
|
||||
} //-- FunctionCall
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
|
@ -189,20 +173,29 @@ MBool FunctionCall::requireParams(int paramCountMin, txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this NodeExpr.
|
||||
**/
|
||||
void FunctionCall::toString(String& dest)
|
||||
void FunctionCall::toString(String& aDest)
|
||||
{
|
||||
dest.append(this->name);
|
||||
dest.append('(');
|
||||
//-- add parameters
|
||||
txListIterator iter(¶ms);
|
||||
int argc = 0;
|
||||
while (iter.hasNext()) {
|
||||
if (argc > 0)
|
||||
dest.append(',');
|
||||
Expr* expr = (Expr*)iter.next();
|
||||
expr->toString(dest);
|
||||
++argc;
|
||||
txAtom* functionNameAtom = 0;
|
||||
String functionName;
|
||||
if (!NS_SUCCEEDED(getNameAtom(&functionNameAtom)) ||
|
||||
!TX_GET_ATOM_STRING(functionNameAtom, functionName)) {
|
||||
NS_ASSERTION(0, "Can't get function name.");
|
||||
TX_IF_RELEASE_ATOM(functionNameAtom);
|
||||
return;
|
||||
}
|
||||
dest.append(')');
|
||||
} //-- toString
|
||||
TX_RELEASE_ATOM(functionNameAtom);
|
||||
|
||||
aDest.append(functionName);
|
||||
aDest.append('(');
|
||||
txListIterator iter(¶ms);
|
||||
MBool addComma = MB_FALSE;
|
||||
while (iter.hasNext()) {
|
||||
if (addComma) {
|
||||
aDest.append(',');
|
||||
}
|
||||
addComma = MB_TRUE;
|
||||
Expr* expr = (Expr*)iter.next();
|
||||
expr->toString(aDest);
|
||||
}
|
||||
aDest.append(')');
|
||||
}
|
||||
|
|
|
@ -39,43 +39,6 @@
|
|||
#include "ExprResult.h"
|
||||
#include "Expr.h"
|
||||
|
||||
|
||||
class XPathNames {
|
||||
|
||||
public:
|
||||
//-- Function Names
|
||||
static const String BOOLEAN_FN;
|
||||
static const String CONCAT_FN;
|
||||
static const String CONTAINS_FN;
|
||||
static const String COUNT_FN ;
|
||||
static const String FALSE_FN;
|
||||
static const String ID_FN;
|
||||
static const String LANG_FN;
|
||||
static const String LAST_FN;
|
||||
static const String LOCAL_NAME_FN;
|
||||
static const String NAME_FN;
|
||||
static const String NAMESPACE_URI_FN;
|
||||
static const String NORMALIZE_SPACE_FN;
|
||||
static const String NOT_FN;
|
||||
static const String POSITION_FN;
|
||||
static const String STARTS_WITH_FN;
|
||||
static const String STRING_FN;
|
||||
static const String STRING_LENGTH_FN;
|
||||
static const String SUBSTRING_FN;
|
||||
static const String SUBSTRING_AFTER_FN;
|
||||
static const String SUBSTRING_BEFORE_FN;
|
||||
static const String SUM_FN;
|
||||
static const String TRANSLATE_FN;
|
||||
static const String TRUE_FN;
|
||||
// OG+
|
||||
static const String NUMBER_FN;
|
||||
static const String ROUND_FN;
|
||||
static const String CEILING_FN;
|
||||
static const String FLOOR_FN;
|
||||
}; //-- XPathNames
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The following are definitions for the XPath functions
|
||||
*
|
||||
|
@ -118,7 +81,7 @@ public:
|
|||
**/
|
||||
BooleanFunctionCall(BooleanFunctions aType);
|
||||
|
||||
TX_DECL_EVALUATE;
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
BooleanFunctions mType;
|
||||
|
@ -134,7 +97,7 @@ public:
|
|||
ErrorFunctionCall();
|
||||
ErrorFunctionCall(const String& errorMsg);
|
||||
|
||||
TX_DECL_EVALUATE;
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
void setErrorMessage(String& errorMsg);
|
||||
|
||||
|
@ -166,7 +129,7 @@ public:
|
|||
*/
|
||||
NodeSetFunctionCall(NodeSetFunctions aType);
|
||||
|
||||
TX_DECL_EVALUATE;
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
NodeSetFunctions mType;
|
||||
|
@ -198,7 +161,7 @@ public:
|
|||
**/
|
||||
StringFunctionCall(StringFunctions aType);
|
||||
|
||||
TX_DECL_EVALUATE;
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
StringFunctions mType;
|
||||
|
@ -225,7 +188,7 @@ public:
|
|||
*/
|
||||
NumberFunctionCall(NumberFunctions aType);
|
||||
|
||||
TX_DECL_EVALUATE;
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
NumberFunctions mType;
|
||||
|
|
|
@ -33,40 +33,17 @@
|
|||
*/
|
||||
|
||||
#include "FunctionLib.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
#include "Tokenizer.h"
|
||||
#include "txAtom.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txIXPathContext.h"
|
||||
#include "Tokenizer.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
|
||||
/*
|
||||
* Creates a NodeSetFunctionCall of the given type
|
||||
*/
|
||||
NodeSetFunctionCall::NodeSetFunctionCall(NodeSetFunctions aType)
|
||||
: mType(aType)
|
||||
{
|
||||
mType = aType;
|
||||
switch (aType) {
|
||||
case COUNT:
|
||||
name = XPathNames::COUNT_FN;
|
||||
break;
|
||||
case ID:
|
||||
name = XPathNames::ID_FN;
|
||||
break;
|
||||
case LAST:
|
||||
name = XPathNames::LAST_FN;
|
||||
break;
|
||||
case LOCAL_NAME:
|
||||
name = XPathNames::LOCAL_NAME_FN;
|
||||
break;
|
||||
case NAME:
|
||||
name = XPathNames::NAME_FN;
|
||||
break;
|
||||
case NAMESPACE_URI:
|
||||
name = XPathNames::NAMESPACE_URI_FN;
|
||||
break;
|
||||
case POSITION:
|
||||
name = XPathNames::POSITION_FN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -229,3 +206,51 @@ ExprResult* NodeSetFunctionCall::evaluate(txIEvalContext* aContext) {
|
|||
aContext->receiveError(err, NS_ERROR_UNEXPECTED);
|
||||
return new StringResult("error");
|
||||
}
|
||||
|
||||
nsresult NodeSetFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
switch (mType) {
|
||||
case COUNT:
|
||||
{
|
||||
*aAtom = txXPathAtoms::count;
|
||||
break;
|
||||
}
|
||||
case ID:
|
||||
{
|
||||
*aAtom = txXPathAtoms::id;
|
||||
break;
|
||||
}
|
||||
case LAST:
|
||||
{
|
||||
*aAtom = txXPathAtoms::last;
|
||||
break;
|
||||
}
|
||||
case LOCAL_NAME:
|
||||
{
|
||||
*aAtom = txXPathAtoms::localName;
|
||||
break;
|
||||
}
|
||||
case NAME:
|
||||
{
|
||||
*aAtom = txXPathAtoms::name;
|
||||
break;
|
||||
}
|
||||
case NAMESPACE_URI:
|
||||
{
|
||||
*aAtom = txXPathAtoms::namespaceUri;
|
||||
break;
|
||||
}
|
||||
case POSITION:
|
||||
{
|
||||
*aAtom = txXPathAtoms::position;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*aAtom = 0;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -34,32 +34,17 @@
|
|||
*/
|
||||
|
||||
#include "FunctionLib.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
#include <math.h>
|
||||
#include "txAtoms.h"
|
||||
#include "txIXPathContext.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
|
||||
/*
|
||||
* Creates a NumberFunctionCall of the given type
|
||||
*/
|
||||
NumberFunctionCall::NumberFunctionCall(NumberFunctions aType) {
|
||||
mType = aType;
|
||||
switch (mType) {
|
||||
case ROUND:
|
||||
name = XPathNames::ROUND_FN;
|
||||
break;
|
||||
case CEILING:
|
||||
name = XPathNames::CEILING_FN;
|
||||
break;
|
||||
case FLOOR:
|
||||
name = XPathNames::FLOOR_FN;
|
||||
break;
|
||||
case SUM:
|
||||
name = XPathNames::SUM_FN;
|
||||
break;
|
||||
case NUMBER:
|
||||
name = XPathNames::NUMBER_FN;
|
||||
break;
|
||||
}
|
||||
NumberFunctionCall::NumberFunctionCall(NumberFunctions aType)
|
||||
: mType(aType)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -151,3 +136,41 @@ ExprResult* NumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
aContext->receiveError(err, NS_ERROR_UNEXPECTED);
|
||||
return new StringResult("error");
|
||||
}
|
||||
|
||||
nsresult NumberFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
switch (mType) {
|
||||
case NUMBER:
|
||||
{
|
||||
*aAtom = txXPathAtoms::number;
|
||||
break;
|
||||
}
|
||||
case ROUND:
|
||||
{
|
||||
*aAtom = txXPathAtoms::round;
|
||||
break;
|
||||
}
|
||||
case FLOOR:
|
||||
{
|
||||
*aAtom = txXPathAtoms::floor;
|
||||
break;
|
||||
}
|
||||
case CEILING:
|
||||
{
|
||||
*aAtom = txXPathAtoms::ceiling;
|
||||
break;
|
||||
}
|
||||
case SUM:
|
||||
{
|
||||
*aAtom = txXPathAtoms::sum;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*aAtom = 0;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,11 @@ NumberResult::NumberResult(double dbl) {
|
|||
* Virtual Methods from ExprResult
|
||||
*/
|
||||
|
||||
ExprResult* NumberResult::clone()
|
||||
{
|
||||
return new NumberResult(value);
|
||||
}
|
||||
|
||||
short NumberResult::getResultType() {
|
||||
return ExprResult::NUMBER;
|
||||
} //-- getResultType
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "FunctionLib.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
#include "XMLUtils.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txIXPathContext.h"
|
||||
#include <math.h>
|
||||
|
||||
|
@ -40,35 +41,6 @@
|
|||
**/
|
||||
StringFunctionCall::StringFunctionCall(StringFunctions aType) : mType(aType)
|
||||
{
|
||||
switch (aType) {
|
||||
case CONCAT:
|
||||
name = XPathNames::CONCAT_FN;
|
||||
break;
|
||||
case CONTAINS:
|
||||
name = XPathNames::CONTAINS_FN;
|
||||
break;
|
||||
case STARTS_WITH:
|
||||
name = XPathNames::STARTS_WITH_FN;
|
||||
break;
|
||||
case STRING_LENGTH:
|
||||
name = XPathNames::STRING_LENGTH_FN;
|
||||
break;
|
||||
case SUBSTRING:
|
||||
name = XPathNames::SUBSTRING_FN;
|
||||
break;
|
||||
case SUBSTRING_AFTER:
|
||||
name = XPathNames::SUBSTRING_AFTER_FN;
|
||||
break;
|
||||
case SUBSTRING_BEFORE:
|
||||
name = XPathNames::SUBSTRING_BEFORE_FN;
|
||||
break;
|
||||
case TRANSLATE:
|
||||
name = XPathNames::TRANSLATE_FN;
|
||||
break;
|
||||
default:
|
||||
name = XPathNames::STRING_FN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -278,3 +250,66 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
aContext->receiveError(err, NS_ERROR_UNEXPECTED);
|
||||
return new StringResult("error");
|
||||
}
|
||||
|
||||
nsresult StringFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
switch (mType) {
|
||||
case CONCAT:
|
||||
{
|
||||
*aAtom = txXPathAtoms::concat;
|
||||
break;
|
||||
}
|
||||
case CONTAINS:
|
||||
{
|
||||
*aAtom = txXPathAtoms::contains;
|
||||
break;
|
||||
}
|
||||
case NORMALIZE_SPACE:
|
||||
{
|
||||
*aAtom = txXPathAtoms::normalizeSpace;
|
||||
break;
|
||||
}
|
||||
case STARTS_WITH:
|
||||
{
|
||||
*aAtom = txXPathAtoms::startsWith;
|
||||
break;
|
||||
}
|
||||
case STRING:
|
||||
{
|
||||
*aAtom = txXPathAtoms::string;
|
||||
break;
|
||||
}
|
||||
case STRING_LENGTH:
|
||||
{
|
||||
*aAtom = txXPathAtoms::stringLength;
|
||||
break;
|
||||
}
|
||||
case SUBSTRING:
|
||||
{
|
||||
*aAtom = txXPathAtoms::substring;
|
||||
break;
|
||||
}
|
||||
case SUBSTRING_AFTER:
|
||||
{
|
||||
*aAtom = txXPathAtoms::substringAfter;
|
||||
break;
|
||||
}
|
||||
case SUBSTRING_BEFORE:
|
||||
{
|
||||
*aAtom = txXPathAtoms::substringBefore;
|
||||
break;
|
||||
}
|
||||
case TRANSLATE:
|
||||
{
|
||||
*aAtom = txXPathAtoms::translate;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*aAtom = 0;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,11 @@ StringResult::StringResult(const char* str) {
|
|||
* Virtual Methods from ExprResult
|
||||
*/
|
||||
|
||||
ExprResult* StringResult::clone()
|
||||
{
|
||||
return new StringResult(value);
|
||||
}
|
||||
|
||||
short StringResult::getResultType() {
|
||||
return ExprResult::STRING;
|
||||
} //-- getResultType
|
||||
|
|
|
@ -67,41 +67,10 @@ ExprResult* VariableRefExpr::evaluate(txIEvalContext* aContext)
|
|||
nsresult rv = aContext->getVariable(mNamespace, mLocalName, exprResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
// XXX report error, undefined variable
|
||||
return 0;
|
||||
return new StringResult("error");
|
||||
}
|
||||
//-- make copy to prevent deletetion
|
||||
//-- I know, I should add a #copy method to ExprResult, I will
|
||||
ExprResult* copyOfResult = 0;
|
||||
|
||||
if ( exprResult ) {
|
||||
switch ( exprResult->getResultType() ) {
|
||||
//-- BooleanResult
|
||||
case ExprResult::BOOLEAN :
|
||||
copyOfResult = new BooleanResult(exprResult->booleanValue());
|
||||
break;
|
||||
//-- NodeSet
|
||||
case ExprResult::NODESET :
|
||||
{
|
||||
copyOfResult = new NodeSet(*(NodeSet*)exprResult);
|
||||
break;
|
||||
}
|
||||
//-- NumberResult
|
||||
case ExprResult::NUMBER :
|
||||
copyOfResult = new NumberResult(exprResult->numberValue());
|
||||
break;
|
||||
//-- StringResult
|
||||
default:
|
||||
String tmp;
|
||||
exprResult->stringValue(tmp);
|
||||
StringResult* strResult = new StringResult(tmp);
|
||||
copyOfResult = strResult;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else copyOfResult = new StringResult();
|
||||
|
||||
return copyOfResult;
|
||||
} //-- evaluate
|
||||
return exprResult->clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the String representation of this Expr.
|
||||
|
|
|
@ -52,7 +52,6 @@ CPPSRCS = Names.cpp \
|
|||
ProcessorState.cpp \
|
||||
txRtfHandler.cpp \
|
||||
txTextHandler.cpp \
|
||||
VariableBinding.cpp \
|
||||
txXSLTPatterns.cpp \
|
||||
txPatternParser.cpp \
|
||||
XSLTProcessor.cpp
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "XSLTFunctions.h"
|
||||
#include "ProcessorState.h"
|
||||
#include "Names.h"
|
||||
#include "txAtoms.h"
|
||||
#include "XSLTFunctions.h"
|
||||
|
||||
/*
|
||||
Implementation of XSLT 1.0 extension function: current
|
||||
|
@ -10,7 +10,7 @@
|
|||
* Creates a new current function call
|
||||
**/
|
||||
CurrentFunctionCall::CurrentFunctionCall(ProcessorState* aPs)
|
||||
: FunctionCall(CURRENT_FN), mPs(aPs)
|
||||
: mPs(aPs)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -25,3 +25,9 @@ ExprResult* CurrentFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
return new NodeSet(mPs->getEvalContext()->getContextNode());
|
||||
}
|
||||
|
||||
nsresult CurrentFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
*aAtom = txXSLTAtoms::current;
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -36,21 +36,20 @@
|
|||
* A representation of the XSLT additional function: document()
|
||||
*/
|
||||
|
||||
#include "XSLTFunctions.h"
|
||||
#include "ProcessorState.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
#include "Names.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txIXPathContext.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
#include "XSLTFunctions.h"
|
||||
|
||||
/*
|
||||
* Creates a new DocumentFunctionCall.
|
||||
*/
|
||||
DocumentFunctionCall::DocumentFunctionCall(ProcessorState* aPs,
|
||||
Node* aDefResolveNode)
|
||||
: FunctionCall(DOCUMENT_FN)
|
||||
: mProcessorState(aPs),
|
||||
mDefResolveNode(aDefResolveNode)
|
||||
{
|
||||
mProcessorState = aPs;
|
||||
mDefResolveNode = aDefResolveNode;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -133,3 +132,10 @@ ExprResult* DocumentFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
return nodeSet;
|
||||
}
|
||||
|
||||
nsresult DocumentFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
*aAtom = txXSLTAtoms::document;
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "XSLTFunctions.h"
|
||||
#include "XMLUtils.h"
|
||||
#include "Names.h"
|
||||
#include "txIXPathContext.h"
|
||||
#include "txAtoms.h"
|
||||
#include "XMLUtils.h"
|
||||
#include "XSLTFunctions.h"
|
||||
|
||||
/*
|
||||
Implementation of XSLT 1.0 extension function: element-available
|
||||
|
@ -51,8 +51,8 @@
|
|||
* aNode is the Element in the stylesheet containing the
|
||||
* Expr and is used for namespaceID resolution
|
||||
**/
|
||||
ElementAvailableFunctionCall::ElementAvailableFunctionCall(Element* aNode) :
|
||||
FunctionCall(ELEMENT_AVAILABLE_FN), mStylesheetNode(aNode)
|
||||
ElementAvailableFunctionCall::ElementAvailableFunctionCall(Node* aQNameResolveNode)
|
||||
: mQNameResolveNode(aQNameResolveNode)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -76,52 +76,46 @@ ExprResult* ElementAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
exprResult->getResultType() == ExprResult::STRING) {
|
||||
String property;
|
||||
exprResult->stringValue(property);
|
||||
if (XMLUtils::isValidQName(property)) {
|
||||
String prefix;
|
||||
PRInt32 aNSID = kNameSpaceID_None;
|
||||
XMLUtils::getPrefix(property, prefix);
|
||||
if (!prefix.isEmpty()) {
|
||||
txAtom* prefixAtom = TX_GET_ATOM(prefix);
|
||||
aNSID = mStylesheetNode->lookupNamespaceID(prefixAtom);
|
||||
TX_IF_RELEASE_ATOM(prefixAtom);
|
||||
}
|
||||
if (aNSID == kNameSpaceID_XSLT) {
|
||||
String localName;
|
||||
XMLUtils::getLocalPart(property, localName);
|
||||
if ( localName.isEqual(APPLY_IMPORTS) ||
|
||||
localName.isEqual(APPLY_TEMPLATES) ||
|
||||
localName.isEqual(ATTRIBUTE) ||
|
||||
localName.isEqual(ATTRIBUTE_SET) ||
|
||||
localName.isEqual(CALL_TEMPLATE) ||
|
||||
localName.isEqual(CHOOSE) ||
|
||||
localName.isEqual(COMMENT) ||
|
||||
localName.isEqual(COPY) ||
|
||||
localName.isEqual(COPY_OF) ||
|
||||
localName.isEqual(DECIMAL_FORMAT) ||
|
||||
localName.isEqual(ELEMENT) ||
|
||||
localName.isEqual(FOR_EACH) ||
|
||||
localName.isEqual(IF) ||
|
||||
localName.isEqual(IMPORT) ||
|
||||
localName.isEqual(INCLUDE) ||
|
||||
localName.isEqual(KEY) ||
|
||||
localName.isEqual(MESSAGE) ||
|
||||
localName.isEqual(NUMBER) ||
|
||||
localName.isEqual(OTHERWISE) ||
|
||||
localName.isEqual(OUTPUT) ||
|
||||
localName.isEqual(PARAM) ||
|
||||
localName.isEqual(PROC_INST) ||
|
||||
localName.isEqual(PRESERVE_SPACE) ||
|
||||
localName.isEqual(SORT) ||
|
||||
localName.isEqual(STRIP_SPACE) ||
|
||||
localName.isEqual(TEMPLATE) ||
|
||||
localName.isEqual(TEXT) ||
|
||||
localName.isEqual(VALUE_OF) ||
|
||||
localName.isEqual(VARIABLE) ||
|
||||
localName.isEqual(WHEN) ||
|
||||
localName.isEqual(WITH_PARAM) ) {
|
||||
result = new BooleanResult(MB_TRUE);
|
||||
}
|
||||
}
|
||||
txExpandedName qname;
|
||||
nsresult rv = qname.init(property, mQNameResolveNode, MB_TRUE);
|
||||
if (NS_SUCCEEDED(rv) &&
|
||||
qname.mNamespaceID == kNameSpaceID_XSLT &&
|
||||
(qname.mLocalName == txXSLTAtoms::applyImports ||
|
||||
qname.mLocalName == txXSLTAtoms::applyTemplates ||
|
||||
qname.mLocalName == txXSLTAtoms::attribute ||
|
||||
qname.mLocalName == txXSLTAtoms::attributeSet ||
|
||||
qname.mLocalName == txXSLTAtoms::callTemplate ||
|
||||
qname.mLocalName == txXSLTAtoms::choose ||
|
||||
qname.mLocalName == txXSLTAtoms::comment ||
|
||||
qname.mLocalName == txXSLTAtoms::copy ||
|
||||
qname.mLocalName == txXSLTAtoms::copyOf ||
|
||||
qname.mLocalName == txXSLTAtoms::decimalFormat ||
|
||||
qname.mLocalName == txXSLTAtoms::element ||
|
||||
// qname.mLocalName == txXSLTAtoms::fallback ||
|
||||
qname.mLocalName == txXSLTAtoms::forEach ||
|
||||
qname.mLocalName == txXSLTAtoms::_if ||
|
||||
qname.mLocalName == txXSLTAtoms::import ||
|
||||
qname.mLocalName == txXSLTAtoms::include ||
|
||||
qname.mLocalName == txXSLTAtoms::key ||
|
||||
qname.mLocalName == txXSLTAtoms::message ||
|
||||
// qname.mLocalName == txXSLTAtoms::namespaceAlias ||
|
||||
qname.mLocalName == txXSLTAtoms::number ||
|
||||
qname.mLocalName == txXSLTAtoms::otherwise ||
|
||||
qname.mLocalName == txXSLTAtoms::output ||
|
||||
qname.mLocalName == txXSLTAtoms::param ||
|
||||
qname.mLocalName == txXSLTAtoms::preserveSpace ||
|
||||
qname.mLocalName == txXSLTAtoms::processingInstruction ||
|
||||
qname.mLocalName == txXSLTAtoms::sort ||
|
||||
qname.mLocalName == txXSLTAtoms::stripSpace ||
|
||||
qname.mLocalName == txXSLTAtoms::stylesheet ||
|
||||
qname.mLocalName == txXSLTAtoms::_template ||
|
||||
qname.mLocalName == txXSLTAtoms::text ||
|
||||
qname.mLocalName == txXSLTAtoms::transform ||
|
||||
qname.mLocalName == txXSLTAtoms::valueOf ||
|
||||
qname.mLocalName == txXSLTAtoms::variable ||
|
||||
qname.mLocalName == txXSLTAtoms::when ||
|
||||
qname.mLocalName == txXSLTAtoms::withParam)) {
|
||||
result = new BooleanResult(MB_TRUE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -139,3 +133,9 @@ ExprResult* ElementAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
return result;
|
||||
}
|
||||
|
||||
nsresult ElementAvailableFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
*aAtom = txXSLTAtoms::elementAvailable;
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#include "XSLTFunctions.h"
|
||||
#include "ProcessorState.h"
|
||||
#include "primitives.h"
|
||||
#include "Names.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txIXPathContext.h"
|
||||
#include <math.h>
|
||||
|
||||
|
@ -61,8 +61,7 @@ const UNICODE_CHAR txFormatNumberFunctionCall::FORMAT_QUOTE = '\'';
|
|||
*/
|
||||
txFormatNumberFunctionCall::txFormatNumberFunctionCall(ProcessorState* aPs,
|
||||
Node* aQNameResolveNode)
|
||||
: FunctionCall(FORMAT_NUMBER_FN),
|
||||
mPs(aPs),
|
||||
: mPs(aPs),
|
||||
mQNameResolveNode(aQNameResolveNode)
|
||||
{
|
||||
}
|
||||
|
@ -262,7 +261,6 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
// Did we manage to parse the entire formatstring and was it valid
|
||||
if ((c != format->mPatternSeparator && pos < formatLen) ||
|
||||
minIntegerSize == 0 ||
|
||||
inQuote ||
|
||||
groupSize == 0) {
|
||||
String err(INVALID_PARAM_VALUE);
|
||||
|
@ -287,9 +285,15 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
int bufsize;
|
||||
if (value > 1)
|
||||
bufsize = (int)log10(value) + maxFractionSize + 5;
|
||||
bufsize = (int)log10(value) + 1;
|
||||
else
|
||||
bufsize = 1 + maxFractionSize + 5;
|
||||
bufsize = 1;
|
||||
|
||||
if (bufsize < minIntegerSize)
|
||||
bufsize = minIntegerSize;
|
||||
|
||||
bufsize += maxFractionSize + 3; // decimal separator + ending null +
|
||||
// rounding safety
|
||||
|
||||
char* buf = new char[bufsize];
|
||||
if (!buf) {
|
||||
|
@ -316,10 +320,10 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
// Integer digits
|
||||
int i;
|
||||
for (i = 0; i < intDigits; ++i) {
|
||||
res.append((UNICODE_CHAR)(buf[i] - '0' + format->mZeroDigit));
|
||||
|
||||
if ((intDigits-i)%groupSize == 0 && intDigits-i != 0)
|
||||
if ((intDigits-i)%groupSize == 0 && i != 0)
|
||||
res.append(format->mGroupingSeparator);
|
||||
|
||||
res.append((UNICODE_CHAR)(buf[i] - '0' + format->mZeroDigit));
|
||||
}
|
||||
|
||||
// Fractions
|
||||
|
@ -330,7 +334,7 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
i++; // skip decimal separator
|
||||
|
||||
for (; buf[i]; i++) {
|
||||
if (i-intDigits-1 > minFractionSize && buf[i] == '0') {
|
||||
if (i-intDigits-1 >= minFractionSize && buf[i] == '0') {
|
||||
extraZeros++;
|
||||
}
|
||||
else {
|
||||
|
@ -346,6 +350,12 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
res.append((UNICODE_CHAR)(buf[i] - '0' + format->mZeroDigit));
|
||||
}
|
||||
}
|
||||
|
||||
if (!intDigits && printDeci) {
|
||||
// If we havn't added any characters we add a '0'
|
||||
// This can only happen for formats like '##.##'
|
||||
res.append(format->mZeroDigit);
|
||||
}
|
||||
|
||||
delete [] buf;
|
||||
|
||||
|
@ -373,7 +383,7 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
intDigits = bufIntDigits > minIntegerSize ? bufIntDigits : minIntegerSize;
|
||||
|
||||
if (groupSize < 0)
|
||||
groupSize = intDigits * 2; //to simplify grouping
|
||||
groupSize = intDigits + 10; //to simplify grouping
|
||||
|
||||
// XXX We shouldn't use SetLength.
|
||||
res.getNSString().SetLength(res.length() +
|
||||
|
@ -391,16 +401,18 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
// Fractions
|
||||
for (; i >= bufIntDigits; --i) {
|
||||
int digit;
|
||||
if (i >= buflen) {
|
||||
if (i >= buflen || i < 0) {
|
||||
digit = 0;
|
||||
}
|
||||
else if (carry) {
|
||||
digit = (buf[i] - '0' + 1) % 10;
|
||||
carry = digit == 0;
|
||||
}
|
||||
else {
|
||||
digit = buf[i] - '0';
|
||||
}
|
||||
|
||||
if (carry) {
|
||||
digit = (digit + 1) % 10;
|
||||
carry = digit == 0;
|
||||
}
|
||||
|
||||
if (hasFraction || digit != 0 || i < bufIntDigits+minFractionSize) {
|
||||
hasFraction = MB_TRUE;
|
||||
res.replace(resPos--,
|
||||
|
@ -430,7 +442,7 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
|
||||
if (carry) {
|
||||
digit = digit % 10;
|
||||
digit = (digit + 1) % 10;
|
||||
carry = digit == 0;
|
||||
}
|
||||
|
||||
|
@ -447,6 +459,12 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
res.insert(resPos + 1, (UNICODE_CHAR)(1 + format->mZeroDigit));
|
||||
}
|
||||
|
||||
if (!hasFraction && !intDigits && !carry) {
|
||||
// If we havn't added any characters we add a '0'
|
||||
// This can only happen for formats like '##.##'
|
||||
res.append(format->mZeroDigit);
|
||||
}
|
||||
|
||||
delete [] buf;
|
||||
|
||||
|
@ -458,6 +476,12 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
return new StringResult(res);
|
||||
} //-- evaluate
|
||||
|
||||
nsresult txFormatNumberFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
*aAtom = txXSLTAtoms::formatNumber;
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* txDecimalFormat
|
||||
|
|
|
@ -37,11 +37,10 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "XSLTFunctions.h"
|
||||
#include "FunctionLib.h"
|
||||
#include "XMLUtils.h"
|
||||
#include "Names.h"
|
||||
#include "txIXPathContext.h"
|
||||
#include "txAtoms.h"
|
||||
#include "XMLUtils.h"
|
||||
#include "XSLTFunctions.h"
|
||||
|
||||
/*
|
||||
Implementation of XSLT 1.0 extension function: function-available
|
||||
|
@ -50,8 +49,8 @@
|
|||
/**
|
||||
* Creates a new function-available function call
|
||||
**/
|
||||
FunctionAvailableFunctionCall::FunctionAvailableFunctionCall() :
|
||||
FunctionCall(FUNCTION_AVAILABLE_FN)
|
||||
FunctionAvailableFunctionCall::FunctionAvailableFunctionCall(Node* aQNameResolveNode)
|
||||
: mQNameResolveNode(aQNameResolveNode)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -75,48 +74,47 @@ ExprResult* FunctionAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
exprResult->getResultType() == ExprResult::STRING) {
|
||||
String property;
|
||||
exprResult->stringValue(property);
|
||||
if (XMLUtils::isValidQName(property)) {
|
||||
String prefix;
|
||||
XMLUtils::getPrefix(property, prefix);
|
||||
if (prefix.isEmpty() &&
|
||||
(property.isEqual(XPathNames::BOOLEAN_FN) ||
|
||||
property.isEqual(XPathNames::CONCAT_FN) ||
|
||||
property.isEqual(XPathNames::CONTAINS_FN) ||
|
||||
property.isEqual(XPathNames::COUNT_FN ) ||
|
||||
property.isEqual(XPathNames::FALSE_FN) ||
|
||||
property.isEqual(XPathNames::ID_FN) ||
|
||||
property.isEqual(XPathNames::LANG_FN) ||
|
||||
property.isEqual(XPathNames::LAST_FN) ||
|
||||
property.isEqual(XPathNames::LOCAL_NAME_FN) ||
|
||||
property.isEqual(XPathNames::NAME_FN) ||
|
||||
property.isEqual(XPathNames::NAMESPACE_URI_FN) ||
|
||||
property.isEqual(XPathNames::NORMALIZE_SPACE_FN) ||
|
||||
property.isEqual(XPathNames::NOT_FN) ||
|
||||
property.isEqual(XPathNames::POSITION_FN) ||
|
||||
property.isEqual(XPathNames::STARTS_WITH_FN) ||
|
||||
property.isEqual(XPathNames::STRING_FN) ||
|
||||
property.isEqual(XPathNames::STRING_LENGTH_FN) ||
|
||||
property.isEqual(XPathNames::SUBSTRING_FN) ||
|
||||
property.isEqual(XPathNames::SUBSTRING_AFTER_FN) ||
|
||||
property.isEqual(XPathNames::SUBSTRING_BEFORE_FN) ||
|
||||
property.isEqual(XPathNames::SUM_FN) ||
|
||||
property.isEqual(XPathNames::TRANSLATE_FN) ||
|
||||
property.isEqual(XPathNames::TRUE_FN) ||
|
||||
property.isEqual(XPathNames::NUMBER_FN) ||
|
||||
property.isEqual(XPathNames::ROUND_FN) ||
|
||||
property.isEqual(XPathNames::CEILING_FN) ||
|
||||
property.isEqual(XPathNames::FLOOR_FN) ||
|
||||
property.isEqual(DOCUMENT_FN) ||
|
||||
property.isEqual(KEY_FN) ||
|
||||
property.isEqual(FORMAT_NUMBER_FN) ||
|
||||
property.isEqual(CURRENT_FN) ||
|
||||
// property.isEqual(UNPARSED_ENTITY_URI_FN) ||
|
||||
property.isEqual(GENERATE_ID_FN) ||
|
||||
property.isEqual(SYSTEM_PROPERTY_FN) ||
|
||||
property.isEqual(ELEMENT_AVAILABLE_FN) ||
|
||||
property.isEqual(FUNCTION_AVAILABLE_FN))) {
|
||||
result = new BooleanResult(MB_TRUE);
|
||||
}
|
||||
txExpandedName qname;
|
||||
nsresult rv = qname.init(property, mQNameResolveNode, MB_FALSE);
|
||||
if (NS_SUCCEEDED(rv) &&
|
||||
qname.mNamespaceID == kNameSpaceID_None &&
|
||||
(qname.mLocalName == txXPathAtoms::boolean ||
|
||||
qname.mLocalName == txXPathAtoms::ceiling ||
|
||||
qname.mLocalName == txXPathAtoms::concat ||
|
||||
qname.mLocalName == txXPathAtoms::contains ||
|
||||
qname.mLocalName == txXPathAtoms::count ||
|
||||
qname.mLocalName == txXPathAtoms::_false ||
|
||||
qname.mLocalName == txXPathAtoms::floor ||
|
||||
qname.mLocalName == txXPathAtoms::id ||
|
||||
qname.mLocalName == txXPathAtoms::lang ||
|
||||
qname.mLocalName == txXPathAtoms::last ||
|
||||
qname.mLocalName == txXPathAtoms::localName ||
|
||||
qname.mLocalName == txXPathAtoms::name ||
|
||||
qname.mLocalName == txXPathAtoms::namespaceUri ||
|
||||
qname.mLocalName == txXPathAtoms::normalizeSpace ||
|
||||
qname.mLocalName == txXPathAtoms::_not ||
|
||||
qname.mLocalName == txXPathAtoms::number ||
|
||||
qname.mLocalName == txXPathAtoms::position ||
|
||||
qname.mLocalName == txXPathAtoms::round ||
|
||||
qname.mLocalName == txXPathAtoms::startsWith ||
|
||||
qname.mLocalName == txXPathAtoms::string ||
|
||||
qname.mLocalName == txXPathAtoms::stringLength ||
|
||||
qname.mLocalName == txXPathAtoms::substring ||
|
||||
qname.mLocalName == txXPathAtoms::substringAfter ||
|
||||
qname.mLocalName == txXPathAtoms::substringBefore ||
|
||||
qname.mLocalName == txXPathAtoms::sum ||
|
||||
qname.mLocalName == txXPathAtoms::translate ||
|
||||
qname.mLocalName == txXPathAtoms::_true ||
|
||||
qname.mLocalName == txXSLTAtoms::current ||
|
||||
qname.mLocalName == txXSLTAtoms::document ||
|
||||
qname.mLocalName == txXSLTAtoms::elementAvailable ||
|
||||
qname.mLocalName == txXSLTAtoms::formatNumber ||
|
||||
qname.mLocalName == txXSLTAtoms::functionAvailable ||
|
||||
qname.mLocalName == txXSLTAtoms::generateId ||
|
||||
qname.mLocalName == txXSLTAtoms::key ||
|
||||
// qname.mLocalName == txXSLTAtoms::unparsedEntityUri ||
|
||||
qname.mLocalName == txXSLTAtoms::systemProperty)) {
|
||||
result = new BooleanResult(MB_TRUE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -134,3 +132,9 @@ ExprResult* FunctionAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
return result;
|
||||
}
|
||||
|
||||
nsresult FunctionAvailableFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
*aAtom = txXSLTAtoms::functionAvailable;
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "XSLTFunctions.h"
|
||||
#include "Names.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txIXPathContext.h"
|
||||
#include "XSLTFunctions.h"
|
||||
#ifdef TX_EXE
|
||||
#include <stdio.h>
|
||||
#else
|
||||
|
@ -45,8 +45,8 @@ const char GenerateIdFunctionCall::printfFmt[] = "id0x%016p";
|
|||
* Creates a new generate-id function call
|
||||
**/
|
||||
GenerateIdFunctionCall::GenerateIdFunctionCall()
|
||||
: FunctionCall(GENERATE_ID_FN)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates this Expr based on the given context node and processor state
|
||||
|
@ -101,3 +101,10 @@ ExprResult* GenerateIdFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
#endif
|
||||
return new StringResult(buf);
|
||||
}
|
||||
|
||||
nsresult GenerateIdFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
*aAtom = txXSLTAtoms::generateId;
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
* -- original author.
|
||||
*/
|
||||
|
||||
#include "XSLTFunctions.h"
|
||||
#include "ProcessorState.h"
|
||||
#include "Names.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txSingleNodeContext.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
#include "XSLTFunctions.h"
|
||||
|
||||
/*
|
||||
* txKeyFunctionCall
|
||||
|
@ -33,10 +33,9 @@
|
|||
* Creates a new key function call
|
||||
*/
|
||||
txKeyFunctionCall::txKeyFunctionCall(ProcessorState* aPs,
|
||||
Node* aQNameResolveNode) :
|
||||
FunctionCall(KEY_FN),
|
||||
mProcessorState(aPs),
|
||||
mQNameResolveNode(aQNameResolveNode)
|
||||
Node* aQNameResolveNode)
|
||||
: mProcessorState(aPs),
|
||||
mQNameResolveNode(aQNameResolveNode)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -107,6 +106,13 @@ ExprResult* txKeyFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
} // evaluate
|
||||
|
||||
nsresult txKeyFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
*aAtom = txXSLTAtoms::key;
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class representing an <xsl:key>. Or in the case where several <xsl:key>s
|
||||
* have the same name one object represents all <xsl:key>s with that name
|
||||
|
|
|
@ -61,7 +61,7 @@ void txMozillaTextOutput::attribute(const String& aName,
|
|||
void txMozillaTextOutput::characters(const String& aData)
|
||||
{
|
||||
if (mTextNode)
|
||||
mTextNode->AppendData(aData.getConstNSString());
|
||||
mTextNode->AppendData(aData);
|
||||
}
|
||||
|
||||
void txMozillaTextOutput::comment(const String& aData)
|
||||
|
|
|
@ -88,16 +88,15 @@ void txMozillaXMLOutput::attribute(const String& aName,
|
|||
|
||||
if ((mOutputFormat.mMethod == eHTMLOutput) && (aNsID == kNameSpaceID_None)) {
|
||||
// Outputting HTML as XHTML, lowercase attribute names
|
||||
nsAutoString lowerName(aName.getConstNSString());
|
||||
nsAutoString lowerName(aName);
|
||||
ToLowerCase(lowerName);
|
||||
element->SetAttributeNS(NS_LITERAL_STRING(""), lowerName,
|
||||
aValue.getConstNSString());
|
||||
aValue);
|
||||
}
|
||||
else {
|
||||
nsAutoString nsURI;
|
||||
mNameSpaceManager->GetNameSpaceURI(aNsID, nsURI);
|
||||
element->SetAttributeNS(nsURI, aName.getConstNSString(),
|
||||
aValue.getConstNSString());
|
||||
element->SetAttributeNS(nsURI, aName, aValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +104,7 @@ void txMozillaXMLOutput::characters(const String& aData)
|
|||
{
|
||||
closePrevious(eCloseElement);
|
||||
|
||||
mText.Append(aData.getConstNSString());
|
||||
mText.Append(aData);
|
||||
}
|
||||
|
||||
void txMozillaXMLOutput::comment(const String& aData)
|
||||
|
@ -115,7 +114,7 @@ void txMozillaXMLOutput::comment(const String& aData)
|
|||
TX_ENSURE_CURRENTNODE;
|
||||
|
||||
nsCOMPtr<nsIDOMComment> comment;
|
||||
nsresult rv = mDocument->CreateComment(aData.getConstNSString(),
|
||||
nsresult rv = mDocument->CreateComment(aData,
|
||||
getter_AddRefs(comment));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create comment");
|
||||
|
||||
|
@ -162,7 +161,7 @@ void txMozillaXMLOutput::endElement(const String& aName, const PRInt32 aNsID)
|
|||
#ifdef DEBUG
|
||||
nsAutoString nodeName;
|
||||
mCurrentNode->GetNodeName(nodeName);
|
||||
NS_ASSERTION(nodeName.Equals(aName.getConstNSString(), nsCaseInsensitiveStringComparator()),
|
||||
NS_ASSERTION(nodeName.Equals(aName, nsCaseInsensitiveStringComparator()),
|
||||
"Unbalanced startElement and endElement calls!");
|
||||
#endif
|
||||
|
||||
|
@ -231,8 +230,7 @@ void txMozillaXMLOutput::processingInstruction(const String& aTarget, const Stri
|
|||
TX_ENSURE_CURRENTNODE;
|
||||
|
||||
nsCOMPtr<nsIDOMProcessingInstruction> pi;
|
||||
nsresult rv = mDocument->CreateProcessingInstruction(aTarget.getConstNSString(),
|
||||
aData.getConstNSString(),
|
||||
nsresult rv = mDocument->CreateProcessingInstruction(aTarget, aData,
|
||||
getter_AddRefs(pi));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create entity reference");
|
||||
|
||||
|
@ -316,10 +314,10 @@ void txMozillaXMLOutput::startElement(const String& aName,
|
|||
if (mOutputFormat.mMethod == eHTMLOutput)
|
||||
qName.Assign(NS_LITERAL_STRING("html"));
|
||||
else
|
||||
qName.Assign(aName.getConstNSString());
|
||||
qName.Assign(aName);
|
||||
rv = implementation->CreateDocumentType(qName,
|
||||
mOutputFormat.mPublicId.getConstNSString(),
|
||||
mOutputFormat.mSystemId.getConstNSString(),
|
||||
mOutputFormat.mPublicId,
|
||||
mOutputFormat.mSystemId,
|
||||
getter_AddRefs(documentType));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create doctype");
|
||||
|
||||
|
@ -334,7 +332,7 @@ void txMozillaXMLOutput::startElement(const String& aName,
|
|||
|
||||
if ((mOutputFormat.mMethod == eHTMLOutput) && (aNsID == kNameSpaceID_None)) {
|
||||
// Outputting HTML as XHTML, lowercase element names
|
||||
nsAutoString lowerName(aName.getConstNSString());
|
||||
nsAutoString lowerName(aName);
|
||||
ToLowerCase(lowerName);
|
||||
rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kXHTMLNameSpaceURI), lowerName,
|
||||
getter_AddRefs(element));
|
||||
|
@ -345,8 +343,7 @@ void txMozillaXMLOutput::startElement(const String& aName,
|
|||
else {
|
||||
nsAutoString nsURI;
|
||||
mNameSpaceManager->GetNameSpaceURI(aNsID, nsURI);
|
||||
rv = mDocument->CreateElementNS(nsURI, aName.getConstNSString(),
|
||||
getter_AddRefs(element));
|
||||
rv = mDocument->CreateElementNS(nsURI, aName, getter_AddRefs(element));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create element");
|
||||
|
||||
if (aNsID == kNameSpaceID_XHTML)
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
#include "XSLTFunctions.h"
|
||||
#include "ProcessorState.h"
|
||||
#include "XMLUtils.h"
|
||||
#include "Names.h"
|
||||
#include "txIXPathContext.h"
|
||||
|
||||
const String XSL_VERSION_PROPERTY("version");
|
||||
const String XSL_VENDOR_PROPERTY("vendor");
|
||||
const String XSL_VENDOR_URL_PROPERTY("vendor-url");
|
||||
#include "txAtoms.h"
|
||||
#include "XMLUtils.h"
|
||||
#include "XSLTFunctions.h"
|
||||
|
||||
/*
|
||||
Implementation of XSLT 1.0 extension function: system-property
|
||||
|
@ -17,8 +12,8 @@ const String XSL_VENDOR_URL_PROPERTY("vendor-url");
|
|||
* aNode is the Element in the stylesheet containing the
|
||||
* Expr and is used for namespaceID resolution
|
||||
**/
|
||||
SystemPropertyFunctionCall::SystemPropertyFunctionCall(Element* aNode) :
|
||||
FunctionCall(SYSTEM_PROPERTY_FN), mStylesheetNode(aNode)
|
||||
SystemPropertyFunctionCall::SystemPropertyFunctionCall(Node* aQNameResolveNode)
|
||||
: mQNameResolveNode(aQNameResolveNode)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -41,25 +36,18 @@ ExprResult* SystemPropertyFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (exprResult->getResultType() == ExprResult::STRING) {
|
||||
String property;
|
||||
exprResult->stringValue(property);
|
||||
if (XMLUtils::isValidQName(property)) {
|
||||
String prefix;
|
||||
PRInt32 namespaceID = kNameSpaceID_None;
|
||||
XMLUtils::getPrefix(property, prefix);
|
||||
if (!prefix.isEmpty()) {
|
||||
txAtom* prefixAtom = TX_GET_ATOM(prefix);
|
||||
namespaceID =
|
||||
mStylesheetNode->lookupNamespaceID(prefixAtom);
|
||||
TX_IF_RELEASE_ATOM(prefixAtom);
|
||||
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);
|
||||
}
|
||||
if (namespaceID == kNameSpaceID_XSLT) {
|
||||
String localName;
|
||||
XMLUtils::getLocalPart(property, localName);
|
||||
if (localName.isEqual(XSL_VERSION_PROPERTY))
|
||||
result = new NumberResult(1.0);
|
||||
else if (localName.isEqual(XSL_VENDOR_PROPERTY))
|
||||
result = new StringResult("Transformiix");
|
||||
else if (localName.isEqual(XSL_VENDOR_URL_PROPERTY))
|
||||
result = new StringResult("http://www.mozilla.org/projects/xslt/");
|
||||
else if (qname.mLocalName == txXSLTAtoms::vendor) {
|
||||
result = new StringResult("Transformiix");
|
||||
}
|
||||
else if (qname.mLocalName == txXSLTAtoms::vendorUrl) {
|
||||
result = new StringResult("http://www.mozilla.org/projects/xslt/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,9 +58,15 @@ ExprResult* SystemPropertyFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
}
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
else
|
||||
return new StringResult("");
|
||||
if (!result) {
|
||||
result = new StringResult("");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult SystemPropertyFunctionCall::getNameAtom(txAtom** aAtom)
|
||||
{
|
||||
*aAtom = txXSLTAtoms::systemProperty;
|
||||
TX_ADDREF_ATOM(*aAtom);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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
|
||||
* Jonas Sicking.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* Jonas Sicking. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jonas Sicking <sicking@bigfoot.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef TRANSFRMX_VARIABLEMAP_H
|
||||
#define TRANSFRMX_VARIABLEMAP_H
|
||||
|
||||
#include "txError.h"
|
||||
#include "XMLUtils.h"
|
||||
#include "ExprResult.h"
|
||||
#include "txExpandedNameMap.h"
|
||||
|
||||
class txVariableMap {
|
||||
public:
|
||||
txVariableMap(txVariableMap* aParentMap);
|
||||
|
||||
nsresult bindVariable(const txExpandedName& aName,
|
||||
ExprResult* aValue, MBool aOwned);
|
||||
|
||||
ExprResult* getVariable(const txExpandedName& aName);
|
||||
|
||||
private:
|
||||
// Parent map of variables
|
||||
txVariableMap* mParentMap;
|
||||
|
||||
// Map with owned variables
|
||||
txExpandedNameMap mOwnedVariables;
|
||||
|
||||
// Map with non-owned variables
|
||||
txExpandedNameMap mNonOwnedVariables;
|
||||
};
|
||||
|
||||
|
||||
inline txVariableMap::txVariableMap(txVariableMap* aParentMap)
|
||||
: mParentMap(aParentMap),
|
||||
mOwnedVariables(MB_TRUE),
|
||||
mNonOwnedVariables(MB_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
inline nsresult txVariableMap::bindVariable(const txExpandedName& aName,
|
||||
ExprResult* aValue, MBool aOwned)
|
||||
{
|
||||
TxObject* var = 0;
|
||||
txVariableMap* map = this;
|
||||
while (!var && map) {
|
||||
var = map->mOwnedVariables.get(aName);
|
||||
if (!var) {
|
||||
var = map->mNonOwnedVariables.get(aName);
|
||||
}
|
||||
map = map->mParentMap;
|
||||
}
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (!var) {
|
||||
if (aOwned) {
|
||||
rv = mOwnedVariables.add(aName, aValue);
|
||||
}
|
||||
else {
|
||||
rv = mNonOwnedVariables.add(aName, aValue);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline ExprResult* txVariableMap::getVariable(const txExpandedName& aName)
|
||||
{
|
||||
ExprResult* var = 0;
|
||||
txVariableMap* map = this;
|
||||
while (!var && map) {
|
||||
var = (ExprResult*)map->mOwnedVariables.get(aName);
|
||||
if (!var) {
|
||||
var = (ExprResult*)map->mNonOwnedVariables.get(aName);
|
||||
}
|
||||
map = map->mParentMap;
|
||||
}
|
||||
return var;
|
||||
}
|
||||
|
||||
|
||||
#endif //TRANSFRMX_VARIABLEMAP_H
|
|
@ -42,25 +42,26 @@ TX_ATOM(applyTemplates, "apply-templates");
|
|||
TX_ATOM(attribute, "attribute");
|
||||
TX_ATOM(attributeSet, "attribute-set");
|
||||
TX_ATOM(callTemplate, "call-template");
|
||||
TX_ATOM(caseOrder, "case-order");
|
||||
TX_ATOM(choose, "choose");
|
||||
TX_ATOM(comment, "comment");
|
||||
TX_ATOM(copy, "copy");
|
||||
TX_ATOM(copyOf, "copy-of");
|
||||
TX_ATOM(decimalFormat, "decimal-format");
|
||||
TX_ATOM(element, "element");
|
||||
TX_ATOM(fallback, "fallback");
|
||||
TX_ATOM(forEach, "for-each");
|
||||
TX_ATOM(_if, "if");
|
||||
TX_ATOM(import, "import");
|
||||
TX_ATOM(include, "include");
|
||||
TX_ATOM(key, "key");
|
||||
TX_ATOM(message, "message");
|
||||
TX_ATOM(namespaceAlias, "namespace-alias");
|
||||
TX_ATOM(number, "number");
|
||||
TX_ATOM(otherwise, "otherwise");
|
||||
TX_ATOM(output, "output");
|
||||
TX_ATOM(param, "param");
|
||||
TX_ATOM(processingInstruction, "processing-instruction");
|
||||
TX_ATOM(preserveSpace, "preserve-space");
|
||||
TX_ATOM(processingInstruction, "processing-instruction");
|
||||
TX_ATOM(sort, "sort");
|
||||
TX_ATOM(stripSpace, "strip-space");
|
||||
TX_ATOM(stylesheet, "stylesheet");
|
||||
|
@ -73,7 +74,7 @@ TX_ATOM(when, "when");
|
|||
TX_ATOM(withParam, "with-param");
|
||||
|
||||
// XSLT attributes
|
||||
TX_ATOM(case_order, "case-order");
|
||||
TX_ATOM(caseOrder, "case-order");
|
||||
TX_ATOM(cdataSectionElements, "cdata-section-elements");
|
||||
TX_ATOM(count, "count");
|
||||
TX_ATOM(dataType, "data-type");
|
||||
|
@ -124,3 +125,7 @@ TX_ATOM(functionAvailable, "function-available");
|
|||
TX_ATOM(generateId, "generate-id");
|
||||
TX_ATOM(unparsedEntityUri, "unparsed-entity-uri");
|
||||
TX_ATOM(systemProperty, "system-property");
|
||||
|
||||
// XSLT properties
|
||||
TX_ATOM(vendor, "vendor");
|
||||
TX_ATOM(vendorUrl, "vendor-url");
|
||||
|
|
|
@ -32,14 +32,14 @@
|
|||
#define TRANSFRMX_XSLT_FUNCTIONS_H
|
||||
|
||||
#include "Expr.h"
|
||||
#include "ExprResult.h"
|
||||
#include "TxString.h"
|
||||
#include "Map.h"
|
||||
#include "NamedMap.h"
|
||||
#include "List.h"
|
||||
#include "txXSLTPatterns.h"
|
||||
#include "ExprResult.h"
|
||||
|
||||
class NamedMap;
|
||||
class ProcessorState;
|
||||
class txPattern;
|
||||
|
||||
/**
|
||||
* The definition for the XSLT document() function
|
||||
**/
|
||||
|
@ -52,10 +52,7 @@ public:
|
|||
**/
|
||||
DocumentFunctionCall(ProcessorState* aPs, Node* aDefResolveNode);
|
||||
|
||||
/**
|
||||
* Virtual methods from FunctionCall
|
||||
**/
|
||||
ExprResult* evaluate(txIEvalContext* aContext);
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
ProcessorState* mProcessorState;
|
||||
|
@ -74,13 +71,7 @@ public:
|
|||
*/
|
||||
txKeyFunctionCall(ProcessorState* aPs, Node* aQNameResolveNode);
|
||||
|
||||
/*
|
||||
* Evaluates a key() xslt-functioncall. First argument is name of key
|
||||
* to use, second argument is value to look up.
|
||||
*
|
||||
* Virtual function from FunctionCall
|
||||
*/
|
||||
ExprResult* evaluate(txIEvalContext* aContext);
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
ProcessorState* mProcessorState;
|
||||
|
@ -186,10 +177,7 @@ public:
|
|||
**/
|
||||
txFormatNumberFunctionCall(ProcessorState* aPs, Node* aQNameResolveNode);
|
||||
|
||||
/**
|
||||
* Virtual function from FunctionCall
|
||||
**/
|
||||
ExprResult* evaluate(txIEvalContext* aContext);
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
static const UNICODE_CHAR FORMAT_QUOTE;
|
||||
|
@ -246,10 +234,7 @@ public:
|
|||
**/
|
||||
CurrentFunctionCall(ProcessorState* ps);
|
||||
|
||||
/**
|
||||
* Virtual function from FunctionCall
|
||||
**/
|
||||
ExprResult* evaluate(txIEvalContext* aContext);
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
ProcessorState* mPs;
|
||||
|
@ -267,15 +252,7 @@ public:
|
|||
**/
|
||||
UnparsedEntityUriFunctionCall();
|
||||
|
||||
/**
|
||||
* 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* evaluate(txIEvalContext* aContext);
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
};
|
||||
|
@ -292,15 +269,7 @@ public:
|
|||
**/
|
||||
GenerateIdFunctionCall();
|
||||
|
||||
/**
|
||||
* Evaluates this Expr based on the given context node and processor state
|
||||
* @param context the context node for evaluation of this Expr
|
||||
* @param ps the ContextState containing the stack information needed
|
||||
* for evaluation
|
||||
* @return the result of the evaluation
|
||||
* @see FunctionCall.h
|
||||
**/
|
||||
ExprResult* evaluate(txIEvalContext* aContext);
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
static const char printfFmt[];
|
||||
|
@ -318,23 +287,15 @@ public:
|
|||
* aNode is the Element in the stylesheet containing the
|
||||
* Expr and is used for namespaceID resolution
|
||||
**/
|
||||
SystemPropertyFunctionCall(Element* aNode);
|
||||
SystemPropertyFunctionCall(Node* 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* evaluate(txIEvalContext* aContext);
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
/*
|
||||
* resolve namespaceIDs with this node
|
||||
*/
|
||||
Element* mStylesheetNode;
|
||||
Node* mQNameResolveNode;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -349,23 +310,15 @@ public:
|
|||
* aNode is the Element in the stylesheet containing the
|
||||
* Expr and is used for namespaceID resolution
|
||||
**/
|
||||
ElementAvailableFunctionCall(Element* aNode);
|
||||
ElementAvailableFunctionCall(Node* 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* evaluate(txIEvalContext* aContext);
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
/*
|
||||
* resolve namespaceIDs with this node
|
||||
*/
|
||||
Element* mStylesheetNode;
|
||||
Node* mQNameResolveNode;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -378,19 +331,15 @@ public:
|
|||
/**
|
||||
* Creates a new function-available() function call
|
||||
**/
|
||||
FunctionAvailableFunctionCall();
|
||||
FunctionAvailableFunctionCall(Node* 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* evaluate(txIEvalContext* aContext);
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
private:
|
||||
/*
|
||||
* resolve namespaceIDs with this node
|
||||
*/
|
||||
Node* mQNameResolveNode;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -318,8 +318,7 @@ void txRootPattern::toString(String& aDest)
|
|||
* This looks like the id() function, but may only have LITERALs as
|
||||
* argument.
|
||||
*/
|
||||
|
||||
txIdPattern::txIdPattern(const String aString)
|
||||
txIdPattern::txIdPattern(const String& aString)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
mIds = aString;
|
||||
|
|
|
@ -159,7 +159,7 @@ private:
|
|||
class txIdPattern : public txPattern
|
||||
{
|
||||
public:
|
||||
txIdPattern(const String aString);
|
||||
txIdPattern(const String& aString);
|
||||
|
||||
~txIdPattern();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче