View Javadoc

1   package org.paneris.user.controller;
2   
3   import java.sql.Connection;
4   
5   import org.paneris.jal.model.DBConnectionManager;
6   import org.paneris.user.model.User;
7   import org.webmacro.Template;
8   import org.webmacro.servlet.HandlerException;
9   import org.webmacro.servlet.PanerisPage;
10  import org.webmacro.servlet.WebContext;
11  
12  /**
13   * Used by www.paneris.co.uk to grant edit rights to 
14   * files based upon the paneris.org database.
15   */
16  
17  public class Access extends PanerisPage {
18      
19    private static final long serialVersionUID = 1L;
20      private DBConnectionManager connMgr = DBConnectionManager.getInstance();
21      private Connection conn;
22  
23      /**
24       * Handle a request to use a URL 
25       *
26       * @param context   the WebContext
27       * @return          a Template to be expanded
28       * @exception       org.webmacro.servlet.HandlerException Cannot Connect to DB
29       * @exception       org.webmacro.servlet.HandlerException Cannot find templates
30       */
31      public Template handle(WebContext context) throws HandlerException {
32  
33          String db             = null;
34          String templateName   = null;
35          String requestedURL   = null;
36          User user;
37          // --------------------------------
38          // Read in parameters from the form
39          // --------------------------------
40  
41          db = context.getForm("db");
42          if (db == null) throw new HandlerException("No datasource specified.");
43          else {
44              conn = connMgr.getConnection("Access",db);
45              if (conn == null) throw new HandlerException("Can't get connection: "+db);
46          }
47          try {
48                  user = User.getInstance(context);
49                  if (!user.isLoggedOn()) {
50                       User.setReturnURL(context);
51                       templateName = User.getLoginPage(context," access the old Paneris System.");
52                  } else {
53                    requestedURL = context.getForm("requestedURL");
54                    templateName="user/view/PanerisAccessGranted.wm";
55                  }
56          } catch (Exception e) {
57              throw new HandlerException(e.toString());
58          } finally {
59              connMgr.freeConnection(db, conn);
60          }
61  
62  
63  
64  
65          // ----------------------------------------------------------------
66          // Put all the variables into the context (maybe to go into a form)
67          // ----------------------------------------------------------------
68  
69          context.put("db",db);
70          context.put("wmtemplate",templateName);
71          context.put("requested_url",requestedURL);
72          context.put("user", user);
73  
74          // return the appropriate template
75          try {
76              return (Template) context.getBroker().get("template",templateName);
77          } catch (Exception e) {
78              throw new HandlerException("Could not locate template: " + templateName);
79          }
80      }
81  }
82  
83  
84  
85  
86