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:
peterv%netscape.com 2002-08-06 12:28:27 +00:00
Родитель d4b6f606a9
Коммит 8046e251db
66 изменённых файлов: 1246 добавлений и 1192 удалений

Просмотреть файл

@ -119,7 +119,6 @@ LOBJS =../source/base/ArrayList.$(OBJ_SUFFIX) \
../source/xpath/UnionExpr.$(OBJ_SUFFIX) \
../source/xpath/UnaryExpr.$(OBJ_SUFFIX) \
../source/xpath/VariableRefExpr.$(OBJ_SUFFIX) \
../source/xpath/XPathNames.$(OBJ_SUFFIX) \
../source/xml/XMLUtils.$(OBJ_SUFFIX) \
../source/xml/XMLDOMUtils.$(OBJ_SUFFIX) \
../source/xml/parser/XMLParser.$(OBJ_SUFFIX) \
@ -132,7 +131,6 @@ LOBJS =../source/base/ArrayList.$(OBJ_SUFFIX) \
../source/xslt/txMozillaXMLOutput.$(OBJ_SUFFIX) \
../source/xslt/txRtfHandler.$(OBJ_SUFFIX) \
../source/xslt/txTextHandler.$(OBJ_SUFFIX) \
../source/xslt/VariableBinding.$(OBJ_SUFFIX) \
../source/xslt/txXSLTPatterns.$(OBJ_SUFFIX) \
../source/xslt/txPatternParser.$(OBJ_SUFFIX) \
../source/xslt/XSLTProcessor.$(OBJ_SUFFIX) \

Просмотреть файл

@ -106,7 +106,6 @@ CPP_OBJS= \
..\source\xpath\$(OBJDIR)\UnionExpr.obj \
..\source\xpath\$(OBJDIR)\UnaryExpr.obj \
..\source\xpath\$(OBJDIR)\VariableRefExpr.obj \
..\source\xpath\$(OBJDIR)\XPathNames.obj \
..\source\xml\$(OBJDIR)\XMLUtils.obj \
..\source\xml\$(OBJDIR)\XMLDOMUtils.obj \
..\source\xml\parser\$(OBJDIR)\nsSyncLoader.obj \
@ -119,7 +118,6 @@ CPP_OBJS= \
..\source\xslt\$(OBJDIR)\txMozillaXMLOutput.obj \
..\source\xslt\$(OBJDIR)\txRtfHandler.obj \
..\source\xslt\$(OBJDIR)\txTextHandler.obj \
..\source\xslt\$(OBJDIR)\VariableBinding.obj \
..\source\xslt\$(OBJDIR)\txXSLTPatterns.obj \
..\source\xslt\$(OBJDIR)\txPatternParser.obj \
..\source\xslt\$(OBJDIR)\XSLTProcessor.obj \

Просмотреть файл

@ -1135,13 +1135,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>VariableBinding.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>FilterExpr.cpp</PATH>
@ -1170,13 +1163,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XPathNames.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>StringFunctionCall.cpp</PATH>
@ -1793,11 +1779,6 @@
<PATH>txURIUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>VariableBinding.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>FilterExpr.cpp</PATH>
@ -1818,11 +1799,6 @@
<PATH>FunctionCall.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>XPathNames.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>StringFunctionCall.cpp</PATH>
@ -3221,13 +3197,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>VariableBinding.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>FilterExpr.cpp</PATH>
@ -3256,13 +3225,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XPathNames.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>StringFunctionCall.cpp</PATH>
@ -3895,11 +3857,6 @@
<PATH>txURIUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>VariableBinding.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>FilterExpr.cpp</PATH>
@ -3920,11 +3877,6 @@
<PATH>FunctionCall.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>XPathNames.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>StringFunctionCall.cpp</PATH>
@ -4769,12 +4721,6 @@
<PATH>VariableRefExpr.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>XPathNames.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>xslt</NAME>
<FILEREF>
@ -4837,12 +4783,6 @@
<PATH>txXSLTPatterns.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>VariableBinding.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

Просмотреть файл

@ -174,9 +174,8 @@ double Double::toDouble(const String& aSrc)
// "."==NaN, ".0"=="0."==0
if (digitFound && idx == len) {
char* buf = aSrc.toCharArray();
double res = buf ? atof(buf) : Double::NaN;
delete [] buf;
NS_LossyConvertUCS2toASCII buf(aSrc);
double res = buf.get() ? atof(buf.get()) : Double::NaN;
return res;
}

Просмотреть файл

@ -436,18 +436,3 @@ MBool String::isEqual(const char* aData) const
}
return MB_TRUE;
}
char* String::toCharArray() const
{
char* tmpBuffer = new char[mLength + 1];
NS_ASSERTION(tmpBuffer, "out of memory");
if (tmpBuffer) {
PRUint32 conversionLoop;
for (conversionLoop = 0; conversionLoop < mLength; ++conversionLoop) {
tmpBuffer[conversionLoop] = (char)mBuffer[conversionLoop];
}
tmpBuffer[mLength] = 0;
}
return tmpBuffer;
}

Просмотреть файл

@ -51,12 +51,12 @@ public:
*/
String();
#ifdef TX_EXE
/*
* Copying constructor.
*/
String(const String& aSource);
#ifdef TX_EXE
/*
* Constructor, allocates a buffer and copies the supplied string buffer.
* If aLength is zero it computes the length from the supplied string.
@ -173,12 +173,12 @@ public:
/*
* Return a reference to this string's nsString.
*/
nsString& getNSString();
operator nsAString&();
/*
* Return a const reference to this string's nsString.
*/
const nsString& getConstNSString() const;
operator const nsAString&() const;
#endif
private:
@ -201,10 +201,8 @@ private:
*/
static PRUint32 unicodeLength(const UNICODE_CHAR* aData);
/*
* Translate UNICODE_CHARs to Chars and output to the provided stream.
*/
friend ostream& operator << (ostream& aOutput, const String& aSource);
friend class txCharBuffer;
UNICODE_CHAR* mBuffer;
PRUint32 mBufferLength;
@ -217,11 +215,59 @@ public:
explicit String(const char* aSource); // XXX Used for literal strings
void append(const char* aSource);
MBool isEqual(const char* aData) const;
char* toCharArray() const;
#ifndef TX_EXE
nsString& getNSString();
const nsString& getConstNSString() const;
#endif
// XXX DEPRECATED
};
#ifdef TX_EXE
/*
* A helper class for getting a char* buffer out of a String.
* Don't use this directly, use NS_LossyConvertUCS2toASCII which
* is typedef'ed to this class on standalone and will fall back
* on the Mozilla implementation for the Mozilla module.
*/
class txCharBuffer
{
public:
txCharBuffer(const String& aString) : mString(aString),
mBuffer(0)
{
};
~txCharBuffer()
{
delete [] mBuffer;
};
const char* get()
{
if (!mBuffer) {
mBuffer = new char[mString.mLength + 1];
NS_ASSERTION(mBuffer, "out of memory");
if (mBuffer) {
PRUint32 loop;
for (loop = 0; loop < mString.mLength; ++loop) {
mBuffer[loop] = (char)mString.mBuffer[loop];
}
mBuffer[mString.mLength] = 0;
}
}
return mBuffer;
}
private:
const String& mString;
char* mBuffer;
};
typedef txCharBuffer NS_LossyConvertUCS2toASCII;
/*
* Translate UNICODE_CHARs to Chars and output to the provided stream.
*/
ostream& operator << (ostream& aOutput, const String& aSource);
inline UNICODE_CHAR String::charAt(PRUint32 aIndex) const

Просмотреть файл

@ -155,7 +155,7 @@ private:
typedef nsIAtom txAtom;
#define TX_GET_ATOM(str) \
NS_NewAtom((str).getConstNSString())
NS_NewAtom(str)
#define TX_ADDREF_ATOM(atom) NS_ADDREF(atom)
@ -166,7 +166,7 @@ typedef nsIAtom txAtom;
#define TX_IF_RELEASE_ATOM(atom) NS_IF_RELEASE(atom)
#define TX_GET_ATOM_STRING(atom, string) \
NS_SUCCEEDED((atom)->ToString(string.getNSString()))
NS_SUCCEEDED((atom)->ToString(string))
#endif // TX_EXE

Просмотреть файл

