Bug 15460. Expose XML element creation via nsIXMLElementFactory interface. r=kipp.

This commit is contained in:
waterson%netscape.com 1999-10-05 00:12:21 +00:00
Родитель eccb08e095
Коммит 24e09d82e2
12 изменённых файлов: 208 добавлений и 0 удалений

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

@ -1,2 +1,3 @@
nsIXMLContentSink.h nsIXMLContentSink.h
nsIXMLDocument.h nsIXMLDocument.h
nsIXMLElementFactory.h

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

@ -27,6 +27,7 @@ MODULE = layout
EXPORTS = \ EXPORTS = \
nsIXMLContentSink.h \ nsIXMLContentSink.h \
nsIXMLDocument.h \ nsIXMLDocument.h \
nsIXMLElementFactory.h \
$(NULL) $(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

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

@ -20,6 +20,7 @@ DEPTH=..\..\..\..
EXPORTS = \ EXPORTS = \
nsIXMLContentSink.h \ nsIXMLContentSink.h \
nsIXMLDocument.h \ nsIXMLDocument.h \
nsIXMLElementFactory.h \
$(NULL) $(NULL)
MODULE=raptor MODULE=raptor

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

@ -18,6 +18,7 @@
*/ */
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsXMLContentSink.h" #include "nsXMLContentSink.h"
#include "nsIXMLElementFactory.h"
#include "nsIParser.h" #include "nsIParser.h"
#include "nsIUnicharInputStream.h" #include "nsIUnicharInputStream.h"
#include "nsIUnicharStreamLoader.h" #include "nsIUnicharStreamLoader.h"
@ -1881,3 +1882,71 @@ nsXMLContentSink::RefreshIfEnabled(nsIViewManager* vm)
} }
return NS_OK; return NS_OK;
} }
////////////////////////////////////////////////////////////////////////
//
// XML Element Factory
//
class XMLElementFactoryImpl : public nsIXMLElementFactory
{
protected:
XMLElementFactoryImpl();
virtual ~XMLElementFactoryImpl();
public:
friend
nsresult
NS_NewXMLElementFactory(nsIXMLElementFactory** aResult);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIXMLElementFactory interface
NS_IMETHOD CreateInstanceByTag(const nsString& aTag, nsIXMLContent** aResult);
};
XMLElementFactoryImpl::XMLElementFactoryImpl()
{
NS_INIT_REFCNT();
}
XMLElementFactoryImpl::~XMLElementFactoryImpl()
{
}
NS_IMPL_ISUPPORTS(XMLElementFactoryImpl, NS_GET_IID(nsIXMLElementFactory));
nsresult
NS_NewXMLElementFactory(nsIXMLElementFactory** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
XMLElementFactoryImpl* result = new XMLElementFactoryImpl();
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aResult = result;
return NS_OK;
}
NS_IMETHODIMP
XMLElementFactoryImpl::CreateInstanceByTag(const nsString& aTag, nsIXMLContent** aResult)
{
nsCOMPtr<nsIAtom> tag = dont_AddRef(NS_NewAtom(aTag));
if (! tag)
return NS_ERROR_OUT_OF_MEMORY;
return NS_NewXMLElement(aResult, tag);
}

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

