1 13 package info.magnolia.cms.gui.control; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.core.NodeData; 17 18 import java.util.ArrayList ; 19 import java.util.Hashtable ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import javax.jcr.PropertyType; 25 import javax.servlet.http.HttpServletRequest ; 26 27 import org.apache.commons.lang.StringUtils; 28 29 30 34 public class ControlSuper implements ControlInterface { 35 36 public static final int BUTTONTYPE_PUSHBUTTON = 0; 37 38 public static final int BUTTONTYPE_CHECKBOX = 1; 39 40 public static final int BUTTONTYPE_RADIO = 2; 41 42 public static final int BUTTONSTATE_NORMAL = 0; 43 44 public static final int BUTTONSTATE_MOUSEOVER = 1; 45 46 public static final int BUTTONSTATE_MOUSEDOWN = 2; 47 48 public static final int BUTTONSTATE_PUSHED = 3; 49 50 public static final int BUTTONSTATE_DISABLED = 4; 52 public static final int VALUETYPE_SINGLE = 0; 53 54 public static final int VALUETYPE_MULTIPLE = 1; 55 56 public static final int ENCODING_NO = 0; 57 58 public static final int ENCODING_BASE64 = 1; 59 60 public static final int ENCODING_UNIX = 2; 61 62 public static final int RICHEDIT_NONE = 0; 63 64 public static final int RICHEDIT_KUPU = 1; 65 66 public static final int RICHEDIT_FCK = 2; 67 68 public static final String CSSCLASS_CONTROLBUTTON = "mgnlControlButton"; 70 public static final String CSSCLASS_CONTROLBUTTONSMALL = "mgnlControlButtonSmall"; 72 public static final String CSSCLASS_CONTROLBAR = "mgnlControlBar"; 74 public static final String CSSCLASS_CONTROLBARSMALL = "mgnlControlBarSmall"; 76 private int valueType = VALUETYPE_SINGLE; 77 78 private int encoding = ENCODING_NO; 79 80 private int isRichEditValue = RICHEDIT_NONE; 81 82 private String label; 83 84 private String name; 85 86 private String id; 87 88 private String value; 89 90 private List values = new ArrayList (); 92 private Map events = new Hashtable (); 93 94 private Content websiteNode; 95 96 private String htmlPre; 97 98 private String htmlInter; 99 100 private String htmlPost; 101 102 private int type = PropertyType.STRING; 103 104 private boolean saveInfo = true; 105 106 private String cssClass = StringUtils.EMPTY; 107 108 private Map cssStyles = new Hashtable (); 109 110 private String path; 111 112 private String nodeCollectionName; 113 114 private String nodeName; 115 116 private String paragraph; 117 118 private HttpServletRequest request; 119 120 ControlSuper() { 121 } 122 123 ControlSuper(String name, String value) { 124 this.setName(name); 125 this.setValue(value); 126 } 127 128 ControlSuper(String name, List values) { 129 this.setName(name); 130 this.setValues(values); 131 } 132 133 ControlSuper(String name, Content websiteNode) { 134 this.setName(name); 135 this.setWebsiteNode(websiteNode); 136 } 137 138 public void setPath(String path) { 139 this.path = path; 140 } 141 142 public String getPath() { 143 return this.path; 144 } 145 146 public void setNodeCollectionName(String nodeCollectionName) { 147 this.nodeCollectionName = nodeCollectionName; 148 } 149 150 public String getNodeCollectionName() { 151 return this.nodeCollectionName; 152 } 153 154 public String getNodeCollectionName(String nullOrEmptyValue) { 155 if (StringUtils.isEmpty(this.getNodeCollectionName())) { 156 return nullOrEmptyValue; 157 } 158 159 return this.getNodeCollectionName(); 160 } 161 162 public void setNodeName(String nodeName) { 163 this.nodeName = nodeName; 164 } 165 166 public String getNodeName() { 167 return this.nodeName; 168 } 169 170 public String getNodeName(String nullOrEmptyValue) { 171 if (StringUtils.isEmpty(this.getNodeName())) { 172 return nullOrEmptyValue; 173 } 174 175 return this.getNodeName(); 176 } 177 178 public void setParagraph(String paragraph) { 179 this.paragraph = paragraph; 180 } 181 182 public String getParagraph() { 183 return this.paragraph; 184 } 185 186 public void setRequest(HttpServletRequest request) { 187 this.request = request; 188 } 189 190 public HttpServletRequest getRequest() { 191 return this.request; 192 } 193 194 public void setName(String s) { 195 this.name = s; 196 } 197 198 public String getName() { 199 return this.name; 200 } 201 202 public void setId(String s) { 203 this.id = s; 204 } 205 206 public String getId() { 207 return this.id; 208 } 209 210 public String getHtmlId() { 211 if (StringUtils.isNotEmpty(this.getId())) { 212 return " id=\"" + this.getId() + "\""; } 214 215 return StringUtils.EMPTY; 216 } 217 218 public void setValue(String value) { 219 this.value = value; 220 } 221 222 public String getValue() { 223 if (this.value != null) { 224 return this.value; 225 } 226 227 try { 228 return this.getWebsiteNode().getNodeData(this.getName()).getString(); 229 } 230 catch (Exception e) { 231 return StringUtils.EMPTY; 232 } 233 234 } 235 236 public void setValues(List values) { 237 this.values = values; 238 } 239 240 public List getValues() { 241 if (this.values.size() != 0) { 242 return this.values; 243 } 244 try { 245 Iterator it = this.getWebsiteNode().getContent(this.getName()).getNodeDataCollection().iterator(); 246 List l = new ArrayList (); 247 while (it.hasNext()) { 248 NodeData data = (NodeData) it.next(); 249 l.add(data.getString()); 250 } 251 return l; 252 } 253 catch (Exception re) { 254 return this.values; 255 } 256 } 257 258 public void setWebsiteNode(Content c) { 259 this.websiteNode = c; 260 } 261 262 public Content getWebsiteNode() { 263 return this.websiteNode; 264 } 265 266 public void setLabel(String label) { 267 this.label = label; 268 } 269 270 public String getLabel() { 271 return this.label; 272 } 273 274 public void setEvent(String event, String action) { 275 setEvent(event, action, false); 276 } 277 278 public void setEvent(String event, String action, boolean removeExisting) { 279 String eventLower = event.toLowerCase(); 280 String existing = null; 281 if (!removeExisting) { 282 existing = (String ) this.getEvents().get(eventLower); 283 } 284 if (existing == null) { 285 existing = StringUtils.EMPTY; 286 } 287 288 this.getEvents().put(eventLower, existing + action); 289 } 290 291 public void setEvents(Map h) { 292 this.events = h; 293 } 294 295 public Map getEvents() { 296 return this.events; 297 } 298 299 public String getHtmlEvents() { 300 StringBuffer html = new StringBuffer (); 301 Iterator en = this.getEvents().keySet().iterator(); 302 while (en.hasNext()) { 303 String key = (String ) en.next(); 304 html.append(" " + key + "=\"" + this.getEvents().get(key) + "\""); } 306 return html.toString(); 307 } 308 309 313 public String getHtml() { 314 return StringUtils.EMPTY; 315 } 316 317 public void setHtmlPre(String s) { 318 this.htmlPre = s; 319 } 320 321 public String getHtmlPre() { 322 return this.getHtmlPre(StringUtils.EMPTY); 323 } 324 325 public String getHtmlPre(String nullValue) { 326 if (this.htmlPre != null) { 327 return this.htmlPre; 328 } 329 330 return nullValue; 331 } 332 333 public void setHtmlInter(String s) { 334 this.htmlInter = s; 335 } 336 337 public String getHtmlInter() { 338 return this.getHtmlInter(StringUtils.EMPTY); 339 } 340 341 public String getHtmlInter(String nullValue) { 342 if (this.htmlInter != null) { 343 return this.htmlInter; 344 } 345 346 return nullValue; 347 } 348 349 public void setHtmlPost(String s) { 350 this.htmlPost = s; 351 } 352 353 public String getHtmlPost() { 354 return this.getHtmlPost(StringUtils.EMPTY); 355 } 356 357 public String getHtmlPost(String nullValue) { 358 if (this.htmlPost != null) { 359 return this.htmlPost; 360 } 361 362 return nullValue; 363 } 364 365 public void setType(int i) { 366 this.type = i; 367 } 368 369 public void setType(String s) { 370 this.type = PropertyType.valueFromName(s); 371 } 372 373 public int getType() { 374 return this.type; 375 } 376 377 public void setSaveInfo(boolean b) { 378 this.saveInfo = b; 379 } 380 381 public boolean getSaveInfo() { 382 return this.saveInfo; 383 } 384 385 public void setCssClass(String s) { 386 this.cssClass = s; 387 } 388 389 public String getCssClass() { 390 return this.cssClass; 391 } 392 393 public String getHtmlCssClass() { 394 if (StringUtils.isNotEmpty(this.getCssClass())) { 395 return " class=\"" + this.getCssClass() + "\""; } 397 398 return StringUtils.EMPTY; 399 } 400 401 public String getHtmlSaveInfo() { 402 StringBuffer html = new StringBuffer (); 403 if (this.getSaveInfo()) { 404 html.append("<input type=\"hidden\""); html.append(" name=\"mgnlSaveInfo\""); html.append(" value=\"" + this.getName() + "," + PropertyType.nameFromValue(this.getType()) + "," + this.getValueType() + "," + this.getIsRichEditValue() + "," + this.getEncoding() + "\""); html.append(" />"); } 414 return html.toString(); 415 } 416 417 public void setCssStyles(Map h) { 418 this.cssStyles = h; 419 } 420 421 public void setCssStyles(String key, String value) { 422 this.getCssStyles().put(key, value); 423 } 424 425 public Map getCssStyles() { 426 return this.cssStyles; 427 } 428 429 public String getCssStyles(String key, String nullValue) { 430 if (this.getCssStyles().containsKey(key)) { 431 return (String ) this.getCssStyles().get(key); 432 } 433 return nullValue; 434 } 435 436 public String getCssStyles(String key) { 437 return this.getCssStyles(key, StringUtils.EMPTY); 438 } 439 440 public String getHtmlCssStyles() { 441 StringBuffer html = new StringBuffer (); 442 Iterator en = this.getCssStyles().keySet().iterator(); 443 while (en.hasNext()) { 444 String key = (String ) en.next(); 445 html.append(key + ":" + this.getCssStyles().get(key) + ";"); } 447 if (html.length() > 0) { 448 return " style=\"" + html + "\""; } 450 return StringUtils.EMPTY; 451 } 452 453 public void setValueType(int i) { 454 this.valueType = i; 455 } 456 457 public int getValueType() { 458 return this.valueType; 459 } 460 461 public void setEncoding(int i) { 462 this.encoding = i; 463 } 464 465 public int getEncoding() { 466 return this.encoding; 467 } 468 469 public void setIsRichEditValue(int i) { 470 this.isRichEditValue = i; 471 } 472 473 public int getIsRichEditValue() { 474 return this.isRichEditValue; 475 } 476 477 public static String escapeHTML(String str) { 478 return str.replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">"); } 480 481 } 482 | Popular Tags |