KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/galleries/A_CmsGallery.java,v $
3  * Date : $Date: 2006/05/19 08:34:50 $
4  * Version: $Revision: 1.25 $
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.CmsProperty;
35 import org.opencms.file.CmsPropertyDefinition;
36 import org.opencms.file.CmsResource;
37 import org.opencms.file.CmsResourceFilter;
38 import org.opencms.file.types.CmsResourceTypeFolderExtended;
39 import org.opencms.i18n.CmsEncoder;
40 import org.opencms.i18n.CmsMessageContainer;
41 import org.opencms.jsp.CmsJspActionElement;
42 import org.opencms.loader.CmsLoaderException;
43 import org.opencms.lock.CmsLock;
44 import org.opencms.main.CmsException;
45 import org.opencms.main.CmsLog;
46 import org.opencms.main.CmsRuntimeException;
47 import org.opencms.main.OpenCms;
48 import org.opencms.security.CmsPermissionSet;
49 import org.opencms.util.CmsStringUtil;
50 import org.opencms.workplace.CmsDialog;
51 import org.opencms.workplace.CmsWorkplace;
52 import org.opencms.workplace.CmsWorkplaceManager;
53 import org.opencms.workplace.CmsWorkplaceSettings;
54 import org.opencms.workplace.explorer.CmsNewResource;
55 import org.opencms.workplace.explorer.CmsNewResourceUpload;
56
57 import java.util.ArrayList JavaDoc;
58 import java.util.Iterator JavaDoc;
59 import java.util.List JavaDoc;
60 import java.util.Map JavaDoc;
61 import java.util.TreeMap JavaDoc;
62
63 import javax.servlet.http.HttpServletRequest JavaDoc;
64 import javax.servlet.http.HttpSession JavaDoc;
65
66 import org.apache.commons.logging.Log;
67
68 /**
69  * Provides constants, members and methods to generate a gallery popup window usable in editors or as widget.<p>
70  *
71  * Extend this class for every gallery type (e.g. image gallery) to build.<p>
72  *
73  * @author Andreas Zahner
74  * @author Armen Markarian
75  *
76  * @version $Revision: 1.25 $
77  *
78  * @since 6.0.0
79  */

