001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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 GmbH & Co. KG, please see the 018 * company website: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.workplace; 029 030import org.opencms.i18n.CmsEncoder; 031import org.opencms.jsp.CmsJspActionElement; 032import org.opencms.main.CmsLog; 033import org.opencms.main.OpenCms; 034 035import org.apache.commons.logging.Log; 036 037/** 038 * Selects the dialog which should be displayed by OpenCms depending on the configuration value.<p> 039 * 040 * You can define the class of your dialog handler in the OpenCms XML configuration files. 041 * The following files use this class: 042 * <ul> 043 * <li>/commons/property_html 044 * <li>/commons/delete_html 045 * <li>/commons/lock_html 046 * <li>/commons/lockchange_html 047 * <li>/commons/unlock_html 048 * </ul> 049 * <p> 050 * 051 * @since 6.0.0 052 * 053 * @see org.opencms.workplace.I_CmsDialogHandler 054 */ 055public class CmsDialogSelector { 056 057 // Constants for the dialog handler key names used for the runtime properties. 058 // For each handler, a constant has to be added here. 059 /** Constant for the delete dialog handler key name. */ 060 public static final String DIALOG_DELETE = "class_dialog_delete"; 061 /** Constant for the lock dialog handler key name. */ 062 public static final String DIALOG_LOCK = "class_dialog_lock"; 063 /** Constant for the property dialog handler key name. */ 064 public static final String DIALOG_PROPERTY = "class_dialog_property"; 065 066 /** The log object for this class. */ 067 private static final Log LOG = CmsLog.getLog(CmsDialogSelector.class); 068 069 /** The dialog handler. */ 070 private String m_handler; 071 072 /** The JSP context. */ 073 private CmsJspActionElement m_jsp; 074 075 /** The resource parameter. */ 076 private String m_paramResource; 077 078 /** 079 * Public constructor with JSP action element.<p> 080 * 081 * @param jsp an initialized JSP action element 082 * @param handler the key name of the dialog handler (use the constants in your classes!) 083 */ 084 public CmsDialogSelector(CmsJspActionElement jsp, String handler) { 085 086 setJsp(jsp); 087 setHandler(handler); 088 setParamResource(CmsEncoder.decode(jsp.getRequest().getParameter(CmsDialog.PARAM_RESOURCE))); 089 } 090 091 /** 092 * Returns the uri of the dialog which will be displayed.<p> 093 * 094 * @return the uri of the property dialog 095 */ 096 public String getSelectedDialogUri() { 097 098 if (LOG.isDebugEnabled()) { 099 LOG.debug( 100 Messages.get().getBundle().key( 101 Messages.LOG_DIALOG_HANDLER_CLASS_2, 102 getClass().getName(), 103 getHandler())); 104 LOG.debug( 105 Messages.get().getBundle().key( 106 Messages.LOG_PARAM_RESOURCE_2, 107 getClass().getName(), 108 getParamResource())); 109 } 110 // get the handler class from the OpenCms runtime property 111 I_CmsDialogHandler dialogClass = OpenCms.getWorkplaceManager().getDialogHandler(getHandler()); 112 if (dialogClass == null) { 113 // error getting the dialog class, return to file list 114 return CmsWorkplace.FILE_EXPLORER_FILELIST; 115 } 116 // get the dialog URI from the class defined in the configuration 117 return dialogClass.getDialogUri(getParamResource(), getJsp()); 118 } 119 120 /** 121 * Returns the key name of the dialog handler.<p> 122 * 123 * @return the key name of the dialog handler 124 */ 125 private String getHandler() { 126 127 return m_handler; 128 } 129 130 /** 131 * Returns the CmsJspActionElement.<p> 132 * 133 * @return the CmsJspActionElement 134 */ 135 private CmsJspActionElement getJsp() { 136 137 return m_jsp; 138 } 139 140 /** 141 * Returns the resource parameter String.<p> 142 * 143 * @return the resource parameter String 144 */ 145 private String getParamResource() { 146 147 return m_paramResource; 148 } 149 150 /** 151 * Sets the key name of the dialog handler.<p> 152 * 153 * @param handler the key name of the dialog handler 154 */ 155 private void setHandler(String handler) { 156 157 m_handler = handler; 158 } 159 160 /** 161 * Sets the CmsJspActionElement.<p> 162 * 163 * @param jsp the CmsJspActionElement 164 */ 165 private void setJsp(CmsJspActionElement jsp) { 166 167 m_jsp = jsp; 168 } 169 170 /** 171 * Sets the resource parameter String.<p> 172 * 173 * @param resource the resource parameter String 174 */ 175 private void setParamResource(String resource) { 176 177 m_paramResource = resource; 178 } 179 180}