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 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "ogr_georss.h" 14 : 15 : #include <cstring> 16 : 17 : #include "cpl_conv.h" 18 : #include "cpl_error.h" 19 : #include "cpl_port.h" 20 : #include "cpl_vsi.h" 21 : #include "gdal.h" 22 : #include "gdal_priv.h" 23 : #include "ogr_core.h" 24 : 25 : /************************************************************************/ 26 : /* Open() */ 27 : /************************************************************************/ 28 : 29 24768 : static GDALDataset *OGRGeoRSSDriverOpen(GDALOpenInfo *poOpenInfo) 30 : 31 : { 32 24768 : if (poOpenInfo->eAccess == GA_Update || poOpenInfo->fpL == nullptr) 33 22329 : return nullptr; 34 : 35 2439 : if (strstr((const char *)poOpenInfo->pabyHeader, "<rss") == nullptr && 36 2428 : strstr((const char *)poOpenInfo->pabyHeader, "<feed") == nullptr && 37 2425 : strstr((const char *)poOpenInfo->pabyHeader, "<atom:feed") == nullptr) 38 2424 : return nullptr; 39 : 40 15 : OGRGeoRSSDataSource *poDS = new OGRGeoRSSDataSource(); 41 : 42 15 : if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->eAccess == GA_Update)) 43 : { 44 1 : delete poDS; 45 1 : poDS = nullptr; 46 : } 47 : 48 15 : return poDS; 49 : } 50 : 51 : /************************************************************************/ 52 : /* Create() */ 53 : /************************************************************************/ 54 : 55 : static GDALDataset * 56 40 : OGRGeoRSSDriverCreate(const char *pszName, CPL_UNUSED int nBands, 57 : CPL_UNUSED int nXSize, CPL_UNUSED int nYSize, 58 : CPL_UNUSED GDALDataType eDT, char **papszOptions) 59 : { 60 40 : OGRGeoRSSDataSource *poDS = new OGRGeoRSSDataSource(); 61 : 62 40 : if (!poDS->Create(pszName, papszOptions)) 63 : { 64 1 : delete poDS; 65 1 : poDS = nullptr; 66 : } 67 : 68 40 : return poDS; 69 : } 70 : 71 : /************************************************************************/ 72 : /* Delete() */ 73 : /************************************************************************/ 74 : 75 32 : static CPLErr OGRGeoRSSDriverDelete(const char *pszFilename) 76 : 77 : { 78 32 : if (VSIUnlink(pszFilename) == 0) 79 32 : return CE_None; 80 : else 81 0 : return CE_Failure; 82 : } 83 : 84 : /************************************************************************/ 85 : /* RegisterOGRGeoRSS() */ 86 : /************************************************************************/ 87 : 88 1595 : void RegisterOGRGeoRSS() 89 : 90 : { 91 1595 : if (!GDAL_CHECK_VERSION("OGR/GeoRSS driver")) 92 0 : return; 93 : 94 1595 : if (GDALGetDriverByName("GeoRSS") != nullptr) 95 302 : return; 96 : 97 1293 : GDALDriver *poDriver = new GDALDriver(); 98 : 99 1293 : poDriver->SetDescription("GeoRSS"); 100 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 101 1293 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 102 1293 : poDriver->SetMetadataItem(GDAL_DCAP_DELETE_LAYER, "YES"); 103 1293 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); 104 1293 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 105 1293 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "GeoRSS"); 106 1293 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/georss.html"); 107 : 108 1293 : poDriver->SetMetadataItem( 109 : GDAL_DMD_CREATIONOPTIONLIST, 110 : "<CreationOptionList>" 111 : " <Option name='FORMAT' type='string-select' description='whether the " 112 : "document must be in RSS 2.0 or Atom 1.0 format' default='RSS'>" 113 : " <Value>RSS</Value>" 114 : " <Value>ATOM</Value>" 115 : " </Option>" 116 : " <Option name='GEOM_DIALECT' type='string-select' " 117 : "description='encoding of location information' default='SIMPLE'>" 118 : " <Value>SIMPLE</Value>" 119 : " <Value>GML</Value>" 120 : " <Value>W3C_GEO</Value>" 121 : " </Option>" 122 : " <Option name='USE_EXTENSIONS' type='boolean' description='Whether " 123 : "extension fields (that is to say fields not in the base schema of RSS " 124 : "or Atom documents) will be written' default='NO'/>" 125 : " <Option name='WRITE_HEADER_AND_FOOTER' type='boolean' " 126 : "description='Whether header and footer are written' default='YES'/>" 127 : " <Option name='HEADER' type='string' description='XML content that " 128 : "will be put between the <channel> element and the first " 129 : "<item> element for a RSS document, or between the xml tag and " 130 : "the first <entry> element for an Atom document. If it is " 131 : "specified, it will overload the following options'/>" 132 : " <Option name='TITLE' type='string' description='value put inside " 133 : "the <title> element in the header'/>" 134 : " <Option name='DESCRIPTION' type='string' description='(RSS only) " 135 : "value put inside the <description> element in the header'/>" 136 : " <Option name='LINK' type='string' description='(RSS only) value put " 137 : "inside the <link> element in the header'/>" 138 : " <Option name='UPDATED' type='string' description='(RSS only) value " 139 : "put inside the <updated> element in the header. Should be " 140 : "formatted as a XML datetime'/>" 141 : " <Option name='AUTHOR_NAME' type='string' description='(ATOM only) " 142 : "value put inside the <author><name> element in the " 143 : "header'/>" 144 : " <Option name='ID' type='string' description='(ATOM only) value put " 145 : "inside the <id> element in the header.'/>" 146 1293 : "</CreationOptionList>"); 147 1293 : poDriver->SetMetadataItem(GDAL_DS_LAYER_CREATIONOPTIONLIST, 148 1293 : "<LayerCreationOptionList/>"); 149 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 150 1293 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 151 : 152 1293 : poDriver->pfnOpen = OGRGeoRSSDriverOpen; 153 1293 : poDriver->pfnCreate = OGRGeoRSSDriverCreate; 154 1293 : poDriver->pfnDelete = OGRGeoRSSDriverDelete; 155 : 156 1293 : GetGDALDriverManager()->RegisterDriver(poDriver); 157 : }