80 public abstract class A_CmsGallery extends CmsDialog implements Comparable JavaDoc {
81
82     /** Value for the action: delete the gallery item. */
83     public static final int ACTION_DELETE = 101;
84
85     /** Value for the action: list gallery items. */
86     public static final int ACTION_LIST = 102;
87
88     /** Value for the action: search gallery items. */
89     public static final int ACTION_SEARCH = 103;
90
91     /** Value for the action: upload a new gallery item. */
92     public static final int ACTION_UPLOAD = 104;
93
94     /** The CSS filename used in the galleries. */
95     public static final String JavaDoc CSS_FILENAME = "gallery.css";
96
97     /** Request parameter value for the action: delete the gallery item. */
98     public static final String JavaDoc DIALOG_DELETE = "delete";
99
100     /** Request parameter value for the action: edit property value. */
101     public static final String JavaDoc DIALOG_EDITPROPERTY = "editproperty";
102
103     /** Request parameter value for the action: list gallery items. */
104     public static final String JavaDoc DIALOG_LIST = "list";
105
106     /** Request parameter value for the action: search gallery items. */
107     public static final String JavaDoc DIALOG_SEARCH = "search";
108
109     /** The dialog type. */
110     public static final String JavaDoc DIALOG_TYPE = "gallery";
111
112     /** Request parameter value for the action: upload a new gallery item. */
113     public static final String JavaDoc DIALOG_UPLOAD = "upload";
114
115     /** Request parameter value for the dialog mode: editor. */
116     public static final String JavaDoc MODE_EDITOR = "editor";
117
118     /** Request parameter value for the dialog mode: view. */
119     public static final String JavaDoc MODE_VIEW = "view";
120
121     /** Request parameter value for the dialog mode: widget. */
122     public static final String JavaDoc MODE_WIDGET = "widget";
123
124     /** The uri suffix for the gallery start page. */
125     public static final String JavaDoc OPEN_URI_SUFFIX = "gallery_fs.jsp";
126
127     /** Request parameter name for the dialog mode (widget or editor). */
128     public static final String JavaDoc PARAM_DIALOGMODE = "dialogmode";
129
130     /** Request parameter name for the input field id. */
131     public static final String JavaDoc PARAM_FIELDID = "fieldid";
132
133     /** Request parameter name for the gallery type. */
134     public static final String JavaDoc PARAM_GALLERY_TYPENAME = "gallerytypename";
135
136     /** Request parameter name for the gallery path. */
137     public static final String JavaDoc PARAM_GALLERYPATH = "gallerypath";
138
139     /** Request parameter name for the gallery list page. */
140     public static final String JavaDoc PARAM_PAGE = "page";
141
142     /** Request parameter name for the property value. */
143     public static final String JavaDoc PARAM_PROPERTYVALUE = "propertyvalue";
144
145     /** Request parameter name for the resourcepath. */
146     public static final String JavaDoc PARAM_RESOURCEPATH = "resourcepath";
147
148     /** Request parameter name for the search word. */
149     public static final String JavaDoc PARAM_SEARCHWORD = "searchword";
150
151     /** The galleries path in the workplace containing the JSPs. */
152     public static final String JavaDoc PATH_GALLERIES = CmsWorkplace.VFS_PATH_WORKPLACE + "galleries/";
153
154     /** The log object for this class. */
155     private static final Log LOG = CmsLog.getLog(A_CmsGallery.class);
156
157     /** The currently displayed gallery resource. */
158     private CmsResource m_currentResource;
159
160     /** Thed gallery items to display. */
161     private List JavaDoc m_galleryItems;
162
163     /** The resource type id of this gallery instance. */
164     private int m_galleryTypeId;
165
166     /** The resource type name of this gallery instance. */
167     private String JavaDoc m_galleryTypeName;
168
169     /** The optional parameters for the gallery from the XML configuration. */
170     private String JavaDoc m_galleryTypeParams;
171
172     /** The dialog mode the gallery is running in. */
173     private String JavaDoc m_paramDialogMode;
174
175     /** The input field id that is required when in widget mode. */
176     private String JavaDoc m_paramFieldId;
177
178     /** The current gallery path. */
179     private String JavaDoc m_paramGalleryPath;
180
181     /** The page number to display. */
182     private String JavaDoc m_paramPage;
183
184     /** The value of the property (current propertydefinition: Title). */
185     private String JavaDoc m_paramPropertyValue;
186
187     /** The resource path parameter. */
188     private String JavaDoc m_paramResourcePath;
189
190     /** The search word parameter. */
191     private String JavaDoc m_paramSearchWord;
192
193     /** The gallery base resource type. */
194     private CmsResourceTypeFolderExtended m_resourceType;
195
196     /**
197      * Public empty constructor, required for {@link A_CmsGallery#createInstance(String, CmsJspActionElement)}.<p>
198      */

199     public A_CmsGallery() {
200
201         this(null);
202     }
203
204     /**
205      * Public constructor with JSP action element.<p>
206      *
207      * @param jsp an initialized JSP action element
208      */

209     public A_CmsGallery(CmsJspActionElement jsp) {
210
211         super(jsp);
212     }
213
214     /**
215      * Creates a new gallery instance.<p>
216      *
217      * @param jsp an initialized JSP action element
218      *
219      * @return a new gallery instance
220      */

221     public static A_CmsGallery createInstance(CmsJspActionElement jsp) {
222
223         String JavaDoc galleryTypeName = null;
224         if (jsp != null) {
225             // must have a valid JSP in order to read from the request
226
galleryTypeName = jsp.getRequest().getParameter(PARAM_GALLERY_TYPENAME);
227         }
228         return A_CmsGallery.createInstance(galleryTypeName, jsp);
229     }
230
231     /**
232      * Creates a new gallery instance of the given gallery type name.<p>
233      *
234      * @param galleryTypeName the gallery type name to create the instance for
235      * @param jsp an initialized JSP action element
236      *
237      * @return a new gallery instance of the given gallery type name
238      */

239     public static A_CmsGallery createInstance(String JavaDoc galleryTypeName, CmsJspActionElement jsp) {
240
241         if (jsp != null) {
242             // must have a valid JSP in order to read from the user session
243
HttpSession JavaDoc session = jsp.getRequest().getSession();
244             // lookup the workplace settings
245
CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
246             if (CmsStringUtil.isEmpty(galleryTypeName)) {
247                 // look up the gallery type from the settings
248
galleryTypeName = settings.getGalleryType();
249             } else {
250                 // store the last used gallery type name
251
settings.setGalleryType(galleryTypeName);
252             }
253         }
254         // get the gallery class name for the type
255
A_CmsGallery template = (A_CmsGallery)OpenCms.getWorkplaceManager().getGalleries().get(galleryTypeName);
256
257         if (template == null) {
258             // requested gallery type is not configured
259
CmsMessageContainer message;
260             if (jsp == null) {
261                 message = Messages.get().container(Messages.LOG_UNKNOWN_GALLERY_TYPE_REQ_1, galleryTypeName);
262             } else {
263                 message = Messages.get().container(
264                     Messages.LOG_UNKNOWN_GALLERY_TYPE_REQ_JSP_2,
265                     galleryTypeName,
266                     jsp.info("opencms.request.element.uri"));
267             }
268             LOG.error(message.key());
269             throw new CmsRuntimeException(message);
270         }
271
272         try {
273             // first get the class of the gallery
274
Class JavaDoc galleryClass = Class.forName(template.getResourceType().getFolderClassName());
275             // create a new instance and cast to a gallery
276
A_CmsGallery galleryInstance = (A_CmsGallery)galleryClass.newInstance();
277             // set the type name and id
278
galleryInstance.m_galleryTypeName = galleryTypeName;
279             galleryInstance.m_resourceType = template.getResourceType();
280             galleryInstance.m_galleryTypeParams = template.getResourceType().getFolderClassParams();
281             galleryInstance.m_galleryTypeId = template.getResourceType().getTypeId();
282             // initialize the members
283
galleryInstance.initWorkplaceMembers(jsp);
284             // perform other intialization
285
galleryInstance.init();
286             // return the result
287
return galleryInstance;
288         } catch (Exception JavaDoc e) {
289             // requested type is not configured
290
CmsMessageContainer message;
291             if (jsp == null) {
292                 message = Messages.get().container(
293                     Messages.LOG_CREATE_GALLERY_INSTANCE_FAILED_2,
294                     template.getResourceType().getFolderClassName(),
295                     galleryTypeName);
296             } else {
297                 message = Messages.get().container(
298                     Messages.LOG_CREATE_GALLERY_INSTANCE_FAILED_JSP_3,
299                     template.getResourceType().getFolderClassName(),
300                     galleryTypeName,
301                     jsp.info("opencms.request.element.uri"));
302             }
303             LOG.error(message.key());
304             throw new CmsRuntimeException(message);
305         }
306     }
307
308     /**
309      * Initializes the gallery dialog before redirecting.<p>
310      *
311      * @param wp the workplace object
312      */

313     public static void initGallery(CmsDialog wp) {
314
315         // 1. get "gallerytypename" by reading the folderpath
316
String JavaDoc galleryTypeName = null;
317         if (wp.useNewStyle()) {
318             galleryTypeName = CmsResource.getName(CmsResource.getFolderPath(wp.getAdminTool().getHandler().getLink()));
319         } else {
320             galleryTypeName = CmsResource.getName(CmsResource.getFolderPath(wp.getJsp().getRequestContext().getUri()));
321         }
322         if (galleryTypeName.endsWith("/")) {
323             galleryTypeName = galleryTypeName.substring(0, galleryTypeName.length() - 1);
324         }
325         if (!galleryTypeName.equals("commons")) {
326             // 2. Set in user settings
327
wp.getSettings().setGalleryType(galleryTypeName);
328         }
329     }
330
331     /**
332      * Generates an apply button for the gallery button bar.<p>
333      *
334      * The default apply button calls the javascript function link(resourcePath, input.title.value, input.title.value).
335      * Overwrite this method if necessary in the specified gallery class.<p>
336      *
337      * @return an apply button for the gallery button bar
338      */

339     public String JavaDoc applyButton() {
340
341         if (MODE_VIEW.equals(getParamDialogMode())) {
342             // in view mode, show disabled button
343
return button(null, null, "apply_in.png", Messages.GUI_BUTTON_PASTE_0, 0);
344         } else {
345             // in editor or widget mode, create enabled button
346
String JavaDoc uri = getParamResourcePath();
347             if (CmsStringUtil.isEmpty(getParamDialogMode())) {
348                 uri = getJsp().link(uri);
349             }
350             return button(
351                 "javascript:link('" + uri + "',document.form.title.value, document.form.title.value);",
352                 null,
353                 "apply.png",
354                 Messages.GUI_BUTTON_PASTE_0,
355                 0);
356         }
357     }
358
359     /**
360      * Builds the html String for the buttonbar frame.<p>
361      *
362      * @return the html String for the buttonbar frame
363      */

364     public String JavaDoc buildGalleryButtonBar() {
365
366         StringBuffer JavaDoc buttonBar = new StringBuffer JavaDoc();
367         try {
368             if (CmsStringUtil.isNotEmpty(getParamResourcePath())) {
369                 // we have a resource to display
370
CmsResource res = getCms().readResource(getParamResourcePath());
371                 if (res != null) {
372                     setCurrentResource(res);
373                     // check if the current user has write/lock permissions to the resource
374
if (hasWritePermissions() && DIALOG_EDITPROPERTY.equals(getParamAction())) {
375                         // write the changed title property value
376
writeTitleProperty(res);
377                     }
378                     String JavaDoc title = CmsEncoder.escapeXml(getPropertyValue(res, CmsPropertyDefinition.PROPERTY_TITLE));
379                     buttonBar.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" ");
380                     buttonBar.append("style=\"align: left; width:100%; background-color: ThreeDFace; margin: 0; border-right: 1px solid ThreeDShadow\">");
381                     buttonBar.append("<tr align=\"left\">");
382                     buttonBar.append(buttonBarStartTab(0, 0));
383                     // apply button
384
buttonBar.append(applyButton());
385                     // publish button
386
buttonBar.append(publishButton());
387                     // delete button
388
buttonBar.append(deleteButton());
389                     buttonBar.append(buttonBarSeparator(5, 5));
390                     buttonBar.append("<td class=\"nowrap\"><b>");
391                     buttonBar.append(key(Messages.GUI_INPUT_TITLE_0));
392                     buttonBar.append("</b>&nbsp;</td>");
393                     buttonBar.append("<td class=\"maxwidth\">");
394                     buttonBar.append("<input name=\"title\" value=\"");
395                     buttonBar.append(title);
396                     buttonBar.append("\" style=\"width: 95%\">");
397                     buttonBar.append("</td>\r\n");
398                     // hidden field
399
buttonBar.append("<input type=\"hidden\" name=\"");
400                     buttonBar.append(PARAM_PROPERTYVALUE);
401                     buttonBar.append("\" value=\"");
402                     buttonBar.append(title);
403                     buttonBar.append("\">\r\n");
404                     // edit property button
405
buttonBar.append(editPropertyButton());
406                     // target select
407
buttonBar.append(targetSelectBox());
408                     // preview button
409
buttonBar.append(previewButton());
410                     buttonBar.append(buttonBar(HTML_END));
411                 }
412             } else {
413                 // no resource to display, create empty row
414
buttonBar.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>");
415                 buttonBar.append("<img height=\"22\" border=\"0\" SRC=\"");
416                 buttonBar.append(getJsp().link(CmsWorkplace.VFS_PATH_RESOURCES + "tree/empty.gif"));
417                 buttonBar.append("\">");
418                 buttonBar.append("</td></tr></table>");
419             }
420         } catch (CmsException e) {
421             // resource is deleted, display empty table
422
buttonBar.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>");
423             buttonBar.append("<img height=\"22\" border=\"0\" SRC=\"");
424             buttonBar.append(getJsp().link(CmsWorkplace.VFS_PATH_RESOURCES + "tree/empty.gif"));
425             buttonBar.append("\">");
426             buttonBar.append("</td></tr></table>");
427         }
428         return buttonBar.toString();
429     }
430
431     /**
432      * Builds the html String for the preview frame.<p>
433      *
434      * @return the html String for the preview frame
435      */

