1 31 32 package org.opencms.widgets; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.main.OpenCms; 36 import org.opencms.util.CmsStringUtil; 37 import org.opencms.workplace.CmsWorkplace; 38 39 48 public class CmsUserWidget extends A_CmsWidget { 49 50 51 public static final String CONFIGURATION_FLAGS = "flags"; 52 53 54 public static final String CONFIGURATION_GROUP = "group"; 55 56 57 public static final String CONFIGURATION_USERTYPE = "usertype"; 58 59 60 private Integer m_flags; 61 62 63 private String m_groupName; 64 65 66 private Integer m_userType; 67 68 71 public CmsUserWidget() { 72 73 this(""); 75 } 76 77 84 public CmsUserWidget(Integer flags, Integer userType, String groupName) { 85 86 m_flags = flags; 87 m_userType = userType; 88 m_groupName = groupName; 89 } 90 91 96 public CmsUserWidget(String configuration) { 97 98 super(configuration); 99 } 100 101 104 public String getConfiguration() { 105 106 StringBuffer result = new StringBuffer (8); 107 108 if (m_flags != null) { 110 if (result.length() > 0) { 111 result.append("|"); 112 } 113 result.append(CONFIGURATION_FLAGS); 114 result.append("="); 115 result.append(m_flags); 116 } 117 if (m_userType != null) { 119 if (result.length() > 0) { 120 result.append("|"); 121 } 122 result.append(CONFIGURATION_USERTYPE); 123 result.append("="); 124 result.append(m_userType.intValue()); 125 } 126 if (m_groupName != null) { 128 if (result.length() > 0) { 129 result.append("|"); 130 } 131 result.append(CONFIGURATION_GROUP); 132 result.append("="); 133 result.append(m_groupName); 134 } 135 136 return result.toString(); 137 } 138 139 142 public String getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 143 144 StringBuffer result = new StringBuffer (16); 145 result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "components/widgets/userselector.js")); 146 return result.toString(); 147 } 148 149 152 public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 153 154 String id = param.getId(); 155 StringBuffer result = new StringBuffer (128); 156 157 result.append("<td class=\"xmlTd\">"); 158 result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\"><tr><td style=\"width: 100%;\">"); 159 result.append("<input style=\"width: 99%;\" class=\"xmlInput"); 160 if (param.hasError()) { 161 result.append(" xmlInputError"); 162 } 163 result.append("\" value=\""); 164 result.append(param.getStringValue(cms)); 165 result.append("\" name=\""); 166 result.append(id); 167 result.append("\" id=\""); 168 result.append(id); 169 result.append("\"></td>"); 170 result.append(widgetDialog.dialogHorizontalSpacer(10)); 171 result.append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>"); 172 173 StringBuffer buttonJs = new StringBuffer (8); 174 buttonJs.append("javascript:openUserWin('"); 175 buttonJs.append(OpenCms.getSystemInfo().getOpenCmsContext()); 176 buttonJs.append("/system/workplace/commons/user_selection.jsp"); 177 buttonJs.append("','EDITOR', '"); 178 buttonJs.append(id); 179 buttonJs.append("', document, '"); 180 if (m_flags != null) { 181 buttonJs.append(m_flags); 182 } else { 183 buttonJs.append("null"); 184 } 185 buttonJs.append("', '"); 186 if (m_groupName != null) { 187 buttonJs.append(m_groupName); 188 } else { 189 buttonJs.append("null"); 190 } 191 buttonJs.append("', '"); 192 if (m_userType != null) { 193 buttonJs.append(m_userType.intValue()); 194 } else { 195 buttonJs.append("null"); 196 } 197 buttonJs.append("'"); 198 buttonJs.append(");"); 199 200 result.append(widgetDialog.button( 201 buttonJs.toString(), 202 null, 203 "user", 204 org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_SEARCH_0, 205 widgetDialog.getButtonStyle())); 206 result.append("</tr></table>"); 207 result.append("</td></tr></table>"); 208 209 result.append("</td>"); 210 211 return result.toString(); 212 } 213 214 219 public Integer getFlags() { 220 221 return m_flags; 222 } 223 224 229 public String getGroupName() { 230 231 return m_groupName; 232 } 233 234 239 public Integer getUserType() { 240 241 return m_userType; 242 } 243 244 247 public I_CmsWidget newInstance() { 248 249 return new CmsUserWidget(getConfiguration()); 250 } 251 252 255 public void setConfiguration(String configuration) { 256 257 m_groupName = null; 258 m_userType = null; 259 m_flags = null; 260 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration)) { 261 int flagsIndex = configuration.indexOf(CONFIGURATION_FLAGS); 262 if (flagsIndex != -1) { 263 String flags = configuration.substring(CONFIGURATION_FLAGS.length() + 1); 265 if (flags.indexOf('|') != -1) { 266 flags = flags.substring(0, flags.indexOf('|')); 268 } 269 try { 270 m_flags = Integer.valueOf(flags); 271 } catch (Throwable t) { 272 } 274 } 275 int typeIndex = configuration.indexOf(CONFIGURATION_USERTYPE); 276 if (typeIndex != -1) { 277 String type = configuration.substring(CONFIGURATION_USERTYPE.length() + 1); 279 if (type.indexOf('|') != -1) { 280 type = type.substring(0, type.indexOf('|')); 282 } 283 try { 284 m_userType = Integer.valueOf(type); 285 } catch (Throwable t) { 286 } 288 } 289 int groupIndex = configuration.indexOf(CONFIGURATION_GROUP); 290 if (groupIndex != -1) { 291 String group = configuration.substring(CONFIGURATION_GROUP.length() + 1); 293 if (group.indexOf('|') != -1) { 294 group = group.substring(0, group.indexOf('|')); 296 } 297 m_groupName = group; 298 } 299 } 300 super.setConfiguration(configuration); 301 } 302 } | Popular Tags |