import core
import unicodesplitter
import oaipmh
from schemaRegistry import schemaRegistry

def initialize(context):
    context.registerClass(
        core.OAIService,
        constructors = (
            core.manage_addOAIServiceForm,
            core.manage_addOAIService),
        icon = "www/oai_service.png"
        )
    registerOAIPMHSchemas()
        
def registerOAIPMHSchemas():
    for metadata_prefix, schema in schemaRegistry.items():
        oaipmh_schema = oaipmh.MetadataSchema(metadata_prefix, schema.getNamespaces())
        for field in schema.getFields():
            oaipmh_schema.addFieldDescription(field.id, 'textList', field.getXpath())
        oaipmh.addMetadataSchema(oaipmh_schema)
        