Skip to content

Commit

Permalink
Refactor configuration parsing and configuration cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Mar 27, 2014
1 parent 99a8612 commit e490991
Show file tree
Hide file tree
Showing 21 changed files with 3,520 additions and 45 deletions.
7 changes: 4 additions & 3 deletions src/mapserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ SET ( qgis_mapserv_SRCS
qgis_map_serv.cpp
qgscapabilitiescache.cpp
qgsconfigcache.cpp
qgsconfigparser.cpp
qgsprojectparser.cpp
qgshttprequesthandler.cpp
qgsgetrequesthandler.cpp
qgspostrequesthandler.cpp
qgssoaprequesthandler.cpp
qgssldparser.cpp
qgswmsserver.cpp
qgswfsserver.cpp
qgswcsserver.cpp
Expand All @@ -43,6 +40,10 @@ SET ( qgis_mapserv_SRCS
qgsremotedatasourcebuilder.cpp
qgssentdatasourcebuilder.cpp
qgsmsutils.cpp
qgswcsprojectparser.cpp
qgswfsprojectparser.cpp
qgswmsprojectparser.cpp
qgsserverprojectparser.cpp
)

# SET (qgis_mapserv_UIS
Expand Down
33 changes: 19 additions & 14 deletions src/mapserver/qgis_map_serv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,6 @@ int main( int argc, char * argv[] )
//Config file path
QString configFilePath = configPath( defaultConfigFilePath, parameterMap );

//Admin config parser
QgsConfigParser* adminConfigParser = QgsConfigCache::instance()->searchConfiguration( configFilePath );
if ( !adminConfigParser )
{
QgsDebugMsg( "parse error on config file " + configFilePath );
theRequestHandler->sendServiceException( QgsMapServiceException( "", "Configuration file problem : perhaps you left off the .qgs extension?" ) );
continue;
}
adminConfigParser->setParameterMap( parameterMap );

//Service parameter
QString serviceString;
paramIt = parameterMap.find( "SERVICE" );
Expand All @@ -338,18 +328,33 @@ int main( int argc, char * argv[] )

if ( serviceString == "WCS" )
{
QgsWCSServer wcsServer( configFilePath, parameterMap, adminConfigParser, theRequestHandler );
QgsWCSProjectParser* p = QgsConfigCache::instance()->wcsConfiguration( configFilePath );
if ( !p )
{
//error handling
}
QgsWCSServer wcsServer( configFilePath, parameterMap, p, theRequestHandler );
wcsServer.executeRequest();
}
else if ( serviceString == "WFS" )
{
QgsWFSServer wfsServer( configFilePath, parameterMap, adminConfigParser, theRequestHandler );
QgsWFSProjectParser* p = QgsConfigCache::instance()->wfsConfiguration( configFilePath );
if ( !p )
{
//error handling
}
QgsWFSServer wfsServer( configFilePath, parameterMap, p, theRequestHandler );
wfsServer.executeRequest();
}
else //WMS else
{
adminConfigParser->loadLabelSettings( theMapRenderer->labelingEngine() );
QgsWMSServer wmsServer( configFilePath, parameterMap, adminConfigParser, theRequestHandler, theMapRenderer, &capabilitiesCache );
QgsWMSConfigParser* p = QgsConfigCache::instance()->wmsConfiguration( configFilePath );
if ( !p )
{
//error handling
}
//adminConfigParser->loadLabelSettings( theMapRenderer->labelingEngine() );
QgsWMSServer wmsServer( configFilePath, parameterMap, p, theRequestHandler, theMapRenderer, &capabilitiesCache );
wmsServer.executeRequest();
}
}
Expand Down
90 changes: 90 additions & 0 deletions src/mapserver/qgsconfigcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,94 @@
***************************************************************************/

#include "qgsconfigcache.h"
#include "qgswcsprojectparser.h"
#include "qgswfsprojectparser.h"
#include "qgswmsprojectparser.h"

QgsConfigCache* QgsConfigCache::instance()
{
static QgsConfigCache mInstance;
return &mInstance;
}

QgsConfigCache::~QgsConfigCache()
{
}

QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
{
QgsWCSProjectParser* p = mWCSConfigCache.object( filePath );
if ( p )
{
return p;
}

QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}
p = new QgsWCSProjectParser( doc, filePath );
mWCSConfigCache.insert( filePath, p );
return p;
}

QgsWFSProjectParser* QgsConfigCache::wfsConfiguration( const QString& filePath )
{
return 0; //todo...
}

QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath )
{
QgsWMSConfigParser* p = mWMSConfigCache.object( filePath );

QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}

//sld or QGIS project file?
//is it an sld document or a qgis project file?
QDomElement documentElem = doc->documentElement();
if ( documentElem.tagName() == "StyledLayerDescriptor" )
{
}
else
{
p = new QgsWMSProjectParser( doc, filePath );
}

mWMSConfigCache.insert( filePath, p );
return p;
}

QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
{
//first open file
QFile configFile( filePath );
if ( !configFile.exists() || !configFile.open( QIODevice::ReadOnly ) )
{
QgsDebugMsg( "File unreadable: " + filePath );
return 0;
}

//then create xml document
QDomDocument* xmlDoc = new QDomDocument();
QString errorMsg;
int line, column;
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )
{
QgsDebugMsg( QString( "Parse error %1 at row %2, column %3 in %4 " )
.arg( errorMsg ).arg( line ).arg( column ).arg( filePath ) );
delete xmlDoc;
return 0;
}
return xmlDoc;
}

#if 0

