Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: NAS Reader
5 : * Purpose: Private Declarations for OGR NAS Reader code.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2008, Frank Warmerdam
10 : * Copyright (c) 2010-2013, Even Rouault <even dot rouault at spatialys.com>
11 : *
12 : * Permission is hereby granted, free of charge, to any person obtaining a
13 : * copy of this software and associated documentation files (the "Software"),
14 : * to deal in the Software without restriction, including without limitation
15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : * and/or sell copies of the Software, and to permit persons to whom the
17 : * Software is furnished to do so, subject to the following conditions:
18 : *
19 : * The above copyright notice and this permission notice shall be included
20 : * in all copies or substantial portions of the Software.
21 : *
22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 : * DEALINGS IN THE SOFTWARE.
29 : ****************************************************************************/
30 :
31 : #ifndef CPL_NASREADERP_H_INCLUDED
32 : #define CPL_NASREADERP_H_INCLUDED
33 :
34 : #include "xercesc_headers.h"
35 : #include "ogr_xerces.h"
36 :
37 : #include "gmlreader.h"
38 : #include "gmlreaderp.h"
39 : #include "ogr_api.h"
40 : #include "ogr_geometry.h"
41 : #include "cpl_string.h"
42 : #include <list>
43 :
44 : IGMLReader *CreateNASReader();
45 :
46 : class NASReader;
47 :
48 : CPL_C_START
49 : OGRGeometryH OGR_G_CreateFromGML3(const char *pszGML);
50 : CPL_C_END
51 :
52 : /************************************************************************/
53 : /* NASHandler */
54 : /************************************************************************/
55 : class NASHandler final : public DefaultHandler
56 : {
57 : NASReader *m_poReader;
58 :
59 : char *m_pszCurField;
60 :
61 : char *m_pszGeometry;
62 : int m_nGeomAlloc;
63 : int m_nGeomLen;
64 :
65 : int m_nGeometryDepth;
66 : int m_nGeometryPropertyIndex;
67 : bool IsGeometryElement(const char *);
68 :
69 : int m_nDepth;
70 : int m_nDepthFeature;
71 : bool m_bIgnoreFeature;
72 :
73 : CPLString m_osDeleteContext;
74 : CPLString m_osTypeName;
75 : CPLString m_osReplacingFID;
76 : CPLString m_osSafeToIgnore;
77 : CPLString m_osUpdatePropertyName;
78 : CPLString m_osUpdateEnds;
79 : CPLString m_osFeatureId;
80 : std::list<CPLString> m_UpdateOccasions;
81 :
82 : CPLString m_osElementName;
83 : CPLString m_osCharacters;
84 :
85 : const Locator *m_Locator;
86 :
87 : public:
88 : explicit NASHandler(NASReader *poReader);
89 : virtual ~NASHandler();
90 :
91 : void startElement(const XMLCh *const uri, const XMLCh *const localname,
92 : const XMLCh *const qname,
93 : const Attributes &attrs) override;
94 : void endElement(const XMLCh *const uri, const XMLCh *const localname,
95 : const XMLCh *const qname) override;
96 : #if XERCES_VERSION_MAJOR >= 3
97 : void characters(const XMLCh *const chars, const XMLSize_t length) override;
98 : #else
99 : void characters(const XMLCh *const chars, const unsigned int length);
100 : #endif
101 :
102 : void fatalError(const SAXParseException &) override;
103 :
104 : void setDocumentLocator(const Locator *locator) override;
105 :
106 : CPLString GetAttributes(const Attributes *attr);
107 : };
108 :
109 : /************************************************************************/
110 : /* GMLReadState */
111 : /************************************************************************/
112 :
113 : // for now, use existing gmlreadstate.
114 : #ifdef notdef
115 : class GMLReadState
116 : {
117 : void RebuildPath();
118 :
119 : public:
120 : GMLReadState();
121 : ~GMLReadState();
122 :
123 : void PushPath(const char *pszElement);
124 : void PopPath();
125 :
126 : int MatchPath(const char *pszPathInput);
127 :
128 : const char *GetPath() const
129 : {
130 : return m_pszPath;
131 : }
132 :
133 : const char *GetLastComponent() const;
134 :
135 : GMLFeature *m_poFeature;
136 : GMLReadState *m_poParentState;
137 :
138 : char *m_pszPath; // element path ... | as separator.
139 :
140 : int m_nPathLength;
141 : char **m_papszPathComponents;
142 : };
143 : #endif
144 :
145 : /************************************************************************/
146 : /* NASReader */
147 : /************************************************************************/
148 :
149 : class NASReader final : public IGMLReader
150 : {
151 : private:
152 : bool m_bClassListLocked;
153 :
154 : int m_nClassCount;
155 : GMLFeatureClass **m_papoClass;
156 :
157 : char *m_pszFilename;
158 :
159 : NASHandler *m_poNASHandler;
160 : SAX2XMLReader *m_poSAXReader;
161 : bool m_bReadStarted;
162 : bool m_bXercesInitialized;
163 : XMLPScanToken m_oToFill;
164 :
165 : GMLReadState *m_poState;
166 :
167 : GMLFeature *m_poCompleteFeature;
168 : VSILFILE *m_fp;
169 : InputSource *m_GMLInputSource;
170 :
171 : bool SetupParser();
172 : void CleanupParser();
173 :
174 : char *m_pszFilteredClassName;
175 : bool m_bStopParsing = false;
176 :
177 : public:
178 : NASReader();
179 : virtual ~NASReader();
180 :
181 6 : bool IsClassListLocked() const override
182 : {
183 6 : return m_bClassListLocked;
184 : }
185 :
186 3 : void SetClassListLocked(bool bFlag) override
187 : {
188 3 : m_bClassListLocked = bFlag;
189 3 : }
190 :
191 : void SetSourceFile(const char *pszFilename) override;
192 : const char *GetSourceFileName() override;
193 :
194 38 : int GetClassCount() const override
195 : {
196 38 : return m_nClassCount;
197 : }
198 :
199 : GMLFeatureClass *GetClass(int i) const override;
200 : GMLFeatureClass *GetClass(const char *pszName) const override;
201 :
202 : int AddClass(GMLFeatureClass *poClass) override;
203 : void ClearClasses() override;
204 :
205 : GMLFeature *NextFeature() override;
206 :
207 : bool LoadClasses(const char *pszFile = nullptr) override;
208 : bool SaveClasses(const char *pszFile = nullptr) override;
209 :
210 : bool PrescanForSchema(bool bGetExtents = true,
211 : bool bOnlyDetectSRS = false) override;
212 : bool PrescanForTemplate() override;
213 : void ResetReading() override;
214 :
215 : bool ParseXSD(const char * /* pszFile */)
216 : {
217 : return false;
218 : }
219 :
220 : bool ResolveXlinks(const char *pszFile, bool *pbOutIsTempFile,
221 : char **papszSkip = nullptr,
222 : const bool bStrict = false) override;
223 :
224 : bool HugeFileResolver(const char *pszFile, bool bSqliteIsTempFile,
225 : int iSqliteCacheMB) override;
226 :
227 : // ---
228 :
229 1060 : GMLReadState *GetState() const
230 : {
231 1060 : return m_poState;
232 : }
233 :
234 : void PopState();
235 : void PushState(GMLReadState *);
236 :
237 : bool IsFeatureElement(const char *pszElement);
238 : bool IsAttributeElement(const char *pszElement, const Attributes &attrs);
239 :
240 : void PushFeature(const char *pszElement, const Attributes &attrs);
241 :
242 : void SetFeaturePropertyDirectly(const char *pszElement, char *pszValue);
243 :
244 0 : void StopParsing()
245 : {
246 0 : m_bStopParsing = true;
247 0 : }
248 :
249 0 : bool HasStoppedParsing() override
250 : {
251 0 : return m_bStopParsing;
252 : }
253 :
254 : int GetAttributeElementIndex(const char *pszElement, int nLen,
255 : const char *pszAttrKey);
256 : void DealWithAttributes(const char *pszElement, int nLenName,
257 : const Attributes &attrs);
258 :
259 0 : virtual const char *GetGlobalSRSName() override
260 : {
261 0 : return nullptr;
262 : }
263 :
264 0 : virtual bool CanUseGlobalSRSName() override
265 : {
266 0 : return false;
267 : }
268 :
269 : bool SetFilteredClassName(const char *pszClassName) override;
270 :
271 9 : const char *GetFilteredClassName() override
272 : {
273 9 : return m_pszFilteredClassName;
274 : }
275 :
276 : static OGRGeometry *ConvertGeometry(OGRGeometry *);
277 : };
278 :
279 : #endif /* CPL_NASREADERP_H_INCLUDED */
|