KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > editors > htmlarea > CmsHtmlAreaEditor


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/editors/htmlarea/CmsHtmlAreaEditor.java,v $
3  * Date : $Date: 2006/03/27 14:52:59 $
4  * Version: $Revision: 1.3 $
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.htmlarea;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.OpenCms;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.workplace.editors.CmsEditorDisplayOptions;
38 import org.opencms.workplace.editors.CmsSimplePageEditor;
39 import org.opencms.workplace.galleries.A_CmsGallery;
40
41 import java.util.ArrayList JavaDoc;
42 import java.util.Collections JavaDoc;
43 import java.util.HashMap JavaDoc;
44 import java.util.Iterator JavaDoc;
45 import java.util.List JavaDoc;
46 import java.util.Map JavaDoc;
47 import java.util.Properties JavaDoc;
48
49 /**
50  * Creates the output for editing a page with the open source HtmlArea editor.<p>
51  *
52  * The following editor uses this class:
53  * <ul>
54  * <li>/editors/htmlarea/editor.jsp
55  * </ul>
56  * <p>
57  *
58  * @author Andreas Zahner
59  *
60  * @version $Revision: 1.3 $
61  *
62  * @since 6.0.1
63  */

64 public class CmsHtmlAreaEditor extends CmsSimplePageEditor {
65
66     /** Constant for the editor type, must be the same as the editors subfolder name in the VFS. */
67     private static final String JavaDoc EDITOR_TYPE = "htmlarea";
68    
69     /**
70      * Public constructor.<p>
71      *
72      * @param jsp an initialized JSP action element
73      */

74     public CmsHtmlAreaEditor(CmsJspActionElement jsp) {
75
76         super(jsp);
77     }
78
79     /**
80      * @see org.opencms.workplace.editors.CmsDefaultPageEditor#buildGalleryButtons(CmsEditorDisplayOptions, int, Properties)
81      */

82     public String JavaDoc buildGalleryButtons(CmsEditorDisplayOptions options, int buttonStyle, Properties JavaDoc displayOptions) {
83
84         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
85         Iterator JavaDoc i = OpenCms.getWorkplaceManager().getGalleries().keySet().iterator();
86         
87         while (i.hasNext()) {
88             String JavaDoc galleryType = (String JavaDoc)i.next();
89             String JavaDoc galleryName = CmsStringUtil.substitute(galleryType, "gallery", "");
90             if (options.showElement("gallery." + galleryName, displayOptions)) {
91                 // gallery is shown, create button code
92
result.append("config.registerButton(\"");
93                 result.append(galleryType);
94                 result.append("\", \"");
95                 result.append(key(org.opencms.workplace.editors.Messages.getGalleryKey(galleryName)));
96                 result.append("\", __editor.imgURL(\"../../editors/htmlarea/images/opencms/");
97                 result.append(galleryType);
98                 result.append(".gif\"), false, function(e) { openGallery(\'");
99                 result.append(galleryType);
100                 result.append("\'); });\n");
101             }
102         }
103    
104         return result.toString();
105     }
106     
107     /**
108      * Returns the configuration String for the gallery button row in HtmlArea.<p>
109      *
110      * @param options the display configuration for the editor
111      * @param displayOptions the display options for the editor
112      * @return the html String for the gallery buttons
113      */

114     public String JavaDoc buildGalleryButtonRow(CmsEditorDisplayOptions options, Properties JavaDoc displayOptions) {
115
116         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
117         Map JavaDoc galleryMap = OpenCms.getWorkplaceManager().getGalleries();
118         List JavaDoc galleries = new ArrayList JavaDoc(galleryMap.size());
119         Map JavaDoc typeMap = new HashMap JavaDoc(galleryMap.size());
120         
121         Iterator JavaDoc i = galleryMap.keySet().iterator();
122         while (i.hasNext()) {
123             String JavaDoc key = (String JavaDoc)i.next();
124             A_CmsGallery currGallery = (A_CmsGallery)galleryMap.get(key);
125             galleries.add(currGallery);
126             // put the type name to the type Map
127
typeMap.put(currGallery, key);
128         }
129         
130         // sort the found galleries by their order
131
Collections.sort(galleries);
132         
133         for (int k=0; k<galleries.size(); k++) {
134             A_CmsGallery currGallery = (A_CmsGallery)galleries.get(k);
135             String JavaDoc galleryType = (String JavaDoc)typeMap.get(currGallery);
136             if (options.showElement("gallery." + CmsStringUtil.substitute(galleryType, "gallery", ""), displayOptions)) {
137                 // gallery is shown, build row configuration String
138
if (result.length() == 0) {
139                     result.append(", \"separator\"");
140                 }
141                 result.append(", \"" + galleryType + "\"");
142             }
143         }
144         return result.toString();
145     }
146     
147     /**
148      * @see org.opencms.workplace.editors.CmsEditor#getEditorResourceUri()
149      */

150     public String JavaDoc getEditorResourceUri() {
151
152         return getSkinUri() + "editors/" + EDITOR_TYPE + "/";
153     }
154
155 }
156
Popular Tags