001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.layout.impl;
018:
019: import java.util.Map;
020:
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023: import org.apache.jetspeed.JetspeedActions;
024: import org.apache.jetspeed.ajax.AjaxAction;
025: import org.apache.jetspeed.ajax.AjaxBuilder;
026: import org.apache.jetspeed.decoration.DecorationFactory;
027: import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
028: import org.apache.jetspeed.request.RequestContext;
029:
030: /**
031: * Get Portal-wide themes lists
032: * (page decorators, portlet decorators, layouts, desktop-page-decorators, desktop-portlet-decorators)
033: *
034: * AJAX Parameters:
035: * none
036: *
037: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
038: * @version $Id: $
039: */
040: public class GetThemesAction extends BasePortletAction implements
041: AjaxAction, AjaxBuilder, Constants {
042: protected static final Log log = LogFactory
043: .getLog(GetThemesAction.class);
044: protected DecorationFactory decorationFactory;
045:
046: public GetThemesAction(String template, String errorTemplate,
047: DecorationFactory decorationFactory,
048: PortletActionSecurityBehavior securityBehavior) {
049: super (template, errorTemplate, securityBehavior);
050: this .decorationFactory = decorationFactory;
051: }
052:
053: public boolean run(RequestContext requestContext, Map resultMap) {
054: boolean success = true;
055: String status = "success";
056: try {
057: resultMap.put(ACTION, "getthemes");
058: if (false == checkAccess(requestContext,
059: JetspeedActions.VIEW)) {
060: success = false;
061: resultMap.put(REASON,
062: "Insufficient access to get themes");
063: return success;
064: }
065: String type = getActionParameter(requestContext, TYPE);
066: String format = getActionParameter(requestContext, FORMAT);
067: if (format == null)
068: format = "xml";
069: if (type == null || type.equals(PAGE_DECORATIONS))
070: resultMap.put(PAGE_DECORATIONS, decorationFactory
071: .getPageDecorations(requestContext));
072: if (type == null || type.equals(PORTLET_DECORATIONS))
073: resultMap.put(PORTLET_DECORATIONS, decorationFactory
074: .getPortletDecorations(requestContext));
075: if (type == null || type.equals(LAYOUTS))
076: resultMap.put(LAYOUTS, decorationFactory
077: .getLayouts(requestContext));
078: if (type == null || type.equals(DESKTOP_PAGE_DECORATIONS))
079: resultMap
080: .put(
081: DESKTOP_PAGE_DECORATIONS,
082: decorationFactory
083: .getDesktopPageDecorations(requestContext));
084: if (type == null
085: || type.equals(DESKTOP_PORTLET_DECORATIONS))
086: resultMap
087: .put(
088: DESKTOP_PORTLET_DECORATIONS,
089: decorationFactory
090: .getDesktopPortletDecorations(requestContext));
091: resultMap.put(TYPE, type);
092: resultMap.put(FORMAT, format);
093: resultMap.put(STATUS, status);
094: } catch (Exception e) {
095: // Log the exception
096: log.error("exception while getting theme info", e);
097: // Return a failure indicator
098: success = false;
099: }
100:
101: return success;
102: }
103:
104: }
|