• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDocTools

xslt_help.cpp

Go to the documentation of this file.
00001 #include "xslt_help.h"
00002 #include "xslt.h"
00003 
00004 #include <libxslt/xsltconfig.h>
00005 #include <libxslt/xsltInternals.h>
00006 #include <libxslt/transform.h>
00007 #include <libxslt/xsltutils.h>
00008 #include <libxml/xmlIO.h>
00009 #include <libxml/parserInternals.h>
00010 #include <libxml/catalog.h>
00011 #include <kdebug.h>
00012 #include <kstandarddirs.h>
00013 #include <QtCore/QDate>
00014 #include <QtCore/QDir>
00015 #include <QtCore/QRegExp>
00016 #include <kcomponentdata.h>
00017 #include <klocale.h>
00018 #include <assert.h>
00019 #include <kfilterbase.h>
00020 #include <kfilterdev.h>
00021 #include <QtCore/QTextCodec>
00022 #include <stdlib.h>
00023 #include <config.h>
00024 #include <stdarg.h>
00025 #include <kcharsets.h>
00026 #include <kurl.h>
00027 
00028 
00029 static bool readCache( const QString &filename,
00030                        const QString &cache, QString &output)
00031 {
00032     kDebug( 7119 ) << filename << " " << cache;
00033     KGlobal::dirs()->addResourceType("dtd", "data", "ksgmltools2/");
00034     if ( !compareTimeStamps( filename, cache ) )
00035         return false;
00036     if ( !compareTimeStamps( KStandardDirs::locate( "dtd", "customization/kde-chunk.xsl"), cache ) )
00037         return false;
00038 
00039     kDebug( 7119 ) << "create filter";
00040     QIODevice *fd = ::getBZip2device(cache);
00041     if ( !fd )
00042         return false;
00043 
00044     if (!fd->open(QIODevice::ReadOnly))
00045     {
00046        delete fd;
00047        QFile::remove(cache);
00048        return false;
00049     }
00050 
00051     kDebug( 7119 ) << "reading";
00052 
00053     char buffer[32000];
00054     int n;
00055     QByteArray text;
00056     // Also end loop in case of error, when -1 is returned
00057     while ( ( n = fd->read(buffer, 31900) ) > 0)
00058     {
00059         buffer[n] = 0;
00060         text += buffer;
00061     }
00062     kDebug( 7119 ) << "read " << text.length();
00063     fd->close();
00064 
00065     output = QString::fromUtf8( text );
00066     delete fd;
00067 
00068     if (n == -1)
00069         return false;
00070 
00071     kDebug( 7119 ) << "finished ";
00072 
00073     return true;
00074 }
00075 
00076 QString lookForCache( const QString &filename )
00077 {
00078     kDebug() << "lookForCache " << filename;
00079     assert( filename.endsWith( QLatin1String(".docbook") ) );
00080     assert( QDir::isAbsolutePath(filename));
00081     QString cache = filename.left( filename.length() - 7 );
00082     QString output;
00083     if ( readCache( filename, cache + "cache.bz2", output) )
00084         return output;
00085 #ifdef Q_WS_WIN
00086     QFileInfo fi(filename);
00087     // make sure filenames do not contain the base path, otherwise
00088     // accessing user data from another location invalids cached files.
00089     // Accessing user data under a different path is possible
00090     // when using usb sticks - this may affect unix/mac systems also
00091     cache = '/' + fi.absolutePath().remove(KStandardDirs::installPath("html"),Qt::CaseInsensitive).replace('/','_') + '_' + fi.baseName() + '.';
00092 #endif
00093     if ( readCache( filename,
00094                     KStandardDirs::locateLocal( "cache",
00095                                  "kio_help" + cache +
00096                                  "cache.bz2" ), output ) )
00097         return output;
00098 
00099     return QString();
00100 }
00101 
00102 bool compareTimeStamps( const QString &older, const QString &newer )
00103 {
00104     QFileInfo _older( older );
00105     QFileInfo _newer( newer );
00106     assert( _older.exists() );
00107     if ( !_newer.exists() )
00108         return false;
00109     return ( _newer.lastModified() > _older.lastModified() );
00110 }

KDocTools

Skip menu "KDocTools"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal