2 from oai.handlers import Catalogue, NS_DCTERMS, nsdcterms
3 from oaipmh.server import ServerBase, oai_dc_writer, NS_OAIDC, NS_DC, NS_XSI, nsoaidc, nsdc
4 from oaipmh.metadata import MetadataRegistry
5 from django.http import HttpResponse
6 from lxml.etree import tostring, SubElement
10 #ns_map = {'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI }
13 def fbc_oai_dc_writer(element, metadata):
14 """FBC notified us that original writer does not output all necessary namespace declarations.
16 e_dc = SubElement(element, nsoaidc('dc'),
17 nsmap={'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI})
18 e_dc.set('{%s}schemaLocation' % NS_XSI,
19 '%s http://www.openarchives.org/OAI/2.0/oai_dc.xsd' % NS_OAIDC)
20 map = metadata.getMap()
22 'title', 'creator', 'subject', 'description', 'publisher',
23 'contributor', 'date', 'type', 'format', 'identifier',
24 'source', 'language', 'relation', 'coverage', 'rights',
26 for value in map.get(name, []):
27 e = SubElement(e_dc, nsdc(name))
31 def qdc_writer(element, metadata):
32 """FBC notified us that original writer does not output all necessary namespace declarations.
34 nsmap={'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI, 'dcterms': NS_DCTERMS}
35 map = metadata.getMap()
37 'title', 'creator', 'subject', 'description', 'publisher',
38 'contributor', 'date', 'type', 'format', 'identifier',
39 'source', 'language', 'relation', 'coverage', 'rights',
41 for value in map.get(name, []):
42 e = SubElement(element, nsdc(name), nsmap=nsmap)
45 for name in ['hasPart', 'isPartOf']:
46 for value in map.get(name, []):
47 e = SubElement(element, nsdcterms(name), nsmap=nsmap)
52 metadata_registry = MetadataRegistry()
53 metadata_registry.registerWriter('oai_dc', fbc_oai_dc_writer)
54 metadata_registry.registerWriter('qdc', qdc_writer)
57 server = ServerBase(Catalogue(metadata_registry), metadata_registry,
62 resp = server.handleRequest(request.GET)
63 return HttpResponse(resp, content_type='application/xml')