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 ControlImpl implements Control { 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 public ControlImpl() { 121 } 122 123 public ControlImpl(String name, String value) { 124 this.setName(name); 125 this.setValue(value); 126 } 127 128 public ControlImpl(String name, List values) { 129 this.setName(name); 130 this.setValues(values); 131 } 132 133 public ControlImpl(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() 408 + "," + PropertyType.nameFromValue(this.getType()) 410 + "," + this.getValueType() 412 + "," + this.getIsRichEditValue() 414 + "," + this.getEncoding() 416 + "\""); html.append(" />"); } 419 return html.toString(); 420 } 421 422 public void setCssStyles(Map h) { 423 this.cssStyles = h; 424 } 425 426 public void setCssStyles(String key, String value) { 427 this.getCssStyles().put(key, value); 428 } 429 430 public Map getCssStyles() { 431 return this.cssStyles; 432 } 433 434 public String getCssStyles(String key, String nullValue) { 435 if (this.getCssStyles().containsKey(key)) { 436 return (String ) this.getCssStyles().get(key); 437 } 438 return nullValue; 439 } 440 441 public String getCssStyles(String key) { 442 return this.getCssStyles(key, StringUtils.EMPTY); 443 } 444 445 public String getHtmlCssStyles() { 446 StringBuffer html = new StringBuffer (); 447 Iterator en = this.getCssStyles().keySet().iterator(); 448 while (en.hasNext()) { 449 String key = (String ) en.next(); 450 html.append(key + ":" + this.getCssStyles().get(key) + ";"); } 452 if (html.length() > 0) { 453 return " style=\"" + html + "\""; } 455 return StringUtils.EMPTY; 456 } 457 458 public void setValueType(int i) { 459 this.valueType = i; 460 } 461 462 public int getValueType() { 463 return this.valueType; 464 } 465 466 public void setEncoding(int i) { 467 this.encoding = i; 468 } 469 470 public int getEncoding() { 471 return this.encoding; 472 } 473 474 public void setIsRichEditValue(int i) { 475 this.isRichEditValue = i; 476 } 477 478 public int getIsRichEditValue() { 479 return this.isRichEditValue; 480 } 481 482 public static String escapeHTML(String str) { 483 return str.replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">"); } 485 486 } 487 | Popular Tags |