File indexing completed on 2025-01-05 03:59:10

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