/** * Write the transformed xml document out to a file descriptor. * @param xml The xml document * @param xsl The xml stylesheet * @param params The transform parameters * @param fd The source xml input descriptor * @return @c TRUE if successful, @c FALSE if an error occurs. * @ingroup EXML_XSLT_Group */ int exml_transform_fd_write( EXML *xml, EXML_XSL *xsl, const char *params[], int fd ) { int ret; xmlDocPtr res, doc; CHECK_PARAM_POINTER_RETURN("xml", xml, FALSE); CHECK_PARAM_POINTER_RETURN("xsl", xsl, FALSE); exml_doc_write(xml, &doc); res = xsltApplyStylesheet(xsl->cur, doc, params); xmlFreeDoc(doc); if( !res ) { return FALSE; } ret = xsltSaveResultToFd(fd, res, xsl->cur); xmlFreeDoc(res); xsltCleanupGlobals(); if( ret < 0 ) return FALSE; return TRUE; }
void Docbook2XhtmlGeneratorJob::run() { UMLDoc* umlDoc = UMLApp::app()->document(); xsltStylesheetPtr cur = NULL; xmlDocPtr doc, res; const char *params[16 + 1]; int nbparams = 0; params[nbparams] = NULL; umlDoc->writeToStatusBar(i18n("Exporting to XHTML...")); QString xsltFileName(KGlobal::dirs()->findResource("appdata", QLatin1String("docbook2xhtml.xsl"))); uDebug() << "XSLT file is'" << xsltFileName << "'"; QFile xsltFile(xsltFileName); xsltFile.open(QIODevice::ReadOnly); QString xslt = QString::fromLatin1(xsltFile.readAll()); uDebug() << "XSLT is'" << xslt << "'"; xsltFile.close(); QString localXsl = KGlobal::dirs()->findResource("data", QLatin1String("ksgmltools2/docbook/xsl/html/docbook.xsl")); uDebug() << "Local xsl is'" << localXsl << "'"; if (!localXsl.isEmpty()) { localXsl = QLatin1String("href=\"file://") + localXsl + QLatin1String("\""); xslt.replace(QRegExp(QLatin1String("href=\"http://[^\"]*\"")), localXsl); } KTemporaryFile tmpXsl; tmpXsl.setAutoRemove(false); tmpXsl.open(); QTextStream str (&tmpXsl); str << xslt; str.flush(); xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; uDebug() << "Parsing stylesheet " << tmpXsl.fileName(); cur = xsltParseStylesheetFile((const xmlChar *)tmpXsl.fileName().toLatin1().constData()); uDebug() << "Parsing file " << m_docbookUrl.path(); doc = xmlParseFile((const char*)(m_docbookUrl.path().toUtf8())); uDebug() << "Applying stylesheet "; res = xsltApplyStylesheet(cur, doc, params); KTemporaryFile tmpXhtml; tmpXhtml.setAutoRemove(false); tmpXhtml.open(); uDebug() << "Writing HTML result to temp file: " << tmpXhtml.fileName(); xsltSaveResultToFd(tmpXhtml.handle(), res, cur); xsltFreeStylesheet(cur); xmlFreeDoc(res); xmlFreeDoc(doc); xsltCleanupGlobals(); xmlCleanupParser(); emit xhtmlGenerated(tmpXhtml.fileName()); }
void DocbookGeneratorJob::run() { UMLApp* app = UMLApp::app(); UMLDoc* umlDoc = app->document(); //write the XMI model in an in-memory char* string QString xmi; QTextStream xmiStream(&xmi, QIODevice::WriteOnly); #if QT_VERSION >= 0x050000 QTemporaryFile file; // we need this tmp file if we are writing to a remote file #else KTemporaryFile file; // we need this tmp file if we are writing to a remote file #endif file.setAutoRemove(false); // lets open the file for writing if (!file.open()) { uError() << "There was a problem saving file" << file.fileName(); return; } umlDoc->saveToXMI(file); // save the xmi stuff to it xsltStylesheetPtr cur = NULL; xmlDocPtr doc, res; const char *params[16 + 1]; int nbparams = 0; params[nbparams] = NULL; #if QT_VERSION >= 0x050000 QString xsltFile(QStandardPaths::locate(QStandardPaths::DataLocation, QLatin1String("xmi2docbook.xsl"))); #else QString xsltFile(KGlobal::dirs()->findResource("appdata", QLatin1String("xmi2docbook.xsl"))); #endif xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; cur = xsltParseStylesheetFile((const xmlChar *)xsltFile.toLatin1().constData()); doc = xmlParseFile((const char*)(file.fileName().toUtf8())); res = xsltApplyStylesheet(cur, doc, params); #if QT_VERSION >= 0x050000 QTemporaryFile tmpDocBook; #else KTemporaryFile tmpDocBook; #endif tmpDocBook.setAutoRemove(false); tmpDocBook.open(); umlDoc->writeToStatusBar(i18n("Exporting to DocBook...")); xsltSaveResultToFd(tmpDocBook.handle(), res, cur); xsltFreeStylesheet(cur); xmlFreeDoc(res); xmlFreeDoc(doc); xsltCleanupGlobals(); xmlCleanupParser(); emit docbookGenerated(tmpDocBook.fileName()); }