<?xml version="1.0"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp" xmlns:sdx="http://www.culture.gouv.fr/ns/sdx/sdx">
    <sdx:page langSession="lang" langParam="lang">
        <sdx:userIsSu>
			<!-- list of application candidate (folder with a conf) -->
			<folders>
<xsp:logic>
File server=new File(context.getRealPath("/"));
File[] folders=server.listFiles();
for (int i=0;i &lt; folders.length;i++ ) {
	// if not a directory, let it 
	if (!folders[i].isDirectory()) continue;
	// verify if it has a conf folder
	File[] children=folders[i].listFiles();
	for (int j=0;j &lt; children.length;j++ ) {
		if ("conf".equals(children[j].getName())) {
			<folder><xsp:expr>folders[i].getName()</xsp:expr></folder>
		}
	}
}

</xsp:logic>
			</folders>
            <apps>
                <xsp:logic>
        try 
        {
                        <!-- administrate applications, action reconfigure -->
            if (request.getParameter("reconfigure-server") != null)
            {
                sdx_frame.reconfigure(null);
            }
            else if (request.getParameter("reconfigure") != null)
            {
                sdx_frame.reconfigureApplication(request.getParameter("app"));
            }
            <!-- administrate applications, action close -->
            else if (request.getParameter("close") != null)
            {
                sdx_frame.removeApplication(request.getParameter("app"));
            }
            <!-- administrate applications, action open -->
            else if (request.getParameter("folder") != null)
            {
                sdx_frame.addApplication(request.getParameter("folder"));
            }
        }
        catch (fr.gouv.culture.sdx.exception.SDXException sdx_e) {
                sdx_e.toSAX(contentHandler);
        	 			if (sdx_log != null) sdx_log.error(sdx_e.getMessage(), sdx_e.fillInStackTrace());
        }
            
                </xsp:logic>
            </apps>
            <sdx:fallback>
                <isnot-superuser/>
            </sdx:fallback>
        </sdx:userIsSu>
        <sdx:userIsSu>
			<!-- list of application opened, after the actions -->
			<applications>
				<xsp:logic>
					String id;
					if(sdx_frame.getApplicationIds()!=null){
						for (java.util.Enumeration e=sdx_frame.getApplicationIds(); e.hasMoreElements();)
						{
							id=(String)e.nextElement();
							<application>
								<xsp:attribute name="id"><xsp:expr>id</xsp:expr></xsp:attribute>
								<xsp:attribute name="name"><xsp:expr>id</xsp:expr></xsp:attribute>
								<xsp:attribute name="path"><xsp:expr>sdx_frame.getApplicationById(id).getPath()</xsp:expr></xsp:attribute>
							</application>
							<!-- TODO : application.toSax() -->
						}
					}
				</xsp:logic>
			</applications>
            <bar>
                <button id="welcome" href="index.xsp"/>
                <button id="login" href="loginsu.xsp"/>
                <button id="apps" href="apps.xsp" self="true"/>
                <button id="su" href="superuser.xsp"/>
                <button id="reconfigure" href="reconfigure.xsp"/>
            </bar>
            <sdx:fallback>
                <bar>
                    <button id="welcome" href="index.xsp"/>
                    <button id="login" href="loginsu.xsp"/>
                </bar>
            </sdx:fallback>
        </sdx:userIsSu>
    </sdx:page>
</xsp:page>