436     public abstract String JavaDoc buildGalleryItemPreview();
437
438     /**
439      * Builds the html for the gallery items list.<p>
440      *
441      * @return the html for the gallery items list
442      */

443     public String JavaDoc buildGalleryItems() {
444
445         StringBuffer JavaDoc result = new StringBuffer JavaDoc(64);
446         result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\">");
447         result.append(buildGalleryItemListHeadline());
448         List JavaDoc items = getGalleryItems();
449         // get the current page number
450
String JavaDoc pageno = getParamPage();
451         if (pageno == null) {
452             pageno = "1";
453         }
454         if (items != null && items.size() > 0) {
455             // calculate page items
456
int start = 0;
457             int end = getSettings().getUserSettings().getExplorerFileEntries();
458             start = (Integer.parseInt(pageno) * end) - end;
459             end = (Integer.parseInt(pageno) * end);
460             if (end > items.size()) {
461                 end = items.size();
462             }
463             if (start > end) {
464                 start = 0;
465             }
466             for (int i = start; i < end; i++) {
467
468                 CmsResource res = (CmsResource)items.get(i);
469                 int state = res.getState();
470                 String JavaDoc tdClass;
471                 switch (state) {
472                     case CmsResource.STATE_CHANGED:
473                         tdClass = "fc";
474                         break;
475                     case CmsResource.STATE_NEW:
476                         tdClass = "fn";
477                         break;
478                     default:
479                         tdClass = "list";
480                 }
481                 String JavaDoc resPath = getCms().getSitePath(res);
482                 String JavaDoc resName = CmsResource.getName(resPath);
483                 String JavaDoc title = getPropertyValue(res, CmsPropertyDefinition.PROPERTY_TITLE);
484
485                 result.append("<tr>\n");
486
487                 // append the custom start columns
488
result.append(buildGalleryItemListCustomStartCols(res, tdClass));
489
490                 // file name
491
result.append("\t<td class=\"");
492                 result.append(tdClass);
493                 result.append("\"><a class=\"");
494                 result.append(tdClass);
495                 result.append("\" HREF=\"javascript: preview(\'");
496                 result.append(resPath);
497                 result.append("\');\" title=\"");
498                 result.append(key(Messages.GUI_BUTTON_PREVIEW_0));
499                 result.append("\">");
500                 result.append(resName);
501                 result.append("</a></td>\n");
502                 // file title
503
result.append("\t<td class=\"");
504                 result.append(tdClass);
505                 result.append("\">");
506                 result.append(CmsEncoder.escapeXml(title));
507                 result.append("</td>\n");
508
509                 // append the custom end columns
510
result.append(buildGalleryItemListCustomEndCols(res, tdClass));
511
512                 result.append("</tr>\n");
513             }
514         }
515         result.append("</table>");
516         return result.toString();
517     }
518
519     /**
520      * Returns the html for the gallery select box.<p>
521      *
522      * @return the html for the gallery select box
523      */

