adding mime type resolver module.

This commit is contained in:
valeski%netscape.com 1999-07-02 20:08:27 +00:00
Родитель c2f73d352c
Коммит ad4fca8f6b
14 изменённых файлов: 815 добавлений и 0 удалений

33
netwerk/mime/Makefile.in Normal file
Просмотреть файл

@ -0,0 +1,33 @@
#! gmake
#
# 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.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
MODULE = mime
include $(DEPTH)/config/autoconf.mk
DIRS= \
public \
src \
$(NULL)
include $(topsrcdir)/config/rules.mk

27
netwerk/mime/makefile.win Normal file
Просмотреть файл

@ -0,0 +1,27 @@
#!gmake
#
# 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.
DEPTH = ..\..
MODULE = mime
DIRS= \
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,46 @@
#!gmake
#
# 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.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
MODULE = mime
XPIDL_MODULE = mime
XPIDLSRCS = \
nsIMIMEService.idl \
nsIMIMEInfo.idl \
$(NULL)
EXPORTS = \
nsIMIMEInfo.h \
nsIMIMEService.h \
$(NULL)
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,43 @@
#!gmake
#
# 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.
MODULE = mime
DEPTH = ..\..\..
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
XPIDL_MODULE = mime
XPIDLSRCS = \
.\nsIMIMEInfo.idl \
.\nsIMIMEService.idl \
$(NULL)
EXPORTS = \
$(NULL)
include <$(DEPTH)/config/rules.mak>
$(DEPTH)\netwerk\dist\include:
-mkdir $(DEPTH)\netwerk\dist
-mkdir $(DEPTH)\netwerk\dist\include

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

@ -0,0 +1,37 @@
/* -*- Mode: IDL; 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.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.
*/
/* An nsIMIMEInfo gives a user access to mime information
*
*/
#include "nsISupports.idl"
[scriptable, uuid(6A57EAE0-2FE8-11d3-A164-0050041CAF44)]
interface nsIMIMEInfo : nsISupports {
// return the file extensions associated with this MIME type set.
attribute string FileExtensions;
// return the MIME types associated with this file extension set.
attribute string MIMEType;
// return the description of this MIME type set.
attribute wstring Description;
boolean Equals(in nsIMIMEInfo aMIMEInfo);
};

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

@ -0,0 +1,52 @@
/* -*- Mode: IDL; 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.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.
*/
/* The MIME service is responsible for mapping file extensions to MIME-types
* (see RFC 2045).
*/
#include "nsISupports.idl"
#include "nsIMIMEInfo.idl"
%{C++
#define NS_MIMESERVICE_CID \
{ /* 9ac9e770-18bc-11d3-9337-00104ba0fd40 */ \
0x9ac9e770, \
0x18bc, \
0x11d3, \
{0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
%}
[scriptable, uuid(6C424C90-2FE7-11d3-A164-0050041CAF44)]
interface nsIMIMEService : nsISupports {
// return a nsIMIMEInfo for the given file extension.
nsIMIMEInfo GetFromExtension(in wstring aFileExt);
// return a nsIMIMEInfo for the given MIME type.
nsIMIMEInfo GetFromMIMEType(in wstring aMIMEType);
// insert a nsIMIMEInfo in the the database.
void AddMIMEInfo(in nsIMIMEInfo aMIMEInfo);
// remove a nsIMIMEInfo from the database.
void RemoveMIMEInfo(in nsIMIMEInfo aMIMEInfo);
};

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

@ -0,0 +1,46 @@
# 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.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
MODULE = mime
LIBRARY_NAME = mime
IS_COMPONENT = 1
include $(DEPTH)/config/autoconf.mk
CPPSRCS = \
nsMIMEInfoImpl.cpp \
nsMIMEService.cpp \
$(NULL)
include $(topsrcdir)/config/config.mk
REQUIRES = xpcom
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
TARGET = $(LIBARY)
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,56 @@
# 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.
DEPTH = ..\..\..
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
MODULE = mime
IS_COMPONENT=1
MAKE_OBJ_TYPE=DLL
DLLNAME=mime
DLL=.\$(OBJDIR)\$(DLLNAME).dll
LLIBS= $(LLIBS) \
$(DIST)\lib\xpcom.lib \
$(NULL)
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
CPP_OBJS = \
nsMIMEInfoImpl.obj \
nsMIMEService.obj \
$(NULL)
LOCAL_INCLUDES=-I.
INCLUDES = $(LOCAL_INCLUDES)
INCS = $(INCS) \
-I$(DEPTH)\dist\include \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
clobber::
rv -f $(DLL) $(DIST)\bin\components

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

@ -0,0 +1,101 @@
/* -*- 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 "nsMIMEInfoImpl.h"
#include "nsCRT.h"
// nsISupports methods
NS_IMPL_ISUPPORTS(nsMIMEInfoImpl, nsCOMTypeInfo<nsIMIMEInfo>::GetIID());
// nsMIMEInfoImpl methods
nsMIMEInfoImpl::nsMIMEInfoImpl(const char *aMIMEType, const char *aFileExtensions, const char *aDescription) {
mMIMEType = NS_NewAtom(aMIMEType);
mFileExtensions.SetString(aFileExtensions);
mDescription.SetString(aDescription);
}
nsMIMEInfoImpl::~nsMIMEInfoImpl() {
delete mMIMEType;
}
PRBool
nsMIMEInfoImpl::InExtensions(nsIAtom* anIAtom) {
nsString2 extension;
anIAtom->ToString(extension);
if (mFileExtensions.Find(extension) == -1)
return PR_FALSE;
return PR_TRUE;
}
// nsIMIMEInfo methods
NS_IMETHODIMP
nsMIMEInfoImpl::GetFileExtensions(char * *aFileExtensions) {
if (!aFileExtensions) return NS_ERROR_NULL_POINTER;
*aFileExtensions = mFileExtensions.ToNewCString();
if (!*aFileExtensions)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::SetFileExtensions(char * aFileExtensions) {
mFileExtensions.SetString(aFileExtensions);
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::GetMIMEType(char * *aMIMEType) {
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
nsString2 strMIMEType;
mMIMEType->ToString(strMIMEType);
*aMIMEType = strMIMEType.ToNewCString();
if (!*aMIMEType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::SetMIMEType(char * aMIMEType) {
delete mMIMEType;
mMIMEType = NS_NewAtom(aMIMEType);
if (!mMIMEType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::GetDescription(PRUnichar * *aDescription) {
if (!aDescription) return NS_ERROR_NULL_POINTER;
*aDescription = mDescription.ToNewUnicode();
if (!*aDescription) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::SetDescription(PRUnichar * aDescription) {
mDescription.SetString(aDescription);
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval) {
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -0,0 +1,54 @@
/* -*- 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 __nsmimeinfoimpl_h___
#define __nsmimeinfoimpl_h___
#include "nsIMIMEInfo.h"
#include "nsIAtom.h"
#include "nsString2.h"
class nsMIMEInfoImpl : public nsIMIMEInfo {
// nsISupports methods
NS_DECL_ISUPPORTS
// nsMIMEInfoImpl methods
nsMIMEInfoImpl(const char *aMIMEType, const char *aFileExtensions, const char *aDescription);
~nsMIMEInfoImpl();
PRBool InExtensions(nsIAtom* anIAtom);
// nsIMIMEInfo methods
NS_IMETHOD GetFileExtensions(char * *aFileExtensions);
NS_IMETHOD SetFileExtensions(char * aFileExtensions);
NS_IMETHOD GetMIMEType(char * *aMIMEType);
NS_IMETHOD SetMIMEType(char * aMIMEType);
NS_IMETHOD GetDescription(PRUnichar * *aDescription);
NS_IMETHOD SetDescription(PRUnichar * aDescription);
NS_IMETHOD Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval);
// member variables
nsIAtom* mMIMEType;
nsString2 mFileExtensions;
nsString2 mDescription;
};
#endif //__nsmimeinfoimpl_h___

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

@ -0,0 +1,115 @@
/* -*- 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 "nsMIMEService.h"
#include "nsVoidArray.h"
#include "nsEnumeratorUtils.h" // for nsArrayEnumerator
#include "nsString2.h"
#include "nsMIMEInfoImpl.h"
#include "nsIMIMEInfo.h"
// nsMIMEService methods
nsMIMEService::nsMIMEService() {
mInfoArray = new nsVoidArray();
InitFromHack(); // XXX bogus
}
nsMIMEService::~nsMIMEService() {
PRInt32 count = mInfoArray->Count();
for (int i = 0; i < count; i++) {
nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)mInfoArray->ElementAt(i);
mInfoArray->RemoveElementAt(i);
// delete entry;
}
}
/* This bad boy needs to retrieve a url, and parse the data coming back, and
* add entries into the mInfoArray.
*/
nsresult
nsMIMEService::InitFromURI(nsIURI *aUri) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsMIMEService::InitFromHack() {
nsMIMEInfoImpl* anInfo = nsnull;
anInfo = new nsMIMEInfoImpl("text/html", "htm,html", "Hyper Text Markup Language");
if (!anInfo) return NS_ERROR_OUT_OF_MEMORY;
mInfoArray->AppendElement(anInfo);
anInfo = new nsMIMEInfoImpl("text/rdf", "rdf", "Resource Description Framework");
if (!anInfo) return NS_ERROR_OUT_OF_MEMORY;
mInfoArray->AppendElement(anInfo);
anInfo = new nsMIMEInfoImpl("text/xul", "xul", "XML-Based User Interface Language");
if (!anInfo) return NS_ERROR_OUT_OF_MEMORY;
mInfoArray->AppendElement(anInfo);
anInfo = new nsMIMEInfoImpl("text/xml", "xml", "Extensible Markup Language");
if (!anInfo) return NS_ERROR_OUT_OF_MEMORY;
mInfoArray->AppendElement(anInfo);
return NS_OK;
}
// nsIMIMEService methods
NS_IMETHODIMP
nsMIMEService::GetFromExtension(const PRUnichar *aFileExt, nsIMIMEInfo **_retval) {
nsIAtom* extension = NS_NewAtom(aFileExt);
if (!extension) return NS_ERROR_OUT_OF_MEMORY;
PRInt32 count = mInfoArray->Count();
for (int i = 0; i < count; i++) {
nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)mInfoArray->ElementAt(i);
if (entry->InExtensions(extension)) {
*_retval = NS_STATIC_CAST(nsIMIMEInfo*, entry);
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMIMEService::GetFromMIMEType(const PRUnichar *aMIMEType, nsIMIMEInfo **_retval) {
nsIAtom* MIMEType = NS_NewAtom(aMIMEType);
if (!MIMEType) return NS_ERROR_OUT_OF_MEMORY;
PRInt32 count = mInfoArray->Count();
for (int i = 0; i < count; i++) {
nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)mInfoArray->ElementAt(i);
if (entry->mMIMEType == MIMEType) {
*_retval = NS_STATIC_CAST(nsIMIMEInfo*, entry);
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMIMEService::AddMIMEInfo(nsIMIMEInfo *aMIMEInfo) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMIMEService::RemoveMIMEInfo(nsIMIMEInfo *aMIMEInfo) {
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -0,0 +1,50 @@
/* -*- 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.
*/
/*
* There is a 1-to-many relationship between MIME-types and file extensions
* I.e. there can be many file extensions that have the same mime type.
*/
#ifndef ___nsIMIMEService__h___
#define ___nsIMIMEService__h___
#include "nsIMIMEService.h"
#include "nsIURI.h"
class nsVoidArray;
class nsMIMEService : public nsIMIMEService {
// nsMIMEService methods
nsMIMEService();
~nsMIMEService();
// nsIMIMEService methods
NS_IMETHOD GetFromExtension(const PRUnichar *aFileExt, nsIMIMEInfo **_retval);
NS_IMETHOD GetFromMIMEType(const PRUnichar *aMIMEType, nsIMIMEInfo **_retval);
NS_IMETHOD AddMIMEInfo(nsIMIMEInfo *aMIMEInfo);
NS_IMETHOD RemoveMIMEInfo(nsIMIMEInfo *aMIMEInfo);
private:
nsresult InitFromURI(nsIURI *aUri);
nsresult InitFromHack();
nsVoidArray* mInfoArray;
};
#endif // ___nsIMIMEService__h___

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

@ -0,0 +1,101 @@
/* -*- 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 "nsMIMEInfoImpl.h"
#include "nsCRT.h"
// nsISupports methods
NS_IMPL_ISUPPORTS(nsMIMEInfoImpl, nsCOMTypeInfo<nsIMIMEInfo>::GetIID());
// nsMIMEInfoImpl methods
nsMIMEInfoImpl::nsMIMEInfoImpl(const char *aMIMEType, const char *aFileExtensions, const char *aDescription) {
mMIMEType = NS_NewAtom(aMIMEType);
mFileExtensions.SetString(aFileExtensions);
mDescription.SetString(aDescription);
}
nsMIMEInfoImpl::~nsMIMEInfoImpl() {
delete mMIMEType;
}
PRBool
nsMIMEInfoImpl::InExtensions(nsIAtom* anIAtom) {
nsString2 extension;
anIAtom->ToString(extension);
if (mFileExtensions.Find(extension) == -1)
return PR_FALSE;
return PR_TRUE;
}
// nsIMIMEInfo methods
NS_IMETHODIMP
nsMIMEInfoImpl::GetFileExtensions(char * *aFileExtensions) {
if (!aFileExtensions) return NS_ERROR_NULL_POINTER;
*aFileExtensions = mFileExtensions.ToNewCString();
if (!*aFileExtensions)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::SetFileExtensions(char * aFileExtensions) {
mFileExtensions.SetString(aFileExtensions);
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::GetMIMEType(char * *aMIMEType) {
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
nsString2 strMIMEType;
mMIMEType->ToString(strMIMEType);
*aMIMEType = strMIMEType.ToNewCString();
if (!*aMIMEType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::SetMIMEType(char * aMIMEType) {
delete mMIMEType;
mMIMEType = NS_NewAtom(aMIMEType);
if (!mMIMEType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::GetDescription(PRUnichar * *aDescription) {
if (!aDescription) return NS_ERROR_NULL_POINTER;
*aDescription = mDescription.ToNewUnicode();
if (!*aDescription) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::SetDescription(PRUnichar * aDescription) {
mDescription.SetString(aDescription);
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoImpl::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval) {
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -0,0 +1,54 @@
/* -*- 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 __nsmimeinfoimpl_h___
#define __nsmimeinfoimpl_h___
#include "nsIMIMEInfo.h"
#include "nsIAtom.h"
#include "nsString2.h"
class nsMIMEInfoImpl : public nsIMIMEInfo {
// nsISupports methods
NS_DECL_ISUPPORTS
// nsMIMEInfoImpl methods
nsMIMEInfoImpl(const char *aMIMEType, const char *aFileExtensions, const char *aDescription);
~nsMIMEInfoImpl();
PRBool InExtensions(nsIAtom* anIAtom);
// nsIMIMEInfo methods
NS_IMETHOD GetFileExtensions(char * *aFileExtensions);
NS_IMETHOD SetFileExtensions(char * aFileExtensions);
NS_IMETHOD GetMIMEType(char * *aMIMEType);
NS_IMETHOD SetMIMEType(char * aMIMEType);
NS_IMETHOD GetDescription(PRUnichar * *aDescription);
NS_IMETHOD SetDescription(PRUnichar * aDescription);
NS_IMETHOD Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval);
// member variables
nsIAtom* mMIMEType;
nsString2 mFileExtensions;
nsString2 mDescription;
};
#endif //__nsmimeinfoimpl_h___