From 7934bfa1f63b2cd36696871ee41d37fdd67cba2b Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Sun, 22 Aug 1999 00:33:51 +0000 Subject: [PATCH] updating DOM Viewer - start creating DOM elements using the PROGID system for creating elements git-svn-id: svn://10.0.0.236/trunk@44031 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/rdf/tests/domds/Makefile.in | 6 +- mozilla/rdf/tests/domds/nsIDOMDataSource.idl | 5 -- .../rdf/tests/domds/nsIDOMViewerElement.idl | 13 +++ .../rdf/tests/domds/nsRDFDOMDataSource.cpp | 4 +- .../tests/domds/nsRDFDOMDataSourceFactory.cpp | 17 +++- .../tests/domds/nsRDFDOMResourceFactory.cpp | 88 +++++++++++++++++++ .../rdf/tests/domds/nsRDFDOMResourceFactory.h | 37 ++++++++ 7 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 mozilla/rdf/tests/domds/nsIDOMViewerElement.idl create mode 100644 mozilla/rdf/tests/domds/nsRDFDOMResourceFactory.cpp create mode 100644 mozilla/rdf/tests/domds/nsRDFDOMResourceFactory.h diff --git a/mozilla/rdf/tests/domds/Makefile.in b/mozilla/rdf/tests/domds/Makefile.in index 8d98397ed56..b2447e45f9e 100644 --- a/mozilla/rdf/tests/domds/Makefile.in +++ b/mozilla/rdf/tests/domds/Makefile.in @@ -27,11 +27,15 @@ LIBRARY_NAME=rdfdomds IS_COMPONENT=1 DIRS = resources -XPIDLSRCS = nsIDOMDataSource.idl +XPIDLSRCS = \ + nsIDOMDataSource.idl \ + nsIDOMViewerElement.idl \ + $(NULL) CPPSRCS = \ nsRDFDOMDataSource.cpp \ nsRDFDOMDataSourceFactory.cpp \ + nsRDFDOMResourceFactory.cpp \ $(NULL) EXTRA_DSO_LDOPTS += \ diff --git a/mozilla/rdf/tests/domds/nsIDOMDataSource.idl b/mozilla/rdf/tests/domds/nsIDOMDataSource.idl index c703a29c09f..597b0c4f148 100644 --- a/mozilla/rdf/tests/domds/nsIDOMDataSource.idl +++ b/mozilla/rdf/tests/domds/nsIDOMDataSource.idl @@ -31,8 +31,3 @@ interface nsIDOMDataSource : nsISupports { void SetWindow(in nsIDOMWindow window); }; -[scriptable, uuid(2842a0ba-4bd8-11d3-ac84-00a0c900d445)] -interface nsIDOMViewerElement : nsISupports { - attribute nsIDOMNode node; -}; - diff --git a/mozilla/rdf/tests/domds/nsIDOMViewerElement.idl b/mozilla/rdf/tests/domds/nsIDOMViewerElement.idl new file mode 100644 index 00000000000..bd385844d6c --- /dev/null +++ b/mozilla/rdf/tests/domds/nsIDOMViewerElement.idl @@ -0,0 +1,13 @@ + +#include "nsISupports.idl" +#include "domstubs.idl" +%{C++ +#include "nsIDOMNode.h" +%} + + +[scriptable, uuid(2842a0ba-4bd8-11d3-ac84-00a0c900d445)] +interface nsIDOMViewerElement : nsISupports { + attribute nsIDOMNode node; +}; + diff --git a/mozilla/rdf/tests/domds/nsRDFDOMDataSource.cpp b/mozilla/rdf/tests/domds/nsRDFDOMDataSource.cpp index d94ecbd9d6b..8c1f477b4b9 100644 --- a/mozilla/rdf/tests/domds/nsRDFDOMDataSource.cpp +++ b/mozilla/rdf/tests/domds/nsRDFDOMDataSource.cpp @@ -639,13 +639,13 @@ nsRDFDOMDataSource::getURIForNode(nsIDOMNode *node, char **uri) char *idstr = PR_smprintf("%8.8X", gCurrentId++); id = idstr; printf("Element has no ID. Assigning it %s\n", idstr); + - element->SetAttribute(nsAutoString("id"), id); } else { printf("ID of this element is %s\n", id.ToNewCString()); } - + // leaks id.ToNewCString() *uri = PR_smprintf("dom://%s", id.ToNewCString()); } diff --git a/mozilla/rdf/tests/domds/nsRDFDOMDataSourceFactory.cpp b/mozilla/rdf/tests/domds/nsRDFDOMDataSourceFactory.cpp index 78798e9bafb..2f848af66d7 100644 --- a/mozilla/rdf/tests/domds/nsRDFDOMDataSourceFactory.cpp +++ b/mozilla/rdf/tests/domds/nsRDFDOMDataSourceFactory.cpp @@ -18,6 +18,7 @@ #include "nsIGenericFactory.h" #include "nsRDFDOMDataSource.h" +#include "nsRDFDOMResourceFactory.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "rdf.h" @@ -26,7 +27,8 @@ #include #endif -static NS_DEFINE_CID(kRDFDataSourceCID, NS_RDF_DOMDATASOURCE_CID); +static NS_DEFINE_CID(kRDFDOMDataSourceCID, NS_RDF_DOMDATASOURCE_CID); +static NS_DEFINE_CID(kRDFDOMResourceFactoryCID, NS_RDF_DOMRESOURCEFACTORY_CID); static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); nsresult @@ -38,8 +40,10 @@ NSGetFactory(nsISupports* aServMgr, { nsresult rv=NS_OK; nsIGenericFactory* fact; - if (aClass.Equals(kRDFDataSourceCID)) + if (aClass.Equals(kRDFDOMDataSourceCID)) rv = NS_NewGenericFactory(&fact, NS_NewRDFDOMDataSource); + if (aClass.Equals(kRDFDOMDataSourceCID)) + rv = NS_NewGenericFactory(&fact, NS_NewRDFDOMResourceFactory); else rv = NS_ERROR_FAILURE; @@ -64,11 +68,15 @@ NSRegisterSelf(nsISupports* aServMgr, const char* aPath) if (NS_FAILED(rv)) return rv; - rv = compMgr->RegisterComponent(kRDFDataSourceCID, + rv = compMgr->RegisterComponent(kRDFDOMDataSourceCID, "Generic DataSource DataSource", NS_RDF_DATASOURCE_PROGID_PREFIX "domds", aPath, PR_TRUE, PR_TRUE); + rv = compMgr->RegisterComponent(kRDFDOMResourceFactoryCID, + "DOM element resource factory", + NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX "dom", + aPath, PR_TRUE, PR_TRUE); return rv; } @@ -81,7 +89,8 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath) aServMgr, kComponentManagerCID, &rv); if (NS_FAILED(rv)) return rv; - rv = compMgr->UnregisterComponent(kRDFDataSourceCID, aPath); + rv = compMgr->UnregisterComponent(kRDFDOMDataSourceCID, aPath); + rv = compMgr->UnregisterComponent(kRDFDOMResourceFactoryCID, aPath); return rv; } diff --git a/mozilla/rdf/tests/domds/nsRDFDOMResourceFactory.cpp b/mozilla/rdf/tests/domds/nsRDFDOMResourceFactory.cpp new file mode 100644 index 00000000000..7db848c06bb --- /dev/null +++ b/mozilla/rdf/tests/domds/nsRDFDOMResourceFactory.cpp @@ -0,0 +1,88 @@ +/* -*- 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 Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + */ + +#include "nscore.h" +#include "nsCOMPtr.h" + +#include "rdf.h" +#include "nsRDFResource.h" +#include "nsRDFDOMResourceFactory.h" +#include "nsIDOMViewerElement.h" +#include "nsIDOMNode.h" + +class nsRDFDOMViewerElement : nsRDFResource, + nsIDOMViewerElement { +public: + nsRDFDOMViewerElement(); + virtual ~nsRDFDOMViewerElement(); + + NS_DECL_ISUPPORTS_INHERITED + + NS_DECL_NSIDOMVIEWERELEMENT + +private: + + nsIDOMNode *mNode; + + +}; + +nsRDFDOMViewerElement::nsRDFDOMViewerElement() : + mNode(nsnull) +{ + +} + +nsRDFDOMViewerElement::~nsRDFDOMViewerElement() +{ + if (mNode) NS_RELEASE(mNode); +} + +NS_IMPL_ISUPPORTS_INHERITED(nsRDFDOMViewerElement, nsRDFResource, nsIDOMViewerElement) + +NS_IMETHODIMP +nsRDFDOMViewerElement::SetNode(nsIDOMNode* node) +{ + if (mNode) NS_RELEASE(mNode); + mNode = node; + NS_ADDREF(mNode); + return NS_OK; +} + +NS_IMETHODIMP +nsRDFDOMViewerElement::GetNode(nsIDOMNode** node) +{ + if (!node) return NS_ERROR_NULL_POINTER; + + *node = mNode; + NS_ADDREF(*node); + return NS_OK; +} + +nsresult +NS_NewRDFDOMResourceFactory(nsISupports* aOuter, + const nsIID& iid, + void **result) { + + nsRDFDOMViewerElement* ve = new nsRDFDOMViewerElement(); + if (!ve) return NS_ERROR_NULL_POINTER; + return ve->QueryInterface(iid, result); +} + diff --git a/mozilla/rdf/tests/domds/nsRDFDOMResourceFactory.h b/mozilla/rdf/tests/domds/nsRDFDOMResourceFactory.h new file mode 100644 index 00000000000..1f3d09a390a --- /dev/null +++ b/mozilla/rdf/tests/domds/nsRDFDOMResourceFactory.h @@ -0,0 +1,37 @@ +/* -*- 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 Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + */ + +#ifndef __nsRDFDOMResourceFactory_h +#define __nsRDFDOMResourceFactory_h + +#include "nsIRDFService.h" + +/* {84a87046-57f4-11d3-9061-00a0c900d445} */ +#define NS_RDF_DOMRESOURCEFACTORY_CID \ + {0x84a87046, 0x57f4, 0x11d3, \ + { 0x90, 0x61, 0x0, 0xa0, 0xc9, 0x0, 0xd4, 0x45 }} + + +nsresult +NS_NewRDFDOMResourceFactory(nsISupports* aOuter, + const nsIID& iid, + void **result); + +#endif