<?xml version="1.0"?>
<!--

    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/

-->
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
	<map:components>
		<map:transformers>
			<map:transformer name="StatisticsTransformer" src="org.dspace.app.xmlui.aspect.statistics.StatisticsTransformer"/>
			<map:transformer name="Navigation" src="org.dspace.app.xmlui.aspect.statistics.Navigation"/>
            <map:transformer name="RestrictedItem" src="org.dspace.app.xmlui.aspect.artifactbrowser.RestrictedItem"/>
            <map:transformer name="StatisticsSearchTransformer" src="org.dspace.app.xmlui.aspect.statistics.StatisticsSearchTransformer"/>
            <map:transformer name="StatisticsWorkflowTransformer" src="org.dspace.app.xmlui.aspect.statistics.StatisticsWorkflowTransformer"/>
        </map:transformers>
		<map:matchers default="wildcard">
            <map:matcher name="HandleAuthorizedMatcher" src="org.dspace.app.xmlui.aspect.general.HandleAuthorizedMatcher"/>
			<map:matcher name="HandleTypeMatcher" src="org.dspace.app.xmlui.aspect.general.HandleTypeMatcher"/>
			<map:matcher name="StatisticsAuthorizedMatcher" src="org.dspace.app.xmlui.aspect.statistics.StatisticsAuthorizedMatcher"/>
		</map:matchers>
        <map:selectors>
            <map:selector name="AuthenticatedSelector" src="org.dspace.app.xmlui.aspect.general.AuthenticatedSelector"/>
        </map:selectors>
        <map:actions>
            <map:action name="SearchResultLogAction" src="org.dspace.app.xmlui.aspect.statistics.SearchResultLogAction" />
        </map:actions>
	</map:components>
    
	<map:pipelines>
		<map:pipeline>

			<map:generate/>

            <!--Make sure that the home page also receives statistics-->
            <map:match pattern="">
                <map:match type="StatisticsAuthorizedMatcher" pattern="READ">
                    <map:parameter name="type" value="usage,search,workflow"/>

                    <map:transform type="Navigation"/>
                </map:match>
            </map:match>

            <!--Home page statistics-->
            <map:match pattern="statistics-home">
                <map:match type="StatisticsAuthorizedMatcher" pattern="READ">
                    <map:parameter name="type" value="usage"/>

                    <map:transform type="StatisticsTransformer"/>
                    <map:transform type="Navigation"/>
                </map:match>
            </map:match>

            <map:match pattern="search-statistics">
                <map:match type="StatisticsAuthorizedMatcher" pattern="READ">
                    <map:parameter name="type" value="search"/>

                    <map:transform type="IncludePageMeta">
                        <map:parameter name="javascript.static.statistics#1" value="loadJQuery.js"/>
                        <map:parameter name="javascript.static.statistics#2" value="static/js/usage-statistics.js"/>
                    </map:transform>
                    <map:transform type="StatisticsSearchTransformer"/>
                    <map:transform type="Navigation"/>
                </map:match>
            </map:match>


            <map:match pattern="workflow-statistics">
                <map:match type="StatisticsAuthorizedMatcher" pattern="READ">
                    <map:parameter name="type" value="workflow"/>

                    <map:transform type="IncludePageMeta">
                        <map:parameter name="javascript.static.statistics#1" value="loadJQuery.js"/>
                        <map:parameter name="javascript.static.statistics#2" value="static/js/usage-statistics.js"/>
                    </map:transform>
                    <map:transform type="StatisticsWorkflowTransformer"/>
                    <map:transform type="Navigation"/>
                </map:match>
            </map:match>

            <!--Only show the stats link if we have read rights-->
            <map:match pattern="handle/*/*">
                <map:match type="StatisticsAuthorizedMatcher" pattern="READ">
                    <map:parameter name="type" value="usage,search,workflow"/>

                    <map:transform type="Navigation"/>
                </map:match>
            </map:match>

            <!--Match our statistics-->
            <map:match pattern="handle/*/*/statistics">
                <map:match type="StatisticsAuthorizedMatcher" pattern="READ">
                    <map:parameter name="type" value="usage"/>

                    <map:transform type="StatisticsTransformer"/>
                    <map:transform type="Navigation"/>
                </map:match>

                <map:match type="StatisticsAuthorizedMatcher" pattern="!READ">
                    <map:parameter name="type" value="usage"/>

                    <map:select type="AuthenticatedSelector">
                            <map:when test="eperson">
                                    <map:transform type="RestrictedItem"/>
                                    <map:serialize/>
                            </map:when>
                            <map:otherwise>
                                    <map:act type="StartAuthentication">
                                            <map:parameter name="header" value="xmlui.ArtifactBrowser.RestrictedItem.auth_header"/>
                                            <map:parameter name="message" value="xmlui.ArtifactBrowser.RestrictedItem.auth_message"/>
                                    </map:act>
                                    <map:serialize/>
                            </map:otherwise>
                    </map:select>
                </map:match>
            </map:match>

            <!--Match for search statistics-->
            <map:match pattern="handle/*/*/search-statistics">
                <map:match type="StatisticsAuthorizedMatcher" pattern="READ">
                    <map:parameter name="type" value="search"/>

                    <map:transform type="IncludePageMeta">
                        <map:parameter name="javascript.static.statistics#1" value="loadJQuery.js"/>
                        <map:parameter name="javascript.static.statistics#2" value="static/js/usage-statistics.js"/>
                    </map:transform>
                    <map:transform type="StatisticsSearchTransformer"/>
                    <map:transform type="Navigation"/>
                </map:match>

                <map:match type="StatisticsAuthorizedMatcher" pattern="!READ">
                    <map:parameter name="type" value="search"/>

                    <map:select type="AuthenticatedSelector">
                            <map:when test="eperson">
                                    <map:transform type="RestrictedItem"/>
                                    <map:serialize/>
                            </map:when>
                            <map:otherwise>
                                    <map:act type="StartAuthentication">
                                            <map:parameter name="header" value="xmlui.ArtifactBrowser.RestrictedItem.auth_header"/>
                                            <map:parameter name="message" value="xmlui.ArtifactBrowser.RestrictedItem.auth_message"/>
                                    </map:act>
                                    <map:serialize/>
                            </map:otherwise>
                    </map:select>
                </map:match>
            </map:match>


            <map:match pattern="handle/*/*/workflow-statistics">
                <map:match type="StatisticsAuthorizedMatcher" pattern="READ">
                    <map:parameter name="type" value="workflow"/>

                    <map:transform type="IncludePageMeta">
                        <map:parameter name="javascript.static.statistics#1" value="loadJQuery.js"/>
                        <map:parameter name="javascript.static.statistics#2" value="static/js/usage-statistics.js"/>
                    </map:transform>
                    <map:transform type="StatisticsWorkflowTransformer"/>
                    <map:transform type="Navigation"/>
                </map:match>

                <map:match type="StatisticsAuthorizedMatcher" pattern="!READ">
                    <map:parameter name="type" value="workflow"/>

                    <map:select type="AuthenticatedSelector">
                            <map:when test="eperson">
                                    <map:transform type="RestrictedItem"/>
                                    <map:serialize/>
                            </map:when>
                            <map:otherwise>
                                    <map:act type="StartAuthentication">
                                            <map:parameter name="header" value="xmlui.ArtifactBrowser.RestrictedItem.auth_header"/>
                                            <map:parameter name="message" value="xmlui.ArtifactBrowser.RestrictedItem.auth_message"/>
                                    </map:act>
                                    <map:serialize/>
                            </map:otherwise>
                    </map:select>
                </map:match>
            </map:match>

            <!-- The legacy Lucene search index has been removed in DSpace 6.0, so mappings
                 for "handle/*/*/search", "handle/*/*/simple-search", and "handle/*/*/advanced-search"
                 have been removed -->

            <map:match pattern="discover">
                <map:transform type="IncludePageMeta">
                    <map:parameter name="javascript.static.statistics#100" value="static/js/discovery/discovery-results.js"/>
                </map:transform>
            </map:match>

            <!-- Handle specific features -->
            <map:match pattern="handle/*/**">
                <!-- Logging in case of a search result -->
               <map:match pattern="handle/*/*">
                   <!-- Make sure we have a search result by checking the parameter -->
                   <map:match type="request-parameter" pattern="search-result">
                       <map:match type="HandleAuthorizedMatcher" pattern="READ">
                           <map:match type="HandleTypeMatcher" pattern="community">
                               <map:act type="SearchResultLogAction"/>
                           </map:match>
                           <map:match type="HandleTypeMatcher" pattern="collection">
                               <map:act type="SearchResultLogAction"/>
                           </map:match>
                           <map:match type="HandleTypeMatcher" pattern="item">
                               <map:act type="SearchResultLogAction"/>
                           </map:match>
                       </map:match>
                   </map:match>
                </map:match>
                <!-- Scoped browse by features -->
                <map:match type="HandleAuthorizedMatcher" pattern="READ">
                    <map:match type="HandleTypeMatcher" pattern="community,collection">

                        <!-- The legacy Lucene search index has been removed in DSpace 6.0, so mappings
                             for "handle/*/*/search", "handle/*/*/simple-search", and "handle/*/*/advanced-search"
                             have been removed -->

                        <!--Optional discovery statistics-->
                        <map:match pattern="handle/*/*/discover">
                            <map:transform type="IncludePageMeta">
                                <map:parameter name="javascript.static.statistics#100" value="static/js/discovery/discovery-results.js"/>
                            </map:transform>
                        </map:match>
                    </map:match>
                    <!-- End match community or collection -->
                </map:match>
                <!-- End match can read -->
            </map:match>
            <!-- End match handle/*/** -->


        <map:serialize type="xml"/>

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