Skip to content

Commit 079713d

Browse files
committedDec 8, 2011
WMS server: add more capabilities to GetCapabilities response (including GetPrint)
Thanks Marco Lechner for the initial patch.
1 parent c62ca9f commit 079713d

File tree

6 files changed

+101
-74
lines changed

6 files changed

+101
-74
lines changed
 

‎src/mapserver/qgis_map_serv.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,20 @@ int main( int argc, char * argv[] )
236236
continue;
237237
}
238238

239+
QMap<QString, QString>::const_iterator paramIt;
240+
239241
//set admin config file to wms server object
240-
if ( !parameterMap.contains( "MAP" ) )
242+
QString configFilePath( defaultConfigFilePath );
243+
244+
paramIt = parameterMap.find( "MAP" );
245+
if ( paramIt == parameterMap.constEnd() )
241246
{
242247
QgsDebugMsg( QString( "Using default configuration file path: %1" ).arg( defaultConfigFilePath ) );
243248
}
244-
QString configFilePath = parameterMap.value( "MAP", defaultConfigFilePath );
249+
else
250+
{
251+
configFilePath = paramIt.value();
252+
}
245253

246254
QgsConfigParser* adminConfigParser = QgsConfigCache::instance()->searchConfiguration( configFilePath );
247255
if ( !adminConfigParser )
@@ -255,15 +263,22 @@ int main( int argc, char * argv[] )
255263
adminConfigParser->setParameterMap( parameterMap );
256264

257265
//request to WMS?
258-
QString serviceString = parameterMap.value( "SERVICE", "WMS" );
259-
#if 0
260-
if ( !parameterMap.contains( "SERVICE" ) )
266+
QString serviceString;
267+
#ifndef QGISDEBUG
268+
serviceString = parameterMap.value( "SERVICE", "WMS" );
269+
#else
270+
paramIt = parameterMap.find( "SERVICE" );
271+
if ( paramIt == parameterMap.constEnd() )
261272
{
262273
QgsDebugMsg( "unable to find 'SERVICE' parameter, exiting..." );
263274
theRequestHandler->sendServiceException( QgsMapServiceException( "ServiceNotSpecified", "Service not specified. The SERVICE parameter is mandatory" ) );
264275
delete theRequestHandler;
265276
continue;
266277
}
278+
else
279+
{
280+
serviceString = paramIt.value();
281+
}
267282
#endif
268283

269284
QgsWMSServer* theServer = 0;
@@ -386,7 +401,7 @@ int main( int argc, char * argv[] )
386401
delete theServer;
387402
continue;
388403
}
389-
else if ( request == "GetStyle" )
404+
else if ( request == "GetStyles" || request == "GetStyle" ) // GetStyle for compatibility with earlier QGIS versions
390405
{
391406
try
392407
{
@@ -402,7 +417,7 @@ int main( int argc, char * argv[] )
402417
delete theServer;
403418
continue;
404419
}
405-
else if ( request == "GetLegendGraphics" )
420+
else if ( request == "GetLegendGraphic" || request == "GetLegendGraphics" ) // GetLegendGraphics for compatibility with earlier QGIS versions
406421
{
407422
QImage* result = 0;
408423
try
@@ -416,8 +431,8 @@ int main( int argc, char * argv[] )
416431

417432
if ( result )
418433
{
419-
QgsDebugMsg( "Sending GetLegendGraphics response" );
420-
//sending is the same for GetMap and GetLegendGraphics
434+
QgsDebugMsg( "Sending GetLegendGraphic response" );
435+
//sending is the same for GetMap and GetLegendGraphic
421436
theRequestHandler->sendGetMapResponse( serviceString, result );
422437
}
423438
else
@@ -465,5 +480,3 @@ int main( int argc, char * argv[] )
465480
QgsDebugMsg( "************* all done ***************" );
466481
return 0;
467482
}
468-
469-

‎src/mapserver/qgsgetrequesthandler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include <QUrl>
66
#include <stdlib.h>
77

8-
QgsGetRequestHandler::QgsGetRequestHandler(): QgsHttpRequestHandler()
8+
QgsGetRequestHandler::QgsGetRequestHandler()
9+
: QgsHttpRequestHandler()
910
{
1011
}
1112

‎src/mapserver/qgsmslayercache.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName,
5757
}
5858

