1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.layout.impl;
18
19 import java.util.Map;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.jetspeed.JetspeedActions;
24 import org.apache.jetspeed.ajax.AjaxAction;
25 import org.apache.jetspeed.ajax.AjaxBuilder;
26 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
27 import org.apache.jetspeed.om.page.Link;
28 import org.apache.jetspeed.page.PageManager;
29 import org.apache.jetspeed.request.RequestContext;
30
31 /***
32 * Retrieve a single link
33 *
34 * AJAX Parameters:
35 * link = the path of the link to retrieve information on
36 *
37 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
38 * @version $Id: $
39 */
40 public class GetLinkAction
41 extends BaseGetResourceAction
42 implements AjaxAction, AjaxBuilder, Constants
43 {
44 protected Log log = LogFactory.getLog(GetLinkAction.class);
45
46 public GetLinkAction(String template,
47 String errorTemplate,
48 PageManager pageManager,
49 PortletActionSecurityBehavior securityBehavior)
50 {
51 super(template, errorTemplate, pageManager, securityBehavior);
52 }
53
54 public boolean run(RequestContext requestContext, Map resultMap)
55 {
56 boolean success = true;
57 String status = "success";
58 try
59 {
60 resultMap.put(ACTION, "getlink");
61 if (false == checkAccess(requestContext, JetspeedActions.VIEW))
62 {
63 success = false;
64 resultMap.put(REASON, "Insufficient access to get link");
65 return success;
66 }
67 Link link = retrieveLink(requestContext);
68 resultMap.put(STATUS, status);
69 resultMap.put(LINK, link);
70
71 putSecurityInformation(resultMap, link);
72 }
73 catch (Exception e)
74 {
75
76 log.error("exception while getting link info", e);
77 resultMap.put(REASON, e.getMessage());
78
79 success = false;
80 }
81
82 return success;
83 }
84
85 protected Link retrieveLink(RequestContext requestContext)
86 throws Exception
87 {
88 String linkName = getActionParameter(requestContext, LINK);
89 if (linkName == null)
90 {
91 linkName = "/";
92 }
93 Link link = pageManager.getLink(linkName);
94 return link;
95 }
96 }