Skip to content

Commit

Permalink
LiveCmdiMetadata: introduce a common way for mapping URI values to te…
Browse files Browse the repository at this point in the history
…mplate filenames (closes #4)

All characters out of [-A-Za-z0-9_] class are now converted to underscore.
  • Loading branch information
zozlak committed Jul 9, 2021
1 parent 2e27090 commit 7146068
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions config-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ oai:
defaultLang: en
# Path to the directory storing CMDI XML templates
templateDir: src/acdhOeaw/oai/metadata/liveCmdi
# Metadata property prividng the CMDI schema to be used for a given resource
# Metadata property providng the CMDI schema to be used for a given resource
# The schema is converted to a template filename by replacing all characters out of [-A-Za-z0-9_]
# to an underscore and appending .xml at the end (e.g. http://foo.bar/baz becomes http___foo_bar_baz.xml)
schemaProp: http://can.not.be.overwritten
# Namespace prefixes used in template file's metadata property placeholders
propNmsp:
Expand All @@ -218,7 +220,7 @@ oai:
idNmsp:
id: https://id.acdh.oeaw.ac.at/
cmdiid: https://id.acdh.oeaw.ac.at/cmdi/
# Default CMDI schema to be used when a resource doesn't have the `schemaProp` metadatada property or it points to a schema without a tempalte
# Default CMDI schema to be used when a resource doesn't have the `schemaProp` metadatada property or it points to a schema without a template
schemaDefault: kulturpool
# Handle only resources having `schemaProp` metadata property value equal to the `schemaEnforce` value.
schemaEnforce: ""
7 changes: 4 additions & 3 deletions src/acdhOeaw/arche/oaipmh/metadata/LiveCmdiMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,18 @@ public function __construct(RepoResourceDb $resource,

$formats = $this->res->getGraph()->all($this->format->schemaProp);
foreach ($formats as $i) {
$i = preg_replace('|^.*(clarin.eu:[^/]+).*$|', '\\1', (string) $i);
$i = preg_replace('|[^-A-Za-z0-9_]|', '_', (string) $i);
$path = $this->format->templateDir . '/' . $i . '.xml';
if (file_exists($path)) {
$this->template = $path;
break;
}
}
if ($this->template === null && !empty($this->format->schemaDefault)) {
$this->template = $this->format->templateDir . '/' . $this->format->schemaDefault . '.xml';
$default = preg_replace('|[^-A-Za-z0-9_]|', '_', $this->format->schemaDefault);
$this->template = $this->format->templateDir . '/' . $default . '.xml';
}
if (empty($this->template)) {
if (empty($this->template) || !file_exists($this->template)) {
throw new RuntimeException('No CMDI template matched');
}

Expand Down

0 comments on commit 7146068

Please sign in to comment.