HtmlDocument::HtmlDocument(const QString docfilename, bool bypasscontroll) : DObject() { bypass_validate = bypasscontroll; this->SetBaseFileDoc(docfilename); QFileInfo infofromfile(docfilename); HTMLSTREAM.clear(); bool is_loading = false; bool debugmodus = (DEBUGMODUS == 1) ? true : false; console(QString("Init talking this class. %1..").arg(this->name()), 0); bool doc_continue = true; console(QString("OpenFile: %1").arg(docfilename)); this->SetStyle("docx2html.xsl"); KZip::Stream *unzip = new KZip::Stream(docfilename); if (debugmodus) { unzip->explode_todir(this->get_cachedir(), 1); } if (unzip->canread() && docx_validator(unzip->filelist())) { console(QString("Zip is open OK docx validate ok.")); corefile = unzip->listData(); unzip->~Stream(); unzip = NULL; QByteArray xmldataword = docitem("word/document.xml"); const QString rootxmlfile = QString("%1index.xml").arg(this->get_cachedir()); const QString indexhtmlfile = QString("%1index.html").arg(this->get_cachedir()); QFile::remove(rootxmlfile); QFile::remove(indexhtmlfile); QFile::remove(TEMPFILEXSLTRESULTS); /// if exist.. xslt2 temp file on cache up if (xmldataword.size() > 0) { doc_continue = Tools::_write_file(rootxmlfile, xmldataword); } ///// contibue ok... if (doc_continue) { /// convert xslt now console(QString("Init xslt 1 convert class DOCXML::XsltVersion1.")); QStringList xsltparam; DOCXML::Xslt xsltOne(xsltparam); if (xsltOne.TransformXSLT_1(this->getStyleFile(), rootxmlfile)) { HTMLSTREAM = xsltOne.streamUtf8(); scanimage(); is_loading = Tools::_write_file(indexhtmlfile, HTMLSTREAM, "utf-8"); if (!is_loading) { this->setError(QString("Unable to write on home cache..")); } else { lastreturnfile_html = indexhtmlfile; QString success = QString("Valid document size: %1.").arg( SystemSecure::bytesToSize( HTMLSTREAM.size())); console(success); } } else { this->setError(QString("Register a xslt 1 error .. activate debug to find..")); } } } else { is_loading = false; this->setError(QString("Document bad format unable to open as zip...")); } LASTERRORMSG = ""; /// error from image not open format ... if (this->basicError().size() > 0) { LASTERRORMSG = this->basicError().join(" - "); } }
DocxZipHandler::DocxZipHandler(const QString docfilename) : Document("DOCX"), is_loading(false) { QFileInfo infofromfile(docfilename); bool debugmodus = (DEBUGMODUS == 1)? true : false; console(QString("Init talking this class. %1..").arg(this->name()), 0); bool doc_continue = true; console(QString("OpenFile: %1").arg(docfilename)); this->SetBaseFileDoc(docfilename); this->SetStyle(__localDOCXSTYLE__); KZip::Stream *unzip = new KZip::Stream(docfilename); if (debugmodus) { unzip->explode_todir(cache_dir, 1); } if (unzip->canread() && docx_validator(unzip->filelist())) { console(QString("Zip is open OK doc valid ....")); corefile = unzip->listData(); unzip->~Stream(); unzip = NULL; QByteArray xmldataword = docitem("word/document.xml"); const QString rootxmlfile = QString("%1index.xml").arg(cache_dir); const QString indexhtmlfile = QString("%1index.html").arg(cache_dir); QFile::remove(rootxmlfile); QFile::remove(indexhtmlfile); if (xmldataword.size() > 0) { doc_continue = Tools::_write_file(rootxmlfile, xmldataword); } ///// contibue ok... if (doc_continue && !bin_xsltproc.isEmpty()) { /// convert xslt now console(QString("Init xslt convert...%1.").arg(bin_xsltproc)); QStringList xsltparam; xsltparam << "--param"; xsltparam << "convert_time"; xsltparam << QString("'%1'").arg(Tools::TimeNow()); xsltparam << "--output"; xsltparam << indexhtmlfile; xsltparam << style_file; xsltparam << rootxmlfile; /// xslt param --param data_path2 "'e:/tmp/stu/xx'" const QString errorcmd = execlocal(bin_xsltproc, xsltparam); if (errorcmd.isEmpty()) { console(QString("Xslt convert successful document...")); } else { console(QString("Xslt convert... say: %1").arg(errorcmd)); } } QByteArray prehtml = this->loadbinfile(indexhtmlfile); HTMLSTREAM = QString::fromUtf8(prehtml.constData()); if (doc_continue && prehtml.size() > 0) { scanimage(); /// insert image on html embedet is_loading = Tools::_write_file(indexhtmlfile, HTMLSTREAM, "utf-8"); console(QString("Write last file: %1").arg(indexhtmlfile)); } if (!doc_continue) { is_loading = false; console(QString("Error on Buffer...."), 3); } } else { is_loading = false; console(QString("Document bad format "), 3); } clean(); }