1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */17packageorg.apache.jetspeed.layout.impl;
1819import java.util.Map;
2021import org.apache.commons.logging.Log;
22import org.apache.commons.logging.LogFactory;
23import org.apache.jetspeed.JetspeedActions;
24import org.apache.jetspeed.ajax.AjaxAction;
25import org.apache.jetspeed.ajax.AjaxBuilder;
26import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
27import org.apache.jetspeed.om.page.Link;
28import org.apache.jetspeed.page.PageManager;
29import org.apache.jetspeed.request.RequestContext;
3031/***32 * Retrieve a single link33 *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 */40publicclassGetLinkAction41extendsBaseGetResourceAction42 implements AjaxAction, AjaxBuilder, Constants43 {
44protected Log log = LogFactory.getLog(GetLinkAction.class);
4546publicGetLinkAction(String template,
47 String errorTemplate,
48 PageManager pageManager,
49 PortletActionSecurityBehavior securityBehavior)
50 {
51super(template, errorTemplate, pageManager, securityBehavior);
52 }
5354publicboolean run(RequestContext requestContext, Map resultMap)
55 {
56boolean success = true;
57 String status = "success";
58try59 {
60 resultMap.put(ACTION, "getlink");
61if (false == checkAccess(requestContext, JetspeedActions.VIEW))
62 {
63 success = false;
64 resultMap.put(REASON, "Insufficient access to get link");
65return success;
66 }
67 Link link = retrieveLink(requestContext);
68 resultMap.put(STATUS, status);
69 resultMap.put(LINK, link);
70// resultMap.put(METADATA, link.getMetadata().getFields());71 putSecurityInformation(resultMap, link);
72 }
73catch (Exception e)
74 {
75// Log the exception76 log.error("exception while getting link info", e);
77 resultMap.put(REASON, e.getMessage());
78// Return a failure indicator79 success = false;
80 }
8182return success;
83 }
8485protected Link retrieveLink(RequestContext requestContext)
86 throws Exception
87 {
88 String linkName = getActionParameter(requestContext, LINK);
89if (linkName == null)
90 {
91 linkName = "/";
92 }
93 Link link = pageManager.getLink(linkName);
94return link;
95 }
96 }