1 13 package info.magnolia.cms.gui.dialog; 14 15 import info.magnolia.cms.beans.config.ContentRepository; 16 import info.magnolia.cms.core.Content; 17 import info.magnolia.cms.core.ItemType; 18 import info.magnolia.cms.gui.control.Button; 19 import info.magnolia.cms.gui.control.ControlImpl; 20 import info.magnolia.cms.gui.control.Edit; 21 import info.magnolia.cms.gui.control.Select; 22 import info.magnolia.cms.gui.control.SelectOption; 23 import info.magnolia.cms.gui.misc.CssConstants; 24 import info.magnolia.cms.gui.misc.Spacer; 25 import info.magnolia.cms.i18n.Messages; 26 import info.magnolia.cms.i18n.MessagesManager; 27 import info.magnolia.cms.util.LinkUtil; 28 29 import java.io.IOException ; 30 import java.io.Writer ; 31 import java.util.ArrayList ; 32 import java.util.Date ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 36 import javax.jcr.PathNotFoundException; 37 import javax.jcr.PropertyType; 38 import javax.jcr.RepositoryException; 39 import javax.servlet.http.HttpServletRequest ; 40 import javax.servlet.http.HttpServletResponse ; 41 42 import org.apache.commons.lang.StringUtils; 43 import org.slf4j.Logger; 44 import org.slf4j.LoggerFactory; 45 46 47 51 public class DialogRichedit extends DialogBox { 52 53 56 private static Logger log = LoggerFactory.getLogger(DialogRichedit.class); 57 58 private String richE = StringUtils.EMPTY; 59 60 private String richEPaste = StringUtils.EMPTY; 61 62 private List optionsToolboxStyleCssClasses = new ArrayList (); 63 64 private List optionsToolboxLinkCssClasses = new ArrayList (); 65 66 private List optionsToolboxLinkTargets = new ArrayList (); 67 68 71 protected DialogRichedit() { 72 } 73 74 public void setRichE(String s) { 75 this.richE = s; 76 } 77 78 public String getRichE() { 79 return this.richE; 80 } 81 82 public void setRichEPaste(String s) { 83 this.richE = s; 84 } 85 86 public String getRichEPaste() { 87 return this.richEPaste; 88 } 89 90 public void setOptionsToolboxStyleCssClasses(Content configNode) { 91 List options = this.setOptionsToolbox(configNode, "optionsToolboxStyleCssClasses"); this.setOptionsToolboxStyleCssClasses(options); 93 } 94 95 public void setOptionsToolboxStyleCssClasses(List l) { 96 this.optionsToolboxStyleCssClasses = l; 97 } 98 99 public List getOptionsToolboxStyleCssClasses() { 100 return this.optionsToolboxStyleCssClasses; 101 } 102 103 public void setOptionsToolboxLinkCssClasses(Content configNode) { 104 List options = this.setOptionsToolbox(configNode, "optionsToolboxLinkCssClasses"); this.setOptionsToolboxLinkCssClasses(options); 106 } 107 108 public void setOptionsToolboxLinkCssClasses(List l) { 109 this.optionsToolboxLinkCssClasses = l; 110 } 111 112 public List getOptionsToolboxLinkCssClasses() { 113 return this.optionsToolboxLinkCssClasses; 114 } 115 116 public void setOptionsToolboxLinkTargets(Content configNode) { 117 List options = this.setOptionsToolbox(configNode, "optionsToolboxLinkTargets"); this.setOptionsToolboxLinkTargets(options); 119 } 120 121 public void setOptionsToolboxLinkTargets(List l) { 122 this.optionsToolboxLinkTargets = l; 123 } 124 125 public List getOptionsToolboxLinkTargets() { 126 return this.optionsToolboxLinkTargets; 127 } 128 129 public List setOptionsToolbox(Content configNode, String nodeName) { 130 List options = new ArrayList (); 131 try { 132 Iterator it = configNode.getContent(nodeName).getChildren(ItemType.CONTENTNODE.getSystemName()).iterator(); 133 while (it.hasNext()) { 134 Content n = (Content) it.next(); 135 String value = n.getNodeData("value").getString(); SelectOption option = new SelectOption(null, value); 137 if (n.getNodeData("label").isExist()) { String label = n.getNodeData("label").getString(); label = this.getMessage(label); 140 option.setLabel(label); 141 } 142 if (n.getNodeData("selected").getBoolean()) { option.setId("default"); } 145 options.add(option); 146 } 147 SelectOption lastOption = new SelectOption(StringUtils.EMPTY, StringUtils.EMPTY); 148 lastOption.setSelected(true); 149 options.add(lastOption); 150 } 151 catch (PathNotFoundException e) { 152 if (log.isDebugEnabled()) { 153 log.debug("Option \"" + nodeName + "\" not found"); } 155 } 156 catch (RepositoryException e) { 157 if (log.isDebugEnabled()) { 158 log.debug("Exception caught: " + e.getMessage(), e); } 160 } 161 return options; 162 } 163 164 167 public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode, Content configNode) 168 throws RepositoryException { 169 super.init(request, response, websiteNode, configNode); 170 setOptionsToolboxLinkTargets(configNode); 171 setOptionsToolboxLinkCssClasses(configNode); 172 setOptionsToolboxStyleCssClasses(configNode); 173 } 174 175 178 public void drawHtml(Writer out) throws IOException { 179 Messages msgs = MessagesManager.getMessages(); 180 181 this.drawHtmlPre(out); 182 if (this.getRichE().equals("true") || (StringUtils.isEmpty(this.getRichE()) && this 184 .getTopParent() 185 .getConfigValue("richE", StringUtils.EMPTY).equals("true"))) { 187 DialogLine line = new DialogLine(); 188 this.setSessionAttribute(); 189 190 String value = this.getValue("<br />"); value = LinkUtil.convertUUIDsToAbsoluteLinks(value); 193 194 200 this.setValue(value); 201 out.write("</td></tr><tr><td style=\"padding-right:12px;\">"); String toolboxPasteType = this.getRichEPaste(); 208 if (StringUtils.isEmpty(toolboxPasteType)) { 209 toolboxPasteType = this.getTopParent().getConfigValue("richEPaste", "false"); } 211 if (this.getConfigValue("toolboxPaste", "true").equals("true") && !toolboxPasteType.equals("false")) { 212 out.write(line.getHtml("100%")); out.write("<div class=\"" + CssConstants.CSSCLASS_RICHETOOLBOXLABEL 216 + "\">" + msgs.get("dialog.richedit.cleancopypast") + "</div>"); if (toolboxPasteType.equals("button")) { out.write("<div class=\"" + CssConstants.CSSCLASS_RICHETOOLBOXSUBLABEL + "\">"); out.write(msgs.get("dialog.richedit.pasteUsingThisButton")); out.write("<br/><a HREF=javascript:mgnlDialogRichEPasteCleanHelp();>" + msgs.get("dialog.richedit.info") + "</a>"); out.write("</div>"); out.write(Spacer.getHtml(6, 6)); 228 Button pastePaste = new Button(); 229 pastePaste.setLabel(msgs.get("dialog.richedit.cleanpaste")); pastePaste.setSmall(true); 231 pastePaste.setOnclick("mgnlDialogRichEPasteClean('" + this.getName() + "',true);"); out.write(pastePaste.getHtml()); 233 } 234 else { 235 out.write("<div class=\"" + CssConstants.CSSCLASS_RICHETOOLBOXSUBLABEL + "\">"); out.write(msgs.get("dialog.richedit.pastetext")); out.write("<br/><a HREF=javascript:mgnlDialogRichEPasteCleanHelp();>" + msgs.get("dialog.richedit.info") + "</a>"); out.write("</div>"); out.write(Spacer.getHtml(3, 3)); 243 out.write("<textarea class=\"" + CssConstants.CSSCLASS_EDIT 245 + "\" name=\"" + this.getName() 247 + "-paste\" rows=\"2\" style=\"width:100%;\"></textarea>"); out.write(Spacer.getHtml(3, 3)); 249 Button pasteAppend = new Button(); 250 pasteAppend.setLabel(msgs.get("dialog.richedit.append")); pasteAppend.setSmall(true); 252 pasteAppend.setOnclick("mgnlDialogRichEPasteTextarea('" + this.getName() + "',true);"); out.write(pasteAppend.getHtml()); 254 Button pasteInsert = new Button(); 255 pasteInsert.setLabel(msgs.get("dialog.richedit.insert")); pasteInsert.setSmall(true); 257 pasteInsert.setOnclick("mgnlDialogRichEPasteTextarea('" + this.getName() + "',false);"); out.write(pasteInsert.getHtml()); 259 } 260 out.write(Spacer.getHtml(36, 36)); 261 } 262 if (this.getConfigValue("toolboxLink", "true").equals("true")) { out.write(line.getHtml("100%")); out.write("<div class=\"" + CssConstants.CSSCLASS_RICHETOOLBOXLABEL 268 + "\">" + msgs.get("dialog.richedit.link") + "</div>"); String linkEditName = "kupu-link-input"; Edit linkEdit = new Edit(linkEditName, StringUtils.EMPTY); 274 linkEdit.setCssClass(CssConstants.CSSCLASS_EDIT); 275 linkEdit.setSaveInfo(false); 276 linkEdit.setCssStyles("width", "100%"); out.write(linkEdit.getHtml()); 278 out.write(Spacer.getHtml(2, 2)); 279 Button linkButtonBrowse = new Button(); 281 String extension = this.getConfigValue("toolboxLinkExtension", "html"); String repository = this.getConfigValue("toolboxLinkRepository", ContentRepository.WEBSITE); linkButtonBrowse.setOnclick("mgnlDialogLinkOpenBrowser('" + linkEditName 286 + "','" + repository 288 + "','" + extension 290 + "',false);"); linkButtonBrowse.setSmall(true); 292 linkButtonBrowse.setLabel(msgs.get("dialog.richedit.internallink")); out.write(linkButtonBrowse.getHtml()); 294 if (this.getOptionsToolboxLinkTargets().size() > 1) { 296 out.write("<div class=\"" + CssConstants.CSSCLASS_RICHETOOLBOXSUBLABEL 298 + "\">" + msgs.get("dialog.richedit.target") + "</div>"); Select control = new Select(); 302 control.setName("kupu-link-input-target"); control.setSaveInfo(false); 304 control.setCssClass(CssConstants.CSSCLASS_SELECT); 305 control.setCssStyles("width", "100%"); control.setOptions(this.getOptionsToolboxLinkTargets()); 307 out.write(control.getHtml()); 308 } 309 if (this.getOptionsToolboxLinkCssClasses().size() > 1) { 311 out.write("<div class=\"" + CssConstants.CSSCLASS_RICHETOOLBOXSUBLABEL 313 + "\">" + msgs.get("dialog.richedit.style") + "</div>"); Select control = new Select(); 317 control.setName("kupu-link-input-css"); control.setSaveInfo(false); 319 control.setCssClass(CssConstants.CSSCLASS_SELECT); 320 control.setCssStyles("width", "100%"); control.setOptions(this.getOptionsToolboxLinkCssClasses()); 322 out.write(control.getHtml()); 323 } 324 out.write(Spacer.getHtml(3, 3)); 325 Button linkButtonApply = new Button(); 327 linkButtonApply.setId("kupu-link-button"); linkButtonApply.setLabel(msgs.get("dialog.richedit.applaylink")); linkButtonApply.setSmall(true); 330 out.write(linkButtonApply.getHtml()); 331 Button linkButtonRemove = new Button(); 333 linkButtonRemove.setId("kupu-link-button-remove"); linkButtonRemove.setLabel(msgs.get("dialog.richedit.removelink")); linkButtonRemove.setSmall(true); 336 out.write(linkButtonRemove.getHtml()); 337 out.write(Spacer.getHtml(36, 36)); 338 } 339 if (this.getConfigValue("toolboxStyle", "false").equals("true")) { out.write(line.getHtml("100%")); out.write("<div class=\"" + CssConstants.CSSCLASS_RICHETOOLBOXLABEL 345 + "\">" + msgs.get("dialog.richedit.textstyle") + "</div>"); if (this.getOptionsToolboxStyleCssClasses().size() > 1) { 349 Select control = new Select(); 350 control.setName(this.getName() + "-css-input-css"); control.setSaveInfo(false); 352 control.setCssClass(CssConstants.CSSCLASS_SELECT); 353 control.setCssStyles("width", "100%"); control.setOptions(this.getOptionsToolboxStyleCssClasses()); 355 out.write(control.getHtml()); 356 } 357 out.write(Spacer.getHtml(3, 3)); 358 Button cssButtonApply = new Button(); 360 cssButtonApply.setId(this.getName() + "-css-button"); cssButtonApply.setLabel(msgs.get("dialog.richedit.applaystyle")); cssButtonApply.setSmall(true); 363 out.write(cssButtonApply.getHtml()); 364 Button cssButtonRemove = new Button(); 366 cssButtonRemove.setId(this.getName() + "-css-button-remove"); cssButtonRemove.setLabel(msgs.get("dialog.richedit.removestyle")); cssButtonRemove.setSmall(true); 369 out.write(cssButtonRemove.getHtml()); 370 } 371 out.write("</td><td>"); out.write("<div class=\"kupu-tb\" id=\"toolbar\">"); out.write("<span id=\"kupu-tb-buttons\">"); out.write("<span class=\"kupu-tb-buttongroup\">"); if (this.getConfigValue("toolbarBold", "true").equals("true")) { out.write("<button type=\"button\" class=\"kupu-bold\" title=\"" + msgs.get("dialog.richedit.bold") + "\" onclick=\"kupuui.basicButtonHandler('bold');\"> </button>"); } 388 if (this.getConfigValue("toolbarItalic", "true").equals("true")) { out.write("<button type=\"button\" class=\"kupu-italic\" title=\"" + msgs.get("dialog.richedit.italic") + "\" onclick=\"kupuui.basicButtonHandler('italic');\"> </button>"); } 393 if (this.getConfigValue("toolbarUnderline", "false").equals("true")) { 394 out.write("<button type=\"button\" class=\"kupu-underline\" title=\"" + msgs.get("dialog.richedit.underline") + "\" onclick=\"kupuui.basicButtonHandler('underline');\"> </button>"); } 398 out.write("</span>"); out.write("<span class=\"kupu-tb-buttongroup\">"); if (this.getConfigValue("toolbarSubscript", "false").equals("true")) { 401 out.write("<button type=\"button\" class=\"kupu-subscript\" title=\"" + msgs.get("dialog.richedit.subscript") + "\" onclick=\"kupuui.basicButtonHandler('subscript');\"> </button>"); } 405 if (this.getConfigValue("toolbarSuperscript", "false").equals("true")) { 406 out.write("<button type=\"button\" class=\"kupu-superscript\" title=\"" + msgs.get("dialog.richedit.superscript") + "\" onclick=\"kupuui.basicButtonHandler('superscript');\"> </button>"); } 410 out.write("</span>"); if (this.getConfigValue("toolbarColors", "false").equals("true")) { 412 out.write("<span class=\"kupu-tb-buttongroup\">"); out.write("<button type=\"button\" class=\"kupu-forecolor\" id=\"kupu-forecolor\" title=\"" + msgs.get("dialog.richedit.textcolor") + "\"> </button>"); out.write("<button type=\"button\" class=\"kupu-hilitecolor\" id=\"kupu-hilitecolor\" title=\"" + msgs.get("dialog.richedit.backgroundcolor") + "\"> </button>"); out.write("</span>"); } 423 if (this.getConfigValue("toolbarUndo", "true").equals("true")) { out.write(" <span class=\"kupu-tb-buttongroup\">"); out.write("<button type=\"button\" class=\"kupu-undo\" title=\"" + msgs.get("dialog.richedit.undo") + "\" onclick=\"kupuui.basicButtonHandler('undo');\"></button>"); out.write("<button type=\"button\" class=\"kupu-redo\" title=\"" + msgs.get("dialog.richedit.redo") + "\" onclick=\"kupuui.basicButtonHandler('redo');\"></button>"); out.write(" </span>"); } 433 if (this.getConfigValue("toolbarLists", "true").equals("true")) { out.write("<span class=\"kupu-tb-buttongroup\">"); out.write("<button type=\"button\" class=\"kupu-insertorderedlist\" title=\"" + msgs.get("dialog.richedit.numberedlist") + "\" id=\"kupu-list-ol-addbutton\"></button>"); out.write("<button type=\"button\" class=\"kupu-insertunorderedlist\" title=\"" + msgs.get("dialog.richedit.unorderedlist") + "\" id=\"kupu-list-ul-addbutton\"></button>"); out.write("</span>"); out.write("<select id=\"kupu-ulstyles\" class=\"" + CssConstants.CSSCLASS_SELECT + "\">"); out.write(" <option value=\"disc\">Disc</option>"); out.write(" <option value=\"square\">Square</option>"); out.write(" <option value=\"circle\">Circle</option>"); out.write(" <option value=\"none\">no bullet</option>"); out.write("</select>"); out.write("<select id=\"kupu-olstyles\" class=\"" + CssConstants.CSSCLASS_SELECT + "\">"); out.write(" <option value=\"decimal\">1</option>"); out.write(" <option value=\"upper-roman\">I</option>"); out.write(" <option value=\"lower-roman\">i</option>"); out.write(" <option value=\"upper-alpha\">A</option>"); out.write(" <option value=\"lower-alpha\">a</option>"); out.write("</select>"); } 457 out.write("</span>"); out.write("</div>"); out 464 .write("<div id=\"kupu-colorchooser\" style=\"position: fixed; border-style: solid; border-color: #666666; border-width: 1px;\"> </div>"); out.write("<iframe id=\"" + this.getName() + "-kupu-editor\""); out.write(" class=\"" + CssConstants.CSSCLASS_RICHEIFRAME + "\""); if (this.getConfigValue("height", null) != null) { out.write(" style=\"height:" + this.getConfigValue("height") + ";\""); } 473 out.write(" frameborder=\"0\""); out.write(" SRC=\"" + this.getRequest().getContextPath() 476 + "/.magnolia/pages/richEIFrame.html?" + SESSION_ATTRIBUTENAME_DIALOGOBJECT 478 + "=" + this.getConfigValue(SESSION_ATTRIBUTENAME_DIALOGOBJECT) 480 + "&mgnlCK=" + new Date ().getTime() 482 + "\""); out.write(" reloadsrc=\"0\""); out.write(" usecss=\"1\""); out.write(" strict_output=\"1\""); out.write(" content_type=\"application/xhtml+xml\""); out.write(" scrolling=\"auto\""); out.write("></iframe>"); out.write("<script type=\"text/javascript\">"); out.write("mgnlRichEditors[mgnlRichEditors.length]='" + this.getName() + "';"); out.write("</script>"); out.write("<div style=visibility:hidden;position:absolute;top:0px;left:-500px;>"); Edit hiddenTextarea = new Edit(this.getName(), StringUtils.EMPTY); 500 hiddenTextarea.setRows("5"); hiddenTextarea.setIsRichEditValue(ControlImpl.RICHEDIT_KUPU); 503 out.write(hiddenTextarea.getHtml()); 504 out.write("</div>"); 506 } 507 else { 508 Edit control = new Edit(this.getName(), this.getValue()); 510 control.setType(this.getConfigValue("type", PropertyType.TYPENAME_STRING)); if (this.getConfigValue("saveInfo").equals("false")) { control.setSaveInfo(false); 513 } 514 control.setCssClass(CssConstants.CSSCLASS_EDIT); 515 control.setRows(this.getConfigValue("rows", "18")); control.setCssStyles("width", this.getConfigValue("width", "100%")); 518 out.write(control.getHtml()); 519 520 } 521 this.drawHtmlPost(out); 522 } 523 524 public void drawHtmlEditor(Writer out) throws IOException { 525 526 out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "); out.write(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); 529 out.write("<html><head>"); out.write("<meta http-equiv=\"Pragma\" content=\"no-cache\" />"); out.write("<meta http-equiv=\"Cache-Control\" content=\"no-cache, must-revalidate\" />"); out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>"); out.write("<meta name=\"Effective_date\" content=\"None\" />"); out.write("<meta name=\"Expiration_date\" content=\"None\" />"); out.write("<meta name=\"Type\" content=\"Document\" />"); out.write("<meta name=\"Language\" content=\"\" />"); out.write("<meta name=\"Rights\" content=\"\" />"); out.write("<style type=\"text/css\">"); out.write("body {font-family:verdana;font-size:11px;background-color:#ffffff;}"); out.write("</style>"); if (this.getConfigValue("cssFile", null) != null) { out.write("<link HREF=\"" + this.getConfigValue("cssFile") + "\" rel=\"stylesheet\" type=\"text/css\"/>"); } 548 out.write("<script type=\"text/javascript\">\n"); out.write("document.insertText=function(value)\n"); out.write(" {\n"); out.write(" while (value.indexOf('\\n')!=-1)\n"); out.write(" {\n"); out.write(" value=value.replace('\\n','<br />');\n"); out.write(" }\n"); out.write(" var body=document.getElementsByTagName('body');\n"); out.write(" value=body[0].innerHTML+value;\n"); out.write(" body[0].innerHTML=value;\n"); out.write(" }\n"); out.write("</script>\n"); out.write("</head>\n"); out.write("<body>"); out.write(this.getValue()); 563 out.write("</body></html>"); 565 } 566 567 public String getValue(String lineBreak) { 568 String value = this.getValue(); 569 570 if (value != null) { 571 return value.replaceAll("\n", "<br />"); } 573 else if (this.getWebsiteNode() != null) { 574 return this.getWebsiteNode().getNodeData(this.getName()).getString(lineBreak); 575 } 576 else { 577 return StringUtils.EMPTY; 578 } 579 } 580 } 581 | Popular Tags |