Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use local XML schemas for XML validation #387

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions a3m/cli/client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from a3m.api.transferservice import v1beta1 as transfer_service_api
from a3m.cli.client.wrapper import ClientWrapper
from a3m.cli.common import configure_xml_catalog_files
from a3m.cli.common import init_django
from a3m.cli.common import suppress_warnings
from a3m.server.rpc.client import Client
Expand Down Expand Up @@ -53,6 +54,7 @@ def main(ctx, uri, name, address, processing_config, wait_for_ready, no_input):
"""
init_django()
suppress_warnings()
configure_xml_catalog_files()

# Disable logging.
if not settings.DEBUG:
Expand Down
8 changes: 8 additions & 0 deletions a3m/cli/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
import sys
import warnings

Expand All @@ -25,3 +26,10 @@ def init_django():
"""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "a3m.settings.common")
django.setup()


def configure_xml_catalog_files():
"""Use local XML schemas for validation."""
os.environ["XML_CATALOG_FILES"] = str(
pathlib.Path(__file__).parent.parent / "client/assets/catalog/catalog.xml"
)
2 changes: 2 additions & 0 deletions a3m/cli/server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.conf import settings

from a3m import __version__
from a3m.cli.common import configure_xml_catalog_files
from a3m.cli.common import init_django
from a3m.cli.common import suppress_warnings

Expand All @@ -17,6 +18,7 @@
def main():
init_django()
suppress_warnings()
configure_xml_catalog_files()

from a3m.server.runner import create_server

Expand Down
6 changes: 6 additions & 0 deletions a3m/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
import pathlib


THIS_DIR = os.path.dirname(__file__)

ASSETS_DIR = os.path.join(THIS_DIR, "assets", "")

# Use local XML schemas for validation.
os.environ["XML_CATALOG_FILES"] = str(
pathlib.Path(__file__).parent / "assets/catalog/catalog.xml"
)
33 changes: 33 additions & 0 deletions a3m/client/assets/catalog/catalog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">

<group prefer="system">
<system
systemId="http://www.loc.gov/standards/xlink/xlink.xsd"
uri="../mets/xlink.xsd" />

<system
systemId="http://www.loc.gov/standards/mets/version1121/mets.xsd"
uri="../mets/mets.xsd" />

<system
systemId="http://www.loc.gov/standards/premis/v3/premis.xsd"
uri="../premis/premis.xsd" />

<!-- mets-reader-writer still validates against PREMIS 2.2 -->
<system
systemId="http://www.loc.gov/standards/premis/v2/premis-v2-2.xsd"
uri="../premis/premis-v2-2.xsd" />

<system
systemId="http://www.loc.gov/mods/xml.xsd"
uri="../mods/xml.xsd" />

<system
systemId="http://www.loc.gov/standards/mods/v3/mods.xsd"
uri="../mods/mods.xsd" />

</group>

</catalog>
75 changes: 75 additions & 0 deletions a3m/client/assets/mets/xlink.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- METS XLink Schema, v. 2, Nov. 15, 2004 -->
<schema targetNamespace="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" elementFormDefault="qualified">
<!-- global attributes -->
<attribute name="href" type="anyURI"/>
<attribute name="role" type="string"/>
<attribute name="arcrole" type="string"/>
<attribute name="title" type="string" />
<attribute name="show">
<simpleType>
<restriction base="string">
<enumeration value="new" />
<enumeration value="replace" />
<enumeration value="embed" />
<enumeration value="other" />
<enumeration value="none" />
</restriction>
</simpleType>
</attribute>
<attribute name="actuate">
<simpleType>
<restriction base="string">
<enumeration value="onLoad" />
<enumeration value="onRequest" />
<enumeration value="other" />
<enumeration value="none" />
</restriction>
</simpleType>
</attribute>
<attribute name="label" type="string" />
<attribute name="from" type="string" />
<attribute name="to" type="string" />
<attributeGroup name="simpleLink">
<attribute name="type" type="string" fixed="simple" form="qualified" />
<attribute ref="xlink:href" use="optional" />
<attribute ref="xlink:role" use="optional" />
<attribute ref="xlink:arcrole" use="optional" />
<attribute ref="xlink:title" use="optional" />
<attribute ref="xlink:show" use="optional" />
<attribute ref="xlink:actuate" use="optional" />
</attributeGroup>
<attributeGroup name="extendedLink">
<attribute name="type" type="string" fixed="extended" form="qualified" />
<attribute ref="xlink:role" use="optional" />
<attribute ref="xlink:title" use="optional" />
</attributeGroup>
<attributeGroup name="locatorLink">
<attribute name="type" type="string" fixed="locator" form="qualified" />
<attribute ref="xlink:href" use="required" />
<attribute ref="xlink:role" use="optional" />
<attribute ref="xlink:title" use="optional" />
<attribute ref="xlink:label" use="optional" />
</attributeGroup>
<attributeGroup name="arcLink">
<attribute name="type" type="string" fixed="arc" form="qualified" />
<attribute ref="xlink:arcrole" use="optional" />
<attribute ref="xlink:title" use="optional" />
<attribute ref="xlink:show" use="optional" />
<attribute ref="xlink:actuate" use="optional" />
<attribute ref="xlink:from" use="optional" />
<attribute ref="xlink:to" use="optional" />
</attributeGroup>
<attributeGroup name="resourceLink">
<attribute name="type" type="string" fixed="resource" form="qualified" />
<attribute ref="xlink:role" use="optional" />
<attribute ref="xlink:title" use="optional" />
<attribute ref="xlink:label" use="optional" />
</attributeGroup>
<attributeGroup name="titleLink">
<attribute name="type" type="string" fixed="title" form="qualified" />
</attributeGroup>
<attributeGroup name="emptyLink">
<attribute name="type" type="string" fixed="none" form="qualified" />
</attributeGroup>
</schema>
Loading
Loading