File indexing completed on 2024-05-19 03:51:49

0001 /*
0002     SPDX-FileCopyrightText: 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 
0008 // Own
0009 #include "GeoDataParser.h"
0010 
0011 // Marble
0012 #include "MarbleDebug.h"
0013 
0014 // Geodata
0015 #include "GeoDataDocument.h"
0016 #include "GeoDocument.h"
0017 #include "GeoTagHandler.h"
0018 
0019 
0020 // TODO: GeoRSS support
0021 // #include "GeoRSSElementDictionary.h"
0022 
0023 // KML support
0024 #include "KmlElementDictionary.h"
0025 
0026 namespace Marble
0027 {
0028 
0029 GeoDataParser::GeoDataParser(GeoDataSourceType source)
0030     : GeoParser(source)
0031 {
0032 }
0033 
0034 GeoDataParser::~GeoDataParser()
0035 {
0036 }
0037 
0038 bool GeoDataParser::isValidRootElement()
0039 {
0040     if (m_source == GeoData_UNKNOWN)
0041     {
0042         if (GeoParser::isValidElement(kml::kmlTag_kml))
0043         {
0044             m_source = GeoData_KML;
0045         }
0046         else
0047         {
0048             Q_ASSERT(false);
0049             return false;
0050         }
0051     }
0052     switch ((GeoDataSourceType) m_source) {
0053     // TODO: case GeoData_GeoRSS:
0054     case GeoData_KML:
0055         return isValidElement(kml::kmlTag_kml);
0056     default:
0057         Q_ASSERT(false);
0058         return false;
0059     }
0060 }
0061 
0062 bool GeoDataParser::isValidElement(const QString& tagName) const
0063 {
0064     if (!GeoParser::isValidElement(tagName))
0065         return false;
0066 
0067     switch ((GeoDataSourceType) m_source) {
0068     // TODO: case GeoData_GeoRSS:
0069     case GeoData_KML: {
0070         const QStringRef namespaceUri = this->namespaceUri();
0071         return (namespaceUri == QLatin1String(kml::kmlTag_nameSpace20) ||
0072                 namespaceUri == QLatin1String(kml::kmlTag_nameSpace21) ||
0073                 namespaceUri == QLatin1String(kml::kmlTag_nameSpace22) ||
0074                 namespaceUri == QLatin1String(kml::kmlTag_nameSpaceOgc22) ||
0075                 namespaceUri == QLatin1String(kml::kmlTag_nameSpaceGx22) ||
0076                 namespaceUri == QLatin1String(kml::kmlTag_nameSpaceMx));
0077     }
0078     default:
0079         break;
0080     }
0081 
0082     // Should never be reached.
0083     Q_ASSERT(false);
0084     return false;
0085 }
0086 
0087 GeoDocument* GeoDataParser::createDocument() const
0088 {
0089     return new GeoDataDocument;
0090 }
0091 
0092 // Global helper function for the tag handlers
0093 GeoDataDocument* geoDataDoc(GeoParser& parser)
0094 {
0095     GeoDocument* document = parser.activeDocument();
0096     Q_ASSERT(document->isGeoDataDocument());
0097     return static_cast<GeoDataDocument*>(document);
0098 }
0099 
0100 }