From 783e3ea68e57e06b698eaddd31914f72b40e2431 Mon Sep 17 00:00:00 2001 From: "sicking%bigfoot.com" Date: Sat, 2 Mar 2002 18:39:23 +0000 Subject: [PATCH] Bug 122001. Implement txExpandedNameMap. Add QName parsing and some operators to txExpandedName. r=peterv sr=jst a=asa --- extensions/transformiix/build/Makefile.in | 1 + extensions/transformiix/build/makefile.win | 1 + .../transformiix/source/base/Makefile.in | 9 ++- .../transformiix/source/base/makefile.win | 9 ++- extensions/transformiix/source/base/txAtom.h | 4 ++ .../transformiix/source/main/Makefile.in | 1 + .../transformiix/source/main/makefile.win | 1 + .../transformiix/source/xml/XMLUtils.cpp | 40 +++++++++---- extensions/transformiix/source/xml/XMLUtils.h | 56 +++++++++++++++---- 9 files changed, 96 insertions(+), 26 deletions(-) diff --git a/extensions/transformiix/build/Makefile.in b/extensions/transformiix/build/Makefile.in index 2c5a7d3f78c6..5df6f3a6ba2e 100644 --- a/extensions/transformiix/build/Makefile.in +++ b/extensions/transformiix/build/Makefile.in @@ -63,6 +63,7 @@ LOBJS =../source/base/ArrayList.$(OBJ_SUFFIX) \ ../source/base/StringList.$(OBJ_SUFFIX) \ ../source/base/Tokenizer.$(OBJ_SUFFIX) \ ../source/base/txAtoms.$(OBJ_SUFFIX) \ + ../source/base/txExpandedNameMap.$(OBJ_SUFFIX) \ ../source/base/MozillaString.$(OBJ_SUFFIX) \ ../source/net/URIUtils.$(OBJ_SUFFIX) \ ../source/xml/dom/mozImpl/MozillaObjectWrapper.$(OBJ_SUFFIX) \ diff --git a/extensions/transformiix/build/makefile.win b/extensions/transformiix/build/makefile.win index 46f76d680bfc..2e5020445c78 100644 --- a/extensions/transformiix/build/makefile.win +++ b/extensions/transformiix/build/makefile.win @@ -46,6 +46,7 @@ CPP_OBJS= \ ..\source\base\$(OBJDIR)\StringList.obj \ ..\source\base\$(OBJDIR)\Tokenizer.obj \ ..\source\base\$(OBJDIR)\txAtoms.obj \ + ..\source\base\$(OBJDIR)\txExpandedNameMap.obj \ ..\source\base\$(OBJDIR)\MozillaString.obj \ ..\source\net\$(OBJDIR)\URIUtils.obj \ ..\source\xml\dom\mozImpl\$(OBJDIR)\MozillaObjectWrapper.obj \ diff --git a/extensions/transformiix/source/base/Makefile.in b/extensions/transformiix/source/base/Makefile.in index 3421126a1799..2f643ea0571e 100644 --- a/extensions/transformiix/source/base/Makefile.in +++ b/extensions/transformiix/source/base/Makefile.in @@ -31,6 +31,9 @@ MODULE = transformiix REQUIRES = string \ xpcom \ unicharutil \ + dom \ + content \ + widget \ $(NULL) endif @@ -44,7 +47,8 @@ CPPSRCS = ArrayList.cpp \ Stack.cpp \ StringList.cpp \ Tokenizer.cpp \ - txAtoms.cpp + txAtoms.cpp \ + txExpandedNameMap.cpp ifdef TX_EXE CPPSRCS += CommandLineUtils.cpp \ @@ -55,6 +59,7 @@ endif include $(topsrcdir)/config/rules.mk -INCLUDES += -I$(srcdir)/../xpath -I$(srcdir)/../xslt +INCLUDES += -I$(srcdir)/../xpath -I$(srcdir)/../xslt -I$(srcdir)/../xml \ + -I$(srcdir)/../xml/dom libs:: $(OBJS) diff --git a/extensions/transformiix/source/base/makefile.win b/extensions/transformiix/source/base/makefile.win index fbd1d79b1435..098d9b794942 100644 --- a/extensions/transformiix/source/base/makefile.win +++ b/extensions/transformiix/source/base/makefile.win @@ -20,9 +20,13 @@ # Contributor(s): DEPTH=..\..\..\.. +MODULE = transformiix REQUIRES = string \ xpcom \ unicharutil \ + dom \ + content \ + widget \ $(NULL) include <$(DEPTH)/config/config.mak> @@ -42,7 +46,8 @@ CPP_OBJS= \ .\$(OBJDIR)\Map.obj \ .\$(OBJDIR)\StringList.obj \ .\$(OBJDIR)\Tokenizer.obj \ - .\$(OBJDIR)\txAtoms.obj + .\$(OBJDIR)\txAtoms.obj \ + .\$(OBJDIR)\txExpandedNameMap.obj !ifndef TX_EXE CPP_OBJS = $(CPP_OBJS) \ @@ -58,7 +63,7 @@ CPP_OBJS = $(CPP_OBJS) \ EXPORTS = \ $(NULL) -LINCS=-I$(PUBLIC)\xpcom -I..\xpath -I..\xslt +LINCS=-I$(PUBLIC)\xpcom -I..\xpath -I..\xslt -I..\xml -I..\xml\dom LCFLAGS = \ $(LCFLAGS) \ diff --git a/extensions/transformiix/source/base/txAtom.h b/extensions/transformiix/source/base/txAtom.h index 5934b05772e0..5fcc29963c32 100644 --- a/extensions/transformiix/source/base/txAtom.h +++ b/extensions/transformiix/source/base/txAtom.h @@ -138,6 +138,8 @@ private: #define TX_ADDREF_ATOM(atom) {} +#define TX_IF_ADDREF_ATOM(atom) {} + #define TX_RELEASE_ATOM(atom) {} #define TX_IF_RELEASE_ATOM(atom) {} @@ -157,6 +159,8 @@ typedef nsIAtom txAtom; #define TX_ADDREF_ATOM(atom) NS_ADDREF(atom) +#define TX_IF_ADDREF_ATOM(atom) NS_IF_ADDREF(atom) + #define TX_RELEASE_ATOM(atom) NS_RELEASE(atom) #define TX_IF_RELEASE_ATOM(atom) NS_IF_RELEASE(atom) diff --git a/extensions/transformiix/source/main/Makefile.in b/extensions/transformiix/source/main/Makefile.in index d13c95d60494..7fa3b20586e9 100644 --- a/extensions/transformiix/source/main/Makefile.in +++ b/extensions/transformiix/source/main/Makefile.in @@ -40,6 +40,7 @@ OBJS =../base/ArrayList.$(OBJ_SUFFIX) \ ../base/StringList.$(OBJ_SUFFIX) \ ../base/Tokenizer.$(OBJ_SUFFIX) \ ../base/txAtoms.$(OBJ_SUFFIX) \ + ../base/txExpandedNameMap.$(OBJ_SUFFIX) \ ../base/TxString.$(OBJ_SUFFIX) \ ../net/URIUtils.$(OBJ_SUFFIX) \ ../xml/dom/standalone/Attr.$(OBJ_SUFFIX) \ diff --git a/extensions/transformiix/source/main/makefile.win b/extensions/transformiix/source/main/makefile.win index ac12d07a4284..b44e4a386a8e 100644 --- a/extensions/transformiix/source/main/makefile.win +++ b/extensions/transformiix/source/main/makefile.win @@ -38,6 +38,7 @@ CPP_OBJS= \ ../base/$(OBJDIR)/StringList.obj \ ../base/$(OBJDIR)/Tokenizer.obj \ ../base/$(OBJDIR)/txAtoms.obj \ + ../base/$(OBJDIR)/txExpandedNameMap.obj \ ../base/$(OBJDIR)/TxString.obj \ ../net/$(OBJDIR)/URIUtils.obj \ ../xml/dom/standalone/$(OBJDIR)/Attr.obj \ diff --git a/extensions/transformiix/source/xml/XMLUtils.cpp b/extensions/transformiix/source/xml/XMLUtils.cpp index 890499e42df3..5f8b170b8108 100644 --- a/extensions/transformiix/source/xml/XMLUtils.cpp +++ b/extensions/transformiix/source/xml/XMLUtils.cpp @@ -31,17 +31,37 @@ #include "XMLUtils.h" -txExpandedName::txExpandedName(PRInt32 aNsID, - txAtom* aLocalName) : mNamespaceID(aNsID), - mLocalName(aLocalName) +nsresult txExpandedName::init(const String& aQName, + Node* aResolver, + MBool aUseDefault) { - if (mLocalName) - TX_ADDREF_ATOM(mLocalName); -} + NS_ASSERTION(aResolver, "missing resolve node"); + if (!XMLUtils::isValidQName(aQName)) + return NS_ERROR_FAILURE; -txExpandedName::~txExpandedName() -{ - TX_IF_RELEASE_ATOM(mLocalName); + int idx = aQName.indexOf(':'); + if (idx >= 0) { + String localName, prefixStr; + aQName.subString(0, idx, prefixStr); + txAtom* prefix = TX_GET_ATOM(prefixStr); + PRInt32 namespaceID = aResolver->lookupNamespaceID(prefix); + if (namespaceID == kNameSpaceID_Unknown) + return NS_ERROR_FAILURE; + mNamespaceID = namespaceID; + + aQName.subString(idx+1, localName); + TX_IF_RELEASE_ATOM(mLocalName); + mLocalName = TX_GET_ATOM(localName); + } + else { + TX_IF_RELEASE_ATOM(mLocalName); + mLocalName = TX_GET_ATOM(aQName); + if (aUseDefault) + mNamespaceID = aResolver->lookupNamespaceID(0); + else + mNamespaceID = kNameSpaceID_None; + } + return NS_OK; } //------------------------------/ @@ -111,7 +131,7 @@ MBool XMLUtils::isQNameChar(PRInt32 ch) { /** * Returns true if the given String is a valid XML QName **/ -MBool XMLUtils::isValidQName(String& name) { +MBool XMLUtils::isValidQName(const String& name) { if (name.isEmpty()) return MB_FALSE; diff --git a/extensions/transformiix/source/xml/XMLUtils.h b/extensions/transformiix/source/xml/XMLUtils.h index 8c1f40102971..31363109f7f1 100644 --- a/extensions/transformiix/source/xml/XMLUtils.h +++ b/extensions/transformiix/source/xml/XMLUtils.h @@ -32,26 +32,58 @@ #include "baseutils.h" #include "txAtom.h" +#include "dom.h" +#include "txError.h" class String; class txExpandedName { public: - txExpandedName(PRInt32 aNsID, txAtom* aLocalName); - ~txExpandedName(); - - MBool - operator == (const txExpandedName& rhs) + txExpandedName() : mNamespaceID(kNameSpaceID_None), + mLocalName(0) { - return ((mNamespaceID == rhs.mNamespaceID) && - (mLocalName == rhs.mLocalName)); } - MBool - operator != (const txExpandedName& rhs) + txExpandedName(PRInt32 aNsID, + txAtom* aLocalName) : mNamespaceID(aNsID), + mLocalName(aLocalName) { - return ((mNamespaceID != rhs.mNamespaceID) || - (mLocalName != rhs.mLocalName)); + TX_IF_ADDREF_ATOM(mLocalName); + } + + txExpandedName(const txExpandedName& aOther) : + mNamespaceID(aOther.mNamespaceID), + mLocalName(aOther.mLocalName) + { + TX_IF_ADDREF_ATOM(mLocalName); + } + + ~txExpandedName() + { + TX_IF_RELEASE_ATOM(mLocalName); + } + + nsresult init(const String& aQName, Node* aResolver, MBool aUseDefault); + + txExpandedName& operator = (const txExpandedName& rhs) + { + mNamespaceID = rhs.mNamespaceID; + TX_IF_RELEASE_ATOM(mLocalName); + mLocalName = rhs.mLocalName; + TX_IF_ADDREF_ATOM(mLocalName); + return *this; + } + + MBool operator == (const txExpandedName& rhs) const + { + return ((mLocalName == rhs.mLocalName) && + (mNamespaceID == rhs.mNamespaceID)); + } + + MBool operator != (const txExpandedName& rhs) const + { + return ((mLocalName != rhs.mLocalName) || + (mNamespaceID != rhs.mNamespaceID)); } PRInt32 mNamespaceID; @@ -69,7 +101,7 @@ public: /** * Returns true if the given String is a valid XML QName **/ - static MBool isValidQName(String& name); + static MBool isValidQName(const String& name); /** * Returns true if the given string has only whitespace characters