Skip to content

Commit

Permalink
[FEATURE]: Optionally specify wms service capabilities in the propert…
Browse files Browse the repository at this point in the history
…ies section of the project file (instead of wms_metadata.xml file)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15067 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 24, 2011
1 parent 8ca338e commit a85387d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
18 changes: 18 additions & 0 deletions src/mapserver/qgsconfigparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
#include <sqlite3.h>
#include <QFile>


QgsConfigParser::QgsConfigParser()
Expand Down Expand Up @@ -401,3 +402,20 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer

return c;
}

void QgsConfigParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
QFile wmsService( "wms_metadata.xml" );
if ( wmsService.open( QIODevice::ReadOnly ) )
{
QDomDocument externServiceDoc;
QString parseError;
int errorLineNo;
if ( externServiceDoc.setContent( &wmsService, false, &parseError, &errorLineNo ) )
{
wmsService.close();
QDomElement service = externServiceDoc.firstChildElement();
parentElement.appendChild( service );
}
}
}
3 changes: 3 additions & 0 deletions src/mapserver/qgsconfigparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class QgsConfigParser
/**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
virtual void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;

/**Appends service metadata to the capabilities document*/
virtual void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

protected:
/**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/
QgsConfigParser* mFallbackParser;
Expand Down
19 changes: 18 additions & 1 deletion src/mapserver/qgsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ QSet<int> QgsProjectParser::supportedOutputCrsSet() const
{
return epsgSet;
}
QDomNodeList valueList = propertiesElem.elementsByTagName( "value" );
QDomNodeList valueList = wmsEpsgElem.elementsByTagName( "value" );
bool conversionOk;
for ( int i = 0; i < valueList.size(); ++i )
{
Expand Down Expand Up @@ -1009,3 +1009,20 @@ QDomElement QgsProjectParser::composerByName( const QString& composerName ) cons
return composerElem;
}

void QgsProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
QDomElement qgisElem = mXMLDoc->documentElement();
QDomNodeList serviceCapabilitiesList = qgisElem.elementsByTagName( "WMSServiceCapabilities" );
if ( serviceCapabilitiesList.size() < 1 ) //service capabilities not embedded in the project file. Use wms_metadata.xml as fallback
{
QgsConfigParser::serviceCapabilities( parentElement, doc );
return;
}

QDomElement serviceElem = serviceCapabilitiesList.at( 0 ).firstChildElement( "Service" );
if ( !serviceElem.isNull() )
{
parentElement.appendChild( doc.importNode( serviceElem, true ) );
}
}

3 changes: 3 additions & 0 deletions src/mapserver/qgsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class QgsProjectParser: public QgsConfigParser
/**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

/**Reads service metadata from projectfile or falls back to parent class method if not there*/
void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

private:
/**Content of project file*/
QDomDocument* mXMLDoc;
Expand Down
22 changes: 2 additions & 20 deletions src/mapserver/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,9 @@ QDomDocument QgsWMSServer::getCapabilities()
wmsCapabilitiesElement.setAttribute( "version", "1.3.0" );
doc.appendChild( wmsCapabilitiesElement );

QFile wmsService( "wms_metadata.xml" );
if ( !wmsService.open( QIODevice::ReadOnly ) )
{
//throw an exception...
QgsMSDebugMsg( "external wms service capabilities not found" )
}
else
if ( mConfigParser )
{
QDomDocument externServiceDoc;
QString parseError;
int errorLineNo;
if ( !externServiceDoc.setContent( &wmsService, false, &parseError, &errorLineNo ) )
{
QgsMSDebugMsg( "parse error at setting content of external wms service capabilities: "
+ parseError + " at line " + QString::number( errorLineNo ) )
wmsService.close();
}
wmsService.close();

QDomElement service = externServiceDoc.firstChildElement();
wmsCapabilitiesElement.appendChild( service );
mConfigParser->serviceCapabilities( wmsCapabilitiesElement, doc );
}

//wms:Capability element
Expand Down

0 comments on commit a85387d

Please sign in to comment.