Cleanup the generate-id() xpath function implementation.
b=101672 r=peterv, Pike sr=jst git-svn-id: svn://10.0.0.236/trunk@103978 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
4c0f541d76
commit
f46a1c678e
@ -66,37 +66,6 @@ Node* DOMHelper::appearsFirst(Node* node1, Node* node2) {
|
||||
|
||||
} //-- compareDocumentOrders
|
||||
|
||||
/**
|
||||
* Generates a unique ID for the given node and places the result in
|
||||
* dest
|
||||
**/
|
||||
void DOMHelper::generateId(Node* node, String& dest) {
|
||||
|
||||
if (!node) {
|
||||
dest.append("<null>");
|
||||
return;
|
||||
}
|
||||
|
||||
dest.append("id");
|
||||
|
||||
if (node->getNodeType() == Node::DOCUMENT_NODE) {
|
||||
Integer::toString(NS_PTR_TO_INT32(node),dest);
|
||||
return;
|
||||
}
|
||||
|
||||
Integer::toString(NS_PTR_TO_INT32(node->getOwnerDocument()), dest);
|
||||
|
||||
OrderInfo* orderInfo = getDocumentOrder(node);
|
||||
|
||||
int i = 0;
|
||||
while (i < orderInfo->size) {
|
||||
dest.append('.');
|
||||
Integer::toString(orderInfo->order[i], dest);
|
||||
++i;
|
||||
}
|
||||
|
||||
} //-- generateId
|
||||
|
||||
//-------------------/
|
||||
//- Private Methods -/
|
||||
//-------------------/
|
||||
|
||||
@ -80,12 +80,6 @@ public:
|
||||
**/
|
||||
Node* appearsFirst(Node* node1, Node* node2);
|
||||
|
||||
/**
|
||||
* Generates a unique ID for the given node and places the result in
|
||||
* dest
|
||||
**/
|
||||
void generateId(Node* node, String& dest);
|
||||
|
||||
/**
|
||||
* Returns the child number of the given node. Numbering
|
||||
* starts at 1 for all nodes except the Document node and
|
||||
|
||||
@ -424,14 +424,6 @@ Element* ProcessorState::findTemplate(Node* node, Node* context, String* mode) {
|
||||
return matchTemplate;
|
||||
} //-- 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
|
||||
* or null if no AttributeSet is found
|
||||
@ -866,7 +858,7 @@ FunctionCall* ProcessorState::resolveFunctionCall(const String& name) {
|
||||
err.append(name);
|
||||
}
|
||||
else if (GENERATE_ID_FN.isEqual(name)) {
|
||||
return new GenerateIdFunctionCall(&domHelper);
|
||||
return new GenerateIdFunctionCall();
|
||||
}
|
||||
else if (SYSTEM_PROPERTY_FN.isEqual(name)) {
|
||||
return new SystemPropertyFunctionCall();
|
||||
|
||||
@ -96,12 +96,6 @@ public:
|
||||
**/
|
||||
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
|
||||
* or null if no AttributeSet is found
|
||||
|
||||
@ -24,18 +24,28 @@
|
||||
|
||||
#include "XSLTFunctions.h"
|
||||
#include "Names.h"
|
||||
#ifdef TX_EXE
|
||||
#include "stdio.h"
|
||||
#else
|
||||
#include "prprf.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
Implementation of XSLT 1.0 extension function: generate-id
|
||||
*/
|
||||
|
||||
#ifndef HAVE_64BIT_OS
|
||||
char* GenerateIdFunctionCall::printfFmt = "id0x%08p";
|
||||
#else
|
||||
char* GenerateIdFunctionCall::printfFmt = "id0x%016p";
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Creates a new generate-id function call
|
||||
**/
|
||||
GenerateIdFunctionCall::GenerateIdFunctionCall(DOMHelper* domHelper) : FunctionCall(GENERATE_ID_FN)
|
||||
{
|
||||
this->domHelper = domHelper;
|
||||
} //-- GenerateIdFunctionCall
|
||||
GenerateIdFunctionCall::GenerateIdFunctionCall()
|
||||
: FunctionCall(GENERATE_ID_FN)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Evaluates this Expr based on the given context node and processor state
|
||||
@ -45,40 +55,53 @@ GenerateIdFunctionCall::GenerateIdFunctionCall(DOMHelper* domHelper) : FunctionC
|
||||
* @return the result of the evaluation
|
||||
* @see FunctionCall.h
|
||||
**/
|
||||
ExprResult* GenerateIdFunctionCall::evaluate(Node* context, ContextState* cs) {
|
||||
ExprResult* GenerateIdFunctionCall::evaluate(Node* aContext,
|
||||
ContextState* aCs) {
|
||||
|
||||
Node* node = context;
|
||||
if (!requireParams(0, 1, aCs))
|
||||
return new StringResult();
|
||||
|
||||
int argc = params.getLength();
|
||||
Node* node = 0;
|
||||
|
||||
StringResult* stringResult = 0;
|
||||
// get node to generate id for
|
||||
if (params.getLength() == 1) {
|
||||
txListIterator iter(¶ms);
|
||||
Expr* param = (Expr*)iter.next();
|
||||
|
||||
if (argc > 0) {
|
||||
ListIterator* iter = params.iterator();
|
||||
Expr* param = (Expr*) iter->next();
|
||||
delete iter;
|
||||
ExprResult* exprResult = param->evaluate(context, cs);
|
||||
if (!exprResult) return new StringResult("");
|
||||
if (exprResult->getResultType() == ExprResult::NODESET) {
|
||||
NodeSet* nodes = (NodeSet*) exprResult;
|
||||
if (nodes->size() == 0)
|
||||
stringResult = new StringResult("");
|
||||
else
|
||||
node = nodes->get(0);
|
||||
ExprResult* exprResult = param->evaluate(aContext, aCs);
|
||||
if (!exprResult)
|
||||
return 0;
|
||||
|
||||
if (exprResult->getResultType() != ExprResult::NODESET) {
|
||||
String err("Invalid argument passed to generate-id(), "
|
||||
"expecting NodeSet");
|
||||
aCs->recieveError(err);
|
||||
delete exprResult;
|
||||
return new StringResult(err);
|
||||
}
|
||||
else {
|
||||
String err("Invalid argument passed to generate-id(), expecting NodeSet");
|
||||
stringResult = new StringResult(err);
|
||||
|
||||
NodeSet* nodes = (NodeSet*) exprResult;
|
||||
if (nodes->size() > 0) {
|
||||
aCs->sortByDocumentOrder(nodes);
|
||||
node = nodes->get(0);
|
||||
}
|
||||
delete exprResult;
|
||||
}
|
||||
else {
|
||||
node = aContext;
|
||||
}
|
||||
|
||||
if (stringResult) return stringResult;
|
||||
|
||||
//-- generate id for selected node
|
||||
String id;
|
||||
domHelper->generateId(node, id);
|
||||
return new StringResult(id);
|
||||
|
||||
} //-- evaluate
|
||||
|
||||
// generate id for selected node
|
||||
char buf[22];
|
||||
if (node) {
|
||||
#ifdef TX_EXE
|
||||
sprintf(buf, printfFmt, node);
|
||||
#else
|
||||
PR_snprintf(buf, 21, printfFmt, node);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
buf[0] = 0;
|
||||
}
|
||||
return new StringResult(buf);
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ public:
|
||||
/**
|
||||
* Creates a new generate-id() function call
|
||||
**/
|
||||
GenerateIdFunctionCall(DOMHelper* domHelper);
|
||||
GenerateIdFunctionCall();
|
||||
|
||||
/**
|
||||
* Evaluates this Expr based on the given context node and processor state
|
||||
@ -278,7 +278,7 @@ public:
|
||||
virtual ExprResult* evaluate(Node* context, ContextState* cs);
|
||||
|
||||
private:
|
||||
DOMHelper* domHelper;
|
||||
static char* printfFmt;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user