KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/galleries/CmsLinkGallery.java,v $
3  * Date : $Date: 2006/03/27 14:52:54 $
4  * Version: $Revision: 1.22 $
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.CmsPropertyDefinition;
36 import org.opencms.file.CmsResource;
37 import org.opencms.file.types.CmsResourceTypePointer;
38 import org.opencms.jsp.CmsJspActionElement;
39 import org.opencms.main.CmsException;
40 import org.opencms.main.CmsLog;
41 import org.opencms.main.OpenCms;
42 import org.opencms.util.CmsStringUtil;
43 import org.opencms.workplace.explorer.CmsNewResource;
44 import org.opencms.workplace.explorer.CmsNewResourceUpload;
45
46 import java.util.ArrayList JavaDoc;
47 import java.util.Iterator JavaDoc;
48 import java.util.List JavaDoc;
49
50 import javax.servlet.http.HttpServletRequest JavaDoc;
51 import javax.servlet.http.HttpServletResponse JavaDoc;
52 import javax.servlet.jsp.PageContext JavaDoc;
53
54 import org.apache.commons.logging.Log;
55
56 /**
57  * Generates the links gallery popup window which can be used in editors or as a dialog widget.<p>
58  *
59  * The following files use this class:
60  * <ul>
61  * <li>/commons/galeries/download_fs.jsp
62  * </ul>
63  * <p>
64  *
65  * @author Armen Markarian
66  *
67  * @version $Revision: 1.22 $
68  *
69  * @since 6.0.0
70  */

