Skip to content

Commit

Permalink
Fix for bug #10372 (QGIS Server WMS does not put SERVICE section in G…
Browse files Browse the repository at this point in the history
…etCapabilities anymore)
  • Loading branch information
mhugent committed May 28, 2014
1 parent 5f23232 commit 776e9b3
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 5 deletions.
182 changes: 182 additions & 0 deletions src/mapserver/qgsserverprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,188 @@ bool QgsServerProjectParser::updateLegendDrawingOrder() const
return legendElem().attribute( "updateDrawingOrder", "true" ).compare( "true", Qt::CaseInsensitive ) == 0;
}

void QgsServerProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc, const QString& service, bool sia2045 ) const
{
QDomElement propertiesElement = propertiesElem();
if ( propertiesElement.isNull() )
{
QgsConfigParserUtils::fallbackServiceCapabilities( parentElement, doc );
return;
}
QDomElement serviceElem = doc.createElement( "Service" );

QDomElement serviceCapabilityElem = propertiesElement.firstChildElement( "WMSServiceCapabilities" );
if ( serviceCapabilityElem.isNull() || serviceCapabilityElem.text().compare( "true", Qt::CaseInsensitive ) != 0 )
{
QgsConfigParserUtils::fallbackServiceCapabilities( parentElement, doc );
return;
}

//Service name
QDomElement wmsNameElem = doc.createElement( "Name" );
QDomText wmsNameText = doc.createTextNode( service );
wmsNameElem.appendChild( wmsNameText );
serviceElem.appendChild( wmsNameElem );

//WMS title
QDomElement titleElem = propertiesElement.firstChildElement( "WMSServiceTitle" );
if ( !titleElem.isNull() )
{
QDomElement wmsTitleElem = doc.createElement( "Title" );
QDomText wmsTitleText = doc.createTextNode( titleElem.text() );
wmsTitleElem.appendChild( wmsTitleText );
serviceElem.appendChild( wmsTitleElem );
}

//WMS abstract
QDomElement abstractElem = propertiesElement.firstChildElement( "WMSServiceAbstract" );
if ( !abstractElem.isNull() )
{
QDomElement wmsAbstractElem = doc.createElement( "Abstract" );
QDomText wmsAbstractText = doc.createTextNode( abstractElem.text() );
wmsAbstractElem.appendChild( wmsAbstractText );
serviceElem.appendChild( wmsAbstractElem );
}

//keyword list
QDomElement keywordListElem = propertiesElement.firstChildElement( "WMSKeywordList" );
if ( !keywordListElem.isNull() && !keywordListElem.text().isEmpty() )
{
QDomElement wmsKeywordElem = doc.createElement( "KeywordList" );
QDomNodeList keywordList = keywordListElem.elementsByTagName( "value" );
for ( int i = 0; i < keywordList.size(); ++i )
{
QDomElement keywordElem = doc.createElement( "Keyword" );
QDomText keywordText = doc.createTextNode( keywordList.at( i ).toElement().text() );
keywordElem.appendChild( keywordText );
if ( sia2045 )
{
keywordElem.setAttribute( "vocabulary", "SIA_Geo405" );
}
wmsKeywordElem.appendChild( keywordElem );
}

if ( keywordList.size() > 0 )
{
serviceElem.appendChild( wmsKeywordElem );
}
}

//OnlineResource element is mandatory according to the WMS specification
QDomElement wmsOnlineResourceElem = propertiesElement.firstChildElement( "WMSOnlineResource" );
QDomElement onlineResourceElem = doc.createElement( "OnlineResource" );
onlineResourceElem.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
onlineResourceElem.setAttribute( "xlink:type", "simple" );
if ( !wmsOnlineResourceElem.isNull() )
{
onlineResourceElem.setAttribute( "xlink:href", wmsOnlineResourceElem.text() );
}

serviceElem.appendChild( onlineResourceElem );

//Contact information
QDomElement contactInfoElem = doc.createElement( "ContactInformation" );

//Contact person primary
QDomElement contactPersonPrimaryElem = doc.createElement( "ContactPersonPrimary" );

//Contact person
QDomElement contactPersonElem = propertiesElement.firstChildElement( "WMSContactPerson" );
QString contactPersonString;
if ( !contactPersonElem.isNull() )
{
contactPersonString = contactPersonElem.text();
}
QDomElement wmsContactPersonElem = doc.createElement( "ContactPerson" );
QDomText contactPersonText = doc.createTextNode( contactPersonString );
wmsContactPersonElem.appendChild( contactPersonText );
contactPersonPrimaryElem.appendChild( wmsContactPersonElem );


//Contact organisation
QDomElement contactOrganizationElem = propertiesElement.firstChildElement( "WMSContactOrganization" );
QString contactOrganizationString;
if ( !contactOrganizationElem.isNull() )
{
contactOrganizationString = contactOrganizationElem.text();
}
QDomElement wmsContactOrganizationElem = doc.createElement( "ContactOrganization" );
QDomText contactOrganizationText = doc.createTextNode( contactOrganizationString );
wmsContactOrganizationElem.appendChild( contactOrganizationText );
contactPersonPrimaryElem.appendChild( wmsContactOrganizationElem );
contactInfoElem.appendChild( contactPersonPrimaryElem );

//phone
QDomElement phoneElem = propertiesElement.firstChildElement( "WMSContactPhone" );
if ( !phoneElem.isNull() )
{
QDomElement wmsPhoneElem = doc.createElement( "ContactVoiceTelephone" );
QDomText wmsPhoneText = doc.createTextNode( phoneElem.text() );
wmsPhoneElem.appendChild( wmsPhoneText );
contactInfoElem.appendChild( wmsPhoneElem );
}

//mail
QDomElement mailElem = propertiesElement.firstChildElement( "WMSContactMail" );
if ( !mailElem.isNull() )
{
QDomElement wmsMailElem = doc.createElement( "ContactElectronicMailAddress" );
QDomText wmsMailText = doc.createTextNode( mailElem.text() );
wmsMailElem.appendChild( wmsMailText );
contactInfoElem.appendChild( wmsMailElem );
}

serviceElem.appendChild( contactInfoElem );

//Fees
QDomElement feesElem = propertiesElement.firstChildElement( "WMSFees" );
if ( !feesElem.isNull() )
{
QDomElement wmsFeesElem = doc.createElement( "Fees" );
QDomText wmsFeesText = doc.createTextNode( feesElem.text() );
wmsFeesElem.appendChild( wmsFeesText );
serviceElem.appendChild( wmsFeesElem );
}

//AccessConstraints
QDomElement accessConstraintsElem = propertiesElement.firstChildElement( "WMSAccessConstraints" );
if ( !accessConstraintsElem.isNull() )
{
QDomElement wmsAccessConstraintsElem = doc.createElement( "AccessConstraints" );
QDomText wmsAccessConstraintsText = doc.createTextNode( accessConstraintsElem.text() );
wmsAccessConstraintsElem.appendChild( wmsAccessConstraintsText );
serviceElem.appendChild( wmsAccessConstraintsElem );
}

//max width, max height for WMS
if ( service.compare( "WMS", Qt::CaseInsensitive ) == 0 )
{
QString version = doc.documentElement().attribute( "version" );
if ( version != "1.1.1" )
{
//max width
QDomElement mwElem = propertiesElement.firstChildElement( "WMSMaxWidth" );
if ( !mwElem.isNull() )
{
QDomElement maxWidthElem = doc.createElement( "MaxWidth" );
QDomText maxWidthText = doc.createTextNode( mwElem.text() );
maxWidthElem.appendChild( maxWidthText );
serviceElem.appendChild( maxWidthElem );
}
//max height
QDomElement mhElem = propertiesElement.firstChildElement( "WMSMaxHeight" );
if ( !mhElem.isNull() )
{
QDomElement maxHeightElem = doc.createElement( "MaxHeight" );
QDomText maxHeightText = doc.createTextNode( mhElem.text() );
maxHeightElem.appendChild( maxHeightText );
serviceElem.appendChild( maxHeightElem );
}
}
}
parentElement.appendChild( serviceElem );
}

