1 package uk.ac.cam.spectra.spectrasub.pages;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import org.apache.log4j.Logger;
7 import org.apache.tapestry.IPage;
8 import org.apache.tapestry.annotations.InjectObject;
9 import org.apache.tapestry.annotations.InjectPage;
10 import org.apache.tapestry.web.WebContext;
11
12 import uk.ac.cam.spectra.spectrasub.Constants;
13 import uk.ac.cam.spectra.spectrasub.servlet.SpectraContextLoader;
14
15
16
17
18
19
20
21
22
23
24 public abstract class ConfigureWorkspace extends BaseSPECTRaSubPage {
25
26 private final static Logger LOG = Logger
27 .getLogger(ConfigureWorkspace.class);
28
29 public IPage submit() {
30 LOG.info("Submit called");
31 File workspace = new File(getWorkspaceLocation());
32 try {
33 workspace.mkdirs();
34 getWebContext().setAttribute(Constants.WORKSPACE_ATTRIBUTE,
35 workspace.getCanonicalPath());
36 File profile = new File(workspace, Constants.PROFILE_FILENAME);
37
38 if (profile.exists()) {
39 profile.setLastModified(System.currentTimeMillis());
40 new SpectraContextLoader().checkAndReconfigure(getWebContext());
41 }
42 } catch (IOException e) {
43 throw new RuntimeException(e);
44 }
45 return getHome();
46 }
47
48 @InjectObject("service:tapestry.globals.WebContext")
49 public abstract WebContext getWebContext();
50
51 @InjectPage("Home")
52 public abstract IPage getHome();
53
54 public abstract String getWorkspaceLocation();
55 }