/********************************************************************************** 
 * $URL$ 
 * $Id$ 
 *********************************************************************************** 
 * 
 * Copyright (c) 2011 The Sakai Foundation 
 * 
 * Licensed under the Educational Community License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.osedu.org/licenses/ECL-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * 
 **********************************************************************************/ 

package org.sakaiproject.dash.tool;

import org.apache.wicket.Page;
import org.apache.wicket.Request;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.Response;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.WebRequestCycle;
import org.apache.wicket.protocol.http.WebResponse;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;

import org.sakaiproject.dash.tool.pages.DashboardPage;
import org.sakaiproject.dash.tool.pages.DashboardMobilePage;
import org.sakaiproject.dash.tool.pages.OptionsPage;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.cover.SessionManager;

/**
 * Main application class for our app
 * 
 * @author Steve Swinsburg (steve.swinsburg@anu.edu.au)
 *
 */
public class MyApplication extends WebApplication {    
   
	/**
	 * Configure your app here
	 */
	@Override
	protected void init() {
		
		//Configure for Spring injection
		addComponentInstantiationListener(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(DashboardPage.class);
		getApplicationSettings().setAccessDeniedPage(OptionsPage.class);
		
		//to put this app into deployment mode, see web.xml
		
	}
	
	/**
	 *  Throw RuntimeExceptions so they are caught by the Sakai ErrorReportHandler(non-Javadoc)
	 *  
	 * @see org.apache.wicket.protocol.http.WebApplication#newRequestCycle(org.apache.wicket.Request, org.apache.wicket.Response)
	 */
	@Override
	public RequestCycle newRequestCycle(Request request, Response response) {
		return new WebRequestCycle(this, (WebRequest)request, (WebResponse)response) {
			@Override
			public Page onRuntimeException(Page page, RuntimeException e) {
				throw e;
			}
		};
	}
	
	/**
	 * The main page for our app
	 * 
	 * @see org.apache.wicket.Application#getHomePage()
	 */
	public Class getHomePage() {
		Session session = SessionManager.getCurrentSession();
		Boolean mobileDeviceParam = (Boolean)session.getAttribute("is_mobile_device");
		if (mobileDeviceParam)
		{
			// mobile view
			return DashboardMobilePage.class;
		}
		else
		{
			return DashboardPage.class;
		}
	}
	
	
	/**
     * Constructor
     */
	public MyApplication()
	{
	}
	
	

}

@@ -1280,32 +1280,85 @@
 tp.WebResponse;%0A
+import org.apache.wicket.protocol.http.RequestUtils;%0A
 import org.apach
@@ -1678,16 +1678,93 @@
 nager;%0A%0A
+import javax.servlet.http.HttpServletRequest;%0Aimport java.util.Enumeration;%0A%0A
 /**%0A * M
@@ -3463,169 +3463,248 @@
 () %7B
+%09
 %0A%09%09S
-ession session = SessionManager.getCurrentSession();%0A%09%09Boolean mobileDeviceParam = (Boolean)session.getAttribute(%22is_mobile_device%22);%0A%09%09if (mobileDeviceParam
+tring fullUrl = RequestUtils.toAbsolutePath(RequestCycle.get().getRequest().%0A%09%09%09%09  getRelativePathPrefixToWicketHandler());%0A%09%09// detect the pda url path and determine the dashboard home page accordingly %0A%09%09if (fullUrl.contains(%22/pda/%22)
 )%0A%09%09

DASH-266 detect the pda string inside the request url