QString QgsServerProjectParser::layerName( const QDomElement& layerElem ) const
{
if ( layerElem.isNull() )
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgsserverprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class QgsServerProjectParser

bool updateLegendDrawingOrder() const;

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc, const QString& service, bool sia2045 = false ) const;

private:

/**Content of project file*/
Expand Down
12 changes: 12 additions & 0 deletions src/mapserver/qgssldconfigparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,18 @@ int QgsSLDConfigParser::nLayers() const
return 0;
}

void QgsSLDConfigParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
if ( mFallbackParser )
{
mFallbackParser->serviceCapabilities( parentElement, doc );
}
else
{
QgsConfigParserUtils::fallbackServiceCapabilities( parentElement, doc );
}
}

QList<QDomElement> QgsSLDConfigParser::findNamedLayerElements( const QString& layerName ) const
{
QList<QDomElement> resultList;
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgssldconfigparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class QgsSLDConfigParser: public QgsWMSConfigParser

int nLayers() const;

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

private:

/**SLD as dom document*/
Expand Down
3 changes: 3 additions & 0 deletions src/mapserver/qgswcsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ QgsWCSProjectParser::~QgsWCSProjectParser()

void QgsWCSProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
mProjectParser.serviceCapabilities( parentElement, doc, "WCS" );
#if 0
QDomElement serviceElem = doc.createElement( "Service" );

QDomElement propertiesElem = mProjectParser.propertiesElem();
Expand Down Expand Up @@ -111,6 +113,7 @@ void QgsWCSProjectParser::serviceCapabilities( QDomElement& parentElement, QDomD
}

parentElement.appendChild( serviceElem );
#endif //0
}

