not part of build, code by axel@pike.org, r=peterv; code by peterv@netscape.com, r=me. Fixing 59937, xpath function lib complete, 59649, 60059, 47720; building windows standalone, 46640; general code cleanup, fixing warnings; XPathProcessor and XSLTProcessor available to JS (work in progress)

This commit is contained in:
axel%pike.org 2001-01-12 20:06:48 +00:00
Родитель f46626eb26
Коммит bcbac73b27
75 изменённых файлов: 2597 добавлений и 256 удалений

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

@ -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<nsIDOMLoadListener> listener = do_QueryReferent(mParent);
if (listener) {
return listener->HandleEvent(aEvent);
}
return NS_OK;
}
nsresult
nsLoadListenerProxy::Load(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener = do_QueryReferent(mParent);
if (listener) {
return listener->Load(aEvent);
}
return NS_OK;
}
nsresult
nsLoadListenerProxy::Unload(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener = do_QueryReferent(mParent);
if (listener) {
return listener->Unload(aEvent);
}
return NS_OK;
}
nsresult
nsLoadListenerProxy::Abort(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener = do_QueryReferent(mParent);
if (listener) {
return listener->Abort(aEvent);
}
return NS_OK;
}
nsresult
nsLoadListenerProxy::Error(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> 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<nsILoadGroup> 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<nsIChannel> channel;
rv = NS_OpenURI(getter_AddRefs(channel), documentURI, nsnull, loadGroup);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStream> postDataStream;
// Make sure we've been opened
if (!channel) {
return NS_ERROR_NOT_INITIALIZED;
}
// Get and initialize a DOMImplementation
nsCOMPtr<nsIDOMDOMImplementation> implementation = do_CreateInstance(kIDOMDOMImplementationCID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
//if (mBaseURI) {
// nsCOMPtr<nsIPrivateDOMImplementation> privImpl = do_QueryInterface(implementation);
// if (privImpl) {
// privImpl->Init(mBaseURI);
// }
//}
// Create an empty document from it
nsAutoString emptyStr;
nsCOMPtr<nsIDOMDocument> 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<nsIDOMEventReceiver> 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<nsIStreamListener> listener;
nsCOMPtr<nsIDocument> document = do_QueryInterface(DOMDocument);
if (!document) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIEventQueue> modalEventQueue;
nsCOMPtr<nsIEventQueueService> eventQService;
nsCOMPtr<nsIXPCNativeCallContext> 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<nsIDOMWindowInternal> 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<nsIScriptGlobalObject> global;
global = dont_AddRef(scriptCX->GetGlobalObject());
if (!global) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocShell> docshell;
rv = global->GetDocShell(getter_AddRefs(docshell));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocShellTreeItem> 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;
}

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

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

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

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

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

@ -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<nsIScriptNameSpaceManager> 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<nsIScriptNameSetRegistry> 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**)&registry);
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)

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

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

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

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

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

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

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

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

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

@ -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"
%}

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

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

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

