01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.ui.rendering.util;
20:
21: import java.util.Locale;
22: import javax.servlet.http.HttpServletRequest;
23:
24: /**
25: * An abstract class representing any request made to Roller that has been
26: * parsed in order to extract relevant pieces of information from the url.
27: *
28: * NOTE: It is extremely important to mention that this class and all of its
29: * subclasses are meant to be extremely light weight. Meaning they should
30: * avoid any time consuming operations at all costs, especially operations
31: * which require a trip to the db. Those operations should be used very, very
32: * sparingly and should only be triggered when it's guaranteed that they are
33: * needed.
34: */
35: public abstract class ParsedRequest {
36:
37: HttpServletRequest request = null;
38:
39: private String authenticUser = null;
40:
41: ParsedRequest() {
42: }
43:
44: /**
45: * Parse the given http request and extract any information we can.
46: *
47: * This abstract version of the constructor gathers info likely to be
48: * relevant to all requests to Roller.
49: */
50: public ParsedRequest(HttpServletRequest request)
51: throws InvalidRequestException {
52:
53: // keep a reference to the original request
54: this .request = request;
55:
56: // login status
57: java.security.Principal prince = request.getUserPrincipal();
58: if (prince != null) {
59: this .authenticUser = prince.getName();
60: }
61:
62: }
63:
64: public String getAuthenticUser() {
65: return this .authenticUser;
66: }
67:
68: public void setAuthenticUser(String authenticUser) {
69: this .authenticUser = authenticUser;
70: }
71:
72: public boolean isLoggedIn() {
73: return (this.authenticUser != null);
74: }
75:
76: }
|