KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > content > editor > ContentEditorTag


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.taglib.core.content.editor;
17
18 import com.blandware.atleap.common.util.StringUtil;
19 import com.blandware.atleap.webapp.util.core.GlobalProperties;
20 import com.blandware.atleap.webapp.util.core.LocaleUtil;
21 import com.blandware.atleap.webapp.util.core.RequestUtil;
22 import com.blandware.atleap.webapp.util.core.WebappConstants;
23 import org.apache.commons.validator.GenericValidator;
24 import org.apache.struts.taglib.TagUtils;
25 import org.apache.struts.util.RequestUtils;
26
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.jsp.JspException JavaDoc;
29 import javax.servlet.jsp.PageContext JavaDoc;
30 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.io.StringWriter JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.Locale JavaDoc;
35 import java.util.Map JavaDoc;
36
37 /**
38  * <p>Renders WYSIWYG editor, currently FCKEditor or TinyMCE. That editor
39  * is assigned to be used to edit content of some field with complex formatting
40  * which is represented with HTML.
41  * </p>
42  * <p>
43  * Allowed attributes are:
44  * <ul>
45  * <li>
46  * <b>type</b> - "FCKEditor" or "TinyMCE". If not specified, or specified value
47  * is not one of these two values, then value of global property is checked.
48  * If it's still not one of them, "TinyMCE" is used.
49  * </li>
50  * <li>
51  * <b>id</b> - unique id of rendered editor
52  * </li>
53  * <li>
54  * <b>basePath</b> - directory where the FCKeditor files reside on the server
55  * (only for FCKEditor)
56  * </li>
57  * <li>
58  * <b>baseHref</b> - base HREF (value of attribute <code>href</code> of
59  * <code>base</code> tag in editor window)
60  * </li>
61  * <li>
62  * <b>defaultLanguage</b> - language to use to render editor (for localized
63  * interface and so on). For example, "en".
64  * </li>
65  * <li>
66  * <b>editorAreaLanguage</b> - language of currently rendered editor window.
67  * This language will be sent to link or image browser.
68  * </li>
69  * <li>
70  * <b>fullPage</b> - whether or not to render full page in editor window (with
71  * <code>html</code>, <code>head</code> and <code>body</code> tags)
72  * </li>
73  * <li>
74  * <b>editorAreaCss</b> - path to CSS-file to use in editor window. You may use
75  * reserved word 'no_stylesheet' to say that no CSS file must be used in editor
76  * window.
77  * </li>
78  * <li>
79  * <b>width</b> - width of editor window
80  * </li>
81  * <li>
82  * <b>height</b> - height of editor window
83  * </li>
84  * </ul>
85  * </p>
86  * <p><a HREF="ContentEditorTag.java.htm"><i>View Source</i></a></p>
87  *
88  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
89  * @version $Revision: 1.12 $ $Date: 2006/03/25 10:44:39 $
90  * @jsp.tag name="contentEditor"
91  * body-content="scriptless"
92  */

