QGIS API Documentation  3.23.0-Master (dd0cd13a00)
qgsserverapicontext.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsserverapicontext.cpp - QgsServerApiContext
3 
4  ---------------------
5  begin : 13.5.2019
6  copyright : (C) 2019 by Alessandro Pasotti
7  email : elpaso at itopen dot it
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #include "qgsserverapicontext.h"
17 
18 #include "qgsserverrequest.h"
19 #include "qgsserverresponse.h"
20 #include "qgsproject.h"
21 #include "qgsserverinterface.h"
22 
23 QgsServerApiContext::QgsServerApiContext( const QString &apiRootPath, const QgsServerRequest *request, QgsServerResponse *response, const QgsProject *project, QgsServerInterface *serverInterface ):
24  mApiRootPath( apiRootPath ),
25  mRequest( request ),
26  mResponse( response ),
27  mProject( project ),
28  mServerInterface( serverInterface )
29 {
30 
31 }
32 
34 {
35  return mRequest;
36 }
37 
38 
40 {
41  return mResponse;
42 }
43 
44 
46 {
47  return mProject;
48 }
49 
51 {
52  mProject = project;
53 }
54 
56 {
57  return mServerInterface;
58 }
59 
60 const QString QgsServerApiContext::matchedPath() const
61 {
62  auto path { mRequest->url().path( )};
63  const int idx { path.indexOf( mApiRootPath )};
64  if ( idx != -1 )
65  {
66  path.truncate( idx + mApiRootPath.length() );
67  return path;
68  }
69  else
70  {
71  return QString();
72  }
73 }
74 
76 {
77  return mApiRootPath;
78 }
79 
81 {
82  mRequest = request;
83 }
84 
86 {
87  const QUrl url { request()->url() };
88  const QString urlBasePath { matchedPath() };
89  if ( ! urlBasePath.isEmpty() )
90  {
91  return url.path().mid( urlBasePath.length() );
92  }
93  else
94  {
95  return url.path();
96  }
97 }
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:101
const QgsProject * project() const
Returns the (possibly NULL) project.
QgsServerResponse * response() const
Returns the server response object.
QString handlerPath() const
Returns the handler component of the URL path, i.e.
const QgsServerRequest * request() const
Returns the server request object.
void setProject(const QgsProject *project)
Sets the project to project.
void setRequest(const QgsServerRequest *request)
Sets context request to request.
QgsServerInterface * serverInterface() const
Returns the server interface.
QString apiRootPath() const
Returns the API root path.
QgsServerApiContext(const QString &apiRootPath, const QgsServerRequest *request, QgsServerResponse *response, const QgsProject *project, QgsServerInterface *serverInterface)
QgsServerApiContext constructor.
const QString matchedPath() const
Returns the initial part of the incoming request URL path that matches the API root path.
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...