524     public String JavaDoc buildGallerySelectBox() {
525
526         List JavaDoc galleries = getGalleries();
527         if (galleries != null && galleries.size() == 1) {
528             // exactly one gallery present
529
CmsResource res = (CmsResource)galleries.get(0);
530             StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
531             String JavaDoc path = getCms().getSitePath(res);
532             String JavaDoc title = "";
533             try {
534                 // read the gallery title
535
title = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue("");
536             } catch (CmsException e) {
537                 // error reading title property
538
LOG.error(e);
539             }
540             result.append(title);
541             result.append(" (");
542             result.append(path);
543             result.append(" )\r\n");
544             result.append("<input type=\"hidden\" name=\"");
545             result.append(PARAM_GALLERYPATH);
546             result.append("\" value=\"");
547             result.append(path);
548             result.append("\">");
549             return result.toString();
550         } else if (galleries.size() > 1) {
551             // more than one gallery present
552
int galleryCount = galleries.size();
553             List JavaDoc options = new ArrayList JavaDoc(galleryCount);
554             List JavaDoc values = new ArrayList JavaDoc(galleryCount);
555             int selectedIndex = -1;
556             for (int i = 0; i < galleryCount; i++) {
557                 CmsResource res = (CmsResource)galleries.get(i);
558                 String JavaDoc path = getCms().getSitePath(res);
559                 if (path.equals(getParamGalleryPath())) {
560                     selectedIndex = i;
561                 }
562                 String JavaDoc title = "";
563                 try {
564                     // read the gallery title
565
title = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue("");
566                 } catch (CmsException e) {
567                     // error reading title property
568
if (LOG.isErrorEnabled()) {
569                         LOG.error(e);
570                     }
571                 }
572                 options.add(title + " (" + path + ")");
573                 values.add(path);
574
575             }
576             selectedIndex = sortOptions(options, values);
577             String JavaDoc attrs = "name=\"" + PARAM_GALLERYPATH;
578             attrs += "\" size=\"1\" style=\"width: 100%;\" onchange=\"displayGallery();\"";
579             return buildSelect(attrs, options, values, selectedIndex);
580         } else {
581             // no gallery present, create hidden input field to avoid JS errors
582
StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
583             result.append(key(Messages.getGalleryNotFoundKey(getGalleryTypeName())));
584             result.append("\r\n<input type=\"hidden\" name=\"");
585             result.append(PARAM_GALLERYPATH);
586             result.append("\">");
587             return result.toString();
588         }
589     }
590
591     /**
592      * Builds the HTML String for the page select box.<p>
593      *
594      * @return the HTML String for the page select box
595      */

596     public String JavaDoc buildPageSelectBox() {
597
598         StringBuffer JavaDoc html = new StringBuffer JavaDoc(16);
599         List JavaDoc items = getGalleryItems();
600         // get the page number
601
String JavaDoc pageno = getParamPage();
602         if (pageno == null) {
603             pageno = "1";
604         }
605         int count = 0;
606         int pages = 1;
607         int rest = 0;
608         // get the maxentries per page from the user settings
609
int maxentries = getSettings().getUserSettings().getExplorerFileEntries();
610
611         if (items != null) {
612             count = items.size();
613         }
614         // calculate the number of pages
615
if (count > maxentries) {
616             pages = count / maxentries;
617             rest = count % maxentries;
618             if (rest > 0) {
619                 rest = 1;
620             } else {
621                 rest = 0;
622             }
623             pages += rest;
624         }
625         // display the select box if the number of pages > 1
626
if (pages > 1) {
627             html.append("<select name=\"page\" class=\"location\" onchange=\"displayGallery();\">");
628             String JavaDoc selected = "";
629             for (int i = 1; i < pages + 1; i++) {
630                 if (i == Integer.parseInt(pageno)) {
631                     selected = " selected=\"selected\"";
632                 }
633                 html.append("<option value='");
634                 html.append(i);
635                 html.append("'");
636                 html.append(selected);
637                 html.append(">");
638                 html.append(i);
639                 html.append("</option>");
640                 selected = "";
641             }
642             html.append("</select>");
643         }
644
645         return html.toString();
646     }
647
648     /**
649      * Compares gallery objects by their order, this is used to sort the gallery buttons for the editors.<p>
650      *
651      * @see java.lang.Comparable#compareTo(java.lang.Object)
652      */

653     public int compareTo(Object JavaDoc o) {
654
655         if (!(o instanceof A_CmsGallery)) {
656             // wrong object
657
return 0;
658         }
659
660         // compare the order values of the galleries
661
return getOrder().compareTo(((A_CmsGallery)o).getOrder());
662     }
663
664     /**
665      * Generates a delete button for the gallery button bar.<p>
666      *
667      * This button is disabled if the urrent user has no write permissions.<p>
668      *
669      * Overwrite this method if necessary in the specified gallery class.<p>
670      *
671      * @return a delete button for the gallery button bar
672      */

673     public String JavaDoc deleteButton() {
674
675         try {
676             if (hasWritePermissions()) {
677                 return button(
678                     "javascript:deleteResource(\'" + getParamResourcePath() + "\');",
679                     null,
680                     "deletecontent.png",
681                     Messages.GUI_TITLE_DELETE_0,
682                     0);
683             }
684         } catch (CmsException e) {
685             // error checking permissions
686
if (LOG.isErrorEnabled()) {
687                 LOG.error(e);
688             }
689         }
690         return button(null, null, "deletecontent_in.png", "", 0);
691     }
692
693     /**
694      * Generates an edit property button for the gallery button bar.<p>
695      *
696      * If the current resource is not 'editable' a disabled button will be returned.<p>
697      *
698      * Overwrite this method if necessary in the specified gallery class.<p>
699      *
700      * @return an edit property button for the gallery button bar
701      */

702     public String JavaDoc editPropertyButton() {
703
704         try {
705             if (hasWritePermissions()) {
706                 return button(
707                     "javascript:editProperty('" + getParamResourcePath() + "');",
708                     null,
709                     "edit.png",
710                     Messages.GUI_INPUT_EDITPROPERTYINFO_0,
711                     0);
712             }
713         } catch (CmsException e) {
714             // error checking permissions
715
LOG.error(e);
716         }
717         return button(null, null, "edit_in.png", "", 0);
718     }
719
720     /**
721      * Checks if at least one gallery exists.<p>
722      *
723      * @return true if at least one gallery exists, otherwise false
724      */

725     public boolean galleriesExists() {
726
727         List JavaDoc galleries = getGalleries();
728         if (galleries != null && galleries.size() > 0) {
729             // at least one gallery exists
730
return true;
731         }
732         return false;
733     }
734
735     /**
736      * Returns the javascript body onload call for the gallery head frame.<p>
737      *
738      * @return the javascript body onload call for the gallery head frame
739      */

740     public String JavaDoc getBodyOnload() {
741
742         StringBuffer JavaDoc onload = new StringBuffer JavaDoc();
743         onload.append("self.focus();");
744         if (CmsStringUtil.isEmpty(getParamGalleryPath())) {
745             onload.append("displayGallery();");
746         }
747
748         return onload.toString();
749     }
750
751     /**
752      * Return the path of the css file used in the galleries.<p>
753      *
754      * @return the path of the css file used in the galleries
755      */

756     public String JavaDoc getCssPath() {
757
758         return getJsp().link(PATH_GALLERIES + CSS_FILENAME);
759     }
760
761     /**
762      * Returns the current resource in the gallery.<p>
763      *
764      * @return the current resource in the gallery
765      */