93 public class ContentEditorTag extends SimpleTagSupport JavaDoc {
94
95     // ~ Static fields/initializers
96

97     /**
98      * TinyMCE editor (<a HREF="http://tinymce.moxiecode.com/">http://tinymce.moxiecode.com/</a>)
99      */

100     public static final String JavaDoc EDITOR_TYPE_TINYMCE = "TinyMCE";
101
102     /**
103      * FCKEditor (<a HREF="http://fckeditor.net">http://fckeditor.net</a>)
104      */

105     public static final String JavaDoc EDITOR_TYPE_FCKEDITOR = "FCKEditor";
106
107     /**
108      * Keyword to determine that no CSS file must be used for content in editor window
109      */

110     public static final String JavaDoc EDITOR_AREA_CSS_NO_STYLESHEET = "no_stylesheet";
111
112     /**
113      * Context key under which count of already rendered TinyMCE editors is stored
114      */

115     public static final String JavaDoc TINY_MCE_COUNT_KEY = "com.blandware.atleap.webapp.taglib.core.content.editor.TINY_MCE_COUNT";
116
117     /**
118      * Context key under which count of already rendered FCK editors is stored
119      */

120     public static final String JavaDoc FCKEDITOR_COUNT_KEY = "com.blandware.atleap.webapp.taglib.core.content.editor.FCKEDITOR_COUNT";
121
122     /**
123      * Count of already rendered TinyMCE editors for internal use
124      */

125     protected int tinyMCECount = 0;
126
127     /**
128      * Type of editor to render
129      */

130     protected String JavaDoc type = null;
131
132     // ~ Instance variables
133

134     /**
135      * Unique ID of this editor
136      */

137     protected String JavaDoc id;
138
139     /**
140      * Dir where the FCKeditor files reside on the server
141      */

142     protected String JavaDoc basePath = null;
143
144     /**
145      * Language to use to render editor
146      */

147     protected String JavaDoc defaultLanguage;
148
149     /**
150      * Base HREF (value of attribute <code>href</code> of <code>base</code> tag in editor window)
151      */

152     protected String JavaDoc baseHref;
153
154     /**
155      * Language of currently rendered editor window. This language will be sent to link or image browser
156      */

157     protected String JavaDoc editorAreaLanguage;
158
159     /**
160      * Whether or not to render full page in editor window (with <code>html</code>, <code>head</code> and <code>body</code> tags)
161      */

162     protected Boolean JavaDoc fullPage;
163
164     /**
165      * Path to CSS-file to use in editor window. You may use reserved word 'no_stylesheet' to say that no CSS file must be used
166      * in editor window
167      */

168     protected String JavaDoc editorAreaCss;
169
170     /**
171      * Width of editor window
172      */

173     protected String JavaDoc width = null;
174
175     /**
176      * Height of editor window
177      */

178     protected String JavaDoc height = null;
179
180     /**
181      * Returns editor type
182      *
183      * @return editor type
184      * @jsp.attribute required="false"
185      * rtexprvalue="true"
186      * type="java.lang.String"
187      * description="Type of editor to render"
188      */

189     public String JavaDoc getType() {
190         return type;
191     }
192
193     /**
194      * Sets editor type
195      *
196      * @param type editor type to set
197      */

198     public void setType(String JavaDoc type) {
199         this.type = type;
200     }
201
202
203     /**
204      * Gets the unique id of the editor
205      *
206      * @return id
207      * @jsp.attribute required="true"
208      * rtexprvalue="true"
209      * type="java.lang.String"
210      * description="Unique id of the editor"
211      */

212     public String JavaDoc getId() {
213         return id;
214     }
215
216     /**
217      * Sets the unique id of the editor
218      *
219      * @param value name
220      */

221     public void setId(String JavaDoc value) {
222         id = value;
223     }
224
225     /**
226      * Gets the dir where the FCKeditor files reside on the server
227      *
228      * @return path
229      * @jsp.attribute required="false"
230      * rtexprvalue="true"
231      * type="java.lang.String"
232      * description="Dir where the FCKeditor files reside on the server"
233      */

234     public String JavaDoc getBasePath() {
235         return basePath;
236     }
237
238     /**
239      * Sets the dir where the FCKeditor files reside on the server
240      *
241      * @param value path
242      */

243     public void setBasePath(String JavaDoc value) {
244         basePath = value;
245     }
246
247     /**
248      * Returns default language
249      *
250      * @return default language
251      * @jsp.attribute required="false"
252      * rtexprvalue="true"
253      * type="java.lang.String"
254      * description="Language to use to render editor"
255      */

256     public String JavaDoc getDefaultLanguage() {
257         return defaultLanguage;
258     }
259
260     /**
261      * Sets default language
262      *
263      * @param defaultLanguage default language to set
264      */

265     public void setDefaultLanguage(String JavaDoc defaultLanguage) {
266         this.defaultLanguage = defaultLanguage;
267     }
268
269     /**
270      * Returns base href
271      *
272      * @return base href
273      * @see #baseHref
274      * @jsp.attribute required="false"
275      * rtexprvalue="true"
276      * type="java.lang.String"
277      * description="Base HREF (value of attribute 'href' of 'base' tag in editor window)"
278      */

279     public String JavaDoc getBaseHref() {
280         return baseHref;
281     }
282
283     /**
284      * Sets base href
285      *
286      * @param baseHref base href to set
287      * @see #baseHref
288      */

289     public void setBaseHref(String JavaDoc baseHref) {
290         this.baseHref = baseHref;
291     }
292
293     /**
294      * Returns editor area language
295      *
296      * @return editor area language
297      * @see #editorAreaLanguage
298      * @jsp.attribute required="false"
299      * rtexprvalue="true"
300      * type="java.lang.String"
301      * description="Language of currently rendered editor window. THis language will be sent to link or image browser"
302      */

303     public String JavaDoc getEditorAreaLanguage() {
304         return editorAreaLanguage;
305     }
306
307     /**
308      * Sets editor area language
309      *
310      * @param editorAreaLanguage editor area language to set
311      * @see #editorAreaLanguage
312      */

313     public void setEditorAreaLanguage(String JavaDoc editorAreaLanguage) {
314         this.editorAreaLanguage = editorAreaLanguage;
315     }
316
317     /**
318      * Returns whether or not to render full page in editor window
319      *
320      * @return whether or not to render full page in editor window
321      * @see #fullPage
322      * @jsp.attribute required="false"
323      * rtexprvalue="true"
324      * type="java.lang.Boolean"
325      * description="Whether or not to render full page in editor wndow"
326      */

327     public Boolean JavaDoc getFullPage() {
328         return fullPage;
329     }
330
331     /**
332      * Sets whether or not to render full page in editor window
333      *
334      * @param fullPage whether or not to render full page in editor window
335      * @see #fullPage
336      */

337     public void setFullPage(Boolean JavaDoc fullPage) {
338         this.fullPage = fullPage;
339     }
340
341     /**
342      * Returns editor area CSS
343      *
344      * @return editor area CSS
345      * @see #editorAreaCss
346      * @jsp.attribute required="false"
347      * rtexprvalue="true"
348      * type="java.lang.String"
349      * description="Path to CSS-file to use in editor window"
350      */

351     public String JavaDoc getEditorAreaCss() {
352         return editorAreaCss;
353     }
354
355     /**
356      * Sets editor area CSS
357      *
358      * @param editorAreaCss editor area CSS to set
359      * @see #editorAreaCss
360      */

361     public void setEditorAreaCss(String JavaDoc editorAreaCss) {
362         this.editorAreaCss = editorAreaCss;
363     }
364
365     /**
366      * Gets the width of the textarea
367      *
368      * @return width
369      * @jsp.attribute required="false"
370      * rtexprvalue="true"
371      * type="java.lang.String"
372      * description="Width of the textarea"
373      */

374     public String JavaDoc getWidth() {
375         return width;
376     }
377
378     /**
379      * Sets the width of the textarea
380      *
381      * @param value width
382      */

383     public void setWidth(String JavaDoc value) {
384         width = value;
385     }
386
387     /**
388      * Gets the height of the textarea
389      *
390      * @return height
391      * @jsp.attribute required="false"
392      * rtexprvalue="true"
393      * type="java.lang.String"
394      * description="Height of the textarea"
395      */

396     public String JavaDoc getHeight() {
397         return height;
398     }
399
400     /**
401      * Sets the height of the textarea
402      *
403      * @param value height
404      */

405     public void setHeight(String JavaDoc value) {
406         height = value;
407     }
408
409     /**
410      * Initializes the editor container and sets attributes
411      */

412     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
413
414         PageContext JavaDoc pageContext = (PageContext JavaDoc) getJspContext();
415         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
416
417         if ( !EDITOR_TYPE_FCKEDITOR.equalsIgnoreCase(type) && !EDITOR_TYPE_TINYMCE.equalsIgnoreCase(type) ) {
418             // get global property value
419
type = GlobalProperties.getInstance(pageContext.getServletContext()).getString(WebappConstants.GLOBAL_PROPERTY_WYSIWYG_EDITOR_TYPE, EDITOR_TYPE_TINYMCE);
420             if ( !EDITOR_TYPE_FCKEDITOR.equalsIgnoreCase(type) && !EDITOR_TYPE_TINYMCE.equalsIgnoreCase(type) ) {
421                 // default is TinyMCE
422
type = EDITOR_TYPE_TINYMCE;
423             }
424         }
425
426         // calculate counts
427
if ( EDITOR_TYPE_FCKEDITOR.equalsIgnoreCase(type) ) {
428             Integer JavaDoc tagNumber = (Integer JavaDoc) pageContext.getAttribute(FCKEDITOR_COUNT_KEY, PageContext.REQUEST_SCOPE);
429             if ( tagNumber == null ) {
430                 tagNumber = new Integer JavaDoc(0);
431             } else {
432                 tagNumber = new Integer JavaDoc(tagNumber.intValue() + 1);
433             }
434             pageContext.setAttribute(FCKEDITOR_COUNT_KEY, tagNumber, PageContext.REQUEST_SCOPE);
435         } else {
436             Integer JavaDoc tagNumber = (Integer JavaDoc) pageContext.getAttribute(TINY_MCE_COUNT_KEY, PageContext.REQUEST_SCOPE);
437             if ( tagNumber == null ) {
438                 tagNumber = new Integer JavaDoc(0);
439             } else {
440                 tagNumber = new Integer JavaDoc(tagNumber.intValue() + 1);
441             }
442             pageContext.setAttribute(TINY_MCE_COUNT_KEY, tagNumber, PageContext.REQUEST_SCOPE);
443             this.tinyMCECount = tagNumber.intValue();
444         }
445
446         // base path is used by FCKEditor only
447
if ( basePath == null ) {
448             basePath = ((HttpServletRequest JavaDoc) pageContext.getRequest()).getContextPath() + "/FCKeditor/";
449         }
450
451         // ensure, that default language is set
452
if ( GenericValidator.isBlankOrNull(defaultLanguage) ) {
453             Locale JavaDoc locale = RequestUtils.getUserLocale(request, null);
454             if ( locale == null ) {
455                 defaultLanguage = LocaleUtil.getInstance(pageContext.getServletContext()).getDefaultLocale().getIdentifier();
456             } else {
457                 defaultLanguage = locale.getLanguage();
458             }
459         }
460
461         // ensure that content css is set
462
if ( editorAreaCss == null ) {
463             editorAreaCss = request.getContextPath() + "/styles/core/core.css";
464         } else if ( EDITOR_AREA_CSS_NO_STYLESHEET.equalsIgnoreCase(editorAreaCss) ) {
465             editorAreaCss = "";
466         }
467
468         // set default width
469
if ( GenericValidator.isBlankOrNull(width) ) {
470             width = "100%";
471         }
472
473         // set default height
474
if ( GenericValidator.isBlankOrNull(height) ) {
475             height = "400px;";
476         }
477
478         StringWriter JavaDoc sw = new StringWriter JavaDoc();
479         getJspBody().invoke(sw);
480         String JavaDoc htmlCode = null;
481         if ( EDITOR_TYPE_FCKEDITOR.equalsIgnoreCase(type) ) {
482             htmlCode = createFCKEditorHTML(sw.toString());
483         } else {
484             htmlCode = createTinyMCEHTML(sw.toString());
485         }
486         TagUtils.getInstance().write(pageContext, htmlCode);
487     }
488
489     /**
490      * Returns <code>true</code> if editor is compatible with used user agent
491      *
492      * @return <code>true</code> if editor is compatible with used user agent
493      */

