Checking in the non-dangerous parts of the XIF document/html encoder

git-svn-id: svn://10.0.0.236/trunk@33681 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
akkana%netscape.com 1999-06-04 01:04:08 +00:00
parent 3c4b404cd9
commit 5199693c7c
7 changed files with 639 additions and 0 deletions

View File

@ -0,0 +1,114 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIDocumentEncoder_h__
#define nsIDocumentEncoder_h__
#include "nsISupports.h"
#include "nsString.h"
class nsIDocumentEncoder;
class nsIDocument;
class nsIDOMSelection;
class nsIOutputStream;
class nsISupportsArray;
#define NS_IDOCUMENT_ENCODER_IID \
{ /* a6cf9103-15b3-11d2-932e-00805f8add32 */ \
0xa6cf9103, \
0x15b3, \
0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
}
#define NS_HTML_ENCODER_CID \
{ /* a6cf9104-15b3-11d2-932e-00805f8add32 */ \
0xa6cf9104, \
0x15b3, \
0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
}
class nsIDocumentEncoder : public nsISupports
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
#if 0
/**
* Creates a stream representation of aDocument.
* Uses the MIMEType to choose an encoding.
*
* aDocument must point to a valid, non-null nsIDocument object.
* Possible result codes: NS_OK, NS_ERROR_ENCODER_NOT_FOUND
*
*/
nsIDocumentEncoder(nsIDocument* aDocument,
const nsString& aMIMEType);
virtual ~nsIDocumentEncoder();
#endif
/**
* If the selection is set to a non-null value, then the
* selection is used for encoding, otherwise the entire
* document is encoded.
*
*/
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection) = 0;
/**
* Documents typically have an intrinsic character set.
* If no intrinsic value is found, the platform character set
* is used.
* aCharset overrides the both the intrinsic or platform
* character set when encoding the document.
*
* Possible result codes: NS_ERROR_NO_CHARSET_CONVERTER
*
*/
NS_IMETHOD SetCharset(const nsString& aCharset) = 0;
/**
* The document is encoded, the result is sent to the
* to nsIOutputStream.
*
* Possible result codes are passing along whatever stream errors
* might have been encountered.
*
*/
NS_IMETHOD Encode(nsIOutputStream* aStream) = 0;
};
// Example of a output service for a particular encoder
class nsIHTMLEncoder : public nsIDocumentEncoder
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
// Get embedded objects -- images, links, etc.
// NOTE: we may want to use an enumerator
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aObjects) = 0;
NS_IMETHOD SubstituteURL(const nsString& aOriginal,
const nsString& aReplacement) = 0;
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
};
#endif /* nsIDocumentEncoder_h__ */

View File

