Skip to content

Commit

Permalink
support #62 move from XML to xml2
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jan 26, 2024
1 parent c52032a commit 9445267
Show file tree
Hide file tree
Showing 100 changed files with 452 additions and 1,485 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: geosapi
Type: Package
Title: GeoServer REST API R Interface
Version: 0.6-7
Date: 2023-10-04
Version: 0.7
Date: 2024-01-26
Authors@R: c(person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com", comment = c(ORCID = "0000-0002-5870-5762")))
Maintainer: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
Description: Provides an R interface to the GeoServer REST API, allowing to upload
Expand All @@ -12,8 +12,8 @@ Description: Provides an R interface to the GeoServer REST API, allowing to uplo
layers, styles, as well as vector data upload operations. For more information about
the GeoServer REST API, see <https://docs.geoserver.org/stable/en/user/rest/>.
Depends: R (>= 3.1.0)
Imports: R6, openssl, httr, XML, keyring, readr
Suggests: testthat, roxygen2, covr, shiny, knitr, markdown
Imports: R6, openssl, httr, xml2, keyring, readr
Suggests: testthat, waldo, roxygen2, shiny, knitr, markdown
License: MIT + file LICENSE
URL: https://github.com/eblondel/geosapi, https://eblondel.github.io/geosapi/, https://geoserver.org/
BugReports: https://github.com/eblondel/geosapi/issues
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(GSLayerGroup)
export(GSLayerManager)
export(GSManager)
export(GSMetadataLink)
export(GSMonitorManager)
export(GSNamespace)
export(GSNamespaceManager)
export(GSOracleNGDataStore)
Expand All @@ -46,9 +47,9 @@ export(GSWorkspace)
export(GSWorkspaceManager)
export(GSWorkspaceSettings)
export(GSWorldImageCoverageStore)
import(XML)
import(httr)
import(keyring)
import(xml2)
importFrom(R6,R6Class)
importFrom(openssl,base64_encode)
importFrom(readr,read_csv)
Expand Down
11 changes: 6 additions & 5 deletions R/GSAbstractCoverageStore.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GSAbstractCoverageStore <- R6Class("GSAbstractCoverageStore",
url = NULL,

#'@description initializes an abstract coverage store
#'@param xml an object of class \link{XMLInternalNode-class} to create object from XML
#'@param xml an object of class \link{xml_node-class} to create object from XML
#'@param type the type of coverage store
#'@param name coverage store name
#'@param description coverage store description
Expand All @@ -30,7 +30,7 @@ GSAbstractCoverageStore <- R6Class("GSAbstractCoverageStore",
super$initialize(xml = xml, storeType = private$STORE_TYPE, type = type,
name = name, description = description, enabled = enabled)
if(!missing(xml) & !is.null(xml)){
if(!any(class(xml) %in% c("XMLInternalNode","XMLInternalDocument"))){
if(!any(class(xml) %in% c("xml_document","xml_node"))){
stop("The argument 'xml' is not a valid XML object")
}
self$decode(xml)
Expand All @@ -40,12 +40,13 @@ GSAbstractCoverageStore <- R6Class("GSAbstractCoverageStore",
},

#'@description Decodes a coverage store from XML
#'@param xml an object of class \link{XMLInternalNode-class}
#'@param xml an object of class \link{xml_node-class}
#'@return an object of class \link{GSAbstractCoverageStore}
decode = function(xml){
xml = xml2::as_xml_document(xml)
super$decode(xml)
urlXML <- getNodeSet(xml,"//url")
if(length(urlXML) > 0) self$url <- xmlValue(urlXML[[1]])
urlXML <- xmL2::xml_find_first(xml,"//url")
if(length(urlXML) > 0) self$url <- xml2::xml_text(urlXML)
},

#'@description set coverage store URL
Expand Down
2 changes: 1 addition & 1 deletion R/GSAbstractDBDataStore.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GSAbstractDBDataStore <- R6Class("GSAbstractDBDataStore",
public = list(

#'@description initializes an abstract DB data store
#'@param xml an object of class \link{XMLInternalNode-class} to create object from XML
#'@param xml an object of class \link{xml_node-class} to create object from XML
#'@param type the type of DB data store
#'@param dbType DB type
#'@param name coverage store name
Expand Down
7 changes: 4 additions & 3 deletions R/GSAbstractDataStore.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GSAbstractDataStore <- R6Class("GSAbstractDataStore",
connectionParameters = NULL,

#'@description initializes an abstract data store
#'@param xml an object of class \link{XMLInternalNode-class} to create object from XML
#'@param xml an object of class \link{xml_node-class} to create object from XML
#'@param type the type of coverage store
#'@param name coverage store name
#'@param description coverage store description
Expand All @@ -31,7 +31,7 @@ GSAbstractDataStore <- R6Class("GSAbstractDataStore",
super$initialize(xml = xml, storeType = private$STORE_TYPE, type = type,
name = name, description = description, enabled = enabled)
if(!missing(xml) & !is.null(xml)){
if(!any(class(xml) %in% c("XMLInternalNode","XMLInternalDocument"))){
if(!any(class(xml) %in% c("xml_document","xml_node"))){
stop("The argument 'xml' is not a valid XML object")
}
self$decode(xml)
Expand All @@ -45,9 +45,10 @@ GSAbstractDataStore <- R6Class("GSAbstractDataStore",
},

#'@description Decodes a data store from XML
#'@param xml an object of class \link{XMLInternalNode-class}
#'@param xml an object of class \link{xml_node-class}
#'@return an object of class \link{GSAbstractDataStore}
decode = function(xml){
xml = xml2::as_xml_document(xml)
super$decode(xml)
self$connectionParameters = GSRESTEntrySet$new(rootName = "connectionParameters", xml)
},
Expand Down
23 changes: 12 additions & 11 deletions R/GSAbstractStore.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GSAbstractStore <- R6Class("GSAbstractStore",
workspace = NULL,

#'@description initializes an abstract store
#'@param xml an object of class \link{XMLInternalNode-class} to create object from XML
#'@param xml an object of class \link{xml_node-class} to create object from XML
#'@param storeType store type
#'@param type the type of coverage store
#'@param name coverage store name
Expand All @@ -40,7 +40,7 @@ GSAbstractStore <- R6Class("GSAbstractStore",
super$initialize(rootName = storeType)
private$store_type = storeType
if(!missing(xml) & !is.null(xml)){
if(!any(class(xml) %in% c("XMLInternalNode","XMLInternalDocument"))){
if(!any(class(xml) %in% c("xml_document","xml_node"))){
stop("The argument 'xml' is not a valid XML object")
}
self$decode(xml)
Expand All @@ -55,20 +55,21 @@ GSAbstractStore <- R6Class("GSAbstractStore",
},

#'@description Decodes store from XML
#'@param xml object of class \link{XMLInternalNode-class}
#'@param xml object of class \link{xml_node-class}
decode = function(xml){
names <- getNodeSet(xml, sprintf("//%s/name", private$store_type))
self$name <- xmlValue(names[[1]])
enabled <- getNodeSet(xml,"//enabled")
xml = xml2::as_xml_document(xml)
names <- xml2::xml_find_first(xml, sprintf("//%s/name", private$store_type))
self$name <- xml2::xml_text(names)
enabled <- xml2::xml_find_first(xml,"//enabled")
self$full <- length(enabled) > 0
if(self$full){
self$enabled <- as.logical(xmlValue(enabled[[1]]))
self$enabled <- as.logical(xml2::xml_text(enabled))

descriptionXML <- getNodeSet(xml,"//description")
if(length(descriptionXML) > 0) self$description <- xmlValue(descriptionXML[[1]])
descriptionXML <- xml2::xml_find_first(xml,"//description")
if(length(descriptionXML) > 0) self$description <- xml2::xml_text(descriptionXML)

typeXML <- getNodeSet(xml,"//type")
if(length(typeXML) > 0) self$type <- xmlValue(typeXML[[1]])
typeXML <- xml2::xml_find_first(xml,"//type")
if(length(typeXML) > 0) self$type <- xml2::xml_text(typeXML)
}
},

Expand Down
2 changes: 1 addition & 1 deletion R/GSArcGridCoverageStore.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GSArcGridCoverageStore <- R6Class("GSArcGridCoverageStore",
url = NULL,

#'@description initializes an abstract ArcGrid coverage store
#'@param xml an object of class \link{XMLInternalNode-class} to create object from XML
#'@param xml an object of class \link{xml_node-class} to create object from XML
#'@param name coverage store name
#'@param description coverage store description
#'@param enabled whether the store should be enabled or not. Default is \code{TRUE}
Expand Down
4 changes: 2 additions & 2 deletions R/GSCoverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ GSCoverage <- R6Class("GSCoverage",
cqlFilter = NULL,

#'@description Initializes a \link{GSCoverage} from XML
#'@param xml object of class \link{XMLInternalNode-class}
#'@param xml object of class \link{xml_node-class}
initialize = function(xml = NULL){
super$initialize(rootName = "coverage")
if(!missing(xml) & !is.null(xml)){
Expand All @@ -34,7 +34,7 @@ GSCoverage <- R6Class("GSCoverage",
},

#'@description Decodes coverage from XML
#'@param xml object of class \link{XMLInternalNode-class}
#'@param xml object of class \link{xml_node-class}
decode = function(xml){
super$decode(xml)
},
Expand Down
20 changes: 10 additions & 10 deletions R/GSCoverageBand.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ GSCoverageBand <- R6Class("GSCoverageBand",
compositionType = "BAND_SELECT",

#'@description Initalizes a \link{GSCoverageBand}
#'@param xml object of class \link{XMLInternalNode-class}
#'@param xml object of class \link{xml_node-class}
initialize = function(xml = NULL){
super$initialize(rootName = "coverageBand")
if(!missing(xml) & !is.null(xml)){
Expand All @@ -65,19 +65,19 @@ GSCoverageBand <- R6Class("GSCoverageBand",
},

#'@description Decodes from XML
#'@param xml object of class \link{XMLInternalNode-class}
#'@param xml object of class \link{xml_node-class}
decode = function(xml){

def <- getNodeSet(xml, "//definition")
self$definition <- xmlValue(def[[1]])
xml = xml2::as_xml_document(xml)
def <- xml2::xml_find_first(xml, "//definition")
self$definition <- xml2::xml_text(def)

idx <- getNodeSet(xml, "//index")
self$index <- xmlValue(idx[[1]])
idx <- xml2::xml_find_first(xml, "//index")
self$index <- xml2::xml_text(idx)

ct <- getNodeSet(xml, "//compositionType")
self$compositionType <- xmlValue(ct[[1]])
ct <- xml2::xml_find_first(xml, "//compositionType")
self$compositionType <- xml2::xml_text(ct)

bands <- getNodeSet(xml, "//inputCoverageBands/inputCoverageBand")
bands <- as(xml2::xml_find_all(xml, "//inputCoverageBands/inputCoverageBand"),"list")
if(length(bands)>0){
for(band in bands){
band <- GSInputCoverageBand$new(xml = band)
Expand Down
18 changes: 7 additions & 11 deletions R/GSCoverageStoreManager.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ GSCoverageStoreManager <- R6Class("GSCoverageStoreManager",
covList <- NULL
if(status_code(req) == 200){
covXML <- GSUtils$parseResponseXML(req)
covXMLList <- getNodeSet(covXML, "//coverageStore")
covList <- lapply(covXMLList, function(x){
xml <- xmlDoc(x)
covType <- xmlValue(xmlChildren(xmlRoot(xml))$type)
covXMLList <- as(xml2::xml_find_all(covXML, "//coverageStore"), "list")
covList <- lapply(covXMLList, function(xml){
covType <- xml2::xml_find_first(xml, "//type") %>% xml::xml_text()
coverageStore <- switch(covType,
"GeoTIFF" = GSGeoTIFFCoverageStore$new(xml = xml),
"WorldImage" = GSWorldImageCoverageStore$new(xml = xml),
Expand Down Expand Up @@ -77,12 +76,12 @@ GSCoverageStoreManager <- R6Class("GSCoverageStoreManager",
coverageStore <- NULL
if(status_code(req) == 200){
covXML <- GSUtils$parseResponseXML(req)
covType <- xmlValue(xmlChildren(xmlRoot(covXML))$type)
covType <- xml2::xml_find_first(covXML, "//type") %>% xml2::xml_text()
coverageStore <- switch(covType,
"GeoTIFF" = GSGeoTIFFCoverageStore$new(xml = covXML),
"WorldImage" = GSWorldImageCoverageStore$new(xml = covXML),
"ImageMosaic" = GSImageMosaicCoverageStore$new(xml = covXML),
"ArcGrid" = GSArcGridCoverageStore$new(xml = xml),
"ArcGrid" = GSArcGridCoverageStore$new(xml = covXML),
GSAbstractCoverageStore$new(xml = covXML)
)
self$INFO("Successfully fetched coverage store!")
Expand Down Expand Up @@ -195,11 +194,8 @@ GSCoverageStoreManager <- R6Class("GSCoverageStoreManager",
covList <- NULL
if(status_code(req) == 200){
covXML <- GSUtils$parseResponseXML(req)
covXMLList <- getNodeSet(covXML, "//coverages/coverage")
covList <- lapply(covXMLList, function(x){
xml <- xmlDoc(x)
return(GSCoverage$new(xml = xml))
})
covXMLList <- as(xml2::xml_find_all(covXML, "//coverages/coverage"), "list")
covList <- lapply(covXMLList, GSCoverage$new)
self$INFO(sprintf("Successfully fetched %s coverages!", length(covList)))
}else{
self$ERROR("Error while fetching list of coverages")
Expand Down
23 changes: 12 additions & 11 deletions R/GSCoverageView.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ GSCoverageView <- R6Class("GSCoverageView",
coverageBands = list(),

#'@description Initializes an object of class \link{GSCoverageView}
#'@param xml object of class \link{XMLInternalNode-class}
#'@param xml object of class \link{xml_node-class}
initialize = function(xml = NULL){
super$initialize(rootName = "coverageView")
if(!missing(xml) & !is.null(xml)){
Expand All @@ -36,21 +36,22 @@ GSCoverageView <- R6Class("GSCoverageView",
},

#'@description Decodes from XML
#'@param xml object of class \link{XMLInternalNode-class}
#'@param xml object of class \link{xml_node-class}
decode = function(xml){
names <- getNodeSet(xml, "//name")
self$name <- xmlValue(names[[1]])
xml = xml2::as_xml_document(xml)
names <- xml2::xml_find_first(xml, "//name")
self$name <- xml2::xml_text(names)

ect <- getNodeSet(xml, "//envelopeCompositionType")
self$envelopeCompositionType <- xmlValue(ect[[1]])
ect <- xml2::xml_find_first(xml, "//envelopeCompositionType")
self$envelopeCompositionType <- xml2::xml_text(ect)

sr <- getNodeSet(xml, "//selectedResolution")
self$selectedResolution <- xmlValue(sr[[1]])
sr <- xml2::xml_find_first(xml, "//selectedResolution")
self$selectedResolution <- xml2::xml_text(sr)

sri <- getNodeSet(xml, "//selectedResolutionIndex")
self$selectedResolutionIndex <- xmlValue(sri[[1]])
sri <- xml2::xml_find_first(xml, "//selectedResolutionIndex")
self$selectedResolutionIndex <- xml2::xml_text(sri)

bands <- getNodeSet(xml, "//coverageBand")
bands <- as(xml2::xml_find_all(xml, "//coverageBand"), "list")
if(length(bands)>0){
for(band in bands){
band <- GSCoverageBand$new(xml = band)
Expand Down
16 changes: 6 additions & 10 deletions R/GSDatastoreManager.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ GSDataStoreManager <- R6Class("GSDataStoreManager",
dsList <- NULL
if(status_code(req) == 200){
dsXML <- GSUtils$parseResponseXML(req)
dsXMLList <- getNodeSet(dsXML, "//dataStore")
dsList <- lapply(dsXMLList, function(x){
xml <- xmlDoc(x)
dsType <- xmlValue(xmlChildren(xmlRoot(xml))$type)
dsXMLList <- as(xml2::xml_find_all(dsXML, "//dataStore"), "list")
dsList <- lapply(dsXMLList, function(xml){
dsType <- xml2::xml_find_first(xml, "//type") %>% xml2::xml_text
dataStore <- switch(dsType,
"Shapefile" = GSShapefileDataStore$new(xml = xml),
"Directory of spatial files (shapefiles)" = GSShapefileDirectoryDataStore$new(xml = xml),
Expand Down Expand Up @@ -79,7 +78,7 @@ GSDataStoreManager <- R6Class("GSDataStoreManager",
dataStore <- NULL
if(status_code(req) == 200){
dsXML <- GSUtils$parseResponseXML(req)
dsType <- xmlValue(xmlChildren(xmlRoot(dsXML))$type)
dsType <- xml2::xml_find_first(dsXML, "//type") %>% xml2::xml_text()
dataStore <- switch(dsType,
"Shapefile" = GSShapefileDataStore$new(xml = dsXML),
"Directory of spatial files (shapefiles)" = GSShapefileDirectoryDataStore$new(xml = dsXML),
Expand Down Expand Up @@ -192,11 +191,8 @@ GSDataStoreManager <- R6Class("GSDataStoreManager",
ftList <- NULL
if(status_code(req) == 200){
ftXML <- GSUtils$parseResponseXML(req)
ftXMLList <- getNodeSet(ftXML, "//featureTypes/featureType")
ftList <- lapply(ftXMLList, function(x){
xml <- xmlDoc(x)
return(GSFeatureType$new(xml = xml))
})
ftXMLList <- as(xml2::xml_find_all(ftXML, "//featureTypes/featureType"), "list")
ftList <- lapply(ftXMLList, GSFeatureType$new)
self$INFO(sprintf("Successfully fetched %s featureTypes!", length(ftList)))
}else{
self$ERROR("Error while fetching list of featureTypes")
Expand Down
19 changes: 11 additions & 8 deletions R/GSDimension.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ GSDimension <- R6Class("GSDimension",
unitSymbol = NULL,

#'@description Initializes an object of class \link{GSDimension}
#'@param xml object of class \link{XMLInternalNode-class}
#'@param xml object of class \link{xml_node-class}
initialize = function(xml = NULL){
super$initialize(rootName = "dimensionInfo")
if(!missing(xml) & !is.null(xml)){
Expand All @@ -41,14 +41,17 @@ GSDimension <- R6Class("GSDimension",
},

#'@description Decodes from XML
#'@param xml object of class \link{XMLInternalNode-class}
#'@param xml object of class \link{xml_node-class}
decode = function(xml){
propsXML <- xmlChildren(xml)
props <- lapply(propsXML, xmlValue)
self$setEnabled(as.logical(props$enabled))
if(!is.null(props$presentation)) self$setPresentation(props$presentation)
self$setUnit(props$units)
self$setUnitSymbol(props$unitSymbol)
xml = xml2::as_xml_document(xml)
enabled = xml2::xml_find_first(xml, "//enabled") %>% xml2::xml_text() %>% as.logical()
self$setEnabled(enabled)
presentation = xml2::xml_find_first(xml, "//presentation") %>% xml2::xml_text()
self$setPresentation(presentation)
units = xml2::xml_find_first(xml, "//units") %>% xml2::xml_text()
self$setUnit(units)
unitSymbol = xml2::xml_find_first(xml, "//unitSymbol") %>% xml2::xml_text()
self$setUnitSymbol(unitSymbol)
},

#'@description Set enabled
Expand Down
Loading

0 comments on commit 9445267

Please sign in to comment.