71 public class CmsLinkGallery extends A_CmsGallery {
72
73     /** URI of the image gallery popup dialog. */
74     public static final String JavaDoc URI_GALLERY = PATH_GALLERIES + "link_fs.jsp";
75
76     /** The log object for this class. */
77     private static final Log LOG = CmsLog.getLog(CmsLinkGallery.class);
78
79     /** The order value of the gallery for sorting the galleries. */
80     private static final Integer JavaDoc ORDER_GALLERY = new Integer JavaDoc(30);
81
82     /**
83      * Public empty constructor, required for {@link A_CmsGallery#createInstance(String, CmsJspActionElement)}.<p>
84      */

85     public CmsLinkGallery() {
86
87         // noop
88
}
89
90     /**
91      * Public constructor with JSP action element.<p>
92      *
93      * @param jsp an initialized JSP action element
94      */

95     public CmsLinkGallery(CmsJspActionElement jsp) {
96
97         super(jsp);
98     }
99
100     /**
101      * Public constructor with JSP variables.<p>
102      *
103      * @param context the JSP page context
104      * @param req the JSP request
105      * @param res the JSP response
106      */

107     public CmsLinkGallery(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
108
109         this(new CmsJspActionElement(context, req, res));
110     }
111
112     /**
113      * @see org.opencms.workplace.galleries.A_CmsGallery#applyButton()
114      */

115     public String JavaDoc applyButton() {
116
117         if (MODE_VIEW.equals(getParamDialogMode())) {
118             // in view mode, generate disabled button
119
return button(null, null, "apply_in.png", Messages.GUI_BUTTON_PASTE_0, 0);
120         } else {
121             String JavaDoc uri = getParamResourcePath();
122             if (MODE_WIDGET.equals(getParamDialogMode())) {
123                 // get real link target in widget mode from file content
124
try {
125                     CmsResource res = getCms().readResource(getParamResourcePath());
126                     uri = new String JavaDoc(CmsFile.upgrade(res, getCms()).getContents());
127                 } catch (CmsException e) {
128                     // this should never happen
129
LOG.error(e);
130                 }
131             } else {
132                 // in editor mode, create a valid link from resource path
133
uri = getJsp().link(uri);
134             }
135
136             return button(
137                 "javascript:link('" + uri + "',document.form.title.value, document.form.title.value);",
138                 null,
139                 "apply.png",
140                 Messages.GUI_BUTTON_PASTE_0,
141                 0);
142         }
143     }
144
145     /**
146      * Builds the html String for the preview frame.<p>
147      *
148      * @return the html String for the preview frame
149      */

150     public String JavaDoc buildGalleryItemPreview() {
151
152         StringBuffer JavaDoc html = new StringBuffer JavaDoc(32);
153         try {
154             if (CmsStringUtil.isNotEmpty(getParamResourcePath())) {
155                 CmsResource res = getCms().readResource(getParamResourcePath());
156                 if (res != null) {
157                     // file target
158
String JavaDoc pointer = new String JavaDoc(CmsFile.upgrade(res, getCms()).getContents());
159                     if (CmsStringUtil.isEmptyOrWhitespaceOnly(pointer)) {
160                         pointer = getJsp().link(getCms().getSitePath(res));
161                     }
162                     String JavaDoc title = getPropertyValue(res, CmsPropertyDefinition.PROPERTY_TITLE);
163                     String JavaDoc description = getJsp().property(
164                         CmsPropertyDefinition.PROPERTY_DESCRIPTION,
165                         getParamResourcePath());
166                     String JavaDoc keywords = getJsp().property(CmsPropertyDefinition.PROPERTY_KEYWORDS, getParamResourcePath());
167                     String JavaDoc lastmodified = getMessages().getDateTime(res.getDateLastModified());
168                     html.append("<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" style=\"align: middle; width:100%; background-color: ThreeDFace; margin: 0;\">");
169                     html.append("<tr align=\"left\">");
170                     html.append("<td width=\"35%\"><b>");
171                     html.append(key(Messages.GUI_INPUT_LINKTO_0));
172                     html.append("</b></td>");
173                     html.append("<td width=\"65%\"><a HREF=\"#\" onclick=\"");
174                     html.append("javascript:window.open('");
175                     html.append(getJsp().link(getCms().getSitePath(res)));
176                     html.append("','_preview','')");
177                     html.append("\">");
178                     html.append(pointer);
179                     html.append("</a></td>");
180                     // file name
181
html.append(previewRow(key(Messages.GUI_LABEL_NAME_0), res.getName()));
182                     // file title
183
html.append(previewRow(key(Messages.GUI_INPUT_TITLE_0), title));
184                     // file last modified date
185
html.append(previewRow(key(Messages.GUI_INPUT_DATELASTMODIFIED_0), lastmodified));
186                     // file description if existing
187
if (CmsStringUtil.isNotEmpty(description)) {
188                         html.append(previewRow(key(Messages.GUI_INPUT_DESCRIPTION_0), description));
189                     }
190                     // file keywords if existing
191
if (CmsStringUtil.isNotEmpty(keywords)) {
192                         html.append(previewRow(key(Messages.GUI_INPUT_KEYWORDS_0), keywords));
193                     }
194                     html.append("</table>");
195                 }
196             }
197         } catch (CmsException e) {
198             // reading the resource or property value failed
199
LOG.error(e);
200         }
201         return html.toString();
202     }
203
204     /**
205      * @see org.opencms.workplace.galleries.A_CmsGallery#getGalleryItemsTypeId()
206      */

207     public int getGalleryItemsTypeId() {
208
209         return CmsResourceTypePointer.getStaticTypeId();
210     }
211
212     /**
213      * @see org.opencms.workplace.galleries.A_CmsGallery#getHeadFrameSetHeight()
214      */

215     public String JavaDoc getHeadFrameSetHeight() {
216
217         return "450";
218     }
219
220     /**
221      * Returns the order of the implemented gallery, used to sort the gallery buttons in the editors.<p>
222      *
223      * @return the order of the implemented gallery
224      */

225     public Integer JavaDoc getOrder() {
226
227         return ORDER_GALLERY;
228     }
229
230     /**
231      * Returns the url for the new CmsResourceTypePointer dialog.<p>
232      *
233      * @return the url for the wizard dialog
234      */

235     public String JavaDoc getWizardUrl() {
236
237         StringBuffer JavaDoc wizardUrl = new StringBuffer JavaDoc(8);
238         wizardUrl.append(getJsp().link(
239             PATH_DIALOGS
240                 + OpenCms.getWorkplaceManager().getExplorerTypeSetting(CmsResourceTypePointer.getStaticTypeName()).getNewResourceUri()));
241         wizardUrl.append("?action=newform&");
242         wizardUrl.append(CmsNewResourceUpload.PARAM_REDIRECTURL);
243         wizardUrl.append("=");
244         wizardUrl.append(PATH_GALLERIES);
245         wizardUrl.append("gallery_list.jsp&");
246         wizardUrl.append(CmsNewResourceUpload.PARAM_TARGETFRAME);
247         wizardUrl.append("=gallery_list&");
248         wizardUrl.append(CmsNewResource.PARAM_CURRENTFOLDER);
249         wizardUrl.append("=");
250
251         return wizardUrl.toString();
252     }
253
254     /**
255      * @see org.opencms.workplace.galleries.A_CmsGallery#wizardButton()
256      */

257     public String JavaDoc wizardButton() {
258
259         return button("javascript:wizard();", null, "upload.png", Messages.GUI_TITLE_NEW_0, 0);
260     }
261
262     /**
263      * @see org.opencms.workplace.galleries.A_CmsGallery#buildGalleryItemListCustomEndCols(org.opencms.file.CmsResource, java.lang.String)
264      */

265     protected String JavaDoc buildGalleryItemListCustomEndCols(CmsResource res, String JavaDoc tdClass) {
266
267         StringBuffer JavaDoc result = new StringBuffer JavaDoc(64);
268         result.append("\t<td class=\"");
269         result.append(tdClass);
270         result.append("\">");
271         String JavaDoc linkTarget;
272         try {
273             CmsFile file = CmsFile.upgrade(res, getCms());
274             linkTarget = new String JavaDoc(file.getContents());
275         } catch (CmsException e) {
276             linkTarget = "";
277         }
278         result.append(linkTarget);
279         result.append("</td>\n");
280         return result.toString();
281     }
282
283     /**
284      * @see org.opencms.workplace.galleries.A_CmsGallery#buildGalleryItemListHeadline()
285      */

286     protected String JavaDoc buildGalleryItemListHeadline() {
287
288         StringBuffer JavaDoc headline = new StringBuffer JavaDoc(16);
289         headline.append("<tr>");
290         headline.append("<td class=\"headline\">&nbsp;</td>");
291         headline.append("<td class=\"headline\" width=\"25%\">");
292         headline.append(key(Messages.GUI_LABEL_NAME_0));
293         headline.append("</td>");
294         headline.append("<td class=\"headline\" width=\"45%\">");
295         headline.append(key(Messages.GUI_LABEL_TITLE_0));
296         headline.append("</td>");
297         headline.append("<td class=\"headline\" width=\"30%\">");
298         headline.append(key(Messages.GUI_INPUT_LINKTO_0));
299         headline.append("</td>");
300         headline.append("</tr>");
301
302         return headline.toString();
303     }
304
305     /**
306      * Returns a list of hit items.<p>
307      *
308      * Searches by the title property value, resource name and stored external link.<p>
309      *
310      * @param items a list of resource items
311      * @return a list of hit items
312      */

313     protected List JavaDoc getSearchHits(List JavaDoc items) {
314
315         String JavaDoc searchword = getParamSearchWord().toLowerCase();
316         List JavaDoc hitlist = new ArrayList JavaDoc();
317         if (items != null) {
318             Iterator JavaDoc i = items.iterator();
319             while (i.hasNext()) {
320                 try {
321                     CmsResource res = (CmsResource)i.next();
322                     String JavaDoc resname = res.getName().toLowerCase();
323                     String JavaDoc restitle = getJsp().property(
324                         CmsPropertyDefinition.PROPERTY_TITLE,
325                         getCms().getSitePath(res),
326                         resname).toLowerCase();
327                     // get the link
328
CmsFile file = CmsFile.upgrade(res, getCms());
329                     String JavaDoc link = new String JavaDoc(file.getContents()).toLowerCase();
330
331                     if (restitle.indexOf(searchword) != -1
332                         || resname.indexOf(searchword) != -1
333                         || link.indexOf(searchword) != -1) {
334                         // add this resource to the hitlist
335
hitlist.add(res);
336                     }
337                 } catch (CmsException e) {
338                     // this should never happen, but in case it does, skip this resource
339
}
340             }
341         }
342
343         return hitlist;
344     }
345 }
Popular Tags