@ -0,0 +1,204 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIDocumentEncoder.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kCHTMLEncoderCID, NS_HTML_ENCODER_CID);
class nsHTMLEncoder : public nsIHTMLEncoder
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
nsHTMLEncoder();
virtual ~nsHTMLEncoder();
/* Interfaces for addref and release and queryinterface */
NS_DECL_ISUPPORTS
// Inherited methods from nsIDocument
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection);
NS_IMETHOD SetCharset(const nsString& aCharset);
NS_IMETHOD Encode(nsIOutputStream* aStream);
// Get embedded objects -- images, links, etc.
// NOTE: we may want to use an enumerator
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aObjects);
NS_IMETHOD SubstituteURL(const nsString& aOriginal,
const nsString& aReplacement);
NS_IMETHOD PrettyPrint(PRBool aYesNO);
};
NS_IMPL_ADDREF(nsHTMLEncoder)
NS_IMPL_RELEASE(nsHTMLEncoder)
nsHTMLEncoder::nsHTMLEncoder()
{
}
nsHTMLEncoder::~nsHTMLEncoder()
{
}
nsresult nsHTMLEncoder::QueryInterface(REFNSIID aIID,
void **aInstancePtr)
{
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = 0;
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void *)(nsISupports*)this;
} else if (aIID.Equals(nsIDocumentEncoder::GetIID())) {
*aInstancePtr = (void *)(nsIDocumentEncoder*)this;
}
if (nsnull == *aInstancePtr)
return NS_NOINTERFACE;
NS_ADDREF_THIS();
return NS_OK;
}
NS_IMETHODIMP
nsHTMLEncoder::SetSelection(nsIDOMSelection* aSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::SetCharset(const nsString& aCharset)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::Encode(nsIOutputStream* aStream)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::GetEmbeddedObjects(nsISupportsArray* aObjects)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::SubstituteURL(const nsString& aOriginal, const nsString& aReplacement)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::PrettyPrint(PRBool aYes)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
NS_NewHTMLEncoder(nsIDocumentEncoder** aResult)
{
*aResult = new nsHTMLEncoder;
if (!*aResult)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
class nsDocumentEncoderFactory : public nsIFactory
{
public:
nsDocumentEncoderFactory();
virtual ~nsDocumentEncoderFactory();
// nsISupports methods
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
};
nsDocumentEncoderFactory::nsDocumentEncoderFactory()
{
mRefCnt = 0;
}
nsDocumentEncoderFactory::~nsDocumentEncoderFactory()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMPL_ADDREF(nsDocumentEncoderFactory)
NS_IMPL_RELEASE(nsDocumentEncoderFactory)
nsresult nsDocumentEncoderFactory::QueryInterface(REFNSIID aIID,
void **aInstancePtr)
{
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = 0;
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void *)(nsISupports*)this;
} else if (aIID.Equals(kIFactoryIID)) {
*aInstancePtr = (void *)(nsIFactory*)this;
}
if (nsnull == *aInstancePtr)
return NS_NOINTERFACE;
NS_ADDREF_THIS();
return NS_OK;
}
nsresult
nsDocumentEncoderFactory::CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = 0;
if (aIID.Equals(kCHTMLEncoderCID))
*aResult = new nsHTMLEncoder;
else
return NS_NOINTERFACE;
if (*aResult == NULL)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}

View File

@ -8,6 +8,7 @@ nsIContentIterator.h
nsIDiskDocument.h
nsIDocument.h
nsIDocumentContainer.h
nsIDocumentEncoder.h
nsIDocumentObserver.h
nsIDocumentViewer.h
nsIFocusTracker.h

View File

@ -33,6 +33,7 @@ EXPORTS = \
nsIDiskDocument.h \
nsIDocument.h \
nsIDocumentContainer.h \
nsIDocumentEncoder.h \
nsIDocumentObserver.h \
nsIDocumentViewer.h \
nsIFocusTracker.h \

View File

@ -26,6 +26,7 @@ EXPORTS = \
nsIDiskDocument.h \
nsIDocument.h \
nsIDocumentContainer.h \
nsIDocumentEncoder.h \
nsIDocumentObserver.h \
nsIDocumentViewer.h \
nsIFocusTracker.h \

View File

@ -0,0 +1,114 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIDocumentEncoder_h__
#define nsIDocumentEncoder_h__
#include "nsISupports.h"
#include "nsString.h"
class nsIDocumentEncoder;
class nsIDocument;
class nsIDOMSelection;
class nsIOutputStream;
class nsISupportsArray;
#define NS_IDOCUMENT_ENCODER_IID \
{ /* a6cf9103-15b3-11d2-932e-00805f8add32 */ \
0xa6cf9103, \
0x15b3, \
0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
}
#define NS_HTML_ENCODER_CID \
{ /* a6cf9104-15b3-11d2-932e-00805f8add32 */ \
0xa6cf9104, \
0x15b3, \
0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
}
class nsIDocumentEncoder : public nsISupports
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
#if 0
/**
* Creates a stream representation of aDocument.
* Uses the MIMEType to choose an encoding.
*
* aDocument must point to a valid, non-null nsIDocument object.
* Possible result codes: NS_OK, NS_ERROR_ENCODER_NOT_FOUND
*
*/
nsIDocumentEncoder(nsIDocument* aDocument,
const nsString& aMIMEType);
virtual ~nsIDocumentEncoder();
#endif
/**
* If the selection is set to a non-null value, then the
* selection is used for encoding, otherwise the entire
* document is encoded.
*
*/
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection) = 0;
/**
* Documents typically have an intrinsic character set.
* If no intrinsic value is found, the platform character set
* is used.
* aCharset overrides the both the intrinsic or platform
* character set when encoding the document.
*
* Possible result codes: NS_ERROR_NO_CHARSET_CONVERTER
*
*/
NS_IMETHOD SetCharset(const nsString& aCharset) = 0;
/**
* The document is encoded, the result is sent to the
* to nsIOutputStream.
*
* Possible result codes are passing along whatever stream errors
* might have been encountered.
*
*/
NS_IMETHOD Encode(nsIOutputStream* aStream) = 0;
};
// Example of a output service for a particular encoder
class nsIHTMLEncoder : public nsIDocumentEncoder
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
// Get embedded objects -- images, links, etc.
// NOTE: we may want to use an enumerator
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aObjects) = 0;
NS_IMETHOD SubstituteURL(const nsString& aOriginal,
const nsString& aReplacement) = 0;
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
};
#endif /* nsIDocumentEncoder_h__ */

