001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.styleguide; 020 021import static org.jboss.seam.ScopeType.CONVERSATION; 022 023import java.util.List; 024 025import org.jboss.seam.annotations.In; 026import org.jboss.seam.annotations.Name; 027import org.jboss.seam.annotations.Scope; 028import org.nuxeo.ecm.platform.actions.Action; 029import org.nuxeo.ecm.platform.actions.ejb.ActionManager; 030 031/** 032 * @since 5.7 033 */ 034@Name("styleGuideActions") 035@Scope(CONVERSATION) 036public class StyleGuideActions { 037 038 public static final String PAGE_ACTION_CAT = "STYLE_GUIDE_PAGE"; 039 040 @In(create = true, required = false) 041 protected transient ActionManager actionManager; 042 043 protected Action currentPage; 044 045 protected List<Action> pages; 046 047 public Action getCurrentPage() { 048 if (currentPage == null) { 049 // initialize 050 getPages(); 051 if (pages != null && !pages.isEmpty()) { 052 currentPage = pages.get(0); 053 } 054 } 055 return currentPage; 056 } 057 058 public void setCurrentPage(Action currentPage) { 059 this.currentPage = currentPage; 060 } 061 062 public String getCurrentPageId() { 063 Action currentPage = getCurrentPage(); 064 if (currentPage != null) { 065 return currentPage.getId(); 066 } 067 return null; 068 } 069 070 public void setCurrentPageId(String currentPageId) { 071 this.currentPage = actionManager.getAction(currentPageId, null, true); 072 } 073 074 public List<Action> getPages() { 075 if (pages == null) { 076 pages = getActions(PAGE_ACTION_CAT); 077 } 078 return pages; 079 } 080 081 public List<Action> getActions(String cat) { 082 return actionManager.getActions(cat, null); 083 } 084 085}