Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

xmlTools.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

QString fixXMLString (QString text)
 Fix strings before exporting to XML such that & becomes &, etc...

void transformXMLtoHTML (QString outputPath, QString theme, bool smallWebExport)
void updateXML (QString inputPath)


Function Documentation

QString fixXMLString QString  text  ) 
 

Fix strings before exporting to XML such that & becomes &, etc...

Definition at line 36 of file xmlTools.cpp.

Referenced by Subalbum::exportToXML(), Photo::exportToXML(), and Album::exportToXML().

00037 { 00038 //the following checks are necessary before exporting 00039 //strings to XML. see http://hdf.ncsa.uiuc.edu/HDF5/XML/xml_escape_chars.html for details 00040 text.replace("&", "&amp;"); 00041 text.replace("\"","&quot;"); 00042 text.replace("'", "&apos;"); 00043 text.replace("<", "&lt;"); 00044 text.replace(">", "&gt;"); 00045 text.replace("\n", "&#10;"); 00046 text.replace("\r", "&#13;"); 00047 return text; 00048 }

void transformXMLtoHTML QString  outputPath,
QString  theme,
bool  smallWebExport
 

Definition at line 50 of file xmlTools.cpp.

References THEMES_PATH.

Referenced by Album::exportCompressedWebAlbum(), and Album::exportToDisk().

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 //For some reason libxslt has trouble handling filenames with spaces on Unix platforms (OSX, 00065 //Linux, FreeBSD?). this problem can be averted by converting the filename to a URI. Converting it 00066 //to a URI on windows using the qt method mangles the drive name though, so only convert to 00067 //URI on OSX. We need to nail this weirdness at some point and be consistant IMHO but for now 00068 //this works... 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 }

void updateXML QString  inputPath  ) 
 

Definition at line 90 of file xmlTools.cpp.

References XMLCONVERSION_PATH.

Referenced by Album::importFromDisk().

00091 { 00092 //skip updating the xml file if we can't find the update.xsl file 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 //For some reason libxslt has trouble handling filenames with spaces on Unix platforms (OSX, 00118 //Linux, FreeBSD?). this problem can be averted by converting the filename to a URI. Converting it 00119 //to a URI on windows using the qt method mangles the drive name though, so only convert to 00120 //URI on OSX. We need to nail this weirdness at some point and be consistant IMHO but for now 00121 //this works... 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 //iterate until Album.updated file is created 00134 QDir workingDir( inputPath ); 00135 00136 int iterations = 0; 00137 while(true) 00138 { 00139 iterations++; 00140 00141 //apply the stylesheet 00142 outputDoc = xsltApplyStylesheet( stylesheet, inputDoc, params ); 00143 00144 //if Album.updated file now exists we have already completed the last iteration, 00145 //meaning the input document is the most up-to-date so break out of loop 00146 if(workingDir.exists( "Album.updated" )) 00147 break; 00148 00149 //free input doc 00150 xmlFreeDoc( inputDoc ); 00151 00152 //swap input and output 00153 inputDoc = outputDoc; 00154 } 00155 00156 //remove updated file 00157 workingDir.remove( inputPath + "/Album.updated" ); 00158 00159 //if we made more than one iteration then changes were applied 00160 if(iterations > 1) 00161 { 00162 //output updated xml file 00163 FILE* outfile = fopen( QFile::encodeName(xmlFile), "w" ); 00164 xsltSaveResultToFile( outfile, inputDoc, stylesheet); 00165 fclose( outfile ); 00166 } 00167 00168 //memory 00169 xsltFreeStylesheet( stylesheet ); 00170 xmlFreeDoc( inputDoc ); 00171 xmlFreeDoc( outputDoc ); 00172 xsltCleanupGlobals(); 00173 xmlCleanupParser(); 00174 }


Generated on Sun Mar 4 19:43:04 2007 for AlbumShaper by doxygen 1.3.7