<?xml version="1.0" encoding="UTF-8"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp" xmlns:oai="http://www.culture.gouv.fr/ns/oai/">
    <xsp:structure>
        <xsp:include>fr.gouv.culture.oai.*</xsp:include>
        <xsp:include>fr.gouv.culture.sdx.framework.Framework</xsp:include>
        <xsp:include>fr.gouv.culture.sdx.framework.FrameworkImpl</xsp:include>
        <xsp:include>fr.gouv.culture.sdx.application.Application</xsp:include>
        <xsp:include>fr.gouv.culture.sdx.documentbase.DocumentBase</xsp:include>
        <xsp:include>fr.gouv.culture.sdx.utils.Utilities</xsp:include>
        <xsp:include>org.apache.cocoon.xml.ContentHandlerWrapper</xsp:include>
        <xsp:include>org.apache.avalon.framework.service.ServiceManager</xsp:include>
        <xsp:include>org.apache.avalon.framework.service.WrapperServiceManager</xsp:include>
    </xsp:structure>
    <xsp:init-page>
        <xsp:logic>
    		ServiceManager cocoon_serviceManager = new WrapperServiceManager(manager);   
    		this.setConsumer(new ContentHandlerWrapper(contentHandler));
    	</xsp:logic>
    </xsp:init-page>
    <oai:dummyRoot>
        <xsp:logic>
        	
            try{
            String app = parameters.getParameter("appbypath", null);
            String base = parameters.getParameter("base", null);
            FrameworkImpl frame = (FrameworkImpl) cocoon_serviceManager.lookup(Framework.ROLE);

                if (Utilities.checkString(app) &amp;&amp; Utilities.checkString(base))
                {
                    Application appli = null;
                    DocumentBase docbase = null;
                    OAIRepository oaiRepo = null;

                    if (frame != null)
                        appli = frame.getApplicationByPath(app);
                    if (appli != null)
                        docbase = appli.getDocumentBase(base);
                    if (docbase != null)
                        oaiRepo = docbase.getOAIRepository();

                    OAIComponentImpl oaiComp = (OAIComponentImpl) cocoon_serviceManager.lookup(OAIComponent.ROLE);
                    if (oaiComp != null)
                        oaiComp.acceptRequest(oaiRepo,request, xmlConsumer);
                }
            } catch (Exception e){
                e.printStackTrace(System.out);
            } 
        </xsp:logic>
    </oai:dummyRoot>
</xsp:page>
