KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > dialog > DialogRichedit


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

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 JavaDoc;
30 import java.io.Writer JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Date JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35
36 import javax.jcr.PathNotFoundException;
37 import javax.jcr.PropertyType;
38 import javax.jcr.RepositoryException;
39 import javax.servlet.http.HttpServletRequest JavaDoc;
40 import javax.servlet.http.HttpServletResponse JavaDoc;
41
42 import org.apache.commons.lang.StringUtils;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45
46
47 /**
48  * @author Vinzenz Wyser
49  * @version 2.0
50  */

51 public class DialogRichedit extends DialogBox {
52
53     /**
54      * Logger.
55      */

56     private static Logger log = LoggerFactory.getLogger(DialogRichedit.class);
57
58     private String JavaDoc richE = StringUtils.EMPTY;
59
60     private String JavaDoc richEPaste = StringUtils.EMPTY;
61
62     private List JavaDoc optionsToolboxStyleCssClasses = new ArrayList JavaDoc();
63
64     private List JavaDoc optionsToolboxLinkCssClasses = new ArrayList JavaDoc();
65
66     private List JavaDoc optionsToolboxLinkTargets = new ArrayList JavaDoc();
67
68     /**
69      * Empty constructor should only be used by DialogFactory.
70      */

71     protected DialogRichedit() {
72     }
73
74     public void setRichE(String JavaDoc s) {
75         this.richE = s;
76     }
77
78     public String JavaDoc getRichE() {
79         return this.richE;
80     }
81
82     public void setRichEPaste(String JavaDoc s) {
83         this.richE = s;
84     }
85
86     public String JavaDoc getRichEPaste() {
87         return this.richEPaste;
88     }
89
90     public void setOptionsToolboxStyleCssClasses(Content configNode) {
91         List JavaDoc options = this.setOptionsToolbox(configNode, "optionsToolboxStyleCssClasses"); //$NON-NLS-1$
92
this.setOptionsToolboxStyleCssClasses(options);
93     }
94
95     public void setOptionsToolboxStyleCssClasses(List JavaDoc l) {
96         this.optionsToolboxStyleCssClasses = l;
97     }
98
99     public List JavaDoc getOptionsToolboxStyleCssClasses() {
100         return this.optionsToolboxStyleCssClasses;
101     }
102
103     public void setOptionsToolboxLinkCssClasses(Content configNode) {
104         List JavaDoc options = this.setOptionsToolbox(configNode, "optionsToolboxLinkCssClasses"); //$NON-NLS-1$
105
this.setOptionsToolboxLinkCssClasses(options);
106     }
107
108     public void setOptionsToolboxLinkCssClasses(List JavaDoc l) {
109         this.optionsToolboxLinkCssClasses = l;
110     }
111
112     public List JavaDoc getOptionsToolboxLinkCssClasses() {
113         return this.optionsToolboxLinkCssClasses;
114     }
115
116     public void setOptionsToolboxLinkTargets(Content configNode) {
117         List JavaDoc options = this.setOptionsToolbox(configNode, "optionsToolboxLinkTargets"); //$NON-NLS-1$
118
this.setOptionsToolboxLinkTargets(options);
119     }
120
121     public void setOptionsToolboxLinkTargets(List JavaDoc l) {
122         this.optionsToolboxLinkTargets = l;
123     }
124
125     public List JavaDoc getOptionsToolboxLinkTargets() {
126         return this.optionsToolboxLinkTargets;
127     }
128
129     public List JavaDoc setOptionsToolbox(Content configNode, String JavaDoc nodeName) {
130         List JavaDoc options = new ArrayList JavaDoc();
131         try {
132             Iterator JavaDoc it = configNode.getContent(nodeName).getChildren(ItemType.CONTENTNODE.getSystemName()).iterator();
133             while (it.hasNext()) {
134                 Content n = (Content) it.next();
135                 String JavaDoc value = n.getNodeData("value").getString(); //$NON-NLS-1$
136
SelectOption option = new SelectOption(null, value);
137                 if (n.getNodeData("label").isExist()) { //$NON-NLS-1$
138
String JavaDoc label = n.getNodeData("label").getString(); //$NON-NLS-1$
139
label = this.getMessage(label);
140                     option.setLabel(label);
141                 }
142                 if (n.getNodeData("selected").getBoolean()) { //$NON-NLS-1$
143
option.setId("default"); //$NON-NLS-1$
144
}
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"); //$NON-NLS-1$ //$NON-NLS-2$
154
}
155         }
156         catch (RepositoryException e) {
157             if (log.isDebugEnabled()) {
158                 log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
159
}
160         }
161         return options;
162     }
163
164     /**
165      * @see info.magnolia.cms.gui.dialog.DialogControl#init(HttpServletRequest, HttpServletResponse, Content, Content)
166      */

167     public void init(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc 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     /**
176      * @see info.magnolia.cms.gui.dialog.DialogControl#drawHtml(Writer)
177      */

178     public void drawHtml(Writer JavaDoc out) throws IOException JavaDoc {
179         Messages msgs = MessagesManager.getMessages();
180
181         this.drawHtmlPre(out);
182         if (this.getRichE().equals("true") //$NON-NLS-1$
183
|| (StringUtils.isEmpty(this.getRichE()) && this
184                 .getTopParent()
185                 .getConfigValue("richE", StringUtils.EMPTY).equals("true"))) { //$NON-NLS-1$ //$NON-NLS-2$
186

187             DialogLine line = new DialogLine();
188             this.setSessionAttribute();
189
190             String JavaDoc value = this.getValue("<br />"); //$NON-NLS-1$
191
// make proper links
192
value = LinkUtil.convertUUIDsToAbsoluteLinks(value);
193
194             // TODO since we do not manipulate during storing we do not have to replace them. Maybe this leads to
195
// problems
196
// remove <span>s by <a>s so its readable by kupu
197
// value = value.replaceAll("<span ", "<a ");
198
// value = value.replaceAll("</span>", "</a>");
199

200             this.setValue(value);
201             // modification of dialogBox
202
out.write("</td></tr><tr><td style=\"padding-right:12px;\">"); //$NON-NLS-1$
203
// #################
204
// toolboxes
205
// #################
206
// toolbox paste
207
String JavaDoc toolboxPasteType = this.getRichEPaste();
208             if (StringUtils.isEmpty(toolboxPasteType)) {
209                 toolboxPasteType = this.getTopParent().getConfigValue("richEPaste", "false"); //$NON-NLS-1$ //$NON-NLS-2$
210
}
211             if (this.getConfigValue("toolboxPaste", "true").equals("true") && !toolboxPasteType.equals("false")) {
212                 // win only; clipboard on mac is clean already
213
out.write(line.getHtml("100%")); //$NON-NLS-1$
214
out.write("<div class=\"" //$NON-NLS-1$
215
+ CssConstants.CSSCLASS_RICHETOOLBOXLABEL
216                     + "\">" //$NON-NLS-1$
217
+ msgs.get("dialog.richedit.cleancopypast") //$NON-NLS-1$
218
+ "</div>"); //$NON-NLS-1$
219
if (toolboxPasteType.equals("button")) { //$NON-NLS-1$
220
// ie/win
221
out.write("<div class=\"" + CssConstants.CSSCLASS_RICHETOOLBOXSUBLABEL + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
222
out.write(msgs.get("dialog.richedit.pasteUsingThisButton")); //$NON-NLS-1$
223
out.write("<br/><a HREF=javascript:mgnlDialogRichEPasteCleanHelp();>" //$NON-NLS-1$
224
+ msgs.get("dialog.richedit.info") //$NON-NLS-1$
225
+ "</a>"); //$NON-NLS-1$
226
out.write("</div>"); //$NON-NLS-1$
227
out.write(Spacer.getHtml(6, 6));
228                     Button pastePaste = new Button();
229                     pastePaste.setLabel(msgs.get("dialog.richedit.cleanpaste")); //$NON-NLS-1$
230
pastePaste.setSmall(true);
231                     pastePaste.setOnclick("mgnlDialogRichEPasteClean('" + this.getName() + "',true);"); //$NON-NLS-1$ //$NON-NLS-2$
232
out.write(pastePaste.getHtml());
233                 }
234                 else {
235                     // mozilla/win
236
out.write("<div class=\"" + CssConstants.CSSCLASS_RICHETOOLBOXSUBLABEL + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
237
out.write(msgs.get("dialog.richedit.pastetext")); //$NON-NLS-1$
238
out.write("<br/><a HREF=javascript:mgnlDialogRichEPasteCleanHelp();>" //$NON-NLS-1$
239
+ msgs.get("dialog.richedit.info") //$NON-NLS-1$
240
+ "</a>"); //$NON-NLS-1$
241
out.write("</div>"); //$NON-NLS-1$
242
out.write(Spacer.getHtml(3, 3));
243                     out.write("<textarea class=\"" //$NON-NLS-1$
244
+ CssConstants.CSSCLASS_EDIT
245                         + "\" name=\"" //$NON-NLS-1$
246
+ this.getName()
247                         + "-paste\" rows=\"2\" style=\"width:100%;\"></textarea>"); //$NON-NLS-1$
248
out.write(Spacer.getHtml(3, 3));
249                     Button pasteAppend = new Button();
250                     pasteAppend.setLabel(msgs.get("dialog.richedit.append")); //$NON-NLS-1$
251
pasteAppend.setSmall(true);
252                     pasteAppend.setOnclick("mgnlDialogRichEPasteTextarea('" + this.getName() + "',true);"); //$NON-NLS-1$ //$NON-NLS-2$
253
out.write(pasteAppend.getHtml());
254                     Button pasteInsert = new Button();
255                     pasteInsert.setLabel(msgs.get("dialog.richedit.insert")); //$NON-NLS-1$
256
pasteInsert.setSmall(true);
257                     pasteInsert.setOnclick("mgnlDialogRichEPasteTextarea('" + this.getName() + "',false);"); //$NON-NLS-1$ //$NON-NLS-2$
258
out.write(pasteInsert.getHtml());
259                 }
260                 out.write(Spacer.getHtml(36, 36));
261             }
262             // END toolbox paste
263
// toolbox link
264
if (this.getConfigValue("toolboxLink", "true").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
265
out.write(line.getHtml("100%")); //$NON-NLS-1$
266
out.write("<div class=\"" //$NON-NLS-1$
267
+ CssConstants.CSSCLASS_RICHETOOLBOXLABEL
268                     + "\">" //$NON-NLS-1$
269
+ msgs.get("dialog.richedit.link") //$NON-NLS-1$
270
+ "</div>"); //$NON-NLS-1$
271
// link: edit control (href)
272
String JavaDoc linkEditName = "kupu-link-input"; //$NON-NLS-1$
273
Edit linkEdit = new Edit(linkEditName, StringUtils.EMPTY);
274                 linkEdit.setCssClass(CssConstants.CSSCLASS_EDIT);
275                 linkEdit.setSaveInfo(false);
276                 linkEdit.setCssStyles("width", "100%"); //$NON-NLS-1$ //$NON-NLS-2$
277
out.write(linkEdit.getHtml());
278                 out.write(Spacer.getHtml(2, 2));
279                 // link: button internal link browse
280
Button linkButtonBrowse = new Button();
281                 // todo: extension
282
String JavaDoc extension = this.getConfigValue("toolboxLinkExtension", "html"); //$NON-NLS-1$ //$NON-NLS-2$
283
String JavaDoc repository = this.getConfigValue("toolboxLinkRepository", ContentRepository.WEBSITE); //$NON-NLS-1$
284
linkButtonBrowse.setOnclick("mgnlDialogLinkOpenBrowser('" //$NON-NLS-1$
285
+ linkEditName
286                     + "','" //$NON-NLS-1$
287
+ repository
288                     + "','" //$NON-NLS-1$
289
+ extension
290                     + "',false);"); //$NON-NLS-1$
291
linkButtonBrowse.setSmall(true);
292                 linkButtonBrowse.setLabel(msgs.get("dialog.richedit.internallink")); //$NON-NLS-1$
293
out.write(linkButtonBrowse.getHtml());
294                 // link: target
295
if (this.getOptionsToolboxLinkTargets().size() > 1) {
296                     out.write("<div class=\"" //$NON-NLS-1$
297
+ CssConstants.CSSCLASS_RICHETOOLBOXSUBLABEL
298                         + "\">" //$NON-NLS-1$
299
+ msgs.get("dialog.richedit.target") //$NON-NLS-1$
300
+ "</div>"); //$NON-NLS-1$
301
Select control = new Select();
302                     control.setName("kupu-link-input-target"); //$NON-NLS-1$
303
control.setSaveInfo(false);
304                     control.setCssClass(CssConstants.CSSCLASS_SELECT);
305                     control.setCssStyles("width", "100%"); //$NON-NLS-1$ //$NON-NLS-2$
306
control.setOptions(this.getOptionsToolboxLinkTargets());
307                     out.write(control.getHtml());
308                 }
309                 // link: css class
310
if (this.getOptionsToolboxLinkCssClasses().size() > 1) {
311                     out.write("<div class=\"" //$NON-NLS-1$
312
+ CssConstants.CSSCLASS_RICHETOOLBOXSUBLABEL
313                         + "\">" //$NON-NLS-1$
314
+ msgs.get("dialog.richedit.style") //$NON-NLS-1$
315
+ "</div>"); //$NON-NLS-1$
316
Select control = new Select();
317                     control.setName("kupu-link-input-css"); //$NON-NLS-1$
318
control.setSaveInfo(false);
319                     control.setCssClass(CssConstants.CSSCLASS_SELECT);
320                     control.setCssStyles("width", "100%"); //$NON-NLS-1$ //$NON-NLS-2$
321
control.setOptions(this.getOptionsToolboxLinkCssClasses());
322                     out.write(control.getHtml());
323                 }
324                 out.write(Spacer.getHtml(3, 3));
325                 // link: apply button
326
Button linkButtonApply = new Button();
327                 linkButtonApply.setId("kupu-link-button"); //$NON-NLS-1$
328
linkButtonApply.setLabel(msgs.get("dialog.richedit.applaylink")); //$NON-NLS-1$
329
linkButtonApply.setSmall(true);
330                 out.write(linkButtonApply.getHtml());
331                 // link: remove button
332
Button linkButtonRemove = new Button();
333                 linkButtonRemove.setId("kupu-link-button-remove"); //$NON-NLS-1$
334
linkButtonRemove.setLabel(msgs.get("dialog.richedit.removelink")); //$NON-NLS-1$
335
linkButtonRemove.setSmall(true);
336                 out.write(linkButtonRemove.getHtml());
337                 out.write(Spacer.getHtml(36, 36));
338             }
339             // END toolbox link
340
// toolbox css
341
if (this.getConfigValue("toolboxStyle", "false").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
342
out.write(line.getHtml("100%")); //$NON-NLS-1$
343
out.write("<div class=\"" //$NON-NLS-1$
344
+ CssConstants.CSSCLASS_RICHETOOLBOXLABEL
345                     + "\">" //$NON-NLS-1$
346
+ msgs.get("dialog.richedit.textstyle") //$NON-NLS-1$
347
+ "</div>"); //$NON-NLS-1$
348
if (this.getOptionsToolboxStyleCssClasses().size() > 1) {
349                     Select control = new Select();
350                     control.setName(this.getName() + "-css-input-css"); //$NON-NLS-1$
351
control.setSaveInfo(false);
352                     control.setCssClass(CssConstants.CSSCLASS_SELECT);
353                     control.setCssStyles("width", "100%"); //$NON-NLS-1$ //$NON-NLS-2$
354
control.setOptions(this.getOptionsToolboxStyleCssClasses());
355                     out.write(control.getHtml());
356                 }
357                 out.write(Spacer.getHtml(3, 3));
358                 // css: apply button
359
Button cssButtonApply = new Button();
360                 cssButtonApply.setId(this.getName() + "-css-button"); //$NON-NLS-1$
361
cssButtonApply.setLabel(msgs.get("dialog.richedit.applaystyle")); //$NON-NLS-1$
362
cssButtonApply.setSmall(true);
363                 out.write(cssButtonApply.getHtml());
364                 // css: remove button
365
Button cssButtonRemove = new Button();
366                 cssButtonRemove.setId(this.getName() + "-css-button-remove"); //$NON-NLS-1$
367
cssButtonRemove.setLabel(msgs.get("dialog.richedit.removestyle")); //$NON-NLS-1$
368
cssButtonRemove.setSmall(true);
369                 out.write(cssButtonRemove.getHtml());
370             }
371             // END toolbox css
372
// #################
373
// END toolboxes
374
// #################
375
// modification of dialogBox
376
out.write("</td><td>"); //$NON-NLS-1$
377
// #################
378
// toolbar
379
// #################
380
out.write("<div class=\"kupu-tb\" id=\"toolbar\">"); //$NON-NLS-1$
381
out.write("<span id=\"kupu-tb-buttons\">"); //$NON-NLS-1$
382
out.write("<span class=\"kupu-tb-buttongroup\">"); //$NON-NLS-1$
383
if (this.getConfigValue("toolbarBold", "true").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
384
out.write("<button type=\"button\" class=\"kupu-bold\" title=\"" //$NON-NLS-1$
385
+ msgs.get("dialog.richedit.bold") //$NON-NLS-1$
386
+ "\" onclick=\"kupuui.basicButtonHandler('bold');\">&nbsp;</button>"); //$NON-NLS-1$
387
}
388             if (this.getConfigValue("toolbarItalic", "true").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
389
out.write("<button type=\"button\" class=\"kupu-italic\" title=\"" //$NON-NLS-1$
390
+ msgs.get("dialog.richedit.italic") //$NON-NLS-1$
391
+ "\" onclick=\"kupuui.basicButtonHandler('italic');\">&nbsp;</button>"); //$NON-NLS-1$
392
}
393             if (this.getConfigValue("toolbarUnderline", "false").equals("true")) {
394                 out.write("<button type=\"button\" class=\"kupu-underline\" title=\"" //$NON-NLS-1$
395
+ msgs.get("dialog.richedit.underline") //$NON-NLS-1$
396
+ "\" onclick=\"kupuui.basicButtonHandler('underline');\">&nbsp;</button>"); //$NON-NLS-1$
397
}
398             out.write("</span>"); //$NON-NLS-1$
399
out.write("<span class=\"kupu-tb-buttongroup\">"); //$NON-NLS-1$
400
if (this.getConfigValue("toolbarSubscript", "false").equals("true")) {
401                 out.write("<button type=\"button\" class=\"kupu-subscript\" title=\"" //$NON-NLS-1$
402
+ msgs.get("dialog.richedit.subscript") //$NON-NLS-1$
403
+ "\" onclick=\"kupuui.basicButtonHandler('subscript');\">&nbsp;</button>"); //$NON-NLS-1$
404
}
405             if (this.getConfigValue("toolbarSuperscript", "false").equals("true")) {
406                 out.write("<button type=\"button\" class=\"kupu-superscript\" title=\"" //$NON-NLS-1$
407
+ msgs.get("dialog.richedit.superscript") //$NON-NLS-1$
408
+ "\" onclick=\"kupuui.basicButtonHandler('superscript');\">&nbsp;</button>"); //$NON-NLS-1$
409
}
410             out.write("</span>"); //$NON-NLS-1$
411
if (this.getConfigValue("toolbarColors", "false").equals("true")) {
412                 // kupu note: the event handlers are attached to these buttons dynamically, like for tools
413
// mozilla (1.5) does not support font background color yet!
414
out.write("<span class=\"kupu-tb-buttongroup\">"); //$NON-NLS-1$
415
out.write("<button type=\"button\" class=\"kupu-forecolor\" id=\"kupu-forecolor\" title=\"" //$NON-NLS-1$
416
+ msgs.get("dialog.richedit.textcolor") //$NON-NLS-1$
417
+ "\">&nbsp;</button>"); //$NON-NLS-1$
418
out.write("<button type=\"button\" class=\"kupu-hilitecolor\" id=\"kupu-hilitecolor\" title=\"" //$NON-NLS-1$
419
+ msgs.get("dialog.richedit.backgroundcolor") //$NON-NLS-1$
420
+ "\">&nbsp;</button>"); //$NON-NLS-1$
421
out.write("</span>"); //$NON-NLS-1$
422
}
423             if (this.getConfigValue("toolbarUndo", "true").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
424
out.write(" <span class=\"kupu-tb-buttongroup\">"); //$NON-NLS-1$
425
out.write("<button type=\"button\" class=\"kupu-undo\" title=\"" //$NON-NLS-1$
426
+ msgs.get("dialog.richedit.undo") //$NON-NLS-1$
427
+ "\" onclick=\"kupuui.basicButtonHandler('undo');\"></button>"); //$NON-NLS-1$
428
out.write("<button type=\"button\" class=\"kupu-redo\" title=\"" //$NON-NLS-1$
429
+ msgs.get("dialog.richedit.redo") //$NON-NLS-1$
430
+ "\" onclick=\"kupuui.basicButtonHandler('redo');\"></button>"); //$NON-NLS-1$
431
out.write(" </span>"); //$NON-NLS-1$
432
}
433             if (this.getConfigValue("toolbarLists", "true").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
434
out.write("<span class=\"kupu-tb-buttongroup\">"); //$NON-NLS-1$
435
// kupu note: list button events are set on the list tool
436
out.write("<button type=\"button\" class=\"kupu-insertorderedlist\" title=\"" //$NON-NLS-1$
437
+ msgs.get("dialog.richedit.numberedlist") //$NON-NLS-1$
438
+ "\" id=\"kupu-list-ol-addbutton\"></button>"); //$NON-NLS-1$
439
out.write("<button type=\"button\" class=\"kupu-insertunorderedlist\" title=\"" //$NON-NLS-1$
440
+ msgs.get("dialog.richedit.unorderedlist") //$NON-NLS-1$
441
+ "\" id=\"kupu-list-ul-addbutton\"></button>"); //$NON-NLS-1$
442
out.write("</span>"); //$NON-NLS-1$
443
out.write("<select id=\"kupu-ulstyles\" class=\"" + CssConstants.CSSCLASS_SELECT + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
444
out.write(" <option value=\"disc\">Disc</option>"); //$NON-NLS-1$
445
out.write(" <option value=\"square\">Square</option>"); //$NON-NLS-1$
446
out.write(" <option value=\"circle\">Circle</option>"); //$NON-NLS-1$
447
out.write(" <option value=\"none\">no bullet</option>"); //$NON-NLS-1$
448
out.write("</select>"); //$NON-NLS-1$
449
out.write("<select id=\"kupu-olstyles\" class=\"" + CssConstants.CSSCLASS_SELECT + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
450
out.write(" <option value=\"decimal\">1</option>"); //$NON-NLS-1$
451
out.write(" <option value=\"upper-roman\">I</option>"); //$NON-NLS-1$
452
out.write(" <option value=\"lower-roman\">i</option>"); //$NON-NLS-1$
453
out.write(" <option value=\"upper-alpha\">A</option>"); //$NON-NLS-1$
454
out.write(" <option value=\"lower-alpha\">a</option>"); //$NON-NLS-1$
455
out.write("</select>"); //$NON-NLS-1$
456
}
457             out.write("</span>"); //$NON-NLS-1$
458
out.write("</div>"); //$NON-NLS-1$
459
// #################
460
// END toolbar
461
// #################
462
// color palette
463
out
464                 .write("<div id=\"kupu-colorchooser\" style=\"position: fixed; border-style: solid; border-color: #666666; border-width: 1px;\"> </div>"); //$NON-NLS-1$
465
// #################
466
// iframe
467
// #################
468
out.write("<iframe id=\"" + this.getName() + "-kupu-editor\""); //$NON-NLS-1$ //$NON-NLS-2$
469
out.write(" class=\"" + CssConstants.CSSCLASS_RICHEIFRAME + "\""); //$NON-NLS-1$ //$NON-NLS-2$
470
if (this.getConfigValue("height", null) != null) { //$NON-NLS-1$
471
out.write(" style=\"height:" + this.getConfigValue("height") + ";\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
472
}
473             out.write(" frameborder=\"0\""); //$NON-NLS-1$
474
out.write(" SRC=\"" //$NON-NLS-1$
475
+ this.getRequest().getContextPath()
476                 + "/.magnolia/pages/richEIFrame.html?" //$NON-NLS-1$
477
+ SESSION_ATTRIBUTENAME_DIALOGOBJECT
478                 + "=" //$NON-NLS-1$
479
+ this.getConfigValue(SESSION_ATTRIBUTENAME_DIALOGOBJECT)
480                 + "&amp;mgnlCK=" //$NON-NLS-1$
481
+ new Date JavaDoc().getTime()
482                 + "\""); //$NON-NLS-1$
483
out.write(" reloadsrc=\"0\""); //$NON-NLS-1$
484
out.write(" usecss=\"1\""); //$NON-NLS-1$
485
out.write(" strict_output=\"1\""); //$NON-NLS-1$
486
out.write(" content_type=\"application/xhtml+xml\""); //$NON-NLS-1$
487
out.write(" scrolling=\"auto\""); //$NON-NLS-1$
488
out.write("></iframe>"); //$NON-NLS-1$
489
out.write("<script type=\"text/javascript\">"); //$NON-NLS-1$
490
out.write("mgnlRichEditors[mgnlRichEditors.length]='" + this.getName() + "';"); //$NON-NLS-1$ //$NON-NLS-2$
491
out.write("</script>"); //$NON-NLS-1$
492
// #################
493
// END iframe
494
// #################
495
// #################
496
// textarea to save data (data will be put into textarea on submit of form)
497
// #################
498
out.write("<div style=visibility:hidden;position:absolute;top:0px;left:-500px;>"); //$NON-NLS-1$
499
Edit hiddenTextarea = new Edit(this.getName(), StringUtils.EMPTY);
500             hiddenTextarea.setRows("5"); //$NON-NLS-1$
501
// special handling during saving
502
hiddenTextarea.setIsRichEditValue(ControlImpl.RICHEDIT_KUPU);
503             out.write(hiddenTextarea.getHtml());
504             out.write("</div>"); //$NON-NLS-1$
505

506         }
507         else {
508             // rich edit not supported: draw textarea
509
Edit control = new Edit(this.getName(), this.getValue());
510             control.setType(this.getConfigValue("type", PropertyType.TYPENAME_STRING)); //$NON-NLS-1$
511
if (this.getConfigValue("saveInfo").equals("false")) { //$NON-NLS-1$ //$NON-NLS-2$
512
control.setSaveInfo(false);
513             }
514             control.setCssClass(CssConstants.CSSCLASS_EDIT);
515             control.setRows(this.getConfigValue("rows", "18")); //$NON-NLS-1$ //$NON-NLS-2$
516
control.setCssStyles("width", this.getConfigValue("width", "100%")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
517

518             out.write(control.getHtml());
519
520         }
521         this.drawHtmlPost(out);
522     }
523
524     public void drawHtmlEditor(Writer JavaDoc out) throws IOException JavaDoc {
525
526         out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "); //$NON-NLS-1$
527
out.write(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); //$NON-NLS-1$
528

529         out.write("<html><head>"); //$NON-NLS-1$
530
// headers to prevent the browser from caching, these *must* be provided,
531
// either in meta-tag form or as HTTP headers
532
out.write("<meta http-equiv=\"Pragma\" content=\"no-cache\" />"); //$NON-NLS-1$
533
out.write("<meta http-equiv=\"Cache-Control\" content=\"no-cache, must-revalidate\" />"); //$NON-NLS-1$
534
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>"); //$NON-NLS-1$
535
out.write("<meta name=\"Effective_date\" content=\"None\" />"); //$NON-NLS-1$
536
out.write("<meta name=\"Expiration_date\" content=\"None\" />"); //$NON-NLS-1$
537
out.write("<meta name=\"Type\" content=\"Document\" />"); //$NON-NLS-1$
538
// out.write("<meta name=\"Format\" content=\"text/html\" />");
539
out.write("<meta name=\"Language\" content=\"\" />"); //$NON-NLS-1$
540
out.write("<meta name=\"Rights\" content=\"\" />"); //$NON-NLS-1$
541
out.write("<style type=\"text/css\">"); //$NON-NLS-1$
542
out.write("body {font-family:verdana;font-size:11px;background-color:#ffffff;}"); //$NON-NLS-1$
543
out.write("</style>"); //$NON-NLS-1$
544
if (this.getConfigValue("cssFile", null) != null) { //$NON-NLS-1$
545
out.write("<link HREF=\"" //$NON-NLS-1$
546
+ this.getConfigValue("cssFile") + "\" rel=\"stylesheet\" type=\"text/css\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
547
}
548         out.write("<script type=\"text/javascript\">\n"); //$NON-NLS-1$
549
out.write("document.insertText=function(value)\n"); //$NON-NLS-1$
550
out.write(" {\n"); //$NON-NLS-1$
551
out.write(" while (value.indexOf('\\n')!=-1)\n"); //$NON-NLS-1$
552
out.write(" {\n"); //$NON-NLS-1$
553
out.write(" value=value.replace('\\n','<br />');\n"); //$NON-NLS-1$
554
out.write(" }\n"); //$NON-NLS-1$
555
out.write(" var body=document.getElementsByTagName('body');\n"); //$NON-NLS-1$
556
out.write(" value=body[0].innerHTML+value;\n"); //$NON-NLS-1$
557
out.write(" body[0].innerHTML=value;\n"); //$NON-NLS-1$
558
out.write(" }\n"); //$NON-NLS-1$
559
out.write("</script>\n"); //$NON-NLS-1$
560
out.write("</head>\n"); //$NON-NLS-1$
561
out.write("<body>"); //$NON-NLS-1$
562
out.write(this.getValue());
563         out.write("</body></html>"); //$NON-NLS-1$
564

565     }
566
567     public String JavaDoc getValue(String JavaDoc lineBreak) {
568         String JavaDoc value = this.getValue();
569
570         if (value != null) {
571             return value.replaceAll("\n", "<br />"); //$NON-NLS-1$ //$NON-NLS-2$
572
}
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