Skip to content

Commit

Permalink
Update cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Nov 20, 2014
1 parent 4a4dc6b commit d663599
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
60 changes: 31 additions & 29 deletions src/mapserver/qgsconfigcache.cpp
Expand Up @@ -42,26 +42,24 @@ QgsConfigCache::~QgsConfigCache()

QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& filePath )
{
QgsServerProjectParser* p = mServerConfigCache.object( filePath );
if ( !p )
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}
p = new QgsServerProjectParser( doc, filePath );
mServerConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
return 0;
}
return p;
return new QgsServerProjectParser( doc, filePath );
}

QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
{
QgsWCSProjectParser* p = mWCSConfigCache.object( filePath );
if ( !p )
{
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}
p = new QgsWCSProjectParser( filePath );
mWCSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
Expand All @@ -76,6 +74,11 @@ QgsWFSProjectParser* QgsConfigCache::wfsConfiguration( const QString& filePath )
QgsWFSProjectParser* p = mWFSConfigCache.object( filePath );
if ( !p )
{
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}
p = new QgsWFSProjectParser( filePath );
mWFSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
Expand Down Expand Up @@ -117,12 +120,6 @@ QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath, c

QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
{
// first get cache
QDomDocument* xmlDoc = mXmlDocumentCache.object( filePath );
if ( xmlDoc )
return xmlDoc;

// i it's first access
//first open file
QFile configFile( filePath );
if ( !configFile.exists() )
Expand All @@ -136,26 +133,31 @@ QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
QgsMessageLog::logMessage( "Error, cannot open configuration file '" + filePath + "'", "Server", QgsMessageLog::CRITICAL );
return 0;
}

//then create xml document
xmlDoc = new QDomDocument();
QString errorMsg;
int line, column;
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )

// first get cache
QDomDocument* xmlDoc = mXmlDocumentCache.object( filePath );
if ( !xmlDoc )
{
QgsMessageLog::logMessage( "Error parsing file '" + filePath +
QString( "': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), "Server", QgsMessageLog::CRITICAL );
delete xmlDoc;
return 0;
//then create xml document
xmlDoc = new QDomDocument();
QString errorMsg;
int line, column;
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )
{
QgsMessageLog::logMessage( "Error parsing file '" + filePath +
QString( "': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), "Server", QgsMessageLog::CRITICAL );
delete xmlDoc;
return 0;
}
mXmlDocumentCache.insert( filePath, xmlDoc );
mFileSystemWatcher.addPath( filePath );
}
mXmlDocumentCache.insert( filePath, xmlDoc );
return xmlDoc;
}

void QgsConfigCache::removeChangedEntry( const QString& path )
{
mXmlDocumentCache.remove( path );
mServerConfigCache.remove( path );
mWMSConfigCache.remove( path );
mWFSConfigCache.remove( path );
mWCSConfigCache.remove( path );
Expand Down
1 change: 0 additions & 1 deletion src/mapserver/qgsconfigcache.h
Expand Up @@ -53,7 +53,6 @@ class QgsConfigCache: public QObject
QDomDocument* xmlDocument( const QString& filePath );

QCache<QString, QDomDocument> mXmlDocumentCache;
QCache<QString, QgsServerProjectParser> mServerConfigCache;
QCache<QString, QgsWMSConfigParser> mWMSConfigCache;
QCache<QString, QgsWFSProjectParser> mWFSConfigCache;
QCache<QString, QgsWCSProjectParser> mWCSConfigCache;
Expand Down
3 changes: 2 additions & 1 deletion src/mapserver/qgswcsprojectparser.cpp
Expand Up @@ -16,13 +16,14 @@
***************************************************************************/

#include "qgswcsprojectparser.h"
#include "qgsconfigcache.h"
#include "qgsconfigparserutils.h"
#include "qgsconfigcache.h"
#include "qgsrasterlayer.h"

QgsWCSProjectParser::QgsWCSProjectParser( const QString& filePath )
{
QgsServerProjectParser* mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
}

QgsWCSProjectParser::~QgsWCSProjectParser()
Expand Down
3 changes: 2 additions & 1 deletion src/mapserver/qgswfsprojectparser.cpp
Expand Up @@ -16,14 +16,15 @@
***************************************************************************/

#include "qgswfsprojectparser.h"
#include "qgsconfigcache.h"
#include "qgsconfigparserutils.h"
#include "qgsconfigcache.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectordataprovider.h"

QgsWFSProjectParser::QgsWFSProjectParser( const QString& filePath )
{
QgsServerProjectParser* mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
}

QgsWFSProjectParser::~QgsWFSProjectParser()
Expand Down
2 changes: 1 addition & 1 deletion src/mapserver/qgswmsprojectparser.cpp
Expand Up @@ -42,7 +42,7 @@
QgsWMSProjectParser::QgsWMSProjectParser( const QString& filePath )
: QgsWMSConfigParser()
{
QgsServerProjectParser* mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
mLegendLayerFont.fromString( mProjectParser->firstComposerLegendElement().attribute( "layerFont" ) );
mLegendItemFont.fromString( mProjectParser->firstComposerLegendElement().attribute( "itemFont" ) );
createTextAnnotationItems();
Expand Down

0 comments on commit d663599

Please sign in to comment.