00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ 00002 00003 /* AbiSource Program Utilities 00004 * 00005 * Copyright (C) 2002 Francis James Franklin <fjf@alinameridon.com> 00006 * Copyright (C) 2002 AbiSource, Inc. 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License 00010 * as published by the Free Software Foundation; either version 2 00011 * of the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00021 * 02110-1301 USA. 00022 */ 00023 00024 #ifndef XAP_RESOURCE_H 00025 #define XAP_RESOURCE_H 00026 00027 #include "ut_string_class.h" 00028 00029 class ABI_EXPORT XAP_Resource 00030 { 00031 protected: 00032 XAP_Resource (const char * resource_name, bool resource_internal); 00033 00034 public: 00035 virtual ~XAP_Resource () { } 00036 00037 const UT_UTF8String & name () const { return m_resource_name; } 00038 00039 UT_uint32 ref () { return ++m_ref_count; } 00040 UT_uint32 unref () { return m_ref_count ? --m_ref_count : 0; } 00041 00042 UT_uint32 count () const { return m_ref_count; } 00043 00044 const bool bInternal; 00045 00046 UT_UTF8String Description; // Doesn't seem to be any point in hiding this... 00047 private: 00048 UT_UTF8String m_resource_name; 00049 00050 UT_uint32 m_ref_count; 00051 }; 00052 00053 class ABI_EXPORT XAP_InternalResource : public XAP_Resource 00054 { 00055 public: 00056 class ABI_EXPORT Writer 00057 { 00058 public: 00059 virtual ~Writer () { } 00060 00061 virtual UT_Error write_base64 (void * context, const char * base64, UT_uint32 length, bool final) = 0; 00062 }; 00063 00064 XAP_InternalResource (const char * resource_id); 00065 00066 ~XAP_InternalResource (); 00067 00068 /* buffer containing binary representation 00069 * 00070 * returns 0 on mem-err or illegal base64 chars encountered; if base64_encoded then length will change 00071 */ 00072 const char * buffer (const char * new_buffer, UT_uint32 new_buffer_length, bool base64_encoded = false); 00073 00074 const char * buffer () const { return m_buffer; } 00075 UT_uint32 length () const { return m_buffer_length; } 00076 00077 UT_Error write_base64 (void * context, Writer & writer); // call's writer's write_base64() callback 00078 00079 const UT_UTF8String & type (const UT_UTF8String & new_content_type); 00080 const UT_UTF8String & type (const char * new_content_type); 00081 00082 const UT_UTF8String & type () const { return m_content_type; } 00083 00084 private: 00085 void clear (); 00086 00087 char * m_buffer; 00088 UT_uint32 m_buffer_length; 00089 00090 UT_UTF8String m_content_type; 00091 }; 00092 00093 class ABI_EXPORT XAP_ExternalResource : public XAP_Resource 00094 { 00095 public: 00096 XAP_ExternalResource (const char * resource_id); 00097 00098 ~XAP_ExternalResource (); 00099 00100 const UT_UTF8String & URL () const 00101 { 00102 return m_url; 00103 } 00104 const UT_UTF8String & URL (const UT_UTF8String & url); 00105 00106 private: 00107 UT_UTF8String m_url; 00108 }; 00109 00110 #endif /* ! XAP_RESOURCE_H */