@ -50,6 +50,11 @@ inline String::String()
MOZ_COUNT_CTOR(String);
}
inline String::String(const String& aSource) : mString(aSource.mString)
{
MOZ_COUNT_CTOR(String);
}
inline String::String(const nsAString& aSource) : mString(aSource)
{
MOZ_COUNT_CTOR(String);
@ -157,12 +162,14 @@ inline void String::truncate(PRUint32 aLength)
inline String& String::subString(PRUint32 aStart, String& aDest) const
{
PRUint32 length = mString.Length() - aStart;
if (length < 0) {
aDest.clear();
PRUint32 length = mString.Length();
if (aStart < length) {
aDest.mString.Assign(Substring(mString, aStart, length - aStart));
}
else {
aDest.mString.Assign(Substring(mString, aStart, length));
NS_ASSERTION(aStart == length,
"Bonehead! Calling subString with negative length.");
aDest.clear();
}
return aDest;
}
@ -170,12 +177,13 @@ inline String& String::subString(PRUint32 aStart, String& aDest) const
inline String& String::subString(PRUint32 aStart, PRUint32 aEnd,
String& aDest) const
{
PRUint32 length = aEnd - aStart;
if (length < 0) {
aDest.clear();
if (aStart < aEnd) {
aDest.mString.Assign(Substring(mString, aStart, aEnd - aStart));
}
else {
aDest.mString.Assign(Substring(mString, aStart, length));
NS_ASSERTION(aStart == aEnd,
"Bonehead! Calling subString with negative length.");
aDest.clear();
}
return aDest;
}
@ -190,12 +198,12 @@ inline void String::toUpperCase()
ToUpperCase(mString);
}
inline nsString& String::getNSString()
inline String::operator nsAString&()
{
return mString;
}
inline const nsString& String::getConstNSString() const
inline String::operator const nsAString&() const
{
return mString;
}
@ -223,9 +231,14 @@ inline MBool String::isEqual(const char* aData) const
return mString.EqualsWithConversion(aData);
}
inline char* String::toCharArray() const
inline nsString& String::getNSString()
{
return ToNewCString(mString);
return mString;
}
inline const nsString& String::getConstNSString() const
{
return mString;
}
#endif // txMozillaString_h__

Просмотреть файл

@ -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) \

Просмотреть файл

@ -87,7 +87,6 @@ CPP_OBJS= \
../xpath/$(OBJDIR)/UnionExpr.obj \
../xpath/$(OBJDIR)/UnaryExpr.obj \
../xpath/$(OBJDIR)/VariableRefExpr.obj \
../xpath/$(OBJDIR)/XPathNames.obj \
../xml/$(OBJDIR)/XMLUtils.obj \
../xml/$(OBJDIR)/XMLDOMUtils.obj \
../xml/parser/$(OBJDIR)/XMLParser.obj \
@ -103,7 +102,6 @@ CPP_OBJS= \
../xslt/$(OBJDIR)/txXMLOutput.obj \
../xslt/$(OBJDIR)/txXSLTPatterns.obj \
../xslt/$(OBJDIR)/txPatternParser.obj \
../xslt/$(OBJDIR)/VariableBinding.obj \
../xslt/$(OBJDIR)/XSLTProcessor.obj \
../xslt/functions/$(OBJDIR)/CurrentFunctionCall.obj \
../xslt/functions/$(OBJDIR)/DocumentFunctionCall.obj \

Просмотреть файл

@ -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();

Просмотреть файл