@ -29,7 +29,9 @@
// Who When What
#include "HashTable.h"
#ifndef MOZ_XSL
#include <iostream.h>
#endif
HashTable::HashTable()
{

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

@ -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 <iostream.h>
#endif
//--------------------------/
//- Implementation of List -/
@ -36,7 +38,7 @@
/**
* Default constructor for a List;
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.4 $ $Date: 2000/05/29 07:14:03 $
* @version $Revision: 1.5 $ $Date: 2001/01/12 20:06:08 $
**/
List::List() {

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

@ -35,7 +35,9 @@
#include <stdlib.h>
#include <string.h>
#include "TxString.h"
#ifndef MOZ_XSL
#include <iostream.h>
#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
{

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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 <iostream.h>
#endif
#include "StringList.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

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

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

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

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

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

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

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

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

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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<nsIURI> 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<nsIURI> 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

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

@ -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 <iostream.h>
#ifndef MOZ_XSL
#include <fstream.h>
#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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.9 $ $Date: 2000/08/27 17:24:04 $
* @version $Revision: 1.10 $ $Date: 2001/01/12 20:06:13 $
*
**/

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

@ -22,7 +22,7 @@
DEPTH=..\..\..\..
!if defined(MOZ_XSL)
DEFINES=-DMOZ_XSL
DEFINES= $(DEFINES) -DMOZ_XSL
!endif
CPPSRCS= \

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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))

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

@ -21,6 +21,10 @@
DEPTH=..\..\..\..\..
DIRS=mozImpl
!ifdef MOZ_XSL
DIRS = mozImpl
!else
DIRS = standalone
!endif
include <$(DEPTH)\config\rules.mak>

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

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

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

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

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

@ -89,7 +89,7 @@ Node* NamedNodeMap::setNamedItem(Node* aNode)
{
nsCOMPtr<nsIDOMNode> node;
if (NS_SUCCEEDED(nsNamedNodeMap->SetNamedItem(aNode->getNSObj(),
if (NS_SUCCEEDED(nsNamedNodeMap->SetNamedItem(aNode->getNSNode(),
getter_AddRefs(node))))
return ownerDocument->createWrapper(node);
else

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

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

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

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

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

@ -21,7 +21,9 @@
DEPTH=..\..\..\..\..\..
DEFINES=-DMOZ_XSL
!ifdef MOZ_XSL
DEFINES=$(DEFINES) -DMOZ_XSL
!endif
CPPSRCS= \
MozillaAttr.cpp \

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -25,6 +25,8 @@ DIRS=dom parser util
!if defined(MOZ_XSL)
DEFINES=$(DEFINES) -DMOZ_XSL
!else
DIRS = $(DIRS) printer
!endif
CPPSRCS= \

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

@ -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<nsIURI> 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;
nsCOMPtr<nsISyncLoader>aLoader = do_CreateInstance( TRANSFORMIIX_SYNCLOADER_CONTRACTID, &rv );
if (NS_FAILED(rv)) return NULL;
nsCOMPtr <nsIDocument> theDocument;
aLoader->LoadDocument(documentURI, getter_AddRefs(theDocument));
nsCOMPtr<nsIDOMDocument> 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;

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

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

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

@ -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<nsIDOMLoadListener> listener = do_QueryReferent(mParent);
if (listener) {
return listener->HandleEvent(aEvent);
}
return NS_OK;
}
nsresult
nsLoadListenerProxy::Load(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener = do_QueryReferent(mParent);
if (listener) {
return listener->Load(aEvent);
}
return NS_OK;
}
nsresult
nsLoadListenerProxy::Unload(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener = do_QueryReferent(mParent);
if (listener) {
return listener->Unload(aEvent);
}
return NS_OK;
}
nsresult
nsLoadListenerProxy::Abort(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener = do_QueryReferent(mParent);
if (listener) {
return listener->Abort(aEvent);
}
return NS_OK;
}
nsresult
nsLoadListenerProxy::Error(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> 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<nsILoadGroup> 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<nsIChannel> channel;
rv = NS_OpenURI(getter_AddRefs(channel), documentURI, nsnull, loadGroup);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStream> postDataStream;
// Make sure we've been opened
if (!channel) {
return NS_ERROR_NOT_INITIALIZED;
}
// Get and initialize a DOMImplementation
nsCOMPtr<nsIDOMDOMImplementation> implementation = do_CreateInstance(kIDOMDOMImplementationCID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
//if (mBaseURI) {
// nsCOMPtr<nsIPrivateDOMImplementation> privImpl = do_QueryInterface(implementation);
// if (privImpl) {
// privImpl->Init(mBaseURI);
// }
//}
// Create an empty document from it
nsAutoString emptyStr;
nsCOMPtr<nsIDOMDocument> 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<nsIDOMEventReceiver> 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<nsIStreamListener> listener;
nsCOMPtr<nsIDocument> document = do_QueryInterface(DOMDocument);
if (!document) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIEventQueue> modalEventQueue;
nsCOMPtr<nsIEventQueueService> eventQService;
nsCOMPtr<nsIXPCNativeCallContext> 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<nsIDOMWindowInternal> 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<nsIScriptGlobalObject> global;
global = dont_AddRef(scriptCX->GetGlobalObject());
if (!global) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocShell> docshell;
rv = global->GetDocShell(getter_AddRefs(docshell));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocShellTreeItem> 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;
}

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

@ -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<nsIDocShellTreeOwner> mDocShellTreeOwner;
};
#endif

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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 {

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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);
}

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

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

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.9 $ $Date: 2001/01/09 20:56:28 $
* @version $Revision: 1.10 $ $Date: 2001/01/12 20:06:31 $
**/
#include <iostream.h>
#include "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 <iostream.h>
#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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.3 $ $Date: 2000/04/13 18:30:00 $
* @version $Revision: 1.4 $ $Date: 2001/01/12 20:06:32 $
**/
class Token {

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

@ -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 <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @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);
}

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

@ -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 <A href="mailto:kvisco@ziplink.net">Keith Visco</A>
* @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 <iostream.h>
#endif
class ExprParser {

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

@ -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 @@
* <BR/>
* Note: for NodeSet, see NodeSet.h <BR />
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @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.

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

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

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

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

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

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

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

@ -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 <iostream.h>
#else
#include "nsDOMCID.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsIScriptGlobalObject.h"
#include "nsIServiceManager.h"
#endif
/**
* NodeSet <BR />
* This class was ported from XSL:P. <BR />
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @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

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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;

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

@ -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 <A HREF="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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; i<lNList->size(); 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; end<lIDList.length(); end++){
cc = lIDList.charAt(end);
isSpace = (cc==' ' || cc=='\n' || cc=='\t'|| cc=='\r');
if (isSpace && !hasSpace){
hasSpace = MB_TRUE;
lIDList.subString(start, end, thisID);
resultSet->add(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);

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

@ -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; i<lNList->size(); 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) ) {

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

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

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

@ -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 <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @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; src<resultStr.length(); src++) {
current=resultStr.charAt(src);
if (current==' ' || current=='\n' ||
current=='\t' || current=='\r') {
if (!hasSpace) {
normed.replace(dest,' ');
dest++;
hasSpace=MB_TRUE;
}
}
else {
normed.replace(dest,current);
dest++;
hasSpace=MB_FALSE;
}
}
result = new StringResult(normed);
}
else result = new StringResult("");
break;
case STARTS_WITH :
if ( requireParams(2, 2, cs) ) {
String arg1, arg2;
@ -142,20 +175,33 @@ ExprResult* StringFunctionCall::evaluate(Node* context, ContextState* cs) {
break;
}
Int32 startIdx = (Int32)ceil(dbl);
Int32 endIdx = src.length();
//-- check for -Infinity
MBool startsNegInf = (dbl==Double::NEGATIVE_INFINITY);
Int32 startIdx = startsNegInf?0:(Int32)floor(dbl+.5);
Int32 endIdx = src.length()+1;
if ( argc == 3) {
dbl += evaluateToNumber((Expr*)iter->next(),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]);

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

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

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

@ -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 <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @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);

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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+

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

@ -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<nsIDOMDocument> aOwnerDOMDocument;
aContextNode->GetOwnerDocument(getter_AddRefs(aOwnerDOMDocument));
nsCOMPtr<nsIDocument> 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;
}

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

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

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

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

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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 = "*";

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

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

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

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

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

@ -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 <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @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<nsIObserverService> 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);
}
}

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

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

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

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

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

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

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

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

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

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

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

@ -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 <iostream.h>
#endif
/**
* @author <a href="kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.1 $ $Date: 2000/04/06 07:47:41 $
* @version $Revision: 1.2 $ $Date: 2001/01/12 20:06:48 $
**/