494     protected boolean isCompatible() {
495
496         PageContext JavaDoc pageContext = (PageContext JavaDoc) getJspContext();
497         String JavaDoc userAgent = ((HttpServletRequest JavaDoc) pageContext.getRequest()).getHeader("user-agent");
498         if ( userAgent == null ) {
499             return false;
500         } else {
501             userAgent = userAgent.toLowerCase();
502         }
503
504         boolean compatible = false;
505
506         // check according to type
507
if ( EDITOR_TYPE_FCKEDITOR.equalsIgnoreCase(type) ) {
508             if ( (userAgent.indexOf("msie") != -1) && (userAgent.indexOf("mac") == -1) && (userAgent.indexOf("opera") == -1) ) {
509                 if ( retrieveBrowserVersion(userAgent) >= 5.5 ) {
510                     compatible = true;
511                 }
512             } else if ( userAgent.indexOf("gecko") != -1 ) {
513                 if ( retrieveBrowserVersion(userAgent) >= 20030210 ) {
514                     compatible = true;
515                 }
516             }
517         } else {
518             if ( userAgent.indexOf("opera") != -1 ) {
519                 compatible = false;
520             } else if ( userAgent.indexOf("msie") != -1 ) {
521                 if ( retrieveBrowserVersion(userAgent) >= 5.5 ) {
522                     compatible = true;
523                 }
524             } else if ( userAgent.indexOf("gecko") != -1 ) {
525                 // todo: check version (what is the correct version)
526
compatible = true;
527             } else if ( userAgent.indexOf("mac") != -1 ) {
528                 compatible = true;
529             } else {
530                 compatible = false;
531             }
532         }
533
534         return compatible;
535     }
536
537     /**
538      * Retrieves browser version
539      *
540      * @param userAgent UserAgent string
541      * @return Browser version
542      */