5959
QPair<QString, QString> urlLayerPair = qMakePair( url, layerName );
60-
if ( mEntries.contains( urlLayerPair ) )
60+
QHash<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.find( urlLayerPair );
61+
if ( it != mEntries.end() )
6162
{
62-
delete mEntries[ urlLayerPair ].layerPointer;
63+
delete it.value().layerPointer;
6364
}
6465

6566
QgsMSLayerCacheEntry newEntry;

‎src/mapserver/qgsremoteowsbuilder.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
#include <QDomElement>
2525
#include <QTemporaryFile>
2626

27-
QgsRemoteOWSBuilder::QgsRemoteOWSBuilder( const QMap<QString, QString>& parameterMap ): QgsMSLayerBuilder(), mParameterMap( parameterMap )
27+
QgsRemoteOWSBuilder::QgsRemoteOWSBuilder( const QMap<QString, QString>& parameterMap )
28+
: QgsMSLayerBuilder()
29+
, mParameterMap( parameterMap )
2830
{
2931

3032
}
3133

32-
QgsRemoteOWSBuilder::QgsRemoteOWSBuilder(): QgsMSLayerBuilder()
34+
QgsRemoteOWSBuilder::QgsRemoteOWSBuilder()
35+
: QgsMSLayerBuilder()
3336
{
3437

3538
}
@@ -39,7 +42,11 @@ QgsRemoteOWSBuilder::~QgsRemoteOWSBuilder()
3942

4043
}
4144

