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.ArrayList;
020: import java.util.Collections;
021: import java.util.Comparator;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.apache.jetspeed.JetspeedActions;
029: import org.apache.jetspeed.ajax.AjaxAction;
030: import org.apache.jetspeed.ajax.AjaxBuilder;
031: import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
032: import org.apache.jetspeed.om.folder.Folder;
033: import org.apache.jetspeed.om.page.Page;
034: import org.apache.jetspeed.page.PageManager;
035: import org.apache.jetspeed.request.RequestContext;
036:
037: /**
038: * Get Pages retrieves all pages for the given folder
039: *
040: * AJAX Parameters:
041: * folder = the path of folder containing the pages
042: *
043: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
044: * @version $Id: $
045: */
046: public class GetPagesAction extends BasePortletAction implements
047: AjaxAction, AjaxBuilder, Constants, Comparator {
048: protected static final Log log = LogFactory
049: .getLog(GetPortletsAction.class);
050:
051: public GetPagesAction(String template, String errorTemplate,
052: PageManager pageManager,
053: PortletActionSecurityBehavior securityBehavior) {
054: super (template, errorTemplate, pageManager, securityBehavior);
055: }
056:
057: public boolean run(RequestContext requestContext, Map resultMap) {
058: boolean success = true;
059: String status = "success";
060: try {
061: resultMap.put(ACTION, "getpages");
062: if (false == checkAccess(requestContext,
063: JetspeedActions.VIEW)) {
064: // if (!createNewPageOnEdit(requestContext))
065: // {
066: success = false;
067: resultMap.put(REASON,
068: "Insufficient access to get portlets");
069: return success;
070: // }
071: // status = "refresh";
072: }
073: List pages = retrievePages(requestContext);
074: resultMap.put(STATUS, status);
075: resultMap.put(PAGES, pages);
076: } catch (Exception e) {
077: // Log the exception
078: log.error("exception while getting portlet info", e);
079:
080: // Return a failure indicator
081: success = false;
082: }
083:
084: return success;
085: }
086:
087: protected List retrievePages(RequestContext requestContext) {
088: List list = new ArrayList();
089:
090: String folderName = getActionParameter(requestContext, FOLDER);
091: if (folderName == null) {
092: return list;
093: }
094: try {
095: Folder folder = pageManager.getFolder(folderName);
096: Iterator it = folder.getPages().iterator();
097: while (it.hasNext()) {
098: Page page = (Page) it.next();
099: list.add(page);
100: }
101: Collections.sort(list, this );
102: } catch (Exception e) {
103: }
104: return list;
105: }
106:
107: public int compare(Object obj1, Object obj2) {
108: Page page1 = (Page) obj1;
109: Page page2 = (Page) obj2;
110: String name1 = page1.getName();
111: String name2 = page2.getName();
112: name1 = (name1 == null) ? "unknown" : name1;
113: name2 = (name2 == null) ? "unknown" : name2;
114: return name1.compareTo(name2);
115: }
116: }
|