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(" - ");
    }
}
void FoxGroundDocument::SetBaseFileDoc(const QString file) {

    QFileInfo localfile(file);
    if (!localfile.exists()) {
        CurrentRunDoc = UNKNOW;
        return;
    }
    document_file = file;
    //// try on pole...
    bool poleisrun = false;
    POLE::Storage storage(file.toLocal8Bit());
    if (storage.open()) {
        QBuffer basestore;
        if (Conversion::readStreamPole(storage, "/SummaryInformation", basestore)) {
            LEInputStream *sis_baseSummaryInformation = new LEInputStream(&basestore);
            poleisrun = true;
            CurrentRunDoc = OFFICEMSO;
            document_name = "DOC";
        }
    }
    QByteArray x;
    QFile *f = new QFile(file);
    if (f->open(QIODevice::ReadOnly)) {
        x = f->readAll();
    }
    f->close();
    const QByteArray data = x;
    QDomDocument document;
    QString c;
    int d, o;
    bool xmlbased = false;
    if (document.setContent(data, true, &c)) {
        /// not xml based...
        xmlbased = true;
    }
    const QByteArray rtfsearch = x.mid(0, 5).simplified();
    /// qDebug() << "rtfsearch :" << rtfsearch;
    //// no office family .. doc
    if (!poleisrun) {
        if (xmlbased && data.indexOf("encoding=") != -1) {
            if (data.indexOf("DOCTYPE html") > 0) {
                CurrentRunDoc = HTML;
                document_name = "HTML";
            } else {
                document_name = "XML";
                CurrentRunDoc = XML;
            }
        } else if (rtfsearch == "{\\rtf") {
            CurrentRunDoc = RTF;
            document_name = "RTF";
        } else if (data.mid(0, 4) == "%PDF") {
            if (bin_pdftohtml.size() > 3) {
                CurrentRunDoc = PDF;
                document_name = "PDF";
            } else {
                CurrentRunDoc = UNKNOW;
            }
        } else if (data.mid(0, 2) == "PK") {
            KZip::Stream *unzip = new KZip::Stream(file);
            if (unzip->canread()) {
                unzipfileliste = unzip->filelist();
                corefile = unzip->listData();
                if (docitem("word/document.xml").size() > 20) {
                    CurrentRunDoc = DOCX;
                    document_name = "DOCX";
                } else if (docitem("content.xml").size() > 20) {
                    CurrentRunDoc = ODT;
                    document_name = "ODT";
                } else {
                    CurrentRunDoc = UNKNOW;
                }
            }
            unzip->~Stream();
            unzip = NULL;
        } else {
            CurrentRunDoc = UNKNOW;
        }
    }

    if (CurrentRunDoc == UNKNOW) {
        document_name = "NULL";
    }
}
Beispiel #3
0
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();
}