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

xmlTools.cpp File Reference

#include <qstring.h>
#include <qdir.h>
#include <string>
#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/HTMLtree.h>
#include <libxml/xmlIO.h>
#include <libxml/DOCBparser.h>
#include <libxml/xinclude.h>
#include <libxml/catalog.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
#include <stdio.h>
#include "xmlTools.h"
#include "../config.h"

Include dependency graph for xmlTools.cpp:

Include dependency graph

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)
void updateXML (QString inputPath)


Function Documentation

QString fixXMLString QString  text  ) 
 

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

Definition at line 40 of file xmlTools.cpp.

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

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

void transformXMLtoHTML QString  outputPath,
QString  theme
 

Definition at line 52 of file xmlTools.cpp.

References THEMES_PATH.

Referenced by Album::exportToDisk().

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 }

void updateXML QString  inputPath  ) 
 

Definition at line 72 of file xmlTools.cpp.

References XMLCONVERSION_PATH.

Referenced by Album::importFromDisk().

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   //iterate until Album.updated file is created
00091   QDir workingDir( inputPath );
00092   
00093   int iterations = 0;
00094   while(true)
00095   {
00096     iterations++;
00097     
00098     //apply the stylesheet
00099     outputDoc = xsltApplyStylesheet( stylesheet, inputDoc, params );
00100 
00101     //if Album.updated file now exists we have already completed the last iteration, 
00102     //meaning the input document is the most up-to-date so break out of loop
00103     if(workingDir.exists( "Album.updated" ))
00104       break;
00105         
00106     //free input  doc
00107     xmlFreeDoc( inputDoc );
00108    
00109     //swap input and output
00110     inputDoc = outputDoc;   
00111   }
00112   
00113   //remove updated file
00114   workingDir.remove( "Album.updated" );
00115 
00116   //if we made more than one iteration then changes were applied
00117   if(iterations > 1)
00118   {
00119     //output updated xml file
00120     FILE* outfile = fopen( QString(inputPath + "/Album.xml").ascii(), "w" );
00121     xsltSaveResultToFile( outfile, inputDoc, stylesheet);
00122     fclose( outfile );
00123   }
00124   
00125   //memory
00126   xsltFreeStylesheet( stylesheet );
00127   xmlFreeDoc( inputDoc );
00128   xmlFreeDoc( outputDoc );
00129   xsltCleanupGlobals();
00130   xmlCleanupParser();
00131 }


Generated on Thu Nov 13 00:11:05 2003 for AlbumShaper by doxygen 1.3.4