QString QgsWCSProjectParser::wcsServiceUrl() const
Expand Down
4 changes: 4 additions & 0 deletions src/mapserver/qgswfsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ QgsWFSProjectParser::~QgsWFSProjectParser()

void QgsWFSProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
mProjectParser.serviceCapabilities( parentElement, doc, "WFS" );

#if 0
QDomElement serviceElem = doc.createElement( "Service" );

QDomElement propertiesElem = mProjectParser.propertiesElem();
Expand Down Expand Up @@ -124,6 +127,7 @@ void QgsWFSProjectParser::serviceCapabilities( QDomElement& parentElement, QDomD
serviceElem.appendChild( wmsAccessConstraintsElem );
}
parentElement.appendChild( serviceElem );
#endif //0
}

QString QgsWFSProjectParser::serviceUrl() const
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgswmsconfigparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class QgsWMSConfigParser

virtual int nLayers() const = 0;

virtual void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;

#if 0
/**List of GML datasets passed outside SLD (e.g. in a SOAP request). Key of the map is the layer name*/
QMap<QString, QDomDocument*> mExternalGMLDatasets;
Expand Down
5 changes: 5 additions & 0 deletions src/mapserver/qgswmsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,11 @@ int QgsWMSProjectParser::nLayers() const
return mProjectParser.numberOfLayers();
}

void QgsWMSProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
mProjectParser.serviceCapabilities( parentElement, doc, "WMS", featureInfoFormatSIA2045() );
}

QDomElement QgsWMSProjectParser::composerByName( const QString& composerName ) const
{
QDomElement composerElem;
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgswmsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class QgsWMSProjectParser: public QgsWMSConfigParser

int nLayers() const;

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

private:
QgsServerProjectParser mProjectParser;

Expand Down
6 changes: 6 additions & 0 deletions src/mapserver/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
wmsCapabilitiesElement.setAttribute( "version", version );
doc.appendChild( wmsCapabilitiesElement );

//todo: add service capabilities
if ( mConfigParser )
{
mConfigParser->serviceCapabilities( wmsCapabilitiesElement, doc );
}

//wms:Capability element
QDomElement capabilityElement = doc.createElement( "Capability"/*wms:Capability*/ );
wmsCapabilitiesElement.appendChild( capabilityElement );
Expand Down
10 changes: 5 additions & 5 deletions src/mapserver/wms_metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
</ContactPersonPrimary>
<ContactAddress>
<AddressType>postal</AddressType>
<Address>Elestastr. 18</Address>
<City>Bad Ragaz</City>
<StateOrProvince>SG</StateOrProvince>
<PostCode>7310</PostCode>
<Address>Weberstrasse 5</Address>
<City>Zürich</City>
<StateOrProvince>ZH</StateOrProvince>
<PostCode>8004</PostCode>
<Country>SWITZERLAND</Country>
</ContactAddress>
<ContactVoiceTelephone>+41 43 377 08 21</ContactVoiceTelephone>
<ContactVoiceTelephone></ContactVoiceTelephone>
<ContactElectronicMailAddress>marco.hugentobler@sourcepole.ch</ContactElectronicMailAddress>
</ContactInformation>
<!-- Fees or access constraints imposed. -->
Expand Down

0 comments on commit 776e9b3

Please sign in to comment.