@ -45,6 +45,11 @@
0xa6cf9063, 0x15b3, 0x11d2, \ 0xa6cf9063, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
#define NS_XML_ELEMENT_FACTORY_CID \
{ /* CF170391-79CC-11d3-BE44-0020A6361667 */ \
0xcf170391, 0x79cc, 0x11d3, \
{0xbe, 0x44, 0x0, 0x20, 0xa6, 0x36, 0x16, 0x67}}
#define NS_IMAGEDOCUMENT_CID \ #define NS_IMAGEDOCUMENT_CID \
{ /* e11a6080-4daa-11d2-b328-00805f8a3859 */ \ { /* e11a6080-4daa-11d2-b328-00805f8a3859 */ \
0xe11a6080, 0x4daa, 0x11d2, \ 0xe11a6080, 0x4daa, 0x11d2, \

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

@ -45,6 +45,7 @@
#include "nsIEventListenerManager.h" #include "nsIEventListenerManager.h"
#include "nsILayoutDebugger.h" #include "nsILayoutDebugger.h"
#include "nsIHTMLElementFactory.h" #include "nsIHTMLElementFactory.h"
#include "nsIXMLElementFactory.h"
#include "nsIDocumentEncoder.h" #include "nsIDocumentEncoder.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIFrameSelection.h" #include "nsIFrameSelection.h"
@ -55,6 +56,7 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID); static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID); static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
static NS_DEFINE_CID(kXMLElementFactoryCID, NS_XML_ELEMENT_FACTORY_CID);
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID); static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
static NS_DEFINE_IID(kCSSParserCID, NS_CSSPARSER_CID); static NS_DEFINE_IID(kCSSParserCID, NS_CSSPARSER_CID);
static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID); static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID);
@ -364,6 +366,14 @@ nsLayoutFactory::CreateInstance(nsISupports *aOuter,
} }
refCounted = PR_TRUE; refCounted = PR_TRUE;
} }
else if (mClassID.Equals(kXMLElementFactoryCID)) {
res = NS_NewXMLElementFactory((nsIXMLElementFactory**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXMLElementFactory", res);
return res;
}
refCounted = PR_TRUE;
}
else if (mClassID.Equals(kTextEncoderCID)) { else if (mClassID.Equals(kTextEncoderCID)) {
res = NS_NewTextEncoder((nsIDocumentEncoder**) &inst); res = NS_NewTextEncoder((nsIDocumentEncoder**) &inst);
if (NS_FAILED(res)) { if (NS_FAILED(res)) {

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

@ -313,6 +313,8 @@ static Components gComponents[] = {
{ "HTML element factory", NS_HTML_ELEMENT_FACTORY_CID, nsnull, }, { "HTML element factory", NS_HTML_ELEMENT_FACTORY_CID, nsnull, },
{ "Text element", NS_TEXTNODE_CID, nsnull, }, { "Text element", NS_TEXTNODE_CID, nsnull, },
{ "XML element factory", NS_XML_ELEMENT_FACTORY_CID, nsnull, },
{ "Selection", NS_SELECTION_CID, nsnull, }, { "Selection", NS_SELECTION_CID, nsnull, },
{ "Frame selection", NS_FRAMESELECTION_CID, nsnull, }, { "Frame selection", NS_FRAMESELECTION_CID, nsnull, },
{ "Range", NS_RANGE_CID, nsnull, }, { "Range", NS_RANGE_CID, nsnull, },

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

@ -1,2 +1,3 @@
nsIXMLContentSink.h nsIXMLContentSink.h
nsIXMLDocument.h nsIXMLDocument.h
nsIXMLElementFactory.h

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

@ -27,6 +27,7 @@ MODULE = layout
EXPORTS = \ EXPORTS = \
nsIXMLContentSink.h \ nsIXMLContentSink.h \
nsIXMLDocument.h \ nsIXMLDocument.h \
nsIXMLElementFactory.h \
$(NULL) $(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

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

@ -20,6 +20,7 @@ DEPTH=..\..\..\..
EXPORTS = \ EXPORTS = \
nsIXMLContentSink.h \ nsIXMLContentSink.h \
nsIXMLDocument.h \ nsIXMLDocument.h \
nsIXMLElementFactory.h \
$(NULL) $(NULL)
MODULE=raptor MODULE=raptor

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

@ -0,0 +1,47 @@
/* -*- 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.0 (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.
*
* 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.
*/
#ifndef nsIXMLElementFactory_h___
#define nsIXMLElementFactory_h___
#include "nslayout.h"
#include "nsISupports.h"
class nsIXMLContent;
class nsString;
// {CF170390-79CC-11d3-BE44-0020A6361667}
#define NS_IXML_ELEMENT_FACTORY_IID \
{ 0xcf170390, 0x79cc, 0x11d3, { 0xbe, 0x44, 0x0, 0x20, 0xa6, 0x36, 0x16, 0x67 } };
/**
* An API for creating XML content objects
*/
class nsIXMLElementFactory : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IXML_ELEMENT_FACTORY_IID; return iid; }
NS_IMETHOD CreateInstanceByTag(const nsString& aTag,
nsIXMLContent** aResult) = 0;
};
extern nsresult
NS_NewXMLElementFactory(nsIXMLElementFactory** aResult);
#endif /* nsIXMLElementFactory_h___ */

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

@ -18,6 +18,7 @@
*/ */
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsXMLContentSink.h" #include "nsXMLContentSink.h"
#include "nsIXMLElementFactory.h"
#include "nsIParser.h" #include "nsIParser.h"
#include "nsIUnicharInputStream.h" #include "nsIUnicharInputStream.h"
#include "nsIUnicharStreamLoader.h" #include "nsIUnicharStreamLoader.h"
@ -1881,3 +1882,71 @@ nsXMLContentSink::RefreshIfEnabled(nsIViewManager* vm)
} }
return NS_OK; return NS_OK;
} }
////////////////////////////////////////////////////////////////////////
//
// XML Element Factory
//
class XMLElementFactoryImpl : public nsIXMLElementFactory
{
protected:
XMLElementFactoryImpl();
virtual ~XMLElementFactoryImpl();
public:
friend
nsresult
NS_NewXMLElementFactory(nsIXMLElementFactory** aResult);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIXMLElementFactory interface
NS_IMETHOD CreateInstanceByTag(const nsString& aTag, nsIXMLContent** aResult);
};
XMLElementFactoryImpl::XMLElementFactoryImpl()
{
NS_INIT_REFCNT();
}
XMLElementFactoryImpl::~XMLElementFactoryImpl()
{
}
NS_IMPL_ISUPPORTS(XMLElementFactoryImpl, NS_GET_IID(nsIXMLElementFactory));
nsresult
NS_NewXMLElementFactory(nsIXMLElementFactory** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
XMLElementFactoryImpl* result = new XMLElementFactoryImpl();
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aResult = result;
return NS_OK;
}
NS_IMETHODIMP
XMLElementFactoryImpl::CreateInstanceByTag(const nsString& aTag, nsIXMLContent** aResult)
{
nsCOMPtr<nsIAtom> tag = dont_AddRef(NS_NewAtom(aTag));
if (! tag)
return NS_ERROR_OUT_OF_MEMORY;
return NS_NewXMLElement(aResult, tag);
}