Skip to content

Commit

Permalink
#181 support M1 - fix conflits between ISO 19115-3/19139 loaded schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Dec 28, 2024
1 parent 3b14cfe commit 80cbf6d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/ISOAbstractObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ ISOAbstractObject <- R6Class("ISOAbstractObject",
}

#proceed with schema xml schema validation
xsd <- getISOMetadataSchemas()
xsd <- getISOMetadataSchemas(version = getMetadataStandard())
if(is(xml, "XMLInternalNode")) xml <- xmlDoc(xml)
report <- xmlSchemaValidate(xsd, xml)

Expand Down
5 changes: 5 additions & 0 deletions R/ISOMetadataNamespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ setISOMetadataNamespaces <- function(version = "19139"){
id = "fcc", uri = "https://standards.iso.org/iso/19110/fcc/1.0",
standard = data.frame(specification = "ISO/TS 19115-3:2023", schema = "ISO/TS 19139:2007", title = "Feature Catalog Common (FCC) Version: 1.0", stringsAsFactors = FALSE)
),
#GFC
ISOMetadataNamespace$new(
id = "gfc", uri = "https://standards.iso.org/iso/19110/gfc/1.1",
standard = data.frame(specification = "ISO/TS 19115-3:2023", schema = "ISO/TS 19139:2007", title = "General Feature Catalog (GFC) Version: 1.1", stringsAsFactors = FALSE)
),
#ISO 19115-3
#----------------------------------------------------
#CAT
Expand Down
29 changes: 20 additions & 9 deletions R/ISOMetadataSchemas.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
#' @description \code{registerISOMetadataSchema} allows to register a new schema
#' in \pkg{geometa}
#'
#' @usage registerISOMetadataSchema(xsdFile)
#' @usage registerISOMetadataSchema(version, xsdFile)
#'
#' @param version the schema version
#' @param xsdFile the schema XSD file
#'
#' @examples
#' registerISOMetadataSchema(xsdFile = "http://www.isotc211.org/2005/gmd/gmd.xsd")
#'
#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com}
#
registerISOMetadataSchema <- function(xsdFile){
registerISOMetadataSchema <- function(version, xsdFile){
schemas <- tryCatch(
XML::xmlParse(
xsdFile, isSchema = TRUE, xinclude = TRUE,
error = function (msg, code, domain, line, col, level, filename, class = "XMLError"){}
error = function (msg, code, domain, line, col, level, filename, class = "XMLError"){
print("=>")
print(filename)
print(msg)
}
)
)
.geometa.iso$schemas <- schemas
.geometa.iso$schemas[[version]] <- schemas
}

#'getISOMetadataSchemaFile
Expand Down Expand Up @@ -50,7 +55,7 @@ getISOMetadataSchemaFile <- function(version = "19139"){
#'@export
setISOMetadataSchemas <- function(version = "19139"){
packageStartupMessage(sprintf("Loading ISO %s XML schemas...", version))
registerISOMetadataSchema(getISOMetadataSchemaFile(version = version))
registerISOMetadataSchema(version = version, getISOMetadataSchemaFile(version = version))
}

#' @name getISOMetadataSchemas
Expand All @@ -59,15 +64,21 @@ setISOMetadataSchemas <- function(version = "19139"){
#' @export
#' @description \code{getISOMetadataSchemas} gets the schemas registered in \pkg{geometa}
#'
#' @usage getISOMetadataSchemas()
#' @usage getISOMetadataSchemas(version)
#'
#' @examples
#' getISOMetadataSchemas()
#' getISOMetadataSchemas(version = "19115-3")
#'
#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com}
#
getISOMetadataSchemas <- function(){
return(.geometa.iso$schemas)
getISOMetadataSchemas <- function(version = "19139"){
available_versions <- c("19139","19115-3")
if(!version %in% available_versions){
errMsg <- sprintf("Version '%s' not among available schema versions (%s)",
version, paste0(available_versions, collapse = ","))
stop(errMsg)
}
return(.geometa.iso$schemas[[version]])
}


Expand Down
4 changes: 2 additions & 2 deletions man/getISOMetadataSchemas.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/registerISOMetadataSchema.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 80cbf6d

Please sign in to comment.