766     public CmsResource getCurrentResource() {
767
768         return m_currentResource;
769     }
770
771     /**
772      * Returns a list of galleries which have the required gallery type id.<p>
773      *
774      * @return a list of galleries
775      */

776     public List JavaDoc getGalleries() {
777
778         List JavaDoc galleries = null;
779         int galleryTypeId = getGalleryTypeId();
780         try {
781             // get the galleries of the current site
782
galleries = getCms().readResources(
783                 "/",
784                 CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(galleryTypeId));
785         } catch (CmsException e) {
786             // error reading resources with filter
787
LOG.error(e);
788         }
789
790         // if the current site is NOT the root site - add all other galleries from the system path
791
if (!getCms().getRequestContext().getSiteRoot().equals("")) {
792             List JavaDoc systemGalleries = null;
793             try {
794                 // get the galleries in the /system/ folder
795
systemGalleries = getCms().readResources(
796                     CmsWorkplace.VFS_PATH_SYSTEM,
797                     CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(galleryTypeId));
798             } catch (CmsException e) {
799                 // error reading resources with filter
800
LOG.error(e);
801             }
802
803             if (systemGalleries != null && systemGalleries.size() > 0) {
804                 // add the found system galleries to the result
805
galleries.addAll(systemGalleries);
806             }
807         }
808
809         // return the found galleries
810
return galleries;
811     }
812
813     /**
814      * Returns a list of gallery items (resources) for the currently selected gallery and resource type id.<p>
815      *
816      * @return a list of gallery items (resources)
817      */

818     public List JavaDoc getGalleryItems() {
819
820         if (m_galleryItems == null) {
821             // gallery items have not been read yet
822
int resTypeId = getGalleryItemsTypeId();
823             if (CmsStringUtil.isNotEmpty(getParamGalleryPath())) {
824                 try {
825                     // set last used gallery in settings to current gallery
826
getSettings().setLastUsedGallery(getGalleryTypeId(), getParamGalleryPath());
827                     CmsResourceFilter filter;
828                     if (resTypeId == -1) {
829                         // filter all resources that are files
830
filter = CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireFile();
831                     } else {
832                         // filter all resources of the required type
833
filter = CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(resTypeId);
834                     }
835                     m_galleryItems = getCms().readResources(getParamGalleryPath(), filter, false);
836                 } catch (CmsException e) {
837                     // error reading reaources
838
LOG.error(e);
839                 } catch (NullPointerException JavaDoc e) {
840                     // ignore this exception
841
}
842             }
843         }
844         List JavaDoc items = m_galleryItems;
845         // apply search filter, if necessary
846
if (CmsStringUtil.isNotEmpty(getParamSearchWord())) {
847             items = getSearchHits(m_galleryItems);
848         }
849         return items;
850     }
851
852     /**
853      * Returns the type id of the gallery items that should be listed.<p>
854      *
855      * In case of downloadgallery use '-1' to list all resources excluding folders.<p>
856      *
857      * @return the type id of the gallery items that should be listed
858      */

859     public abstract int getGalleryItemsTypeId();
860
861     /**
862      * Returns the resource type id of this gallery instance.<p>
863      *
864      * @return the resource type id of this gallery instance
865      */

866     public int getGalleryTypeId() {
867
868         return m_galleryTypeId;
869     }
870
871     /**
872      * Returns the resource type name of this gallery instance.<p>
873      *
874      * @return the resource type name of this gallery instance
875      */

876     public String JavaDoc getGalleryTypeName() {
877
878         return m_galleryTypeName;
879     }
880
881     /**
882      * Returns the (optional) parameters of this gallery instance.<p>
883      *
884      * @return the (optional) parameters of this gallery instance
885      */

886     public String JavaDoc getGalleryTypeParams() {
887
888         return m_galleryTypeParams;
889     }
890
891     /**
892      * Returns the height of the head frameset.<p>
893      *
894      * @return the height of the head frameset
895      */

896     public String JavaDoc getHeadFrameSetHeight() {
897
898         return "280";
899     }
900
901     /**
902      * Returns the key title of the current gallery view.<p>
903      *
904      * @return the key title of the current gallery view
905      */

906     public String JavaDoc getKeyTitle() {
907
908         return key(Messages.getTitleGalleryKey(getGalleryTypeName()));
909     }
910
911     /**
912      * Returns the error message if no gallery could be found.<p>
913      *
914      * @return the error message if no gallery could be found
915      */

916     public String JavaDoc getNoGalleryErrorMsg() {
917
918         return key(Messages.getGalleryNotFoundKey(getGalleryTypeName()));
919     }
920
921     /**
922      * Returns the order of the implemented gallery, used to sort the gallery buttons in the editors.<p>
923      *
924      * @return the order of the implemented gallery
925      */

926     public Integer JavaDoc getOrder() {
927
928         return new Integer JavaDoc(Integer.MAX_VALUE);
929     }
930
931     /**
932      * Returns the current mode of the dialog.<p>
933      *
934      * This is necessary to distinguish between widget mode, view mode and editor mode.<p>
935      *
936      * @return the current mode of the dialog
937      */

938     public String JavaDoc getParamDialogMode() {
939
940         if (m_paramDialogMode == null) {
941             return "";
942         }
943         return m_paramDialogMode;
944     }
945
946     /**
947      * Returns the input field ID when in widget mode.<p>
948      *
949      * @return the input field ID
950      */

951     public String JavaDoc getParamFieldId() {
952
953         return m_paramFieldId;
954     }
955
956     /**
957      * Returns the path of the gallery to display.<p>
958      *
959      * @return the path of the gallery to display
960      */

961     public String JavaDoc getParamGalleryPath() {
962
963         if (CmsStringUtil.isEmpty(m_paramGalleryPath)) {
964             m_paramGalleryPath = "";
965         }
966         return m_paramGalleryPath;
967     }
968
969     /**
970      * Returns the current page to display in the item list.<p>
971      *
972      * @return the current page to display in the item list
973      */

974     public String JavaDoc getParamPage() {
975
976         return m_paramPage;
977     }
978
979     /**
980      * Returns the property value parameter.<p>
981      *
982      * @return the property value parameter
983      */

984     public String JavaDoc getParamPropertyValue() {
985
986         return m_paramPropertyValue;
987     }
988
989     /**
990      * Returns the resource path.<p>
991      *
992      * @return the resource path
993      */

994     public String JavaDoc getParamResourcePath() {
995
996         return m_paramResourcePath;
997     }
998
999     /**
1000     * Returns the search word to look up in the gallery items.<p>
1001     *
1002     * @return the search word to look up in the gallery items
1003     */

1004    public String JavaDoc getParamSearchWord() {
1005
1006        if (CmsStringUtil.isEmpty(m_paramSearchWord)) {
1007            m_paramSearchWord = "";
1008        }
1009        return m_paramSearchWord;
1010    }
1011
1012    /**
1013     * Returns the style for the body tag of the preview frame.<p>
1014     *
1015     * @return the style for the body tag of the preview frame
1016     */

