00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qstring.h>
00019 #include <qdir.h>
00020
00021 #include <string>
00022 #include <libxml/xmlmemory.h>
00023 #include <libxml/debugXML.h>
00024 #include <libxml/HTMLtree.h>
00025 #include <libxml/xmlIO.h>
00026 #include <libxml/DOCBparser.h>
00027 #include <libxml/xinclude.h>
00028 #include <libxml/catalog.h>
00029 #include <libxslt/xslt.h>
00030 #include <libxslt/xsltInternals.h>
00031 #include <libxslt/transform.h>
00032 #include <libxslt/xsltutils.h>
00033 #include <stdio.h>
00034
00035
00036 #include "xmlTools.h"
00037 #include "../config.h"
00038
00039
00040 QString fixXMLString( QString text )
00041 {
00042
00043
00044 text.replace("&", "&");
00045 text.replace("\"",""");
00046 text.replace("'", "'");
00047 text.replace("<", "<");
00048 text.replace(">", ">");
00049 return text;
00050 }
00051
00052 void transformXMLtoHTML( QString outputPath,
00053 QString theme)
00054 {
00055 xmlSubstituteEntitiesDefault(1);
00056 xmlLoadExtDtdDefaultValue = 1;
00057 xsltStylesheetPtr cur = xsltParseStylesheetFile( (const xmlChar *) QString(THEMES_PATH + theme + "/theme.xsl").ascii() );
00058 xmlDocPtr doc = xmlParseFile( QString(outputPath + "/Album.xml").ascii() );
00059 const char* params[3];
00060 params[0] = "outputPath";
00061 QString quotedPath = outputPath;
00062 params[1] = quotedPath.prepend('\"').append('\"').ascii();
00063 params[2] = NULL;
00064 xmlDocPtr res = xsltApplyStylesheet( cur, doc, params);
00065 xsltFreeStylesheet( cur );
00066 xmlFreeDoc( res );
00067 xmlFreeDoc( doc );
00068 xsltCleanupGlobals();
00069 xmlCleanupParser();
00070 }
00071
00072 void updateXML( QString inputPath )
00073 {
00074 xmlSubstituteEntitiesDefault(1);
00075 xmlLoadExtDtdDefaultValue = 1;
00076
00077 xsltStylesheetPtr stylesheet;
00078 xmlDocPtr inputDoc, outputDoc;
00079
00080 stylesheet = xsltParseStylesheetFile( (const xmlChar *) QString(XMLCONVERSION_PATH + "update.xsl").ascii() );
00081
00082 inputDoc = xmlParseFile( QString(inputPath + "/Album.xml").ascii() );
00083
00084 const char* params[3];
00085 params[0] = "outputPath";
00086 QString quotedPath = inputPath;
00087 params[1] = quotedPath.prepend('\"').append('\"').ascii();
00088 params[2] = NULL;
00089
00090
00091 QDir workingDir( inputPath );
00092
00093 int iterations = 0;
00094 while(true)
00095 {
00096 iterations++;
00097
00098
00099 outputDoc = xsltApplyStylesheet( stylesheet, inputDoc, params );
00100
00101
00102
00103 if(workingDir.exists( "Album.updated" ))
00104 break;
00105
00106
00107 xmlFreeDoc( inputDoc );
00108
00109
00110 inputDoc = outputDoc;
00111 }
00112
00113
00114 workingDir.remove( "Album.updated" );
00115
00116
00117 if(iterations > 1)
00118 {
00119
00120 FILE* outfile = fopen( QString(inputPath + "/Album.xml").ascii(), "w" );
00121 xsltSaveResultToFile( outfile, inputDoc, stylesheet);
00122 fclose( outfile );
00123 }
00124
00125
00126 xsltFreeStylesheet( stylesheet );
00127 xmlFreeDoc( inputDoc );
00128 xmlFreeDoc( outputDoc );
00129 xsltCleanupGlobals();
00130 xmlCleanupParser();
00131 }
00132
00133
00134