<?xml version="1.0" encoding="UTF-8"?>
<!--

    The contents of this file are subject to the license and copyright
    detailed in the LICENSE and NOTICE files at the root of the source
    tree and available online at

    http://www.dspace.org/license/

-->

<!-- 

	Sword aspect

-->

<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">

    <map:components>

        <map:transformers>
            <map:transformer name="SelectTargetTransformer"
                             src="org.dspace.app.xmlui.aspect.swordclient.SelectTargetTransformer"/>
            <map:transformer name="SelectCollectionTransformer"
                             src="org.dspace.app.xmlui.aspect.swordclient.SelectCollectionTransformer"/>
            <map:transformer name="SelectPackagingTransformer"
                             src="org.dspace.app.xmlui.aspect.swordclient.SelectPackagingTransformer"/>
            <map:transformer name="DepositResponseTransformer"
                             src="org.dspace.app.xmlui.aspect.swordclient.SwordResponseTransformer"/>
            <map:transformer name="Navigation" src="org.dspace.app.xmlui.aspect.swordclient.Navigation"/>
        </map:transformers>

        <map:selectors>
            <map:selector name="AuthenticatedSelector" src="org.dspace.app.xmlui.aspect.general.AuthenticatedSelector"/>
        </map:selectors>


    </map:components>

    <map:flow language="javascript">
        <map:script src="sword.js"/>
    </map:flow>

    <map:pipelines>
        <map:pipeline>
            <!-- Flow Entry points -->

            <map:select type="AuthenticatedSelector">
                <map:when test="administrator">

                    <map:match pattern="swordclient">
                        <map:match type="request" pattern="swordclient-continue">
                            <map:call continuation="{1}"/>
                        </map:match>
                        <map:call function="startSwordDeposit"/>
                    </map:match>

                </map:when>

            </map:select>

            <map:generate/>

            <!-- Add the navigation bar -->
            <map:transform type="Navigation"/>

            <map:select type="AuthenticatedSelector">
                <map:when test="administrator">

                    <map:match type="WildcardParameterMatcher" pattern="true">
                        <map:parameter name="parameter-name" value="flow"/>
                        <map:parameter name="flow" value="{flow-attribute:flow}"/>
                        <!-- General Notices
                        Sometimes notices are generated by flow parameters that are not tied to
                        the specific state. In this case several flow-attributes are created that
                        describe the notice, if they are present then we add them to the DRI document
                        before all other flow pages.
                        -->
                        <map:match pattern="swordclient/**">
                            <map:match type="WildcardParameterMatcher" pattern="true">
                                <map:parameter name="parameter-name" value="notice"/>
                                <map:parameter name="notice" value="{flow-attribute:notice}"/>
                                <map:transform type="notice">
                                    <map:parameter name="outcome" value="{flow-attribute:outcome}"/>
                                    <map:parameter name="header" value="{flow-attribute:header}"/>
                                    <map:parameter name="message" value="{flow-attribute:message}"/>
                                    <map:parameter name="characters" value="{flow-attribute:characters}"/>
                                </map:transform>
                            </map:match>
                        </map:match>
                    </map:match>

                    <map:match pattern="swordclient/select-target">
                        <map:transform type="SelectTargetTransformer">
                            <map:parameter name="handle" value="{flow-attribute:handle}"/>
                            <map:parameter name="errors" value="{flow-attribute:errors}"/>
                        </map:transform>

                    </map:match>

                    <map:match pattern="swordclient/select-collection">
                        <map:transform type="SelectCollectionTransformer">
                            <map:parameter name="handle" value="{flow-attribute:handle}"/>
                        </map:transform>
                    </map:match>

                    <map:match pattern="swordclient/select-packaging">
                        <map:transform type="SelectPackagingTransformer">
                            <map:parameter name="handle" value="{flow-attribute:handle}"/>
                        </map:transform>
                    </map:match>

                    <map:match pattern="swordclient/deposit-response">
                        <map:transform type="DepositResponseTransformer">
                            <map:parameter name="handle" value="{flow-attribute:handle}"/>
                        </map:transform>
                    </map:match>

                </map:when>
                <map:otherwise>

                    <!-- The user is not an administrator (ie not logged in) so redirect them to the login page -->
                    <map:match pattern="swordclient">
                        <map:act type="StartAuthentication"/>
                    </map:match>

                </map:otherwise>
            </map:select>


            <map:serialize type="xml"/>

        </map:pipeline>
    </map:pipelines>

</map:sitemap>