1017    public String JavaDoc getPreviewBodyStyle() {
1018
1019        return new String JavaDoc(" class=\"dialog\" style=\"background-color: ThreeDFace;\" unselectable=\"on\"");
1020    }
1021
1022    /**
1023     * Returns the style for the div tag of the preview frame.<p>
1024     *
1025     * @return the style for the div tag of the preview frame
1026     */

1027    public String JavaDoc getPreviewDivStyle() {
1028
1029        return new String JavaDoc("style=\"text-align: center; width: 100%; margin-top: 5px\"");
1030    }
1031
1032    /**
1033     * Returns the extended folder resource type this gallery is based on.<p>
1034     *
1035     * @return the extended folder resource type this gallery is based on
1036     */

1037    public CmsResourceTypeFolderExtended getResourceType() {
1038
1039        return m_resourceType;
1040    }
1041
1042    /**
1043     * Returns the url for the upload applet or JSP dialog.<p>
1044     *
1045     * @return the url for the upload applet or JSP dialog
1046     */

1047    public String JavaDoc getWizardUrl() {
1048
1049        StringBuffer JavaDoc wizardUrl = new StringBuffer JavaDoc(16);
1050        wizardUrl.append(getJsp().link(
1051            PATH_DIALOGS + OpenCms.getWorkplaceManager().getExplorerTypeSetting("upload").getNewResourceUri()));
1052        wizardUrl.append("?");
1053        wizardUrl.append(CmsNewResourceUpload.PARAM_REDIRECTURL);
1054        wizardUrl.append("=");
1055        wizardUrl.append(PATH_GALLERIES);
1056        wizardUrl.append("gallery_list.jsp&");
1057        wizardUrl.append(CmsNewResourceUpload.PARAM_TARGETFRAME);
1058        wizardUrl.append("=gallery_list&");
1059        wizardUrl.append(CmsNewResource.PARAM_CURRENTFOLDER);
1060        wizardUrl.append("=");
1061        return wizardUrl.toString();
1062    }
1063
1064    /**
1065     * Initialization method that is called after the gallery instance has been created.<p>
1066     */

1067    public void init() {
1068
1069        // default gallery does not require initialization
1070
}
1071
1072    /**
1073     * Generates a preview button for the gallery button bar.<p>
1074     *
1075     * Overwrite this method if neccessary in the specified gallery class.<p>
1076     *
1077     * @return a preview button for the gallery button bar
1078     */

1079    public String JavaDoc previewButton() {
1080
1081        StringBuffer JavaDoc previewButton = new StringBuffer JavaDoc(8);
1082        previewButton.append(buttonBarSeparator(5, 5));
1083        previewButton.append(button(
1084            getJsp().link(getCms().getSitePath(getCurrentResource())),
1085            "_preview",
1086            "preview.png",
1087            Messages.GUI_BUTTON_PREVIEW_0,
1088            0));
1089        return previewButton.toString();
1090    }
1091
1092    /**
1093     * Generates a HTML table row with two columns.<p>
1094     *
1095     * The first column includes the given key as localized string, the second column
1096     * includes the value of the given property.<p>
1097     *
1098     * @param column1 the string value for the first column
1099     * @param column2 the string value for the second column
1100     * @return a HTML table row with two columns
1101     */

1102    public String JavaDoc previewRow(String JavaDoc column1, String JavaDoc column2) {
1103
1104        StringBuffer JavaDoc previewRow = new StringBuffer JavaDoc();
1105        previewRow.append("<tr align=\"left\">");
1106        previewRow.append("<td><b>");
1107        previewRow.append(column1);
1108        previewRow.append("</b></td>");
1109        previewRow.append("<td>");
1110        previewRow.append(column2);
1111        previewRow.append("</td>");
1112        previewRow.append("</tr>");
1113
1114        return previewRow.toString();
1115
1116    }
1117
1118    /**
1119     * Generates a publish button for the gallery button bar.<p>
1120     *
1121     * This button is disabled if the current user has no publish rights.<p>
1122     *
1123     * @return a publish button for the gallery button bar
1124     */

1125    public String JavaDoc publishButton() {
1126
1127        if (getCms().hasPublishPermissions(getParamResourcePath())) {
1128            return button(
1129                "javascript:publishResource(\'" + getParamResourcePath() + "\');",
1130                null,
1131                "publish.png",
1132                Messages.GUI_MESSAGEBOX_TITLE_PUBLISHRESOURCE_0,
1133                0);
1134        }
1135        return button(null, null, "publish_in.png", "", 0);
1136    }
1137
1138    /**
1139     * Builds the HTML for the search button.<p>
1140     *
1141     * @return the HTML for the search button
1142     */

1143    public String JavaDoc searchButton() {
1144
1145        return button("javascript:displayGallery();", null, "search.png", Messages.GUI_INPUT_SEARCH_0, 0);
1146    }
1147
1148    /**
1149     * Sets the current resource.<p>
1150     *
1151     * @param currentResource the current resource to set
1152     */

1153    public void setCurrentResource(CmsResource currentResource) {
1154
1155        m_currentResource = currentResource;
1156    }
1157
1158    /**
1159     * Sets the current mode of the dialog.<p>
1160     *
1161     * This is necessary to distinguish between widget mode and editor mode.<p>
1162     *
1163     * @param dialogMode the current mode of the dialog
1164     */

1165    public void setParamDialogMode(String JavaDoc dialogMode) {
1166
1167        m_paramDialogMode = dialogMode;
1168    }
1169
1170    /**
1171     * Sets the input field ID if in widget mode.<p>
1172     *
1173     * @param fieldId the input field ID
1174     */

1175    public void setParamFieldId(String JavaDoc fieldId) {
1176
1177        m_paramFieldId = fieldId;
1178    }
1179
1180    /**
1181     * Sets the path of the gallery to display.<p>
1182     *
1183     * @param galleryPath the path of the gallery to display
1184     */

1185    public void setParamGalleryPath(String JavaDoc galleryPath) {
1186
1187        m_paramGalleryPath = galleryPath;
1188    }
1189
1190    /**
1191     * Sets the current page to display in the item list.<p>
1192     *
1193     * @param page the current page to display in the item list
1194     */

1195    public void setParamPage(String JavaDoc page) {
1196
1197        m_paramPage = page;
1198    }
1199
1200    /**
1201     * Sets the property value parameter.<p>
1202     *
1203     * @param paramPropertyValue the property value parameter to set
1204     */

1205    public void setParamPropertyValue(String JavaDoc paramPropertyValue) {
1206
1207        m_paramPropertyValue = paramPropertyValue;
1208    }
1209
1210    /**
1211     * Sets the resource path.<p>
1212     *
1213     * @param resourcePath the resource path to set
1214     */

