00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qstring.h>
00013 #include <qdir.h>
00014 #include <qfile.h>
00015 #include <qdragobject.h>
00016
00017 #include <iostream>
00018 #include <string>
00019 #include <libxml/xmlmemory.h>
00020 #include <libxml/debugXML.h>
00021 #include <libxml/HTMLtree.h>
00022 #include <libxml/xmlIO.h>
00023 #include <libxml/xinclude.h>
00024 #include <libxml/catalog.h>
00025 #include <libxslt/xslt.h>
00026 #include <libxslt/xsltInternals.h>
00027 #include <libxslt/transform.h>
00028 #include <libxslt/xsltutils.h>
00029 #include <stdio.h>
00030
00031
00032 #include "xmlTools.h"
00033 #include "../../config.h"
00034
00035
00036 QString fixXMLString( QString text )
00037 {
00038
00039
00040 text.replace("&", "&");
00041 text.replace("\"",""");
00042 text.replace("'", "'");
00043 text.replace("<", "<");
00044 text.replace(">", ">");
00045 text.replace("\n", " ");
00046 text.replace("\r", " ");
00047 return text;
00048 }
00049
00050 void transformXMLtoHTML( QString outputPath, QString theme, bool smallWebExport)
00051 {
00052 xmlSubstituteEntitiesDefault(1);
00053 xmlLoadExtDtdDefaultValue = 1;
00054 xsltStylesheetPtr cur = xsltParseStylesheetFile( (const xmlChar *) QString(THEMES_PATH + theme + "/theme.xsl").ascii() );
00055
00056 QString xmlFile = QString(outputPath + "/Album.xml");
00057 xmlDocPtr doc = xmlParseFile( QFile::encodeName(xmlFile) );
00058
00059 const char* params[5];
00060
00061 params[0] = "outputPath";
00062 QString quotedPath = outputPath;
00063
00064
00065
00066
00067
00068
00069 #ifndef Q_OS_WIN
00070 quotedPath = QUriDrag::localFileToUri( quotedPath );
00071 #endif
00072
00073 params[1] = quotedPath.prepend('\"').append('\"').ascii();
00074
00075 params[2] = "smallWebExport";
00076 if(smallWebExport)
00077 params[3] = "1";
00078 else
00079 params[3] = "0";
00080
00081 params[4] = NULL;
00082 xmlDocPtr res = xsltApplyStylesheet( cur, doc, params);
00083 xsltFreeStylesheet( cur );
00084 xmlFreeDoc( res );
00085 xmlFreeDoc( doc );
00086 xsltCleanupGlobals();
00087 xmlCleanupParser();
00088 }
00089
00090 void updateXML( QString inputPath )
00091 {
00092
00093 QDir tmpDir;
00094 if( !tmpDir.exists( XMLCONVERSION_PATH + "update.xsl" ) )
00095 {
00096 std::cout << "Can't find update.xsl! Skipping auto-update!\n";
00097 return;
00098 }
00099
00100 xmlSubstituteEntitiesDefault(1);
00101 xmlLoadExtDtdDefaultValue = 1;
00102
00103 xsltStylesheetPtr stylesheet;
00104 xmlDocPtr inputDoc, outputDoc;
00105
00106 stylesheet = xsltParseStylesheetFile( (const xmlChar *) QString(XMLCONVERSION_PATH + "update.xsl").ascii() );
00107
00108 QString xmlFile = QString( inputPath + "/Album.xml" );
00109 xmlFile = QDir::convertSeparators( xmlFile );
00110 inputDoc = xmlParseFile( QFile::encodeName(xmlFile) );
00111
00112 const char* params[3];
00113 params[0] = "outputPath";
00114
00115 QString quotedPath = inputPath;
00116
00117
00118
00119
00120
00121
00122 #ifndef Q_OS_WIN
00123 quotedPath = QUriDrag::localFileToUri( quotedPath );
00124 #endif
00125
00126
00127 params[1] = quotedPath.prepend('\"').append('\"').ascii();
00128
00129 params[2] = NULL;
00130
00131 std::cout.flush();
00132
00133
00134 QDir workingDir( inputPath );
00135
00136 int iterations = 0;
00137 while(true)
00138 {
00139 iterations++;
00140
00141
00142 outputDoc = xsltApplyStylesheet( stylesheet, inputDoc, params );
00143
00144
00145
00146 if(workingDir.exists( "Album.updated" ))
00147 break;
00148
00149
00150 xmlFreeDoc( inputDoc );
00151
00152
00153 inputDoc = outputDoc;
00154 }
00155
00156
00157 workingDir.remove( inputPath + "/Album.updated" );
00158
00159
00160 if(iterations > 1)
00161 {
00162
00163 FILE* outfile = fopen( QFile::encodeName(xmlFile), "w" );
00164 xsltSaveResultToFile( outfile, inputDoc, stylesheet);
00165 fclose( outfile );
00166 }
00167
00168
00169 xsltFreeStylesheet( stylesheet );
00170 xmlFreeDoc( inputDoc );
00171 xmlFreeDoc( outputDoc );
00172 xsltCleanupGlobals();
00173 xmlCleanupParser();
00174 }
00175
00176
00177