<?xml version="1.0"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp" xmlns:sdx="http://www.culture.gouv.fr/ns/sdx/sdx" xmlns:api-explore="http://www.culture.gouv.fr/ns/sdx/sdx/api-explore">
	<xsp:structure>
		<xsp:include>fr.gouv.culture.sdx.user.Group</xsp:include>
		<xsp:include>fr.gouv.culture.sdx.user.User</xsp:include>
		<xsp:include>fr.gouv.culture.sdx.documentbase.IndexParameters</xsp:include>
		<xsp:include>java.util.Vector</xsp:include>
		<xsp:include>java.util.Hashtable</xsp:include>
		<xsp:include>java.util.Enumeration</xsp:include>
		<xsp:include>fr.gouv.culture.sdx.documentbase.AbstractDocumentBase</xsp:include>
	</xsp:structure>
	<sdx:page langSession="lang" langParam="lang">
		<sdx:userIsAdminOrSu>
			<!-- Get the application informations -->
			<sdx:app/>
			<!-- logic for forms submit -->
			<xsp:logic>
				<!-- Check which operation was requested by the super-user -->
				if("optimize".equals(request.getParameter("op"))) {
					<!-- if so, we grab the DocumentBase id and perform a full optimization process, we also don't forget to tell the user what is happening -->
				<!-- TODO:
						1- look for the documentBase
						2- check if this thing is not null or getting an exception
						3- eventually, we optimize it
						4- and then we can use the meta just after this comment to let the super-user know about what's going on
					-->
					if(sdx_app != null) {
						sdx_base = sdx_app.getDocumentBase(request.getParameter("base"));
						if(sdx_base != null) {
							<!-- we got an optimization for a specific documentbase here -->
							sdx_base.optimize();
							<!-- Do also the job : sdx_app.optimize(request.getParameter("base")); -->
				<optimizationDone>
					<xsp:attribute name="base">
						<xsp:expr>request.getParameter("base")</xsp:expr>
					</xsp:attribute>
				</optimizationDone>
						} else {
							<!-- if not specific, then the optimization apply on all the application. That mean all documentbases -->
							sdx_app.optimize();
							<optimizationDone/>
						}
					}
				} else if("backup".equals(request.getParameter("op"))) {
					<!-- Here we have a full application backup request, pretty simple logic here -->
					if(sdx_app != null)
					{
						<!-- Apply it -->
						sdx_app.saveApplication();
						<!-- Notify it -->
				<saveApplicationDone/>
					}
				}else if("restore".equals(request.getParameter("op"))) {
					<!-- Here we have a full application backup request, pretty simple logic here -->
					if(sdx_app != null)
					{
						<!-- Apply it -->
						sdx_app.loadApplication(null);
						<!-- Notify it -->
				<!--saveApplicationDone/-->
					} 
				}else if("integrity".equals(request.getParameter("op"))) {
					<!-- Same logic than for optimization yet, but with the integrity check this time -->
				<!-- TODO: add integrity check for repositories and internal databases here when implemented in java-api -->
					if(sdx_app != null) {
						sdx_base = sdx_app.getDocumentBase(request.getParameter("base"));
						if(sdx_base != null) {
							sdx_base.checkIntegrity();
							<checkIntegrityDone>
					<xsp:attribute name="base">
						<xsp:expr>request.getParameter("base")</xsp:expr>
					</xsp:attribute>
				</checkIntegrityDone>
						} else {
							sdx_app.checkIntegrity();
							<checkIntegrityDone/>
						}
					}
				}
			</xsp:logic>
			<!-- end of submited forms managment -->
			<!-- Include the specific CSS for the exploration interface -->
			<sdx:xplorecss/>
			<!-- Get the application name -->
			<appName/>
			<!-- The exploration interface itself, see the XSL file for more information about how it works -->
			<sdx:explore/>
			<bar>
				<button id="welcome" href="index.xsp"/>
				<button id="login" href="login.xsp"/>
				<button id="identities" href="identities.xsp"/>
				<button id="bases" href="bases.xsp" self="true"/>
				<button id="explorer" href="explorer.xsp" self="true"/>
			</bar>
			<sdx:fallback>
				<bar>
					<button id="welcome" href="index.xsp"/>
					<button id="login" href="loginsu.xsp" self="true"/>
				</bar>
			</sdx:fallback>
		</sdx:userIsAdminOrSu>
	</sdx:page>
</xsp:page>
