File Source: ParsedRequest.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.ui.rendering.util;
20
21 import javax.servlet.http.HttpServletRequest;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.roller.weblogger.WebloggerException;
25 import org.apache.roller.weblogger.business.WebloggerFactory;
26 import org.apache.roller.weblogger.business.UserManager;
27 import org.apache.roller.weblogger.pojos.User;
28
29
30 /**
31 * An abstract class representing any request made to Roller that has been
32 * parsed in order to extract relevant pieces of information from the url.
33 *
34 * NOTE: It is extremely important to mention that this class and all of its
35 * subclasses are meant to be extremely light weight. Meaning they should
36 * avoid any time consuming operations at all costs, especially operations
37 * which require a trip to the db. Those operations should be used very, very
38 * sparingly and should only be triggered when it's guaranteed that they are
39 * needed.
40 */
41 public abstract class ParsedRequest {
42
/*
P/P * Method: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init
*
* Postconditions:
* init'ed(log)
*/
43 private static Log log = LogFactory.getLog(ParsedRequest.class);
44
45 HttpServletRequest request = null;
46
47 // lightweight attributes
48 private String authenticUser = null;
49
50 // heavyweight attributes
51 private User user = null;
52
53
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()
*
* Postconditions:
* this.authenticUser == null
* this.request == null
* this.user == null
*/
54 ParsedRequest() {}
55
56
57 /**
58 * Parse the given http request and extract any information we can.
59 *
60 * This abstract version of the constructor gathers info likely to be
61 * relevant to all requests to Roller.
62 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)
*
* Preconditions:
* request != null
*
* Postconditions:
* init'ed(this.authenticUser)
* this.request == request
* this.request != null
* this.user == null
*
* Test Vectors:
* javax.servlet.http.HttpServletRequest:getUserPrincipal(...)@69: Addr_Set{null}, Inverse{null}
*/
63 public ParsedRequest(HttpServletRequest request) throws InvalidRequestException {
64
65 // keep a reference to the original request
66 this.request = request;
67
68 // login status
69 java.security.Principal prince = request.getUserPrincipal();
70 if(prince != null) {
71 this.authenticUser = prince.getName();
72 }
73
74 }
75
76
77 public String getAuthenticUser() {
/*
P/P * Method: String getAuthenticUser()
*
* Preconditions:
* init'ed(this.authenticUser)
*
* Postconditions:
* return_value == this.authenticUser
* init'ed(return_value)
*/
78 return this.authenticUser;
79 }
80
81
82 public void setAuthenticUser(String authenticUser) {
/*
P/P * Method: void setAuthenticUser(String)
*
* Postconditions:
* this.authenticUser == authenticUser
* init'ed(this.authenticUser)
*/
83 this.authenticUser = authenticUser;
84 }
85
86
87 public User getUser() {
88
/*
P/P * Method: User getUser()
*
* Preconditions:
* init'ed(this.user)
* (soft) log != null
* (soft) init'ed(this.authenticUser)
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@91 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@91 != null
*
* Postconditions:
* init'ed(return_value)
* this.user == return_value
*
* Test Vectors:
* this.user: Inverse{null}, Addr_Set{null}
* this.authenticUser: Addr_Set{null}, Inverse{null}
*/
89 if(user == null && authenticUser != null) {
90 try {
91 UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
92 user = umgr.getUserByUserName(authenticUser);
93 } catch (WebloggerException ex) {
94 log.error("Error looking up user "+authenticUser, ex);
95 }
96 }
97
98 return user;
99 }
100
101
102 public void setUser(User u) {
/*
P/P * Method: void setUser(User)
*
* Postconditions:
* this.user == u
* init'ed(this.user)
*/
103 this.user = u;
104 }
105
106
107 public boolean isLoggedIn() {
/*
P/P * Method: bool isLoggedIn()
*
* Preconditions:
* init'ed(this.authenticUser)
*
* Postconditions:
* init'ed(return_value)
*/
108 return (this.authenticUser != null);
109 }
110
111 }
SofCheck Inspector Build Version : 2.18479
| ParsedRequest.java |
2009-Jan-02 14:25:24 |
| ParsedRequest.class |
2009-Sep-04 03:12:44 |