View File

@ -0,0 +1,204 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIDocumentEncoder.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kCHTMLEncoderCID, NS_HTML_ENCODER_CID);
class nsHTMLEncoder : public nsIHTMLEncoder
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
nsHTMLEncoder();
virtual ~nsHTMLEncoder();
/* Interfaces for addref and release and queryinterface */
NS_DECL_ISUPPORTS
// Inherited methods from nsIDocument
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection);
NS_IMETHOD SetCharset(const nsString& aCharset);
NS_IMETHOD Encode(nsIOutputStream* aStream);
// Get embedded objects -- images, links, etc.
// NOTE: we may want to use an enumerator
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aObjects);
NS_IMETHOD SubstituteURL(const nsString& aOriginal,
const nsString& aReplacement);
NS_IMETHOD PrettyPrint(PRBool aYesNO);
};
NS_IMPL_ADDREF(nsHTMLEncoder)
NS_IMPL_RELEASE(nsHTMLEncoder)
nsHTMLEncoder::nsHTMLEncoder()
{
}
nsHTMLEncoder::~nsHTMLEncoder()
{
}
nsresult nsHTMLEncoder::QueryInterface(REFNSIID aIID,
void **aInstancePtr)
{
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = 0;
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void *)(nsISupports*)this;
} else if (aIID.Equals(nsIDocumentEncoder::GetIID())) {
*aInstancePtr = (void *)(nsIDocumentEncoder*)this;
}
if (nsnull == *aInstancePtr)
return NS_NOINTERFACE;
NS_ADDREF_THIS();
return NS_OK;
}
NS_IMETHODIMP
nsHTMLEncoder::SetSelection(nsIDOMSelection* aSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::SetCharset(const nsString& aCharset)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::Encode(nsIOutputStream* aStream)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::GetEmbeddedObjects(nsISupportsArray* aObjects)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::SubstituteURL(const nsString& aOriginal, const nsString& aReplacement)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEncoder::PrettyPrint(PRBool aYes)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
NS_NewHTMLEncoder(nsIDocumentEncoder** aResult)
{
*aResult = new nsHTMLEncoder;
if (!*aResult)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
class nsDocumentEncoderFactory : public nsIFactory
{
public:
nsDocumentEncoderFactory();
virtual ~nsDocumentEncoderFactory();
// nsISupports methods
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
};
nsDocumentEncoderFactory::nsDocumentEncoderFactory()
{
mRefCnt = 0;
}
nsDocumentEncoderFactory::~nsDocumentEncoderFactory()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMPL_ADDREF(nsDocumentEncoderFactory)
NS_IMPL_RELEASE(nsDocumentEncoderFactory)
nsresult nsDocumentEncoderFactory::QueryInterface(REFNSIID aIID,
void **aInstancePtr)
{
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = 0;
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void *)(nsISupports*)this;
} else if (aIID.Equals(kIFactoryIID)) {
*aInstancePtr = (void *)(nsIFactory*)this;
}
if (nsnull == *aInstancePtr)
return NS_NOINTERFACE;
NS_ADDREF_THIS();
return NS_OK;
}
nsresult
nsDocumentEncoderFactory::CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = 0;
if (aIID.Equals(kCHTMLEncoderCID))
*aResult = new nsHTMLEncoder;
else
return NS_NOINTERFACE;
if (*aResult == NULL)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}