Skip to content
Permalink
Browse files

Merge pull request #1689 from rldhont/server_cache_project_config

[QGIS-Server] Enhance config cache
  • Loading branch information
mhugent committed Nov 21, 2014
2 parents 6c836f0 + d663599 commit 7de1dff387a37696b4fc7db331bc35c92bd4b110
@@ -43,6 +43,10 @@ QgsConfigCache::~QgsConfigCache()
QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& filePath )
{
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}
return new QgsServerProjectParser( doc, filePath );
}

@@ -56,7 +60,7 @@ QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
{
return 0;
}
p = new QgsWCSProjectParser( doc, filePath );
p = new QgsWCSProjectParser( filePath );
mWCSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
@@ -75,8 +79,7 @@ QgsWFSProjectParser* QgsConfigCache::wfsConfiguration( const QString& filePath )
{
return 0;
}

p = new QgsWFSProjectParser( doc, filePath );
p = new QgsWFSProjectParser( filePath );
mWFSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
@@ -105,7 +108,7 @@ QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath, c
}
else
{
p = new QgsWMSProjectParser( doc, filePath );
p = new QgsWMSProjectParser( filePath );
}
mWMSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
@@ -130,23 +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
QDomDocument* 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 );
}
return xmlDoc;
}

void QgsConfigCache::removeChangedEntry( const QString& path )
{
mXmlDocumentCache.remove( path );
mWMSConfigCache.remove( path );
mWFSConfigCache.remove( path );
mWCSConfigCache.remove( path );
@@ -52,6 +52,7 @@ class QgsConfigCache: public QObject
/**Returns xml document for project file / sld or 0 in case of errors*/
QDomDocument* xmlDocument( const QString& filePath );

QCache<QString, QDomDocument> mXmlDocumentCache;
QCache<QString, QgsWMSConfigParser> mWMSConfigCache;
QCache<QString, QgsWFSProjectParser> mWFSConfigCache;
QCache<QString, QgsWCSProjectParser> mWCSConfigCache;
@@ -16,11 +16,14 @@
***************************************************************************/

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

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

QgsWCSProjectParser::~QgsWCSProjectParser()
@@ -29,19 +32,19 @@ QgsWCSProjectParser::~QgsWCSProjectParser()

void QgsWCSProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
mProjectParser.serviceCapabilities( parentElement, doc, "WCS" );
mProjectParser->serviceCapabilities( parentElement, doc, "WCS" );
}

QString QgsWCSProjectParser::wcsServiceUrl() const
{
QString url;

if ( !mProjectParser.xmlDocument() )
if ( !mProjectParser->xmlDocument() )
{
return url;
}

QDomElement propertiesElem = mProjectParser.propertiesElem();
QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( !propertiesElem.isNull() )
{
QDomElement wcsUrlElem = propertiesElem.firstChildElement( "WCSUrl" );
@@ -55,12 +58,12 @@ QString QgsWCSProjectParser::wcsServiceUrl() const

QString QgsWCSProjectParser::serviceUrl() const
{
return mProjectParser.serviceUrl();
return mProjectParser->serviceUrl();
}

void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDocument& doc ) const
{
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return;
@@ -75,7 +78,7 @@ void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDo
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsMapLayer *layer = mProjectParser.createLayerFromElement( elem );
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
if ( layer && wcsLayersId.contains( layer->id() ) )
{
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
@@ -137,12 +140,12 @@ void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDo
QStringList QgsWCSProjectParser::wcsLayers() const
{
QStringList wcsList;
if ( !mProjectParser.xmlDocument() )
if ( !mProjectParser->xmlDocument() )
{
return wcsList;
}

QDomElement propertiesElem = mProjectParser.propertiesElem();
QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( propertiesElem.isNull() )
{
return wcsList;
@@ -162,7 +165,7 @@ QStringList QgsWCSProjectParser::wcsLayers() const

void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElement& parentElement, QDomDocument& doc ) const
{
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return;
@@ -186,7 +189,7 @@ void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElemen
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsMapLayer *layer = mProjectParser.createLayerFromElement( elem );
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
if ( !layer )
continue;
QString coveName = layer->name();
@@ -366,7 +369,7 @@ QList<QgsMapLayer*> QgsWCSProjectParser::mapLayerFromCoverage( const QString& cN
{
QList<QgsMapLayer*> layerList;

const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return layerList;
@@ -379,7 +382,7 @@ QList<QgsMapLayer*> QgsWCSProjectParser::mapLayerFromCoverage( const QString& cN
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsMapLayer *mLayer = mProjectParser.createLayerFromElement( elem, useCache );
QgsMapLayer *mLayer = mProjectParser->createLayerFromElement( elem, useCache );
QgsRasterLayer* layer = dynamic_cast<QgsRasterLayer*>( mLayer );
if ( !layer || !wcsLayersId.contains( layer->id() ) )
return layerList;
@@ -23,7 +23,7 @@
class QgsWCSProjectParser
{
public:
QgsWCSProjectParser( QDomDocument* xmlDoc, const QString& filePath );
QgsWCSProjectParser( const QString& filePath );
~QgsWCSProjectParser();

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
@@ -35,7 +35,7 @@ class QgsWCSProjectParser
QList<QgsMapLayer*> mapLayerFromCoverage( const QString& cName, bool useCache = true ) const;

private:
QgsServerProjectParser mProjectParser;
QgsServerProjectParser* mProjectParser;
};

#endif // QGSWCSPROJECTPARSER_H

0 comments on commit 7de1dff

Please sign in to comment.
You can’t perform that action at this time.