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

KDocTools

  • kdoctools
xslt_help.cpp
Go to the documentation of this file.
1#include "xslt_help.h"
2#include "xslt.h"
3
4#include <libxslt/xsltconfig.h>
5#include <libxslt/xsltInternals.h>
6#include <libxslt/transform.h>
7#include <libxslt/xsltutils.h>
8#include <libxml/xmlIO.h>
9#include <libxml/parserInternals.h>
10#include <libxml/catalog.h>
11#include <kdebug.h>
12#include <kstandarddirs.h>
13#include <QtCore/QDate>
14#include <QtCore/QDir>
15#include <QtCore/QRegExp>
16#include <kcomponentdata.h>
17#include <klocale.h>
18#include <assert.h>
19#include <kfilterbase.h>
20#include <kfilterdev.h>
21#include <QtCore/QTextCodec>
22#include <stdlib.h>
23#include <config.h>
24#include <stdarg.h>
25#include <kcharsets.h>
26#include <kurl.h>
27
28
29static bool readCache( const QString &filename,
30 const QString &cache, QString &output)
31{
32 kDebug( 7119 ) << filename << " " << cache;
33 KGlobal::dirs()->addResourceType("dtd", "data", "ksgmltools2/");
34 if ( !compareTimeStamps( filename, cache ) )
35 return false;
36 if ( !compareTimeStamps( KStandardDirs::locate( "dtd", "customization/kde-chunk.xsl"), cache ) )
37 return false;
38
39 kDebug( 7119 ) << "create filter";
40 QIODevice *fd = ::getBZip2device(cache);
41 if ( !fd )
42 return false;
43
44 if (!fd->open(QIODevice::ReadOnly))
45 {
46 delete fd;
47 QFile::remove(cache);
48 return false;
49 }
50
51 kDebug( 7119 ) << "reading";
52
53 char buffer[32000];
54 int n;
55 QByteArray text;
56 // Also end loop in case of error, when -1 is returned
57 while ( ( n = fd->read(buffer, 31900) ) > 0)
58 {
59 buffer[n] = 0;
60 text += buffer;
61 }
62 kDebug( 7119 ) << "read " << text.length();
63 fd->close();
64
65 output = QString::fromUtf8( text );
66 delete fd;
67
68 if (n == -1)
69 return false;
70
71 kDebug( 7119 ) << "finished ";
72
73 return true;
74}
75
76QString lookForCache( const QString &filename )
77{
78 kDebug() << "lookForCache " << filename;
79 assert( filename.endsWith( QLatin1String(".docbook") ) );
80 assert( QDir::isAbsolutePath(filename));
81 QString cache = filename.left( filename.length() - 7 );
82 QString output;
83 if ( readCache( filename, cache + "cache.bz2", output) )
84 return output;
85#ifdef Q_WS_WIN
86 QFileInfo fi(filename);
87 // make sure filenames do not contain the base path, otherwise
88 // accessing user data from another location invalids cached files.
89 // Accessing user data under a different path is possible
90 // when using usb sticks - this may affect unix/mac systems also
91 cache = '/' + fi.absolutePath().remove(KStandardDirs::installPath("html"),Qt::CaseInsensitive).replace('/','_') + '_' + fi.baseName() + '.';
92#endif
93 if ( readCache( filename,
94 KStandardDirs::locateLocal( "cache",
95 "kio_help" + cache +
96 "cache.bz2" ), output ) )
97 return output;
98
99 return QString();
100}
101
102bool compareTimeStamps( const QString &older, const QString &newer )
103{
104 QFileInfo _older( older );
105 QFileInfo _newer( newer );
106 assert( _older.exists() );
107 if ( !_newer.exists() )
108 return false;
109 return ( _newer.lastModified() > _older.lastModified() );
110}
KStandardDirs::installPath
static QString installPath(const char *type)
KStandardDirs::addResourceType
bool addResourceType(const char *type, const char *basetype, const char *relativename, bool priority=true)
KStandardDirs::locate
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
KStandardDirs::locateLocal
static QString locateLocal(const char *type, const QString &filename, bool createDir, const KComponentData &cData=KGlobal::mainComponent())
QIODevice
output
void output(QList< Action > actions, QHash< QString, QString > domain)
kDebug
#define kDebug
kcharsets.h
kcomponentdata.h
kdebug.h
kfilterbase.h
kfilterdev.h
klocale.h
kstandarddirs.h
kurl.h
KGlobal::dirs
KStandardDirs * dirs()
xslt.h
getBZip2device
QIODevice * getBZip2device(const QString &fileName)
Definition: xslt_kde.cpp:43
lookForCache
QString lookForCache(const QString &filename)
Definition: xslt_help.cpp:76
readCache
static bool readCache(const QString &filename, const QString &cache, QString &output)
Definition: xslt_help.cpp:29
compareTimeStamps
bool compareTimeStamps(const QString &older, const QString &newer)
Compares two files and returns true if.
Definition: xslt_help.cpp:102
xslt_help.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDocTools

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal