KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > editors > fckeditor > CmsFCKEditor


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/editors/fckeditor/CmsFCKEditor.java,v $
3  * Date : $Date: 2006/03/27 14:53:05 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.editors.fckeditor;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.OpenCms;
36 import org.opencms.util.CmsHtmlConverter;
37 import org.opencms.util.CmsStringUtil;
38 import org.opencms.workplace.CmsWorkplaceSettings;
39 import org.opencms.workplace.editors.CmsEditorDisplayOptions;
40 import org.opencms.workplace.editors.CmsSimplePageEditor;
41 import org.opencms.workplace.galleries.A_CmsGallery;
42
43 import java.util.ArrayList JavaDoc;
44 import java.util.Collections JavaDoc;
45 import java.util.HashMap JavaDoc;
46 import java.util.Iterator JavaDoc;
47 import java.util.List JavaDoc;
48 import java.util.Map JavaDoc;
49 import java.util.Properties JavaDoc;
50
51 import javax.servlet.http.HttpServletRequest JavaDoc;
52
53 /**
54  * Creates the output for editing a page with the open source FCKeditor editor.<p>
55  *
56  * This editor supports user defined styles. To show these styles, a plain text file containing the style definition
57  * XML code has to be placed in the same folder where the template CSS style sheet is located.<br>
58  * The file name has to be exactly like the file name of the CSS with the suffix <code>_style.xml</code> added.
59  * E.g. for the CSS file <code>style.css</code> the style definition file
60  * has to be named <code>style.css_style.xml</code>.<p>
61  *
62  * An example for a style XML can be found
63  * in the VFS file <code>/system/workplace/resources/editors/fckeditor/fckstyles.xml</code>.<p>
64  *
65  * The following editor uses this class:
66  * <ul>
67  * <li>/editors/fckeditor/editor.jsp
68  * </ul>
69  * <p>
70  *
71  * @author Andreas Zahner
72  *
73  * @version $Revision: 1.2 $
74  *
75  * @since 6.1.7
76  */

77 public class CmsFCKEditor extends CmsSimplePageEditor {
78     
79     /** Suffix for the style XML file that is added to the used template CSS style sheet file name. */
80     public static final String JavaDoc SUFFIX_STYLESXML = "_style.xml";
81
82     /** Constant for the editor type, must be the same as the editors subfolder name in the VFS. */
83     private static final String JavaDoc EDITOR_TYPE = "fckeditor";
84
85     /**
86      * Public constructor.<p>
87      *
88      * @param jsp an initialized JSP action element
89      */

90     public CmsFCKEditor(CmsJspActionElement jsp) {
91
92         super(jsp);
93     }
94
95     /**
96      * Returns the configuration String for the gallery button row in the FCKeditor.<p>
97      *
98      * @param options the display configuration for the editor
99      * @param displayOptions the display options for the editor
100      * @return the html String for the gallery buttons
101      */

102     public String JavaDoc buildGalleryButtonRow(CmsEditorDisplayOptions options, Properties JavaDoc displayOptions) {
103
104         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
105         Map JavaDoc galleryMap = OpenCms.getWorkplaceManager().getGalleries();
106         List JavaDoc galleries = new ArrayList JavaDoc(galleryMap.size());
107         Map JavaDoc typeMap = new HashMap JavaDoc(galleryMap.size());
108
109         Iterator JavaDoc i = galleryMap.keySet().iterator();
110         while (i.hasNext()) {
111             String JavaDoc key = (String JavaDoc)i.next();
112             A_CmsGallery currGallery = (A_CmsGallery)galleryMap.get(key);
113             galleries.add(currGallery);
114             // put the type name to the type Map
115
typeMap.put(currGallery, key);
116         }
117
118         // sort the found galleries by their order
119
Collections.sort(galleries);
120
121         for (int k = 0; k < galleries.size(); k++) {
122             A_CmsGallery currGallery = (A_CmsGallery)galleries.get(k);
123             String JavaDoc galleryType = (String JavaDoc)typeMap.get(currGallery);
124             if (options.showElement("gallery." + CmsStringUtil.substitute(galleryType, "gallery", ""), displayOptions)) {
125                 // gallery is shown, build row configuration String
126
if (result.length() == 0) {
127                     result.append(", \'-\'");
128                 }
129                 result.append(", \'oc-" + galleryType + "\'");
130             }
131         }
132         return result.toString();
133     }
134
135     /**
136      * @see org.opencms.workplace.editors.CmsDefaultPageEditor#buildGalleryButtons(CmsEditorDisplayOptions, int, Properties)
137      */

138     public String JavaDoc buildGalleryButtons(CmsEditorDisplayOptions options, int buttonStyle, Properties JavaDoc displayOptions) {
139
140         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
141         Iterator JavaDoc i = OpenCms.getWorkplaceManager().getGalleries().keySet().iterator();
142
143         while (i.hasNext()) {
144             String JavaDoc galleryType = (String JavaDoc)i.next();
145             String JavaDoc galleryName = CmsStringUtil.substitute(galleryType, "gallery", "");
146
147             result.append("\n\nvar ").append(galleryType).append("Command = function() { this.Name = \"").append(
148                 galleryType).append("\"; }\n");
149             result.append(galleryType).append("Command.prototype.GetState = function() { return FCK_TRISTATE_OFF ; }\n");
150             result.append(galleryType).append("Command.prototype.Execute = function() {\n");
151             result.append("\topenGallery(\"").append(galleryType).append("\");\n");
152
153             result.append("}\n");
154             result.append("FCKCommands.RegisterCommand(\"oc-").append(galleryType).append("\", new ").append(
155                 galleryType).append("Command());\n");
156             result.append("FCKToolbarItems.RegisterItem(\"oc-").append(galleryType).append("\", ");
157             result.append("new FCKToolbarButton(\"oc-").append(galleryType).append("\", \"");
158             result.append(key(org.opencms.workplace.editors.Messages.getGalleryKey(galleryName))).append("\"));");
159         }
160
161         return result.toString();
162     }
163
164     /**
165      * @see org.opencms.workplace.editors.CmsEditor#getEditorResourceUri()
166      */

167     public String JavaDoc getEditorResourceUri() {
168
169         return getSkinUri() + "editors/" + EDITOR_TYPE + "/";
170     }
171
172     /**
173      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
174      */

175     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
176
177         if (CmsStringUtil.isNotEmpty(request.getParameter(PARAM_RESOURCE))) {
178             super.initWorkplaceRequestValues(settings, request);
179         }
180     }
181
182     /**
183      * @see org.opencms.workplace.editors.CmsSimplePageEditor#prepareContent(boolean)
184      */

185     protected String JavaDoc prepareContent(boolean save) {
186
187         if (save) {
188             String JavaDoc conversionSetting = CmsHtmlConverter.getConversionSettings(getCms(), m_file);
189             if (CmsStringUtil.isEmptyOrWhitespaceOnly(conversionSetting)) {
190                 // by default we want to pretty-print and Xhtml format when saving the content in FCKeditor
191
String JavaDoc content = getParamContent();
192                 CmsHtmlConverter converter = new CmsHtmlConverter(getEncoding(), CmsHtmlConverter.PARAM_XHTML);
193                 content = converter.convertToStringSilent(content);
194                 setParamContent(content);
195             }
196         }
197         // do further processing with super class
198
return super.prepareContent(true);
199     }
200 }
Popular Tags