@ -73,7 +73,7 @@ const String& Attr::getName()
nodeName.clear();
if (nsAttr)
nsAttr->GetName(nodeName.getNSString());
nsAttr->GetName(nodeName);
return nodeName;
}
@ -104,7 +104,7 @@ const String& Attr::getValue()
nodeValue.clear();
if (nsAttr)
nsAttr->GetValue(nodeValue.getNSString());
nsAttr->GetValue(nodeValue);
return nodeValue;
}
@ -118,7 +118,7 @@ void Attr::setValue(const String& aNewValue)
NSI_FROM_TX(Attr)
if (nsAttr)
nsAttr->SetValue(aNewValue.getConstNSString());
nsAttr->SetValue(aNewValue);
}
/*

Просмотреть файл

@ -57,7 +57,7 @@ const String& CharacterData::getData()
nodeValue.clear();
if (nsCharacterData)
nsCharacterData->GetData(nodeValue.getNSString());
nsCharacterData->GetData(nodeValue);
return nodeValue;
}
@ -71,7 +71,7 @@ void CharacterData::setData(const String& aData)
NSI_FROM_TX(CharacterData)
if (nsCharacterData)
nsCharacterData->SetData(aData.getConstNSString());
nsCharacterData->SetData(aData);
}
/**
@ -106,7 +106,7 @@ String& CharacterData::substringData(PRUint32 aOffset, PRUint32 aCount,
aDest.clear();
if (nsCharacterData)
nsCharacterData->SubstringData(aOffset, aCount, aDest.getNSString());
nsCharacterData->SubstringData(aOffset, aCount, aDest);
return aDest;
}
@ -120,7 +120,7 @@ void CharacterData::appendData(const String& aSource)
NSI_FROM_TX(CharacterData)
if (nsCharacterData)
nsCharacterData->AppendData(aSource.getConstNSString());
nsCharacterData->AppendData(aSource);
}
/**
@ -134,7 +134,7 @@ void CharacterData::insertData(PRUint32 aOffset, const String& aSource)
NSI_FROM_TX(CharacterData)
if (nsCharacterData)
nsCharacterData->InsertData(aOffset, aSource.getConstNSString());
nsCharacterData->InsertData(aOffset, aSource);
}
/**
@ -164,5 +164,5 @@ void CharacterData::replaceData(PRUint32 aOffset, PRUint32 aCount,
NSI_FROM_TX(CharacterData)
if (nsCharacterData)
nsCharacterData->ReplaceData(aOffset, aCount, aSource.getConstNSString());
nsCharacterData->ReplaceData(aOffset, aCount, aSource);
}

Просмотреть файл

@ -62,8 +62,7 @@ MBool DOMImplementation::hasFeature(const String& aFeature,
MBool bHasFeature = MB_FALSE;
if (nsDOMImplementation)
nsDOMImplementation->HasFeature(aFeature.getConstNSString(), aVersion.getConstNSString(),
&bHasFeature);
nsDOMImplementation->HasFeature(aFeature, aVersion, &bHasFeature);
return bHasFeature;
}

Просмотреть файл

@ -199,7 +199,7 @@ Element* Document::createElement(const String& aTagName)
NSI_FROM_TX_NULL_CHECK(Document)
nsCOMPtr<nsIDOMElement> element;
if (NS_SUCCEEDED(nsDocument->CreateElement(aTagName.getConstNSString(),
if (NS_SUCCEEDED(nsDocument->CreateElement(aTagName,
getter_AddRefs(element))))
return createElement(element);
else
@ -218,7 +218,7 @@ Element* Document::getElementById(const String aID)
NSI_FROM_TX_NULL_CHECK(Document)
nsCOMPtr<nsIDOMElement> element;
if (NS_SUCCEEDED(nsDocument->GetElementById(aID.getConstNSString(), getter_AddRefs(element))))
if (NS_SUCCEEDED(nsDocument->GetElementById(aID, getter_AddRefs(element))))
return createElement(element);
else
return NULL;
@ -248,7 +248,7 @@ Element* Document::createElementNS(const String& aNamespaceURI,
nsCOMPtr<nsIDOMElement> element;
if (NS_SUCCEEDED(nsDocument->CreateElementNS(
aNamespaceURI.getConstNSString(), aTagName.getConstNSString(),
aNamespaceURI, aTagName,
getter_AddRefs(element))))
return createElement(element);
else
@ -267,7 +267,7 @@ Attr* Document::createAttribute(const String& aName)
NSI_FROM_TX_NULL_CHECK(Document)
nsCOMPtr<nsIDOMAttr> attr;
if (NS_SUCCEEDED(nsDocument->CreateAttribute(aName.getConstNSString(),
if (NS_SUCCEEDED(nsDocument->CreateAttribute(aName,
getter_AddRefs(attr))))
return createAttribute(attr);
else
@ -289,7 +289,7 @@ Attr* Document::createAttributeNS(const String& aNamespaceURI,
nsCOMPtr<nsIDOMAttr> attr;
if (NS_SUCCEEDED(nsDocument->CreateAttributeNS(
aNamespaceURI.getConstNSString(), aName.getConstNSString(),
aNamespaceURI, aName,
getter_AddRefs(attr))))
return createAttribute(attr);
else
@ -317,7 +317,7 @@ Text* Document::createTextNode(const String& aData)
NSI_FROM_TX_NULL_CHECK(Document)
nsCOMPtr<nsIDOMText> text;
if (NS_SUCCEEDED(nsDocument->CreateTextNode(aData.getConstNSString(),
if (NS_SUCCEEDED(nsDocument->CreateTextNode(aData,
getter_AddRefs(text))))
return createTextNode(text);
else
@ -345,7 +345,7 @@ Comment* Document::createComment(const String& aData)
NSI_FROM_TX_NULL_CHECK(Document)
nsCOMPtr<nsIDOMComment> comment;
if (NS_SUCCEEDED(nsDocument->CreateComment(aData.getConstNSString(),
if (NS_SUCCEEDED(nsDocument->CreateComment(aData,
getter_AddRefs(comment))))
return createComment(comment);
else
@ -373,7 +373,7 @@ CDATASection* Document::createCDATASection(const String& aData)
NSI_FROM_TX_NULL_CHECK(Document)
nsCOMPtr<nsIDOMCDATASection> cdata;
if (NS_SUCCEEDED(nsDocument->CreateCDATASection(aData.getConstNSString(),
if (NS_SUCCEEDED(nsDocument->CreateCDATASection(aData,
getter_AddRefs(cdata))))
return createCDATASection(cdata);
else
@ -406,7 +406,7 @@ ProcessingInstruction* Document::createProcessingInstruction(
nsCOMPtr<nsIDOMProcessingInstruction> pi;
if (NS_SUCCEEDED(nsDocument->CreateProcessingInstruction(
aTarget.getConstNSString(), aData.getConstNSString(),
aTarget, aData,
getter_AddRefs(pi))))
return createProcessingInstruction(pi);
else
@ -435,7 +435,7 @@ EntityReference* Document::createEntityReference(const String& aName)
NSI_FROM_TX_NULL_CHECK(Document)
nsCOMPtr<nsIDOMEntityReference> entityRef;
if (NS_SUCCEEDED(nsDocument->CreateEntityReference(aName.getConstNSString(),
if (NS_SUCCEEDED(nsDocument->CreateEntityReference(aName,
getter_AddRefs(entityRef))))
return createEntityReference(entityRef);
else
@ -641,7 +641,7 @@ PRInt32 Document::namespaceURIToID(const String& aNamespaceURI)
{
PRInt32 namesspaceID = kNameSpaceID_Unknown;
if (nsNSManager)
nsNSManager->RegisterNameSpace(aNamespaceURI.getConstNSString(),
nsNSManager->RegisterNameSpace(aNamespaceURI,
namesspaceID);
return namesspaceID;
}
@ -650,6 +650,6 @@ void Document::namespaceIDToURI(PRInt32 aNamespaceID, String& aNamespaceURI)
{
if (nsNSManager)
nsNSManager->GetNameSpaceURI(aNamespaceID,
aNamespaceURI.getNSString());
aNamespaceURI);
return;
}

Просмотреть файл

@ -57,7 +57,7 @@ const String& DocumentType::getName()
nodeName.clear();
if (nsDocumentType)
nsDocumentType->GetName(nodeName.getNSString());
nsDocumentType->GetName(nodeName);
return nodeName;
}

Просмотреть файл

@ -64,7 +64,7 @@ const String& Element::getTagName()
nodeName.clear();
if (nsElement)
nsElement->GetTagName(nodeName.getNSString());
nsElement->GetTagName(nodeName);
return nodeName;
}
@ -96,7 +96,7 @@ void Element::setAttribute(const String& aName, const String& aValue)
NSI_FROM_TX(Element)
if (nsElement)
nsElement->SetAttribute(aName.getConstNSString(), aValue.getConstNSString());
nsElement->SetAttribute(aName, aValue);
}
/*
@ -113,9 +113,9 @@ void Element::setAttributeNS(const String& aNamespaceURI, const String& aName,
NSI_FROM_TX(Element)
if (nsElement)
nsElement->SetAttributeNS(aNamespaceURI.getConstNSString(),
aName.getConstNSString(),
aValue.getConstNSString());
nsElement->SetAttributeNS(aNamespaceURI,
aName,
aValue);
}
/*
@ -134,7 +134,7 @@ void Element::removeAttribute(const String& aName)
Attr* attrWrapper = NULL;
// First, get the nsIDOMAttr object from the nsIDOMElement object
nsElement->GetAttributeNode(aName.getConstNSString(), getter_AddRefs(attr));
nsElement->GetAttributeNode(aName, getter_AddRefs(attr));
// Second, remove the attribute wrapper object from the hash table if it is
// there. It might not be if the attribute was created using
@ -144,7 +144,7 @@ void Element::removeAttribute(const String& aName)
delete attrWrapper;
// Lastly, have the Mozilla object remove the attribute
nsElement->RemoveAttribute(aName.getConstNSString());
nsElement->RemoveAttribute(aName);
}
}
@ -161,7 +161,7 @@ Attr* Element::getAttributeNode(const String& aName)
NSI_FROM_TX_NULL_CHECK(Element)
nsCOMPtr<nsIDOMAttr> attr;
if (NS_SUCCEEDED(nsElement->GetAttributeNode(aName.getConstNSString(),
if (NS_SUCCEEDED(nsElement->GetAttributeNode(aName,
getter_AddRefs(attr))) && attr)
return (Attr*)ownerDocument->createWrapper(attr);
return NULL;
@ -179,7 +179,7 @@ MBool Element::getAttr(txAtom* aLocalName, PRInt32 aNSID,
if (!cont)
return MB_FALSE;
nsresult rv;
rv = cont->GetAttr(aNSID, aLocalName, aValue.getNSString());
rv = cont->GetAttr(aNSID, aLocalName, aValue);
NS_ENSURE_SUCCESS(rv, MB_FALSE);
if (rv != NS_CONTENT_ATTR_NOT_THERE)
return MB_TRUE;
@ -261,7 +261,7 @@ NodeList* Element::getElementsByTagName(const String& aName)
NSI_FROM_TX_NULL_CHECK(Element)
nsCOMPtr<nsIDOMNodeList> list;
if (NS_SUCCEEDED(nsElement->GetElementsByTagName(aName.getConstNSString(),
if (NS_SUCCEEDED(nsElement->GetElementsByTagName(aName,
getter_AddRefs(list))))
return ownerDocument->createNodeList(list);
return NULL;

Просмотреть файл

@ -56,7 +56,7 @@ const String& Entity::getPublicId()
publicId.clear();
if (nsEntity)
nsEntity->GetPublicId(publicId.getNSString());
nsEntity->GetPublicId(publicId);
return publicId;
}
@ -71,7 +71,7 @@ const String& Entity::getSystemId()
systemId.clear();
if (nsEntity)
nsEntity->GetSystemId(systemId.getNSString());
nsEntity->GetSystemId(systemId);
return systemId;
}
@ -87,6 +87,6 @@ const String& Entity::getNotationName()
notationName.clear();
if (nsEntity)
nsEntity->GetNotationName(notationName.getNSString());
nsEntity->GetNotationName(notationName);
return notationName;
}

Просмотреть файл

@ -60,7 +60,7 @@ Node* NamedNodeMap::getNamedItem(const String& aName)
NSI_FROM_TX_NULL_CHECK(NamedNodeMap)
nsCOMPtr<nsIDOMNode> node;
if (NS_SUCCEEDED(nsNamedNodeMap->GetNamedItem(aName.getConstNSString(),
if (NS_SUCCEEDED(nsNamedNodeMap->GetNamedItem(aName,
getter_AddRefs(node))))
return ownerDocument->createWrapper(node);
else
@ -100,7 +100,7 @@ Node* NamedNodeMap::removeNamedItem(const String& aName)
NSI_FROM_TX_NULL_CHECK(NamedNodeMap)
nsCOMPtr<nsIDOMNode> node;
if (NS_SUCCEEDED(nsNamedNodeMap->RemoveNamedItem(aName.getConstNSString(),
if (NS_SUCCEEDED(nsNamedNodeMap->RemoveNamedItem(aName,
getter_AddRefs(node))))
return ownerDocument->createWrapper(node);
else

Просмотреть файл

@ -90,7 +90,7 @@ const String& Node::getNodeName()
nodeName.clear();
if (nsNode)
nsNode->GetNodeName(nodeName.getNSString());
nsNode->GetNodeName(nodeName);
return nodeName;
}
@ -105,7 +105,7 @@ const String& Node::getNodeValue()
nodeValue.clear();
if (nsNode)
nsNode->GetNodeValue(nodeValue.getNSString());
nsNode->GetNodeValue(nodeValue);
return nodeValue;
}
@ -256,7 +256,7 @@ void Node::setNodeValue(const String& aNewNodeValue)
NSI_FROM_TX(Node)
if (nsNode)
nsNode->SetNodeValue(aNewNodeValue.getConstNSString());
nsNode->SetNodeValue(aNewNodeValue);
}
/*
@ -390,7 +390,7 @@ String Node::getNamespaceURI()
NSI_FROM_TX(Node)
String uri;
if (nsNode)
nsNode->GetNamespaceURI(uri.getNSString());
nsNode->GetNamespaceURI(uri);
return uri;
}
@ -510,7 +510,7 @@ String Node::getBaseURI()
String url;
if (nsDOM3Node)
nsDOM3Node->GetBaseURI(url.getNSString());
nsDOM3Node->GetBaseURI(url);
return url;
}

Просмотреть файл

@ -57,7 +57,7 @@ const String& Notation::getPublicId()
publicId.clear();
if (nsNotation)
nsNotation->GetPublicId(publicId.getNSString());
nsNotation->GetPublicId(publicId);
return publicId;
}
@ -72,6 +72,6 @@ const String& Notation::getSystemId()
systemId.clear();
if (nsNotation)
nsNotation->GetSystemId(systemId.getNSString());
nsNotation->GetSystemId(systemId);
return systemId;
}

Просмотреть файл

@ -64,7 +64,7 @@ const String& ProcessingInstruction::getTarget()
target.clear();
if (nsProcessingInstruction)
nsProcessingInstruction->GetTarget(target.getNSString());
nsProcessingInstruction->GetTarget(target);
return target;
}
@ -80,7 +80,7 @@ const String& ProcessingInstruction::getData()
data.clear();
if (nsProcessingInstruction)
nsProcessingInstruction->GetData(data.getNSString());
nsProcessingInstruction->GetData(data);
return data;
}
@ -95,7 +95,7 @@ void ProcessingInstruction::setData(const String& aData)
NSI_FROM_TX(ProcessingInstruction)
if (nsProcessingInstruction)
nsProcessingInstruction->SetData(aData.getConstNSString());
nsProcessingInstruction->SetData(aData);
}
/*

Просмотреть файл

@ -70,7 +70,7 @@ Document* XMLParser::getDocumentFromURI(const String& href,
{
#ifndef TX_EXE
nsCOMPtr<nsIURI> documentURI;
nsresult rv = NS_NewURI(getter_AddRefs(documentURI), href.getConstNSString());
nsresult rv = NS_NewURI(getter_AddRefs(documentURI), href);
NS_ENSURE_SUCCESS(rv, NULL);
nsCOMPtr<nsISyncLoader> loader = do_CreateInstance(TRANSFORMIIX_SYNCLOADER_CONTRACTID, &rv);

Просмотреть файл

@ -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(&params);
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(&params);
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;

Просмотреть файл

@ -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 \

Просмотреть файл

@ -347,6 +347,15 @@ Node* NodeSet::get(int aIndex) const
return mElements[aIndex];
}
/*
* Clones this ExprResult
* @return clone of this ExprResult
*/
ExprResult* NodeSet::clone()
{
return new NodeSet(*this);
}
/*
* Returns the type of ExprResult represented
* @return the type of ExprResult represented

Просмотреть файл

@ -167,6 +167,7 @@ public:
/*
* Virtual methods from ExprResult
*/
ExprResult* clone();
short getResultType();
MBool booleanValue();
double numberValue();

