1 53 54 106 107 package com.Yasna.forum.tags; 108 109 import java.util.*; 110 import javax.servlet.*; 111 import javax.servlet.jsp.*; 112 import javax.servlet.jsp.tagext.*; 113 import javax.servlet.http.*; 114 import com.Yasna.forum.*; 115 import com.Yasna.forum.tags.*; 116 117 162 163 public class AuthorizeTag extends TagSupport 164 { 165 private YazdState js = null; 166 private YazdRequest jr = null; 167 private Authorization auth = null; 168 boolean anonymous = false; 170 private boolean not_authorized = false; 172 173 181 182 public final int doStartTag() throws JspException 183 { 184 String tmp; 185 186 js = (YazdState)pageContext.getAttribute("yazdUserState", 188 PageContext.SESSION_SCOPE); 189 if( js == null ) { 190 js = new YazdState(); 191 pageContext.setAttribute("yazdUserState",js,PageContext.SESSION_SCOPE); 192 } 193 194 jr = (YazdRequest)pageContext.getAttribute("yazdUserRequest", 196 PageContext.REQUEST_SCOPE); 197 if( jr == null ) { 198 jr = new YazdRequest(); 199 pageContext.setAttribute("yazdUserRequest",jr,PageContext.REQUEST_SCOPE); 200 } 201 pageContext.setAttribute(id,jr,PageContext.PAGE_SCOPE); 202 jr.setYazdState(js); 203 204 auth = (Authorization)js.getAuthorization(); 205 if( auth == null ) { 206 auth = AuthorizationFactory.getAnonymousAuthorization(); 208 js.setAuthorization(auth); 209 int val; 211 tmp = TagPropertyManager.getTagProperty(YazdState.MESSAGE_DEPTH); 212 if( tmp != null ) { 213 try { 214 val = Integer.valueOf(tmp).intValue(); 215 js.setMessageDepth(val); 216 } catch(NumberFormatException e) { 217 } 218 } 219 tmp = TagPropertyManager.getTagProperty(YazdState.THREAD_DEPTH); 220 if( tmp != null ) { 221 try { 222 val = Integer.valueOf(tmp).intValue(); 223 js.setThreadDepth(val); 224 } catch(NumberFormatException e) { 225 } 226 } 227 tmp = TagPropertyManager.getTagProperty(YazdState.ITEMS_PER_PAGE); 228 if( tmp != null ) { 229 try { 230 val = Integer.valueOf(tmp).intValue(); 231 js.setItemsPerPage(val); 232 } catch(NumberFormatException e) { 233 } 234 } 235 Cookie [] cookies = ((HttpServletRequest)pageContext.getRequest()).getCookies(); 237 if( cookies != null && cookies.length > 0 ) { 238 String name; 239 String value; 240 for( int i = 0; i < cookies.length; i++ ) { 241 name = cookies[i].getName(); 242 value = cookies[i].getValue(); 243 if( name.equals(YazdState.LAST_VISIT) ) { 244 js.setLastVisit(new Date(Long.valueOf(value).longValue())); 245 } else if( name.startsWith(YazdState.LAST_FORUM_VISIT) ) { 246 js.setLastForumVisitDate(name,new Date(Long.valueOf(value).longValue())); 247 } 248 } 249 } 250 } 251 252 js.setNextVisit(pageContext); 254 255 ServletRequest req = pageContext.getRequest(); 257 tmp = req.getParameter("forum"); 258 if( tmp != null && tmp.length() > 0 ) 259 js.setForumID(Integer.valueOf(tmp).intValue()); 260 tmp = req.getParameter("thread"); 261 if( tmp != null && tmp.length() > 0 ) 262 js.setThreadID(Integer.valueOf(tmp).intValue()); 263 tmp = req.getParameter("message"); 264 if( tmp != null && tmp.length() > 0 ) 265 js.setMessageID(Integer.valueOf(tmp).intValue()); 266 tmp = req.getParameter("parent"); 267 if( tmp != null && tmp.length() > 0 ) 268 js.setParentID(Integer.valueOf(tmp).intValue()); 269 270 User user; 272 try { 273 user = jr.getProfileManager().getUser(auth.getUserID()); 274 } catch( UserNotFoundException ex ) { 275 throw new JspException("authorize tag could not find user with ID: " + 276 auth.getUserID()); 277 } 278 if( !anonymous && user.isAnonymous() ) { 279 not_authorized = true; 281 jr.addError(TagPropertyManager.getTagProperty("yazd.tag.authorize.failed")); 282 return EVAL_BODY_INCLUDE; 283 } 284 return SKIP_BODY; 286 } 287 288 293 public final int doEndTag() throws JspException 294 { 295 if( not_authorized ) 296 return SKIP_PAGE; 297 return EVAL_PAGE; 298 } 299 300 304 public final void setAnonymous(String a) 305 { 306 if( a.equals("true") )anonymous=true; 307 } 308 } 309 | Popular Tags |