001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.actions; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.file.types.CmsResourceTypeXmlContainerPage; 033import org.opencms.file.types.CmsResourceTypeXmlContent; 034import org.opencms.main.OpenCms; 035import org.opencms.ui.A_CmsUI; 036import org.opencms.ui.I_CmsDialogContext; 037import org.opencms.ui.Messages; 038import org.opencms.ui.apps.A_CmsWorkplaceApp; 039import org.opencms.ui.apps.CmsAppWorkplaceUi; 040import org.opencms.ui.apps.CmsEditor; 041import org.opencms.ui.apps.lists.CmsListManager; 042import org.opencms.ui.apps.lists.CmsListManagerConfiguration; 043import org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode; 044import org.opencms.ui.contextmenu.CmsMenuItemVisibilitySingleOnly; 045import org.opencms.ui.contextmenu.CmsStandardVisibilityCheck; 046import org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility; 047import org.opencms.util.CmsStringUtil; 048 049import java.util.List; 050 051/** 052 * The display action. Renders the selected resource.<p> 053 */ 054public class CmsDisplayAction extends A_CmsWorkplaceAction implements I_CmsDefaultAction { 055 056 /** The name of the online version window. */ 057 public static final String ONLINE_WINDOW_NAME = "_blank"; 058 059 /** The action id. */ 060 public static final String ACTION_ID = "display"; 061 062 /** The action visibility. */ 063 public static final I_CmsHasMenuItemVisibility VISIBILITY = new CmsMenuItemVisibilitySingleOnly( 064 CmsStandardVisibilityCheck.EDIT); 065 066 /** 067 * @see org.opencms.ui.actions.I_CmsWorkplaceAction#executeAction(org.opencms.ui.I_CmsDialogContext) 068 */ 069 public void executeAction(I_CmsDialogContext context) { 070 071 if (context.getResources().size() == 1) { 072 CmsResource resource = context.getResources().get(0); 073 if (OpenCms.getResourceManager().getResourceType(resource).getTypeName().equals( 074 CmsListManager.RES_TYPE_LIST_CONFIG)) { 075 CmsAppWorkplaceUi.get().showApp( 076 OpenCms.getWorkplaceAppManager().getAppConfiguration(CmsListManagerConfiguration.APP_ID), 077 A_CmsWorkplaceApp.addParamToState( 078 "", 079 CmsEditor.RESOURCE_ID_PREFIX, 080 resource.getStructureId().toString())); 081 } else { 082 083 boolean isOnline = context.getCms().getRequestContext().getCurrentProject().isOnlineProject(); 084 String link; 085 if (isOnline 086 && !(CmsStringUtil.isEmptyOrWhitespaceOnly(context.getCms().getRequestContext().getSiteRoot()) 087 || OpenCms.getSiteManager().isSharedFolder( 088 context.getCms().getRequestContext().getSiteRoot()))) { 089 // use the online link only in case the current site is not the root site or the shared folder 090 link = OpenCms.getLinkManager().getOnlineLink( 091 context.getCms(), 092 context.getCms().getSitePath(resource)); 093 } else { 094 link = OpenCms.getLinkManager().substituteLink(context.getCms(), resource); 095 } 096 if (isOnline 097 || !(OpenCms.getResourceManager().getResourceType(resource) instanceof CmsResourceTypeXmlContent)) { 098 A_CmsUI.get().openPageOrWarn(link, ONLINE_WINDOW_NAME); 099 } else { 100 A_CmsUI.get().getPage().setLocation(link); 101 } 102 } 103 } 104 } 105 106 /** 107 * @see org.opencms.ui.actions.I_CmsDefaultAction#getDefaultActionRank(org.opencms.ui.I_CmsDialogContext) 108 */ 109 public int getDefaultActionRank(I_CmsDialogContext context) { 110 111 return 10; 112 } 113 114 /** 115 * @see org.opencms.ui.actions.I_CmsWorkplaceAction#getId() 116 */ 117 public String getId() { 118 119 return ACTION_ID; 120 } 121 122 /** 123 * @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.file.CmsObject, java.util.List) 124 */ 125 public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) { 126 127 if ((resources.size() == 1) 128 && resources.get(0).isFile() 129 && !CmsResourceTypeXmlContainerPage.isContainerPage(resources.get(0))) { 130 return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE; 131 } else { 132 return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; 133 } 134 } 135 136 /** 137 * @see org.opencms.ui.actions.A_CmsWorkplaceAction#getTitleKey() 138 */ 139 @Override 140 protected String getTitleKey() { 141 142 return Messages.GUI_ACTION_DISPLAY_0; 143 } 144}