Просмотреть файл

@ -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.

Просмотреть файл

@ -1,62 +0,0 @@
/*
* 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 The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved.
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* Marina Mechtcheriakova, mmarina@mindspring.com
* -- added LANG_FN
*
*/
/**
* XPath names
**/
#include "FunctionLib.h"
//-- Function Names
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");

Просмотреть файл

@ -67,7 +67,6 @@ CPP_OBJS= \
.\$(OBJDIR)\UnionExpr.obj \
.\$(OBJDIR)\UnaryExpr.obj \
.\$(OBJDIR)\VariableRefExpr.obj \
.\$(OBJDIR)\XPathNames.obj \
!if !defined(TX_EXE)
.\$(OBJDIR)\nsXPathEvaluator.obj \
.\$(OBJDIR)\nsXPathException.obj \

Просмотреть файл

@ -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;

Просмотреть файл

@ -52,7 +52,6 @@ CPPSRCS = Names.cpp \
ProcessorState.cpp \
txRtfHandler.cpp \
txTextHandler.cpp \
VariableBinding.cpp \
txXSLTPatterns.cpp \
txPatternParser.cpp \
XSLTProcessor.cpp

Просмотреть файл

@ -37,68 +37,17 @@
#include "Names.h"
//-- Global Strings
const String HTML("html");
const String HTML_NS("http://www.w3.org/1999/xhtml");
const String STYLESHEET_PI("xml-stylesheet");
const String STYLESHEET_PI_OLD("xml:stylesheet");
const String XML_SPACE("xml:space");
const String XSL_MIME_TYPE("text/xsl");
const String XSLT_NS("http://www.w3.org/1999/XSL/Transform");
//-- Elements
const String APPLY_IMPORTS("apply-imports");
const String APPLY_TEMPLATES("apply-templates");
const String ATTRIBUTE("attribute");
const String ATTRIBUTE_SET("attribute-set");
const String CALL_TEMPLATE("call-template");
const String CHOOSE("choose");
const String COMMENT("comment");
const String COPY("copy");
const String COPY_OF("copy-of");
const String DECIMAL_FORMAT("decimal-format");
const String ELEMENT("element");
const String FOR_EACH("for-each");
const String IF("if");
const String IMPORT("import");
const String INCLUDE("include");
const String KEY("key");
const String MESSAGE("message");
const String NUMBER("number");
const String OTHERWISE("otherwise");
const String OUTPUT("output");
const String PARAM("param");
const String PROC_INST("processing-instruction");
const String PRESERVE_SPACE("preserve-space");
const String SORT("sort");
const String STRIP_SPACE("strip-space");
const String TEMPLATE("template");
const String TEXT("text");
const String VALUE_OF("value-of");
const String VARIABLE("variable");
const String WHEN("when");
const String WITH_PARAM("with-param");
//-- Attributes
const String ELEMENTS_ATTR("elements");
const String HREF_ATTR("href");
const String MATCH_ATTR("match");
const String MODE_ATTR("mode");
const String NAME_ATTR("name");
const String SELECT_ATTR("select");
const String TEST_ATTR("test");
const String USE_ATTR("use");
//-- Attribute Values
const String ANY_VALUE("any");
const String ASCENDING_VALUE("ascending");
const String DESCENDING_VALUE("descending");
const String LOWER_FIRST_VALUE("lower-first");
const String MULTIPLE_VALUE("multiple");
const String NO_VALUE("no");
const String NUMBER_VALUE("number");
const String PRESERVE_VALUE("preserve");
const String SINGLE_VALUE("single");
const String STRIP_VALUE("strip");
const String TEXT_VALUE("text");
const String UPPER_FIRST_VALUE("upper-first");
const String YES_VALUE("yes");
@ -117,27 +66,3 @@ const String PARENT_AXIS("parent");
const String PRECEDING_AXIS("preceding");
const String PRECEDING_SIBLING_AXIS("preceding-sibling");
const String SELF_AXIS("self");
//-- NodeTest Operators
const String ATTRIBUTE_FNAME("@");
const String COMMENT_FNAME("comment");
const String PI_FNAME("processing-instruction");
const String TEXT_FNAME("text");
const String NODE_FNAME("node");
const String IDENTITY_OP(".");
const String PARENT_OP("..");
//-- XSLT additional functions
const String DOCUMENT_FN("document");
const String KEY_FN("key");
const String FORMAT_NUMBER_FN("format-number");
const String CURRENT_FN("current");
const String UNPARSED_ENTITY_URI_FN("unparsed-entity-uri");
const String GENERATE_ID_FN("generate-id");
const String SYSTEM_PROPERTY_FN("system-property");
const String ELEMENT_AVAILABLE_FN("element-available");
const String FUNCTION_AVAILABLE_FN("function-available");
//-- MISC
const String WILD_CARD("*");

Просмотреть файл

@ -35,69 +35,17 @@
#include "TxString.h"
//-- Global Strings
extern const String HTML;
extern const String HTML_NS;
extern const String STYLESHEET_PI;
extern const String STYLESHEET_PI_OLD;
extern const String XML_SPACE;
extern const String XSL_MIME_TYPE;
extern const String XSLT_NS;
//-- Elements
extern const String APPLY_IMPORTS;
extern const String APPLY_TEMPLATES;
extern const String ATTRIBUTE;
extern const String ATTRIBUTE_SET;
extern const String CALL_TEMPLATE;
extern const String CHOOSE;
extern const String COMMENT;
extern const String COPY;
extern const String COPY_OF;
extern const String DECIMAL_FORMAT;
extern const String ELEMENT;
extern const String FOR_EACH;
extern const String IF;
extern const String IMPORT;
extern const String INCLUDE;
extern const String KEY;
extern const String MESSAGE;
extern const String NUMBER;
extern const String OTHERWISE;
extern const String OUTPUT;
extern const String PARAM;
extern const String PROC_INST;
extern const String PRESERVE_SPACE;
extern const String STRIP_SPACE;
extern const String SORT;
extern const String TEMPLATE;
extern const String TEXT;
extern const String VALUE_OF;
extern const String VARIABLE;
extern const String WHEN;
extern const String WITH_PARAM;
//-- Attributes
extern const String ELEMENTS_ATTR;
extern const String HREF_ATTR;
extern const String MATCH_ATTR;
extern const String MODE_ATTR;
extern const String NAME_ATTR;
extern const String SELECT_ATTR;
extern const String TEST_ATTR;
extern const String USE_ATTR;
//-- Attribute Values
extern const String ANY_VALUE;
extern const String ASCENDING_VALUE;
extern const String DESCENDING_VALUE;
extern const String LOWER_FIRST_VALUE;
extern const String MULTIPLE_VALUE;
extern const String NO_VALUE;
extern const String NUMBER_VALUE;
extern const String PRESERVE_VALUE;
extern const String SINGLE_VALUE;
extern const String STRIP_VALUE;
extern const String TEXT_VALUE;
extern const String UPPER_FIRST_VALUE;
extern const String YES_VALUE;
@ -117,28 +65,4 @@ extern const String PRECEDING_AXIS;
extern const String PRECEDING_SIBLING_AXIS;
extern const String SELF_AXIS;
//-- NodeTest Operators
extern const String ATTRIBUTE_FNAME;
extern const String COMMENT_FNAME;
extern const String PI_FNAME;
extern const String TEXT_FNAME;
extern const String NODE_FNAME;
extern const String IDENTITY_OP;
extern const String PARENT_OP;
//-- XSLT additional functions
extern const String DOCUMENT_FN;
extern const String KEY_FN;
extern const String FORMAT_NUMBER_FN;
extern const String CURRENT_FN;
extern const String UNPARSED_ENTITY_URI_FN;
extern const String GENERATE_ID_FN;
extern const String SYSTEM_PROPERTY_FN;
extern const String ELEMENT_AVAILABLE_FN;
extern const String FUNCTION_AVAILABLE_FN;
//-- MISC
extern const String WILD_CARD;
#endif

Просмотреть файл

