01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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 extends BaseGetResourceAction implements
41: AjaxAction, AjaxBuilder, Constants {
42: protected Log log = LogFactory.getLog(GetLinkAction.class);
43:
44: public GetLinkAction(String template, String errorTemplate,
45: PageManager pageManager,
46: PortletActionSecurityBehavior securityBehavior) {
47: super (template, errorTemplate, pageManager, securityBehavior);
48: }
49:
50: public boolean run(RequestContext requestContext, Map resultMap) {
51: boolean success = true;
52: String status = "success";
53: try {
54: resultMap.put(ACTION, "getlink");
55: if (false == checkAccess(requestContext,
56: JetspeedActions.VIEW)) {
57: success = false;
58: resultMap
59: .put(REASON, "Insufficient access to get link");
60: return success;
61: }
62: Link link = retrieveLink(requestContext);
63: resultMap.put(STATUS, status);
64: resultMap.put(LINK, link);
65: // resultMap.put(METADATA, link.getMetadata().getFields());
66: putSecurityInformation(resultMap, link);
67: } catch (Exception e) {
68: // Log the exception
69: log.error("exception while getting link info", e);
70: resultMap.put(REASON, e.getMessage());
71: // Return a failure indicator
72: success = false;
73: }
74:
75: return success;
76: }
77:
78: protected Link retrieveLink(RequestContext requestContext)
79: throws Exception {
80: String linkName = getActionParameter(requestContext, LINK);
81: if (linkName == null) {
82: linkName = "/";
83: }
84: Link link = pageManager.getLink(linkName);
85: return link;
86: }
87: }
|