package org.sakaiproject.gradebookng;

import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.cycle.IRequestCycleListener;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.sakaiproject.gradebookng.tool.pages.GradebookPage;

/**
 * Main application class
 * 
 * @author Steve Swinsburg (steve.swinsburg@gmail.com)
 *
 */
public class GradebookNgApplication extends WebApplication {    
   
	@Override
	protected void init() {
		
		//Configure for Spring injection
        getComponentInstantiationListeners().add(new SpringComponentInjector(this));

		//Don't throw an exception if we are missing a property, just fallback
		getResourceSettings().setThrowExceptionOnMissingResource(false);
		
		//Remove the wicket specific tags from the generated markup
		getMarkupSettings().setStripWicketTags(true);
		
		//Don't add any extra tags around a disabled link (default is <em></em>)
		getMarkupSettings().setDefaultBeforeDisabledLink(null);
		getMarkupSettings().setDefaultAfterDisabledLink(null);
				
		// On Wicket session timeout, redirect to main page
		//getApplicationSettings().setPageExpiredErrorPage(FirstPage.class);
		//getApplicationSettings().setAccessDeniedPage(FirstPage.class);

		/* this is mucking up the exception handling in Sakai and thorinw to a portalless page. Fix it.
        getRequestCycleListeners().add(new IRequestCycleListener() {

            //public void onBeginRequest() {
            	// optionally do something at the beginning of the request
            //}

            //public void onEndRequest() {
            	// optionally do something at the end of the request
            //}

            public IRequestHandler onException(RequestCycle cycle, Exception ex) {
	            // optionally do something here when there's an exception
	            // then, return the appropriate IRequestHandler, or "null"
	            // to let another listener handle the exception
                ex.printStackTrace();
                return null;
            }

            @Override
            public void onBeginRequest(RequestCycle arg0) {
            }

            @Override
            public void onDetach(RequestCycle arg0) {
            }

            @Override
            public void onEndRequest(RequestCycle arg0) {
            }

            @Override
            public void onExceptionRequestHandlerResolved(RequestCycle arg0, IRequestHandler arg1, Exception arg2) {
            }

            @Override
            public void onRequestHandlerExecuted(RequestCycle arg0, IRequestHandler arg1) {
            }

            @Override
            public void onRequestHandlerResolved(RequestCycle arg0, IRequestHandler arg1) {
            }

            @Override
            public void onRequestHandlerScheduled(RequestCycle arg0, IRequestHandler arg1) {
            }

            @Override
            public void onUrlMapped(RequestCycle arg0,IRequestHandler arg1, Url arg2) {
            }
        });
        */
        

   
		//to put this app into deployment mode, see web.xml
	}
	

	
	/**
	 * The main page for our app
	 * 
	 * @see org.apache.wicket.Application#getHomePage()
	 */
	public Class<GradebookPage> getHomePage() {
		return GradebookPage.class;
	}
	
	
	/**
     * Constructor
     */
	public GradebookNgApplication() {
	}
	
	

}

@@ -112,23 +112,24 @@
 .wicket.
-request
+settings
 .IReques
@@ -129,23 +129,29 @@
 IRequest
-Handler
+CycleSettings
 ;%0Aimport
@@ -173,207 +173,245 @@
 ket.
-request.Url;%0Aimport org.apache.wicket.request.cycle.IRequestCycleListener;%0Aimport org.apache.wicket.request.cycle.RequestCycle;%0Aimport org.apache.wicket.spring.injection.annot.SpringComponentInjector
+spring.injection.annot.SpringComponentInjector;%0Aimport org.sakaiproject.gradebookng.tool.pages.GradebookPage;%0Aimport org.sakaiproject.gradebookng.tool.pages.ImportExportPage;%0Aimport org.sakaiproject.gradebookng.tool.pages.PermissionsPage
 ;%0Aim
@@ -451,33 +451,32 @@
 .tool.pages.
-Gradebook
+Settings
 Page;%0A%0A/**%0A 
@@ -652,30 +652,489 @@
 e%0A%09p
-rotected void init() %7B
+ublic void init() %7B%0A%09%09super.init();%0A%09%09%0A%09%09//page mounting for bookmarkable URLs%0A%09%09//mountPage(%22/gradebook%22, GradebookPage.class);%0A%09%09//mountPage(%22/settings%22, SettingsPage.class);%0A%09%09//mountPage(%22/importexport%22, ImportExportPage.class);%0A%09%09//mountPage(%22/permissions%22, PermissionsPage.class);%0A%09%09%0A%09%09//remove the version number from the URL so that browser refreshes re-render the page%0A%09%09//getRequestCycleSettings().setRenderStrategy(IRequestCycleSettings.RenderStrategy.ONE_PASS_RENDER); 
 %0A%09%09%0A
@@ -3740,17 +3740,16 @@
 ml%0A%09%7D%0A%09%0A
-%0A
 %09%0A%09/**%0A%09

Put in a stub of the page mapping and a request renderer that does rebuilds each time.