#include "qgslogger.h"
#include "qgsmslayercache.h"
#include "qgsprojectfiletransform.h"
Expand Down Expand Up @@ -141,3 +229,5 @@ void QgsConfigCache::removeChangedEntry( const QString& path )
}
mFileSystemWatcher.removePath( path );
}

#endif //0
36 changes: 35 additions & 1 deletion src/mapserver/qgsconfigcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@
#ifndef QGSCONFIGCACHE_H
#define QGSCONFIGCACHE_H

#include <QCache>
#include <QObject>

class QgsWCSProjectParser;
class QgsWFSProjectParser;
class QgsWMSConfigParser;

class QDomDocument;

class QgsConfigCache: public QObject
{
Q_OBJECT
public:
static QgsConfigCache* instance();
~QgsConfigCache();

QgsWCSProjectParser* wcsConfiguration( const QString& filePath );
QgsWFSProjectParser* wfsConfiguration( const QString& filePath );
QgsWMSConfigParser* wmsConfiguration( const QString& filePath );

private:
static QgsConfigCache* mInstance;

/**Returns xml document for project file / sld or 0 in case of errors*/
QDomDocument* xmlDocument( const QString& filePath );

QCache<QString, QgsWMSConfigParser> mWMSConfigCache;
QCache<QString, QgsWFSProjectParser> mWFSConfigCache;
QCache<QString, QgsWCSProjectParser> mWCSConfigCache;
};


#if 0

#include <QFileSystemWatcher>
#include <QHash>
#include <QObject>
Expand Down Expand Up @@ -55,5 +89,5 @@ class QgsConfigCache: public QObject
/**Removes changed entry from this cache*/
void removeChangedEntry( const QString& path );
};

#endif //0
#endif // QGSCONFIGCACHE_H
5 changes: 2 additions & 3 deletions src/mapserver/qgsowsserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
class QgsOWSServer
{
public:
QgsOWSServer( const QString& configFilePath, const QMap<QString, QString>& parameters, QgsConfigParser* cp, QgsRequestHandler* rh ):
mParameters( parameters ), mConfigParser( cp ), mRequestHandler( rh ), mConfigFilePath( configFilePath ) {}
QgsOWSServer( const QString& configFilePath, const QMap<QString, QString>& parameters, QgsRequestHandler* rh ):
mParameters( parameters ), mRequestHandler( rh ), mConfigFilePath( configFilePath ) {}
virtual ~QgsOWSServer() { delete mRequestHandler; }

virtual void executeRequest() = 0;
Expand All @@ -35,7 +35,6 @@ class QgsOWSServer

protected:
QMap<QString, QString> mParameters;
QgsConfigParser* mConfigParser;
QgsRequestHandler* mRequestHandler;
QString mConfigFilePath;
};
Expand Down
17 changes: 16 additions & 1 deletion src/mapserver/qgsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class QgsProjectParser: public QgsConfigParser
QgsProjectParser( QDomDocument* xmlDoc, const QString& filePath );
virtual ~QgsProjectParser();

//WMS
/**Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.
@param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*/
virtual void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc, const QString& version, bool fullProjectSettings = false ) const;
Expand All @@ -60,21 +61,25 @@ class QgsProjectParser: public QgsConfigParser

int numberOfLayers() const;

//WMS
/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& lName, const QString& styleName, bool useCache = true ) const;

/**Returns maplayers for a layer Id.*/
virtual QgsMapLayer* mapLayerFromLayerId( const QString& lId, bool useCache = true ) const;

//WMS
/**Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success*/
virtual int layersAndStyles( QStringList& layers, QStringList& styles ) const;

//WMS
/**Returns the xml fragment of a style*/
virtual QDomDocument getStyle( const QString& styleName, const QString& layerName ) const;
//WMS
/**Returns the xml fragment of layers styles*/
virtual QDomDocument getStyles( QStringList& layerList ) const;


//WMS
/**Returns if output are MM or PIXEL*/
virtual QgsMapRenderer::OutputUnits outputUnits() const;

Expand Down Expand Up @@ -106,6 +111,7 @@ class QgsProjectParser: public QgsConfigParser
*/
virtual QStringList supportedOutputCrsList() const;

//WMS
/**True if the feature info response should contain the wkt geometry for vector features*/
virtual bool featureInfoWithWktGeometry() const;

Expand All @@ -120,9 +126,11 @@ class QgsProjectParser: public QgsConfigParser

const QDomDocument* xmlDoc() const { return mXMLDoc; }

//WMS
/**Creates a composition from the project file (probably delegated to the fallback parser)*/
QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlList ) const;

//WMS
/**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

Expand All @@ -141,21 +149,28 @@ class QgsProjectParser: public QgsConfigParser
/**Returns the names of the published wcs layers (not the ids as in wcsLayers() )*/
QStringList wcsLayerNames() const;

//WMS
/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
virtual QHash<QString, QString> featureInfoLayerAliasMap() const;

//WMS
virtual QString featureInfoDocumentElement( const QString& defaultValue ) const;

//WMS
virtual QString featureInfoDocumentElementNS() const;

//WMS
virtual QString featureInfoSchema() const;

//WMS
/**Return feature info in format SIA2045?*/
bool featureInfoFormatSIA2045() const;

//WMS
/**Draw text annotation items from the QGIS projectfile*/
void drawOverlays( QPainter* p, int dpi, int width, int height ) const;

//WMS
void loadLabelSettings( QgsLabelingEngineInterface* lbl );

QList< QPair< QString, QgsLayerCoordinateTransform > > layerCoordinateTransforms() const;
Expand Down
Loading

0 comments on commit e490991

Please sign in to comment.