View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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 
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              // resultMap.put(METADATA, link.getMetadata().getFields());
71              putSecurityInformation(resultMap, link);            
72          } 
73          catch (Exception e)
74          {
75              // Log the exception
76              log.error("exception while getting link info", e);
77              resultMap.put(REASON, e.getMessage());
78              // Return a failure indicator
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  }