View Javadoc

1   package org.whatsitcalled.webflange;
2   
3   import java.net.MalformedURLException;
4   
5   import javax.servlet.http.HttpServletRequest;
6   
7   import org.apache.log4j.Logger;
8   import org.apache.wicket.Application;
9   import org.apache.wicket.MarkupContainer;
10  import org.apache.wicket.WicketRuntimeException;
11  import org.apache.wicket.behavior.HeaderContributor;
12  import org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadWebRequest;
13  import org.apache.wicket.protocol.http.WebRequest;
14  import org.apache.wicket.security.hive.HiveMind;
15  import org.apache.wicket.security.hive.authentication.LoginContext;
16  import org.apache.wicket.security.hive.config.PolicyFileHiveFactory;
17  import org.apache.wicket.security.swarm.SwarmWebApplication;
18  import org.apache.wicket.util.time.Duration;
19  import org.whatsitcalled.webflange.security.WebflangeLoginContext;
20  import org.whatsitcalled.webflange.webapp.HomePage;
21  import org.whatsitcalled.webflange.webapp.LoginPage;
22  
23  public class WebflangeApplication extends SwarmWebApplication {
24  	//TODO Add a roadmap page to the main webflange site
25  	//TODO Provide mechanism to clear run data
26  	//TODO Contact Philip on jython-standalone
27  	//TODO include adding a file through maven plugin
28  	//TODO Add response time plot chart for individual tests
29  	//TODO Maybe: Create wizard for proxy creation of scripts
30  	//TODO Allow only one instance of any test to run at a time
31  	//TODO Create ANT task
32  	
33  	private static Logger LOGGER = Logger.getLogger(WebflangeApplication.class);
34  	@Override
35  	public Class getHomePage() {
36  		return HomePage.class;
37  	}
38  	
39  	@Override
40  	protected void init() {
41  		super.init();
42  		getApplicationSettings().setPageExpiredErrorPage(HomePage.class);
43  		getApplicationSettings().setInternalErrorPage(HomePage.class);
44  		getResourceSettings().setResourcePollFrequency(Duration.milliseconds(500));
45  		//Initialize with default data
46  		ResourceFactory.getTestService().init();
47  	}
48  
49  	@Override
50  	protected WebRequest newWebRequest(HttpServletRequest servletRequest) {
51          return new UploadWebRequest(servletRequest);
52  	}
53  	/**
54  	 * @see org.apache.wicket.security.WaspApplication#getLoginPage()
55  	 */
56  	public Class getLoginPage()
57  	{
58  		return LoginPage.class;
59  	}
60  
61  	/**
62  	 * 
63  	 * @see org.apache.wicket.security.examples.MultiUsableApplication#getLogoffContext()
64  	 */
65  	public LoginContext getLogoffContext()
66  	{
67  		return new WebflangeLoginContext();
68  	}
69  	/**
70  	 * @see org.apache.wicket.security.swarm.SwarmWebApplication#getHiveKey()
71  	 */
72  	protected Object getHiveKey()
73  	{
74  		// if you are using servlet api 2.5 i would suggest using:
75  		// return getServletContext().getContextPath();
76  
77  		// if not you have several options:
78  		// -an initparam in web.xml
79  		// -a static object
80  		// -a random object
81  		// -whatever you can think of
82  
83  		// for this example we will be using a fixed string
84  		return "webflange";
85  
86  	}
87  
88  	/**
89  	 * @see org.apache.wicket.security.swarm.SwarmWebApplication#setUpHive()
90  	 */
91  	protected void setUpHive()
92  	{
93  		// create factory
94  		PolicyFileHiveFactory factory = new PolicyFileHiveFactory();
95  		try
96  		{
97  			// this example uses 1 policy file but you can add as many as you
98  			// like
99  			LOGGER.debug("Setting up Hive...");
100 			factory.addPolicyFile(getServletContext().getResource("/WEB-INF/webflange.hive"));
101 		}
102 		catch (MalformedURLException e)
103 		{
104 			throw new WicketRuntimeException(e);
105 		}
106 		// register factory
107 		HiveMind.registerHive(getHiveKey(), factory);
108 
109 	}
110 	
111 	public void addHeaders(MarkupContainer container) {
112 		//For extjs
113 		container.add(HeaderContributor.forCss("extjs/resources/css/ext-all.css"));
114 		container.add(HeaderContributor.forJavaScript("extjs/ext-base.js"));
115 		container.add(HeaderContributor.forJavaScript("extjs/ext-resize.js"));
116 		
117 		//My css overides
118 		container.add(HeaderContributor.forCss("style.css"));	
119 		
120 	}
121 	
122 	
123 
124 }