@ -39,12 +39,14 @@
#include "XMLUtils.h"
#include "XMLDOMUtils.h"
#include "Tokenizer.h"
#include "VariableBinding.h"
#include "ExprResult.h"
#include "Names.h"
#include "XMLParser.h"
#include "TxLog.h"
#include "txAtoms.h"
#include "XSLTProcessor.h"
#include "txSingleNodeContext.h"
#include "txVariableMap.h"
/**
* Creates a new ProcessorState for the given XSL document
@ -58,17 +60,14 @@ ProcessorState::ProcessorState(Document* aSourceDocument,
mEvalContext(0),
mSourceDocument(aSourceDocument),
xslDocument(aXslDocument),
resultDocument(aResultDocument)
resultDocument(aResultDocument),
mLocalVariables(0),
mGlobalVariableValues(MB_TRUE)
{
NS_ASSERTION(aSourceDocument, "missing source document");
NS_ASSERTION(aXslDocument, "missing xslt document");
NS_ASSERTION(aResultDocument, "missing result document");
// add global variable set
NamedMap* globalVars = new NamedMap();
globalVars->setObjectDeletion(MB_TRUE);
variableSets.push(globalVars);
/* turn object deletion on for some of the Maps (NamedMap) */
mExprHashes[SelectAttr].setOwnership(Map::eOwnsItems);
mExprHashes[TestAttr].setOwnership(Map::eOwnsItems);
@ -93,10 +92,6 @@ ProcessorState::ProcessorState(Document* aSourceDocument,
**/
ProcessorState::~ProcessorState()
{
while (! variableSets.empty()) {
delete (NamedMap*) variableSets.pop();
}
// Delete all ImportFrames
txListIterator iter(&mImportFrames);
while (iter.hasNext())
@ -469,41 +464,27 @@ Node* ProcessorState::findTemplate(Node* aNode,
}
#ifdef PR_LOGGING
char *nodeBuf = 0, *modeBuf = 0;
String mode;
if (aMode.mLocalName) {
TX_GET_ATOM_STRING(aMode.mLocalName, mode);
}
if (matchTemplate) {
char *matchBuf = 0, *uriBuf = 0;
PR_LOG(txLog::xslt, PR_LOG_DEBUG,
("MatchTemplate, Pattern %s, Mode %s, Stylesheet %s, " \
"Node %s\n",
(matchBuf = ((Element*)matchTemplate)->getAttribute(String("match")).toCharArray()),
(modeBuf = mode.toCharArray()),
(uriBuf = matchTemplate->getBaseURI().toCharArray()),
(nodeBuf = aNode->getNodeName().toCharArray())));
#ifdef TX_EXE
delete [] matchBuf;
delete [] uriBuf;
#else
nsMemory::Free(matchBuf);
nsMemory::Free(uriBuf);
#endif
NS_LossyConvertUCS2toASCII(
((Element*)matchTemplate)->getAttribute(String("match")))
.get(),
NS_LossyConvertUCS2toASCII(mode).get(),
NS_LossyConvertUCS2toASCII(matchTemplate->getBaseURI()).get(),
NS_LossyConvertUCS2toASCII(aNode->getNodeName()).get()));
}
else {
PR_LOG(txLog::xslt, PR_LOG_DEBUG,
("No match, Node %s, Mode %s\n",
(nodeBuf = aNode->getNodeName().toCharArray()),
(modeBuf = mode.toCharArray())));
NS_LossyConvertUCS2toASCII(aNode->getNodeName()).get(),
NS_LossyConvertUCS2toASCII(mode).get()));
}
#ifdef TX_EXE
delete [] nodeBuf;
delete [] modeBuf;
#else
nsMemory::Free(nodeBuf);
nsMemory::Free(modeBuf);
#endif
#endif
return matchTemplate;
}
@ -654,9 +635,37 @@ Document* ProcessorState::getResultDocument()
return resultDocument;
}
Stack* ProcessorState::getVariableSetStack()
/*
* Add a global variable
*/
nsresult ProcessorState::addGlobalVariable(Element* aVarElem,
ImportFrame* aImportFrame)
{
return &variableSets;
nsresult rv;
txExpandedName varName;
String qName;
aVarElem->getAttr(txXSLTAtoms::name, kNameSpaceID_None, qName);
rv = varName.init(qName, aVarElem, MB_FALSE);
if (NS_FAILED(rv))
return rv;
return aImportFrame->mVariables.add(varName, aVarElem);
}
/*
* Returns map on top of the stack of local variable-bindings
*/
txVariableMap* ProcessorState::getLocalVariables()
{
return mLocalVariables;
}
/*
* Sets top map of the local variable-bindings stack
*/
void ProcessorState::setLocalVariables(txVariableMap* aMap)
{
mLocalVariables = aMap;
}
/*
@ -929,21 +938,71 @@ txDecimalFormat* ProcessorState::getDecimalFormat(const txExpandedName& aName)
nsresult ProcessorState::getVariable(PRInt32 aNamespace, txAtom* aLName,
ExprResult*& aResult)
{
String name;
// XXX TODO, bug 117658
TX_GET_ATOM_STRING(aLName, name);
txStackIterator iter(&variableSets);
ExprResult* exprResult = 0;
while (iter.hasNext()) {
NamedMap* map = (NamedMap*)iter.next();
if (map->get(name)) {
exprResult = ((VariableBinding*)map->get(name))->getValue();
break;
nsresult rv;
aResult = 0;
ExprResult* exprResult;
txExpandedName varName(aNamespace, aLName);
// Check local variables
if (mLocalVariables) {
exprResult = mLocalVariables->getVariable(varName);
if (exprResult) {
aResult = exprResult;
return NS_OK;
}
}
aResult = exprResult;
return aResult ? NS_OK : NS_ERROR_INVALID_ARG;
} //-- getVariable
// Check if global variable is already evaluated
GlobalVariableValue* globVar;
globVar = (GlobalVariableValue*)mGlobalVariableValues.get(varName);
if (globVar) {
if (globVar->mEvaluating) {
String err("Cyclic variable-value detected");
receiveError(err, NS_ERROR_FAILURE);
return NS_ERROR_FAILURE;
}
aResult = globVar->mValue;
return NS_OK;
}
// We need to evaluate the variable
// Search ImportFrames for the variable
ImportFrame* frame;
txListIterator frameIter(&mImportFrames);
Element* varElem = 0;
while (!varElem && (frame = (ImportFrame*)frameIter.next()))
varElem = (Element*)frame->mVariables.get(varName);
if (!varElem)
return NS_ERROR_FAILURE;
// Evaluate the variable
globVar = new GlobalVariableValue();
if (!globVar)
return NS_ERROR_OUT_OF_MEMORY;
globVar->mEvaluating = MB_TRUE;
rv = mGlobalVariableValues.add(varName, globVar);
if (NS_FAILED(rv)) {
delete globVar;
return rv;
}
// Set up the state we have at the beginning of the transformation
txVariableMap *oldVars = mLocalVariables;
mLocalVariables = 0;
txSingleNodeContext evalContext(mSourceDocument, this);
txIEvalContext* priorEC = setEvalContext(&evalContext);
XSLTProcessor processor;
globVar->mValue = processor.processVariable(mSourceDocument, varElem,
this);
setEvalContext(priorEC);
mLocalVariables = oldVars;
globVar->mEvaluating = MB_FALSE;
aResult = globVar->mValue;
return NS_OK;
}
/**
* Determines if the given XML node allows Whitespace stripping
@ -1054,7 +1113,7 @@ nsresult ProcessorState::resolveFunctionCall(txAtom* aName, PRInt32 aID,
return NS_OK;
}
if (CHECK_FN(functionAvailable)) {
aFunction = new FunctionAvailableFunctionCall();
aFunction = new FunctionAvailableFunctionCall(aElem);
return NS_OK;
}
@ -1105,7 +1164,8 @@ ProcessorState::ImportFrame::ImportFrame(ImportFrame* aFirstNotImported)
: mNamedTemplates(MB_FALSE),
mMatchableTemplates(MB_TRUE),
mNamedAttributeSets(MB_TRUE),
mFirstNotImported(aFirstNotImported)
mFirstNotImported(aFirstNotImported),
mVariables(MB_FALSE)
{
}
@ -1158,3 +1218,12 @@ void txPSParseContext::receiveError(const String& aMsg, nsresult aRes)
{
mPS->receiveError(aMsg, aRes);
}
/*
* GlobalVariableValue, Used avoid circular dependencies of variables
*/
ProcessorState::GlobalVariableValue::~GlobalVariableValue()
{
delete mValue;
}

Просмотреть файл

