Adding files for Load/Save. Not part of build.

This commit is contained in:
bzbarsky%mit.edu 2002-08-16 02:05:22 +00:00
parent ec70db0d68
commit 12ba3fc7f0
5 changed files with 627 additions and 0 deletions

View File

@ -0,0 +1,190 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Communiactions Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Boris Zbarsky <bzbarsky@mit.edu> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsDOMBuilder.h"
#include "nsDOMError.h"
#include "nsContentUtils.h" // for NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO
#include "nsIDOMDocument.h"
static const char* kLoadAsData = "loadAsData";
nsresult
NS_NewDOMBuilder(nsIDOMDOMBuilder** aResult,
PRUint16 aMode,
const nsAString & aSchemaType,
nsIDOMDOMImplementation* aDOMImplementation)
{
NS_PRECONDITION(aResult, "Null out ptr? Who do you think you are, flouting XPCOM contract?");
NS_PRECONDITION(aDOMImplementation, "How are we supposed to create documents without a DOMImplementation?");
nsDOMBuilder* it = new nsDOMBuilder(aMode, aSchemaType, aDOMImplementation);
if (!it)
return NS_ERROR_OUT_OF_MEMORY;
return CallQueryInterface(it, aResult);
}
nsDOMBuilder::nsDOMBuilder(PRUint16 aMode,
const nsAString& aSchemaType,
nsIDOMDOMImplementation* aDOMImplementation)
{
NS_INIT_REFCNT();
mDOMImplementation = aDOMImplementation;
}
nsDOMBuilder::~nsDOMBuilder()
{
}
NS_IMPL_ADDREF(nsDOMBuilder)
NS_IMPL_RELEASE(nsDOMBuilder)
NS_INTERFACE_MAP_BEGIN(nsDOMBuilder)
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMBuilder)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDOMBuilder)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(DOMBuilder)
NS_INTERFACE_MAP_END
// nsIDOMDOMBuilder
NS_IMETHODIMP
nsDOMBuilder::GetEntityResolver(nsIDOMDOMEntityResolver** aEntityResolver)
{
*aEntityResolver = mEntityResolver;
NS_IF_ADDREF(*aEntityResolver);
return NS_OK;
}
NS_IMETHODIMP
nsDOMBuilder::SetEntityResolver(nsIDOMDOMEntityResolver* aEntityResolver)
{
mEntityResolver = aEntityResolver;
return NS_OK;
}
NS_IMETHODIMP
nsDOMBuilder::GetErrorHandler(nsIDOMDOMErrorHandler** aErrorHandler)
{
*aErrorHandler = mErrorHandler;
NS_IF_ADDREF(*aErrorHandler);
return NS_OK;
}
NS_IMETHODIMP
nsDOMBuilder::SetErrorHandler(nsIDOMDOMErrorHandler* aErrorHandler)
{
mErrorHandler = aErrorHandler;
return NS_OK;
}
NS_IMETHODIMP
nsDOMBuilder::GetFilter(nsIDOMDOMBuilderFilter** aFilter)
{
*aFilter = mFilter;
NS_IF_ADDREF(*aFilter);
return NS_OK;
}
NS_IMETHODIMP
nsDOMBuilder::SetFilter(nsIDOMDOMBuilderFilter* aFilter)
{
mFilter = aFilter;
return NS_OK;
}
NS_IMETHODIMP
nsDOMBuilder::SetFeature(const nsAString& aName, PRBool aState)
{
// XXX We don't know about any features yet
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_IMETHODIMP
nsDOMBuilder::CanSetFeature(const nsAString& aName, PRBool aState,
PRBool* aCanSet)
{
// XXX We can't set anything
*aCanSet = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsDOMBuilder::GetFeature(const nsAString& aName, PRBool* aIsOn)
{
// XXX We don't know about any features yet
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_IMETHODIMP
nsDOMBuilder::ParseURI(const nsAString& aURI, nsIDOMDocument** aDocument)
{
*aDocument = nsnull;
nsCOMPtr<nsIDOMDocument> domDoc;
NS_NAMED_LITERAL_STRING(emptyStr, "");
mDOMImplementation->CreateDocument(emptyStr,
emptyStr,
nsnull,
getter_AddRefs(domDoc));
if (!domDoc)
return NS_ERROR_FAILURE;
// XXX synchronous loading? We'd have to do something right about now.
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDOMBuilder::Parse(nsIDOMDOMInputSource* aInputSource,
nsIDOMDocument** aDocument)
{
*aDocument = nsnull;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDOMBuilder::ParseWithContext(nsIDOMDOMInputSource* aInputSource,
nsIDOMNode* aContextNode,
PRUint16 aAction)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Communiactions Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Boris Zbarsky <bzbarsky@mit.edu> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDOMBuilder_h__
#define nsDOMBuilder_h__
#include "nsIDOMDOMBuilder.h"
#include "nsIDOMDOMEntityResolver.h"
#include "nsIDOMDOMErrorHandler.h"
#include "nsIDOMDOMBuilderFilter.h"
#include "nsIDOMDOMImplementation.h"
#include "nsCOMPtr.h"
/**
* This class implements the DOMBuilder from DOM3 Load/Save
*/
class nsDOMBuilder : public nsIDOMDOMBuilder
{
public:
nsDOMBuilder(PRUint16 aMode, const nsAString& aSchemaType,
nsIDOMDOMImplementation* aDOMImplementation);
virtual ~nsDOMBuilder();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMDOMBUILDER
private:
nsCOMPtr<nsIDOMDOMEntityResolver> mEntityResolver;
nsCOMPtr<nsIDOMDOMErrorHandler> mErrorHandler;
nsCOMPtr<nsIDOMDOMBuilderFilter> mFilter;
// Strong ref; make sure DOMImplementation never owns us!
nsCOMPtr<nsIDOMDOMImplementation> mDOMImplementation;
};
extern nsresult
NS_NewDOMBuilder(nsIDOMDOMBuilder** aResult,
PRUint16 aMode,
const nsAString & aSchemaType,
nsIDOMDOMImplementation* aDOMImplementation);
#endif // nsDOMBuilder_h__

View File

@ -0,0 +1,69 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Communiactions Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Boris Zbarsky <bzbarsky@mit.edu> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsILoadSaveContentSink_h__
#define nsILoadSaveContentSink_h__
#include "nsIXMLContentSink.h"
#define NS_ILOADSAVE_CONTENT_SINK_IID \
{ 0xa39ed66a, 0x6ef5, 0x49da, \
{ 0xb6, 0xe4, 0x9e, 0x15, 0x85, 0xf0, 0xba, 0xc9 } }
/**
* This interface represents a content sink used by the DOMBuilder in
* DOM3 Load/Save.
*/
class nsILoadSaveContentSink : public nsIXMLContentSink {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILOADSAVE_CONTENT_SINK_IID)
};
/**
* The nsIXMLContentSink passed to this method must also implement
* nsIExpatSink.
*/
extern nsresult
NS_NewLoadSaveContentSink(nsILoadSaveContentSink** aResult,
nsIXMLContentSink* aBaseSink);
#endif // nsILoadSaveContentSink_h__

View File

@ -0,0 +1,202 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Communiactions Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Boris Zbarsky <bzbarsky@mit.edu> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nscore.h"
#include "nsLoadSaveContentSink.h"
nsresult
NS_NewLoadSaveContentSink(nsILoadSaveContentSink** aResult,
nsIXMLContentSink* aBaseSink)
{
NS_PRECONDITION(aResult, "Null out ptr? Who do you think you are, flouting XPCOM contract?");
NS_ENSURE_ARG_POINTER(aBaseSink);
nsLoadSaveContentSink* it;
NS_NEWXPCOM(it, nsLoadSaveContentSink);
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = it->Init(aBaseSink);
if (NS_FAILED(rv)) {
delete it;
return rv;
}
return CallQueryInterface(it, aResult);
}
nsLoadSaveContentSink::nsLoadSaveContentSink()
{
NS_INIT_REFCNT();
}
nsLoadSaveContentSink::~nsLoadSaveContentSink()
{
}
nsresult
nsLoadSaveContentSink::Init(nsIXMLContentSink* aBaseSink)
{
NS_PRECONDITION(aBaseSink, "aBaseSink needs to exist");
mBaseSink = aBaseSink;
mExpatSink = do_QueryInterface(aBaseSink);
if (!mExpatSink) {
return NS_ERROR_INVALID_ARG;
}
return NS_OK;
}
NS_IMPL_THREADSAFE_ADDREF(nsLoadSaveContentSink)
NS_IMPL_THREADSAFE_RELEASE(nsLoadSaveContentSink)
NS_INTERFACE_MAP_BEGIN(nsLoadSaveContentSink)
NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink)
NS_INTERFACE_MAP_ENTRY(nsIExpatSink)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLContentSink)
NS_INTERFACE_MAP_END
// nsIContentSink
NS_IMETHODIMP
nsLoadSaveContentSink::WillBuildModel(void)
{
return mBaseSink->WillBuildModel();
}
NS_IMETHODIMP
nsLoadSaveContentSink::DidBuildModel(PRInt32 aQualityLevel)
{
return mBaseSink->DidBuildModel(aQualityLevel);
}
NS_IMETHODIMP
nsLoadSaveContentSink::WillInterrupt(void)
{
return mBaseSink->WillInterrupt();
}
NS_IMETHODIMP
nsLoadSaveContentSink::WillResume(void)
{
return mBaseSink->WillResume();
}
NS_IMETHODIMP
nsLoadSaveContentSink::SetParser(nsIParser* aParser)
{
return mBaseSink->SetParser(aParser);
}
NS_IMETHODIMP
nsLoadSaveContentSink::FlushPendingNotifications(void)
{
return mBaseSink->FlushPendingNotifications();
}
NS_IMETHODIMP
nsLoadSaveContentSink::SetDocumentCharset(nsAString& aCharset)
{
return mBaseSink->SetDocumentCharset(aCharset);
}
// nsIExpatSink
NS_IMETHODIMP
nsLoadSaveContentSink::HandleStartElement(const PRUnichar *aName,
const PRUnichar **aAtts,
PRUint32 aAttsCount,
PRUint32 aIndex,
PRUint32 aLineNumber)
{
return mExpatSink->HandleStartElement(aName, aAtts, aAttsCount, aIndex,
aLineNumber);
}
NS_IMETHODIMP
nsLoadSaveContentSink::HandleEndElement(const PRUnichar *aName)
{
return mExpatSink->HandleEndElement(aName);
}
NS_IMETHODIMP
nsLoadSaveContentSink::HandleComment(const PRUnichar *aName)
{
return mExpatSink->HandleComment(aName);
}
NS_IMETHODIMP
nsLoadSaveContentSink::HandleCDataSection(const PRUnichar *aData,
PRUint32 aLength)
{
return mExpatSink->HandleCDataSection(aData, aLength);
}
NS_IMETHODIMP
nsLoadSaveContentSink::HandleDoctypeDecl(const nsAString & aSubset,
const nsAString & aName,
const nsAString & aSystemId,
const nsAString & aPublicId,
nsISupports* aCatalogData)
{
return mExpatSink->HandleDoctypeDecl(aSubset, aName, aSystemId, aPublicId,
aCatalogData);
}
NS_IMETHODIMP
nsLoadSaveContentSink::HandleCharacterData(const PRUnichar *aData,
PRUint32 aLength)
{
return mExpatSink->HandleCharacterData(aData, aLength);
}
NS_IMETHODIMP
nsLoadSaveContentSink::HandleProcessingInstruction(const PRUnichar *aTarget,
const PRUnichar *aData)
{
return mExpatSink->HandleProcessingInstruction(aTarget, aData);
}
NS_IMETHODIMP
nsLoadSaveContentSink::ReportError(const PRUnichar* aErrorText,
const PRUnichar* aSourceText)
{
// XXX Do error reporting here. I see no reason to call ReportError
// on the "base" sink; all we need to do is drop the document on the
// floor...
return NS_OK;
}

View File

@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Communiactions Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Boris Zbarsky <bzbarsky@mit.edu> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsLoadSaveContentSink_h__
#define nsLoadSaveContentSink_h__
#include "nsIExpatSink.h"
#include "nsIXMLContentSink.h"
#include "nsILoadSaveContentSink.h"
#include "nsCOMPtr.h"
/**
* This class implements the core of the DOMBuilder for DOM3
* Load/Save. It holds a reference to an actual content sink that
* constructs the content model.
*/
class nsLoadSaveContentSink : public nsILoadSaveContentSink,
public nsIExpatSink
{
public:
nsLoadSaveContentSink();
virtual ~nsLoadSaveContentSink();
/**
* Initializes the sink. This will return an error if the arguments
* do not satisfy some basic sanity-checks.
* @param aBaseSink a "real" sink that the LoadSave sink can use to
* build the document. This must be non-null and
* must also implement nsIExpatSink.
*/
nsresult Init(nsIXMLContentSink* aBaseSink);
NS_DECL_ISUPPORTS
NS_DECL_NSIEXPATSINK
// nsILoadSaveContentSink
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);
NS_IMETHOD SetParser(nsIParser* aParser);
NS_IMETHOD FlushPendingNotifications(void);
NS_IMETHOD SetDocumentCharset(nsAString& aCharset);
private:
/**
* Pointers to the "real" sink. We hold on to both just for
* convenience sake.
*/
nsCOMPtr<nsIXMLContentSink> mBaseSink;
nsCOMPtr<nsIExpatSink> mExpatSink;
};
#endif // nsLoadSaveContentSink_h__