зеркало из https://github.com/mozilla/gecko-dev.git
added support for extension functions
This commit is contained in:
Родитель
f6d198df5e
Коммит
6f10680737
|
@ -25,18 +25,9 @@
|
||||||
* - changed constant short declarations in many of the classes
|
* - changed constant short declarations in many of the classes
|
||||||
* with enumerations, commented with //--LF
|
* with enumerations, commented with //--LF
|
||||||
*
|
*
|
||||||
* $Id: Expr.h,v 1.3 2000/04/12 22:32:25 nisheeth%netscape.com Exp $
|
* $Id: Expr.h,v 1.4 2000/04/19 10:35:49 kvisco%ziplink.net Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* XSL expression class definitions.
|
|
||||||
* Much of this code was ported from XSL:P. <BR />
|
|
||||||
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
|
|
||||||
* @version $Revision: 1.3 $ $Date: 2000/04/12 22:32:25 $
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef TRANSFRMX_EXPR_H
|
|
||||||
#define TRANSFRMX_EXPR_H
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "TxString.h"
|
#include "TxString.h"
|
||||||
|
@ -50,6 +41,22 @@
|
||||||
#include "MITREObject.h"
|
#include "MITREObject.h"
|
||||||
#include "primitives.h"
|
#include "primitives.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
XPath class definitions.
|
||||||
|
Much of this code was ported from XSL:P.
|
||||||
|
@version $Revision: 1.4 $ $Date: 2000/04/19 10:35:49 $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TRANSFRMX_EXPR_H
|
||||||
|
#define TRANSFRMX_EXPR_H
|
||||||
|
|
||||||
|
|
||||||
|
//necessary prototypes
|
||||||
|
class FunctionCall;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The expression context and state class used when evaluating XPath Expressions.
|
||||||
|
**/
|
||||||
class ContextState : public ErrorObserver {
|
class ContextState : public ErrorObserver {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -81,6 +88,13 @@ public:
|
||||||
virtual MBool isStripSpaceAllowed(Node* node) = 0;
|
virtual MBool isStripSpaceAllowed(Node* node) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a call to the function that has the given name.
|
||||||
|
* This method is used for XPath Extension Functions.
|
||||||
|
* @return the FunctionCall for the function with the given name.
|
||||||
|
**/
|
||||||
|
virtual FunctionCall* resolveFunctionCall(const String& name) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the given NodeSet by DocumentOrder.
|
* Sorts the given NodeSet by DocumentOrder.
|
||||||
* @param nodes the NodeSet to sort
|
* @param nodes the NodeSet to sort
|
||||||
|
@ -125,6 +139,88 @@ public:
|
||||||
}; //-- Expr
|
}; //-- Expr
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a FunctionCall as defined by the XPath 1.0
|
||||||
|
* Recommendation.
|
||||||
|
**/
|
||||||
|
class FunctionCall : public Expr {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const String INVALID_PARAM_COUNT;
|
||||||
|
|
||||||
|
|
||||||
|
virtual ~FunctionCall();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the given parameter to this FunctionCall's parameter list
|
||||||
|
* @param expr the Expr to add to this FunctionCall's parameter list
|
||||||
|
**/
|
||||||
|
void addParam(Expr* expr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
**/
|
||||||
|
virtual ExprResult* evaluate(Node* context, ContextState* cs) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of this FunctionCall
|
||||||
|
* @return the name of this FunctionCall
|
||||||
|
**/
|
||||||
|
const String& getName();
|
||||||
|
|
||||||
|
virtual MBool requireParams(int paramCountMin, ContextState* cs);
|
||||||
|
|
||||||
|
virtual MBool requireParams(int paramCountMin,
|
||||||
|
int paramCountMax,
|
||||||
|
ContextState* cs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the function name of this FunctionCall
|
||||||
|
* @param name the name of this Function
|
||||||
|
**/
|
||||||
|
void setName(const String& name);
|
||||||
|
/**
|
||||||
|
* Returns the String representation of this Pattern.
|
||||||
|
* @param dest the String to use when creating the String
|
||||||
|
* representation. The String representation will be appended to
|
||||||
|
* any data in the destination String, to allow cascading calls to
|
||||||
|
* other #toString() methods for Expressions.
|
||||||
|
* @return the String representation of this Pattern.
|
||||||
|
**/
|
||||||
|
virtual void toString(String& dest);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
List params;
|
||||||
|
|
||||||
|
FunctionCall();
|
||||||
|
FunctionCall(const String& name);
|
||||||
|
FunctionCall(const String& name, List* parameters);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluates the given Expression and converts it's result to a String.
|
||||||
|
* The value is appended to the given destination String
|
||||||
|
**/
|
||||||
|
void evaluateToString
|
||||||
|
(Expr* expr, Node* context, ContextState* cs, String& dest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluates the given Expression and converts it's result to a number.
|
||||||
|
**/
|
||||||
|
double evaluateToNumber(Expr* expr, Node* context, ContextState* cs);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
String name;
|
||||||
|
}; //-- FunctionCall
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base Pattern class
|
* A base Pattern class
|
||||||
**/
|
**/
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* -- fixed bug in ::parsePredicates,
|
* -- fixed bug in ::parsePredicates,
|
||||||
* made sure we continue looking for more predicates.
|
* made sure we continue looking for more predicates.
|
||||||
*
|
*
|
||||||
* $Id: ExprParser.cpp,v 1.3 2000/04/14 02:04:50 Peter.VanderBeken%pandora.be Exp $
|
* $Id: ExprParser.cpp,v 1.4 2000/04/19 10:35:52 kvisco%ziplink.net Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
* This class is used to parse XSL Expressions
|
* This class is used to parse XSL Expressions
|
||||||
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
|
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
|
||||||
* @see ExprLexer
|
* @see ExprLexer
|
||||||
* @version $Revision: 1.3 $ $Date: 2000/04/14 02:04:50 $
|
* @version $Revision: 1.4 $ $Date: 2000/04/19 10:35:52 $
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "ExprParser.h"
|
#include "ExprParser.h"
|
||||||
|
@ -468,10 +468,9 @@ FunctionCall* ExprParser::createFunctionCall(ExprLexer& lexer) {
|
||||||
}
|
}
|
||||||
// OG-
|
// OG-
|
||||||
else {
|
else {
|
||||||
//-- create error function() for now, should be ext function
|
//-- Most likely an Extension Function, or error, but it's
|
||||||
String err = "not a valid function: ";
|
//-- not our job to report an invalid function call here
|
||||||
err.append(tok->value);
|
fnCall = new ExtensionFunctionCall(fnName);
|
||||||
fnCall = new ErrorFunctionCall(err);
|
|
||||||
}
|
}
|
||||||
//-- handle parametes
|
//-- handle parametes
|
||||||
List params;
|
List params;
|
||||||
|
|
|
@ -0,0 +1,126 @@
|
||||||
|
/*
|
||||||
|
* 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 XSL:P XSLT processor.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Keith Visco.
|
||||||
|
* Portions created by Keith Visco are Copyright (C) 1999, 2000 Keith Visco.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Keith Visco, kvisco@ziplink.net
|
||||||
|
* -- original author.
|
||||||
|
*
|
||||||
|
* $Id: ExtensionFunctionCall.cpp,v 1.1 2000/04/19 10:35:59 kvisco%ziplink.net Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FunctionLib.h"
|
||||||
|
|
||||||
|
|
||||||
|
const String ExtensionFunctionCall::UNDEFINED_FUNCTION = "Undefined Function: ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an ExtensionFunctionCall with the given function name.
|
||||||
|
* @param name the name of the extension function which to invoke
|
||||||
|
**/
|
||||||
|
ExtensionFunctionCall::ExtensionFunctionCall(const String& name) : FunctionCall(name)
|
||||||
|
{
|
||||||
|
this->fname = name;
|
||||||
|
this->fnCall = 0;
|
||||||
|
|
||||||
|
} //-- ExtensionFunctionCall
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an instance of ExtensionFunctioncall
|
||||||
|
**/
|
||||||
|
ExtensionFunctionCall::~ExtensionFunctionCall() {
|
||||||
|
delete fnCall;
|
||||||
|
} //-- ~ExtensionFunctionCall
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
**/
|
||||||
|
ExprResult* ExtensionFunctionCall::evaluate(Node* context, ContextState* cs) {
|
||||||
|
|
||||||
|
//-- check for existing function call resolution
|
||||||
|
|
||||||
|
if (!fnCall) {
|
||||||
|
fnCall = cs->resolveFunctionCall(fname);
|
||||||
|
|
||||||
|
if (!fnCall) {
|
||||||
|
String err(UNDEFINED_FUNCTION);
|
||||||
|
err.append(fname);
|
||||||
|
return new StringResult(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
//copy parameters
|
||||||
|
ListIterator* iter = params.iterator();
|
||||||
|
Expr* param = 0;
|
||||||
|
|
||||||
|
while (iter->hasNext()) {
|
||||||
|
fnCall->addParam( new ExprWrapper( (Expr*) iter->next() ) );
|
||||||
|
}
|
||||||
|
delete iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-- delegate
|
||||||
|
return fnCall->evaluate(context, cs);
|
||||||
|
|
||||||
|
} //-- evaluate
|
||||||
|
|
||||||
|
//---------------------------------/
|
||||||
|
//- Implementation of ExprWrapper -/
|
||||||
|
//---------------------------------/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ExprWrapper for the given Expr
|
||||||
|
**/
|
||||||
|
ExprWrapper::ExprWrapper(Expr* expr) {
|
||||||
|
this->expr = expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for ExprWrapper
|
||||||
|
**/
|
||||||
|
ExprWrapper::~ExprWrapper() {
|
||||||
|
//-- DO NOTHING!
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
**/
|
||||||
|
ExprResult* ExprWrapper::evaluate(Node* context, ContextState* cs) {
|
||||||
|
//-- just delegate
|
||||||
|
if (!expr) return 0; // <-- hopefully this will never happen
|
||||||
|
return expr->evaluate(context, cs);
|
||||||
|
} //-- evaluate
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the String representation of this Expr.
|
||||||
|
* @param dest the String to use when creating the String
|
||||||
|
* representation. The String representation will be appended to
|
||||||
|
* any data in the destination String, to allow cascading calls to
|
||||||
|
* other #toString() methods for Expressions.
|
||||||
|
* @return the String representation of this Expr.
|
||||||
|
**/
|
||||||
|
void ExprWrapper::toString(String& str) {
|
||||||
|
//-- just delegate
|
||||||
|
if (expr) expr->toString(str);
|
||||||
|
} //-- toString
|
||||||
|
|
|
@ -21,15 +21,15 @@
|
||||||
* Keith Visco, kvisco@ziplink.net
|
* Keith Visco, kvisco@ziplink.net
|
||||||
* -- original author.
|
* -- original author.
|
||||||
*
|
*
|
||||||
* $Id: FunctionCall.cpp,v 1.1 2000/04/06 07:45:30 kvisco%ziplink.net Exp $
|
* $Id: FunctionCall.cpp,v 1.2 2000/04/19 10:36:17 kvisco%ziplink.net Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FunctionLib.h"
|
#include "Expr.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a FunctionCall as defined by the XSL Working Draft
|
* This class represents a FunctionCall as defined by the XSL Working Draft
|
||||||
* @author <A HREF="mailto:kvisco@ziplink">Keith Visco</A>
|
* @author <A HREF="mailto:kvisco@ziplink">Keith Visco</A>
|
||||||
* @version $Revision: 1.1 $ $Date: 2000/04/06 07:45:30 $
|
* @version $Revision: 1.2 $ $Date: 2000/04/19 10:36:17 $
|
||||||
**/
|
**/
|
||||||
|
|
||||||
const String FunctionCall::INVALID_PARAM_COUNT =
|
const String FunctionCall::INVALID_PARAM_COUNT =
|
||||||
|
|
|
@ -24,14 +24,9 @@
|
||||||
* Olivier Gerardin, ogerardin@vo.lu
|
* Olivier Gerardin, ogerardin@vo.lu
|
||||||
* -- added number functions
|
* -- added number functions
|
||||||
*
|
*
|
||||||
* $Id: FunctionLib.h,v 1.4 2000/04/14 02:05:21 Peter.VanderBeken%pandora.be Exp $
|
* $Id: FunctionLib.h,v 1.5 2000/04/19 10:36:18 kvisco%ziplink.net Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MITREXSL_FUNCTIONLIB_H
|
|
||||||
#define MITREXSL_FUNCTIONLIB_H
|
|
||||||
|
|
||||||
#include "TxString.h"
|
#include "TxString.h"
|
||||||
#include "primitives.h"
|
#include "primitives.h"
|
||||||
#include "NodeSet.h"
|
#include "NodeSet.h"
|
||||||
|
@ -44,6 +39,11 @@
|
||||||
#include "XMLUtils.h"
|
#include "XMLUtils.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef TRANSFRMX_FUNCTIONLIB_H
|
||||||
|
#define TRANSFRMX_FUNCTIONLIB_H
|
||||||
|
|
||||||
|
|
||||||
class XPathNames {
|
class XPathNames {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -80,14 +80,16 @@ static const String ERROR_FN;
|
||||||
|
|
||||||
}; //-- XPathNames
|
}; //-- XPathNames
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a FunctionCall as defined by the XSL
|
* The following are definitions for the XPath functions
|
||||||
* Working Draft.
|
*
|
||||||
* This file was ported from XSL:P <BR />
|
|
||||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
|
||||||
* <BR/>
|
|
||||||
* <PRE>
|
* <PRE>
|
||||||
* Modifications:
|
* Modifications:
|
||||||
|
* 20000418: Keith Visco
|
||||||
|
* -- added ExtensionFunctionCall
|
||||||
|
*
|
||||||
* 19990805: Keith Visco
|
* 19990805: Keith Visco
|
||||||
* - added NodeSetFunctionCall
|
* - added NodeSetFunctionCall
|
||||||
* - moved position() function into NodeSetFunctionCall
|
* - moved position() function into NodeSetFunctionCall
|
||||||
|
@ -100,94 +102,16 @@ static const String ERROR_FN;
|
||||||
* - stated using Larry's enum suggestion instead of using static const shorts,
|
* - stated using Larry's enum suggestion instead of using static const shorts,
|
||||||
* as you can see, I am a Java developer! ;-)
|
* as you can see, I am a Java developer! ;-)
|
||||||
* </PRE>
|
* </PRE>
|
||||||
**/
|
*/
|
||||||
class FunctionCall : public Expr {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
static const String INVALID_PARAM_COUNT;
|
|
||||||
|
|
||||||
|
|
||||||
virtual ~FunctionCall();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the given parameter to this FunctionCall's parameter list
|
|
||||||
* @param expr the Expr to add to this FunctionCall's parameter list
|
|
||||||
**/
|
|
||||||
void addParam(Expr* expr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
**/
|
|
||||||
virtual ExprResult* evaluate(Node* context, ContextState* cs) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of this FunctionCall
|
|
||||||
* @return the name of this FunctionCall
|
|
||||||
**/
|
|
||||||
const String& getName();
|
|
||||||
|
|
||||||
virtual MBool requireParams(int paramCountMin, ContextState* cs);
|
|
||||||
|
|
||||||
virtual MBool requireParams(int paramCountMin,
|
|
||||||
int paramCountMax,
|
|
||||||
ContextState* cs);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the function name of this FunctionCall
|
|
||||||
* @param name the name of this Function
|
|
||||||
**/
|
|
||||||
void setName(const String& name);
|
|
||||||
/**
|
|
||||||
* Returns the String representation of this Pattern.
|
|
||||||
* @param dest the String to use when creating the String
|
|
||||||
* representation. The String representation will be appended to
|
|
||||||
* any data in the destination String, to allow cascading calls to
|
|
||||||
* other #toString() methods for Expressions.
|
|
||||||
* @return the String representation of this Pattern.
|
|
||||||
**/
|
|
||||||
virtual void toString(String& dest);
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
List params;
|
|
||||||
|
|
||||||
FunctionCall();
|
|
||||||
FunctionCall(const String& name);
|
|
||||||
FunctionCall(const String& name, List* parameters);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluates the given Expression and converts it's result to a String.
|
|
||||||
* The value is appended to the given destination String
|
|
||||||
**/
|
|
||||||
void evaluateToString
|
|
||||||
(Expr* expr, Node* context, ContextState* cs, String& dest);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluates the given Expression and converts it's result to a number.
|
|
||||||
**/
|
|
||||||
double evaluateToNumber(Expr* expr, Node* context, ContextState* cs);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
String name;
|
|
||||||
}; //-- FunctionCall
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the Set of boolean functions
|
* Represents the Set of boolean functions
|
||||||
* @author <a href="mailto:kvisco@mitre.org">Keith Visco</a>
|
|
||||||
**/
|
**/
|
||||||
class BooleanFunctionCall : public FunctionCall {
|
class BooleanFunctionCall : public FunctionCall {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum BooleanFunctions { TX_BOOLEAN = 1, TX_FALSE, TX_NOT, TX_TRUE };
|
enum booleanFunctions { TX_BOOLEAN = 1, TX_FALSE, TX_NOT, TX_TRUE };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a default BooleanFunctionCall, which always evaluates to False
|
* Creates a default BooleanFunctionCall, which always evaluates to False
|
||||||
|
@ -239,6 +163,89 @@ private:
|
||||||
|
|
||||||
}; //-- ErrorFunctionCall
|
}; //-- ErrorFunctionCall
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for extension functions
|
||||||
|
**/
|
||||||
|
class ExtensionFunctionCall : public FunctionCall {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const String UNDEFINED_FUNCTION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ExtensionFunctionCall with the given function name
|
||||||
|
* @param name the name of the extension function
|
||||||
|
**/
|
||||||
|
ExtensionFunctionCall(const String& name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for extension function call
|
||||||
|
**/
|
||||||
|
virtual ~ExtensionFunctionCall();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
**/
|
||||||
|
virtual ExprResult* evaluate(Node* context, ContextState* cs);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
String fname;
|
||||||
|
FunctionCall* fnCall;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used by ExtensionFunctionCall, to prevent deletion
|
||||||
|
* of the parameter expressions, by the resolved function call. The implementation
|
||||||
|
* for this class is in ExtensionFunctionCall.cpp
|
||||||
|
**/
|
||||||
|
class ExprWrapper : public Expr {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ExprWrapper for the given Expr
|
||||||
|
**/
|
||||||
|
ExprWrapper(Expr* expr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for ExprWrapper
|
||||||
|
**/
|
||||||
|
virtual ~ExprWrapper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
**/
|
||||||
|
virtual ExprResult* evaluate(Node* context, ContextState* cs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the String representation of this Expr.
|
||||||
|
* @param dest the String to use when creating the String
|
||||||
|
* representation. The String representation will be appended to
|
||||||
|
* any data in the destination String, to allow cascading calls to
|
||||||
|
* other #toString() methods for Expressions.
|
||||||
|
* @return the String representation of this Expr.
|
||||||
|
**/
|
||||||
|
virtual void toString(String& str);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Expr* expr;
|
||||||
|
|
||||||
|
}; //-- ExprWrapper
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the XPath NodeSet function calls
|
* Represents the XPath NodeSet function calls
|
||||||
**/
|
**/
|
||||||
|
@ -246,7 +253,7 @@ class NodeSetFunctionCall : public FunctionCall {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum _NodeSetFunctions {
|
enum nodeSetFunctions {
|
||||||
COUNT = 1, //-- count()
|
COUNT = 1, //-- count()
|
||||||
LAST, //-- last()
|
LAST, //-- last()
|
||||||
LOCAL_NAME, //-- local-name()
|
LOCAL_NAME, //-- local-name()
|
||||||
|
@ -286,7 +293,7 @@ class StringFunctionCall : public FunctionCall {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum _StringFunctions {
|
enum stringFunctions {
|
||||||
CONCAT = 1, //-- concat()
|
CONCAT = 1, //-- concat()
|
||||||
CONTAINS, //-- contains()
|
CONTAINS, //-- contains()
|
||||||
NORMALIZE, //-- normalize()
|
NORMALIZE, //-- normalize()
|
||||||
|
@ -331,11 +338,11 @@ class NumberFunctionCall : public FunctionCall {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum _NumberFunctions {
|
enum numberFunctions {
|
||||||
NUMBER = 1, //-- number()
|
NUMBER = 1, //-- number()
|
||||||
ROUND, //-- round()
|
ROUND, //-- round()
|
||||||
FLOOR, //-- floor()
|
FLOOR, //-- floor()
|
||||||
CEILING //-- ceiling()
|
CEILING //-- ceiling()
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,15 +39,16 @@ XPATH_OBJS = AdditiveExpr.o \
|
||||||
RootExpr.o \
|
RootExpr.o \
|
||||||
StringExpr.o \
|
StringExpr.o \
|
||||||
StringResult.o \
|
StringResult.o \
|
||||||
TextExpr.o \
|
TextExpr.o \
|
||||||
UnionExpr.o \
|
UnionExpr.o \
|
||||||
VariableRefExpr.o \
|
VariableRefExpr.o \
|
||||||
WildCardExpr.o \
|
WildCardExpr.o \
|
||||||
XPathNames.o
|
XPathNames.o
|
||||||
|
|
||||||
FUNCTION_CALL_OBJS = \
|
FUNCTION_CALL_OBJS = \
|
||||||
BooleanFunctionCall.o \
|
BooleanFunctionCall.o \
|
||||||
ErrorFunctionCall.o \
|
ErrorFunctionCall.o \
|
||||||
|
ExtensionFunctionCall.o \
|
||||||
FunctionCall.o \
|
FunctionCall.o \
|
||||||
NodeSetFunctionCall.o \
|
NodeSetFunctionCall.o \
|
||||||
NumberFunctionCall.o \
|
NumberFunctionCall.o \
|
||||||
|
@ -144,6 +145,9 @@ XPathNames.o: FunctionLib.h XPathNames.cpp
|
||||||
$(CC) $(INCLUDE_PATHS) -c XPathNames.cpp
|
$(CC) $(INCLUDE_PATHS) -c XPathNames.cpp
|
||||||
|
|
||||||
|
|
||||||
|
FunctionCall.o: Expr.h FunctionCall.cpp
|
||||||
|
$(CC) $(INCLUDE_PATHS) -c FunctionCall.cpp
|
||||||
|
|
||||||
########################
|
########################
|
||||||
## FunctionCall package
|
## FunctionCall package
|
||||||
########################
|
########################
|
||||||
|
@ -155,8 +159,8 @@ BooleanFunctionCall.o: FunctionLib.h BooleanFunctionCall.cpp
|
||||||
ErrorFunctionCall.o: FunctionLib.h ErrorFunctionCall.cpp
|
ErrorFunctionCall.o: FunctionLib.h ErrorFunctionCall.cpp
|
||||||
$(CC) $(INCLUDE_PATHS) -c ErrorFunctionCall.cpp
|
$(CC) $(INCLUDE_PATHS) -c ErrorFunctionCall.cpp
|
||||||
|
|
||||||
FunctionCall.o: FunctionLib.h FunctionCall.cpp
|
ExtensionFunctionCall.o: FunctionLib.h ExtensionFunctionCall.cpp
|
||||||
$(CC) $(INCLUDE_PATHS) -c FunctionCall.cpp
|
$(CC) $(INCLUDE_PATHS) -c ExtensionFunctionCall.cpp
|
||||||
|
|
||||||
NodeSetFunctionCall.o: FunctionLib.h NodeSetFunctionCall.cpp
|
NodeSetFunctionCall.o: FunctionLib.h NodeSetFunctionCall.cpp
|
||||||
$(CC) $(INCLUDE_PATHS) -c NodeSetFunctionCall.cpp
|
$(CC) $(INCLUDE_PATHS) -c NodeSetFunctionCall.cpp
|
||||||
|
@ -166,3 +170,7 @@ NumberFunctionCall.o: FunctionLib.h NumberFunctionCall.cpp
|
||||||
|
|
||||||
StringFunctionCall.o: FunctionLib.h StringFunctionCall.cpp
|
StringFunctionCall.o: FunctionLib.h StringFunctionCall.cpp
|
||||||
$(CC) $(INCLUDE_PATHS) -c StringFunctionCall.cpp
|
$(CC) $(INCLUDE_PATHS) -c StringFunctionCall.cpp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ DOM_PATH = $(XML_PATH)/dom
|
||||||
NET_PATH = $(ROOT_PATH)/net
|
NET_PATH = $(ROOT_PATH)/net
|
||||||
XPATH_PATH = $(ROOT_PATH)/xpath
|
XPATH_PATH = $(ROOT_PATH)/xpath
|
||||||
XSLTUTIL_PATH = ./util
|
XSLTUTIL_PATH = ./util
|
||||||
|
XSLTFUNC_PATH = ./functions
|
||||||
XMLPRINTER_PATH = $(XML_PATH)/printer
|
XMLPRINTER_PATH = $(XML_PATH)/printer
|
||||||
XMLPARSER_PATH = $(XML_PATH)/parser
|
XMLPARSER_PATH = $(XML_PATH)/parser
|
||||||
EXPAT_PARSER_PATH = $(XMLPARSER_PATH)/xmlparse
|
EXPAT_PARSER_PATH = $(XMLPARSER_PATH)/xmlparse
|
||||||
|
@ -18,11 +19,12 @@ EXPAT_TOKEN_PATH = $(XMLPARSER_PATH)/xmltok
|
||||||
|
|
||||||
|
|
||||||
INCLUDE_PATHS = -I. \
|
INCLUDE_PATHS = -I. \
|
||||||
-I$(BASE_PATH) \
|
-I$(BASE_PATH) \
|
||||||
-I$(NET_PATH) \
|
-I$(NET_PATH) \
|
||||||
-I$(DOM_PATH) \
|
-I$(DOM_PATH) \
|
||||||
-I$(XPATH_PATH) \
|
-I$(XPATH_PATH) \
|
||||||
-I$(XSLTUTIL_PATH) \
|
-I$(XSLTUTIL_PATH) \
|
||||||
|
-I$(XSLTFUNC_PATH) \
|
||||||
-I$(XML_PATH) \
|
-I$(XML_PATH) \
|
||||||
-I$(XMLUTIL_PATH) \
|
-I$(XMLUTIL_PATH) \
|
||||||
-I$(XMLPARSER_PATH) \
|
-I$(XMLPARSER_PATH) \
|
||||||
|
|
|
@ -21,14 +21,14 @@
|
||||||
* Keith Visco, kvisco@ziplink.net
|
* Keith Visco, kvisco@ziplink.net
|
||||||
* -- original author.
|
* -- original author.
|
||||||
*
|
*
|
||||||
* $Id: ProcessorState.cpp,v 1.1 2000/04/06 07:46:41 kvisco%ziplink.net Exp $
|
* $Id: ProcessorState.cpp,v 1.2 2000/04/19 10:41:13 kvisco%ziplink.net Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of ProcessorState
|
* Implementation of ProcessorState
|
||||||
* This code was ported from XSL:P
|
* This code was ported from XSL:P
|
||||||
* @author <a href="kvisco@ziplink.net">Keith Visco</a>
|
* @author <a href="kvisco@ziplink.net">Keith Visco</a>
|
||||||
* @version $Revision: 1.1 $ $Date: 2000/04/06 07:46:41 $
|
* @version $Revision: 1.2 $ $Date: 2000/04/19 10:41:13 $
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "ProcessorState.h"
|
#include "ProcessorState.h"
|
||||||
|
@ -291,6 +291,15 @@ Element* ProcessorState::findTemplate(Node* node, Node* context, String* mode) {
|
||||||
return matchTemplate;
|
return matchTemplate;
|
||||||
} //-- findTemplate
|
} //-- findTemplate
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a unique ID for the given node and places the result in
|
||||||
|
* dest
|
||||||
|
**/
|
||||||
|
void ProcessorState::generateId(Node* node, String& dest) {
|
||||||
|
domHelper.generateId(node, dest);
|
||||||
|
} //-- generateId
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the AttributeSet associated with the given name
|
* Returns the AttributeSet associated with the given name
|
||||||
* or null if no AttributeSet is found
|
* or null if no AttributeSet is found
|
||||||
|
@ -568,6 +577,24 @@ void ProcessorState::recieveError(String& errorMessage, ErrorLevel level) {
|
||||||
delete iter;
|
delete iter;
|
||||||
} //-- recieveError
|
} //-- recieveError
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a call to the function that has the given name.
|
||||||
|
* This method is used for XPath Extension Functions.
|
||||||
|
* @return the FunctionCall for the function with the given name.
|
||||||
|
**/
|
||||||
|
FunctionCall* ProcessorState::resolveFunctionCall(const String& name) {
|
||||||
|
|
||||||
|
if (GENERATE_ID_FN.isEqual(name)) {
|
||||||
|
return new GenerateIdFunctionCall(&domHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
String err("invalid function call: ");
|
||||||
|
err.append(name);
|
||||||
|
|
||||||
|
return new ErrorFunctionCall(err);
|
||||||
|
|
||||||
|
} //-- resolveFunctionCall
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the given NodeSet by DocumentOrder.
|
* Sorts the given NodeSet by DocumentOrder.
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
* Keith Visco, kvisco@ziplink.net
|
* Keith Visco, kvisco@ziplink.net
|
||||||
* -- original author.
|
* -- original author.
|
||||||
*
|
*
|
||||||
* $Id: ProcessorState.h,v 1.1 2000/04/06 07:46:46 kvisco%ziplink.net Exp $
|
* $Id: ProcessorState.h,v 1.2 2000/04/19 10:41:13 kvisco%ziplink.net Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,11 +45,12 @@
|
||||||
#include "Tokenizer.h"
|
#include "Tokenizer.h"
|
||||||
#include "VariableBinding.h"
|
#include "VariableBinding.h"
|
||||||
#include "OutputFormat.h"
|
#include "OutputFormat.h"
|
||||||
|
#include "XSLTFunctions.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class used for keeping the current state of the XSL Processor
|
* Class used for keeping the current state of the XSL Processor
|
||||||
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
|
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
|
||||||
* @version $Revision: 1.1 $ $Date: 2000/04/06 07:46:46 $
|
* @version $Revision: 1.2 $ $Date: 2000/04/19 10:41:13 $
|
||||||
**/
|
**/
|
||||||
class ProcessorState : public ContextState
|
class ProcessorState : public ContextState
|
||||||
{
|
{
|
||||||
|
@ -107,6 +108,12 @@ public:
|
||||||
**/
|
**/
|
||||||
Node* copyNode(Node* node);
|
Node* copyNode(Node* node);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a unique ID for the given node and places the result in
|
||||||
|
* dest
|
||||||
|
**/
|
||||||
|
void generateId(Node* node, String& dest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the AttributeSet associated with the given name
|
* Returns the AttributeSet associated with the given name
|
||||||
* or null if no AttributeSet is found
|
* or null if no AttributeSet is found
|
||||||
|
@ -246,6 +253,13 @@ public:
|
||||||
**/
|
**/
|
||||||
virtual void recieveError(String& errorMessage, ErrorLevel level);
|
virtual void recieveError(String& errorMessage, ErrorLevel level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a call to the function that has the given name.
|
||||||
|
* This method is used for XPath Extension Functions.
|
||||||
|
* @return the FunctionCall for the function with the given name.
|
||||||
|
**/
|
||||||
|
virtual FunctionCall* resolveFunctionCall(const String& name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the given NodeSet by DocumentOrder.
|
* Sorts the given NodeSet by DocumentOrder.
|
||||||
* @param nodes the NodeSet to sort
|
* @param nodes the NodeSet to sort
|
||||||
|
|
Загрузка…
Ссылка в новой задаче