diff --git a/content/base/src/nsSyncLoadService.cpp b/content/base/src/nsSyncLoadService.cpp new file mode 100644 index 000000000000..ee80d0c27526 --- /dev/null +++ b/content/base/src/nsSyncLoadService.cpp @@ -0,0 +1,369 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Peter Van der Beken, peterv@netscape.com + * -- original author. + * + */ + +#include "nsSyncLoader.h" +#include "nsNetUtil.h" +#include "nsLayoutCID.h" +#include "nsIEventQueueService.h" +#include "nsIDOMDocument.h" +#include "nsIDOMDOMImplementation.h" +#include "nsIDOMEventReceiver.h" +#include "nsIXPConnect.h" +#include "nsIDocShell.h" +#include "nsIDocShellTreeItem.h" +#include "nsIScriptContext.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDOMWindowInternal.h" +#include "nsAppShellCIDs.h" +#include "nsIAppShellService.h" + +static const char* kLoadAsData = "loadAsData"; + +static NS_DEFINE_CID(kIDOMDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID); +static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); +static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); + +/* + * This class exists to prevent a circular reference between + * the loaded document and the nsSyncloader instance. The + * request owns the document. While the document is loading, + * the request is a load listener, held onto by the document. + * The proxy class breaks the circularity by filling in as the + * load listener and holding a weak reference to the request + * object. + */ + +class nsLoadListenerProxy : public nsIDOMLoadListener { +public: + nsLoadListenerProxy(nsWeakPtr aParent); + virtual ~nsLoadListenerProxy(); + + NS_DECL_ISUPPORTS + + // nsIDOMEventListener + virtual nsresult HandleEvent(nsIDOMEvent* aEvent); + + // nsIDOMLoadListener + virtual nsresult Load(nsIDOMEvent* aEvent); + virtual nsresult Unload(nsIDOMEvent* aEvent); + virtual nsresult Abort(nsIDOMEvent* aEvent); + virtual nsresult Error(nsIDOMEvent* aEvent); + +protected: + nsWeakPtr mParent; +}; + +nsLoadListenerProxy::nsLoadListenerProxy(nsWeakPtr aParent) +{ + NS_INIT_ISUPPORTS(); + mParent = aParent; +} + +nsLoadListenerProxy::~nsLoadListenerProxy() +{ +} + +NS_IMPL_ISUPPORTS1(nsLoadListenerProxy, nsIDOMLoadListener) + +nsresult +nsLoadListenerProxy::HandleEvent(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->HandleEvent(aEvent); + } + + return NS_OK; +} + +nsresult +nsLoadListenerProxy::Load(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->Load(aEvent); + } + + return NS_OK; +} + +nsresult +nsLoadListenerProxy::Unload(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->Unload(aEvent); + } + + return NS_OK; +} + +nsresult +nsLoadListenerProxy::Abort(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->Abort(aEvent); + } + + return NS_OK; +} + +nsresult +nsLoadListenerProxy::Error(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->Error(aEvent); + } + + return NS_OK; +} + +nsSyncLoader::nsSyncLoader() +{ + NS_INIT_ISUPPORTS(); +} + +nsSyncLoader::~nsSyncLoader() +{ + //if (XML_HTTP_REQUEST_SENT == mStatus) { + // Abort(); + //} + if (mDocShellTreeOwner) { + mDocShellTreeOwner->ExitModalLoop(NS_OK); + } +} + +NS_IMPL_ISUPPORTS3(nsSyncLoader, nsISyncLoader, nsIDOMLoadListener, nsISupportsWeakReference) + +NS_IMETHODIMP +nsSyncLoader::LoadDocument(nsIURI* documentURI, nsIDocument **_retval) +{ + nsresult rv = NS_OK; + + nsCOMPtr loadGroup; + + // If we have a base document, use it for the base URL and loadgroup + //if (mBaseDocument) { + // rv = mBaseDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup)); + // if (NS_FAILED(rv)) return rv; + //} + + //rv = NS_NewURI(getter_AddRefs(uri), url, mBaseURI); + //if (NS_FAILED(rv)) return rv; + + nsCOMPtr channel; + rv = NS_OpenURI(getter_AddRefs(channel), documentURI, nsnull, loadGroup); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr postDataStream; + + // Make sure we've been opened + if (!channel) { + return NS_ERROR_NOT_INITIALIZED; + } + + // Get and initialize a DOMImplementation + nsCOMPtr implementation = do_CreateInstance(kIDOMDOMImplementationCID, &rv); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + //if (mBaseURI) { + // nsCOMPtr privImpl = do_QueryInterface(implementation); + // if (privImpl) { + // privImpl->Init(mBaseURI); + // } + //} + + // Create an empty document from it + nsAutoString emptyStr; + nsCOMPtr DOMDocument; + rv = implementation->CreateDocument(emptyStr, + emptyStr, + nsnull, + getter_AddRefs(DOMDocument)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + // Register as a load listener on the document + nsCOMPtr target = do_QueryInterface(DOMDocument); + if (target) { + nsWeakPtr requestWeak = getter_AddRefs(NS_GetWeakReference(NS_STATIC_CAST(nsIDOMLoadListener*, this))); + nsLoadListenerProxy* proxy = new nsLoadListenerProxy(requestWeak); + if (!proxy) return NS_ERROR_OUT_OF_MEMORY; + + // This will addref the proxy + rv = target->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMEventListener*, + proxy), + NS_GET_IID(nsIDOMLoadListener)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + } + + // Tell the document to start loading + nsCOMPtr listener; + nsCOMPtr document = do_QueryInterface(DOMDocument); + if (!document) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr modalEventQueue; + nsCOMPtr eventQService; + + nsCOMPtr cc; + NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv); + if(NS_SUCCEEDED(rv)) { + rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc)); + } + + JSContext* cx; + if (NS_SUCCEEDED(rv) && cc) { + rv = cc->GetJSContext(&cx); + if (NS_FAILED(rv)) NS_ERROR_FAILURE; + } + else { + NS_WITH_SERVICE(nsIAppShellService, appshellSvc, kAppShellServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + nsCOMPtr junk; + rv = appshellSvc->GetHiddenWindowAndJSContext(getter_AddRefs(junk), &cx); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + } + if (NS_SUCCEEDED(rv)) { + nsIScriptContext* scriptCX; + + // We can only do this if we're called from a DOM script context + scriptCX = (nsIScriptContext*)JS_GetContextPrivate(cx); + if (!scriptCX) return NS_OK; + + // Get the nsIDocShellTreeOwner associated with the window + // containing this script context + // XXX Need to find a better way to do this rather than + // chaining through a bunch of getters and QIs + nsCOMPtr global; + global = dont_AddRef(scriptCX->GetGlobalObject()); + if (!global) return NS_ERROR_FAILURE; + + nsCOMPtr docshell; + rv = global->GetDocShell(getter_AddRefs(docshell)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + nsCOMPtr item = do_QueryInterface(docshell); + if (!item) return NS_ERROR_FAILURE; + + rv = item->GetTreeOwner(getter_AddRefs(mDocShellTreeOwner)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + eventQService = do_GetService(kEventQueueServiceCID); + if(!eventQService || + NS_FAILED(eventQService->PushThreadEventQueue(getter_AddRefs(modalEventQueue)))) { + return NS_ERROR_FAILURE; + } + } + + rv = document->StartDocumentLoad(kLoadAsData, channel, + nsnull, nsnull, + getter_AddRefs(listener), + PR_FALSE); + + if (NS_FAILED(rv)) { + if (modalEventQueue) { + eventQService->PopThreadEventQueue(modalEventQueue); + } + return NS_ERROR_FAILURE; + } + + // Start reading from the channel + rv = channel->AsyncRead(listener, nsnull); + + if (NS_FAILED(rv)) { + if (modalEventQueue) { + eventQService->PopThreadEventQueue(modalEventQueue); + } + return NS_ERROR_FAILURE; + } + + // Spin an event loop here and wait + if (mDocShellTreeOwner) { + rv = mDocShellTreeOwner->ShowModal(); + + eventQService->PopThreadEventQueue(modalEventQueue); + + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + } + + *_retval = document; + NS_ADDREF(*_retval); + return rv; +} + +// nsIDOMEventListener +nsresult +nsSyncLoader::HandleEvent(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +// nsIDOMLoadListener +nsresult +nsSyncLoader::Load(nsIDOMEvent* aEvent) +{ + if (mDocShellTreeOwner) { + mDocShellTreeOwner->ExitModalLoop(NS_OK); + mDocShellTreeOwner = 0; + } + + return NS_OK; +} + +nsresult +nsSyncLoader::Unload(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +nsresult +nsSyncLoader::Abort(nsIDOMEvent* aEvent) +{ + if (mDocShellTreeOwner) { + mDocShellTreeOwner->ExitModalLoop(NS_OK); + mDocShellTreeOwner = 0; + } + + return NS_OK; +} + +nsresult +nsSyncLoader::Error(nsIDOMEvent* aEvent) +{ + if (mDocShellTreeOwner) { + mDocShellTreeOwner->ExitModalLoop(NS_OK); + mDocShellTreeOwner = 0; + } + + return NS_OK; +} diff --git a/extensions/transformiix/Makefile.in b/extensions/transformiix/Makefile.in index a6a32cac2350..45682e16b3cf 100644 --- a/extensions/transformiix/Makefile.in +++ b/extensions/transformiix/Makefile.in @@ -29,7 +29,7 @@ include $(DEPTH)/config/autoconf.mk DIRS = source ifdef MOZ_XSL -DIRS += build +DIRS += build public endif include $(topsrcdir)/config/rules.mk diff --git a/extensions/transformiix/build/Makefile.in b/extensions/transformiix/build/Makefile.in index 15025edd078a..4be7d10b106b 100644 --- a/extensions/transformiix/build/Makefile.in +++ b/extensions/transformiix/build/Makefile.in @@ -103,10 +103,12 @@ OBJS =../source/base/ArrayList.o \ ../source/xpath/VariableRefExpr.o \ ../source/xpath/WildCardExpr.o \ ../source/xpath/XPathNames.o \ + ../source/xpath/XPathProcessor.o \ ../source/xml/XMLUtils.o \ ../source/xml/XMLDOMUtils.o \ ../source/xml/util/DOMHelper.o \ ../source/xml/parser/XMLParser.o \ + ../source/xml/parser/nsSyncLoader.o \ ../source/xml/parser/hashtable.o \ ../source/xml/parser/xmlrole.o \ ../source/xml/parser/xmlparse.o \ @@ -117,8 +119,10 @@ OBJS =../source/base/ArrayList.o \ ../source/xslt/ProcessorState.o \ ../source/xslt/VariableBinding.o \ ../source/xslt/XSLTProcessor.o \ + ../source/xslt/functions/CurrentFunctionCall.o \ ../source/xslt/functions/DocumentFunctionCall.o \ ../source/xslt/functions/GenerateIdFunctionCall.o \ + ../source/xslt/functions/SystemPropertyFunctionCall.o \ ../source/xslt/util/NodeSorter.o \ ../source/xslt/util/NodeStack.o \ XSLTProcessorModule.o diff --git a/extensions/transformiix/build/XSLTProcessorModule.cpp b/extensions/transformiix/build/XSLTProcessorModule.cpp index 7c785e9cfd40..9e56a6b5e4ad 100755 --- a/extensions/transformiix/build/XSLTProcessorModule.cpp +++ b/extensions/transformiix/build/XSLTProcessorModule.cpp @@ -24,19 +24,214 @@ */ #include "nsIGenericFactory.h" +#include "nsIAppShellComponent.h" +#include "nsIScriptExternalNameSet.h" +#include "nsIScriptNameSetRegistry.h" +#include "nsIScriptNameSpaceManager.h" +#include "nsIScriptContext.h" +#include "nsIRegistry.h" +#include "nsDOMCID.h" +#include "prprf.h" #include "XSLTProcessor.h" +#include "XPathProcessor.h" +#include "nsSyncLoader.h" + +static NS_DEFINE_CID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID); // Factory Constructor NS_GENERIC_FACTORY_CONSTRUCTOR(XSLTProcessor) +NS_GENERIC_FACTORY_CONSTRUCTOR(XPathProcessor) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsSyncLoader) + +class TransformiixNameset : public nsIScriptExternalNameSet { +public: + TransformiixNameset(); + virtual ~TransformiixNameset(); + + // nsISupports + NS_DECL_ISUPPORTS + + // nsIScriptExternalNameSet + NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext); + NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext); +}; + +TransformiixNameset::TransformiixNameset() +{ + NS_INIT_ISUPPORTS(); +} + +TransformiixNameset::~TransformiixNameset() +{ +} + +NS_IMPL_ISUPPORTS1(TransformiixNameset, nsIScriptExternalNameSet) + +NS_IMETHODIMP +TransformiixNameset::InitializeClasses(nsIScriptContext* aScriptContext) +{ + return NS_OK; +} + +NS_IMETHODIMP +TransformiixNameset::AddNameSet(nsIScriptContext* aScriptContext) +{ + static NS_DEFINE_CID(kXSLTProcessor_CID, TRANSFORMIIX_XSLT_PROCESSOR_CID); + static NS_DEFINE_CID(kXPathProcessor_CID, TRANSFORMIIX_XPATH_PROCESSOR_CID); + nsresult result = NS_OK; + nsCOMPtr manager; + + result = aScriptContext->GetNameSpaceManager(getter_AddRefs(manager)); + if (NS_SUCCEEDED(result)) { + result = manager->RegisterGlobalName(NS_ConvertASCIItoUCS2("XSLTProcessor"), + NS_GET_IID(nsIDocumentTransformer), + kXSLTProcessor_CID, + PR_TRUE); + NS_ENSURE_SUCCESS(result, result); + + result = manager->RegisterGlobalName(NS_ConvertASCIItoUCS2("XPathProcessor"), + NS_GET_IID(nsIXPathNodeSelector), + kXPathProcessor_CID, + PR_TRUE); + NS_ENSURE_SUCCESS(result, result); + } + + return result; +} + +/* 878f99ae-1dd2-11b2-add2-edf7a72f957b */ +#define TRANSFORMIIX_CID \ +{ 0x878f99ae, 0x1dd2, 0x11b2, {0xad, 0xd2, 0xed, 0xf7, 0xa7, 0x2f, 0x95, 0x7b} } + +#define TRANSFORMIIX_CONTRACTID \ +NS_IAPPSHELLCOMPONENT_CONTRACTID "/Transformiix;1" + +class TransformiixComponent : public nsIAppShellComponent { +public: + TransformiixComponent(); + virtual ~TransformiixComponent(); + + NS_DEFINE_STATIC_CID_ACCESSOR(TRANSFORMIIX_CID); + + // nsISupports + NS_DECL_ISUPPORTS + + // nsIAppShellComponent + NS_DECL_NSIAPPSHELLCOMPONENT + + static TransformiixComponent *GetInstance(); + static TransformiixComponent* mInstance; +}; + +TransformiixComponent* TransformiixComponent::mInstance = nsnull; + +TransformiixComponent * +TransformiixComponent::GetInstance() +{ + if (mInstance == nsnull) { + mInstance = new TransformiixComponent(); + // Will be released in the module destructor + NS_IF_ADDREF(mInstance); + } + + NS_IF_ADDREF(mInstance); + return mInstance; +} + +TransformiixComponent::TransformiixComponent() +{ + NS_INIT_ISUPPORTS(); +} + +TransformiixComponent::~TransformiixComponent() +{ +} + +NS_IMPL_ISUPPORTS1(TransformiixComponent, nsIAppShellComponent) + +NS_IMETHODIMP +TransformiixComponent::Initialize(nsIAppShellService *anAppShell, + nsICmdLineService *aCmdLineService) +{ + nsresult rv; + nsCOMPtr namesetService = + do_GetService(kCScriptNameSetRegistryCID, &rv); + + if (NS_SUCCEEDED(rv)) { + TransformiixNameset* nameset = new TransformiixNameset(); + // the NameSet service will AddRef this one + namesetService->AddExternalNameSet(nameset); + } + + return rv; + +} + +NS_IMETHODIMP +TransformiixComponent::Shutdown() +{ + return NS_OK; +} + +NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(TransformiixComponent, TransformiixComponent::GetInstance); + +static NS_METHOD +RegisterTransformiix(nsIComponentManager *aCompMgr, + nsIFile *aPath, + const char *registryLocation, + const char *componentType) +{ + // get the registry + nsIRegistry* registry; + nsresult rv = nsServiceManager::GetService(NS_REGISTRY_CONTRACTID, + NS_GET_IID(nsIRegistry), + (nsISupports**)®istry); + if (NS_SUCCEEDED(rv)) { + registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + char buffer[256]; + char *cid = TransformiixComponent::GetCID().ToString(); + PR_snprintf(buffer, + sizeof buffer, + "%s/%s", + NS_IAPPSHELLCOMPONENT_KEY, + cid ? cid : "unknown" ); + nsCRT::free(cid); + + nsRegistryKey key; + rv = registry->AddSubtree(nsIRegistry::Common, + buffer, + &key ); + nsServiceManager::ReleaseService(NS_REGISTRY_CONTRACTID, registry); + } + return rv; +} // Component Table static nsModuleComponentInfo components[] = { + { "Transformiix component", + TRANSFORMIIX_CID, + TRANSFORMIIX_CONTRACTID, + TransformiixComponentConstructor, + RegisterTransformiix }, { "Transformiix XSLT Processor", TRANSFORMIIX_XSLT_PROCESSOR_CID, TRANSFORMIIX_XSLT_PROCESSOR_CONTRACTID, - XSLTProcessorConstructor } + XSLTProcessorConstructor }, + { "Transformiix XPath Processor", + TRANSFORMIIX_XPATH_PROCESSOR_CID, + TRANSFORMIIX_XPATH_PROCESSOR_CONTRACTID, + XPathProcessorConstructor }, + { "Transformiix Synchronous Loader", + TRANSFORMIIX_SYNCLOADER_CID, + TRANSFORMIIX_SYNCLOADER_CONTRACTID, + nsSyncLoaderConstructor } }; -// NSGetModule implementation. -NS_IMPL_NSGETMODULE("XSLTProcessorModule", components) +static void PR_CALLBACK +TransformiixModuleDtor(nsIModule* self) +{ + NS_IF_RELEASE(TransformiixComponent::mInstance); +} + +NS_IMPL_NSGETMODULE_WITH_DTOR("TransformiixModule", components, TransformiixModuleDtor) diff --git a/extensions/transformiix/build/makefile.win b/extensions/transformiix/build/makefile.win index cbb09268240d..4d72db40ed22 100644 --- a/extensions/transformiix/build/makefile.win +++ b/extensions/transformiix/build/makefile.win @@ -22,7 +22,9 @@ DEPTH=..\..\.. include <$(DEPTH)/config/config.mak> -DEFINES=-DMOZ_XSL +!ifdef MOZ_XSL +DEFINES= $(DEFINES) -DMOZ_XSL +!endif MODULE=transformiix IS_COMPONENT = 1 @@ -102,9 +104,11 @@ CPP_OBJS= \ ..\source\xpath\$(OBJDIR)\VariableRefExpr.obj \ ..\source\xpath\$(OBJDIR)\WildCardExpr.obj \ ..\source\xpath\$(OBJDIR)\XPathNames.obj \ + ..\source\xpath\$(OBJDIR)\XPathProcessor.obj \ ..\source\xml\$(OBJDIR)\XMLUtils.obj \ ..\source\xml\$(OBJDIR)\XMLDOMUtils.obj \ ..\source\xml\util\$(OBJDIR)\DOMHelper.obj \ + ..\source\xml\parser\$(OBJDIR)\nsSyncLoader.obj \ ..\source\xml\parser\$(OBJDIR)\XMLParser.obj \ ..\source\xslt\$(OBJDIR)\OutputFormat.obj \ ..\source\xslt\$(OBJDIR)\Names.obj \ @@ -112,8 +116,10 @@ CPP_OBJS= \ ..\source\xslt\$(OBJDIR)\ProcessorState.obj \ ..\source\xslt\$(OBJDIR)\VariableBinding.obj \ ..\source\xslt\$(OBJDIR)\XSLTProcessor.obj \ + ..\source\xslt\functions\$(OBJDIR)\CurrentFunctionCall.obj \ ..\source\xslt\functions\$(OBJDIR)\DocumentFunctionCall.obj \ ..\source\xslt\functions\$(OBJDIR)\GenerateIdFunctionCall.obj \ + ..\source\xslt\functions\$(OBJDIR)\SystemPropertyFunctionCall.obj \ ..\source\xslt\util\$(OBJDIR)\NodeSorter.obj \ ..\source\xslt\util\$(OBJDIR)\NodeStack.obj \ .\$(OBJDIR)\XSLTProcessorModule.obj \ @@ -132,13 +138,14 @@ LINCS= -I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I..\source\xslt\functions \ -I..\source\xml\dom -I..\source\xml\dom\mozImpl -I..\source\xml\util \ -I..\source\xpath -I..\source\xslt\util -I..\source\xml -I..\source\xslt \ -I..\source\base -I..\source\net -I..\source\xml\parser - + # These are the libraries we need to link with to create the dll LLIBS=$(LLIBS) $(LIBNSPR) \ $(DIST)\lib\xpcom.lib \ !ifndef NECKO $(DIST)\lib\netlib.lib \ !endif + $(DIST)\lib\js3250.lib \ $(DIST)\lib\expat.lib WIN_LIBS = \ diff --git a/extensions/transformiix/makefile.win b/extensions/transformiix/makefile.win index 0720b266a187..cde38d835ca3 100644 --- a/extensions/transformiix/makefile.win +++ b/extensions/transformiix/makefile.win @@ -21,6 +21,16 @@ DEPTH=..\.. -DIRS=source build +!ifdef MOZ_XSL +DIRS=source build public +!else +DIRS=$(DEPTH)\expat source +!endif include <$(DEPTH)\config\rules.mak> + +standalone: setenv all + +setenv: + @set INCS=-UMOZILLA_CLIENT -DXML_DTD=1 -DXML_UNICODE + @set MOZ_XSL= diff --git a/extensions/transformiix/public/Makefile.in b/extensions/transformiix/public/Makefile.in new file mode 100644 index 000000000000..98af46f27aa8 --- /dev/null +++ b/extensions/transformiix/public/Makefile.in @@ -0,0 +1,70 @@ +# +# 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 mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# Peter Van der Beken, peterv@netscape.com +# -- original author. + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = transformiix + +XPIDLSRCS = \ + nsIXPathNodeSelector.idl \ + nsISyncLoader.idl \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/transformiix/public/makefile.win b/extensions/transformiix/public/makefile.win new file mode 100644 index 000000000000..884d23878eef --- /dev/null +++ b/extensions/transformiix/public/makefile.win @@ -0,0 +1,33 @@ +#!nmake +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# Peter Van der Beken, peterv@netscape.com +# -- original author. + +DEPTH=..\..\.. + +XPIDLSRCS = .\nsIXPathNodeSelector.idl \ + .\nsISyncLoader.idl \ + $(NULL) + +MODULE=transformiix + +include <$(DEPTH)\config\rules.mak> + diff --git a/extensions/transformiix/public/nsISyncLoader.idl b/extensions/transformiix/public/nsISyncLoader.idl new file mode 100644 index 000000000000..45b5d788d563 --- /dev/null +++ b/extensions/transformiix/public/nsISyncLoader.idl @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Peter Van der Beken, peter.vanderbeken@pandora.be + * -- original author. + * + */ + +#include "nsISupports.idl" + +interface nsIURI; +interface nsIDocument; + +/** + * The nsISyncLoader interface can be used to synchronously load + * a document. + */ + +[scriptable, uuid(bb159fcc-1dd1-11b2-91ad-c71866a10fd4)] +interface nsISyncLoader : nsISupports { + + /** + * Synchronously load the document specified in documentURI. + * + * @param documentURI The URI of the document to load. + * + * @returns The document loaded from the URI. + */ + nsIDocument loadDocument(in nsIURI aDocumentURI); +}; + +%{ C++ +#define TRANSFORMIIX_SYNCLOADER_CID \ + { /* b63a5d90-1dd1-11b2-bbac-d87f512d79c9 */ \ + 0xb63a5d90, 0x1dd1, 0x11b2, \ + {0xbb, 0xac, 0xd8, 0x7f, 0x51, 0x2d, 0x79, 0xc9} } +#define TRANSFORMIIX_SYNCLOADER_CONTRACTID \ +"@mozilla.org/transformiix/syncloader;1" +%} diff --git a/extensions/transformiix/public/nsIXPathNodeSelector.idl b/extensions/transformiix/public/nsIXPathNodeSelector.idl new file mode 100644 index 000000000000..3b41c1a4aa12 --- /dev/null +++ b/extensions/transformiix/public/nsIXPathNodeSelector.idl @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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. + * + */ + +#include "nsISupports.idl" + +interface nsIDOMNode; +interface nsIDOMNodeList; + +/** + * The nsIXPathNodeSelector can be used to query a DOM tree using XPath. + */ + +[scriptable, uuid(f70c3f08-1dd1-11b2-b582-db02dfacb173)] +interface nsIXPathNodeSelector : nsISupports +{ + + /** + * Return a nodelist that is the result of an XPath query of the tree + * fragment starting with the context node. + * + * @param aContextNode The context node for the query. + * @param aPattern The pattern for the query. + * + * @returns The result of the XPath query. + */ + nsIDOMNodeList selectNodes(in nsIDOMNode aContextNode, + in string aPattern); +}; + + +%{ C++ +extern nsresult +NS_NewXPathNodeSelector(nsIXPathNodeSelector** aNodeSelector); +%} diff --git a/extensions/transformiix/source/base/HashTable.cpp b/extensions/transformiix/source/base/HashTable.cpp index 964ec09a3f6a..9894e3e6f2b8 100644 --- a/extensions/transformiix/source/base/HashTable.cpp +++ b/extensions/transformiix/source/base/HashTable.cpp @@ -29,7 +29,9 @@ // Who When What #include "HashTable.h" +#ifndef MOZ_XSL #include +#endif HashTable::HashTable() { diff --git a/extensions/transformiix/source/base/List.cpp b/extensions/transformiix/source/base/List.cpp index 2f5808ff8a2c..a272aabf1259 100644 --- a/extensions/transformiix/source/base/List.cpp +++ b/extensions/transformiix/source/base/List.cpp @@ -23,11 +23,13 @@ * Bob Miller, kbob@oblix.com * -- plugged core leak. * - * $Id: List.cpp,v 1.4 2000/05/29 07:14:03 kvisco%ziplink.net Exp $ + * $Id: List.cpp,v 1.5 2001/01/12 20:06:08 axel%pike.org Exp $ */ #include "List.h" +#ifndef MOZ_XSL #include +#endif //--------------------------/ //- Implementation of List -/ @@ -36,7 +38,7 @@ /** * Default constructor for a List; * @author Keith Visco - * @version $Revision: 1.4 $ $Date: 2000/05/29 07:14:03 $ + * @version $Revision: 1.5 $ $Date: 2001/01/12 20:06:08 $ **/ List::List() { diff --git a/extensions/transformiix/source/base/MozillaString.cpp b/extensions/transformiix/source/base/MozillaString.cpp index fe124996bf85..6a740c28d82f 100644 --- a/extensions/transformiix/source/base/MozillaString.cpp +++ b/extensions/transformiix/source/base/MozillaString.cpp @@ -35,7 +35,9 @@ #include #include #include "TxString.h" +#ifndef MOZ_XSL #include +#endif // //Default constructor ( nsString() ) @@ -531,7 +533,7 @@ MBool String::isEqual(const String& data) const { if (this == &data) return MB_TRUE; - else if (ptrNSString->Length() != data.length()) + else if (length() != data.length()) return MB_FALSE; else { diff --git a/extensions/transformiix/source/base/StringList.cpp b/extensions/transformiix/source/base/StringList.cpp index 7f933eee59df..df17dbdf09e5 100644 --- a/extensions/transformiix/source/base/StringList.cpp +++ b/extensions/transformiix/source/base/StringList.cpp @@ -23,16 +23,18 @@ * Bob Miller, kbob@oblix.com * -- plugged core leak. * - * $Id: StringList.cpp,v 1.4 2000/02/17 20:56:19 kvisco%ziplink.net Exp $ + * $Id: StringList.cpp,v 1.5 2001/01/12 20:06:08 axel%pike.org Exp $ */ /** * StringList * @author Keith Visco - * @version $Revision: 1.4 $ $Date: 2000/02/17 20:56:19 $ + * @version $Revision: 1.5 $ $Date: 2001/01/12 20:06:08 $ **/ +#ifndef MOZ_XSL #include +#endif #include "StringList.h" /** diff --git a/extensions/transformiix/source/base/baseutils.h b/extensions/transformiix/source/base/baseutils.h index 2f647389ba75..e3df81bc5fa4 100644 --- a/extensions/transformiix/source/base/baseutils.h +++ b/extensions/transformiix/source/base/baseutils.h @@ -24,7 +24,7 @@ * Tom Kneeland, tomk@mitre.org * -- added UInt32 to provide a common unsigned integer * - * $Id: baseutils.h,v 1.5 2000/08/26 04:45:02 Peter.VanderBeken%pandora.be Exp $ + * $Id: baseutils.h,v 1.6 2001/01/12 20:06:09 axel%pike.org Exp $ */ // Basic Definitions used throughout many of these classes @@ -34,7 +34,7 @@ #define TRANSFRMX_BASEUTILS_H typedef int Int32; -#ifndef nsNetUtil_h__ +#ifndef __MACTYPES__ typedef unsigned int UInt32; #endif diff --git a/extensions/transformiix/source/base/makefile.win b/extensions/transformiix/source/base/makefile.win index 3e1aae49cd89..e4bbbaa99c4c 100644 --- a/extensions/transformiix/source/base/makefile.win +++ b/extensions/transformiix/source/base/makefile.win @@ -22,7 +22,7 @@ DEPTH=..\..\..\.. !if defined(MOZ_XSL) -DEFINES=-DMOZ_XSL +DEFINES= $(DEFINES) -DMOZ_XSL !endif CPPSRCS= \ @@ -34,17 +34,25 @@ CPPSRCS= \ Integer.cpp \ List.cpp \ MITREObjectWrapper.cpp \ - MozillaString.cpp \ NamedMap.cpp \ SimpleErrorObserver.cpp \ Stack.cpp \ Map.cpp \ StringComparator.cpp \ StringList.cpp \ - Tokenizer.cpp \ - $(NULL) + Tokenizer.cpp -CPP_OBJS= \ +!ifdef MOZ_XSL +CPPSRCS = $(CPPSRCS) \ + MozillaString.cpp \ + $(NULL) +!else +CPPSRCS = $(CPPSRCS) \ + TxString.cpp \ + $(NULL) +!endif + +CPP_OBJS= \ .\$(OBJDIR)\ArrayList.obj \ .\$(OBJDIR)\CommandLineUtils.obj \ .\$(OBJDIR)\DefaultStringComparator.obj \ @@ -53,15 +61,23 @@ CPP_OBJS= \ .\$(OBJDIR)\Integer.obj \ .\$(OBJDIR)\List.obj \ .\$(OBJDIR)\MITREObjectWrapper.obj \ - .\$(OBJDIR)\MozillaString.obj \ .\$(OBJDIR)\NamedMap.obj \ .\$(OBJDIR)\SimpleErrorObserver.obj \ .\$(OBJDIR)\Stack.obj \ .\$(OBJDIR)\Map.obj \ .\$(OBJDIR)\StringComparator.obj \ .\$(OBJDIR)\StringList.obj \ - .\$(OBJDIR)\Tokenizer.obj \ + .\$(OBJDIR)\Tokenizer.obj + +!ifdef MOZ_XSL +CPP_OBJS = $(CPP_OBJS) \ + .\$(OBJDIR)\MozillaString.obj \ $(NULL) +!else +CPP_OBJS = $(CPP_OBJS) \ + .\$(OBJDIR)\TxString.obj \ + $(NULL) +!endif EXPORTS = \ $(NULL) diff --git a/extensions/transformiix/source/main/Makefile.in b/extensions/transformiix/source/main/Makefile.in index 8877d46f1f2c..e93f8ec51415 100644 --- a/extensions/transformiix/source/main/Makefile.in +++ b/extensions/transformiix/source/main/Makefile.in @@ -114,8 +114,10 @@ OBJS =../base/ArrayList.o \ ../xslt/ProcessorState.o \ ../xslt/VariableBinding.o \ ../xslt/XSLTProcessor.o \ + ../xslt/functions/CurrentFunctionCall.o \ ../xslt/functions/DocumentFunctionCall.o \ ../xslt/functions/GenerateIdFunctionCall.o \ + ../xslt/functions/SystemPropertyFunctionCall.o \ ../xslt/util/NodeSorter.o \ ../xslt/util/NodeStack.o \ transformiix.o diff --git a/extensions/transformiix/source/main/makefile.win b/extensions/transformiix/source/main/makefile.win new file mode 100644 index 000000000000..e552852224d8 --- /dev/null +++ b/extensions/transformiix/source/main/makefile.win @@ -0,0 +1,139 @@ +#!nmake +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\..\.. + +MAKE_OBJ_TYPE = EXE +PROGRAM = ..\..\transformiix.exe + +CPP_OBJS= \ + ../base/$(OBJDIR)/ArrayList.obj \ + ../base/$(OBJDIR)/CommandLineUtils.obj \ + ../base/$(OBJDIR)/DefaultStringComparator.obj \ + ../base/$(OBJDIR)/Double.obj \ + ../base/$(OBJDIR)/HashTable.obj \ + ../base/$(OBJDIR)/Integer.obj \ + ../base/$(OBJDIR)/List.obj \ + ../base/$(OBJDIR)/MITREObjectWrapper.obj \ + ../base/$(OBJDIR)/Map.obj \ + ../base/$(OBJDIR)/NamedMap.obj \ + ../base/$(OBJDIR)/SimpleErrorObserver.obj \ + ../base/$(OBJDIR)/Stack.obj \ + ../base/$(OBJDIR)/StringComparator.obj \ + ../base/$(OBJDIR)/StringList.obj \ + ../base/$(OBJDIR)/Tokenizer.obj \ + ../base/$(OBJDIR)/TxString.obj \ + ../net/$(OBJDIR)/URIUtils.obj \ + ../xml/dom/standalone/$(OBJDIR)/Attr.obj \ + ../xml/dom/standalone/$(OBJDIR)/CDATASection.obj \ + ../xml/dom/standalone/$(OBJDIR)/DocumentType.obj \ + ../xml/dom/standalone/$(OBJDIR)/EntityReference.obj \ + ../xml/dom/standalone/$(OBJDIR)/CharacterData.obj \ + ../xml/dom/standalone/$(OBJDIR)/Comment.obj \ + ../xml/dom/standalone/$(OBJDIR)/DocumentFragment.obj \ + ../xml/dom/standalone/$(OBJDIR)/DOMImplementation.obj \ + ../xml/dom/standalone/$(OBJDIR)/NodeListDefinition.obj \ + ../xml/dom/standalone/$(OBJDIR)/NodeDefinition.obj \ + ../xml/dom/standalone/$(OBJDIR)/Element.obj \ + ../xml/dom/standalone/$(OBJDIR)/NamedNodeMap.obj \ + ../xml/dom/standalone/$(OBJDIR)/Document.obj \ + ../xml/dom/standalone/$(OBJDIR)/Entity.obj \ + ../xml/dom/standalone/$(OBJDIR)/Notation.obj \ + ../xml/dom/standalone/$(OBJDIR)/ProcessingInstruction.obj \ + ../xml/dom/standalone/$(OBJDIR)/Text.obj \ + ../xpath/$(OBJDIR)/AdditiveExpr.obj \ + ../xpath/$(OBJDIR)/AttributeExpr.obj \ + ../xpath/$(OBJDIR)/AttributeValueTemplate.obj \ + ../xpath/$(OBJDIR)/BasicNodeExpr.obj \ + ../xpath/$(OBJDIR)/BooleanExpr.obj \ + ../xpath/$(OBJDIR)/BooleanFunctionCall.obj \ + ../xpath/$(OBJDIR)/BooleanResult.obj \ + ../xpath/$(OBJDIR)/ElementExpr.obj \ + ../xpath/$(OBJDIR)/ErrorFunctionCall.obj \ + ../xpath/$(OBJDIR)/ExprLexer.obj \ + ../xpath/$(OBJDIR)/ExprParser.obj \ + ../xpath/$(OBJDIR)/ExtensionFunctionCall.obj \ + ../xpath/$(OBJDIR)/FilterExpr.obj \ + ../xpath/$(OBJDIR)/FunctionCall.obj \ + ../xpath/$(OBJDIR)/IdentityExpr.obj \ + ../xpath/$(OBJDIR)/LocationStep.obj \ + ../xpath/$(OBJDIR)/MultiplicativeExpr.obj \ + ../xpath/$(OBJDIR)/NodeSet.obj \ + ../xpath/$(OBJDIR)/NodeSetFunctionCall.obj \ + ../xpath/$(OBJDIR)/NumberExpr.obj \ + ../xpath/$(OBJDIR)/NumberFunctionCall.obj \ + ../xpath/$(OBJDIR)/NumberResult.obj \ + ../xpath/$(OBJDIR)/ParentExpr.obj \ + ../xpath/$(OBJDIR)/PathExpr.obj \ + ../xpath/$(OBJDIR)/PredicateList.obj \ + ../xpath/$(OBJDIR)/RelationalExpr.obj \ + ../xpath/$(OBJDIR)/RootExpr.obj \ + ../xpath/$(OBJDIR)/StringExpr.obj \ + ../xpath/$(OBJDIR)/StringFunctionCall.obj \ + ../xpath/$(OBJDIR)/StringResult.obj \ + ../xpath/$(OBJDIR)/TextExpr.obj \ + ../xpath/$(OBJDIR)/UnionExpr.obj \ + ../xpath/$(OBJDIR)/VariableRefExpr.obj \ + ../xpath/$(OBJDIR)/WildCardExpr.obj \ + ../xpath/$(OBJDIR)/XPathNames.obj \ + ../xml/$(OBJDIR)/XMLUtils.obj \ + ../xml/$(OBJDIR)/XMLDOMUtils.obj \ + ../xml/util/$(OBJDIR)/DOMHelper.obj \ + ../xml/parser/$(OBJDIR)/XMLParser.obj \ + ../xml/printer/$(OBJDIR)/XMLPrinter.obj \ + ../xml/printer/$(OBJDIR)/HTMLPrinter.obj \ + ../xml/printer/$(OBJDIR)/TEXTPrinter.obj \ + ../xslt/$(OBJDIR)/OutputFormat.obj \ + ../xslt/$(OBJDIR)/Names.obj \ + ../xslt/$(OBJDIR)/Numbering.obj \ + ../xslt/$(OBJDIR)/ProcessorState.obj \ + ../xslt/$(OBJDIR)/VariableBinding.obj \ + ../xslt/$(OBJDIR)/XSLTProcessor.obj \ + ../xslt/functions/$(OBJDIR)/CurrentFunctionCall.obj \ + ../xslt/functions/$(OBJDIR)/DocumentFunctionCall.obj \ + ../xslt/functions/$(OBJDIR)/GenerateIdFunctionCall.obj \ + ../xslt/functions/$(OBJDIR)/SystemPropertyFunctionCall.obj \ + ../xslt/util/$(OBJDIR)/NodeSorter.obj \ + ../xslt/util/$(OBJDIR)/NodeStack.obj \ + ./$(OBJDIR)/transformiix.obj \ + $(NULL) + +EXPORTS = \ + $(NULL) + +LINCS=-I../xslt -I../base -I../net \ + -I../xml -I../xml/dom -I../xml/util \ + -I../xml/printer -I../xpath -I../xslt/util \ + -I../xslt/functions -I../xml/parser + +LCFLAGS = \ + $(LCFLAGS) \ + $(DEFINES) \ + $(NULL) + +LLIBS= \ + $(DIST)\lib\expat.lib \ + $(NULL) + +CPP_PROG_LINK = 1 +include <$(DEPTH)\config\rules.mak> + +install:: $(OBJDIR) $(PROGRAM) diff --git a/extensions/transformiix/source/makefile.win b/extensions/transformiix/source/makefile.win index 8be8de8101e6..70cc0dad7486 100644 --- a/extensions/transformiix/source/makefile.win +++ b/extensions/transformiix/source/makefile.win @@ -22,8 +22,11 @@ DEPTH=..\..\.. DIRS=base net xml xpath xslt -!if defined(MOZ_XSL) -DIRS=$(DIRS) examples\mozilla\Transformiix + +!ifndef MOZ_XSL +DIRS = $(DIRS) main +!else +DIRS = $(DIRS) examples\mozilla\Transformiix !endif include <$(DEPTH)\config\rules.mak> diff --git a/extensions/transformiix/source/net/URIUtils.cpp b/extensions/transformiix/source/net/URIUtils.cpp index 9715de94edb9..83759587f916 100644 --- a/extensions/transformiix/source/net/URIUtils.cpp +++ b/extensions/transformiix/source/net/URIUtils.cpp @@ -29,7 +29,7 @@ * -- 20000326 * -- added Mozilla integration code * - * $Id: URIUtils.cpp,v 1.6 2000/07/06 12:35:35 axel%pike.org Exp $ + * $Id: URIUtils.cpp,v 1.7 2001/01/12 20:06:13 axel%pike.org Exp $ */ #include "URIUtils.h" @@ -38,9 +38,10 @@ * URIUtils * A set of utilities for handling URIs * @author Keith Visco - * @version $Revision: 1.6 $ $Date: 2000/07/06 12:35:35 $ + * @version $Revision: 1.7 $ $Date: 2001/01/12 20:06:13 $ **/ +#ifndef MOZ_XSL //- Constants -/ const String URIUtils::HTTP_PROTOCOL = "http"; @@ -112,13 +113,13 @@ istream* URIUtils::getInputStream return inStream; } //-- getInputStream +#endif /** * Returns the document base of the href argument * @return the document base of the given href **/ void URIUtils::getDocumentBase(String& href, String& dest) { - #ifdef MOZ_XSL String docBase(""); nsCOMPtr pURL; @@ -165,7 +166,6 @@ void URIUtils::getDocumentBase(String& href, String& dest) { } dest.append(docBase); #endif - } //-- getDocumentBase /** @@ -174,8 +174,6 @@ void URIUtils::getDocumentBase(String& href, String& dest) { * The new resolved href will be appended to the given dest String **/ void URIUtils::resolveHref(String& href, String& documentBase, String& dest) { - - #ifdef MOZ_XSL nsCOMPtr pURL; nsresult result = NS_OK; @@ -183,14 +181,14 @@ void URIUtils::resolveHref(String& href, String& documentBase, String& dest) { NS_WITH_SERVICE(nsIIOService, pService, kIOServiceCID, &result); if (NS_SUCCEEDED(result)) { // XXX This is ugly, there must be an easier (cleaner way). - char *baseStr = (((String)documentBase).getConstNSString()).ToNewCString(); + char *baseStr = (documentBase.getConstNSString()).ToNewCString(); result = pService->NewURI(baseStr, nsnull, getter_AddRefs(pURL)); nsCRT::free(baseStr); if (NS_SUCCEEDED(result)) { nsXPIDLCString newURL; // XXX This is ugly, there must be an easier (cleaner way). - char *hrefStr = (((String)documentBase).getConstNSString()).ToNewCString(); + char *hrefStr = (href.getConstNSString()).ToNewCString(); result = pURL->Resolve(hrefStr, getter_Copies(newURL)); nsCRT::free(hrefStr); if (NS_SUCCEEDED(result)) { @@ -234,9 +232,9 @@ void URIUtils::resolveHref(String& href, String& documentBase, String& dest) { delete uri; delete newUri; #endif - } //-- resolveHref +#ifndef MOZ_XSL istream* URIUtils::openStream(ParsedURI* uri) { if ( !uri ) return 0; // check protocol @@ -264,11 +262,11 @@ URIUtils::ParsedURI* URIUtils::parseURI(const String& uri) { // look for protocol int totalCount = uri.length(); int charCount = 0; - char prevCh = '\0'; + UNICODE_CHAR prevCh = '\0'; int fslash = 0; String buffer(uri.length()); while ( charCount < totalCount ) { - char ch = uri.charAt(charCount++); + UNICODE_CHAR ch = uri.charAt(charCount++); switch(ch) { case '.' : if ( mode == PROTOCOL_MODE ) { @@ -286,7 +284,6 @@ URIUtils::ParsedURI* URIUtils::parseURI(const String& uri) { mode = HOST_MODE; break; case HOST_MODE : - uriTokens->host = buffer; buffer.clear(); mode = PORT_MODE; @@ -383,5 +380,5 @@ void main(int argc, char** argv) { cout << "resolved url : " << url << endl; } -/* -*- */ - +*/ +#endif \ No newline at end of file diff --git a/extensions/transformiix/source/net/URIUtils.h b/extensions/transformiix/source/net/URIUtils.h index 644acf57a59f..def31d93e2e8 100644 --- a/extensions/transformiix/source/net/URIUtils.h +++ b/extensions/transformiix/source/net/URIUtils.h @@ -31,15 +31,14 @@ * -- 20000326 * -- added Mozilla integration code * - * $Id: URIUtils.h,v 1.9 2000/08/27 17:24:04 axel%pike.org Exp $ + * $Id: URIUtils.h,v 1.10 2001/01/12 20:06:13 axel%pike.org Exp $ */ #include "TxString.h" #include "baseutils.h" -#include +#ifndef MOZ_XSL #include - -#ifdef MOZ_XSL +#else #include "nsIServiceManager.h" #include "nsIIOService.h" #include "nsIURL.h" @@ -57,7 +56,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); * A utility class for URI handling * Not yet finished, only handles file URI at this point * @author Keith Visco - * @version $Revision: 1.9 $ $Date: 2000/08/27 17:24:04 $ + * @version $Revision: 1.10 $ $Date: 2001/01/12 20:06:13 $ * **/ diff --git a/extensions/transformiix/source/net/makefile.win b/extensions/transformiix/source/net/makefile.win index 40b04f021a86..79916bfe8582 100644 --- a/extensions/transformiix/source/net/makefile.win +++ b/extensions/transformiix/source/net/makefile.win @@ -22,7 +22,7 @@ DEPTH=..\..\..\.. !if defined(MOZ_XSL) -DEFINES=-DMOZ_XSL +DEFINES= $(DEFINES) -DMOZ_XSL !endif CPPSRCS= \ diff --git a/extensions/transformiix/source/xml/XMLDOMUtils.cpp b/extensions/transformiix/source/xml/XMLDOMUtils.cpp index 66621a3b78ed..366279d72ec1 100644 --- a/extensions/transformiix/source/xml/XMLDOMUtils.cpp +++ b/extensions/transformiix/source/xml/XMLDOMUtils.cpp @@ -21,13 +21,13 @@ * Keith Visco * -- original author. * - * $Id: XMLDOMUtils.cpp,v 1.7 2000/10/26 16:45:26 axel%pike.org Exp $ + * $Id: XMLDOMUtils.cpp,v 1.8 2001/01/12 20:06:16 axel%pike.org Exp $ */ /** * XMLDOMUtils * @author Keith Visco - * @version $Revision: 1.7 $ $Date: 2000/10/26 16:45:26 $ + * @version $Revision: 1.8 $ $Date: 2001/01/12 20:06:16 $ **/ #include "XMLDOMUtils.h" @@ -46,7 +46,7 @@ Node* XMLDOMUtils::copyNode(Node* node, Document* owner, NamespaceResolver* reso //-- document nodes if ((nodeType != Node::DOCUMENT_NODE) && (!owner)) return 0; Node* newNode = 0; - int i = 0; + UInt32 i = 0; switch ( nodeType ) { case Node::ATTRIBUTE_NODE : @@ -62,7 +62,7 @@ Node* XMLDOMUtils::copyNode(Node* node, Document* owner, NamespaceResolver* reso Document* doc = (Document*)node; Document* newDoc = new Document(); #ifdef MOZ_XSL - owner->addWrapper(newDoc, newDoc->getKey()); + owner->addWrapper(newDoc); #endif NodeList* nl = doc->getChildNodes(); for (i = 0; i < nl->getLength(); i++) { @@ -154,7 +154,7 @@ void XMLDOMUtils::getNodeValue(Node* node, String* target) { case Node::ELEMENT_NODE : { nl = node->getChildNodes(); - for ( int i = 0; i < nl->getLength(); i++) { + for (UInt32 i = 0; i < nl->getLength(); i++) { nodeType = nl->item(i)->getNodeType(); if ((nodeType == Node::TEXT_NODE) || (nodeType == Node::ELEMENT_NODE)) diff --git a/extensions/transformiix/source/xml/dom/makefile.win b/extensions/transformiix/source/xml/dom/makefile.win index 5d58efe70208..720121167ca3 100644 --- a/extensions/transformiix/source/xml/dom/makefile.win +++ b/extensions/transformiix/source/xml/dom/makefile.win @@ -21,6 +21,10 @@ DEPTH=..\..\..\..\.. -DIRS=mozImpl +!ifdef MOZ_XSL +DIRS = mozImpl +!else +DIRS = standalone +!endif include <$(DEPTH)\config\rules.mak> diff --git a/extensions/transformiix/source/xml/dom/mozImpl/MozillaDocument.cpp b/extensions/transformiix/source/xml/dom/mozImpl/MozillaDocument.cpp index a3cf8df129f1..4f82e2efc680 100644 --- a/extensions/transformiix/source/xml/dom/mozImpl/MozillaDocument.cpp +++ b/extensions/transformiix/source/xml/dom/mozImpl/MozillaDocument.cpp @@ -31,6 +31,13 @@ static NS_DEFINE_CID(kIDOMDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID); +PR_STATIC_CALLBACK(PRBool) +DeleteWrapper(nsHashKey *aKey, void *aData, void* closure) +{ + delete (MozillaObjectWrapper*)aData; + return PR_TRUE; +} + /** * Construct a new Mozilla document and wrap it. The caller is responsible for * deleting the wrapper object! @@ -50,8 +57,9 @@ Document::Document() : Node(NULL, NULL) getter_AddRefs(document)); //if (NS_FAILED(res)) return NULL; nsDocument = document; + wrapperHashTable = new nsObjectHashtable(nsnull, nsnull, DeleteWrapper, nsnull); bInHashTableDeletion = PR_FALSE; - addWrapper(this, getKey()); + addWrapper(this); } /** @@ -63,8 +71,9 @@ Document::Document() : Node(NULL, NULL) Document::Document(nsIDOMDocument* aDocument) : Node(aDocument, this) { nsDocument = aDocument; + wrapperHashTable = new nsObjectHashtable(nsnull, nsnull, DeleteWrapper, nsnull); bInHashTableDeletion = PR_FALSE; - addWrapper(this, getKey()); + addWrapper(this); } /** @@ -72,8 +81,9 @@ Document::Document(nsIDOMDocument* aDocument) : Node(aDocument, this) */ Document::~Document() { - removeWrapper(getKey()); + removeWrapper(this); bInHashTableDeletion = PR_TRUE; + delete wrapperHashTable; } /** @@ -190,8 +200,9 @@ DocumentFragment* Document::createDocumentFragment( if (aFragment) { + nsISupportsKey key(aFragment); docFragWrapper = - (DocumentFragment*)wrapperHashTable.retrieve(aFragment); + (DocumentFragment*)wrapperHashTable->Get(&key); if (!docFragWrapper) docFragWrapper = new DocumentFragment(aFragment, this); @@ -218,6 +229,23 @@ Element* Document::createElement(const String& aTagName) return NULL; } +/** + * Call nsIDOMDocument::GetElementById to get Element with ID. + * + * @param aID the name of ID referencing the element + * + * @return the Element + */ +Element* Document::getElementById(const String aID) +{ + nsCOMPtr element; + + if (NS_SUCCEEDED(nsDocument->GetElementById(aID.getConstNSString(), getter_AddRefs(element)))) + return createElement(element); + else + return NULL; +} + /** * Create a wrapper for a nsIDOMElement, reuses an existing wrapper if possible. * @@ -231,7 +259,8 @@ Element* Document::createElement(nsIDOMElement* aElement) if (aElement) { - elemWrapper = (Element*)wrapperHashTable.retrieve(aElement); + nsISupportsKey key(aElement); + elemWrapper = (Element*)wrapperHashTable->Get(&key); if (!elemWrapper) elemWrapper = new Element(aElement, this); @@ -295,7 +324,8 @@ Attr* Document::createAttribute(nsIDOMAttr* aAttr) if (aAttr) { - attrWrapper = (Attr*)wrapperHashTable.retrieve(aAttr); + nsISupportsKey key(aAttr); + attrWrapper = (Attr*)wrapperHashTable->Get(&key); if (!attrWrapper) attrWrapper = new Attr(aAttr, this); @@ -338,7 +368,8 @@ Text* Document::createTextNode(nsIDOMText* aText) if (aText) { - textWrapper = (Text*)wrapperHashTable.retrieve(aText); + nsISupportsKey key(aText); + textWrapper = (Text*)wrapperHashTable->Get(&key); if (!textWrapper) textWrapper = new Text(aText, this); @@ -381,7 +412,8 @@ Comment* Document::createComment(nsIDOMComment* aComment) if (aComment) { - commentWrapper = (Comment*)wrapperHashTable.retrieve(aComment); + nsISupportsKey key(aComment); + commentWrapper = (Comment*)wrapperHashTable->Get(&key); if (!commentWrapper) commentWrapper = new Comment(aComment, this); @@ -425,7 +457,8 @@ CDATASection* Document::createCDATASection(nsIDOMCDATASection* aCdata) if (cdataWrapper) { - cdataWrapper = (CDATASection*)wrapperHashTable.retrieve(aCdata); + nsISupportsKey key(aCdata); + cdataWrapper = (CDATASection*)wrapperHashTable->Get(&key); if (!cdataWrapper) cdataWrapper = new CDATASection(aCdata, this); @@ -474,7 +507,8 @@ ProcessingInstruction* Document::createProcessingInstruction( if (aPi) { - piWrapper = (ProcessingInstruction*)wrapperHashTable.retrieve(aPi); + nsISupportsKey key(aPi); + piWrapper = (ProcessingInstruction*)wrapperHashTable->Get(&key); if (!piWrapper) piWrapper = new ProcessingInstruction(aPi, this); @@ -519,8 +553,8 @@ EntityReference* Document::createEntityReference( if (aEntityRef) { - entityWrapper = (EntityReference*) wrapperHashTable.retrieve( - aEntityRef); + nsISupportsKey key(aEntityRef); + entityWrapper = (EntityReference*)wrapperHashTable->Get(&key); if (!entityWrapper) entityWrapper = new EntityReference(aEntityRef, this); @@ -542,7 +576,8 @@ Entity* Document::createEntity(nsIDOMEntity* aEntity) if (aEntity) { - entityWrapper = (Entity*)wrapperHashTable.retrieve(aEntity); + nsISupportsKey key(aEntity); + entityWrapper = (Entity*)wrapperHashTable->Get(&key); if (!entityWrapper) entityWrapper = new Entity(aEntity, this); @@ -564,7 +599,8 @@ Node* Document::createNode(nsIDOMNode* aNode) if (aNode) { - nodeWrapper = (Node*)wrapperHashTable.retrieve(aNode); + nsISupportsKey key(aNode); + nodeWrapper = (Node*)wrapperHashTable->Get(&key); if (!nodeWrapper) nodeWrapper = new Node(aNode, this); @@ -587,7 +623,8 @@ Notation* Document::createNotation(nsIDOMNotation* aNotation) if (aNotation) { - notationWrapper = (Notation*)wrapperHashTable.retrieve(aNotation); + nsISupportsKey key(aNotation); + notationWrapper = (Notation*)wrapperHashTable->Get(&key); if (!notationWrapper) notationWrapper = new Notation(aNotation, this); @@ -611,7 +648,8 @@ DOMImplementation* Document::createDOMImplementation( if (aImpl) { - implWrapper = (DOMImplementation*)wrapperHashTable.retrieve(aImpl); + nsISupportsKey key(aImpl); + implWrapper = (DOMImplementation*)wrapperHashTable->Get(&key); if (!implWrapper) implWrapper = new DOMImplementation(aImpl, this); @@ -634,7 +672,8 @@ DocumentType* Document::createDocumentType(nsIDOMDocumentType* aDoctype) if (aDoctype) { - doctypeWrapper = (DocumentType*)wrapperHashTable.retrieve(aDoctype); + nsISupportsKey key(aDoctype); + doctypeWrapper = (DocumentType*)wrapperHashTable->Get(&key); if (!doctypeWrapper) doctypeWrapper = new DocumentType(aDoctype, this); @@ -657,7 +696,8 @@ NodeList* Document::createNodeList(nsIDOMNodeList* aList) if (aList) { - listWrapper = (NodeList*)wrapperHashTable.retrieve(aList); + nsISupportsKey key(aList); + listWrapper = (NodeList*)wrapperHashTable->Get(&key); if (!listWrapper) listWrapper = new NodeList(aList, this); @@ -680,7 +720,8 @@ NamedNodeMap* Document::createNamedNodeMap(nsIDOMNamedNodeMap* aMap) if (aMap) { - mapWrapper = (NamedNodeMap*)wrapperHashTable.retrieve(aMap); + nsISupportsKey key(aMap); + mapWrapper = (NamedNodeMap*)wrapperHashTable->Get(&key); if (!mapWrapper) mapWrapper = new NamedNodeMap(aMap, this); @@ -743,7 +784,7 @@ Node* Document::createWrapper(nsIDOMNode* aNode) break; case nsIDOMNode::DOCUMENT_NODE: - if (aNode == getKey()) + if (aNode == getNSObj()) return this; else { // XXX (pvdb) We need a createDocument here! @@ -774,9 +815,10 @@ Node* Document::createWrapper(nsIDOMNode* aNode) * @param aObj the MITREObject you want to add * @param aHashValue the key for the object in the hash table */ -void Document::addWrapper(MITREObject* aObj, void* aHashValue) +void Document::addWrapper(MozillaObjectWrapper* aObject) { - wrapperHashTable.add(aObj, aHashValue); + nsISupportsKey key(aObject->getNSObj()); + wrapperHashTable->Put(&key, aObject); } /** @@ -786,7 +828,21 @@ void Document::addWrapper(MITREObject* aObj, void* aHashValue) * * @return the wrapper as a MITREObject */ -MITREObject* Document::removeWrapper(void* aHashValue) +MITREObject* Document::removeWrapper(nsISupports* aMozillaObject) { - return wrapperHashTable.remove(aHashValue); + nsISupportsKey key(aMozillaObject); + return (MITREObject*)wrapperHashTable->Remove(&key); +} + +/** + * Remove a wrapper from the document's hash table and return it to the caller. + * + * @param aHashValue the key for the object you want to remove + * + * @return the wrapper as a MITREObject + */ +MITREObject* Document::removeWrapper(MozillaObjectWrapper* aObject) +{ + nsISupportsKey key(aObject->getNSObj()); + return (MITREObject*)wrapperHashTable->Remove(&key); } diff --git a/extensions/transformiix/source/xml/dom/mozImpl/MozillaElement.cpp b/extensions/transformiix/source/xml/dom/mozImpl/MozillaElement.cpp index 0ee4fa4ca9d0..391a7277defe 100644 --- a/extensions/transformiix/source/xml/dom/mozImpl/MozillaElement.cpp +++ b/extensions/transformiix/source/xml/dom/mozImpl/MozillaElement.cpp @@ -132,7 +132,7 @@ void Element::removeAttribute(const String& aName) // Second, remove the attribute wrapper object from the hash table if it is // there. It might not be if the attribute was created using // Element::setAttribute. If it was removed, then delete it. - attrWrapper = (Attr*)ownerDocument->removeWrapper(attr.get()); + attrWrapper = (Attr*)ownerDocument->removeWrapper(attr); if (attrWrapper) delete attrWrapper; @@ -195,7 +195,7 @@ Attr* Element::removeAttributeNode(Attr* aOldAttr) if (NS_SUCCEEDED(nsElement->RemoveAttributeNode(aOldAttr->getNSAttr(), getter_AddRefs(removedAttr)))) { - attrWrapper = (Attr*)ownerDocument->removeWrapper(removedAttr.get()); + attrWrapper = (Attr*)ownerDocument->removeWrapper(aOldAttr); if (!attrWrapper) attrWrapper = new Attr(removedAttr, ownerDocument); return attrWrapper; diff --git a/extensions/transformiix/source/xml/dom/mozImpl/MozillaNamedNodeMap.cpp b/extensions/transformiix/source/xml/dom/mozImpl/MozillaNamedNodeMap.cpp index 823eea6fdbd0..f40e9307af85 100644 --- a/extensions/transformiix/source/xml/dom/mozImpl/MozillaNamedNodeMap.cpp +++ b/extensions/transformiix/source/xml/dom/mozImpl/MozillaNamedNodeMap.cpp @@ -89,7 +89,7 @@ Node* NamedNodeMap::setNamedItem(Node* aNode) { nsCOMPtr node; - if (NS_SUCCEEDED(nsNamedNodeMap->SetNamedItem(aNode->getNSObj(), + if (NS_SUCCEEDED(nsNamedNodeMap->SetNamedItem(aNode->getNSNode(), getter_AddRefs(node)))) return ownerDocument->createWrapper(node); else diff --git a/extensions/transformiix/source/xml/dom/mozImpl/MozillaNode.cpp b/extensions/transformiix/source/xml/dom/mozImpl/MozillaNode.cpp index 445ba4026f9d..d052897ebd6e 100644 --- a/extensions/transformiix/source/xml/dom/mozImpl/MozillaNode.cpp +++ b/extensions/transformiix/source/xml/dom/mozImpl/MozillaNode.cpp @@ -28,6 +28,8 @@ #include "mozilladom.h" +MOZ_DECL_CTOR_COUNTER(Node) + /** * Construct a wrapper with the specified Mozilla object and document owner. * @@ -37,6 +39,7 @@ Node::Node(nsIDOMNode* aNode, Document* aOwner) : MozillaObjectWrapper(aNode, aOwner) { + MOZ_COUNT_CTOR(Node); nsNode = aNode; } @@ -45,6 +48,7 @@ Node::Node(nsIDOMNode* aNode, Document* aOwner) : */ Node::~Node() { + MOZ_COUNT_DTOR(Node); } /** @@ -57,7 +61,7 @@ void Node::setNSObj(nsIDOMNode* aNode) // First we must remove this wrapper from the document hash table since we // don't want to be associated with the existing nsIDOM* object anymore if (ownerDocument && nsNode) - ownerDocument->removeWrapper(getKey()); + ownerDocument->removeWrapper(nsNode); // Now assume control of the new node MozillaObjectWrapper::setNSObj(aNode); @@ -65,7 +69,7 @@ void Node::setNSObj(nsIDOMNode* aNode) // Finally, place our selves back in the hash table if (ownerDocument && aNode) - ownerDocument->addWrapper(this, getKey()); + ownerDocument->addWrapper(this); } /** @@ -84,7 +88,7 @@ void Node::setNSObj(nsIDOMNode* aNode, Document* aOwner) * * @return the Mozilla object wrapped with this wrapper */ -nsIDOMNode* Node::getNSObj() +nsIDOMNode* Node::getNSNode() { return nsNode; } @@ -291,8 +295,8 @@ Node* Node::insertBefore(Node* aNewChild, Node* aRefChild) if (nsNode == NULL) return NULL; - if (NS_SUCCEEDED(nsNode->InsertBefore(aNewChild->getNSObj(), - aRefChild->getNSObj(), getter_AddRefs(returnValue)))) + if (NS_SUCCEEDED(nsNode->InsertBefore(aNewChild->getNSNode(), + aRefChild->getNSNode(), getter_AddRefs(returnValue)))) return ownerDocument->createWrapper(returnValue); else return NULL; @@ -313,8 +317,8 @@ Node* Node::replaceChild(Node* aNewChild, Node* aOldChild) if (nsNode == NULL) return NULL; - if (NS_SUCCEEDED(nsNode->ReplaceChild(aNewChild->getNSObj(), - aOldChild->getNSObj(), getter_AddRefs(returnValue)))) + if (NS_SUCCEEDED(nsNode->ReplaceChild(aNewChild->getNSNode(), + aOldChild->getNSNode(), getter_AddRefs(returnValue)))) return (Node*)ownerDocument->removeWrapper(returnValue.get()); else return NULL; @@ -334,7 +338,7 @@ Node* Node::removeChild(Node* aOldChild) if (nsNode == NULL) return NULL; - if (NS_SUCCEEDED(nsNode->RemoveChild(aOldChild->getNSObj(), + if (NS_SUCCEEDED(nsNode->RemoveChild(aOldChild->getNSNode(), getter_AddRefs(returnValue)))) return (Node*)ownerDocument->removeWrapper(returnValue.get()); else @@ -355,7 +359,7 @@ Node* Node::appendChild(Node* aNewChild) if (nsNode == NULL) return NULL; - if (NS_SUCCEEDED(nsNode->AppendChild(aNewChild->getNSObj(), + if (NS_SUCCEEDED(nsNode->AppendChild(aNewChild->getNSNode(), getter_AddRefs(returnValue)))) return ownerDocument->createWrapper(returnValue); else diff --git a/extensions/transformiix/source/xml/dom/mozImpl/MozillaObjectWrapper.cpp b/extensions/transformiix/source/xml/dom/mozImpl/MozillaObjectWrapper.cpp index d4cf1eb3b58d..c6a736189972 100644 --- a/extensions/transformiix/source/xml/dom/mozImpl/MozillaObjectWrapper.cpp +++ b/extensions/transformiix/source/xml/dom/mozImpl/MozillaObjectWrapper.cpp @@ -29,6 +29,8 @@ #include "mozilladom.h" +MOZ_DECL_CTOR_COUNTER(MozillaObjectWrapper) + /** * Construct a wrapper with the specified Mozilla object and document owner. * @@ -38,10 +40,11 @@ MozillaObjectWrapper::MozillaObjectWrapper(nsISupports* aNsObject, Document* aOwner) { + MOZ_COUNT_CTOR(MozillaObjectWrapper); nsObject = aNsObject; ownerDocument = aOwner; if (ownerDocument && (ownerDocument != this)) - ownerDocument->addWrapper(this, nsObject.get()); + ownerDocument->addWrapper(this); } /** @@ -49,9 +52,10 @@ MozillaObjectWrapper::MozillaObjectWrapper(nsISupports* aNsObject, */ MozillaObjectWrapper::~MozillaObjectWrapper() { + MOZ_COUNT_DTOR(MozillaObjectWrapper); if (ownerDocument && (ownerDocument != this) && !ownerDocument->inHashTableDeletion()) - ownerDocument->removeWrapper(nsObject.get()); + ownerDocument->removeWrapper(getNSObj()); } /** @@ -74,15 +78,15 @@ void MozillaObjectWrapper::setNSObj(nsISupports* aNsObject, Document* aOwner) nsObject = aNsObject; ownerDocument = aOwner; if (ownerDocument && (ownerDocument != this)) - ownerDocument->addWrapper(this, nsObject.get()); + ownerDocument->addWrapper(this); } /** - * Get the hash key for the Mozilla object that this wrapper wraps. + * Get the Mozilla object wrapped with this wrapper. * - * @return the wrapper's hash key + * @return the Mozilla object wrapped with this wrapper */ -void* MozillaObjectWrapper::getKey() const +nsISupports* MozillaObjectWrapper::getNSObj() const { - return nsObject.get(); + return nsObject; }; diff --git a/extensions/transformiix/source/xml/dom/mozImpl/makefile.win b/extensions/transformiix/source/xml/dom/mozImpl/makefile.win index 6a1d9bbc7300..2f40bd324557 100644 --- a/extensions/transformiix/source/xml/dom/mozImpl/makefile.win +++ b/extensions/transformiix/source/xml/dom/mozImpl/makefile.win @@ -21,7 +21,9 @@ DEPTH=..\..\..\..\..\.. -DEFINES=-DMOZ_XSL +!ifdef MOZ_XSL +DEFINES=$(DEFINES) -DMOZ_XSL +!endif CPPSRCS= \ MozillaAttr.cpp \ diff --git a/extensions/transformiix/source/xml/dom/mozImpl/mozilladom.h b/extensions/transformiix/source/xml/dom/mozImpl/mozilladom.h index 9347fd9a56fd..0543e9db5f1b 100644 --- a/extensions/transformiix/source/xml/dom/mozImpl/mozilladom.h +++ b/extensions/transformiix/source/xml/dom/mozImpl/mozilladom.h @@ -46,10 +46,10 @@ #endif #include "TxString.h" -#include "HashTable.h" //A bunch of Mozilla DOM headers #include "nsCOMPtr.h" +#include "nsHashtable.h" #include "nsIDocument.h" @@ -104,7 +104,7 @@ class MozillaObjectWrapper : public MITREObject void setNSObj(nsISupports* aNsObject); void setNSObj(nsISupports* aNsObject, Document* aaOwner); - void* getKey() const; + nsISupports* getNSObj() const; protected: // We want to maintain a pointer back to the aOwner document for memory @@ -161,7 +161,7 @@ class Node : public MozillaObjectWrapper void setNSObj(nsIDOMNode* aNode); void setNSObj(nsIDOMNode* aNode, Document* aOwner); - nsIDOMNode* getNSObj(); + nsIDOMNode* getNSNode(); // Read functions virtual const String& getNodeName(); @@ -273,8 +273,9 @@ class Document : public Node // Determine what kind of node this is, and create the appropriate // wrapper for it. Node* createWrapper(nsIDOMNode* node); - void addWrapper(MITREObject* aObj, void* aHashValue); - MITREObject* removeWrapper(void* aHashValue); + void addWrapper(MozillaObjectWrapper* aObject); + MITREObject* removeWrapper(nsISupports* aMozillaObject); + MITREObject* removeWrapper(MozillaObjectWrapper* aObject); // Factory functions for various node types. These functions // are responsible for storing the wrapper classes they create in @@ -287,9 +288,6 @@ class Document : public Node Element* createElement(const String& aTagName); Element* createElement(nsIDOMElement* aElement); - - Element* createElementNS(const String& aNamespaceURI, - const String& aTagName); Attr* createAttribute(const String& aName); Attr* createAttribute(nsIDOMAttr* aAttr); @@ -327,12 +325,18 @@ class Document : public Node NamedNodeMap* createNamedNodeMap(nsIDOMNamedNodeMap* aMap); + // Introduced in DOM Level 2 + Element* createElementNS(const String& aNamespaceURI, + const String& aTagName); + + Element* getElementById(const String aID); + private: nsIDOMDocument* nsDocument; PRBool bInHashTableDeletion; - HashTable wrapperHashTable; + nsObjectHashtable *wrapperHashTable; }; /** diff --git a/extensions/transformiix/source/xml/dom/standalone/Document.cpp b/extensions/transformiix/source/xml/dom/standalone/Document.cpp index e72594ad5dae..2dbe869a25f4 100644 --- a/extensions/transformiix/source/xml/dom/standalone/Document.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/Document.cpp @@ -256,3 +256,15 @@ EntityReference* Document::createEntityReference(const String& name) { return new EntityReference(name, this); } + +// +//Return an Element by ID, introduced by DOM2 +// +Element* Document::getElementById(const String aID) +{ + /* This would need knowledge of the DTD, and we don't have it. + * If we knew that we deal with HTML4 or XHTML1 we could check + * for the "id" attribute, but we don't, so return NULL + */ + return NULL; +} diff --git a/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp b/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp index 822cd611f6fc..ea0c4e768970 100644 --- a/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp @@ -144,9 +144,9 @@ Document* NodeDefinition::getOwnerDocument() const return ownerDocument; } -Node* NodeDefinition::item(Int32 index) +Node* NodeDefinition::item(UInt32 index) { - Int32 selectLoop; + UInt32 selectLoop; NodeDefinition* pSelectNode = firstChild; if (index < length) @@ -160,7 +160,7 @@ Node* NodeDefinition::item(Int32 index) return NULL; } -Int32 NodeDefinition::getLength() +UInt32 NodeDefinition::getLength() { return length; } diff --git a/extensions/transformiix/source/xml/dom/standalone/NodeListDefinition.cpp b/extensions/transformiix/source/xml/dom/standalone/NodeListDefinition.cpp index 4bb1983ffd1c..6ccb5484492c 100644 --- a/extensions/transformiix/source/xml/dom/standalone/NodeListDefinition.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/NodeListDefinition.cpp @@ -92,9 +92,9 @@ void NodeListDefinition::append(Node& newNode) // // Return the Node contained in the item specified // -Node* NodeListDefinition::item(Int32 index) +Node* NodeListDefinition::item(UInt32 index) { - Int32 selectLoop; + UInt32 selectLoop; ListItem* pListItem = firstItem; if (index < length) @@ -111,7 +111,7 @@ Node* NodeListDefinition::item(Int32 index) // // Return the number of items in the list // -Int32 NodeListDefinition::getLength() +UInt32 NodeListDefinition::getLength() { return length; } diff --git a/extensions/transformiix/source/xml/dom/standalone/dom.h b/extensions/transformiix/source/xml/dom/standalone/dom.h index f1afd096a4b1..8797032fb630 100644 --- a/extensions/transformiix/source/xml/dom/standalone/dom.h +++ b/extensions/transformiix/source/xml/dom/standalone/dom.h @@ -136,10 +136,10 @@ class Node class NodeList { public: - virtual Node* item(Int32 index) = 0; - virtual Int32 getLength() = 0; + virtual Node* item(UInt32 index) = 0; + virtual UInt32 getLength() = 0; protected: - Int32 length; + UInt32 length; }; // @@ -160,8 +160,8 @@ class NodeListDefinition : public NodeList void append(Node* newNode); //Inherited from NodeList - Node* item(Int32 index); - Int32 getLength(); + Node* item(UInt32 index); + UInt32 getLength(); protected: struct ListItem { @@ -233,8 +233,8 @@ class NodeDefinition : public Node, public NodeList MBool hasChildNodes() const; //Inherrited from NodeList - Node* item(Int32 index); - Int32 getLength(); + Node* item(UInt32 index); + UInt32 getLength(); protected: //Name, value, and attributes for this node. Available to derrived @@ -309,6 +309,9 @@ class Document : public NodeDefinition Node* replaceChild(Node* newChild, Node* oldChild); Node* removeChild(Node* oldChild); + // Introduced in DOM Level 2 + Element* getElementById(const String aID); + private: Element* documentElement; DocumentType* doctype; diff --git a/extensions/transformiix/source/xml/dom/standalone/makefile.win b/extensions/transformiix/source/xml/dom/standalone/makefile.win index 5d58efe70208..1035806c7b93 100644 --- a/extensions/transformiix/source/xml/dom/standalone/makefile.win +++ b/extensions/transformiix/source/xml/dom/standalone/makefile.win @@ -17,10 +17,64 @@ # Copyright (C) 1998 Netscape Communications Corporation. All # Rights Reserved. # -# Contributor(s): +# Contributor(s): -DEPTH=..\..\..\..\.. +DEPTH=..\..\..\..\..\.. -DIRS=mozImpl +!ifdef MOZ_XSL +DEFINES=$(DEFINES) -DMOZ_XSL +!endif + +CPPSRCS=Attr.cpp \ + CDATASection.cpp \ + CharacterData.cpp \ + Comment.cpp \ + DOMImplementation.cpp \ + Document.cpp \ + DocumentFragment.cpp \ + DocumentType.cpp \ + Element.cpp \ + Entity.cpp \ + EntityReference.cpp \ + NamedNodeMap.cpp \ + NodeDefinition.cpp \ + NodeListDefinition.cpp \ + Notation.cpp \ + ProcessingInstruction.cpp \ + Text.cpp \ + $(NULL) + +CPP_OBJS= \ + .\$(OBJDIR)\Attr.obj \ + .\$(OBJDIR)\CDATASection.obj \ + .\$(OBJDIR)\CharacterData.obj \ + .\$(OBJDIR)\Comment.obj \ + .\$(OBJDIR)\DOMImplementation.obj \ + .\$(OBJDIR)\Document.obj \ + .\$(OBJDIR)\DocumentFragment.obj \ + .\$(OBJDIR)\DocumentType.obj \ + .\$(OBJDIR)\Element.obj \ + .\$(OBJDIR)\Entity.obj \ + .\$(OBJDIR)\EntityReference.obj \ + .\$(OBJDIR)\NamedNodeMap.obj \ + .\$(OBJDIR)\NodeDefinition.obj \ + .\$(OBJDIR)\NodeListDefinition.obj \ + .\$(OBJDIR)\Notation.obj \ + .\$(OBJDIR)\ProcessingInstruction.obj \ + .\$(OBJDIR)\Text.obj \ + $(NULL) + +EXPORTS = \ + $(NULL) + +LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I..\..\..\base -I..\..\dom \ + -I..\.. + +LCFLAGS = \ + $(LCFLAGS) \ + $(DEFINES) \ + $(NULL) include <$(DEPTH)\config\rules.mak> + +install:: $(OBJDIR) $(CPP_OBJS) diff --git a/extensions/transformiix/source/xml/makefile.win b/extensions/transformiix/source/xml/makefile.win index b82878424822..d9793cd61fa8 100644 --- a/extensions/transformiix/source/xml/makefile.win +++ b/extensions/transformiix/source/xml/makefile.win @@ -25,6 +25,8 @@ DIRS=dom parser util !if defined(MOZ_XSL) DEFINES=$(DEFINES) -DMOZ_XSL +!else +DIRS = $(DIRS) printer !endif CPPSRCS= \ diff --git a/extensions/transformiix/source/xml/parser/XMLParser.cpp b/extensions/transformiix/source/xml/parser/XMLParser.cpp index c49c52987155..4bdeb10254f8 100644 --- a/extensions/transformiix/source/xml/parser/XMLParser.cpp +++ b/extensions/transformiix/source/xml/parser/XMLParser.cpp @@ -34,11 +34,14 @@ * -- Removed a number of castings of XML_Char to DOM_CHAR since they * were not working on Windows properly * - * $Id: XMLParser.cpp,v 1.10 2000/08/26 04:50:58 Peter.VanderBeken%pandora.be Exp $ + * $Id: XMLParser.cpp,v 1.11 2001/01/12 20:06:26 axel%pike.org Exp $ */ #include "XMLParser.h" - +#ifdef MOZ_XSL +#include "nsSyncLoader.h" +#include "URIUtils.h" +#endif /** * Implementation of an In-Memory DOM based XML parser. The actual XML * parsing is provided by EXPAT. @@ -78,7 +81,27 @@ Document* XMLParser::getDocumentFromURI { #ifdef MOZ_XSL - return NULL; + nsresult rv = NS_OK; + String documentURL; + URIUtils::resolveHref(href, documentBase, documentURL); + nsCOMPtr documentURI; + NS_WITH_SERVICE(nsIIOService, pService, kIOServiceCID, &rv); + if (NS_FAILED(rv)) return NULL; + + char *hrefStr = (documentURL.getConstNSString()).ToNewCString(); + rv = pService->NewURI(hrefStr, nsnull, getter_AddRefs(documentURI)); + nsCRT::free(hrefStr); + if (NS_FAILED(rv)) return NULL; + + nsCOMPtraLoader = do_CreateInstance( TRANSFORMIIX_SYNCLOADER_CONTRACTID, &rv ); + if (NS_FAILED(rv)) return NULL; + + nsCOMPtr theDocument; + aLoader->LoadDocument(documentURI, getter_AddRefs(theDocument)); + nsCOMPtr theDOMDocument = do_QueryInterface(theDocument, & rv); + if (NS_FAILED(rv)) return NULL; + + return new Document(theDOMDocument); #else istream* xslInput = URIUtils::getInputStream(href, documentBase, errMsg); @@ -158,7 +181,6 @@ void startElement(void *userData, const XML_Char *name, const XML_Char **atts) { ParserState* ps = (ParserState*)userData; Element* newElement; - Attr* newAttribute; XML_Char* attName; XML_Char* attValue; XML_Char** theAtts = (XML_Char**)atts; diff --git a/extensions/transformiix/source/xml/parser/makefile.win b/extensions/transformiix/source/xml/parser/makefile.win index d30593f2318a..3d5aea4052e0 100644 --- a/extensions/transformiix/source/xml/parser/makefile.win +++ b/extensions/transformiix/source/xml/parser/makefile.win @@ -21,22 +21,37 @@ DEPTH=..\..\..\..\.. -!if defined(MOZ_XSL) +!ifdef MOZ_XSL DEFINES=$(DEFINES) -DMOZ_XSL -!endif -CPPSRCS= \ - XMLParser.cpp \ +CPPSRCS= \ + nsSyncLoader.cpp \ + XMLParser.cpp \ $(NULL) -CPP_OBJS= \ +CPP_OBJS= \ + .\$(OBJDIR)\nsSyncLoader.obj \ .\$(OBJDIR)\XMLParser.obj \ $(NULL) +!else +CPPSRCS= \ + XMLParser.cpp \ + $(NULL) + +CPP_OBJS= \ + .\$(OBJDIR)\XMLParser.obj \ + $(NULL) +!endif EXPORTS = \ $(NULL) -LINCS=-I..\..\base -I..\dom -I$(PUBLIC)\expat +LINCS=-I..\..\base -I..\dom -I..\..\net +!ifdef MOZ_XSL +LINCS=$(LINCS) -I$(PUBLIC)\expat +!else +LINCS=$(LINCS) -Ixmlparse +!endif LCFLAGS = \ -DXML_UNICODE \ diff --git a/extensions/transformiix/source/xml/parser/nsSyncLoader.cpp b/extensions/transformiix/source/xml/parser/nsSyncLoader.cpp new file mode 100644 index 000000000000..ee80d0c27526 --- /dev/null +++ b/extensions/transformiix/source/xml/parser/nsSyncLoader.cpp @@ -0,0 +1,369 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Peter Van der Beken, peterv@netscape.com + * -- original author. + * + */ + +#include "nsSyncLoader.h" +#include "nsNetUtil.h" +#include "nsLayoutCID.h" +#include "nsIEventQueueService.h" +#include "nsIDOMDocument.h" +#include "nsIDOMDOMImplementation.h" +#include "nsIDOMEventReceiver.h" +#include "nsIXPConnect.h" +#include "nsIDocShell.h" +#include "nsIDocShellTreeItem.h" +#include "nsIScriptContext.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDOMWindowInternal.h" +#include "nsAppShellCIDs.h" +#include "nsIAppShellService.h" + +static const char* kLoadAsData = "loadAsData"; + +static NS_DEFINE_CID(kIDOMDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID); +static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); +static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); + +/* + * This class exists to prevent a circular reference between + * the loaded document and the nsSyncloader instance. The + * request owns the document. While the document is loading, + * the request is a load listener, held onto by the document. + * The proxy class breaks the circularity by filling in as the + * load listener and holding a weak reference to the request + * object. + */ + +class nsLoadListenerProxy : public nsIDOMLoadListener { +public: + nsLoadListenerProxy(nsWeakPtr aParent); + virtual ~nsLoadListenerProxy(); + + NS_DECL_ISUPPORTS + + // nsIDOMEventListener + virtual nsresult HandleEvent(nsIDOMEvent* aEvent); + + // nsIDOMLoadListener + virtual nsresult Load(nsIDOMEvent* aEvent); + virtual nsresult Unload(nsIDOMEvent* aEvent); + virtual nsresult Abort(nsIDOMEvent* aEvent); + virtual nsresult Error(nsIDOMEvent* aEvent); + +protected: + nsWeakPtr mParent; +}; + +nsLoadListenerProxy::nsLoadListenerProxy(nsWeakPtr aParent) +{ + NS_INIT_ISUPPORTS(); + mParent = aParent; +} + +nsLoadListenerProxy::~nsLoadListenerProxy() +{ +} + +NS_IMPL_ISUPPORTS1(nsLoadListenerProxy, nsIDOMLoadListener) + +nsresult +nsLoadListenerProxy::HandleEvent(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->HandleEvent(aEvent); + } + + return NS_OK; +} + +nsresult +nsLoadListenerProxy::Load(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->Load(aEvent); + } + + return NS_OK; +} + +nsresult +nsLoadListenerProxy::Unload(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->Unload(aEvent); + } + + return NS_OK; +} + +nsresult +nsLoadListenerProxy::Abort(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->Abort(aEvent); + } + + return NS_OK; +} + +nsresult +nsLoadListenerProxy::Error(nsIDOMEvent* aEvent) +{ + nsCOMPtr listener = do_QueryReferent(mParent); + + if (listener) { + return listener->Error(aEvent); + } + + return NS_OK; +} + +nsSyncLoader::nsSyncLoader() +{ + NS_INIT_ISUPPORTS(); +} + +nsSyncLoader::~nsSyncLoader() +{ + //if (XML_HTTP_REQUEST_SENT == mStatus) { + // Abort(); + //} + if (mDocShellTreeOwner) { + mDocShellTreeOwner->ExitModalLoop(NS_OK); + } +} + +NS_IMPL_ISUPPORTS3(nsSyncLoader, nsISyncLoader, nsIDOMLoadListener, nsISupportsWeakReference) + +NS_IMETHODIMP +nsSyncLoader::LoadDocument(nsIURI* documentURI, nsIDocument **_retval) +{ + nsresult rv = NS_OK; + + nsCOMPtr loadGroup; + + // If we have a base document, use it for the base URL and loadgroup + //if (mBaseDocument) { + // rv = mBaseDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup)); + // if (NS_FAILED(rv)) return rv; + //} + + //rv = NS_NewURI(getter_AddRefs(uri), url, mBaseURI); + //if (NS_FAILED(rv)) return rv; + + nsCOMPtr channel; + rv = NS_OpenURI(getter_AddRefs(channel), documentURI, nsnull, loadGroup); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr postDataStream; + + // Make sure we've been opened + if (!channel) { + return NS_ERROR_NOT_INITIALIZED; + } + + // Get and initialize a DOMImplementation + nsCOMPtr implementation = do_CreateInstance(kIDOMDOMImplementationCID, &rv); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + //if (mBaseURI) { + // nsCOMPtr privImpl = do_QueryInterface(implementation); + // if (privImpl) { + // privImpl->Init(mBaseURI); + // } + //} + + // Create an empty document from it + nsAutoString emptyStr; + nsCOMPtr DOMDocument; + rv = implementation->CreateDocument(emptyStr, + emptyStr, + nsnull, + getter_AddRefs(DOMDocument)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + // Register as a load listener on the document + nsCOMPtr target = do_QueryInterface(DOMDocument); + if (target) { + nsWeakPtr requestWeak = getter_AddRefs(NS_GetWeakReference(NS_STATIC_CAST(nsIDOMLoadListener*, this))); + nsLoadListenerProxy* proxy = new nsLoadListenerProxy(requestWeak); + if (!proxy) return NS_ERROR_OUT_OF_MEMORY; + + // This will addref the proxy + rv = target->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMEventListener*, + proxy), + NS_GET_IID(nsIDOMLoadListener)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + } + + // Tell the document to start loading + nsCOMPtr listener; + nsCOMPtr document = do_QueryInterface(DOMDocument); + if (!document) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr modalEventQueue; + nsCOMPtr eventQService; + + nsCOMPtr cc; + NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv); + if(NS_SUCCEEDED(rv)) { + rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc)); + } + + JSContext* cx; + if (NS_SUCCEEDED(rv) && cc) { + rv = cc->GetJSContext(&cx); + if (NS_FAILED(rv)) NS_ERROR_FAILURE; + } + else { + NS_WITH_SERVICE(nsIAppShellService, appshellSvc, kAppShellServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + nsCOMPtr junk; + rv = appshellSvc->GetHiddenWindowAndJSContext(getter_AddRefs(junk), &cx); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + } + if (NS_SUCCEEDED(rv)) { + nsIScriptContext* scriptCX; + + // We can only do this if we're called from a DOM script context + scriptCX = (nsIScriptContext*)JS_GetContextPrivate(cx); + if (!scriptCX) return NS_OK; + + // Get the nsIDocShellTreeOwner associated with the window + // containing this script context + // XXX Need to find a better way to do this rather than + // chaining through a bunch of getters and QIs + nsCOMPtr global; + global = dont_AddRef(scriptCX->GetGlobalObject()); + if (!global) return NS_ERROR_FAILURE; + + nsCOMPtr docshell; + rv = global->GetDocShell(getter_AddRefs(docshell)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + nsCOMPtr item = do_QueryInterface(docshell); + if (!item) return NS_ERROR_FAILURE; + + rv = item->GetTreeOwner(getter_AddRefs(mDocShellTreeOwner)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + eventQService = do_GetService(kEventQueueServiceCID); + if(!eventQService || + NS_FAILED(eventQService->PushThreadEventQueue(getter_AddRefs(modalEventQueue)))) { + return NS_ERROR_FAILURE; + } + } + + rv = document->StartDocumentLoad(kLoadAsData, channel, + nsnull, nsnull, + getter_AddRefs(listener), + PR_FALSE); + + if (NS_FAILED(rv)) { + if (modalEventQueue) { + eventQService->PopThreadEventQueue(modalEventQueue); + } + return NS_ERROR_FAILURE; + } + + // Start reading from the channel + rv = channel->AsyncRead(listener, nsnull); + + if (NS_FAILED(rv)) { + if (modalEventQueue) { + eventQService->PopThreadEventQueue(modalEventQueue); + } + return NS_ERROR_FAILURE; + } + + // Spin an event loop here and wait + if (mDocShellTreeOwner) { + rv = mDocShellTreeOwner->ShowModal(); + + eventQService->PopThreadEventQueue(modalEventQueue); + + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + } + + *_retval = document; + NS_ADDREF(*_retval); + return rv; +} + +// nsIDOMEventListener +nsresult +nsSyncLoader::HandleEvent(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +// nsIDOMLoadListener +nsresult +nsSyncLoader::Load(nsIDOMEvent* aEvent) +{ + if (mDocShellTreeOwner) { + mDocShellTreeOwner->ExitModalLoop(NS_OK); + mDocShellTreeOwner = 0; + } + + return NS_OK; +} + +nsresult +nsSyncLoader::Unload(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +nsresult +nsSyncLoader::Abort(nsIDOMEvent* aEvent) +{ + if (mDocShellTreeOwner) { + mDocShellTreeOwner->ExitModalLoop(NS_OK); + mDocShellTreeOwner = 0; + } + + return NS_OK; +} + +nsresult +nsSyncLoader::Error(nsIDOMEvent* aEvent) +{ + if (mDocShellTreeOwner) { + mDocShellTreeOwner->ExitModalLoop(NS_OK); + mDocShellTreeOwner = 0; + } + + return NS_OK; +} diff --git a/extensions/transformiix/source/xml/parser/nsSyncLoader.h b/extensions/transformiix/source/xml/parser/nsSyncLoader.h new file mode 100644 index 000000000000..6fbb08e893eb --- /dev/null +++ b/extensions/transformiix/source/xml/parser/nsSyncLoader.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Peter Van der Beken, peterv@netscape.com + * -- original author. + * + */ + +#ifndef nsSyncLoader_h__ +#define nsSyncLoader_h__ + +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsIDOMLoadListener.h" +#include "nsIDocument.h" +#include "nsIDocShellTreeOwner.h" +#include "nsWeakReference.h" +#include "nsISyncLoader.h" + +class nsSyncLoader : public nsISyncLoader, + public nsIDOMLoadListener, + public nsSupportsWeakReference +{ +public: + nsSyncLoader(); + virtual ~nsSyncLoader(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSISYNCLOADER + + // nsIDOMEventListener + virtual nsresult HandleEvent(nsIDOMEvent* aEvent); + + // nsIDOMLoadListener + virtual nsresult Load(nsIDOMEvent* aEvent); + virtual nsresult Unload(nsIDOMEvent* aEvent); + virtual nsresult Abort(nsIDOMEvent* aEvent); + virtual nsresult Error(nsIDOMEvent* aEvent); + +protected: + nsCOMPtr mDocShellTreeOwner; +}; + +#endif diff --git a/extensions/transformiix/source/xml/util/DOMHelper.cpp b/extensions/transformiix/source/xml/util/DOMHelper.cpp index a3e512c6c716..750d3f1f6439 100644 --- a/extensions/transformiix/source/xml/util/DOMHelper.cpp +++ b/extensions/transformiix/source/xml/util/DOMHelper.cpp @@ -19,13 +19,13 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: DOMHelper.cpp,v 1.5 2000/08/27 05:58:59 kvisco%ziplink.net Exp $ + * $Id: DOMHelper.cpp,v 1.6 2001/01/12 20:06:29 axel%pike.org Exp $ */ /** * A class used to overcome DOM 1.0 deficiencies * @author Keith Visco - * @version $Revision: 1.5 $ $Date: 2000/08/27 05:58:59 $ + * @version $Revision: 1.6 $ $Date: 2001/01/12 20:06:29 $ **/ #include "DOMHelper.h" @@ -116,7 +116,7 @@ Node* DOMHelper::getParentNode(Node* node) { return node->getParentNode(); #ifdef MOZ_XSL - void* key = node->getKey(); + void* key = node->getNSObj(); #else Int32 key = (Int32)node; #endif @@ -144,7 +144,7 @@ Node* DOMHelper::getParentNode(Node* node) { void DOMHelper::addParentReference(Node* child, Node* parent) { #ifdef MOZ_XSL - void* key = child->getKey(); + void* key = child->getNSObj(); #else Int32 key = (Int32)child; #endif @@ -207,7 +207,7 @@ void DOMHelper::continueIndexing(Node* node) { Element* element = (Element*)idxState->next; NamedNodeMap* atts = element->getAttributes(); if (atts) { - for (int i = 0; i < atts->getLength(); i++) { + for (UInt32 i = 0; i < atts->getLength(); i++) { Node* tmpNode = atts->item(i); addParentReference(tmpNode, element); if (node == tmpNode) found = MB_TRUE; @@ -274,7 +274,7 @@ OrderInfo* DOMHelper::getDocumentOrder(Node* node) { if (!node) return 0; #ifdef MOZ_XSL - void* key = node->getKey(); + void* key = node->getNSObj(); #else Int32 key = (Int32)node; #endif diff --git a/extensions/transformiix/source/xpath/AttributeExpr.cpp b/extensions/transformiix/source/xpath/AttributeExpr.cpp index ca5a8e5bead5..1819a291821c 100644 --- a/extensions/transformiix/source/xpath/AttributeExpr.cpp +++ b/extensions/transformiix/source/xpath/AttributeExpr.cpp @@ -21,7 +21,7 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: AttributeExpr.cpp,v 1.1 2000/04/06 07:44:41 kvisco%ziplink.net Exp $ + * $Id: AttributeExpr.cpp,v 1.2 2001/01/12 20:06:30 axel%pike.org Exp $ */ #include "Expr.h" @@ -30,7 +30,7 @@ * This class represents a ElementExpr as defined by the XSL * Working Draft * @author Keith Visco - * @version $Revision: 1.1 $ $Date: 2000/04/06 07:44:41 $ + * @version $Revision: 1.2 $ $Date: 2001/01/12 20:06:30 $ **/ //- Constructors -/ @@ -68,7 +68,7 @@ ExprResult* AttributeExpr::evaluate(Node* context, ContextState* cs) { if ( !context ) return nodeSet; NamedNodeMap* atts = context->getAttributes(); if ( atts ) { - for (int i = 0; i < atts->getLength(); i++ ) { + for (UInt32 i = 0; i < atts->getLength(); i++ ) { Attr* attr = (Attr*)atts->item(i); if ( isWild ) nodeSet->add(attr); else { diff --git a/extensions/transformiix/source/xpath/BasicNodeExpr.cpp b/extensions/transformiix/source/xpath/BasicNodeExpr.cpp index f6e8a02a9319..432ae412117a 100644 --- a/extensions/transformiix/source/xpath/BasicNodeExpr.cpp +++ b/extensions/transformiix/source/xpath/BasicNodeExpr.cpp @@ -21,14 +21,14 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: BasicNodeExpr.cpp,v 1.1 2000/04/06 07:44:45 kvisco%ziplink.net Exp $ + * $Id: BasicNodeExpr.cpp,v 1.2 2001/01/12 20:06:31 axel%pike.org Exp $ */ #include "Expr.h" /** * @author Keith Visco - * @version $Revision: 1.1 $ $Date: 2000/04/06 07:44:45 $ + * @version $Revision: 1.2 $ $Date: 2001/01/12 20:06:31 $ **/ //- Constructors -/ @@ -67,7 +67,7 @@ ExprResult* BasicNodeExpr::evaluate(Node* context, ContextState* cs) { NodeSet* nodeSet = new NodeSet(); if ( !context ) return nodeSet; NodeList* nl = context->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++ ) { + for (UInt32 i = 0; i < nl->getLength(); i++ ) { Node* node = nl->item(i); if (matches(node, context, cs)) nodeSet->add(node); } diff --git a/extensions/transformiix/source/xpath/ElementExpr.cpp b/extensions/transformiix/source/xpath/ElementExpr.cpp index 07af30c14493..12b1987b8be8 100644 --- a/extensions/transformiix/source/xpath/ElementExpr.cpp +++ b/extensions/transformiix/source/xpath/ElementExpr.cpp @@ -21,7 +21,7 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: ElementExpr.cpp,v 1.2 2000/11/07 10:49:07 kvisco%ziplink.net Exp $ + * $Id: ElementExpr.cpp,v 1.3 2001/01/12 20:06:31 axel%pike.org Exp $ */ #include "Expr.h" @@ -83,7 +83,7 @@ ExprResult* ElementExpr::evaluate(Node* context, ContextState* cs) { NodeList* nl = context->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++ ) { + for (UInt32 i = 0; i < nl->getLength(); i++ ) { Node* node = nl->item(i); if (matches(node, context, cs)) nodeSet->add(node); } diff --git a/extensions/transformiix/source/xpath/ExprLexer.cpp b/extensions/transformiix/source/xpath/ExprLexer.cpp index 6a202b685397..21cc8589aa92 100644 --- a/extensions/transformiix/source/xpath/ExprLexer.cpp +++ b/extensions/transformiix/source/xpath/ExprLexer.cpp @@ -29,16 +29,15 @@ * -- Fixed bug in parse method so that we make sure we check for * axis identifier wild cards, such as ancestor::* * - * $Id: ExprLexer.cpp,v 1.9 2001/01/09 20:56:28 axel%pike.org Exp $ + * $Id: ExprLexer.cpp,v 1.10 2001/01/12 20:06:31 axel%pike.org Exp $ */ /** * Lexical analyzer for XPath expressions * @author Keith Visco - * @version $Revision: 1.9 $ $Date: 2001/01/09 20:56:28 $ + * @version $Revision: 1.10 $ $Date: 2001/01/12 20:06:31 $ **/ -#include #include "ExprLexer.h" //---------------------------/ diff --git a/extensions/transformiix/source/xpath/ExprLexer.h b/extensions/transformiix/source/xpath/ExprLexer.h index 1ec22374f379..4d2b121a3671 100644 --- a/extensions/transformiix/source/xpath/ExprLexer.h +++ b/extensions/transformiix/source/xpath/ExprLexer.h @@ -25,7 +25,7 @@ * -- changed constant short declarations in Token and ExprLexer to * enumerations, commented with //--LF * - * $Id: ExprLexer.h,v 1.3 2000/04/13 18:30:00 nisheeth%netscape.com Exp $ + * $Id: ExprLexer.h,v 1.4 2001/01/12 20:06:32 axel%pike.org Exp $ */ @@ -34,7 +34,9 @@ #include "TxString.h" #include "baseutils.h" +#ifndef MOZ_XSL #include +#endif /** * A Token class for the ExprLexer. @@ -42,7 +44,7 @@ * This class was ported from XSL:P, an open source Java based * XSLT processor, written by yours truly. * @author Keith Visco - * @version $Revision: 1.3 $ $Date: 2000/04/13 18:30:00 $ + * @version $Revision: 1.4 $ $Date: 2001/01/12 20:06:32 $ **/ class Token { diff --git a/extensions/transformiix/source/xpath/ExprParser.cpp b/extensions/transformiix/source/xpath/ExprParser.cpp index cf76c1c84873..88c32db62ebb 100644 --- a/extensions/transformiix/source/xpath/ExprParser.cpp +++ b/extensions/transformiix/source/xpath/ExprParser.cpp @@ -30,7 +30,7 @@ * -- fixed bug in ::parsePredicates, * made sure we continue looking for more predicates. * - * $Id: ExprParser.cpp,v 1.6 2000/06/11 11:43:02 Peter.VanderBeken%pandora.be Exp $ + * $Id: ExprParser.cpp,v 1.7 2001/01/12 20:06:32 axel%pike.org Exp $ */ /** @@ -38,7 +38,7 @@ * This class is used to parse XSL Expressions * @author Keith Visco * @see ExprLexer - * @version $Revision: 1.6 $ $Date: 2000/06/11 11:43:02 $ + * @version $Revision: 1.7 $ $Date: 2001/01/12 20:06:32 $ **/ #include "ExprParser.h" @@ -69,8 +69,8 @@ AttributeValueTemplate* ExprParser::createAttributeValueTemplate String buffer; MBool inExpr = MB_FALSE; MBool inLiteral = MB_FALSE; - char endLiteral = '"'; - char prevCh = '\0'; + UNICODE_CHAR endLiteral = '"'; + UNICODE_CHAR prevCh = '\0'; while ( cc < size) { UNICODE_CHAR ch = attValue.charAt(cc++); @@ -227,6 +227,7 @@ Expr* ExprParser::createExpr(ExprLexer& lexer) { Token* tok = lexer.nextToken(); switch ( tok->type ) { + case Token::L_BRACKET: // Predicate starts here case Token::R_BRACKET: case Token::R_PAREN: case Token::COMMA : @@ -415,6 +416,9 @@ FunctionCall* ExprParser::createFunctionCall(ExprLexer& lexer) { else if ( XPathNames::FALSE_FN.isEqual(tok->value) ) { fnCall = new BooleanFunctionCall(); } + else if ( XPathNames::ID_FN.isEqual(tok->value) ) { + fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::ID); + } else if ( XPathNames::LANG_FN.isEqual(tok->value) ) { fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_LANG); } @@ -430,6 +434,9 @@ FunctionCall* ExprParser::createFunctionCall(ExprLexer& lexer) { else if ( XPathNames::NAMESPACE_URI_FN.isEqual(tok->value) ) { fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::NAMESPACE_URI); } + else if ( XPathNames::NORMALIZE_SPACE_FN.isEqual(tok->value) ) { + fnCall = new StringFunctionCall(StringFunctionCall::NORMALIZE_SPACE); + } else if ( XPathNames::NOT_FN.isEqual(tok->value) ) { fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_NOT); } @@ -454,6 +461,9 @@ FunctionCall* ExprParser::createFunctionCall(ExprLexer& lexer) { else if ( XPathNames::SUBSTRING_BEFORE_FN.isEqual(tok->value) ) { fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING_BEFORE); } + else if ( XPathNames::SUM_FN.isEqual(tok->value) ) { + fnCall = new NumberFunctionCall(NumberFunctionCall::SUM); + } else if ( XPathNames::TRANSLATE_FN.isEqual(tok->value) ) { fnCall = new StringFunctionCall(StringFunctionCall::TRANSLATE); } diff --git a/extensions/transformiix/source/xpath/ExprParser.h b/extensions/transformiix/source/xpath/ExprParser.h index 8a3357a6daea..b6fba806cf95 100644 --- a/extensions/transformiix/source/xpath/ExprParser.h +++ b/extensions/transformiix/source/xpath/ExprParser.h @@ -21,14 +21,14 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: ExprParser.h,v 1.2 2000/04/12 22:32:58 nisheeth%netscape.com Exp $ + * $Id: ExprParser.h,v 1.3 2001/01/12 20:06:33 axel%pike.org Exp $ */ /** * ExprParser * This class is used to parse XSL Expressions * @author Keith Visco - * @version $Revision: 1.2 $ $Date: 2000/04/12 22:32:58 $ + * @version $Revision: 1.3 $ $Date: 2001/01/12 20:06:33 $ * @see ExprLexer **/ @@ -41,7 +41,9 @@ #include "FunctionLib.h" #include "List.h" #include "Stack.h" +#ifndef MOZ_XSL #include +#endif class ExprParser { diff --git a/extensions/transformiix/source/xpath/ExprResult.h b/extensions/transformiix/source/xpath/ExprResult.h index 4c7c8fc32ef0..ce7c3e755022 100644 --- a/extensions/transformiix/source/xpath/ExprResult.h +++ b/extensions/transformiix/source/xpath/ExprResult.h @@ -23,7 +23,7 @@ * Larry Fitzpatrick, OpenText, lef@opentext.com * -- changed constant short result types to enum * - * $Id: ExprResult.h,v 1.6 2000/06/11 11:43:07 Peter.VanderBeken%pandora.be Exp $ + * $Id: ExprResult.h,v 1.7 2001/01/12 20:06:33 axel%pike.org Exp $ */ #include "MITREObject.h" @@ -42,7 +42,7 @@ *
* Note: for NodeSet, see NodeSet.h
* @author Keith Visco - * @version $Revision: 1.6 $ $Date: 2000/06/11 11:43:07 $ + * @version $Revision: 1.7 $ $Date: 2001/01/12 20:06:33 $ */ class ExprResult : public MITREObject { @@ -65,6 +65,7 @@ public: * @return the type of ExprResult represented **/ virtual short getResultType() = 0; + /** * Creates a String representation of this ExprResult * @param str the destination string to append the String representation to. diff --git a/extensions/transformiix/source/xpath/FunctionLib.h b/extensions/transformiix/source/xpath/FunctionLib.h index 3ece81382111..8641292fd755 100644 --- a/extensions/transformiix/source/xpath/FunctionLib.h +++ b/extensions/transformiix/source/xpath/FunctionLib.h @@ -27,7 +27,7 @@ * Marina Mechtcheriakova * -- added support for lang function * - * $Id: FunctionLib.h,v 1.8 2000/08/26 04:45:32 Peter.VanderBeken%pandora.be Exp $ + * $Id: FunctionLib.h,v 1.9 2001/01/12 20:06:33 axel%pike.org Exp $ */ #include "TxString.h" @@ -57,11 +57,13 @@ 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; @@ -70,6 +72,7 @@ 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+ @@ -261,6 +264,7 @@ public: enum nodeSetFunctions { COUNT = 1, //-- count() + ID, //-- id() LAST, //-- last() LOCAL_NAME, //-- local-name() NAMESPACE_URI, //-- namespace-uri() @@ -302,7 +306,7 @@ public: enum stringFunctions { CONCAT = 1, //-- concat() CONTAINS, //-- contains() - NORMALIZE, //-- normalize() + NORMALIZE_SPACE, //-- normalize-space() STARTS_WITH, //-- starts-with() STRING, //-- string() STRING_LENGTH, //-- string-length() @@ -348,7 +352,8 @@ public: NUMBER = 1, //-- number() ROUND, //-- round() FLOOR, //-- floor() - CEILING //-- ceiling() + CEILING, //-- ceiling() + SUM //-- sum() }; /** diff --git a/extensions/transformiix/source/xpath/LocationStep.cpp b/extensions/transformiix/source/xpath/LocationStep.cpp index cd09e58b6e85..12f489805126 100644 --- a/extensions/transformiix/source/xpath/LocationStep.cpp +++ b/extensions/transformiix/source/xpath/LocationStep.cpp @@ -21,12 +21,12 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: LocationStep.cpp,v 1.2 2000/05/24 04:29:00 kvisco%ziplink.net Exp $ + * $Id: LocationStep.cpp,v 1.3 2001/01/12 20:06:34 axel%pike.org Exp $ */ /* Implementation of an XPath LocationStep - @version $Revision: 1.2 $ $Date: 2000/05/24 04:29:00 $ + @version $Revision: 1.3 $ $Date: 2001/01/12 20:06:34 $ */ #include "Expr.h" @@ -123,7 +123,7 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) { { NamedNodeMap* atts = context->getAttributes(); if ( atts ) { - for ( int i = 0; i < atts->getLength(); i++ ) { + for ( UInt32 i = 0; i < atts->getLength(); i++ ) { Attr* attr = (Attr*)atts->item(i); if ( nodeExpr->matches(attr, context, cs) ) nodes->add(attr); } @@ -202,7 +202,7 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) { default: //-- Children Axis { NodeList* nl = context->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++ ) { + for ( UInt32 i = 0; i < nl->getLength(); i++ ) { if ( nodeExpr->matches(nl->item(i), context, cs) ) nodes->add(nl->item(i)); } @@ -240,7 +240,7 @@ void LocationStep::fromDescendants(Node* context, ContextState* cs, NodeSet* nod if (( !context ) || (! nodeExpr )) return; NodeList* nl = context->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++) { + for (UInt32 i = 0; i < nl->getLength(); i++) { Node* child = nl->item(i); if (nodeExpr->matches(child, context, cs)) nodes->add(child); diff --git a/extensions/transformiix/source/xpath/Makefile.in b/extensions/transformiix/source/xpath/Makefile.in index 3037ab7d601e..253ccac02c56 100644 --- a/extensions/transformiix/source/xpath/Makefile.in +++ b/extensions/transformiix/source/xpath/Makefile.in @@ -61,11 +61,18 @@ CPPSRCS = AdditiveExpr.cpp \ VariableRefExpr.cpp \ WildCardExpr.cpp \ XPathNames.cpp -## Parser.cpp \ +ifdef MOZ_XSL +CPPSRCS += XPathProcessor.cpp +endif include $(topsrcdir)/config/rules.mk INCLUDES += -I$(srcdir)/../base -I$(srcdir)/../xml \ - -I$(srcdir)/../xml/dom -I$(srcdir)/../xslt + -I$(srcdir)/../xml/dom -I$(srcdir)/../xml/util \ + -I$(srcdir)/../xslt -I$(srcdir)/../xslt/util \ + -I$(srcdir)/../xslt/functions +ifdef MOZ_XSL +INCLUDES += -I$(srcdir) +endif install:: $(OBJS) \ No newline at end of file diff --git a/extensions/transformiix/source/xpath/NodeSet.cpp b/extensions/transformiix/source/xpath/NodeSet.cpp index 3609764a8ced..625f5f43f5ab 100644 --- a/extensions/transformiix/source/xpath/NodeSet.cpp +++ b/extensions/transformiix/source/xpath/NodeSet.cpp @@ -27,19 +27,36 @@ * Olivier Gerardin, ogerardin@vo.lu * -- fixed numberValue() * - * $Id: NodeSet.cpp,v 1.3 2000/06/11 12:22:48 Peter.VanderBeken%pandora.be Exp $ + * $Id: NodeSet.cpp,v 1.4 2001/01/12 20:06:35 axel%pike.org Exp $ */ #include "NodeSet.h" +#include "XMLDOMUtils.h" +#ifndef MOZ_XSL #include +#else +#include "nsDOMCID.h" +#include "nsIDOMScriptObjectFactory.h" +#include "nsIScriptGlobalObject.h" +#include "nsIServiceManager.h" +#endif + /** * NodeSet
* This class was ported from XSL:P.
* @author Keith Visco - * @version $Revision: 1.3 $ $Date: 2000/06/11 12:22:48 $ + * @version $Revision: 1.4 $ $Date: 2001/01/12 20:06:35 $ **/ +#ifdef MOZ_XSL +static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); + +NS_IMPL_ISUPPORTS2(NodeSet, + nsIDOMNodeList, + nsIScriptObjectOwner) +#endif + //-------------/ //- Constants -/ //-------------/ @@ -77,6 +94,11 @@ NodeSet::NodeSet(const NodeSet& source) { * Helper method for Constructors **/ void NodeSet::initialize(int size) { +#ifdef MOZ_XSL + NS_INIT_ISUPPORTS(); + + mScriptObject = nsnull; +#endif elements = new Node*[size]; for ( int i = 0; i < size; i++ ) elements[i] = 0; elementCount = 0; @@ -98,7 +120,7 @@ NodeSet::~NodeSet() { * @return true if the Node is added to the NodeSet **/ MBool NodeSet::add(Node* node) { - if (!contains(node)) { + if (node && !contains(node)) { if (elementCount == bufferSize) increaseSize(); elements[elementCount++] = node; return MB_TRUE; @@ -115,7 +137,7 @@ MBool NodeSet::add(Node* node) { **/ MBool NodeSet::add(int index, Node* node) { - if ((index < 0) || (index > elementCount)) return MB_FALSE; + if (!node || (index < 0) || (index > elementCount)) return MB_FALSE; if (contains(node)) return MB_FALSE; @@ -190,6 +212,18 @@ Node* NodeSet::get(int index) { } //-- get +#ifdef MOZ_XSL +NS_IMETHODIMP NodeSet::Item(PRUint32 aIndex, nsIDOMNode** aReturn) +{ + if ((aIndex < 0) || aIndex >= (UInt32)elementCount) return NS_ERROR_INVALID_ARG; + Node* aNode = elements[aIndex]; + if (!aNode) return NS_ERROR_INVALID_ARG; + *aReturn = aNode->getNSNode(); + return NS_OK; +} //-- Item +#endif + + /** * Returns the index of the specified Node, * or -1 if the Node is not contained in the NodeSet @@ -249,6 +283,15 @@ int NodeSet::size() const{ return elementCount; } //-- size +#ifdef MOZ_XSL +NS_IMETHODIMP NodeSet::GetLength(PRUint32* aLength) +{ + *aLength = elementCount; + return NS_OK; +} //-- GetLength +#endif + + /** * Creates a String representation of this NodeSet * @param str the destination string to append the String representation to. @@ -350,3 +393,41 @@ void NodeSet::stringValue(String& str) { } } //-- stringValue +#ifdef MOZ_XSL +/* + * nsIScriptObjectOwner + */ + +NS_IMETHODIMP +NodeSet::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) +{ + nsresult rv = NS_OK; + nsIScriptGlobalObject* global = aContext->GetGlobalObject(); + + if (nsnull == mScriptObject) { + nsIDOMScriptObjectFactory *factory; + + if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID, + NS_GET_IID(nsIDOMScriptObjectFactory), + (nsISupports **)&factory))) { + rv = factory->NewScriptNodeList(aContext, + (nsISupports*)(nsIDOMNodeList*)this, + global, + (void**)&mScriptObject); + + nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory); + } + } + *aScriptObject = mScriptObject; + + NS_RELEASE(global); + return rv; +} + +NS_IMETHODIMP +NodeSet::SetScriptObject(void* aScriptObject) +{ + mScriptObject = aScriptObject; + return NS_OK; +} +#endif diff --git a/extensions/transformiix/source/xpath/NodeSet.h b/extensions/transformiix/source/xpath/NodeSet.h index 209a75c6e3fe..df9ebdad44d8 100644 --- a/extensions/transformiix/source/xpath/NodeSet.h +++ b/extensions/transformiix/source/xpath/NodeSet.h @@ -24,13 +24,13 @@ * Larry Fitzpatrick, OpenText, lef@opentext.com * -- moved initialization of DEFAULT_SIZE to NodeSet.cpp * - * $Id: NodeSet.h,v 1.3 2000/06/11 12:22:51 Peter.VanderBeken%pandora.be Exp $ + * $Id: NodeSet.h,v 1.4 2001/01/12 20:06:35 axel%pike.org Exp $ */ /** * NodeSet * @author Keith Visco - * @version $Revision: 1.3 $ $Date: 2000/06/11 12:22:51 $ + * @version $Revision: 1.4 $ $Date: 2001/01/12 20:06:35 $ **/ #ifndef TRANSFRMX_NODESET_H @@ -39,10 +39,18 @@ #include "MITREObject.h" #include "dom.h" #include "ExprResult.h" -#include "XMLDOMUtils.h" -class NodeSet : public ExprResult { +#ifdef MOZ_XSL +#include "nsIDOMNodeList.h" +#include "nsIScriptObjectOwner.h" +class NodeSet : public ExprResult, + public nsIDOMNodeList, + public nsIScriptObjectOwner +#else +class NodeSet : public ExprResult +#endif +{ public: @@ -70,6 +78,17 @@ public: **/ virtual ~NodeSet(); +#ifdef MOZ_XSL + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsIDocumentTransformer interface + NS_DECL_IDOMNODELIST + + // nsIScriptObjectOwner interface + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + NS_IMETHOD SetScriptObject(void* aScriptObject); +#endif /** * Adds the specified Node to this NodeSet if it is not already * contained within in this NodeSet. @@ -200,6 +219,10 @@ private: //- Private Members -/ //-------------------/ +#ifdef MOZ_XSL + void* mScriptObject; +#endif + static const int DEFAULT_SIZE; Node** elements; diff --git a/extensions/transformiix/source/xpath/NodeSetFunctionCall.cpp b/extensions/transformiix/source/xpath/NodeSetFunctionCall.cpp index 7643c014df25..9c36466553d4 100644 --- a/extensions/transformiix/source/xpath/NodeSetFunctionCall.cpp +++ b/extensions/transformiix/source/xpath/NodeSetFunctionCall.cpp @@ -24,14 +24,14 @@ * Marina Mechtcheriakova, mmarina@mindspring.com * -- changed some behavoir to be more compliant with spec * - * $Id: NodeSetFunctionCall.cpp,v 1.2 2000/04/20 10:12:05 kvisco%ziplink.net Exp $ + * $Id: NodeSetFunctionCall.cpp,v 1.3 2001/01/12 20:06:35 axel%pike.org Exp $ */ /** * NodeSetFunctionCall * A representation of the XPath NodeSet funtions * @author Keith Visco - * @version $Revision: 1.2 $ $Date: 2000/04/20 10:12:05 $ + * @version $Revision: 1.3 $ $Date: 2001/01/12 20:06:35 $ **/ #include "FunctionLib.h" @@ -53,6 +53,9 @@ NodeSetFunctionCall::NodeSetFunctionCall(short type) : FunctionCall() { case COUNT : FunctionCall::setName(XPathNames::COUNT_FN); break; + case ID : + FunctionCall::setName(XPathNames::ID_FN); + break; case LAST : FunctionCall::setName(XPathNames::LAST_FN); break; @@ -105,6 +108,43 @@ ExprResult* NodeSetFunctionCall::evaluate(Node* context, ContextState* cs) { result = new NumberResult(0.0); } break; + case ID : + if ( requireParams(1, 1, cs) ) { + NodeSet* resultSet = new NodeSet(); + param = (Expr*)iter->next(); + ExprResult* exprResult = param->evaluate(context, cs); + String lIDList; + if ( exprResult->getResultType() == ExprResult::NODESET ) { + NodeSet *lNList = (NodeSet *)exprResult; + NodeSet tmp; + for (int i=0; isize(); i++){ + tmp.add(0,lNList->get(i)); + tmp.stringValue(lIDList); + lIDList.append(' '); + }; + } else { + exprResult->stringValue(lIDList); + }; + lIDList.trim(); + Int32 start=0; + MBool hasSpace = MB_FALSE, isSpace; + UNICODE_CHAR cc; + String thisID; + for (Int32 end=0; endadd(context->getOwnerDocument()->getElementById(thisID)); + } else if (!isSpace && hasSpace){ + start = end; + hasSpace = MB_FALSE; + }; + }; + result = resultSet; + }; + break; case LAST : if ( nodeSet ) result = new NumberResult((double)nodeSet->size()); else result = new NumberResult(0.0); diff --git a/extensions/transformiix/source/xpath/NumberFunctionCall.cpp b/extensions/transformiix/source/xpath/NumberFunctionCall.cpp index d61b03e501e0..3b99483b443c 100644 --- a/extensions/transformiix/source/xpath/NumberFunctionCall.cpp +++ b/extensions/transformiix/source/xpath/NumberFunctionCall.cpp @@ -25,7 +25,7 @@ * Nisheeth Ranjan, nisheeth@netscape.com * -- implemented rint function, which was not available on Windows. * - * $Id: NumberFunctionCall.cpp,v 1.9 2001/01/10 11:48:47 axel%pike.org Exp $ + * $Id: NumberFunctionCall.cpp,v 1.10 2001/01/12 20:06:36 axel%pike.org Exp $ */ /* @@ -58,6 +58,9 @@ NumberFunctionCall::NumberFunctionCall(short type) : FunctionCall() { case FLOOR : FunctionCall::setName(XPathNames::FLOOR_FN); break; + case SUM : + FunctionCall::setName(XPathNames::SUM_FN); + break; case NUMBER : default : FunctionCall::setName(XPathNames::NUMBER_FN); @@ -130,6 +133,26 @@ ExprResult* NumberFunctionCall::evaluate(Node* context, ContextState* cs) { else result->setValue(0.0); break; + case SUM : + double numResult; + numResult = 0 ; + if ( requireParams(1, 1, cs) ) { + param = (Expr*)iter->next(); + ExprResult* exprResult = param->evaluate(context, cs); + if ( exprResult->getResultType() == ExprResult::NODESET ) { + NodeSet *lNList = (NodeSet *)exprResult; + NodeSet tmp; + for (int i=0; isize(); i++){ + tmp.add(0,lNList->get(i)); + numResult += tmp.numberValue(); + }; + }; + delete exprResult; + exprResult=0; + }; + result = new NumberResult(numResult); + break; + case NUMBER : default : //-- number( object? ) if ( requireParams(0, 1, cs) ) { diff --git a/extensions/transformiix/source/xpath/PathExpr.cpp b/extensions/transformiix/source/xpath/PathExpr.cpp index ffff27cc79dd..cefaedb26d75 100644 --- a/extensions/transformiix/source/xpath/PathExpr.cpp +++ b/extensions/transformiix/source/xpath/PathExpr.cpp @@ -29,7 +29,7 @@ * - foo//bar would not match properly if there was more than * one node in the NodeSet (nodes) on the final iteration * - * $Id: PathExpr.cpp,v 1.4 2000/11/07 10:42:35 kvisco%ziplink.net Exp $ + * $Id: PathExpr.cpp,v 1.5 2001/01/12 20:06:36 axel%pike.org Exp $ */ #include "Expr.h" @@ -154,7 +154,7 @@ ExprResult* PathExpr::evaluate(Node* context, ContextState* cs) { } delete (NodeSet*) cs->getNodeSetStack()->pop(); nodes = tmpNodes; - if ( nodes->size() == 0 ) break; + if ( !nodes || nodes->size() == 0 ) break; } delete iter; @@ -173,7 +173,7 @@ void PathExpr::fromDescendants if (( !context ) || (! pExpr )) return; NodeList* nl = context->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++) { + for (UInt32 i = 0; i < nl->getLength(); i++) { Node* child = nl->item(i); if (pExpr->matches(child, context, cs)) nodes->add(child); diff --git a/extensions/transformiix/source/xpath/StringFunctionCall.cpp b/extensions/transformiix/source/xpath/StringFunctionCall.cpp index c2a71fe775b5..34d1fbbca69e 100644 --- a/extensions/transformiix/source/xpath/StringFunctionCall.cpp +++ b/extensions/transformiix/source/xpath/StringFunctionCall.cpp @@ -21,14 +21,14 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: StringFunctionCall.cpp,v 1.5 2001/01/10 11:48:47 axel%pike.org Exp $ + * $Id: StringFunctionCall.cpp,v 1.6 2001/01/12 20:06:37 axel%pike.org Exp $ */ /** * StringFunctionCall * A representation of the XPath String funtions * @author Keith Visco - * @version $Revision: 1.5 $ $Date: 2001/01/10 11:48:47 $ + * @version $Revision: 1.6 $ $Date: 2001/01/12 20:06:37 $ **/ #include "FunctionLib.h" @@ -110,6 +110,39 @@ ExprResult* StringFunctionCall::evaluate(Node* context, ContextState* cs) { else result = new BooleanResult(MB_FALSE); break; + case NORMALIZE_SPACE: + if ( requireParams(0, 1, cs) ) { + String resultStr; + if ( argc == 1) + evaluateToString((Expr*)iter->next(),context, cs, resultStr); + else + XMLDOMUtils::getNodeValue(context, &resultStr); + // Leading & Trailing Whitespace + resultStr.trim(); + MBool hasSpace = MB_FALSE; + Int32 lastchar=-1, dest=0; + String normed(resultStr.length()); + UNICODE_CHAR current; + for (Int32 src=0; srcnext(),context, cs); - if (dbl == Double::POSITIVE_INFINITY) ++endIdx; - else if ( dbl == Double::NEGATIVE_INFINITY ) endIdx = 0; - else endIdx = (Int32)floor(dbl); + dbl = evaluateToNumber((Expr*)iter->next(),context, cs); + if (startsNegInf) { + result = new StringResult(""); + break; + } + if (dbl == Double::POSITIVE_INFINITY) ; //already complete + else if ( Double::isNaN(dbl) || + dbl == Double::NEGATIVE_INFINITY || + dbl < 0 ) + endIdx = 0; + else endIdx = startIdx+(Int32)floor(dbl+.5); } String resultStr; //-- strings are indexed starting at 1 for XSL //-- adjust to a 0-based index - if (startIdx > 0) --startIdx; - else if (startIdx == 0 ) --endIdx; - else startIdx=0; + endIdx--; + if (startIdx<1){ + startIdx = 0; + } else { + startIdx--; + } src.subString(startIdx,endIdx,resultStr); result = new StringResult(resultStr); @@ -208,7 +254,7 @@ ExprResult* StringFunctionCall::evaluate(Node* context, ContextState* cs) { for (i = 0; i < size; i++) { Int32 idx = oldChars.indexOf(chars[i]); if (idx >= 0) { - char nchar = newChars.charAt(idx); + UNICODE_CHAR nchar = newChars.charAt(idx); if (nchar != -1) src.append(nchar); } else src.append(chars[i]); diff --git a/extensions/transformiix/source/xpath/TextExpr.cpp b/extensions/transformiix/source/xpath/TextExpr.cpp index 82b2d8c38981..9321658d087d 100644 --- a/extensions/transformiix/source/xpath/TextExpr.cpp +++ b/extensions/transformiix/source/xpath/TextExpr.cpp @@ -21,7 +21,7 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: TextExpr.cpp,v 1.1 2000/04/06 07:45:49 kvisco%ziplink.net Exp $ + * $Id: TextExpr.cpp,v 1.2 2001/01/12 20:06:37 axel%pike.org Exp $ */ #include "Expr.h" @@ -41,7 +41,7 @@ ExprResult* TextExpr::evaluate(Node* context, ContextState* cs) { NodeList* nl = context->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++ ) { + for ( UInt32 i = 0; i < nl->getLength(); i++ ) { Node* node = nl->item(i); if ( node->getNodeType() == Node::TEXT_NODE ) nodeSet->add(node); diff --git a/extensions/transformiix/source/xpath/WildCardExpr.cpp b/extensions/transformiix/source/xpath/WildCardExpr.cpp index 653ae5c16e9c..ba43fbbdcf2b 100644 --- a/extensions/transformiix/source/xpath/WildCardExpr.cpp +++ b/extensions/transformiix/source/xpath/WildCardExpr.cpp @@ -21,7 +21,7 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: WildCardExpr.cpp,v 1.1 2000/04/06 07:46:00 kvisco%ziplink.net Exp $ + * $Id: WildCardExpr.cpp,v 1.2 2001/01/12 20:06:37 axel%pike.org Exp $ */ #include "Expr.h" @@ -30,7 +30,7 @@ * This class represents a WildCardExpr as defined by the XSL * Working Draft * @author Keith Visco - * @version $Revision: 1.1 $ $Date: 2000/04/06 07:46:00 $ + * @version $Revision: 1.2 $ $Date: 2001/01/12 20:06:37 $ **/ /** @@ -48,7 +48,7 @@ ExprResult* WildCardExpr::evaluate(Node* context, ContextState* cs) { NodeList* nl = context->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++ ) { + for ( UInt32 i = 0; i < nl->getLength(); i++ ) { Node* node = nl->item(i); if ( node->getNodeType() == Node::ELEMENT_NODE ) nodeSet->add(node); diff --git a/extensions/transformiix/source/xpath/XPathNames.cpp b/extensions/transformiix/source/xpath/XPathNames.cpp index 1b2add04b04e..927c28f8c9e8 100644 --- a/extensions/transformiix/source/xpath/XPathNames.cpp +++ b/extensions/transformiix/source/xpath/XPathNames.cpp @@ -24,13 +24,13 @@ * Marina Mechtcheriakova, mmarina@mindspring.com * -- added LANG_FN * - * $Id: XPathNames.cpp,v 1.3 2000/06/11 12:31:28 Peter.VanderBeken%pandora.be Exp $ + * $Id: XPathNames.cpp,v 1.4 2001/01/12 20:06:37 axel%pike.org Exp $ */ /** * XPath names * @author Keith Visco - * @version $Revision: 1.3 $ $Date: 2000/06/11 12:31:28 $ + * @version $Revision: 1.4 $ $Date: 2001/01/12 20:06:37 $ **/ #include "FunctionLib.h" @@ -41,10 +41,12 @@ 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"; @@ -53,6 +55,7 @@ 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"; // OG+ diff --git a/extensions/transformiix/source/xpath/XPathProcessor.cpp b/extensions/transformiix/source/xpath/XPathProcessor.cpp new file mode 100644 index 000000000000..d0f84037f3f9 --- /dev/null +++ b/extensions/transformiix/source/xpath/XPathProcessor.cpp @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Peter Van der Beken, peterv@netscape.com + * -- original author. + * + */ + +#include "XPathProcessor.h" +#include "dom.h" +#include "ProcessorState.h" +#include "Expr.h" + +NS_IMPL_ISUPPORTS2(XPathProcessor, + nsIXPathNodeSelector, + nsISecurityCheckedComponent) + +/** + * Creates a new XPathProcessor +**/ +XPathProcessor::XPathProcessor() { + + NS_INIT_ISUPPORTS(); +} //-- XPathProcessor + +/** + * Default destructor +**/ +XPathProcessor::~XPathProcessor() { +} //-- ~XPathProcessor + +/* nsIDOMNodeList selectNodes (in nsIDOMNode aContextNode, in string aPattern); */ +NS_IMETHODIMP XPathProcessor::SelectNodes(nsIDOMNode *aContextNode, const char *aPattern, nsIDOMNodeList **_retval) +{ + nsCOMPtr aOwnerDOMDocument; + aContextNode->GetOwnerDocument(getter_AddRefs(aOwnerDOMDocument)); + nsCOMPtr aOwnerDocument = do_QueryInterface(aOwnerDOMDocument); + Document* aDocument = new Document(aOwnerDOMDocument); + Node* aNode = new Node(aContextNode, aDocument); + + ProcessorState* aProcessorState = new ProcessorState(*aDocument, *aDocument); + ExprParser* aParser = new ExprParser; + + Expr* aExpression = aParser->createExpr(aPattern); + ExprResult* exprResult = aExpression->evaluate(aNode, aProcessorState); + if ( exprResult->getResultType() == ExprResult::NODESET ) { + *_retval = (NodeSet*)exprResult; + } + else { + // Return an empty nodeset + *_retval = new NodeSet(0); + } + NS_ADDREF(*_retval); + + delete aExpression; + delete aNode; + delete aDocument; + + return NS_OK; +} + +/* + * nsISecurityCheckedComponent + */ + +static const char* kAllAccess = "AllAccess"; + +/* string canCreateWrapper (in nsIIDPtr iid); */ +NS_IMETHODIMP +XPathProcessor::CanCreateWrapper(const nsIID * iid, char **_retval) +{ + if (iid->Equals(NS_GET_IID(nsIXPathNodeSelector))) { + *_retval = nsCRT::strdup(kAllAccess); + } + + return NS_OK; +} + +/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */ +NS_IMETHODIMP +XPathProcessor::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval) +{ + if (iid->Equals(NS_GET_IID(nsIXPathNodeSelector))) { + *_retval = nsCRT::strdup(kAllAccess); + } + + return NS_OK; +} + +/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */ +NS_IMETHODIMP +XPathProcessor::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval) +{ + if (iid->Equals(NS_GET_IID(nsIXPathNodeSelector))) { + *_retval = nsCRT::strdup(kAllAccess); + } + + return NS_OK; +} + +/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */ +NS_IMETHODIMP +XPathProcessor::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval) +{ + if (iid->Equals(NS_GET_IID(nsIXPathNodeSelector))) { + *_retval = nsCRT::strdup(kAllAccess); + } + + return NS_OK; +} diff --git a/extensions/transformiix/source/xpath/XPathProcessor.h b/extensions/transformiix/source/xpath/XPathProcessor.h new file mode 100644 index 000000000000..3f41204738c1 --- /dev/null +++ b/extensions/transformiix/source/xpath/XPathProcessor.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Peter Van der Beken, peterv@netscape.com + * -- original author. + * + */ + +#ifndef XPathProcessor_h__ +#define XPathProcessor_h__ + +#include "nsIXPathNodeSelector.h" +#include "nsISecurityCheckedComponent.h" + +/* e4172588-1dd1-11b2-bf09-ec309437245a */ +#define TRANSFORMIIX_XPATH_PROCESSOR_CID \ +{ 0xe4172588, 0x1dd1, 0x11b2, {0xbf, 0x09, 0xec, 0x30, 0x94, 0x37, 0x24, 0x5a} } + +#define TRANSFORMIIX_XPATH_PROCESSOR_CONTRACTID \ +"@mozilla.org/xpath-nodeselector;1" + +/** + * A class for processing an XPath query +**/ +class XPathProcessor : public nsIXPathNodeSelector, + public nsISecurityCheckedComponent +{ +public: + /** + * Creates a new XPathProcessor + **/ + XPathProcessor(); + + /** + * Default destructor for XPathProcessor + **/ + virtual ~XPathProcessor(); + + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsIXPathNodeSelector interface + NS_DECL_NSIXPATHNODESELECTOR + + // nsISecurityCheckedComponent + NS_DECL_NSISECURITYCHECKEDCOMPONENT + +}; //-- XPathProcessor + +#endif diff --git a/extensions/transformiix/source/xpath/makefile.win b/extensions/transformiix/source/xpath/makefile.win index ad114d461b35..b3bfdfd5a79c 100644 --- a/extensions/transformiix/source/xpath/makefile.win +++ b/extensions/transformiix/source/xpath/makefile.win @@ -61,6 +61,9 @@ CPPSRCS= \ VariableRefExpr.cpp \ WildCardExpr.cpp \ XPathNames.cpp \ +!if defined(MOZ_XSL) + XPathProcessor.cpp \ +!endif $(NULL) CPP_OBJS= \ @@ -99,13 +102,17 @@ CPP_OBJS= \ .\$(OBJDIR)\VariableRefExpr.obj \ .\$(OBJDIR)\WildCardExpr.obj \ .\$(OBJDIR)\XPathNames.obj \ +!if defined(MOZ_XSL) + .\$(OBJDIR)\XPathProcessor.obj \ +!endif $(NULL) EXPORTS = \ $(NULL) -LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I..\base -I..\util -I..\xml\dom \ - -I..\xml -I ..\xslt +LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ + -I..\base -I..\util -I..\xml -I..\xml\util -I..\xml\dom -I..\xslt \ + -I..\xslt\functions -I..\xslt\util LCFLAGS = \ $(LCFLAGS) \ diff --git a/extensions/transformiix/source/xslt/Names.cpp b/extensions/transformiix/source/xslt/Names.cpp index 05a28c1da164..c0023fd5ef72 100644 --- a/extensions/transformiix/source/xslt/Names.cpp +++ b/extensions/transformiix/source/xslt/Names.cpp @@ -28,14 +28,14 @@ * W3C XPath 1.0 Recommendation * -- Added lang attr declaration * - * $Id: Names.cpp,v 1.8 2000/06/15 09:20:53 rbs%maths.uq.edu.au Exp $ + * $Id: Names.cpp,v 1.9 2001/01/12 20:06:42 axel%pike.org Exp $ */ /** * XSL names used throughout the XSLProcessor. * Probably should be wrapped in a Namespace * @author Keith Visco - * @version $Revision: 1.8 $ $Date: 2000/06/15 09:20:53 $ + * @version $Revision: 1.9 $ $Date: 2001/01/12 20:06:42 $ **/ #include "Names.h" @@ -79,7 +79,6 @@ const String VARIABLE = "variable"; const String WHEN = "when"; const String WITH_PARAM = "with-param"; - //-- Attributes const String CDATA_ELEMENTS_ATTR = "cdata-section-elements"; const String COUNT_ATTR = "count"; @@ -111,7 +110,6 @@ const String USE_ATTRIBUTE_SETS_ATTR = "use-attribute-sets"; const String VALUE_ATTR = "value"; const String VERSION_ATTR = "version"; - //-- Attribute Values const String ANY_VALUE = "any"; const String MULTIPLE_VALUE = "multiple"; @@ -139,7 +137,6 @@ 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"; @@ -150,11 +147,15 @@ const String IDENTITY_OP = "."; const String PARENT_OP = ".."; //-- XSLT additional functions -const String CURRENT_FN = "current"; +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 DOCUMENT_FN = "document"; +const String ELEMENT_AVAILABLE_FN = "element-available"; +const String FUNCTION_AVAILABLE_FN = "function-available"; //-- MISC const String WILD_CARD = "*"; diff --git a/extensions/transformiix/source/xslt/Names.h b/extensions/transformiix/source/xslt/Names.h index a66486f3f187..b6b19bab2bfc 100644 --- a/extensions/transformiix/source/xslt/Names.h +++ b/extensions/transformiix/source/xslt/Names.h @@ -27,7 +27,7 @@ * W3C XPath 1.0 Recommendation * -- Added lang attr declaration - * $Id: Names.h,v 1.6 2000/05/24 03:45:41 kvisco%ziplink.net Exp $ + * $Id: Names.h,v 1.7 2001/01/12 20:06:42 axel%pike.org Exp $ */ #include "TxString.h" @@ -145,12 +145,15 @@ extern const String IDENTITY_OP; extern const String PARENT_OP; //-- XSLT additional functions -extern const String CURRENT_FN; +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 DOCUMENT_FN; - +extern const String ELEMENT_AVAILABLE_FN; +extern const String FUNCTION_AVAILABLE_FN; //-- MISC extern const String WILD_CARD; diff --git a/extensions/transformiix/source/xslt/ProcessorState.cpp b/extensions/transformiix/source/xslt/ProcessorState.cpp index 0d91e9ccac59..154106b44b89 100644 --- a/extensions/transformiix/source/xslt/ProcessorState.cpp +++ b/extensions/transformiix/source/xslt/ProcessorState.cpp @@ -25,13 +25,13 @@ * -- added code in ::resolveFunctionCall to support the * document() function. * - * $Id: ProcessorState.cpp,v 1.12 2000/11/07 10:46:03 kvisco%ziplink.net Exp $ + * $Id: ProcessorState.cpp,v 1.13 2001/01/12 20:06:42 axel%pike.org Exp $ */ /** * Implementation of ProcessorState * Much of this code was ported from XSL:P - * @version $Revision: 1.12 $ $Date: 2000/11/07 10:46:03 $ + * @version $Revision: 1.13 $ $Date: 2001/01/12 20:06:42 $ **/ #include "ProcessorState.h" @@ -101,7 +101,7 @@ void ProcessorState::addAttributeSet(Element* attributeSet) { //-- add xsl:attribute elements to attSet NodeList* nl = attributeSet->getChildNodes(); - for ( int i = 0; i < nl->getLength(); i++) { + for ( UInt32 i = 0; i < nl->getLength(); i++) { Node* node = nl->item(i); if ( node->getNodeType() == Node::ELEMENT_NODE) { String nodeName = node->getNodeName(); @@ -669,16 +669,44 @@ void ProcessorState::recieveError(String& errorMessage, ErrorLevel level) { * @return the FunctionCall for the function with the given name. **/ FunctionCall* ProcessorState::resolveFunctionCall(const String& name) { + String err; - if (GENERATE_ID_FN.isEqual(name)) { - return new GenerateIdFunctionCall(&domHelper); - } - else if (DOCUMENT_FN.isEqual(name)) { + if (DOCUMENT_FN.isEqual(name)) { return new DocumentFunctionCall(xslDocument); } - - String err("invalid function call: "); - err.append(name); + else if (KEY_FN.isEqual(name)) { + err = "function not yet implemented: "; + err.append(name); + } + else if (FORMAT_NUMBER_FN.isEqual(name)) { + err = "function not yet implemented: "; + err.append(name); + } + else if (CURRENT_FN.isEqual(name)) { + return new CurrentFunctionCall(); + } + else if (UNPARSED_ENTITY_URI_FN.isEqual(name)) { + err = "function not yet implemented: "; + err.append(name); + } + else if (GENERATE_ID_FN.isEqual(name)) { + return new GenerateIdFunctionCall(&domHelper); + } + else if (SYSTEM_PROPERTY_FN.isEqual(name)) { + return new SystemPropertyFunctionCall(); + } + else if (ELEMENT_AVAILABLE_FN.isEqual(name)) { + err = "function not yet implemented: "; + err.append(name); + } + else if (FUNCTION_AVAILABLE_FN.isEqual(name)) { + err = "function not yet implemented: "; + err.append(name); + } + else { + err = "invalid function call: "; + err.append(name); + } return new ErrorFunctionCall(err); @@ -792,7 +820,7 @@ void ProcessorState::initialize() { //-- process namespace nodes NamedNodeMap* atts = element->getAttributes(); if ( atts ) { - for (int i = 0; i < atts->getLength(); i++) { + for (UInt32 i = 0; i < atts->getLength(); i++) { Attr* attr = (Attr*)atts->item(i); String attName = attr->getName(); String attValue = attr->getValue(); diff --git a/extensions/transformiix/source/xslt/XSLTProcessor.cpp b/extensions/transformiix/source/xslt/XSLTProcessor.cpp index 6c9c99412e4b..462c12a16185 100644 --- a/extensions/transformiix/source/xslt/XSLTProcessor.cpp +++ b/extensions/transformiix/source/xslt/XSLTProcessor.cpp @@ -38,7 +38,7 @@ * Olivier Gerardin * -- Changed behavior of passing parameters to templates * - * $Id: XSLTProcessor.cpp,v 1.27 2001/01/10 11:48:48 axel%pike.org Exp $ + * $Id: XSLTProcessor.cpp,v 1.28 2001/01/12 20:06:43 axel%pike.org Exp $ */ #include "XSLTProcessor.h" @@ -53,7 +53,7 @@ /** * XSLTProcessor is a class for Processing XSL styelsheets * @author Keith Visco - * @version $Revision: 1.27 $ $Date: 2001/01/10 11:48:48 $ + * @version $Revision: 1.28 $ $Date: 2001/01/12 20:06:43 $ **/ /** @@ -191,7 +191,7 @@ void XSLTProcessor::getHrefFromStylesheetPI(Document& xmlDocument, String& href) NodeList* nl = xmlDocument.getChildNodes(); String type; String tmpHref; - for ( int i = 0; i < nl->getLength(); i++ ) { + for ( UInt32 i = 0; i < nl->getLength(); i++ ) { Node* node = nl->item(i); if ( node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE ) { String target = ((ProcessingInstruction*)node)->getTarget(); @@ -382,7 +382,7 @@ void XSLTProcessor::processTopLevel if (!stylesheet) return; NodeList* nl = stylesheet->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++) { + for (UInt32 i = 0; i < nl->getLength(); i++) { Node* node = nl->item(i); if (node->getNodeType() == Node::ELEMENT_NODE) { Element* element = (Element*)node; @@ -756,7 +756,7 @@ MBool XSLTProcessor::getText if ( deep ) XMLDOMUtils::getNodeValue(dfrag, &dest); else { NodeList* nl = dfrag->getChildNodes(); - for ( int i = 0; i < nl->getLength(); i++ ) { + for ( UInt32 i = 0; i < nl->getLength(); i++ ) { Node* node = nl->item(i); switch(node->getNodeType()) { case Node::CDATA_SECTION_NODE: @@ -992,7 +992,7 @@ void XSLTProcessor::processAction { NodeList* nl = actionElement->getChildNodes(); Element* xslTemplate = 0; - for (int i = 0; i < nl->getLength(); i++ ) { + for ( UInt32 i = 0; i < nl->getLength(); i++ ) { Node* tmp = nl->item(i); if ( tmp->getNodeType() != Node::ELEMENT_NODE ) continue; xslTemplate = (Element*)tmp; @@ -1068,6 +1068,10 @@ void XSLTProcessor::processAction // XXX (pvdb) Check if we need to set a new default namespace? String nameSpaceURI; ps->getNameSpaceURI(name, nameSpaceURI); + // XXX HACK (pvdb) Workaround for BUG 51656 Html rendered as xhtml + if (ps->getOutputFormat()->isHTMLOutput()) { + name.toLowerCase(); + } element = resultDoc->createElementNS(nameSpaceURI, name); #else element = resultDoc->createElement(name); @@ -1313,6 +1317,10 @@ void XSLTProcessor::processAction String nameSpaceURI; ps->getNameSpaceURI(nodeName, nameSpaceURI); + // XXX HACK (pvdb) Workaround for BUG 51656 Html rendered as xhtml + if (ps->getOutputFormat()->isHTMLOutput()) { + nodeName.toLowerCase(); + } Element* element = resultDoc->createElementNS(nameSpaceURI, nodeName); #else Element* element = resultDoc->createElement(nodeName); @@ -1322,12 +1330,12 @@ void XSLTProcessor::processAction ps->getNodeStack()->push(element); //-- handle attributes NamedNodeMap* atts = actionElement->getAttributes(); + if ( atts ) { String xsltNameSpace = ps->getXSLNamespace(); NodeSet nonXSLAtts(atts->getLength()); //-- process special XSL attributes first - int i; - for (i = 0; i < atts->getLength(); i++ ) { + for ( UInt32 i = 0; i < atts->getLength(); i++ ) { Attr* attr = (Attr*) atts->item(i); //-- filter attributes in the XSLT namespace String attrNameSpace; @@ -1344,8 +1352,8 @@ void XSLTProcessor::processAction else nonXSLAtts.add(attr); } //-- process all non XSL attributes - for ( i = 0; i < nonXSLAtts.size(); i++ ) { - Attr* attr = (Attr*) nonXSLAtts.get(i); + for ( int j = 0; j < nonXSLAtts.size(); j++ ) { + Attr* attr = (Attr*) nonXSLAtts.get(j); Attr* newAttr = resultDoc->createAttribute(attr->getName()); //-- process Attribute Value Templates String value; @@ -1356,8 +1364,7 @@ void XSLTProcessor::processAction } //-- process children NodeList* nl = xslAction->getChildNodes(); - int i; - for ( i = 0; i < nl->getLength(); i++) { + for ( UInt32 i = 0; i < nl->getLength(); i++) { processAction(node, nl->item(i),ps); } ps->getNodeStack()->pop(); @@ -1447,7 +1454,7 @@ NamedMap* XSLTProcessor::processParameters(Element* xslAction, Node* context, Pr //-- handle xsl:with-param elements NodeList* nl = xslAction->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++) { + for (UInt32 i = 0; i < nl->getLength(); i++) { Node* tmpNode = nl->item(i); int nodeType = tmpNode->getNodeType(); if ( nodeType == Node::ELEMENT_NODE ) { @@ -1500,7 +1507,7 @@ void XSLTProcessor::processTemplate(Node* node, Node* xslTemplate, ProcessorStat bindings->push(&localBindings); processTemplateParams(xslTemplate, node, ps, params); NodeList* nl = xslTemplate->getChildNodes(); - for (int i = 0; i < nl->getLength(); i++) + for (UInt32 i = 0; i < nl->getLength(); i++) processAction(node, nl->item(i), ps); bindings->pop(); } @@ -1522,9 +1529,8 @@ void XSLTProcessor::processTemplateParams if ( xslTemplate ) { NodeList* nl = xslTemplate->getChildNodes(); - int i = 0; //-- handle params - for (i = 0; i < nl->getLength(); i++) { + for (UInt32 i = 0; i < nl->getLength(); i++) { Node* tmpNode = nl->item(i); int nodeType = tmpNode->getNodeType(); if ( nodeType == Node::ELEMENT_NODE ) { @@ -1591,7 +1597,7 @@ ExprResult* XSLTProcessor::processVariable Document* resultTree = ps->getResultDocument(); NodeStack* nodeStack = ps->getNodeStack(); nodeStack->push(resultTree->createDocumentFragment()); - for (int i = 0; i < nl->getLength(); i++) { + for (UInt32 i = 0; i < nl->getLength(); i++) { processAction(node, nl->item(i), ps); } Node* node = nodeStack->pop(); @@ -1631,6 +1637,10 @@ void XSLTProcessor::xslCopy(Node* node, Element* action, ProcessorState* ps) { String nameSpaceURI; ps->getNameSpaceURI(nodeName, nameSpaceURI); + // XXX HACK (pvdb) Workaround for BUG 51656 Html rendered as xhtml + if (ps->getOutputFormat()->isHTMLOutput()) { + nodeName.toLowerCase(); + } copy = resultDoc->createElementNS(nameSpaceURI, nodeName); #else copy = resultDoc->createElement(nodeName); @@ -1751,7 +1761,6 @@ XSLTProcessor::TransformDocument(nsIDOMNode* aSourceDOM, //------------------------------------------------------/ //- index templates and process top level xsl elements -/ //------------------------------------------------------/ - processTopLevel(xslDocument, ps); //---------------------------------------/ @@ -1765,10 +1774,17 @@ XSLTProcessor::TransformDocument(nsIDOMNode* aSourceDOM, nsCOMPtr anObserverService = do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &res); if (NS_SUCCEEDED(res)) { - nsIDOMNode* docElement = (resultDocument->getDocumentElement())->getNSObj(); + Node* docElement = resultDocument->getDocumentElement(); + nsIDOMNode* nsDocElement; + if (docElement) { + nsDocElement = docElement->getNSNode(); + } + else { + nsDocElement = nsnull; + } anObserverService->AddObserver(aObserver, topic.GetUnicode()); - anObserverService->Notify(docElement, topic.GetUnicode(), nsnull); + anObserverService->Notify(nsDocElement, topic.GetUnicode(), nsnull); } } diff --git a/extensions/transformiix/source/xslt/functions/CurrentFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/CurrentFunctionCall.cpp new file mode 100644 index 000000000000..f2acb9b5ca27 --- /dev/null +++ b/extensions/transformiix/source/xslt/functions/CurrentFunctionCall.cpp @@ -0,0 +1,29 @@ +#include "XSLTFunctions.h" + +/* + Implementation of XSLT 1.0 extension function: current +*/ + +/** + * Creates a new current function call +**/ +CurrentFunctionCall::CurrentFunctionCall() : + FunctionCall(CURRENT_FN) +{ +} + +/** + * 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* CurrentFunctionCall::evaluate(Node* context, ContextState* cs) { +// NodeSet* result = new NodeSet(0); +// result->add(cs->getCurrentNode); +// return result; + return new StringResult("function not yet implemented: current"); +} + diff --git a/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp new file mode 100644 index 000000000000..46fbca9670d2 --- /dev/null +++ b/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp @@ -0,0 +1,69 @@ +#include "XSLTFunctions.h" +#include "XMLUtils.h" + +const String XSL_VERSION_PROPERTY = "version"; +const String XSL_VENDOR_PROPERTY = "vendor"; +const String XSL_VENDOR_URL_PROPERTY = "vendor-url"; + +/* + Implementation of XSLT 1.0 extension function: system-property +*/ + +/** + * Creates a new system-property function call +**/ +SystemPropertyFunctionCall::SystemPropertyFunctionCall() : + FunctionCall(SYSTEM_PROPERTY_FN) +{ +} + +/** + * 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* SystemPropertyFunctionCall::evaluate(Node* context, ContextState* cs) { + + //int argc = params.getLength(); + + ExprResult* result = 0; + + //if (argc > 0) { + if ( requireParams(1,1,cs) ) { + ListIterator* iter = params.iterator(); + Expr* param = (Expr*) iter->next(); + delete iter; + ExprResult* exprResult = param->evaluate(context, cs); + if (exprResult->getResultType() == ExprResult::STRING) { + String property; + exprResult->stringValue(property); + if (XMLUtils::isValidQName(property)) { + String propertyNsURI; + cs->getNameSpaceURI(property, propertyNsURI); + if (propertyNsURI.isEqual(XSLT_NS)) { + 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 { + String err("Invalid argument passed to system-property(), expecting String"); + result = new StringResult(err); + } + } + + if (result) + return result; + else + return new StringResult(""); +} + diff --git a/extensions/transformiix/source/xslt/functions/XSLTFunctions.h b/extensions/transformiix/source/xslt/functions/XSLTFunctions.h index a05c7e2cf19e..00146908154e 100644 --- a/extensions/transformiix/source/xslt/functions/XSLTFunctions.h +++ b/extensions/transformiix/source/xslt/functions/XSLTFunctions.h @@ -23,7 +23,7 @@ * Olivier Gerardin, * -- added document() function definition * - * $Id: XSLTFunctions.h,v 1.2 2000/05/24 03:46:31 kvisco%ziplink.net Exp $ + * $Id: XSLTFunctions.h,v 1.3 2001/01/12 20:06:46 axel%pike.org Exp $ */ #include "dom.h" @@ -36,6 +36,133 @@ #ifndef TRANSFRMX_XSLT_FUNCTIONS_H #define TRANSFRMX_XSLT_FUNCTIONS_H +/** + * The definition for the XSLT document() function +**/ +class DocumentFunctionCall : public FunctionCall { + +public: + + /** + * Creates a new document() function call + **/ + DocumentFunctionCall(Document* xslDocument); + + /** + * 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 + **/ + virtual ExprResult* evaluate(Node* context, ContextState* cs); + +private: + void retrieveDocument(String& uri,String& baseUri, NodeSet &resultNodeSet, ContextState* cs); + Document* xslDocument; +}; + +/** + * The definition for the XSLT key() function +**/ +class KeyFunctionCall : public FunctionCall { + +public: + + /** + * Creates a new key() function call + **/ + KeyFunctionCall(); + + /** + * 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 + **/ + virtual ExprResult* evaluate(Node* context, ContextState* cs); + +private: +}; + +/** + * The definition for the XSLT format-number() function +**/ +class FormatNumberFunctionCall : public FunctionCall { + +public: + + /** + * Creates a new format-number() function call + **/ + FormatNumberFunctionCall(); + + /** + * 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 + **/ + virtual ExprResult* evaluate(Node* context, ContextState* cs); + +private: +}; + +/** + * The definition for the XSLT current() function +**/ +class CurrentFunctionCall : public FunctionCall { + +public: + + /** + * Creates a new current() function call + **/ + CurrentFunctionCall(); + + /** + * 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 + **/ + virtual ExprResult* evaluate(Node* context, ContextState* cs); + +private: +}; + +/** + * The definition for the XSLT unparsed-entity-uri() function +**/ +class UnparsedEntityUriFunctionCall : public FunctionCall { + +public: + + /** + * Creates a new unparsed-entity-uri() function call + **/ + 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 + **/ + virtual ExprResult* evaluate(Node* context, ContextState* cs); + +private: +}; + /** * The definition for the XSLT generate-id() function **/ @@ -44,7 +171,7 @@ class GenerateIdFunctionCall : public FunctionCall { public: /** - * Creates a new generate-id function call + * Creates a new generate-id() function call **/ GenerateIdFunctionCall(DOMHelper* domHelper); @@ -63,21 +190,71 @@ private: }; /** - * The definition for the XSLT document() function + * The definition for the XSLT system-property() function **/ -class DocumentFunctionCall : public FunctionCall { +class SystemPropertyFunctionCall : public FunctionCall { public: /** - * Creates a new document() function call + * Creates a new system-property() function call **/ - DocumentFunctionCall(Document* xslDocument); + SystemPropertyFunctionCall(); /** * 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 + * @param cs the ContextState containing the stack information needed + * for evaluation + * @return the result of the evaluation + * @see FunctionCall.h + **/ + virtual ExprResult* evaluate(Node* context, ContextState* cs); + +private: +}; + +/** + * The definition for the XSLT element-available() function +**/ +class ElementAvailableFunctionCall : public FunctionCall { + +public: + + /** + * Creates a new element-available() function call + **/ + ElementAvailableFunctionCall(); + + /** + * 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 + **/ + virtual ExprResult* evaluate(Node* context, ContextState* cs); + +private: +}; + +/** + * The definition for the XSLT function-available() function +**/ +class FunctionAvailableFunctionCall : public FunctionCall { + +public: + + /** + * Creates a new function-available() function call + **/ + FunctionAvailableFunctionCall(); + + /** + * 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 @@ -85,8 +262,6 @@ public: virtual ExprResult* evaluate(Node* context, ContextState* cs); private: - void retrieveDocument(String& uri,String& baseUri, NodeSet &resultNodeSet, ContextState* cs); - Document* xslDocument; }; #endif diff --git a/extensions/transformiix/source/xslt/functions/makefile.win b/extensions/transformiix/source/xslt/functions/makefile.win index 15b27ee9c898..1e8b9d74e094 100644 --- a/extensions/transformiix/source/xslt/functions/makefile.win +++ b/extensions/transformiix/source/xslt/functions/makefile.win @@ -28,19 +28,23 @@ DEFINES=$(DEFINES) -DMOZ_XSL CPPSRCS= \ GenerateIDFunctionCall.cpp \ DocumentFunctionCall.cpp \ + SystemPropertyFunctionCall.cpp \ + CurrentFunctionCall.cpp \ $(NULL) CPP_OBJS= \ .\$(OBJDIR)\GenerateIDFunctionCall.obj \ .\$(OBJDIR)\DocumentFunctionCall.obj \ + .\$(OBJDIR)\SystemPropertyFunctionCall.obj \ + .\$(OBJDIR)\CurrentFunctionCall.obj \ $(NULL) EXPORTS = \ $(NULL) -LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I..\..\base -I..\..\xml\dom \ +LINCS= $(LINCS) -I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I..\..\base -I..\..\xml\dom \ -I..\..\xpath -I..\..\xml -I..\ -I..\..\xml\util \ - -I..\..\net -I..\..\xml\parser + -I..\..\net -I$(DEPTH)\expat -I..\..\xml\parser LCFLAGS = \ $(LCFLAGS) \ diff --git a/extensions/transformiix/source/xslt/makefile.win b/extensions/transformiix/source/xslt/makefile.win index 596b3558ace1..4f2595b963be 100644 --- a/extensions/transformiix/source/xslt/makefile.win +++ b/extensions/transformiix/source/xslt/makefile.win @@ -24,7 +24,7 @@ DEPTH=..\..\..\.. DIRS=util functions !if defined(MOZ_XSL) -DEFINES=-DMOZ_XSL +DEFINES= $(DEFINES) -DMOZ_XSL !endif CPPSRCS= \ @@ -48,8 +48,13 @@ CPP_OBJS= \ EXPORTS = \ $(NULL) +!ifdef MOZ_XSL LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I..\xpath -I..\xml\dom -I..\xml\dom\mozImpl \ -I..\base -I ..\xml -I ..\xml\util -I .\util -I ..\net -I..\xml\parser -I.\functions +!else +LINCS=-I. -I..\base -I..\net -I..\xml -I..\xml\dom -I..\xml\util -I..\xml\parser \ + -I..\xml\parser\xmlparse -I..\xml\printer -I..\xpath -Iutil -Ifunctions +!endif LCFLAGS = \ $(LCFLAGS) \ diff --git a/extensions/transformiix/source/xslt/util/NodeStack.cpp b/extensions/transformiix/source/xslt/util/NodeStack.cpp index ff7a86afb721..ec4171466822 100644 --- a/extensions/transformiix/source/xslt/util/NodeStack.cpp +++ b/extensions/transformiix/source/xslt/util/NodeStack.cpp @@ -24,15 +24,17 @@ * Larry Fitzpatrick, OpenText, lef@opentext.com * -- moved initialization of DEFAULT_SIZE from NodeStack.h to here * - * $Id: NodeStack.cpp,v 1.1 2000/04/06 07:47:41 kvisco%ziplink.net Exp $ + * $Id: NodeStack.cpp,v 1.2 2001/01/12 20:06:48 axel%pike.org Exp $ */ #include "NodeStack.h" +#ifndef MOZ_XSL #include +#endif /** * @author Keith Visco - * @version $Revision: 1.1 $ $Date: 2000/04/06 07:47:41 $ + * @version $Revision: 1.2 $ $Date: 2001/01/12 20:06:48 $ **/