File Source: UIActionInterceptor.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.struts2.util;
20
21 import com.opensymphony.xwork2.ActionContext;
22 import com.opensymphony.xwork2.ActionInvocation;
23 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
24 import javax.servlet.http.HttpServletRequest;
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.roller.weblogger.business.WebloggerFactory;
29 import org.apache.roller.weblogger.business.UserManager;
30 import org.apache.roller.weblogger.pojos.Weblog;
31 import org.apache.roller.weblogger.ui.core.RollerSession;
32 import org.apache.struts2.StrutsStatics;
33
34
35 /**
36 * A struts2 interceptor for configuring specifics of the weblogger ui.
37 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.struts2.util.UIActionInterceptor()
*/
38 public class UIActionInterceptor extends AbstractInterceptor
39 implements StrutsStatics {
40
/*
P/P * Method: org.apache.roller.weblogger.ui.struts2.util.UIActionInterceptor__static_init
*
* Postconditions:
* init'ed(log)
*/
41 private static Log log = LogFactory.getLog(UIActionInterceptor.class);
42
43
44 public String intercept(ActionInvocation invocation) throws Exception {
45
/*
P/P * Method: String intercept(ActionInvocation)
*
* Preconditions:
* invocation != null
* log != null
*
* Presumptions:
* com.opensymphony.xwork2.ActionInvocation:getInvocationContext(...)@49 != null
* org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@71 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@71 != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* org.apache.commons.lang.StringUtils:isEmpty(...)@68: {1}, {0}
* org.apache.roller.weblogger.business.UserManager:getWebsiteByHandle(...)@72: Addr_Set{null}, Inverse{null}
* org.apache.roller.weblogger.ui.core.RollerSession:getRollerSession(...)@61: Addr_Set{null}, Inverse{null}
*/
46 log.debug("Entering UIActionInterceptor");
47
48 final Object action = invocation.getAction();
49 final ActionContext context = invocation.getInvocationContext();
50
51 HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
52
53 // is this one of our own UIAction classes?
54 if (action instanceof UIAction) {
55
56 log.debug("action is a UIAction, setting relevant attributes");
57
58 UIAction theAction = (UIAction) action;
59
60 // extract the authenticated user and set it
61 RollerSession rses = RollerSession.getRollerSession(request);
62 if(rses != null) {
63 theAction.setAuthenticatedUser(rses.getAuthenticatedUser());
64 }
65
66 // extract the work weblog and set it
67 String weblogHandle = theAction.getWeblog();
68 if(!StringUtils.isEmpty(weblogHandle)) {
69 Weblog weblog = null;
70 try {
71 UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
72 weblog = mgr.getWebsiteByHandle(weblogHandle);
73 if(weblog != null) {
74 theAction.setActionWeblog(weblog);
75 }
76 } catch(Exception e) {
77 log.error("Error looking up action weblog - "+weblogHandle, e);
78 }
79 }
80 }
81
82 return invocation.invoke();
83 }
84
85 }
SofCheck Inspector Build Version : 2.18479
| UIActionInterceptor.java |
2009-Jan-02 14:25:22 |
| UIActionInterceptor.class |
2009-Sep-04 03:12:45 |