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.tapestry.PageRedirectException;
7   import org.apache.tapestry.annotations.InjectPage;
8   import org.apache.tapestry.event.PageBeginRenderListener;
9   import org.apache.tapestry.event.PageEvent;
10  import org.apache.tapestry.web.WebContext;
11  
12  import uk.ac.cam.spectra.spectrasub.Constants;
13  
14  public abstract class Home extends BaseSPECTRaSubPage implements
15  		PageBeginRenderListener {
16  
17  	public void pageBeginRender(PageEvent event) {
18  		LOG.debug("Home rendering - deciding where to redirect...");
19  		WebContext ctx = getWebContext();
20  		// Check that the workspace has been configured.
21  		String wsLoc = (String) ctx.getAttribute(Constants.WORKSPACE_ATTRIBUTE);
22  
23  		if (wsLoc == null) {
24  			LOG.info("No workspace found, configuring");
25  			throw new PageRedirectException(getConfigureWorkspace());
26  		} else {
27  			LOG.debug("Found workspace: " + wsLoc);
28  			File workspace = new File(wsLoc);
29  			if (!workspace.exists()) {
30  				if (!workspace.mkdirs()) {
31  					throw new RuntimeException(
32  							"Could not create workspace directory at: " + wsLoc);
33  				}
34  			}
35  			try {
36  				ctx.setAttribute(Constants.WORKSPACE_ATTRIBUTE, workspace
37  						.getCanonicalPath());
38  			} catch (IOException e) {
39  				throw new RuntimeException(e);
40  			}
41  			File profileF = new File(workspace, Constants.PROFILE_FILENAME);
42  			if (!profileF.exists()) {
43  				LOG.info("No profile found at " + profileF + ", configuring");
44  				throw new PageRedirectException(getConfigureProfile());
45  			}
46  			throw new PageRedirectException(getUpload());
47  		}
48  	}
49  
50  	@InjectPage("Upload")
51  	public abstract Upload getUpload();
52  }