@ -41,8 +41,10 @@
#include "txIXPathContext.h"
#include "txExpandedNameMap.h"
#include "XSLTFunctions.h"
#include "txError.h"
class txXSLKey;
class txVariableMap;
/**
* Class used for keeping the current state of the XSL Processor
@ -90,10 +92,12 @@ public:
// ImportFrame which is the first one *not* imported by this frame
ImportFrame* mFirstNotImported;
// Map of top-level variables/parameters
txExpandedNameMap mVariables;
// The following stuff is missing here:
// Namespace aliases (xsl:namespace-alias)
// Toplevel variables/parameters
};
// To be able to do some cleaning up in destructor
friend class ImportFrame;
@ -150,9 +154,25 @@ public:
**/
txOutputFormat* getOutputFormat();
/*
* Add a global variable
*/
nsresult addGlobalVariable(Element* aVarElem,
ImportFrame* aImportFrame);
Stack* getVariableSetStack();
/*
* Returns map on top of the stack of local variable-bindings
*/
txVariableMap* getLocalVariables();
/*
* Sets top map of the local variable-bindings stack
*/
void setLocalVariables(txVariableMap* aMap);
/*
* Enums for the getExpr and getPattern functions
*/
enum ExprAttr {
SelectAttr = 0,
TestAttr,
@ -232,7 +252,7 @@ public:
struct TemplateRule {
ImportFrame* mFrame;
const txExpandedName* mMode;
NamedMap* mParams;
txVariableMap* mParams;
};
/*
@ -346,6 +366,14 @@ private:
txPattern* mMatch;
double mPriority;
};
class GlobalVariableValue : public TxObject {
public:
virtual ~GlobalVariableValue();
ExprResult* mValue;
MBool mEvaluating;
};
/**
* The list of ErrorObservers registered with this ProcessorState
@ -410,10 +438,19 @@ private:
*/
TemplateRule* mCurrentTemplateRule;
/*
* Top of stack of local variable-bindings
*/
txVariableMap* mLocalVariables;
/*
* Map of values of global variables
*/
txExpandedNameMap mGlobalVariableValues;
Document* mSourceDocument;
Document* xslDocument;
Document* resultDocument;
Stack variableSets;
/**
* Returns the closest xml:space value for the given node

Просмотреть файл

@ -44,7 +44,7 @@
#include "XSLTProcessor.h"
#include "Names.h"
#include "XMLParser.h"
#include "VariableBinding.h"
#include "txVariableMap.h"
#include "XMLUtils.h"
#include "XMLDOMUtils.h"
#include "txNodeSorter.h"
@ -431,6 +431,8 @@ void XSLTProcessor::processTopLevel(Document* aSource,
txListIterator* importFrame,
ProcessorState* aPs)
{
nsresult rv = NS_OK;
// Index templates and process top level xsl elements
NS_ASSERTION(aStylesheet, "processTopLevel called without stylesheet element");
if (!aStylesheet)
@ -524,16 +526,14 @@ void XSLTProcessor::processTopLevel(Document* aSource,
}
// xsl:param
else if (localName == txXSLTAtoms::param) {
String name;
element->getAttr(txXSLTAtoms::name, kNameSpaceID_None,
name);
if (name.isEmpty()) {
String err("missing required name attribute for xsl:param");
// Once we support stylesheet parameters we should process the
// value here. For now we just use the default value
// See bug 73492
rv = aPs->addGlobalVariable(element, currentFrame);
if (NS_FAILED(rv)) {
String err("unable to add global xsl:param");
aPs->receiveError(err, NS_ERROR_FAILURE);
break;
}
ExprResult* exprResult = processVariable(aSource, element, aPs);
bindVariable(name, exprResult, MB_TRUE, aPs);
}
// xsl:import
else if (localName == txXSLTAtoms::import) {
@ -661,16 +661,11 @@ void XSLTProcessor::processTopLevel(Document* aSource,
}
// xsl:variable
else if (localName == txXSLTAtoms::variable) {
String name;
element->getAttr(txXSLTAtoms::name, kNameSpaceID_None,
name);
if (name.isEmpty()) {
String err("missing required name attribute for xsl:variable");
rv = aPs->addGlobalVariable(element, currentFrame);
if (NS_FAILED(rv)) {
String err("unable to add global xsl:variable");
aPs->receiveError(err, NS_ERROR_FAILURE);
break;
}
ExprResult* exprResult = processVariable(aSource, element, aPs);
bindVariable(name, exprResult, MB_FALSE, aPs);
}
// xsl:preserve-space
else if (localName == txXSLTAtoms::preserveSpace) {
@ -983,35 +978,6 @@ void XSLTProcessor::process
//- Private Methods -/
//-------------------/
void XSLTProcessor::bindVariable
(String& name, ExprResult* value, MBool allowShadowing, ProcessorState* ps)
{
NamedMap* varSet = (NamedMap*)ps->getVariableSetStack()->peek();
//-- check for duplicate variable names
VariableBinding* current = (VariableBinding*) varSet->get(name);
VariableBinding* binding = 0;
if (current) {
binding = current;
if (current->isShadowingAllowed() ) {
current->setShadowValue(value);
}
else {
//-- error cannot rebind variables
String err("cannot rebind variables: ");
err.append(name);
err.append(" already exists in this scope.");
ps->receiveError(err, NS_ERROR_FAILURE);
}
}
else {
binding = new VariableBinding(name, value);
varSet->put((const String&)name, binding);
}
if ( allowShadowing ) binding->allowShadowing();
else binding->disallowShadowing();
} //-- bindVariable
void XSLTProcessor::process(Node* node,
const String& mode,
ProcessorState* ps) {
@ -1153,7 +1119,8 @@ void XSLTProcessor::processAction(Node* aNode,
sorter.sortNodeSet(nodeSet);
// Process xsl:with-param elements
NamedMap* actualParams = processParameters(actionElement, aNode, aPs);
txVariableMap params(0);
processParameters(actionElement, aNode, &params, aPs);
// Get mode
String modeStr;
@ -1165,7 +1132,6 @@ void XSLTProcessor::processAction(Node* aNode,
String err("malformed mode-name in xsl:apply-templates");
aPs->receiveError(err);
TX_IF_RELEASE_ATOM(localName);
delete actualParams;
return;
}
}
@ -1180,12 +1146,10 @@ void XSLTProcessor::processAction(Node* aNode,
Node* xslTemplate;
xslTemplate = aPs->findTemplate(currNode, mode, &frame);
processMatchedTemplate(xslTemplate, currNode,
actualParams, mode, frame, aPs);
&params, mode, frame, aPs);
}
aPs->setEvalContext(priorEC);
delete actualParams;
}
else {
String err("error processing apply-templates");
@ -1278,18 +1242,14 @@ void XSLTProcessor::processAction(Node* aNode,
if (NS_SUCCEEDED(rv)) {
Element* xslTemplate = aPs->getNamedTemplate(templateName);
if (xslTemplate) {
#ifdef PR_LOGGING
char *nameBuf = 0, *uriBuf = 0;
PR_LOG(txLog::xslt, PR_LOG_DEBUG,
("CallTemplate, Name %s, Stylesheet %s\n",
(nameBuf = nameStr.toCharArray()),
(uriBuf = xslTemplate->getBaseURI().toCharArray())));
delete nameBuf;
delete uriBuf;
#endif
NamedMap* actualParams = processParameters(actionElement, aNode, aPs);
processTemplate(aNode, xslTemplate, aPs, actualParams);
delete actualParams;
NS_LossyConvertUCS2toASCII(nameStr).get(),
NS_LossyConvertUCS2toASCII(xslTemplate->getBaseURI())
.get()));
txVariableMap params(0);
processParameters(actionElement, aNode, &params, aPs);
processTemplate(aNode, xslTemplate, &params, aPs);
}
}
else {
@ -1344,7 +1304,7 @@ void XSLTProcessor::processAction(Node* aNode,
PRUint32 length = value.length();
while ((pos = value.indexOf('-', pos)) != kNotFound) {
++pos;
if ((pos == length) || (value.charAt(pos) == '-'))
if (((PRUint32)pos == length) || (value.charAt(pos) == '-'))
value.insert(pos++, ' ');
}
NS_ASSERTION(mResultHandler, "mResultHandler must not be NULL!");
@ -1530,7 +1490,7 @@ void XSLTProcessor::processAction(Node* aNode,
NS_ASSERTION(NS_SUCCEEDED(rv), "xsl:message couldn't get console service");
if (consoleSvc) {
nsAutoString logString(NS_LITERAL_STRING("xsl:message - "));
logString.Append(message.getConstNSString());
logString.Append(message);
rv = consoleSvc->LogStringMessage(logString.get());
NS_ASSERTION(NS_SUCCEEDED(rv), "xsl:message couldn't log");
}
@ -1545,7 +1505,8 @@ void XSLTProcessor::processAction(Node* aNode,
}
// xsl:param
else if (localName == txXSLTAtoms::param) {
// Ignore in this loop (already processed)
String err("misplaced xsl:param");
aPs->receiveError(err, NS_ERROR_FAILURE);
}
// xsl:processing-instruction
else if (localName == txXSLTAtoms::processingInstruction) {
@ -1637,16 +1598,31 @@ void XSLTProcessor::processAction(Node* aNode,
}
// xsl:variable
else if (localName == txXSLTAtoms::variable) {
String name;
if (!actionElement->getAttr(txXSLTAtoms::name,
kNameSpaceID_None, name)) {
String err("missing required name attribute for xsl:variable");
txExpandedName varName;
String qName;
actionElement->getAttr(txXSLTAtoms::name, kNameSpaceID_None,
qName);
rv = varName.init(qName, actionElement, MB_FALSE);
if (NS_FAILED(rv)) {
String err("bad name for xsl:variable");
aPs->receiveError(err, NS_ERROR_FAILURE);
TX_IF_RELEASE_ATOM(localName);
TX_RELEASE_ATOM(localName);
return;
}
ExprResult* exprResult = processVariable(aNode, actionElement, aPs);
bindVariable(name, exprResult, MB_FALSE, aPs);
ExprResult* exprResult = processVariable(aNode, actionElement,
aPs);
if (!exprResult) {
TX_RELEASE_ATOM(localName);
return;
}
txVariableMap* vars = aPs->getLocalVariables();
NS_ASSERTION(vars, "missing localvariable map");
rv = vars->bindVariable(varName, exprResult, MB_TRUE);
if (NS_FAILED(rv)) {
String err("bad name for xsl:variable");
aPs->receiveError(err, NS_ERROR_FAILURE);
}
}
TX_IF_RELEASE_ATOM(localName);
}
@ -1655,7 +1631,9 @@ void XSLTProcessor::processAction(Node* aNode,
* Processes the attribute sets specified in the use-attribute-sets attribute
* of the element specified in aElement
**/
void XSLTProcessor::processAttributeSets(Element* aElement, Node* aNode, ProcessorState* aPs)
void XSLTProcessor::processAttributeSets(Element* aElement, Node* aNode,
ProcessorState* aPs,
Stack* aRecursionStack)
{
nsresult rv = NS_OK;
String names;
@ -1680,12 +1658,14 @@ void XSLTProcessor::processAttributeSets(Element* aElement, Node* aNode, Process
return;
}
txStackIterator attributeSets(&mAttributeSetStack);
while (attributeSets.hasNext()) {
if (name == *(txExpandedName*)attributeSets.next()) {
String err("circular inclusion detected in use-attribute-sets");
aPs->receiveError(err);
return;
if (aRecursionStack) {
txStackIterator attributeSets(aRecursionStack);
while (attributeSets.hasNext()) {
if (name == *(txExpandedName*)attributeSets.next()) {
String err("circular inclusion detected in use-attribute-sets");
aPs->receiveError(err);
return;
}
}
}
@ -1697,10 +1677,18 @@ void XSLTProcessor::processAttributeSets(Element* aElement, Node* aNode, Process
//-- for different xsl:attribute nodes. I will probably create
//-- an AttributeSet object, which will handle this case better. - Keith V.
if (attSet->size() > 0) {
mAttributeSetStack.push(&name);
Element* parent = (Element*) attSet->get(0)->getXPathParent();
processAttributeSets(parent, aNode, aPs);
mAttributeSetStack.pop();
if (aRecursionStack) {
aRecursionStack->push(&name);
processAttributeSets(parent, aNode, aPs, aRecursionStack);
aRecursionStack->pop();
}
else {
Stack recursionStack;
recursionStack.push(&name);
processAttributeSets(parent, aNode, aPs, &recursionStack);
recursionStack.pop();
}
}
for (i = 0; i < attSet->size(); i++)
processAction(aNode, attSet->get(i), aPs);
@ -1709,29 +1697,24 @@ void XSLTProcessor::processAttributeSets(Element* aElement, Node* aNode, Process
}
} //-- processAttributeSets
/**
/*
* Processes the xsl:with-param child elements of the given xsl action.
* A VariableBinding is created for each actual parameter, and
* added to the result NamedMap. At this point, we do not care
* whether the actual parameter matches a formal parameter of the template
* or not.
* @param xslAction the action node that takes parameters (xsl:call-template
* or xsl:apply-templates
* @param context the current context node
* @ps the current ProcessorState
* @return a NamedMap of variable bindings
**/
NamedMap* XSLTProcessor::processParameters(Element* xslAction, Node* context, ProcessorState* ps)
* @param aAction the action node that takes parameters (xsl:call-template
* or xsl:apply-templates
* @param aContext the current context node
* @param aMap map to place parsed variables in
* @param aPs the current ProcessorState
* @return errorcode
*/
nsresult XSLTProcessor::processParameters(Element* aAction,
Node* aContext,
txVariableMap* aMap,
ProcessorState* aPs)
{
NamedMap* params = new NamedMap();
NS_ASSERTION(aAction && aMap, "missing argument");
nsresult rv = NS_OK;
if (!xslAction || !params)
return params;
params->setObjectDeletion(MB_TRUE);
//-- handle xsl:with-param elements
Node* tmpNode = xslAction->getFirstChild();
Node* tmpNode = aAction->getFirstChild();
while (tmpNode) {
if (tmpNode->getNodeType() == Node::ELEMENT_NODE &&
tmpNode->getNamespaceID() == kNameSpaceID_XSLT) {
@ -1744,54 +1727,58 @@ NamedMap* XSLTProcessor::processParameters(Element* xslAction, Node* context, Pr
}
Element* action = (Element*)tmpNode;
String name;
if (!action->getAttr(txXSLTAtoms::name,
kNameSpaceID_None, name)) {
String err("missing required name attribute for xsl:with-param");
ps->receiveError(err, NS_ERROR_FAILURE);
txExpandedName paramName;
String qName;
action->getAttr(txXSLTAtoms::name, kNameSpaceID_None, qName);
rv = paramName.init(qName, action, MB_FALSE);
if (NS_FAILED(rv)) {
String err("bad name for xsl:param");
aPs->receiveError(err, NS_ERROR_FAILURE);
break;
}
else {
ExprResult* exprResult = processVariable(context, action, ps);
if (params->get(name)) {
//-- error cannot rebind parameters
String err("value for parameter '");
err.append(name);
err.append("' specified more than once.");
ps->receiveError(err, NS_ERROR_FAILURE);
}
else {
VariableBinding* binding = new VariableBinding(name, exprResult);
params->put((const String&)name, binding);
}
ExprResult* exprResult = processVariable(aContext, action, aPs);
if (!exprResult) {
return NS_ERROR_FAILURE;
}
rv = aMap->bindVariable(paramName, exprResult, MB_TRUE);
if (NS_FAILED(rv)) {
String err("Unable to bind parameter '");
err.append(qName);
err.append("'");
aPs->receiveError(err, NS_ERROR_FAILURE);
return rv;
}
TX_RELEASE_ATOM(localName);
}
tmpNode = tmpNode->getNextSibling();
}
return params;
} //-- processParameters
return NS_OK;
}
/**
* Processes the children of the specified element using the given context node
* and ProcessorState
* @param node the context node
* @param xslElement the template to be processed. Must be != NULL
* @param ps the current ProcessorState
* @param aContext context node
* @param aXslElement template to be processed. Must be != NULL
* @param aPs current ProcessorState
**/
void XSLTProcessor::processChildren(Node* node, Element* xslElement, ProcessorState* ps) {
void XSLTProcessor::processChildren(Node* aContext,
Element* aXslElement,
ProcessorState* aPs)
{
NS_ASSERTION(aXslElement, "missing aXslElement");
NS_ASSERTION(xslElement,"xslElement is NULL in call to XSLTProcessor::processChildren!");
Stack* bindings = ps->getVariableSetStack();
NamedMap localBindings;
localBindings.setObjectDeletion(MB_TRUE);
bindings->push(&localBindings);
Node* child = xslElement->getFirstChild();
txVariableMap* oldVars = aPs->getLocalVariables();
txVariableMap localVars(oldVars);
aPs->setLocalVariables(&localVars);
Node* child = aXslElement->getFirstChild();
while (child) {
processAction(node, child, ps);
processAction(aContext, child, aPs);
child = child->getNextSibling();
}
bindings->pop();
aPs->setLocalVariables(oldVars);
} //-- processChildren
void
@ -1808,61 +1795,88 @@ XSLTProcessor::processChildrenAsValue(Node* aNode,
mResultHandler = previousHandler;
}
/**
* Processes the specified template using the given context, ProcessorState, and actual
* parameters.
* @param xslTemplate the template to be processed
* @ps the current ProcessorState
* @param params a NamedMap of variable bindings that contain the actual parameters for
* the template. Parameters that do not match a formal parameter of the template (i.e.
* there is no corresponding xsl:param in the template definition) will be discarded.
**/
void XSLTProcessor::processTemplate(Node* node, Node* xslTemplate, ProcessorState* ps, NamedMap* params) {
/*
* Processes the specified template using the given context,
* ProcessorState, and parameters.
* @param aContext the current context node
* @param aTemplate the node in the xslt document that contains the
* template
* @param aParams map with parameters to the template
* @param aPs the current ProcessorState
*/
void XSLTProcessor::processTemplate(Node* aContext, Node* aTemplate,
txVariableMap* aParams, ProcessorState* aPs)
{
NS_ASSERTION(aTemplate, "aTemplate is NULL");
NS_ASSERTION(xslTemplate, "xslTemplate is NULL in call to XSLTProcessor::processTemplate!");
nsresult rv;
Stack* bindings = ps->getVariableSetStack();
NamedMap localBindings;
localBindings.setObjectDeletion(MB_TRUE);
bindings->push(&localBindings);
processTemplateParams(xslTemplate, node, ps, params);
Node* tmp = xslTemplate->getFirstChild();
while (tmp) {
processAction(node,tmp,ps);
tmp = tmp->getNextSibling();
}
if (params) {
StringList* keys = params->keys();
if (keys) {
StringListIterator keyIter(keys);
String* key;
while((key = keyIter.next())) {
VariableBinding *var, *param;
var = (VariableBinding*)localBindings.get(*key);
param = (VariableBinding*)params->get(*key);
if (var && var->getValue() == param->getValue()) {
// Don't delete the contained ExprResult since it's
// not ours
var->setValue(0);
}
txVariableMap* oldVars = aPs->getLocalVariables();
txVariableMap localVars(0);
aPs->setLocalVariables(&localVars);
// handle params
Node* tmpNode = aTemplate->getFirstChild();
while (tmpNode) {
int nodeType = tmpNode->getNodeType();
if (nodeType == Node::ELEMENT_NODE) {
txAtom* localName;
tmpNode->getLocalName(&localName);
if (tmpNode->getNamespaceID() != kNameSpaceID_XSLT ||
localName != txXSLTAtoms::param) {
TX_RELEASE_ATOM(localName);
break;
}
TX_RELEASE_ATOM(localName);
Element* action = (Element*)tmpNode;
txExpandedName paramName;
String qName;
action->getAttr(txXSLTAtoms::name, kNameSpaceID_None, qName);
rv = paramName.init(qName, action, MB_FALSE);
if (NS_FAILED(rv)) {
String err("bad name for xsl:param");
aPs->receiveError(err, NS_ERROR_FAILURE);
break;
}
ExprResult* exprResult;
if (aParams && (exprResult = aParams->getVariable(paramName))) {
rv = localVars.bindVariable(paramName, exprResult, MB_FALSE);
}
else {
exprResult = processVariable(aContext, action, aPs);
if (!exprResult)
break;
rv = localVars.bindVariable(paramName, exprResult, MB_TRUE);
}
if (NS_FAILED(rv)) {
String err("unable to bind xsl:param");
aPs->receiveError(err, NS_ERROR_FAILURE);
}
}
else {
// out of memory so we can't get the keys
// don't delete any variables since it's better we leak then
// crash
localBindings.setObjectDeletion(MB_FALSE);
else if (!(nodeType == Node::COMMENT_NODE ||
((nodeType == Node::TEXT_NODE ||
nodeType == Node::CDATA_SECTION_NODE) &&
XMLUtils::isWhitespace(tmpNode->getNodeValue())))) {
break;
}
delete keys;
tmpNode = tmpNode->getNextSibling();
}
bindings->pop();
} //-- processTemplate
// execute contents
while (tmpNode) {
processAction(aContext, tmpNode, aPs);
tmpNode = tmpNode->getNextSibling();
}
aPs->setLocalVariables(oldVars);
}
void XSLTProcessor::processMatchedTemplate(Node* aXslTemplate,
Node* aNode,
NamedMap* aParams,
txVariableMap* aParams,
const txExpandedName& aMode,
ProcessorState::ImportFrame* aFrame,
ProcessorState* aPs)
@ -1875,7 +1889,7 @@ void XSLTProcessor::processMatchedTemplate(Node* aXslTemplate,
newTemplate.mParams = aParams;
aPs->setCurrentTemplateRule(&newTemplate);
processTemplate(aNode, aXslTemplate, aPs, aParams);
processTemplate(aNode, aXslTemplate, aParams, aPs);
aPs->setCurrentTemplateRule(oldTemplate);
}
@ -1945,70 +1959,6 @@ void XSLTProcessor::processDefaultTemplate(Node* node,
}
} //-- processDefaultTemplate
/**
* Builds the initial bindings for the template. Formal parameters (xsl:param) that
* have a corresponding binding in actualParams are bound to the actual parameter value,
* otherwise to their default value. Actual parameters that do not match any formal
* parameter are discarded.
* @param xslTemplate the template node
* @param context the current context node
* @param ps the current ProcessorState
* @param actualParams a NamedMap of variable bindings that contains the actual parameters
**/
void XSLTProcessor::processTemplateParams
(Node* xslTemplate, Node* context, ProcessorState* ps, NamedMap* actualParams)
{
if ( xslTemplate ) {
Node* tmpNode = xslTemplate->getFirstChild();
//-- handle params
while (tmpNode) {
unsigned short nodeType = tmpNode->getNodeType();
if (nodeType == Node::ELEMENT_NODE) {
txAtom* localName;
tmpNode->getLocalName(&localName);
if (tmpNode->getNamespaceID() != kNameSpaceID_XSLT ||
localName != txXSLTAtoms::param) {
TX_IF_RELEASE_ATOM(localName);
break;
}
TX_RELEASE_ATOM(localName);
Element* action = (Element*)tmpNode;
String name;
if (!action->getAttr(txXSLTAtoms::name,
kNameSpaceID_None, name)) {
String err("missing required name attribute for xsl:param");
ps->receiveError(err, NS_ERROR_FAILURE);
}
else {
VariableBinding* binding = 0;
if (actualParams) {
binding = (VariableBinding*) actualParams->get((const String&)name);
}
if (binding) {
// the formal parameter has a corresponding actual parameter, use it
ExprResult* exprResult = binding->getValue();
bindVariable(name, exprResult, MB_FALSE, ps);
}
else {
// no actual param, use default
ExprResult* exprResult = processVariable(context, action, ps);
bindVariable(name, exprResult, MB_FALSE, ps);
}
}
}
else if (nodeType == Node::TEXT_NODE ||
nodeType == Node::CDATA_SECTION_NODE) {
if (!XMLUtils::isWhitespace(tmpNode->getNodeValue()))
break;
}
tmpNode = tmpNode->getNextSibling();
}
}
} //-- processTemplateParams
/**
* processes the xslVariable parameter as an xsl:variable using the given context,
* and ProcessorState.
@ -2020,10 +1970,7 @@ void XSLTProcessor::processTemplateParams
ExprResult* XSLTProcessor::processVariable
(Node* node, Element* xslVariable, ProcessorState* ps)
{
if ( !xslVariable ) {
return new StringResult("unable to process variable");
}
NS_ASSERTION(xslVariable, "missing xslVariable");
//-- check for select attribute
if (xslVariable->hasAttr(txXSLTAtoms::select, kNameSpaceID_None)) {
@ -2046,7 +1993,7 @@ ExprResult* XSLTProcessor::processVariable
return rtf;
}
else {
return new StringResult("");
return new StringResult();
}
} //-- processVariable

Просмотреть файл

@ -87,6 +87,7 @@ class XSLTProcessor
public nsIScriptLoaderObserver
#endif
{
friend class ProcessorState;
public:
#ifndef TX_EXE
@ -251,18 +252,17 @@ private:
*/
Expr* mNodeExpr;
/**
* Binds the given Variable
**/
void bindVariable(String& name,
ExprResult* value,
MBool allowShadowing,
ProcessorState* ps);
/**
* Processes the xsl:with-param elements of the given xsl action
**/
NamedMap* processParameters(Element* xslAction, Node* context, ProcessorState* ps);
/*
* Processes the xsl:with-param child elements of the given xsl action.
* @param aAction the action node that takes parameters (xsl:call-template
* or xsl:apply-templates
* @param aContext the current context node
* @param aMap map to place parsed variables in
* @param aPs the current ProcessorState
* @return errorcode
*/
nsresult processParameters(Element* aAction, Node* aContext,
txVariableMap* aMap, ProcessorState* aPs);
#ifdef TX_EXE
/**
@ -281,23 +281,35 @@ private:
* Processes the attribute sets specified in the use-attribute-sets attribute
* of the element specified in aElement
**/
void processAttributeSets(Element* aElement, Node* node, ProcessorState* ps);
void processAttributeSets(Element* aElement, Node* node,
ProcessorState* ps, Stack* aRecursionStack = 0);
/**
* Processes the children of the specified element using the given context node
* and ProcessorState
* @param node the context node
* @param xslElement the template to be processed. Must be != NULL
* @param ps the current ProcessorState
* @param aContext context node
* @param aXslElement template to be processed. Must be != NULL
* @param aPs current ProcessorState
**/
void processChildren(Node* node, Element* xslElement, ProcessorState* ps);
void processChildren(Node* aContext,
Element* aXslElement,
ProcessorState* aPs);
void processTemplate(Node* node, Node* xslTemplate, ProcessorState* ps, NamedMap* actualParams = NULL);
void processTemplateParams(Node* xslTemplate, Node* context, ProcessorState* ps, NamedMap* actualParams);
/*
* Processes the specified template using the given context,
* ProcessorState, and parameters.
* @param aContext the current context node
* @param aTemplate the node in the xslt document that contains the
* template
* @param aParams map with parameters to the template
* @param aPs the current ProcessorState
*/
void processTemplate(Node* aContext, Node* aTemplate,
txVariableMap* aParams, ProcessorState* aPs);
void processMatchedTemplate(Node* aXslTemplate,
Node* aNode,
NamedMap* aParams,
txVariableMap* aParams,
const txExpandedName& aMode,
ProcessorState::ImportFrame* aFrame,
ProcessorState* aPs);
@ -369,7 +381,6 @@ private:
#endif
txXMLEventHandler* mResultHandler;
MBool mHaveDocumentElement;
Stack mAttributeSetStack;
#ifndef TX_EXE
void SignalTransformEnd();

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -49,7 +49,6 @@ CPP_OBJS= \
.\$(OBJDIR)\ProcessorState.obj \
.\$(OBJDIR)\txRtfHandler.obj \
.\$(OBJDIR)\txTextHandler.obj \
.\$(OBJDIR)\VariableBinding.obj \
.\$(OBJDIR)\txXSLTPatterns.obj \
.\$(OBJDIR)\txPatternParser.obj \
.\$(OBJDIR)\XSLTProcessor.obj

Просмотреть файл

@ -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)

Просмотреть файл

@ -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");

Просмотреть файл

@ -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();