1 13 14 15 package com.espada.bugtracker.servlets; 16 17 18 import org.webmacro.*; 20 import org.webmacro.broker.*; 21 import org.webmacro.resource.*; 22 import org.webmacro.servlet.WebContext; 23 24 import javax.servlet.http.*; 26 import javax.servlet.*; 27 28 import com.espada.bugtracker.app.*; 30 31 32 public class Home extends BTServlet 33 { 34 35 39 40 41 42 43 private static final String defaultTemplate = "index.wm"; 44 private String templateToUse = defaultTemplate; 45 46 47 48 49 50 51 52 private void returnHome(HttpServletRequest request, HttpServletResponse response, WebContext c) 53 { 54 55 HttpSession session = request.getSession(); 56 57 String passwd = new String (); 58 String name = new String (); 59 60 61 if(session.getAttribute("USER") != null) 62 { 63 name = ( (String ) session.getAttribute("USER") ); 64 passwd = ( (String ) session.getAttribute("PW") ); 65 66 } 67 68 User me = new User(name); 69 70 boolean loggedIn = false; 71 72 if((me.found)&&(me.checkPassword(passwd))) 73 { 74 templateToUse = "index.wm"; 75 session.setAttribute("UID",new Integer (me.uid)); 76 session.setAttribute("USER",new String (me.username)); 77 session.setAttribute("PW",new String (me.password)); 78 session.setAttribute("UROLE",new Boolean (me.admin)); 79 loggedIn=true; 80 } 81 else 82 { 83 templateToUse = "errorMesg.wm"; 84 c.put("errorId","7"); 85 } 86 87 88 session.setAttribute("loggedIn",String.valueOf(loggedIn)); 89 c.put("loggedIn",String.valueOf(loggedIn)); 90 c.put("me",me); 91 c.put("proId","0"); 92 c.put("USER",session.getAttribute("USER")); 93 c.put("myRoleId",session.getAttribute("USERROLE") ); 94 95 } 97 98 99 100 101 103 public void doGet(HttpServletRequest req, HttpServletResponse resp) 104 { 105 106 try 107 { 108 try 109 { 110 111 WebContext c = _wm.getWebContext(req,resp); 113 114 String s = "http://" + req.getServerName(); 115 c.put("serverName", s); 116 returnHome(req,resp,c); 117 118 119 Template t = _wm.getTemplate(templateToUse); 121 122 FastWriter fw = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 124 125 t.write(fw, c); 127 fw.close(); 128 129 } 130 catch (org.webmacro.NotFoundException e) 131 { 132 133 FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 134 135 out.write("ERROR! Could not locate template " + templateToUse + ", check that your template path is set properly in WebMacro.properties"); 136 137 out.close(); 138 139 } 140 141 catch (org.webmacro.ContextException e) 142 { 143 144 FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 145 146 out.write("ERROR! Could not locate required data in the Context."); 147 148 out.close(); 149 150 } 151 } 152 153 catch (java.io.IOException e) 154 { 155 156 System.out.println("ERROR: IOException while writing to servlet output stream."); 158 159 } 160 161 } 163 } 165 | Popular Tags |