42-
QgsMapLayer* QgsRemoteOWSBuilder::createMapLayer( const QDomElement& elem, const QString& layerName, QList<QTemporaryFile*>& filesToRemove, QList<QgsMapLayer*>& layersToRemove, bool allowCaching ) const
45+
QgsMapLayer* QgsRemoteOWSBuilder::createMapLayer(
46+
const QDomElement& elem,
47+
const QString& layerName,
48+
QList<QTemporaryFile*>& filesToRemove,
49+
QList<QgsMapLayer*>& layersToRemove, bool allowCaching ) const
4350
{
4451
if ( elem.isNull() )
4552
{

‎src/mapserver/qgswmsserver.cpp

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ QgsWMSServer::QgsWMSServer()
6969
{
7070
}
7171

72+
void QgsWMSServer::appendFormats( QDomDocument &doc, QDomElement &elem, const QStringList &formats )
73+
{
74+
foreach( QString format, formats )
75+
{
76+
QDomElement formatElem = doc.createElement( "Format"/*wms:Format*/ );
77+
formatElem.appendChild( doc.createTextNode( format ) );
78+
elem.appendChild( formatElem );
79+
}
80+
}
81+
7282
QDomDocument QgsWMSServer::getCapabilities( QString version )
7383
{
7484
QgsDebugMsg( "Entering." );
@@ -101,25 +111,25 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
101111
//wms:Request element
102112
QDomElement requestElement = doc.createElement( "Request"/*wms:Request*/ );
103113
capabilityElement.appendChild( requestElement );
104-
//wms:GetCapabilities
105-
QDomElement getCapabilitiesElement = doc.createElement( "GetCapabilities"/*wms:GetCapabilities*/ );
106-
requestElement.appendChild( getCapabilitiesElement );
107-
QDomElement capabilitiesFormatElement = doc.createElement( "Format" );/*wms:Format*/
108-
getCapabilitiesElement.appendChild( capabilitiesFormatElement );
109-
QDomText capabilitiesFormatText = doc.createTextNode( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" );
110-
capabilitiesFormatElement.appendChild( capabilitiesFormatText );
111114

112115
QDomElement dcpTypeElement = doc.createElement( "DCPType"/*wms:DCPType*/ );
113-
getCapabilitiesElement.appendChild( dcpTypeElement );
114116
QDomElement httpElement = doc.createElement( "HTTP"/*wms:HTTP*/ );
115117
dcpTypeElement.appendChild( httpElement );
116118

119+
QDomElement elem;
120+
121+
//wms:GetCapabilities
122+
elem = doc.createElement( "GetCapabilities"/*wms:GetCapabilities*/ );
123+
appendFormats( doc, elem, QStringList() << ( version == "1.1.1" ? "application/vnd.ogc.wms_xml" : "text/xml" ) );
124+
elem.appendChild( dcpTypeElement );
125+
requestElement.appendChild( elem );
126+
117127
//Prepare url
118128
//Some client requests already have http://<SERVER_NAME> in the REQUEST_URI variable
119129
QString hrefString;
120130
QString requestUrl = getenv( "REQUEST_URI" );
121131
QUrl mapUrl( requestUrl );
122-
mapUrl.setHost( QString( getenv( "SERVER_NAME" ) ) );
132+
mapUrl.setHost( getenv( "SERVER_NAME" ) );
123133

124134
//Add non-default ports to url
125135
QString portString = getenv( "SERVER_PORT" );
@@ -193,60 +203,52 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
193203
olResourceElement.setAttribute( "xlink:href", hrefString );
194204
getElement.appendChild( olResourceElement );
195205

206+
#if 0
196207
// POST already used by SOAP
197-
// QDomElement postElement = doc.createElement("post"/*wms:SOAP*/);
198-
// httpElement.appendChild(postElement);
199-
// QDomElement postResourceElement = doc.createElement("OnlineResource"/*wms:OnlineResource*/);
200-
// postResourceElement.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");
201-
// postResourceElement.setAttribute("xlink:type","simple");
202-
// postResourceElement.setAttribute("xlink:href", "http://" + QString(getenv("SERVER_NAME")) + QString(getenv("REQUEST_URI")));
203-
// postElement.appendChild(postResourceElement);
204-
// dcpTypeElement.appendChild(postElement);
208+
QDomElement postElement = doc.createElement( "post"/*wms:SOAP*/ );
209+
httpElement.appendChild( postElement );
210+
QDomElement postResourceElement = doc.createElement( "OnlineResource"/*wms:OnlineResource*/ );
211+
postResourceElement.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
212+
postResourceElement.setAttribute( "xlink:type", "simple" );
213+
postResourceElement.setAttribute( "xlink:href", "http://" + QString( getenv( "SERVER_NAME" ) ) + QString( getenv( "REQUEST_URI" ) ) );
214+
postElement.appendChild( postResourceElement );
215+
dcpTypeElement.appendChild( postElement );
216+
#endif
205217

206218
//wms:GetMap
207-
QDomElement getMapElement = doc.createElement( "GetMap"/*wms:GetMap*/ );
208-
requestElement.appendChild( getMapElement );
209-
QDomElement jpgFormatElement = doc.createElement( "Format"/*wms:Format*/ );
210-
QDomText jpgFormatText = doc.createTextNode( "image/jpeg" );
211-
jpgFormatElement.appendChild( jpgFormatText );
212-
getMapElement.appendChild( jpgFormatElement );
213-
QDomElement pngFormatElement = doc.createElement( "Format"/*wms:Format*/ );
214-
QDomText pngFormatText = doc.createTextNode( "image/png" );
215-
pngFormatElement.appendChild( pngFormatText );
216-
getMapElement.appendChild( pngFormatElement );
217-
QDomElement getMapDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
218-
getMapElement.appendChild( getMapDhcTypeElement );
219+
elem = doc.createElement( "GetMap"/*wms:GetMap*/ );
220+
appendFormats( doc, elem, QStringList() << "image/jpeg" << "image/png" );
221+
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
222+
requestElement.appendChild( elem );
219223

220224
//wms:GetFeatureInfo
221-
QDomElement getFeatureInfoElem = doc.createElement( "GetFeatureInfo" );
222-
//text/plain
223-
QDomElement textFormatElem = doc.createElement( "Format" );
224-
QDomText textFormatText = doc.createTextNode( "text/plain" );
225-
textFormatElem.appendChild( textFormatText );
226-
getFeatureInfoElem.appendChild( textFormatElem );
227-
//text/html
228-
QDomElement htmlFormatElem = doc.createElement( "Format" );
229-
QDomText htmlFormatText = doc.createTextNode( "text/html" );
230-
htmlFormatElem.appendChild( htmlFormatText );
231-
getFeatureInfoElem.appendChild( htmlFormatElem );
232-
//text/xml
233-
QDomElement xmlFormatElem = doc.createElement( "Format" );
234-
QDomText xmlFormatText = doc.createTextNode( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" );
235-
xmlFormatElem.appendChild( xmlFormatText );
236-
getFeatureInfoElem.appendChild( xmlFormatElem );
237-
238-
//dcpType
239-
QDomElement getFeatureInfoDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
240-
getFeatureInfoElem.appendChild( getFeatureInfoDhcTypeElement );
241-
requestElement.appendChild( getFeatureInfoElem );
225+
elem = doc.createElement( "GetFeatureInfo" );
226+
appendFormats( doc, elem, QStringList() << "text/plain" << "text/html" << "text/xml" );
227+
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
228+
requestElement.appendChild( elem );
229+
230+
//wms:GetLegendGraphic
231+
elem = doc.createElement( "GetLegendGraphic"/*wms:GetLegendGraphic*/ );
232+
appendFormats( doc, elem, QStringList() << "jpeg" << "image/jpeg" << "image/png" );
233+
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); // this is the same as for 'GetCapabilities'
234+
requestElement.appendChild( elem );
235+
236+
//wms:GetStyles
237+
elem = doc.createElement( "GetStyles"/*wms:GetStyles*/ );
238+
appendFormats( doc, elem, QStringList() << "text/xml" );
239+
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
240+
requestElement.appendChild( elem );
241+
242+
//wms:GetPrint
243+
elem = doc.createElement( "GetPrint"/*wms:GetPrint*/ );
244+
appendFormats( doc, elem, QStringList() << "svg" << "png" << "pdf" );
245+
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
246+
requestElement.appendChild( elem );
242247

243248
//Exception element is mandatory
244-
QDomElement exceptionElement = doc.createElement( "Exception" );
245-
QDomElement exFormatElement = doc.createElement( "Format" );
246-
QDomText formatText = doc.createTextNode( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" );
247-
exFormatElement.appendChild( formatText );
248-
exceptionElement.appendChild( exFormatElement );
249-
capabilityElement.appendChild( exceptionElement );
249+
elem = doc.createElement( "Exception" );
250+
appendFormats( doc, elem, QStringList() << ( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" ) );
251+
capabilityElement.appendChild( elem );
250252

251253
//Insert <ComposerTemplate> elements derived from wms:_ExtendedCapabilities
252254
if ( mConfigParser )
@@ -271,6 +273,7 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
271273
doc.save( capabilitiesStream, 4 );
272274
}
273275
#endif
276+
274277
return doc;
275278
}
276279

@@ -832,7 +835,7 @@ QImage* QgsWMSServer::initializeRendering( QStringList& layersList, QStringList&
832835
}
833836
//pass external GML to the SLD parser.
834837
QString gml = mParameterMap.value( "GML" );
835-
if( !gml.isEmpty() )
838+
if ( !gml.isEmpty() )
836839
{
837840
QDomDocument* gmlDoc = new QDomDocument();
838841
if ( gmlDoc->setContent( gml, true ) )

‎src/mapserver/qgswmsserver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class QgsWMSServer
155155
/**Clear all feature selections in the given layers*/
156156
void clearFeatureSelections( const QStringList& layerIds ) const;
157157

158+
void appendFormats( QDomDocument &doc, QDomElement &elem, const QStringList &formats );
159+
158160
/**Map containing the WMS parameters*/
159161
QMap<QString, QString> mParameterMap;
160162
QgsConfigParser* mConfigParser;

0 commit comments

Comments
 (0)
Please sign in to comment.