Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef IE_EXP_H
00023 #define IE_EXP_H
00024
00025 #include <stdio.h>
00026 #include <map>
00027 #include <string>
00028
00029 #include "ie_types.h"
00030
00031 #include "ut_go_file.h"
00032 #include <gsf/gsf-output.h>
00033
00034 #include "ut_string_class.h"
00035
00036 class PD_Document;
00037 class PD_DocumentRange;
00038 class UT_ByteBuf;
00039
00041
00043
00044 class IE_Exp;
00045 class IE_FieldUpdater;
00046
00047 class ABI_EXPORT IE_ExpSniffer
00048 {
00049 friend class IE_Exp;
00050
00051 public:
00052 virtual ~IE_ExpSniffer();
00053
00054
00055 inline bool supportsFileType (IEFileType type) {return m_type == type;}
00056 inline IEFileType getFileType() const {return m_type;}
00057
00058
00059 virtual bool recognizeSuffix (const char * szSuffix) = 0;
00060 virtual bool getDlgLabels (const char ** szDesc,
00061 const char ** szSuffixList,
00062 IEFileType * ft) = 0;
00063
00064 virtual UT_UTF8String getPreferredSuffix();
00065
00066 virtual UT_Error constructExporter (PD_Document * pDocument,
00067 IE_Exp ** ppie) = 0;
00068
00074 virtual UT_Confidence_t supportsMIME (const char * ) { return UT_CONFIDENCE_ZILCH; }
00075
00076 const UT_UTF8String & name () const { return m_name; }
00077
00078 bool getCanCopy () const {
00079 return m_bCanCopy;
00080 }
00081
00082 protected:
00083 IE_ExpSniffer(const char * name, bool canCopy = false);
00084
00085 private:
00086 const UT_UTF8String m_name;
00087
00088
00089 inline void setFileType (IEFileType type) {m_type = type;}
00090 IEFileType m_type;
00091
00092 bool m_bCanCopy;
00093 };
00094
00095 class ABI_EXPORT IE_Exp
00096 {
00097 public:
00098
00099
00100
00101
00102
00103 static IEFileType fileTypeForSuffix(const char * szSuffix);
00104 static IEFileType fileTypeForMimetype(const char * szMimetype);
00105 static IEFileType fileTypeForDescription(const char * szSuffix);
00106 static IEFileType fileTypeForSuffixes(const char * suffixList);
00107 static IE_ExpSniffer * snifferForFileType(IEFileType ieft);
00108 static const char * suffixesForFileType(IEFileType ieft);
00109 static const char * descriptionForFileType(IEFileType ieft);
00110 static UT_UTF8String preferredSuffixForFileType(IEFileType ieft);
00111
00112 static UT_Error constructExporter(PD_Document * pDocument,
00113 const char * szFilename,
00114 IEFileType ieft,
00115 IE_Exp ** ppie,
00116 IEFileType * pieft = NULL);
00117 static UT_Error constructExporter(PD_Document * pDocument,
00118 GsfOutput * output,
00119 IEFileType ieft,
00120 IE_Exp ** ppie,
00121 IEFileType * pieft = NULL);
00122 static bool enumerateDlgLabels(UT_uint32 ndx,
00123 const char ** pszDesc,
00124 const char ** pszSuffixList,
00125 IEFileType * ft);
00126 static UT_uint32 getExporterCount(void);
00127
00128 static void registerExporter (IE_ExpSniffer *);
00129 static void unregisterExporter (IE_ExpSniffer *);
00130 static void unregisterAllExporters ();
00131
00132 virtual ~IE_Exp();
00133
00134 UT_Error writeFile(const char * szFilename);
00135 UT_Error writeFile(GsfOutput * fp);
00136 virtual UT_Error copyToBuffer(PD_DocumentRange * pDocRange, UT_ByteBuf * pBuf);
00137 virtual void write(const char * sz);
00138 virtual void write(const char * sz, UT_uint32 length);
00139 virtual char rewindChar(void);
00140 void write(const std::string & inStr)
00141 {
00142 write(inStr.c_str(), inStr.size());
00143 }
00144 void write (const UT_String & inStr)
00145 {
00146 write ( inStr.c_str(), inStr.size() ) ;
00147 }
00148
00149 virtual const char * getFileName(void) const
00150 { return m_szFileName.c_str(); }
00151
00152 UT_Confidence_t getFidelity () const {
00153 return m_fidelity;
00154 }
00155
00156 void setProps (const char * props);
00157
00158 bool isCopying () const {
00159 return getDocRange () != NULL;
00160 }
00161
00162 void populateFields();
00163
00164
00165
00166 static UT_Error writeBufferToFile(const UT_ConstByteBufPtr & pByteBuf,
00167 const std::string & imagedir,
00168 const std::string & filename);
00169
00170 protected:
00171
00172 IE_Exp(PD_Document * pDocument, UT_Confidence_t fidelity = 0);
00173 virtual UT_Error _writeDocument(void) = 0;
00174
00175 GsfOutput* openFile(const char * szFilename);
00176
00177 virtual GsfOutput* _openFile(const char *szFilename);
00178
00179
00180
00181
00182 virtual UT_uint32 _writeBytes(const UT_Byte * pBytes, UT_uint32 length);
00183 virtual bool _writeBytes(const UT_Byte * sz);
00184 virtual void _abortFile(void);
00185
00186 void _cancelExport () { m_bCancelled = true; }
00187
00188 bool _closeFile(void);
00189
00190 PD_Document * getDoc() const;
00191 PD_DocumentRange * getDocRange() const;
00193 GsfOutput* getFp() const
00194 {
00195 return m_fp;
00196 }
00197
00198 bool m_error;
00199 void _setByteBuf(UT_ByteBuf * pBuf)
00200 { m_pByteBuf = pBuf;}
00201 UT_ByteBuf * _getByteBuf(void) const
00202 { return m_pByteBuf;}
00203
00204 public:
00205 std::string getProperty (const std::string & key) const;
00206
00207 private:
00208 PD_Document * m_pDocument;
00209 PD_DocumentRange * m_pDocRange;
00210 UT_ByteBuf * m_pByteBuf;
00211 std::string m_szFileName;
00212 GsfOutput * m_fp;
00213 bool m_bOwnsFp;
00214
00215 bool m_bCancelled;
00216
00217 std::map<std::string, std::string> m_props_map;
00218
00219 UT_Confidence_t m_fidelity;
00220 IE_FieldUpdater * m_fieldUpdater;
00221 };
00222
00223
00224 #endif