543     protected double retrieveBrowserVersion(String JavaDoc userAgent) {
544         if ( userAgent.indexOf("msie") > -1 ) {
545             String JavaDoc str = userAgent.substring(userAgent.indexOf("msie") + 5);
546             return Double.parseDouble(str.substring(0, str.indexOf(";")));
547         } else {
548             String JavaDoc str = userAgent.substring(userAgent.indexOf("gecko") + 6);
549             return Double.parseDouble(str.substring(0, 8));
550         }
551     }
552
553
554     /**
555      * Generates the HTML Code for the FCK editor.
556      * <br />
557      * Evalutes the browser capabilities and generates the editor if IE 5.5 or Gecko 20030210 or greater,
558      * or a simple textarea otherwise.
559      *
560      * @param content Content of the editor window
561      * @return HTML code representing editor window
562      */

563     protected String JavaDoc createFCKEditorHTML(String JavaDoc content) {
564         StringBuffer JavaDoc strEditor = new StringBuffer JavaDoc();
565
566         strEditor.append("<div>");
567         content = StringUtil.htmlEncode(content);
568
569         if ( isCompatible() ) {
570
571             if ( content != null && content.trim().length() > 0 ) {
572                 strEditor.append("<input type=\"hidden\" id=\"" + id + "\" name=\"" + id + "\" value=\"" + content + "\">");
573             } else {
574                 strEditor.append("<input type=\"hidden\" id=\"" + id + "\" name=\"" + id + "\">");
575             }
576
577             strEditor.append(createFCKConfigHTML());
578             strEditor.append(createFCKIFrameHTML());
579
580         } else {
581             strEditor.append("<textarea name=\"" + id + "\" rows=\"4\" cols=\"40\" style=\"width: " + width + "; height: " + height + "\" wrap=\"virtual\">" + content + "</textarea>");
582         }
583         strEditor.append("</div>");
584         return strEditor.toString();
585     }
586
587     /**
588      * Collects all values and puts 'em into string. Creates <code>hidden</code> element which stores string.
589      *
590      * @return String representing HTML <code>hidden</code> element which stores configuration
591      */

