1 package org.astrogrid.portal.myspace.acting;
2
3 import java.util.Map;
4
5 import org.apache.avalon.framework.logger.Logger;
6 import org.apache.avalon.framework.parameters.Parameters;
7 import org.apache.cocoon.acting.AbstractAction;
8 import org.apache.cocoon.environment.ObjectModelHelper;
9 import org.apache.cocoon.environment.Redirector;
10 import org.apache.cocoon.environment.Request;
11 import org.apache.cocoon.environment.Session;
12 import org.apache.cocoon.environment.SourceResolver;
13
14 import org.astrogrid.portal.utils.acting.ActionUtils;
15 import org.astrogrid.portal.utils.acting.ActionUtilsFactory;
16 import org.astrogrid.portal.myspace.acting.framework.*;
17
18 /***
19 * Find and execute the correct handler for the desired MySpace action.
20 *
21 * @author peter.shillan
22 */
23 public class MySpaceControlAction extends AbstractAction {
24
25 private static final String PARAM_ACTION = "myspace-action";
26
27 /***
28 * Find and execute the correct handler for the desired MySpace action.
29 *
30 * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
31 */
32 public Map act(
33 Redirector redirector,
34 SourceResolver resolver,
35 Map objectModel,
36 String source,
37 Parameters params) {
38 Logger logger = getLogger();
39
40
41 Map sitemapParams = null;
42
43
44 ActionUtils utils = ActionUtilsFactory.getActionUtils();
45
46
47 Request request = ObjectModelHelper.getRequest(objectModel);
48 Session session = request.getSession(true);
49
50
51 ContextWrapper context = null;
52 String contextProtocol = utils.getAnyParameter(
53 ContextWrapper.PARAM_PROTOCOL, params, request, session);
54
55 try {
56 context = ContextWrapperFactory.getContextWrapper(
57 contextProtocol, utils, params, request, session);
58 sitemapParams = findAndExecute(context);
59 }
60 catch(Throwable t) {
61
62 logger.error("error processing MySpace action", t);
63 }
64
65 return sitemapParams;
66 }
67
68 /***
69 * Get the correct MySpace handler and execute it.
70 *
71 * @param context environment context
72 * @return sitemap results
73 */
74 private Map findAndExecute(ContextWrapper context) {
75 Logger logger = getLogger();
76
77 Map results = null;
78
79
80 String action = context.getParameter(MySpaceControlAction.PARAM_ACTION);
81
82
83 MySpaceHandler handler = null;
84 if(action != null && action.length() > 0) {
85 handler = MySpaceHandlerFactory.getMySpaceHandler(action, context);
86 }
87
88
89 if(handler != null) {
90 results = handler.execute();
91 }
92 else {
93 logger.error("no handler found for MySpace action [" + action + "]");
94 }
95
96 return results;
97 }
98 }