Skip to content
Permalink
Browse files

[FEATURE]: Optionally specify wms service capabilities in the propert…

…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
mhugent committed Jan 24, 2011
1 parent 8ca338e commit a85387d2b086b72b2c0485af1bfa6eda184e8c09
@@ -23,6 +23,7 @@
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
#include <sqlite3.h>
#include <QFile>


QgsConfigParser::QgsConfigParser()
@@ -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 );
}
}
}
@@ -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;
@@ -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 )
{
@@ -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 ) );
}
}

@@ -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;
@@ -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

0 comments on commit a85387d

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