KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > galleries > CmsHtmlGallery


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/galleries/CmsHtmlGallery.java,v $
3  * Date : $Date: 2006/05/19 08:34:50 $
4  * Version: $Revision: 1.18 $
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.workplace.galleries;
33
34 import org.opencms.file.CmsFile;
35 import org.opencms.file.CmsResource;
36 import org.opencms.file.types.CmsResourceTypePlain;
37 import org.opencms.i18n.CmsEncoder;
38 import org.opencms.jsp.CmsJspActionElement;
39 import org.opencms.main.CmsException;
40 import org.opencms.main.CmsLog;
41 import org.opencms.util.CmsStringUtil;
42
43 import javax.servlet.http.HttpServletRequest JavaDoc;
44 import javax.servlet.http.HttpServletResponse JavaDoc;
45 import javax.servlet.jsp.PageContext JavaDoc;
46
47 import org.apache.commons.logging.Log;
48
49 /**
50  * Generates the html gallery popup window which can be used in editors or as a dialog widget.<p>
51  *
52  * @author Armen Markarian
53  * @author Andreas Zahner
54  *
55  * @version $Revision: 1.18 $
56  *
57  * @since 6.0.0
58  */

59 public class CmsHtmlGallery extends A_CmsGallery {
60
61     /** URI of the image gallery popup dialog. */
62     public static final String JavaDoc URI_GALLERY = PATH_GALLERIES + "html_fs.jsp";
63
64     /** The log object for this class. */
65     private static final Log LOG = CmsLog.getLog(CmsHtmlGallery.class);
66
67     /** The order value of the gallery for sorting the galleries. */
68     private static final Integer JavaDoc ORDER_GALLERY = new Integer JavaDoc(40);
69
70     /**
71      * Public empty constructor, required for {@link A_CmsGallery#createInstance(String, CmsJspActionElement)}.<p>
72      */

73     public CmsHtmlGallery() {
74
75         // noop
76
}
77
78     /**
79      * Public constructor with JSP action element.<p>
80      *
81      * @param jsp an initialized JSP action element
82      */

83     public CmsHtmlGallery(CmsJspActionElement jsp) {
84
85         super(jsp);
86     }
87
88     /**
89      * Public constructor with JSP variables.<p>
90      *
91      * @param context the JSP page context
92      * @param req the JSP request
93      * @param res the JSP response
94      */

95     public CmsHtmlGallery(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
96
97         this(new CmsJspActionElement(context, req, res));
98     }
99
100     /**
101      * Generates the apply button and distinguishes between the different gallery modes.<p>
102      *
103      * @see org.opencms.workplace.galleries.A_CmsGallery#applyButton()
104      */

105     public String JavaDoc applyButton() {
106
107         if (MODE_VIEW.equals(getParamDialogMode())) {
108             // in view mode, generate disabled button
109
return button(null, null, "apply_in.png", "button.paste", 0);
110         } else if (MODE_WIDGET.equals(getParamDialogMode())) {
111             // in widget mode, get file content to apply to input field
112
String JavaDoc content = "";
113             try {
114                 CmsResource res = getCms().readResource(getParamResourcePath());
115                 CmsFile file = getCms().readFile(getCms().getSitePath(res));
116                 content = new String JavaDoc(file.getContents());
117                 // prepare the content for javascript usage
118
content = CmsStringUtil.escapeJavaScript(content);
119             } catch (CmsException e) {
120                 // this should never happen
121
if (LOG.isErrorEnabled()) {
122                     LOG.error(org.opencms.db.Messages.get().getBundle().key(
123                         org.opencms.db.Messages.ERR_READ_RESOURCE_1,
124                         getParamResourcePath()));
125                 }
126             }
127             content = CmsEncoder.escapeXml(content);
128             // use javascript function call with content as parameter
129
return button("javascript:pasteContent('" + content + "')", null, "apply.png", Messages.GUI_BUTTON_PASTE_0, 0);
130         } else {
131             // in editor mode, use simple javascript function call
132
return button("javascript:pasteContent()", null, "apply.png", Messages.GUI_BUTTON_PASTE_0, 0);
133         }
134     }
135
136     /**
137      * Builds the html String for the preview frame.<p>
138      *
139      * @return the html String for the preview frame
140      */

141     public String JavaDoc buildGalleryItemPreview() {
142
143         StringBuffer JavaDoc html = new StringBuffer JavaDoc(16);
144         try {
145             if (CmsStringUtil.isNotEmpty(getParamResourcePath())) {
146                 CmsResource res = getCms().readResource(getParamResourcePath());
147                 if (res != null) {
148                     html.append("<p><div id=\"icontent\" width=\"100%\" height=\"100%\">");
149                     html.append(getJsp().getContent(getParamResourcePath()));
150                     html.append("</div></p>");
151                 }
152             }
153         } catch (CmsException e) {
154             // reading the resource failed
155
LOG.error(e);
156         }
157         return html.toString();
158     }
159
160     /**
161      * @see org.opencms.workplace.galleries.A_CmsGallery#getGalleryItemsTypeId()
162      */

163     public int getGalleryItemsTypeId() {
164
165         return CmsResourceTypePlain.getStaticTypeId();
166     }
167
168     /**
169      * Returns the order of the implemented gallery, used to sort the gallery buttons in the editors.<p>
170      *
171      * @return the order of the implemented gallery
172      */

173     public Integer JavaDoc getOrder() {
174
175         return ORDER_GALLERY;
176     }
177
178     /**
179      * @see org.opencms.workplace.galleries.A_CmsGallery#getPreviewBodyStyle()
180      */

181     public String JavaDoc getPreviewBodyStyle() {
182
183         return new String JavaDoc(" class=\"dialog\" unselectable=\"on\"");
184     }
185
186     /**
187      * @see org.opencms.workplace.galleries.A_CmsGallery#getPreviewDivStyle()
188      */

189     public String JavaDoc getPreviewDivStyle() {
190
191         return new String JavaDoc("style=\"width: 100%; margin-top: 5px\"");
192     }
193
194     /**
195      * @see org.opencms.workplace.galleries.A_CmsGallery#previewButton()
196      */

197     public String JavaDoc previewButton() {
198
199         return "";
200     }
201
202     /**
203      * @see org.opencms.workplace.galleries.A_CmsGallery#targetSelectBox()
204      */

205     public String JavaDoc targetSelectBox() {
206
207         return "";
208     }
209 }
Popular Tags