2 from oai.handlers import Catalogue
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
9 ns_map = {'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI}
12 def fbc_oai_dc_writer(element, metadata):
13 """FBC notified us that original writer does not output all necessary namespace declarations.
15 e_dc = SubElement(element, nsoaidc('dc'),
16 nsmap={'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI})
17 e_dc.set('{%s}schemaLocation' % NS_XSI,
18 '%s http://www.openarchives.org/OAI/2.0/oai_dc.xsd' % NS_OAIDC)
19 map = metadata.getMap()
21 'title', 'creator', 'subject', 'description', 'publisher',
22 'contributor', 'date', 'type', 'format', 'identifier',
23 'source', 'language', 'relation', 'coverage', 'rights',
24 'isPartOf', 'hasPart']:
25 for value in map.get(name, []):
26 e = SubElement(e_dc, nsdc(name))
30 metadata_registry = MetadataRegistry()
31 metadata_registry.registerWriter('oai_dc', fbc_oai_dc_writer)
33 server = ServerBase(Catalogue(metadata_registry), metadata_registry,
38 resp = server.handleRequest(request.GET)
39 return HttpResponse(resp, content_type='application/xml')