View Javadoc

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   * The job of this page is to ask the user for a workspace directory, set it up
17   * and save the location into the context properties file and as a context
18   * attribute.
19   * 
20   * @author ojd20
21   * 
22   * @todo add persistent storage of workspace location.
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              // If the workspace already contains a profile, redo the spring config.
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  }