1215    public void setParamResourcePath(String JavaDoc resourcePath) {
1216
1217        m_paramResourcePath = resourcePath;
1218    }
1219
1220    /**
1221     * Sets the search word to look up in the gallery items.<p>
1222     *
1223     * @param searchWord the search word to look up in the gallery items
1224     */

1225    public void setParamSearchWord(String JavaDoc searchWord) {
1226
1227        m_paramSearchWord = searchWord;
1228    }
1229
1230    /**
1231     * Sets the extended folder resource type this gallery is based on.<p>
1232     *
1233     * @param type the extended folder resource type this gallery is based on
1234     */

1235    public void setResourceType(CmsResourceTypeFolderExtended type) {
1236
1237        m_resourceType = type;
1238    }
1239
1240    /**
1241     * Generates a HTML String representing a target select box.<p>
1242     *
1243     * @return a HTML String representing a target select box
1244     */

1245    public String JavaDoc targetSelectBox() {
1246
1247        StringBuffer JavaDoc targetSelectBox = new StringBuffer JavaDoc(32);
1248        targetSelectBox.append(buttonBarSpacer(5));
1249        targetSelectBox.append("<td nowrap><b>");
1250        targetSelectBox.append(key(Messages.GUI_INPUT_LINKTARGET_0));
1251        targetSelectBox.append("</b>&nbsp;</td>");
1252        targetSelectBox.append("<td>\r\n");
1253        targetSelectBox.append("<select name=\"linktarget\" id=\"linktarget\" size=\"1\" style=\"width:150px\"");
1254        if (MODE_VIEW.equals(getParamDialogMode())) {
1255            targetSelectBox.append(" disabled=\"disabled\"");
1256        }
1257        targetSelectBox.append(">");
1258        targetSelectBox.append(getTargetOptions());
1259        targetSelectBox.append("</select>");
1260        targetSelectBox.append("</td>");
1261
1262        return targetSelectBox.toString();
1263    }
1264
1265    /**
1266     * Builds the HTML for the wizard button.<p>
1267     *
1268     * @return the HTML for the wizard button
1269     */

1270    public String JavaDoc wizardButton() {
1271
1272        return button("javascript:wizard();", null, "upload.png", OpenCms.getWorkplaceManager().getExplorerTypeSetting(
1273            "upload").getKey(), 0);
1274    }
1275
1276    /**
1277     * Generates the HTML for custom columns to shown at the end of the list of gallery columns.<p>
1278     *
1279     * @param res the current VFS resource
1280     * @param tdClass the current syle sheet class name for the table cell
1281     *
1282     * @return the HTML for custom columns to shown at the end of the list of gallery columns
1283     */

1284    protected String JavaDoc buildGalleryItemListCustomEndCols(CmsResource res, String JavaDoc tdClass) {
1285
1286        StringBuffer JavaDoc result = new StringBuffer JavaDoc(64);
1287        result.append("\t<td class=\"");
1288        result.append(tdClass);
1289        result.append("\" style=\"text-align: right;\">");
1290        result.append(res.getLength() / 1024);
1291        result.append(" ");
1292        result.append(key(Messages.GUI_LABEL_KILOBYTES_0));
1293        result.append("</td>\n");
1294        return result.toString();
1295    }
1296
1297    /**
1298     * Generates the HTML for custom columns to shown at the start of the list of gallery columns.<p>
1299     *
1300     * @param res the current VFS resource
1301     * @param tdClass the current syle sheet class name for the table cell
1302     *
1303     * @return the HTML for custom columns to shown at the end of the list of gallery columns
1304     */

1305    protected String JavaDoc buildGalleryItemListCustomStartCols(CmsResource res, String JavaDoc tdClass) {
1306
1307        String JavaDoc resType;
1308        try {
1309            // get the resource type name
1310
resType = OpenCms.getResourceManager().getResourceType(res.getTypeId()).getTypeName();
1311        } catch (CmsLoaderException e) {
1312            // unknown restype (highly unlikley)
1313
resType = null;
1314        }
1315        StringBuffer JavaDoc result = new StringBuffer JavaDoc(64);
1316        result.append("\t<td>");
1317        if ((resType != null) && (tdClass != null)) {
1318            result.append("<img SRC=\"");
1319            result.append(getSkinUri());
1320            result.append("filetypes/");
1321            result.append(resType);
1322            result.append(".gif\">");
1323        }
1324        result.append("</td>\n");
1325        return result.toString();
1326    }
1327
1328    /**
1329     * Generates the HTML for the gallery item list headline.<p>
1330     *
1331     * @return the HTML for the gallery item list headline
1332     */

1333    protected String JavaDoc buildGalleryItemListHeadline() {
1334
1335        StringBuffer JavaDoc headline = new StringBuffer JavaDoc(32);
1336        headline.append("<tr>");
1337        headline.append("<td class=\"headline\">&nbsp;</td>");
1338        headline.append("<td class=\"headline\" width=\"35%\">");
1339        headline.append(key(Messages.GUI_LABEL_NAME_0));
1340        headline.append("</td>");
1341        headline.append("<td class=\"headline\" width=\"55%\">");
1342        headline.append(key(Messages.GUI_LABEL_TITLE_0));
1343        headline.append("</td>");
1344        headline.append("<td class=\"headline\" style=\"text-align: right;\" width=\"10%\">");
1345        headline.append(key(Messages.GUI_LABEL_SIZE_0));
1346        headline.append("</td>");
1347        headline.append("</tr>");
1348
1349        return headline.toString();
1350    }
1351
1352    /**
1353     * Returns the value of the given property definition of the specified resource.<p>
1354     *
1355     * If the property value is null, '[resourcename]' will be returned instead.<p>
1356     *
1357     * @param resource the cms resource
1358     * @param propertydefinition the property definition
1359     * @return the value of the title property or '[resourcename]' if property value was null
1360     */

1361    protected String JavaDoc getPropertyValue(CmsResource resource, String JavaDoc propertydefinition) {
1362
1363        String JavaDoc value = "";
1364        if (resource != null) {
1365            String JavaDoc resPath = getCms().getSitePath(resource);
1366            String JavaDoc resName = CmsResource.getName(resPath);
1367            try {
1368                CmsProperty property = getCms().readPropertyObject(resPath, propertydefinition, false);
1369                // get property value
1370
value = property.getValue("[" + resName + "]");
1371            } catch (CmsException e) {
1372                // error reading property object
1373
LOG.error(e);
1374            }
1375        }
1376        return value;
1377    }
1378
1379    /**
1380     * Returns a list of hit items.<p>
1381     *
1382     * Searches by the title property value and resource name.<p>
1383     *
1384     * @param items a list of resource items
1385     * @return a list of hit items
1386     */

