• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ie_imp_EPUB.h

Go to the documentation of this file.
00001 /* AbiSource
00002  *
00003  * Copyright (C) 2011 Volodymyr Rudyj <vladimir.rudoy@gmail.com>
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018  * 02110-1301 USA.
00019  */
00020 
00021 #ifndef IE_IMP_EPUB_H_
00022 #define IE_IMP_EPUB_H_
00023 
00024 #include <gsf/gsf-infile-zip.h>
00025 #include <gsf/gsf-infile.h>
00026 #include <gsf/gsf-libxml.h>
00027 #include <gsf/gsf-input-memory.h>
00028 #include <ut_go_file.h>
00029 #include <stdexcept>
00030 #include <vector>
00031 #include <map>
00032 #include <string>
00033 
00034 // AbiWord includes
00035 #include <ie_imp.h>
00036 #include <ie_imp_XHTML.h>
00037 #include <ut_xml.h>
00038 #include <ie_imp_PasteListener.h>
00039 #include <xap_Prefs.h>
00040 #include <xap_App.h>
00041 
00042 
00043 
00044 #define EPUB_MIMETYPE "application/epub+zip"
00045 
00046 typedef std::pair<std::string, std::string> string_pair;
00050 class IE_Imp_EPUB: public IE_Imp
00051 {
00052 public:
00053     IE_Imp_EPUB(PD_Document * pDocument);
00054     virtual ~IE_Imp_EPUB();
00055     virtual bool pasteFromBuffer(PD_DocumentRange * pDocRange,
00056             const unsigned char * pData, UT_uint32 lenData,
00057             const char * szEncoding = 0);
00058 protected:
00059     virtual UT_Error _loadFile(GsfInput * input);
00060 
00061 private:
00062     GsfInfile* m_epub;
00063     std::string m_rootfilePath;
00064     std::string m_tmpDir;
00065     std::string m_opsDir;
00066     std::vector<std::string> m_spine;
00067     std::map<std::string, std::string> m_manifestItems;
00068 
00069     UT_Error readMetadata();
00070     UT_Error readPackage();
00071     UT_Error uncompress();
00072     UT_Error readStructure();
00073     static GsfOutput* createFileByPath(const char* path);
00074 };
00075 
00076 /*
00077  * Listener for parsing container.xml data
00078  */
00079 class ContainerListener: public UT_XML::Listener
00080 {
00081 public:
00082     void startElement(const gchar * name, const gchar ** atts);
00083     void endElement(const gchar * name);
00084     void charData(const gchar * buffer, int length);
00085 
00086     const std::string & getRootFilePath() const;
00087 
00088 private:
00089     std::string m_rootFilePath;
00090 };
00091 
00092 /*
00093  * Listener for parsing .opf
00094  */
00095 class OpfListener: public UT_XML::Listener
00096 {
00097 public:
00098     void startElement(const gchar * name, const gchar ** atts);
00099     void endElement(const gchar * name);
00100     void charData(const gchar * buffer, int length);
00101 
00102     const std::map<std::string, std::string> & getManifestItems() const
00103     {
00104         return m_manifestItems;
00105     }
00106     const std::vector<std::string> & getSpine() const
00107     {
00108         return m_spine;
00109     }
00110 
00111     OpfListener();
00112 
00113 private:
00114     /* Vector with list of OPS files needed to be imported. Sorted in the linear
00115      * reading order
00116      */
00117     std::vector<std::string> m_spine;
00118     /* Map with all files that will be used for import
00119      */
00120     std::map<std::string, std::string> m_manifestItems;
00121 
00122     bool m_inManifest;
00123     bool m_inSpine;
00124 };
00125 
00126 /*
00127  * Listener for parsing .ncx
00128  */
00129 class NavigationListener: public UT_XML::Listener
00130 {
00131 public:
00132     void startElement(const gchar * name, const gchar ** atts);
00133     void endElement(const gchar * name);
00134     void charData(const gchar * buffer, int length);
00135 };
00136 
00137 #endif
00138 

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1