diff --git a/config-sample.yaml b/config-sample.yaml index 4dc1826..b9e9e80 100644 --- a/config-sample.yaml +++ b/config-sample.yaml @@ -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: @@ -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: "" diff --git a/src/acdhOeaw/arche/oaipmh/metadata/LiveCmdiMetadata.php b/src/acdhOeaw/arche/oaipmh/metadata/LiveCmdiMetadata.php index 8593de7..3c55c42 100644 --- a/src/acdhOeaw/arche/oaipmh/metadata/LiveCmdiMetadata.php +++ b/src/acdhOeaw/arche/oaipmh/metadata/LiveCmdiMetadata.php @@ -190,7 +190,7 @@ 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; @@ -198,9 +198,10 @@ public function __construct(RepoResourceDb $resource, } } 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'); }