LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/georss - ogrgeorssdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 44 46 95.7 %
Date: 2024-05-04 12:52:34 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GeoRSS Translator
       4             :  * Purpose:  Implements OGRGeoRSSDriver.
       5             :  * Author:   Even Rouault, even dot rouault at spatialys.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2008, 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
      21             :  * OR 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 "ogr_georss.h"
      30             : 
      31             : #include <cstring>
      32             : 
      33             : #include "cpl_conv.h"
      34             : #include "cpl_error.h"
      35             : #include "cpl_port.h"
      36             : #include "cpl_vsi.h"
      37             : #include "gdal.h"
      38             : #include "gdal_priv.h"
      39             : #include "ogr_core.h"
      40             : 
      41             : /************************************************************************/
      42             : /*                                Open()                                */
      43             : /************************************************************************/
      44             : 
      45       22968 : static GDALDataset *OGRGeoRSSDriverOpen(GDALOpenInfo *poOpenInfo)
      46             : 
      47             : {
      48       22968 :     if (poOpenInfo->eAccess == GA_Update || poOpenInfo->fpL == nullptr)
      49       20789 :         return nullptr;
      50             : 
      51        2179 :     if (strstr((const char *)poOpenInfo->pabyHeader, "<rss") == nullptr &&
      52        2168 :         strstr((const char *)poOpenInfo->pabyHeader, "<feed") == nullptr &&
      53        2165 :         strstr((const char *)poOpenInfo->pabyHeader, "<atom:feed") == nullptr)
      54        2164 :         return nullptr;
      55             : 
      56          15 :     OGRGeoRSSDataSource *poDS = new OGRGeoRSSDataSource();
      57             : 
      58          15 :     if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->eAccess == GA_Update))
      59             :     {
      60           1 :         delete poDS;
      61           1 :         poDS = nullptr;
      62             :     }
      63             : 
      64          15 :     return poDS;
      65             : }
      66             : 
      67             : /************************************************************************/
      68             : /*                               Create()                               */
      69             : /************************************************************************/
      70             : 
      71             : static GDALDataset *
      72          40 : OGRGeoRSSDriverCreate(const char *pszName, CPL_UNUSED int nBands,
      73             :                       CPL_UNUSED int nXSize, CPL_UNUSED int nYSize,
      74             :                       CPL_UNUSED GDALDataType eDT, char **papszOptions)
      75             : {
      76          40 :     OGRGeoRSSDataSource *poDS = new OGRGeoRSSDataSource();
      77             : 
      78          40 :     if (!poDS->Create(pszName, papszOptions))
      79             :     {
      80           1 :         delete poDS;
      81           1 :         poDS = nullptr;
      82             :     }
      83             : 
      84          40 :     return poDS;
      85             : }
      86             : 
      87             : /************************************************************************/
      88             : /*                               Delete()                               */
      89             : /************************************************************************/
      90             : 
      91          32 : static CPLErr OGRGeoRSSDriverDelete(const char *pszFilename)
      92             : 
      93             : {
      94          32 :     if (VSIUnlink(pszFilename) == 0)
      95          32 :         return CE_None;
      96             :     else
      97           0 :         return CE_Failure;
      98             : }
      99             : 
     100             : /************************************************************************/
     101             : /*                           RegisterOGRGeoRSS()                           */
     102             : /************************************************************************/
     103             : 
     104        1520 : void RegisterOGRGeoRSS()
     105             : 
     106             : {
     107        1520 :     if (!GDAL_CHECK_VERSION("OGR/GeoRSS driver"))
     108           0 :         return;
     109             : 
     110        1520 :     if (GDALGetDriverByName("GeoRSS") != nullptr)
     111         301 :         return;
     112             : 
     113        1219 :     GDALDriver *poDriver = new GDALDriver();
     114             : 
     115        1219 :     poDriver->SetDescription("GeoRSS");
     116        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
     117        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES");
     118        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_DELETE_LAYER, "YES");
     119        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES");
     120        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES");
     121        1219 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "GeoRSS");
     122        1219 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/georss.html");
     123             : 
     124        1219 :     poDriver->SetMetadataItem(
     125             :         GDAL_DMD_CREATIONOPTIONLIST,
     126             :         "<CreationOptionList>"
     127             :         "  <Option name='FORMAT' type='string-select' description='whether the "
     128             :         "document must be in RSS 2.0 or Atom 1.0 format' default='RSS'>"
     129             :         "    <Value>RSS</Value>"
     130             :         "    <Value>ATOM</Value>"
     131             :         "  </Option>"
     132             :         "  <Option name='GEOM_DIALECT' type='string-select' "
     133             :         "description='encoding of location information' default='SIMPLE'>"
     134             :         "    <Value>SIMPLE</Value>"
     135             :         "    <Value>GML</Value>"
     136             :         "    <Value>W3C_GEO</Value>"
     137             :         "  </Option>"
     138             :         "  <Option name='USE_EXTENSIONS' type='boolean' description='Whether "
     139             :         "extension fields (that is to say fields not in the base schema of RSS "
     140             :         "or Atom documents) will be written' default='NO'/>"
     141             :         "  <Option name='WRITE_HEADER_AND_FOOTER' type='boolean' "
     142             :         "description='Whether header and footer are written' default='YES'/>"
     143             :         "  <Option name='HEADER' type='string' description='XML content that "
     144             :         "will be put between the &lt;channel&gt; element and the first "
     145             :         "&lt;item&gt; element for a RSS document, or between the xml tag and "
     146             :         "the first &lt;entry&gt; element for an Atom document. If it is "
     147             :         "specified, it will overload the following options'/>"
     148             :         "  <Option name='TITLE' type='string' description='value put inside "
     149             :         "the &lt;title&gt; element in the header'/>"
     150             :         "  <Option name='DESCRIPTION' type='string' description='(RSS only) "
     151             :         "value put inside the &lt;description&gt; element in the header'/>"
     152             :         "  <Option name='LINK' type='string' description='(RSS only) value put "
     153             :         "inside the &lt;link&gt; element in the header'/>"
     154             :         "  <Option name='UPDATED' type='string' description='(RSS only) value "
     155             :         "put inside the &lt;updated&gt; element in the header. Should be "
     156             :         "formatted as a XML datetime'/>"
     157             :         "  <Option name='AUTHOR_NAME' type='string' description='(ATOM only) "
     158             :         "value put inside the &lt;author&gt;&lt;name&gt; element in the "
     159             :         "header'/>"
     160             :         "  <Option name='ID' type='string' description='(ATOM only) value put "
     161             :         "inside the &lt;id&gt; element in the header.'/>"
     162        1219 :         "</CreationOptionList>");
     163        1219 :     poDriver->SetMetadataItem(GDAL_DS_LAYER_CREATIONOPTIONLIST,
     164        1219 :                               "<LayerCreationOptionList/>");
     165        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     166        1219 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
     167             : 
     168        1219 :     poDriver->pfnOpen = OGRGeoRSSDriverOpen;
     169        1219 :     poDriver->pfnCreate = OGRGeoRSSDriverCreate;
     170        1219 :     poDriver->pfnDelete = OGRGeoRSSDriverDelete;
     171             : 
     172        1219 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     173             : }

Generated by: LCOV version 1.14