Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: GML registry
4 : * Purpose: GML reader
5 : * Author: Even Rouault, <even dot rouault at spatialys.com>
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2013, Even Rouault <even dot rouault at spatialys.com>
9 : *
10 : * Permission is hereby granted, free of charge, to any person obtaining a
11 : * copy of this software and associated documentation files (the "Software"),
12 : * to deal in the Software without restriction, including without limitation
13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 : * and/or sell copies of the Software, and to permit persons to whom the
15 : * Software is furnished to do so, subject to the following conditions:
16 : *
17 : * The above copyright notice and this permission notice shall be included
18 : * in all copies or substantial portions of the Software.
19 : *
20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 : * DEALINGS IN THE SOFTWARE.
27 : ****************************************************************************/
28 :
29 : #include "cpl_port.h"
30 : #include "gmlregistry.h"
31 :
32 : #include <cstring>
33 :
34 : #include "cpl_conv.h"
35 :
36 : /************************************************************************/
37 : /* Parse() */
38 : /************************************************************************/
39 :
40 97 : bool GMLRegistry::Parse()
41 : {
42 97 : if (osRegistryPath.empty())
43 : {
44 96 : const char *pszFilename = CPLFindFile("gdal", "gml_registry.xml");
45 96 : if (pszFilename)
46 96 : osRegistryPath = pszFilename;
47 : }
48 97 : if (osRegistryPath.empty())
49 0 : return false;
50 97 : CPLXMLNode *psRootNode = CPLParseXMLFile(osRegistryPath);
51 97 : if (psRootNode == nullptr)
52 0 : return false;
53 97 : CPLXMLNode *psRegistryNode = CPLGetXMLNode(psRootNode, "=gml_registry");
54 97 : if (psRegistryNode == nullptr)
55 : {
56 0 : CPLDestroyXMLNode(psRootNode);
57 0 : return false;
58 : }
59 97 : CPLXMLNode *psIter = psRegistryNode->psChild;
60 1154 : while (psIter != nullptr)
61 : {
62 1057 : if (psIter->eType == CXT_Element &&
63 577 : strcmp(psIter->pszValue, "namespace") == 0)
64 : {
65 1154 : GMLRegistryNamespace oNameSpace;
66 577 : if (oNameSpace.Parse(osRegistryPath, psIter))
67 : {
68 577 : aoNamespaces.push_back(oNameSpace);
69 : }
70 : }
71 1057 : psIter = psIter->psNext;
72 : }
73 97 : CPLDestroyXMLNode(psRootNode);
74 97 : return true;
75 : }
76 :
77 : /************************************************************************/
78 : /* Parse() */
79 : /************************************************************************/
80 :
81 577 : bool GMLRegistryNamespace::Parse(const char *pszRegistryFilename,
82 : CPLXMLNode *psNode)
83 : {
84 577 : const char *pszPrefix = CPLGetXMLValue(psNode, "prefix", "");
85 577 : const char *pszURI = CPLGetXMLValue(psNode, "uri", nullptr);
86 577 : if (pszURI == nullptr)
87 0 : return false;
88 577 : osPrefix = pszPrefix;
89 577 : osURI = pszURI;
90 : const char *pszUseGlobalSRSName =
91 577 : CPLGetXMLValue(psNode, "useGlobalSRSName", nullptr);
92 577 : if (pszUseGlobalSRSName != nullptr &&
93 481 : strcmp(pszUseGlobalSRSName, "true") == 0)
94 481 : bUseGlobalSRSName = true;
95 :
96 577 : CPLXMLNode *psIter = psNode->psChild;
97 6245 : while (psIter != nullptr)
98 : {
99 5668 : if (psIter->eType == CXT_Element &&
100 4129 : strcmp(psIter->pszValue, "featureType") == 0)
101 : {
102 8258 : GMLRegistryFeatureType oFeatureType;
103 4129 : if (oFeatureType.Parse(pszRegistryFilename, psIter))
104 : {
105 4129 : aoFeatureTypes.push_back(oFeatureType);
106 : }
107 : }
108 5668 : psIter = psIter->psNext;
109 : }
110 577 : return true;
111 : }
112 :
113 : /************************************************************************/
114 : /* Parse() */
115 : /************************************************************************/
116 :
117 4129 : bool GMLRegistryFeatureType::Parse(const char *pszRegistryFilename,
118 : CPLXMLNode *psNode)
119 : {
120 4129 : const char *pszElementName = CPLGetXMLValue(psNode, "elementName", nullptr);
121 : const char *pszSchemaLocation =
122 4129 : CPLGetXMLValue(psNode, "schemaLocation", nullptr);
123 : const char *pszGFSSchemaLocation =
124 4129 : CPLGetXMLValue(psNode, "gfsSchemaLocation", nullptr);
125 4129 : if (pszElementName == nullptr ||
126 3744 : (pszSchemaLocation == nullptr && pszGFSSchemaLocation == nullptr))
127 0 : return false;
128 :
129 : const char *pszElementValue =
130 4129 : CPLGetXMLValue(psNode, "elementValue", nullptr);
131 4129 : osElementName = pszElementName;
132 :
133 4129 : if (pszSchemaLocation != nullptr)
134 : {
135 771 : if (!STARTS_WITH(pszSchemaLocation, "http://") &&
136 386 : !STARTS_WITH(pszSchemaLocation, "https://") &&
137 1 : CPLIsFilenameRelative(pszSchemaLocation))
138 : {
139 1 : pszSchemaLocation = CPLFormFilename(CPLGetPath(pszRegistryFilename),
140 : pszSchemaLocation, nullptr);
141 : }
142 385 : osSchemaLocation = pszSchemaLocation;
143 : }
144 3744 : else if (pszGFSSchemaLocation != nullptr)
145 : {
146 11232 : if (!STARTS_WITH(pszGFSSchemaLocation, "http://") &&
147 7488 : !STARTS_WITH(pszGFSSchemaLocation, "https://") &&
148 3744 : CPLIsFilenameRelative(pszGFSSchemaLocation))
149 : {
150 3744 : pszGFSSchemaLocation = CPLFormFilename(
151 : CPLGetPath(pszRegistryFilename), pszGFSSchemaLocation, nullptr);
152 : }
153 3744 : osGFSSchemaLocation = pszGFSSchemaLocation;
154 : }
155 :
156 4129 : if (pszElementValue != nullptr)
157 : {
158 384 : osElementValue = pszElementValue;
159 : }
160 :
161 4129 : return true;
162 : }
|