592     protected String JavaDoc createFCKConfigHTML() {
593
594         // create config map
595
Map JavaDoc config = new HashMap JavaDoc();
596         config.put("DefaultLanguage", defaultLanguage);
597         config.put("BaseHref", baseHref);
598         config.put("EditorAreaLanguage", editorAreaLanguage);
599         config.put("FullPage", fullPage);
600         config.put("EditorAreaCss", editorAreaCss);
601
602         // create query string
603
String JavaDoc configStr = RequestUtil.createQueryStringFromMap(config, "&").toString();
604
605         return "<input type=\"hidden\" id=\"" + id + "___Config\" value=\"" + configStr + "\">";
606     }
607
608     /**
609      * Creates <code>iframe</code> element which is used to render editor window
610      *
611      * @return String representing <code>iframe</code> element used to render editor window
612      */

613     protected String JavaDoc createFCKIFrameHTML() {
614
615         String JavaDoc src = basePath + "editor/fckeditor.html?InstanceName=" + id;
616         src += "&Toolbar=Default";
617
618         StringBuffer JavaDoc iframe = new StringBuffer JavaDoc("<iframe");
619         iframe.append(" SRC=\"").append(src).append("\"");
620         iframe.append(" id=\"").append(id).append("\"");
621         iframe.append(" name=\"").append(id).append("\"");
622         StringBuffer JavaDoc style = new StringBuffer JavaDoc();
623         if ( !GenericValidator.isBlankOrNull(width) ) {
624             style.append(" width: ").append(width).append(";");
625         }
626         if ( !GenericValidator.isBlankOrNull(height) ) {
627             style.append(" height: ").append(height).append(";");
628         }
629         if ( style.length() > 0 ) {
630             iframe.append(" style=\"").append(style).append("\"");
631         }
632         iframe.append(" frameborder=\"no\"");
633         iframe.append(" scrolling=\"no\"");
634         iframe.append(">");
635         iframe.append("</iframe>");
636         return iframe.toString();
637
638     }
639
640     /**
641      * Creates TinyMCE editor window
642      *
643      * @param content Content of the editor window
644      * @return HTML code representing the editor window
645      */

