37
37
#include " qgsvectordataprovider.h"
38
38
#include " qgsvectorlayer.h"
39
39
#include " qgslogger.h"
40
+ #include " qgsmessagelog.h"
40
41
#include " qgsmapserviceexception.h"
41
42
#include " qgssldconfigparser.h"
42
43
#include " qgssymbolv2.h"
@@ -199,7 +200,20 @@ void QgsWMSServer::executeRequest()
199
200
try
200
201
{
201
202
QDomDocument doc = getContext ();
202
- mRequestHandler ->setGetStyleResponse ( doc );
203
+ mRequestHandler ->setXmlResponse ( doc );
204
+ }
205
+ catch ( QgsMapServiceException& ex )
206
+ {
207
+ mRequestHandler ->setServiceException ( ex );
208
+ }
209
+ }
210
+ // GetSchemaExtension
211
+ else if ( request.compare ( " GetSchemaExtension" , Qt::CaseInsensitive ) == 0 )
212
+ {
213
+ try
214
+ {
215
+ QDomDocument doc = getSchemaExtension ();
216
+ mRequestHandler ->setXmlResponse ( doc );
203
217
}
204
218
catch ( QgsMapServiceException& ex )
205
219
{
@@ -212,7 +226,7 @@ void QgsWMSServer::executeRequest()
212
226
try
213
227
{
214
228
QDomDocument doc = getStyle ();
215
- mRequestHandler ->setGetStyleResponse ( doc );
229
+ mRequestHandler ->setXmlResponse ( doc );
216
230
}
217
231
catch ( QgsMapServiceException& ex )
218
232
{
@@ -222,23 +236,17 @@ void QgsWMSServer::executeRequest()
222
236
// GetStyles
223
237
else if ( request.compare ( " GetStyles" , Qt::CaseInsensitive ) == 0 )
224
238
{
225
- // GetStyles is only defined for WMS1.1.1/SLD1.0
226
- if ( version != " 1.1.1" )
227
- {
228
- mRequestHandler ->setServiceException ( QgsMapServiceException ( " OperationNotSupported" , " GetStyles method is only available in WMS version 1.1.1" ) );
229
- }
230
- else
231
- {
232
- try
233
- {
234
- QDomDocument doc = getStyles ();
235
- mRequestHandler ->setGetStyleResponse ( doc );
236
- }
237
- catch ( QgsMapServiceException& ex )
238
- {
239
- mRequestHandler ->setServiceException ( ex );
240
- }
241
- }
239
+ // GetStyles is defined for WMS1.1.1/SLD1.0
240
+ // and in qgis-server WMS1.3.0 extension
241
+ try
242
+ {
243
+ QDomDocument doc = getStyles ();
244
+ mRequestHandler ->setXmlResponse ( doc );
245
+ }
246
+ catch ( QgsMapServiceException& ex )
247
+ {
248
+ mRequestHandler ->setServiceException ( ex );
249
+ }
242
250
}
243
251
// GetLegendGraphic
244
252
else if ( request.compare ( " GetLegendGraphic" , Qt::CaseInsensitive ) == 0 ||
@@ -313,6 +321,13 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
313
321
QDomDocument doc;
314
322
QDomElement wmsCapabilitiesElement;
315
323
324
+ // Prepare url
325
+ QString hrefString = mConfigParser ->serviceUrl ();
326
+ if ( hrefString.isEmpty () )
327
+ {
328
+ hrefString = serviceUrl ();
329
+ }
330
+
316
331
if ( version == " 1.1.1" )
317
332
{
318
333
doc = QDomDocument ( " WMT_MS_Capabilities SYSTEM 'http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd'" ); // WMS 1.1.1 needs DOCTYPE "SYSTEM http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd"
@@ -324,8 +339,16 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
324
339
addXMLDeclaration ( doc );
325
340
wmsCapabilitiesElement = doc.createElement ( " WMS_Capabilities" /* wms:WMS_Capabilities*/ );
326
341
wmsCapabilitiesElement.setAttribute ( " xmlns" , " http://www.opengis.net/wms" );
342
+ wmsCapabilitiesElement.setAttribute ( " xmlns:sld" , " http://www.opengis.net/sld" );
343
+ wmsCapabilitiesElement.setAttribute ( " xmlns:qgs" , " http://www.qgis.org/wms" );
327
344
wmsCapabilitiesElement.setAttribute ( " xmlns:xsi" , " http://www.w3.org/2001/XMLSchema-instance" );
328
- wmsCapabilitiesElement.setAttribute ( " xsi:schemaLocation" , " http://www.opengis.net/wms http://qgis.org/wms_1_3_0.xsd" );
345
+ QString schemaLocation = " http://www.opengis.net/wms" ;
346
+ schemaLocation += " http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd" ;
347
+ schemaLocation += " http://www.opengis.net/sld" ;
348
+ schemaLocation += " http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd" ;
349
+ schemaLocation += " http://www.qgis.org/wms" ;
350
+ schemaLocation += " " + hrefString +" SERVICE=WMS&REQUEST=GetSchemaExtension" ;
351
+ wmsCapabilitiesElement.setAttribute ( " xsi:schemaLocation" , schemaLocation );
329
352
}
330
353
wmsCapabilitiesElement.setAttribute ( " version" , version );
331
354
doc.appendChild ( wmsCapabilitiesElement );
@@ -355,14 +378,6 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
355
378
elem.appendChild ( dcpTypeElement );
356
379
requestElement.appendChild ( elem );
357
380
358
- // Prepare url
359
- QString hrefString = mConfigParser ->serviceUrl ();
360
- if ( hrefString.isEmpty () )
361
- {
362
- hrefString = serviceUrl ();
363
- }
364
-
365
-
366
381
// SOAP platform
367
382
// only give this information if it is not a WMS request to be in sync with the WMS capabilities schema
368
383
QMap<QString, QString>::const_iterator service_it = mParameters .find ( " SERVICE" );
@@ -411,19 +426,19 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
411
426
requestElement.appendChild ( elem );
412
427
413
428
// wms:GetLegendGraphic
414
- elem = doc.createElement ( " GetLegendGraphic" /* wms:GetLegendGraphic*/ );
429
+ elem = doc.createElement ( ( version == " 1.1.1 " ? " GetLegendGraphic" : " sld:GetLegendGraphic " ) /* wms:GetLegendGraphic*/ );
415
430
appendFormats ( doc, elem, QStringList () << " image/jpeg" << " image/png" );
416
431
elem.appendChild ( dcpTypeElement.cloneNode ().toElement () ); // this is the same as for 'GetCapabilities'
417
432
requestElement.appendChild ( elem );
418
433
419
434
// wms:GetStyles
420
- elem = doc.createElement ( " GetStyles" /* wms:GetStyles*/ );
435
+ elem = doc.createElement ( ( version == " 1.1.1 " ? " GetStyles" : " qgs:GetStyles " ) /* wms:GetStyles*/ );
421
436
appendFormats ( doc, elem, QStringList () << " text/xml" );
422
437
elem.appendChild ( dcpTypeElement.cloneNode ().toElement () ); // this is the same as for 'GetCapabilities'
423
438
requestElement.appendChild ( elem );
424
439
425
440
// wms:GetPrint
426
- elem = doc.createElement ( " GetPrint" /* wms:GetPrint*/ );
441
+ elem = doc.createElement ( ( version == " 1.1.1 " ? " GetPrint" : " qgs:GetPrint " ) /* wms:GetPrint*/ );
427
442
appendFormats ( doc, elem, QStringList () << " svg" << " png" << " pdf" );
428
443
elem.appendChild ( dcpTypeElement.cloneNode ().toElement () ); // this is the same as for 'GetCapabilities'
429
444
requestElement.appendChild ( elem );
@@ -956,6 +971,42 @@ void QgsWMSServer::legendParameters( double& boxSpace, double& layerSpace, doubl
956
971
}
957
972
}
958
973
974
+ QDomDocument QgsWMSServer::getSchemaExtension ()
975
+ {
976
+ QDomDocument xsdDoc;
977
+
978
+ QFileInfo xsdFileInfo ( " schemaExtension.xsd" );
979
+ if ( !xsdFileInfo.exists () )
980
+ {
981
+ QgsMessageLog::logMessage ( " Error, xsd file 'schemaExtension.xsd' does not exist" , " Server" , QgsMessageLog::CRITICAL );
982
+ return xsdDoc;
983
+ }
984
+
985
+ QString xsdFilePath = xsdFileInfo.absoluteFilePath ();
986
+ QFile xsdFile ( xsdFilePath );
987
+ if ( !xsdFile.exists () )
988
+ {
989
+ QgsMessageLog::logMessage ( " Error, xsd file 'schemaExtension.xsd' does not exist" , " Server" , QgsMessageLog::CRITICAL );
990
+ return xsdDoc;
991
+ }
992
+
993
+ if ( !xsdFile.open ( QIODevice::ReadOnly ) )
994
+ {
995
+ QgsMessageLog::logMessage ( " Error, cannot open xsd file 'schemaExtension.xsd' does not exist" , " Server" , QgsMessageLog::CRITICAL );
996
+ return xsdDoc;
997
+ }
998
+
999
+ QString errorMsg;
1000
+ int line, column;
1001
+ if ( !xsdDoc.setContent ( &xsdFile, true , &errorMsg, &line, &column ) )
1002
+ {
1003
+ QgsMessageLog::logMessage ( " Error parsing file 'schemaExtension.xsd" +
1004
+ QString ( " ': parse error %1 at row %2, column %3" ).arg ( errorMsg ).arg ( line ).arg ( column ), " Server" , QgsMessageLog::CRITICAL );
1005
+ return xsdDoc;
1006
+ }
1007
+ return xsdDoc;
1008
+ }
1009
+
959
1010
QDomDocument QgsWMSServer::getStyle ()
960
1011
{
961
1012
QDomDocument doc;
@@ -975,7 +1026,7 @@ QDomDocument QgsWMSServer::getStyle()
975
1026
return mConfigParser ->getStyle ( styleName, layerName );
976
1027
}
977
1028
978
- // GetStyles is only defined for WMS1.1.1/SLD1.0
1029
+ // GetStyles is defined for WMS1.1.1/SLD1.0 and in WMS 1.3.0 SLD Extension
979
1030
QDomDocument QgsWMSServer::getStyles ()
980
1031
{
981
1032
QDomDocument doc;
0 commit comments