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 GmbH & Co. KG, 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.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(Messages.get().getBundle().key( 105 Messages.LOG_PARAM_RESOURCE_2, 106 getClass().getName(), 107 getParamResource())); 108 } 109 // get the handler class from the OpenCms runtime property 110 I_CmsDialogHandler dialogClass = OpenCms.getWorkplaceManager().getDialogHandler(getHandler()); 111 if (dialogClass == null) { 112 // error getting the dialog class, return to file list 113 return CmsWorkplace.FILE_EXPLORER_FILELIST; 114 } 115 // get the dialog URI from the class defined in the configuration 116 return dialogClass.getDialogUri(getParamResource(), getJsp()); 117 } 118 119 /** 120 * Returns the key name of the dialog handler.<p> 121 * 122 * @return the key name of the dialog handler 123 */ 124 private String getHandler() { 125 126 return m_handler; 127 } 128 129 /** 130 * Returns the CmsJspActionElement.<p> 131 * 132 * @return the CmsJspActionElement 133 */ 134 private CmsJspActionElement getJsp() { 135 136 return m_jsp; 137 } 138 139 /** 140 * Returns the resource parameter String.<p> 141 * 142 * @return the resource parameter String 143 */ 144 private String getParamResource() { 145 146 return m_paramResource; 147 } 148 149 /** 150 * Sets the key name of the dialog handler.<p> 151 * 152 * @param handler the key name of the dialog handler 153 */ 154 private void setHandler(String handler) { 155 156 m_handler = handler; 157 } 158 159 /** 160 * Sets the CmsJspActionElement.<p> 161 * 162 * @param jsp the CmsJspActionElement 163 */ 164 private void setJsp(CmsJspActionElement jsp) { 165 166 m_jsp = jsp; 167 } 168 169 /** 170 * Sets the resource parameter String.<p> 171 * 172 * @param resource the resource parameter String 173 */ 174 private void setParamResource(String resource) { 175 176 m_paramResource = resource; 177 } 178 179}