UT_Error IE_Imp_EPUB::readMetadata() { GsfInput* metaInf = gsf_infile_child_by_name(m_epub, "META-INF"); if (metaInf == NULL) { UT_DEBUGMSG(("Can`t open container META-INF dir\n")); return UT_ERROR; } GsfInput* meta = gsf_infile_child_by_name(GSF_INFILE(metaInf), "container.xml"); if (meta == NULL) { UT_DEBUGMSG(("Can`t open container metadata\n")); return UT_ERROR; } size_t metaSize = gsf_input_size(meta); if (metaSize == 0) { UT_DEBUGMSG(("Container metadata file is empty\n")); return UT_ERROR; } gchar* metaXml = (gchar*) gsf_input_read(meta, metaSize, NULL); std::string rootfilePath; UT_XML metaParser; ContainerListener containerListener; metaParser.setListener(&containerListener); if (metaParser.sniff(metaXml, metaSize, "container")) { UT_DEBUGMSG(("Parsing container.xml file\n")); metaParser.parse(metaXml, metaSize); } else { UT_DEBUGMSG(("Incorrect container.xml file\n")); return UT_ERROR; } m_rootfilePath = containerListener.getRootFilePath(); g_object_unref(G_OBJECT(meta)); g_object_unref(G_OBJECT(metaInf)); return UT_OK; }
UT_Error IE_Imp_EPUB::readPackage() { gchar **aname = g_strsplit(m_rootfilePath.c_str(), G_DIR_SEPARATOR_S, 0); GsfInput* opf = gsf_infile_child_by_aname(m_epub, (const char**) aname); UT_DEBUGMSG(("Getting parent\n")); GsfInfile* opfParent = gsf_input_container(opf); m_opsDir = std::string(gsf_input_name(GSF_INPUT(opfParent))); UT_DEBUGMSG(("OPS dir: %s\n", m_opsDir.c_str())); if (opf == NULL) { UT_DEBUGMSG(("Can`t open .opf file\n")); return UT_ERROR; } size_t opfSize = gsf_input_size(opf); gchar* opfXml = (gchar*) gsf_input_read(opf, opfSize, NULL); UT_XML opfParser; OpfListener opfListener; opfParser.setListener(&opfListener); if (opfParser.sniff(opfXml, opfSize, "package")) { UT_DEBUGMSG(("Parsing opf file\n")); opfParser.parse(opfXml, opfSize); } else { UT_DEBUGMSG(("Incorrect opf file found \n")); return UT_ERROR; } g_strfreev(aname); g_object_unref(G_OBJECT(opf)); //g_object_unref(G_OBJECT(opfParent)); m_spine = opfListener.getSpine(); m_manifestItems = opfListener.getManifestItems(); return UT_OK; }