QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 }
QgsServerApiContext::matchedPath
const QString matchedPath() const
Returns the initial part of the incoming request URL path that matches the API root path.
Definition: qgsserverapicontext.cpp:60
QgsServerRequest
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
Definition: qgsserverrequest.h:38
QgsServerApiContext::setRequest
void setRequest(const QgsServerRequest *request)
Sets context request to request.
Definition: qgsserverapicontext.cpp:80
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsServerApiContext::apiRootPath
QString apiRootPath() const
Returns the API root path.
Definition: qgsserverapicontext.cpp:75
QgsServerApiContext::handlerPath
QString handlerPath() const
Returns the handler component of the URL path, i.e.
Definition: qgsserverapicontext.cpp:85
QgsServerApiContext::QgsServerApiContext
QgsServerApiContext(const QString &apiRootPath, const QgsServerRequest *request, QgsServerResponse *response, const QgsProject *project, QgsServerInterface *serverInterface)
QgsServerApiContext constructor.
Definition: qgsserverapicontext.cpp:23
qgsserverrequest.h
qgsserverresponse.h
QgsServerApiContext::project
const QgsProject * project() const
Returns the (possibly NULL) project.
Definition: qgsserverapicontext.cpp:45
QgsServerApiContext::response
QgsServerResponse * response() const
Returns the server response object.
Definition: qgsserverapicontext.cpp:39
QgsServerApiContext::serverInterface
QgsServerInterface * serverInterface() const
Returns the server interface.
Definition: qgsserverapicontext.cpp:55
QgsServerApiContext::setProject
void setProject(const QgsProject *project)
Sets the project to project.
Definition: qgsserverapicontext.cpp:50
QgsServerRequest::url
QUrl url() const
Definition: qgsserverrequest.cpp:86
QgsServerApiContext::request
const QgsServerRequest * request() const
Returns the server request object.
Definition: qgsserverapicontext.cpp:33
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:60
qgsproject.h
QgsServerResponse
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Definition: qgsserverresponse.h:43
qgsserverapicontext.h
qgsserverinterface.h