AttributionURL.h
Aller à la documentation de ce fichier.
1 /*
2  * Copyright © (2011-2013) Institut national de l'information
3  * géographique et forestière
4  *
5  * Géoportail SAV <contact.geoservices@ign.fr>
6  *
7  * This software is a computer program whose purpose is to publish geographic
8  * data using OGC WMS and WMTS protocol.
9  *
10  * This software is governed by the CeCILL-C license under French law and
11  * abiding by the rules of distribution of free software. You can use,
12  * modify and/ or redistribute the software under the terms of the CeCILL-C
13  * license as circulated by CEA, CNRS and INRIA at the following URL
14  * "http://www.cecill.info".
15  *
16  * As a counterpart to the access to the source code and rights to copy,
17  * modify and redistribute granted by the license, users are provided only
18  * with a limited warranty and the software's author, the holder of the
19  * economic rights, and the successive licensors have only limited
20  * liability.
21  *
22  * In this respect, the user's attention is drawn to the risks associated
23  * with loading, using, modifying and/or developing or reproducing the
24  * software by the user in light of its specific status of free software,
25  * that may mean that it is complicated to manipulate, and that also
26  * therefore means that it is reserved for developers and experienced
27  * professionals having in-depth computer knowledge. Users are therefore
28  * encouraged to load and test the software's suitability as regards their
29  * requirements in conditions enabling the security of their systems and/or
30  * data to be ensured and, more generally, to use and operate it in the
31  * same conditions as regards security.
32  *
33  * The fact that you are presently reading this means that you have had
34  *
35  * knowledge of the CeCILL-C license and that you accept its terms.
36  */
37 
46 class AttributionURL;
47 
48 #ifndef ATTRIBUTIONURL_H
49 #define ATTRIBUTIONURL_H
50 
51 #include <rok4/utils/ResourceLocator.h>
52 #include "UtilsXML.h"
53 
63 class AttributionURL : public ResourceLocator {
64 private:
69  std::string title;
74  int width;
79  int height;
80 
85  ResourceLocator* logo;
86 
87 public:
96  AttributionURL ( json11::Json doc ) : ResourceLocator (), logo(NULL) {
97 
98  if (! doc["title"].is_string()) {
99  missingField = "title";
100  return;
101  }
102  title = doc["title"].string_value();
103 
104  if (! doc["url"].is_string()) {
105  missingField = "url";
106  return;
107  }
108  href = doc["url"].string_value();
109 
110  if (doc["logo"].is_object()) {
111  if (! doc["logo"]["width"].is_number()) {
112  missingField = "logo.width";
113  return;
114  }
115  width = doc["logo"]["width"].number_value();
116  if (! doc["logo"]["height"].is_number()) {
117  missingField = "logo.height";
118  return;
119  }
120  height = doc["logo"]["height"].number_value();
121 
122  if (! doc["logo"]["format"].is_string()) {
123  missingField = "logo.format";
124  return;
125  }
126  if (! doc["logo"]["url"].is_string()) {
127  missingField = "logo.url";
128  return;
129  }
130  logo = new ResourceLocator(doc["logo"]["format"].string_value(), doc["logo"]["url"].string_value());
131  }
132  };
133 
140  std::string getTmsXml() {
141  std::string res = "<Attribution><Title>" + title + "</Title>";
142  if (logo != NULL) {
143  res += "<Logo width=\"" + std::to_string(width) + "\" height=\"" + std::to_string(height) + "\" href=\"" + logo->getHRef() + "\" mime-type=\"" + logo->getFormat() + "\" />\n";
144  }
145  res += "</Attribution>";
146  return res;
147  }
148 
153  TiXmlElement* getWmsXml() {
154  TiXmlElement* el = new TiXmlElement ( "Attribution" );
155  el->LinkEndChild ( UtilsXML::buildTextNode ( "Title", title ) );
156 
157  TiXmlElement* orEl = new TiXmlElement ( "OnlineResource" );
158  orEl->SetAttribute ( "xlink:type","simple" );
159  orEl->SetAttribute ( "xlink:href", href );
160  el->LinkEndChild ( orEl );
161 
162  if (logo != NULL) {
163  TiXmlElement* logoEl = new TiXmlElement ( "LogoURL" );
164  logoEl->SetAttribute ( "width", width );
165  logoEl->SetAttribute ( "height", height );
166  logoEl->LinkEndChild ( UtilsXML::buildTextNode ( "Format", logo->getFormat() ) );
167 
168  TiXmlElement* logoOrEl = new TiXmlElement ( "OnlineResource" );
169  logoOrEl->SetAttribute ( "xlink:type","simple" );
170  logoOrEl->SetAttribute ( "xlink:href", logo->getHRef() );
171  logoEl->LinkEndChild ( logoOrEl );
172 
173  el->LinkEndChild ( logoEl );
174  }
175 
176  return el;
177  }
178 
185  virtual ~AttributionURL() {
186  if (logo != NULL) delete logo;
187  };
188 };
189 
190 #endif // ATTRIBUTIONURL_H
AttributionURL
Gestion des éléments d'attribution des documents de capacités.
Definition: AttributionURL.h:63
AttributionURL::getTmsXml
std::string getTmsXml()
Export XML pour le GetCapabilities TMS.
Definition: AttributionURL.h:140
AttributionURL::getWmsXml
TiXmlElement * getWmsXml()
Export XML pour le GetCapabilities WMS.
Definition: AttributionURL.h:153
AttributionURL::AttributionURL
AttributionURL(json11::Json doc)
Crée un AttributionURL à partir d'un élément JSON.
Definition: AttributionURL.h:96
UtilsXML::buildTextNode
static TiXmlElement * buildTextNode(std::string elementName, std::string value)
Definition: UtilsXML.h:60
AttributionURL::~AttributionURL
virtual ~AttributionURL()
Destructeur par défaut.
Definition: AttributionURL.h:185