QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgswmsgetschemaextension.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswmsgetschemaextension.cpp
3  -------------------------
4  begin : December 20 , 2016
5  copyright : (C) 2007 by Marco Hugentobler (original code)
6  (C) 2014 by Alessandro Pasotti (original code)
7  (C) 2016 by David Marteau
8  email : marco dot hugentobler at karto dot baug dot ethz dot ch
9  a dot pasotti at itopen dot it
10  david dot marteau at 3liz dot com
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 #include "qgswmsutils.h"
23 #include "qgsapplication.h"
24 
25 #include <QDir>
26 #include <QFileInfo>
27 
28 namespace QgsWms
29 {
30 
31  void writeGetSchemaExtension( QgsServerInterface *serverIface, const QString &version,
32  const QgsServerRequest &request, QgsServerResponse &response )
33  {
34  QDomDocument doc = getSchemaExtension( serverIface, version, request );
35  response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
36  response.write( doc.toByteArray() );
37  }
38 
39  QDomDocument getSchemaExtension( QgsServerInterface *serverIface, const QString &version,
40  const QgsServerRequest &request )
41  {
42  Q_UNUSED( version )
43  Q_UNUSED( serverIface )
44 
45  QgsServerRequest::Parameters parameters = request.parameters();
46 
47  QDomDocument xsdDoc;
48 
49  QDir resourcesDir = QFileInfo( QgsApplication::serverResourcesPath() ).absoluteDir();
50  QFileInfo xsdFileInfo( resourcesDir, QStringLiteral( "schemaExtension.xsd" ) );
51 
52  if ( !xsdFileInfo.exists() )
53  {
54  QgsMessageLog::logMessage( QStringLiteral( "Error, xsd file 'schemaExtension.xsd' does not exist" ),
55  QStringLiteral( "Server" ), Qgis::Critical );
56  return xsdDoc;
57  }
58 
59  QString xsdFilePath = xsdFileInfo.absoluteFilePath();
60  QFile xsdFile( xsdFilePath );
61  if ( !xsdFile.exists() )
62  {
63  QgsMessageLog::logMessage( QStringLiteral( "Error, xsd file 'schemaExtension.xsd' does not exist" ),
64  QStringLiteral( "Server" ), Qgis::Critical );
65  return xsdDoc;
66  }
67 
68  if ( !xsdFile.open( QIODevice::ReadOnly ) )
69  {
70  QgsMessageLog::logMessage( QStringLiteral( "Error, cannot open xsd file 'schemaExtension.xsd' does not exist" ),
71  QStringLiteral( "Server" ), Qgis::Critical );
72  return xsdDoc;
73  }
74 
75  QString errorMsg;
76  int line, column;
77  if ( !xsdDoc.setContent( &xsdFile, true, &errorMsg, &line, &column ) )
78  {
79  QgsMessageLog::logMessage( QStringLiteral( "Error parsing file 'schemaExtension.xsd" ) +
80  QStringLiteral( "': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ),
81  QStringLiteral( "Server" ), Qgis::Critical );
82  }
83 
84  return xsdDoc;
85  }
86 
87 } // namespace QgsWms
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device...
QDomDocument getSchemaExtension(QgsServerInterface *serverIface, const QString &version, const QgsServerRequest &request)
Returns the schemaExtension for WMS 1.3.0 capabilities.
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Median cut implementation.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
void writeGetSchemaExtension(QgsServerInterface *serverIface, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetSchemaExtension response.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
static QString serverResourcesPath()
Returns the path to the server resources directory.
QMap< QString, QString > Parameters