646     protected String JavaDoc createTinyMCEHTML(String JavaDoc content) {
647         StringBuffer JavaDoc htmlCode = new StringBuffer JavaDoc();
648         if ( tinyMCECount == 0 ) {
649             htmlCode.append(createTinyMCEInitCode()).append("\n");
650         }
651
652         // add editor area language, if specified
653
StringBuffer JavaDoc languageScript = new StringBuffer JavaDoc("<script language=\"javascript\">");
654         languageScript.append("this.editorAreaLanguages[this.editorAreaLanguages.length] = ");
655         if ( !GenericValidator.isBlankOrNull(editorAreaLanguage) ) {
656             languageScript.append("\"").append(editorAreaLanguage).append("\"");
657         } else {
658             languageScript.append("null");
659         }
660         languageScript.append(";");
661         languageScript.append("</script>");
662
663         // insert textarea element
664
StringBuffer JavaDoc editor = new StringBuffer JavaDoc("<textarea");
665         editor.append(" id=\"").append(id).append("\"");
666         editor.append(" name=\"").append(id).append("\"");
667
668         StringBuffer JavaDoc style = new StringBuffer JavaDoc();
669         if ( !GenericValidator.isBlankOrNull(width) ) {
670             style.append(" width: ").append(width).append(";");
671         }
672         if ( !GenericValidator.isBlankOrNull(height) ) {
673             style.append(" height: ").append(height).append(";");
674         }
675         if ( style.length() > 0 ) {
676             editor.append(" style=\"").append(style).append("\"");
677         }
678         editor.append(" class=\"contentEditorInstance\"");
679         editor.append(">");
680
681         // append content
682
if ( content != null ) {
683             editor.append(content).append("\n");
684         }
685
686         // close textearea element
687
editor.append("</textarea>");
688
689         htmlCode.append(languageScript);
690         htmlCode.append(editor);
691
692         return htmlCode.toString();
693     }
694
695     /**
696      * Creates initialization code for TinyMCE
697      *
698      * @return String representing init code for Tiny MCE
699      */

700     protected StringBuffer JavaDoc createTinyMCEInitCode() {
701         StringBuffer JavaDoc initCode = new StringBuffer JavaDoc();
702         // This is done because in AtLeap UTF-8 is default while for TinyMCE
703
// cp1251 is default russian encoding
704
String JavaDoc language = "ru".equals(defaultLanguage) ? "ru_UTF-8" : defaultLanguage;
705
706         initCode.append("<script language=\"javascript\" type=\"text/javascript\">");
707         initCode.append("tinyMCE.init({");
708         initCode.append("theme : \"advanced\"");
709         initCode.append(", mode : \"specific_textareas\"");
710         initCode.append(", editor_selector : \"contentEditorInstance\"");
711         initCode.append(", dialog_type : \"window\"");
712         initCode.append(", remove_linebreaks : false");
713 // initCode.append(", preformatted : true");
714
initCode.append(", language : \"").append(language).append("\"");
715         initCode.append(", docs_language : \"").append(language).append("\"");
716         initCode.append(", content_css : \"").append(editorAreaCss.trim()).append("\"");
717         initCode.append(", plugins : \"table,save,advhr,advimage,advlink,emotions,iespell,preview,flash,searchreplace,print,contextmenu,paste,directionality,fullscreen\"");
718         initCode.append(", theme_advanced_buttons1_add_before : \"save,separator\"");
719         initCode.append(", theme_advanced_buttons1_add : \"fontselect,fontsizeselect\"");
720         initCode.append(", theme_advanced_buttons2_add : \"separator,preview,separator,forecolor,backcolor\"");
721         initCode.append(", theme_advanced_buttons2_add_before: \"cut,copy,paste,pastetext,pasteword,separator,search,replace,separator\"");
722         initCode.append(", theme_advanced_buttons3_add_before : \"tablecontrols,separator\"");
723         initCode.append(", theme_advanced_buttons3_add : \"emotions,iespell,flash,advhr,separator,print,separator,ltr,rtl,separator,fullscreen\"");
724         initCode.append(", theme_advanced_toolbar_location : \"top\"");
725         initCode.append(", theme_advanced_toolbar_align : \"left\"");
726         initCode.append(", theme_advanced_path_location : \"bottom\"");
727         initCode.append(", extended_valid_elements : \"a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]\"");
728         initCode.append(", file_browser_callback : \"tinyMCEBrowserCallBack\"");
729         initCode.append(", init_instance_callback : \"tinyMCEInitInstanceCallBack\"");
730         if ( !GenericValidator.isBlankOrNull(baseHref) ) {
731             initCode.append(", relative_urls : true");
732             initCode.append(", document_base_url : \"").append(baseHref).append("\"");
733         }
734         initCode.append(", apply_source_formatting : true");
735         initCode.append("});");
736
737         if ( !GenericValidator.isBlankOrNull(editorAreaLanguage) ) {
738             initCode.append("this.editorAreaLanguages = new Array();");
739         }
740
741         initCode.append("</script>");
742
743         return initCode;
744     }
745 }
746
Popular Tags