QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 & )
41  {
42  Q_UNUSED( version )
43  Q_UNUSED( serverIface )
44 
45  QDomDocument xsdDoc;
46 
47  QDir resourcesDir = QFileInfo( QgsApplication::serverResourcesPath() ).absoluteDir();
48  QFileInfo xsdFileInfo( resourcesDir, QStringLiteral( "schemaExtension.xsd" ) );
49 
50  if ( !xsdFileInfo.exists() )
51  {
52  QgsMessageLog::logMessage( QStringLiteral( "Error, xsd file 'schemaExtension.xsd' does not exist" ),
53  QStringLiteral( "Server" ), Qgis::Critical );
54  return xsdDoc;
55  }
56 
57  QString xsdFilePath = xsdFileInfo.absoluteFilePath();
58  QFile xsdFile( xsdFilePath );
59  if ( !xsdFile.exists() )
60  {
61  QgsMessageLog::logMessage( QStringLiteral( "Error, xsd file 'schemaExtension.xsd' does not exist" ),
62  QStringLiteral( "Server" ), Qgis::Critical );
63  return xsdDoc;
64  }
65 
66  if ( !xsdFile.open( QIODevice::ReadOnly ) )
67  {
68  QgsMessageLog::logMessage( QStringLiteral( "Error, cannot open xsd file 'schemaExtension.xsd' does not exist" ),
69  QStringLiteral( "Server" ), Qgis::Critical );
70  return xsdDoc;
71  }
72 
73  QString errorMsg;
74  int line, column;
75  if ( !xsdDoc.setContent( &xsdFile, true, &errorMsg, &line, &column ) )
76  {
77  QgsMessageLog::logMessage( QStringLiteral( "Error parsing file 'schemaExtension.xsd" ) +
78  QStringLiteral( "': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ),
79  QStringLiteral( "Server" ), Qgis::Critical );
80  }
81 
82  return xsdDoc;
83  }
84 
85 } // 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 &)
Returns the schemaExtension for WMS 1.3.0 capabilities.
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.