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.widgets.CmsInputWidget; 031import org.opencms.widgets.I_CmsWidget; 032 033import java.lang.reflect.Constructor; 034 035/** 036 * Represents an user additional information entry.<p> 037 * 038 * @since 6.5.6 039 */ 040public final class CmsWorkplaceUserInfoEntry { 041 042 /** The entry's key. */ 043 private final String m_key; 044 045 /** If entry is optional. */ 046 private final String m_optional; 047 048 /** The widget. */ 049 private final String m_widget; 050 051 /** The class name of the stored data type. */ 052 private String m_type; 053 054 /** The widget parameters. */ 055 private String m_params; 056 057 /** 058 * Default constructor.<p> 059 * 060 * @param key the key for this entry 061 * @param type the class name of the stored data type 062 * @param widget the widget to use 063 * @param params the widget parameters 064 * @param optional if this entry is optional 065 */ 066 public CmsWorkplaceUserInfoEntry(String key, String type, String widget, String params, String optional) { 067 068 m_key = key; 069 m_type = type; 070 m_widget = widget; 071 m_params = params; 072 m_optional = optional; 073 } 074 075 /** 076 * Returns the class type.<p> 077 * 078 * @return the class type 079 */ 080 public Class<?> getClassType() { 081 082 if (m_type == null) { 083 return String.class; 084 } 085 try { 086 return Class.forName(m_type); 087 } catch (ClassNotFoundException e) { 088 return String.class; 089 } 090 } 091 092 /** 093 * Returns the key.<p> 094 * 095 * @return the key 096 */ 097 public String getKey() { 098 099 return m_key; 100 } 101 102 /** 103 * Returns the optional flag.<p> 104 * 105 * @return the optional flag 106 */ 107 public String getOptional() { 108 109 return m_optional; 110 } 111 112 /** 113 * Returns the configured widget parameters.<p> 114 * 115 * @return the configured widget parameters 116 */ 117 public String getParams() { 118 119 return m_params; 120 } 121 122 /** 123 * Returns the configured class name type.<p> 124 * 125 * @return the configured class name type 126 */ 127 public String getType() { 128 129 return m_type; 130 } 131 132 /** 133 * Returns the widget class name.<p> 134 * 135 * @return the widget class name 136 */ 137 public String getWidget() { 138 139 return m_widget; 140 } 141 142 /** 143 * Returns a new widget object.<p> 144 * 145 * @return a new widget object 146 */ 147 public I_CmsWidget getWidgetObject() { 148 149 if (getWidget() == null) { 150 if (m_params == null) { 151 return new CmsInputWidget(); 152 } else { 153 return new CmsInputWidget(m_params); 154 } 155 } 156 try { 157 if (m_params == null) { 158 return (I_CmsWidget)Class.forName(getWidget()).newInstance(); 159 } 160 Class<?> clazz = Class.forName(getWidget()); 161 Constructor<?> ctor = clazz.getConstructor(new Class[] {String.class}); 162 return (I_CmsWidget)ctor.newInstance(new Object[] {m_params}); 163 } catch (Exception e) { 164 return new CmsInputWidget(); 165 } 166 } 167 168 /** 169 * Returns the optional flag.<p> 170 * 171 * @return the optional flag 172 */ 173 public boolean isOptional() { 174 175 return Boolean.valueOf(m_optional).booleanValue(); 176 } 177}