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.decoration.DecorationFactory;
27  import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
28  import org.apache.jetspeed.request.RequestContext;
29  
30  /***
31   * Get Portal-wide themes lists 
32   * (page decorators, portlet decorators, layouts, desktop-page-decorators, desktop-portlet-decorators)
33   *
34   * AJAX Parameters: 
35   *    none 
36   *    
37   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
38   * @version $Id: $
39   */
40  public class GetThemesAction 
41      extends BasePortletAction 
42      implements AjaxAction, AjaxBuilder, Constants
43  {
44      protected static final Log log = LogFactory.getLog(GetThemesAction.class);
45      protected DecorationFactory decorationFactory;
46      
47      public GetThemesAction(String template, 
48                             String errorTemplate,
49                             DecorationFactory decorationFactory,
50                             PortletActionSecurityBehavior securityBehavior)
51      {
52          super(template, errorTemplate, securityBehavior);
53          this.decorationFactory = decorationFactory;
54      }
55  
56      public boolean run( RequestContext requestContext, Map resultMap )
57      {
58          boolean success = true;
59          String status = "success";
60          try
61          {
62              resultMap.put( ACTION, "getthemes" );
63              if (false == checkAccess( requestContext, JetspeedActions.VIEW ) )
64              {
65                      success = false;
66                      resultMap.put( REASON, "Insufficient access to get themes" );
67                      return success;
68              }                     
69              String type = getActionParameter(requestContext, TYPE );
70              String format = getActionParameter(requestContext, FORMAT );
71              if (format == null)
72                  format = "xml";
73              if (type == null || type.equals( PAGE_DECORATIONS ) )
74                  resultMap.put( PAGE_DECORATIONS, decorationFactory.getPageDecorations( requestContext ) );
75              if (type == null || type.equals( PORTLET_DECORATIONS ) )
76                  resultMap.put( PORTLET_DECORATIONS, decorationFactory.getPortletDecorations( requestContext ) );
77              if (type == null || type.equals( LAYOUTS ) )
78                  resultMap.put( LAYOUTS, decorationFactory.getLayouts( requestContext ) );
79              if (type == null || type.equals( DESKTOP_PAGE_DECORATIONS) )
80                  resultMap.put( DESKTOP_PAGE_DECORATIONS, decorationFactory.getDesktopPageDecorations( requestContext ) );
81              if (type == null || type.equals( DESKTOP_PORTLET_DECORATIONS ) )
82                  resultMap.put( DESKTOP_PORTLET_DECORATIONS, decorationFactory.getDesktopPortletDecorations( requestContext ) );
83              resultMap.put( TYPE, type );
84              resultMap.put( FORMAT, format );
85              resultMap.put( STATUS, status );
86          } 
87          catch (Exception e)
88          {
89              // Log the exception
90              log.error( "exception while getting theme info", e );
91              // Return a failure indicator
92              success = false;
93          }
94  
95          return success;
96  	}
97      
98      
99  }