QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 #include <QTextStream>
28 
29 namespace QgsWms
30 {
31 
33  {
34  QDir resourcesDir = QFileInfo( QgsApplication::serverResourcesPath() ).absoluteDir();
35  QFileInfo xsdFileInfo( resourcesDir, QStringLiteral( "schemaExtension.xsd" ) );
36  QString schema_str = QStringLiteral( "<?xml version='1.0'?>" );
37 
38  if ( !xsdFileInfo.exists() )
39  {
40  QgsMessageLog::logMessage( QStringLiteral( "Error, xsd file 'schemaExtension.xsd' does not exist" ),
41  QStringLiteral( "Server" ), Qgis::Critical );
42  }
43  else
44  {
45  QFile file( xsdFileInfo.absoluteFilePath() );
46  if ( file.open( QFile::ReadOnly | QFile::Text ) )
47  {
48  QTextStream in( &file );
49  schema_str = in.readAll();
50  file.close();
51  }
52  else
53  {
54  QgsMessageLog::logMessage( QStringLiteral( "Error, xsd file 'schemaExtension.xsd' not readable" ),
55  QStringLiteral( "Server" ), Qgis::Critical );
56  }
57  }
58  response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
59  response.write( schema_str );
60  }
61 
62 } // namespace QgsWms
@ Critical
Definition: qgis.h:92
static QString serverResourcesPath()
Returns the path to the server resources directory.
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).
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
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...
Median cut implementation.
void writeGetSchemaExtension(QgsServerResponse &response)
Output GetSchemaExtension response.