Re: volodymyr - r29814 - in abiword/trunk: . plugins/epub plugins/epub/common/xp plugins/epub/exp/xp

From: Xun Sun <xun.sun.cn_at_gmail.com>
Date: Mon Jun 13 2011 - 11:46:02 CEST

Hi volodymyr,

Please see my comments below:

On Mon, Jun 13, 2011 at 3:28 PM, <cvs@abisource.com> wrote:
>
> Author: volodymyr
> Date: 2011-06-13 09:28:28 +0200 (Mon, 13 Jun 2011)
> New Revision: 29814
>
> Modified:
>   abiword/trunk/
>   abiword/trunk/plugins/epub/
>   abiword/trunk/plugins/epub/common/xp/
>   abiword/trunk/plugins/epub/exp/xp/
>   abiword/trunk/plugins/epub/exp/xp/ie_exp_EPUB.cpp
>   abiword/trunk/plugins/epub/exp/xp/ie_exp_EPUB.h
> Log:
> Added creation of list of files  generated by HTML exporter to EPUB plugin
>
>
>
> Property changes on: abiword/trunk
> ___________________________________________________________________
> Modified: svn:ignore
>   - nbproject
> Makefile
> Makefile.in
> configure
> depcomp
> autogen.err
> config.*
> ltmain.sh
> INSTALL
> plugin-configure.m4
> plugin-makefiles.m4
> plugin-list.m4
> aclocal.m4
> libabiword.pc
> stamp-*
> autom4te.cache
> libtool
> missing
> install-sh
> doltlibtool
> doltcompile
> plugin-builtin.m4
> libtool.m4
> shave-libtool
> ax_boost_base.m4
> ltsugar.m4
> ltversion.m4
> ltoptions.m4
> shave
> abiword-?.?.pc
> .gsf-save-VJORWV
> .gsf-save-C9KNWV
> lt~obsolete.m4
>
>   + nbproject
> Makefile
> Makefile.in
> configure
> depcomp
> autogen.err
> config.*
> ltmain.sh
> INSTALL
> plugin-configure.m4
> plugin-makefiles.m4
> plugin-list.m4
> aclocal.m4
> libabiword.pc
> stamp-*
> autom4te.cache
> libtool
> missing
> install-sh
> doltlibtool
> doltcompile
> plugin-builtin.m4
> libtool.m4
> shave-libtool
> ax_boost_base.m4
> ltsugar.m4
> ltversion.m4
> ltoptions.m4
> shave
> abiword-?.?.pc
> .gsf-save-VJORWV
> .gsf-save-C9KNWV
> lt~obsolete.m4
> .project
> .cproject
>
>
>
> Property changes on: abiword/trunk/plugins/epub
> ___________________________________________________________________
> Modified: svn:ignore
>   - .deps
> .libs
> Makefile.in
>
>   + .deps
> .libs
> Makefile.in
> .gsf-save-G746WV
> Makefile
>
>
>
> Property changes on: abiword/trunk/plugins/epub/common/xp
> ___________________________________________________________________
> Modified: svn:ignore
>   - .deps
> .libs
> Makefile.in
>
>   + .deps
> .libs
> Makefile.in
> Makefile
>
>
>
> Property changes on: abiword/trunk/plugins/epub/exp/xp
> ___________________________________________________________________
> Modified: svn:ignore
>   - .deps
> .libs
> Makefile.in
> Makefile
>
>   + .deps
> .libs
> Makefile.in
> Makefile
> .ie_exp_EPUB.cpp.swp
> .ie_exp_EPUB.h.swp
>
>
> Modified: abiword/trunk/plugins/epub/exp/xp/ie_exp_EPUB.cpp
> ===================================================================
> --- abiword/trunk/plugins/epub/exp/xp/ie_exp_EPUB.cpp   2011-06-13 03:11:09 UTC (rev 29813)
> +++ abiword/trunk/plugins/epub/exp/xp/ie_exp_EPUB.cpp   2011-06-13 07:28:28 UTC (rev 29814)
> @@ -31,45 +31,152 @@
>  }
>  IE_Exp_EPUB::~IE_Exp_EPUB()
>  {
> -
> +
>  }
>
>  UT_Error IE_Exp_EPUB::_writeDocument()
>  {
> -
> -        m_outputFile = GSF_OUTFILE(gsf_outfile_zip_new (getFp(), NULL));
> -        GsfOutput *mimetype = gsf_outfile_new_child (m_outputFile, "mimetype", FALSE);
> -        gsf_output_write(mimetype, strlen(EPUB_MIMETYPE), (const guint8*)EPUB_MIMETYPE);
> -        gsf_output_close(mimetype);
> -        GsfOutput *oebpsDir = gsf_outfile_new_child(m_outputFile, "oebps", TRUE);
> -
> -        // Now we need to create temporary file to which
> -        // HTML plugin will export our document
> -        UT_UTF8String tmpPath;
> -        tmpPath = "file://";
> -        tmpPath += g_get_tmp_dir();
> -        tmpPath += "/";
> -        // To generate unique filename we`ll use document UUID
> -        tmpPath += getDoc()->getDocUUIDString();
> -        tmpPath += ".html";
>
> +       // We need to create temporary directory to which
> +       // HTML plugin will export our document
> +       m_baseTempDir = "file://";
> +       m_baseTempDir += g_get_tmp_dir();
> +       m_baseTempDir += "/";
>
> -        char *tmpFilename = (char*)g_malloc(strlen(tmpPath.utf8_str()) + 1);
> -        strcpy(tmpFilename, tmpPath.utf8_str());
> -
> +       // To generate unique directory name we`ll use document UUID
> +       m_baseTempDir += getDoc()->getDocUUIDString();
> +       UT_go_directory_create (m_baseTempDir.utf8_str (), 750, NULL);
> +
> +       writeContainer();
> +       writeStructure();
> +       package();
> +       return UT_OK;
> +}
>
> -        IE_Exp_HTML *pExpHtml = new IE_Exp_HTML(getDoc());
> -        pExpHtml->suppressDialog(true);
> -        pExpHtml->setProps("embed-css: no;");
> -        pExpHtml->writeFile(tmpFilename);
> +void IE_Exp_EPUB::writeContainer()
> +{
> +       UT_UTF8String metaInfPath = m_baseTempDir + "/META-INF";
> +       UT_go_directory_create(metaInfPath.utf8_str (), 750, NULL);

Does this mean to be 0750? And a few of other appearances.

> +       UT_UTF8String containerPath = metaInfPath + "/container.xml";
> +
> +       GsfOutput* containerFile = UT_go_file_create (containerPath.utf8_str (), NULL);
> +       GsfXMLOut * containerXml = gsf_xml_out_new (containerFile);
> +       gsf_xml_out_start_element (containerXml, "container");
> +       gsf_xml_out_add_cstr (containerXml, "version", "1.0");
> +       gsf_xml_out_add_cstr(containerXml, "xmlns", OCF201_NAMESPACE);
> +       gsf_xml_out_start_element (containerXml, "rootfiles");
> +       gsf_xml_out_start_element (containerXml, "rootfile");
> +       gsf_xml_out_add_cstr (containerXml, "full-path", "OEBPS/book.opf");
> +       gsf_xml_out_add_cstr(containerXml, "media-type", OPF_MIMETYPE);
> +       gsf_xml_out_end_element(containerXml);
> +       gsf_xml_out_end_element (containerXml);
> +       gsf_xml_out_end_element (containerXml);
> +       gsf_output_close (containerFile);
> +}
>
> -
> -
> -        g_free(tmpFilename);
> -      //  gsf_output_close(tempFile);
> -        gsf_output_close(oebpsDir);
> -        gsf_output_close(GSF_OUTPUT(m_outputFile));
> -        return UT_OK;
> +void IE_Exp_EPUB::writeStructure()
> +{
> +       m_oebpsDir = m_baseTempDir + "/OEBPS";
> +       UT_go_directory_create (m_oebpsDir.utf8_str (), 750, NULL);
> +       UT_UTF8String indexPath = m_oebpsDir + "/index.xhtml";
> +
> +       // Exporting document to XHTML using HTML export plugin
> +       char *szIndexPath = (char*)g_malloc(strlen(indexPath.utf8_str()) + 1);
> +       strcpy(szIndexPath, indexPath.utf8_str());
> +       IE_Exp_HTML *pExpHtml = new IE_Exp_HTML(getDoc());
> +       pExpHtml->suppressDialog(true);
> +       pExpHtml->setProps("embed-css:no;html4:no;");
> +       pExpHtml->writeFile(szIndexPath);
> +       g_free(szIndexPath);
>  }
>
> +void IE_Exp_EPUB::package()
> +{
> +       UT_UTF8String mimetypeFile = m_baseTempDir + "/mimetype";
> +       GsfOutput *mimetype = UT_go_file_create (mimetypeFile.utf8_str (), NULL);
> +       gsf_output_write(mimetype, strlen(EPUB_MIMETYPE), (const guint8*)EPUB_MIMETYPE);
> +       gsf_output_close (mimetype);
>
> +
> +       std::vector<UT_UTF8String> listing = getFileList(m_oebpsDir.substr(7, m_oebpsDir.length() -7));
> +
> +       UT_UTF8String opfPath = m_oebpsDir + "/book.opf";
> +       GsfOutput* opf = UT_go_file_create(opfPath.utf8_str(), NULL);
> +       GsfXMLOut* opfXml = gsf_xml_out_new(opf);
> +       gsf_xml_out_start_element (opfXml, "package");
> +       gsf_xml_out_add_cstr(opfXml, "version", "2.0");

How do we plan to override this for epub 3.0? Do we
- handle different versions in the same IE_Exp_EPUB class,
- or derive a IE_Exp_EPUB_3_0 from this one and override methods on demand?

Not big issue for now. Just want to make sure we donot overlook this.

> +       gsf_xml_out_add_cstr(opfXml, "xmlns", OPF201_NAMESPACE);
> +       gsf_xml_out_add_cstr(opfXml, "unique-identifier", getDoc()->getDocUUIDString());
> +
> +       gsf_xml_out_start_element(opfXml, "metadata");
> +       gsf_xml_out_add_cstr(opfXml, "xmlns:dc", DC_NAMESPACE);
> +       gsf_xml_out_add_cstr(opfXml,"xmlns:opf", OPF201_NAMESPACE);
> +
> +       gsf_xml_out_start_element(opfXml, "dc:title");
> +       // gsf_xml_out_add_cstr(opfXml, NULL, getDoc()->to
> +       gsf_xml_out_end_element(opfXml);
> +       gsf_xml_out_end_element(opfXml);
> +
> +       gsf_xml_out_start_element(opfXml, "manifest");
> +       for(std::vector<UT_UTF8String>::iterator i = listing.begin(); i != listing.end(); i++)
> +       {
> +               UT_UTF8String fullItemPath = m_oebpsDir + "/" + *i;
> +               gsf_xml_out_start_element(opfXml, "item");
> +               gsf_xml_out_add_cstr(opfXml, "id", "");
> +               gsf_xml_out_add_cstr(opfXml, "href", (*i).utf8_str());
> +               gsf_xml_out_add_cstr(opfXml, "media-type", UT_go_get_mime_type(fullItemPath.utf8_str()));
> +               gsf_xml_out_end_element(opfXml);
> +       }
> +       gsf_xml_out_end_element(opfXml);
> +
> +       gsf_xml_out_start_element(opfXml, "spine");
> +       gsf_xml_out_end_element(opfXml);
> +
> +
> +
> +
> +       gsf_xml_out_end_element(opfXml);
> +       gsf_output_close(opf);
> +
> +       for(std::vector<UT_UTF8String>::iterator i = listing.begin(); i != listing.end(); i++)
> +       {
> +               UT_DEBUGMSG(((*i).utf8_str()));
> +       }
> +
> +}
> +
> +std::vector<UT_UTF8String> IE_Exp_EPUB::getFileList(const UT_UTF8String &directory)
> +{
> +       std::vector<UT_UTF8String> result;
> +       std::vector<UT_UTF8String> dirs;
> +
> +       dirs.push_back(directory);
> +
> +       while (dirs.size() > 0)
> +       {
> +               UT_UTF8String currentDir = dirs.back();
> +               dirs.pop_back();
> +               GDir* baseDir = g_dir_open(currentDir.utf8_str(), 0, NULL);
> +
> +               gchar const *entryName = NULL;
> +               while ((entryName = g_dir_read_name(baseDir)) != NULL)
> +               {
> +                       UT_UTF8String entryFullPath = currentDir + "/";
> +                       entryFullPath += entryName;
> +
> +                       if (g_file_test(entryFullPath.utf8_str(), G_FILE_TEST_IS_DIR))
> +                       {
> +                               dirs.push_back(entryFullPath);
> +                       } else
> +                       {
> +                               result.push_back(entryFullPath.substr(directory.length() + 1, entryFullPath.length() - directory.length()));
> +                       }
> +               }
> +
> +               g_dir_close(baseDir);
> +
> +       }
> +
> +       return result;
> +}
> +
>
> Modified: abiword/trunk/plugins/epub/exp/xp/ie_exp_EPUB.h
> ===================================================================
> --- abiword/trunk/plugins/epub/exp/xp/ie_exp_EPUB.h     2011-06-13 03:11:09 UTC (rev 29813)
> +++ abiword/trunk/plugins/epub/exp/xp/ie_exp_EPUB.h     2011-06-13 07:28:28 UTC (rev 29814)
> @@ -21,6 +21,7 @@
>  #define IE_EXP_EPUB_H_
>
>  #include <string>
> +#include <vector>
>  // External includes
>  #include <gsf/gsf-output-stdio.h>
>  #include <gsf/gsf-outfile.h>
> @@ -33,8 +34,13 @@
>  #include <ie_exp_HTML.h>
>  #include <pd_Document.h>
>  #include <ut_go_file.h>
> +#include <ut_vector.h>
>
>  #define EPUB_MIMETYPE "application/epub+zip"
> +#define OPF_MIMETYPE "application/oebps-package+xml"
> +#define OCF201_NAMESPACE "urn:oasis:names:tc:opendocument:xmlns:container"
> +#define OPF201_NAMESPACE "http://www.idpf.org/2007/opf"
> +#define DC_NAMESPACE "http://purl.org/dc/elements/1.1/"
>
>
>  class IE_Exp_EPUB : public IE_Exp {
> @@ -47,8 +53,12 @@
>        virtual UT_Error _writeDocument();
>
>  private:
> -    GsfOutfile *m_outputFile;
> -
> +       UT_UTF8String m_baseTempDir;
> +       UT_UTF8String m_oebpsDir;
> +       void writeStructure();
> +       void writeContainer();
> +       void package();
> +       static std::vector<UT_UTF8String> getFileList(const UT_UTF8String &directory);
>  };
>
>
>
> -----------------------------------------------
> To unsubscribe from this list, send a message to
> abisource-cvs-commit-request@abisource.com with the word
> unsubscribe in the message body.
>

-- 
Thanks & regards
Xun Sun
Received on Mon Jun 13 11:51:40 2011

This archive was generated by hypermail 2.1.8 : Mon Jun 13 2011 - 11:51:40 CEST