1387    protected List JavaDoc getSearchHits(List JavaDoc items) {
1388
1389        String JavaDoc searchword = getParamSearchWord().toLowerCase();
1390        List JavaDoc hitlist = new ArrayList JavaDoc();
1391        if (items != null) {
1392            Iterator JavaDoc i = items.iterator();
1393            while (i.hasNext()) {
1394                CmsResource res = (CmsResource)i.next();
1395                String JavaDoc resname = res.getName().toLowerCase();
1396                String JavaDoc restitle = getJsp().property(
1397                    CmsPropertyDefinition.PROPERTY_TITLE,
1398                    getCms().getSitePath(res),
1399                    resname).toLowerCase();
1400                if (restitle.indexOf(searchword) != -1 || resname.indexOf(searchword) != -1) {
1401                    // add this resource to the hitlist
1402
hitlist.add(res);
1403                }
1404            }
1405        }
1406
1407        return hitlist;
1408    }
1409
1410    /**
1411     * Returns a HTML String representing the options of the target select box.<p>
1412     *
1413     * @return a HTML String representing the options of the target select box
1414     */

1415    protected String JavaDoc getTargetOptions() {
1416
1417        StringBuffer JavaDoc options = new StringBuffer JavaDoc();
1418        options.append("<option value=\"_self\">");
1419        options.append(key(Messages.GUI_INPUT_LINKTARGETSELF_0));
1420        options.append("</option>\r\n");
1421        options.append("<option value=\"_blank\">");
1422        options.append(key(Messages.GUI_INPUT_LINKTARGETBLANK_0));
1423        options.append("</option>\r\n");
1424        options.append("<option value=\"_top\">");
1425        options.append(key(Messages.GUI_INPUT_LINKTARGETTOP_0));
1426        options.append("</option>\r\n");
1427
1428        return options.toString();
1429    }
1430
1431    /**
1432     * Checks if the current user has required permissions to edit the current resource.<p>
1433     *
1434     * @return true if the required permissions are satisfied
1435     * @throws CmsException if something goes wrong
1436     */

1437    protected boolean hasWritePermissions() throws CmsException {
1438
1439        return getCms().hasPermissions(
1440            getCurrentResource(),
1441            CmsPermissionSet.ACCESS_WRITE,
1442            false,
1443            CmsResourceFilter.ALL);
1444    }
1445
1446    /**
1447     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
1448     */

1449    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
1450
1451        // fill the parameter values in the get/set methods
1452
fillParamValues(request);
1453        // set the dialog type
1454
setParamDialogtype(DIALOG_TYPE);
1455        if (CmsStringUtil.isEmpty(getParamGalleryPath())) {
1456            String JavaDoc lastUsedGallery = getSettings().getLastUsedGallery(getGalleryTypeId());
1457            if (CmsStringUtil.isNotEmpty(lastUsedGallery)) {
1458                // set the resourcepath of the last used gallery if the resource is not deleted
1459
try {
1460                    getCms().readResource(lastUsedGallery, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
1461                    setParamGalleryPath(lastUsedGallery);
1462                } catch (CmsException e) {
1463                    // reading the last used gallery failed, may be deleted
1464
}
1465            }
1466        }
1467    }
1468
1469    /**
1470     * Sorts the options and associated values in alphabetical order.<p>
1471     *
1472     * @param options a list of options
1473     * @param values a list of associated values
1474     *
1475     * @return the new index of the currently selected option according to the new order
1476     */

1477    protected int sortOptions(List JavaDoc options, List JavaDoc values) {
1478
1479        int selectedIndex = -1;
1480        Map JavaDoc valuesByOption = new TreeMap JavaDoc();
1481
1482        // save the values in a map keyed by their associated option
1483
for (int i = 0, n = options.size(); i < n; i++) {
1484
1485            String JavaDoc option = (String JavaDoc)options.get(i);
1486            String JavaDoc value = (String JavaDoc)values.get(i);
1487
1488            if (CmsStringUtil.isNotEmpty(option) && CmsStringUtil.isNotEmpty(value)) {
1489                valuesByOption.put(option, value);
1490            }
1491        }
1492
1493        // sort the options
1494
values.clear();
1495        options.clear();
1496
1497        // bring the values in the new order according to the sorted options
1498
Iterator JavaDoc it = valuesByOption.keySet().iterator();
1499        while (it.hasNext()) {
1500            String JavaDoc option = (String JavaDoc)it.next();
1501            String JavaDoc value = (String JavaDoc)valuesByOption.get(option);
1502
1503            if (value.equals(getParamGalleryPath())) {
1504                selectedIndex = options.size();
1505            }
1506
1507            options.add(option);
1508            values.add(value);
1509        }
1510
1511        return selectedIndex;
1512    }
1513
1514    /**
1515     * Changes the value of the property title for the specified resource.<p>
1516     *
1517     * @param res the resource to change the property value
1518     */

1519    protected void writeTitleProperty(CmsResource res) {
1520
1521        String JavaDoc resPath = getCms().getSitePath(res);
1522        String JavaDoc currentPropertyValue = getParamPropertyValue();
1523        try {
1524            CmsProperty currentProperty = getCms().readPropertyObject(
1525                resPath,
1526                CmsPropertyDefinition.PROPERTY_TITLE,
1527                false);
1528            // detect if property is a null property or not
1529
if (currentProperty.isNullProperty()) {
1530                // create new property object and set key and value
1531
currentProperty = new CmsProperty();
1532                currentProperty.setName(CmsPropertyDefinition.PROPERTY_TITLE);
1533                if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
1534                    // set structure value
1535
currentProperty.setStructureValue(currentPropertyValue);
1536                    currentProperty.setResourceValue(null);
1537                } else {
1538                    // set resource value
1539
currentProperty.setStructureValue(null);
1540                    currentProperty.setResourceValue(currentPropertyValue);
1541                }
1542            } else if (currentProperty.getStructureValue() != null) {
1543                // structure value has to be updated
1544
currentProperty.setStructureValue(currentPropertyValue);
1545                currentProperty.setResourceValue(null);
1546            } else {
1547                // resource value has to be updated
1548
currentProperty.setStructureValue(null);
1549                currentProperty.setResourceValue(currentPropertyValue);
1550            }
1551            CmsLock lock = getCms().getLock(res);
1552            if (lock.getType() == CmsLock.TYPE_UNLOCKED) {
1553                // lock resource before operation
1554
getCms().lockResource(resPath);
1555            }
1556            // write the property to the resource
1557
getCms().writePropertyObject(resPath, currentProperty);
1558            // unlock the resource
1559
getCms().unlockResource(resPath);
1560        } catch (CmsException e) {
1561            // writing the property failed, log error
1562
LOG.error(e);
1563        }
1564    }
1565}
Popular Tags