KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > explorer > CmsExplorer


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsExplorer.java,v $
3  * Date : $Date: 2006/07/21 12:01:54 $
4  * Version: $Revision: 1.34 $
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.explorer;
33
34 import org.opencms.db.CmsDbUtil;
35 import org.opencms.db.CmsUserSettings;
36 import org.opencms.file.CmsFolder;
37 import org.opencms.file.CmsObject;
38 import org.opencms.file.CmsProject;
39 import org.opencms.file.CmsPropertyDefinition;
40 import org.opencms.file.CmsResource;
41 import org.opencms.file.CmsResourceFilter;
42 import org.opencms.file.collectors.I_CmsResourceCollector;
43 import org.opencms.file.types.CmsResourceTypePlain;
44 import org.opencms.i18n.CmsEncoder;
45 import org.opencms.jsp.CmsJspActionElement;
46 import org.opencms.lock.CmsLock;
47 import org.opencms.main.CmsException;
48 import org.opencms.main.CmsLog;
49 import org.opencms.main.CmsRuntimeException;
50 import org.opencms.main.OpenCms;
51 import org.opencms.util.CmsStringUtil;
52 import org.opencms.workplace.CmsWorkplace;
53 import org.opencms.workplace.CmsWorkplaceSettings;
54 import org.opencms.workplace.commons.CmsTouch;
55 import org.opencms.workplace.galleries.A_CmsGallery;
56
57 import java.util.ArrayList JavaDoc;
58 import java.util.Collections JavaDoc;
59 import java.util.List JavaDoc;
60
61 import javax.servlet.http.HttpServletRequest JavaDoc;
62
63 import org.apache.commons.logging.Log;
64
65 /**
66  * Provides methods for building the main framesets of the OpenCms Workplace.<p>
67  *
68  * The following files use this class:
69  * <ul>
70  * <li>/views/explorer/explorer_fs.jsp
71  * <li>/views/explorer/explorer_files.jsp
72  * <li>/views/explorer/explorer_body_fs.jsp
73  * </ul>
74  * <p>
75  *
76  * @author Alexander Kandzior
77  *
78  * @version $Revision: 1.34 $
79  *
80  * @since 6.0.0
81  */

82 public class CmsExplorer extends CmsWorkplace {
83
84     /** Layoutstyle for resources after expire date. */
85     public static final int LAYOUTSTYLE_AFTEREXPIRE = 2;
86
87     /** Layoutstyle for resources before release date. */
88     public static final int LAYOUTSTYLE_BEFORERELEASE = 1;
89
90     /** Layoutstyle for resources after release date and before expire date. */
91     public static final int LAYOUTSTYLE_INRANGE = 0;
92
93     /** The "mode" parameter. */
94     public static final String JavaDoc PARAMETER_MODE = "mode";
95
96     /** The "list" view selection. */
97     public static final String JavaDoc VIEW_LIST = "listview";
98
99     /** The "siblings:" location prefix for VFS sibling display. */
100     private static final String JavaDoc LOCATION_SIBLING = "siblings:";
101
102     /** The log object for this class. */
103     private static final Log LOG = CmsLog.getLog(CmsExplorer.class);
104
105     /** The "flaturl" parameter. */
106     private static final String JavaDoc PARAMETER_FLATURL = "flaturl";
107
108     /** The "page" parameter. */
109     private static final String JavaDoc PARAMETER_PAGE = "page";
110
111     /** The "resource" parameter. */
112     private static final String JavaDoc PARAMETER_RESOURCE = "resource";
113
114     /** The "showlinks" parameter. */
115     private static final String JavaDoc PARAMETER_SHOWLINKS = "showlinks";
116
117     /** The "explorerview" view selection. */
118     public static final String JavaDoc VIEW_EXPLORER = "explorerview";
119
120     /** The "galleryview" view selection. */
121     public static final String JavaDoc VIEW_GALLERY = "galleryview";
122
123     /**
124      * Public constructor.<p>
125      *
126      * @param jsp an initialized JSP action element
127      */

128     public CmsExplorer(CmsJspActionElement jsp) {
129
130         super(jsp);
131     }
132
133     /**
134      * Returns the html for the explorer file list.<p>
135      *
136      * @return the html for the explorer file list
137      */

138     public String JavaDoc getFileList() {
139
140         // if mode is "listonly", only the list will be shown
141
boolean galleryView = VIEW_GALLERY.equals(getSettings().getExplorerMode());
142         // if mode is "listview", all file in the set collector will be shown
143
boolean listView = VIEW_LIST.equals(getSettings().getExplorerMode());
144         // if VFS links should be displayed, this is true
145
boolean showVfsLinks = getSettings().getExplorerShowLinks();
146
147         CmsResource currentResource = null;
148
149         String JavaDoc currentFolder = getSettings().getExplorerResource();
150         boolean found = true;
151         try {
152             currentResource = getCms().readResource(currentFolder, CmsResourceFilter.ALL);
153         } catch (CmsException e) {
154             // file was not readable
155
found = false;
156         }
157         if (found) {
158             if (showVfsLinks) {
159                 // file / folder exists and is readable
160
currentFolder = LOCATION_SIBLING + currentFolder;
161             }
162         } else {
163             // show the root folder in case of an error and reset the state
164
currentFolder = "/";
165             showVfsLinks = false;
166             try {
167                 currentResource = getCms().readResource(currentFolder, CmsResourceFilter.ALL);
168             } catch (CmsException e) {
169                 // should usually never happen
170
LOG.error(e);
171                 throw new CmsRuntimeException(e.getMessageContainer(), e);
172             }
173         }
174
175         // start creating content
176
StringBuffer JavaDoc content = new StringBuffer JavaDoc(2048);
177         content.append("function initialize() {\n");
178
179         content.append("top.setRootFolder(\"");
180         String JavaDoc rootFolder = getRootFolder();
181         content.append(rootFolder);
182         content.append("\");\n");
183
184         content.append("top.mode=\"");
185         content.append(getSettings().getExplorerMode());
186         content.append("\";\n");
187
188         content.append("top.showlinks=");
189         content.append(showVfsLinks);
190         content.append(";\n");
191
192         // the resource id of plain resources
193
content.append("top.plainresid=");
194         content.append(CmsResourceTypePlain.getStaticTypeId());
195         content.append(";\n");
196
197         // the autolock setting
198
content.append("top.autolock=");
199         content.append(OpenCms.getWorkplaceManager().autoLockResources());
200         content.append(";\n");
201
202         // the button type setting
203
content.append("top.buttonType=");
204         content.append(getSettings().getUserSettings().getExplorerButtonStyle());
205         content.append(";\n");
206
207         // the help_url
208
content.append("top.head.helpUrl='explorer/index.html';\n");
209         // the project
210
content.append("top.setProject(");
211         if (!listView) {
212             content.append(getSettings().getProject());
213         } else {
214             content.append(getSettings().getExplorerProjectId());
215         }
216         content.append(");\n");
217         // the onlineProject
218
content.append("top.setOnlineProject(");
219         content.append(CmsProject.ONLINE_PROJECT_ID);
220         content.append(");\n");
221         // set the writeAccess for the current Folder
222
boolean writeAccess = VIEW_EXPLORER.equals(getSettings().getExplorerMode());
223         if (writeAccess && (!showVfsLinks)) {
224             writeAccess = getCms().isInsideCurrentProject(currentFolder);
225         }
226         content.append("top.enableNewButton(");
227         content.append(writeAccess);
228         content.append(");\n");
229         // the folder
230
content.append("top.setDirectory(\"");
231         content.append(CmsResource.getFolderPath(currentResource.getRootPath()));
232         content.append("\",\"");
233         if (showVfsLinks) {
234             content.append(LOCATION_SIBLING);
235             content.append(getSettings().getExplorerResource());
236         } else {
237             content.append(CmsResource.getFolderPath(getSettings().getExplorerResource()));
238         }
239         content.append("\");\n");
240         content.append("top.rD();\n");
241         List JavaDoc reloadTreeFolders = (List JavaDoc)getJsp().getRequest().getAttribute(REQUEST_ATTRIBUTE_RELOADTREE);
242         if (reloadTreeFolders != null) {
243             // folder tree has to be reloaded after copy, delete, move, rename operation
244
String JavaDoc reloadFolder = "";
245             for (int i = 0; i < reloadTreeFolders.size(); i++) {
246                 reloadFolder = (String JavaDoc)reloadTreeFolders.get(i);
247                 if (getSettings().getUserSettings().getRestrictExplorerView()) {
248                     // in restricted view, adjust folder path to reload: remove restricted folder name
249
reloadFolder = reloadFolder.substring(rootFolder.length() - 1);
250                 }
251                 content.append("top.addNodeToLoad(\"" + reloadFolder + "\");\n");
252             }
253             content.append("top.reloadNodeList();\n");
254         }
255         content.append("\n");
256
257         // now check which filelist colums we want to show
258
int preferences = getUserPreferences();
259
260         boolean showTitle = (preferences & CmsUserSettings.FILELIST_TITLE) > 0;
261         boolean showPermissions = (preferences & CmsUserSettings.FILELIST_PERMISSIONS) > 0;
262         boolean showDateLastModified = (preferences & CmsUserSettings.FILELIST_DATE_LASTMODIFIED) > 0;
263         boolean showUserWhoLastModified = (preferences & CmsUserSettings.FILELIST_USER_LASTMODIFIED) > 0;
264         boolean showDateCreated = (preferences & CmsUserSettings.FILELIST_DATE_CREATED) > 0;
265         boolean showUserWhoCreated = (preferences & CmsUserSettings.FILELIST_USER_CREATED) > 0;
266         boolean showDateReleased = (preferences & CmsUserSettings.FILELIST_DATE_RELEASED) > 0;
267         boolean showDateExpired = (preferences & CmsUserSettings.FILELIST_DATE_EXPIRED) > 0;
268
269         // now get the entries for the filelist
270
List JavaDoc resources = getResources(getSettings().getExplorerResource());
271
272         // if a folder contains to much entrys we split them to pages of C_ENTRYS_PER_PAGE length
273
int startat = 0;
274         int stopat = resources.size();
275         int selectedPage = 1;
276         int numberOfPages = 0;
277         int maxEntrys = getSettings().getUserSettings().getExplorerFileEntries();
278
279         if (!(galleryView || showVfsLinks)) {
280             selectedPage = getSettings().getExplorerPage();
281             if (stopat > maxEntrys) {
282                 // we have to split
283
numberOfPages = (stopat / maxEntrys) + 1;
284                 if (selectedPage > numberOfPages) {
285                     // the user has changed the folder and then selected a page for the old folder
286
selectedPage = 1;
287                 }
288                 startat = (selectedPage - 1) * maxEntrys;
289                 if ((startat + maxEntrys) < stopat) {
290                     stopat = startat + maxEntrys;
291                 }
292             }
293         }
294         // set the right project
295
CmsProject project;
296         try {
297             if (!listView) {
298                 project = getCms().readProject(getSettings().getProject());
299             } else {
300                 project = getCms().readProject(getSettings().getExplorerProjectId());
301             }
302         } catch (CmsException ex) {
303             project = getCms().getRequestContext().currentProject();
304         }
305
306         // read the list of project resource to select which resource is "inside" or "outside"
307
List JavaDoc projectResources;
308         try {
309             projectResources = getCms().readProjectResources(project);
310         } catch (CmsException e) {
311             // use an empty list (all resources are "outside")
312
if (LOG.isInfoEnabled()) {
313                 LOG.info(e);
314             }
315             projectResources = new ArrayList JavaDoc();
316         }
317
318         for (int i = startat; i < stopat; i++) {
319             CmsResource res = (CmsResource)resources.get(i);
320             CmsLock lock = null;
321             String JavaDoc path = getCms().getSitePath(res);
322
323             try {
324                 lock = getCms().getLock(res);
325             } catch (CmsException e) {
326                 lock = CmsLock.getNullLock();
327
328                 LOG.error(e);
329             }
330
331             content.append("top.aF(");
332
333             // position 1: name
334
content.append("\"");
335             content.append(res.getName());
336             content.append("\",");
337
338             // position 2: path
339
if (showVfsLinks || galleryView || listView) {
340                 content.append("\"");
341                 content.append(path);
342                 content.append("\",");
343             } else {
344                 //is taken from top.setDirectory
345
content.append("\"\",");
346             }
347
348             // position 3: title
349
if (showTitle) {
350                 String JavaDoc title = "";
351                 try {
352                     title = getCms().readPropertyObject(
353                         getCms().getSitePath(res),
354                         CmsPropertyDefinition.PROPERTY_TITLE,
355                         false).getValue();
356                 } catch (CmsException e) {
357                     getCms().getRequestContext().saveSiteRoot();
358                     try {
359                         getCms().getRequestContext().setSiteRoot("/");
360                         title = getCms().readPropertyObject(
361                             res.getRootPath(),
362                             CmsPropertyDefinition.PROPERTY_TITLE,
363                             false).getValue();
364                     } catch (Exception JavaDoc e1) {
365                         // should usually never happen
366
if (LOG.isInfoEnabled()) {
367                             LOG.info(e);
368                         }
369                     } finally {
370                         getCms().getRequestContext().restoreSiteRoot();
371                     }
372                 }
373                 content.append("\"");
374                 if (title != null) {
375                     content.append(CmsEncoder.escapeWBlanks(title, CmsEncoder.ENCODING_UTF_8));
376                 }
377                 content.append("\",");
378
379             } else {
380                 content.append("\"\",");
381             }
382
383             // position 4: type
384
content.append(res.getTypeId());
385             content.append(",");
386
387             // position 5: link count
388
if (res.getSiblingCount() > 1) {
389                 // links are present
390
if (res.isLabeled()) {
391                     // there is at least one link in a marked site
392
content.append("2");
393                 } else {
394                     // common links are present
395
content.append("1");
396                 }
397             } else {
398                 // no links to the resource are in the VFS
399
content.append("0");
400             }
401             content.append(",");
402
403             // position 6: size
404
content.append(res.getLength());
405             content.append(",");
406
407             // position 7: state
408
content.append(res.getState());
409             content.append(",");
410
411             // position 8: layoutstyle
412
int layoutstyle = CmsExplorer.LAYOUTSTYLE_INRANGE;
413             if (res.getDateReleased() > getCms().getRequestContext().getRequestTime()) {
414                 layoutstyle = CmsExplorer.LAYOUTSTYLE_BEFORERELEASE;
415             } else if ((res.getDateExpired() < getCms().getRequestContext().getRequestTime())) {
416                 layoutstyle = CmsExplorer.LAYOUTSTYLE_AFTEREXPIRE;
417             }
418             content.append(layoutstyle);
419             content.append(',');
420
421             // position 9: project
422
int projectId = res.getProjectLastModified();
423             if (!lock.isNullLock()
424                 && lock.getType() != CmsLock.TYPE_INHERITED
425                 && lock.getType() != CmsLock.TYPE_SHARED_INHERITED) {
426                 // use lock project ID only if lock is not inherited
427
projectId = lock.getProjectId();
428             }
429             content.append(projectId);
430             content.append(",");
431
432             // position 10: date of last modification
433
if (showDateLastModified) {
434                 content.append("\"");
435                 content.append(getMessages().getDateTime(res.getDateLastModified()));
436                 content.append("\",");
437
438             } else {
439                 content.append("\"\",");
440             }
441
442             // position 11: user who last modified the resource
443
if (showUserWhoLastModified) {
444                 content.append("\"");
445                 try {
446                     content.append(getCms().readUser(res.getUserLastModified()).getName());
447                 } catch (CmsException e) {
448                     content.append(res.getUserLastModified().toString());
449                 }
450                 content.append("\",");
451             } else {
452                 content.append("\"\",");
453             }
454
455             // position 12: date of creation
456
if (showDateCreated) {
457                 content.append("\"");
458                 content.append(getMessages().getDateTime(res.getDateCreated()));
459                 content.append("\",");
460
461             } else {
462                 content.append("\"\",");
463             }
464
465             // position 13 : user who created the resource
466
if (showUserWhoCreated) {
467                 content.append("\"");
468                 try {
469                     content.append(getCms().readUser(res.getUserCreated()).getName());
470                 } catch (CmsException e) {
471                     content.append(res.getUserCreated().toString());
472                 }
473                 content.append("\",");
474             } else {
475                 content.append("\"\",");
476             }
477
478             // position 14: date of release
479
if (showDateReleased) {
480                 content.append("\"");
481                 long release = res.getDateReleased();
482                 if (release != CmsResource.DATE_RELEASED_DEFAULT) {
483                     content.append(getMessages().getDateTime(release));
484                 } else {
485                     content.append(CmsTouch.DEFAULT_DATE_STRING);
486                 }
487                 content.append("\",");
488
489             } else {
490                 content.append("\"\",");
491             }
492
493             // position 15: date of expiration
494
if (showDateExpired) {
495                 content.append("\"");
496                 long expire = res.getDateExpired();
497                 if (expire != CmsResource.DATE_EXPIRED_DEFAULT) {
498                     content.append(getMessages().getDateTime(expire));
499                 } else {
500                     content.append(CmsTouch.DEFAULT_DATE_STRING);
501                 }
502                 content.append("\",");
503
504             } else {
505                 content.append("\"\",");
506             }
507
508             // position 16: permissions
509
if (showPermissions) {
510                 content.append("\"");
511                 try {
512                     content.append(getCms().getPermissions(getCms().getSitePath(res)).getPermissionString());
513                 } catch (CmsException e) {
514                     getCms().getRequestContext().saveSiteRoot();
515                     try {
516                         getCms().getRequestContext().setSiteRoot("/");
517                         content.append(getCms().getPermissions(res.getRootPath()).getPermissionString());
518                     } catch (Exception JavaDoc e1) {
519                         content.append(CmsStringUtil.escapeJavaScript(e1.getMessage()));
520                     } finally {
521                         getCms().getRequestContext().restoreSiteRoot();
522                     }
523                 }
524                 content.append("\",");
525             } else {
526                 content.append("\"\",");
527             }
528
529             // position 17: locked by
530
if (lock.isNullLock()) {
531                 content.append("\"\",");
532             } else {
533                 content.append("\"");
534                 try {
535                     content.append(getCms().readUser(lock.getUserId()).getName());
536                 } catch (CmsException e) {
537                     content.append(CmsStringUtil.escapeJavaScript(e.getMessage()));
538                 }
539                 content.append("\",");
540             }
541
542             // position 18: type of lock
543
content.append(lock.getType());
544             content.append(",");
545
546             // position 19: name of project where the resource is locked in
547
int lockedInProject = CmsDbUtil.UNKNOWN_ID;
548             if (lock.isNullLock() && res.getState() != CmsResource.STATE_UNCHANGED) {
549                 // resource is unlocked and modified
550
lockedInProject = res.getProjectLastModified();
551             } else {
552                 if (res.getState() != CmsResource.STATE_UNCHANGED) {
553                     // resource is locked and modified
554
lockedInProject = projectId;
555                 } else {
556                     // resource is locked and unchanged
557
lockedInProject = lock.getProjectId();
558                 }
559             }
560             String JavaDoc lockedInProjectName;
561             try {
562                 if (lockedInProject == CmsDbUtil.UNKNOWN_ID) {
563                     // the resource is unlocked and unchanged
564
lockedInProjectName = "";
565                 } else {
566                     lockedInProjectName = getCms().readProject(lockedInProject).getName();
567                 }
568             } catch (CmsException exc) {
569                 // where did my project go?
570
if (LOG.isInfoEnabled()) {
571                     LOG.info(exc);
572                 }
573                 lockedInProjectName = "";
574             }
575             content.append("\"");
576             content.append(lockedInProjectName);
577             content.append("\",");
578
579             // position 20: id of project where resource belongs to
580
content.append(lockedInProject);
581             content.append(",\"");
582
583             // position 21: project state, I=resource is inside current project, O=resource is outside current project
584
if (CmsProject.isInsideProject(projectResources, res)) {
585                 content.append("I");
586             } else {
587                 content.append("O");
588             }
589             content.append("\"");
590             content.append(");\n");
591         }
592
593         content.append("top.dU(document,");
594         content.append(numberOfPages);
595         content.append(",");
596         content.append(selectedPage);
597         content.append("); \n");
598
599         // display eventual error message
600
if (getSettings().getErrorMessage() != null) {
601             // display error message as JavaScript alert
602
content.append("alert(\"");
603             content.append(CmsStringUtil.escapeJavaScript(getSettings().getErrorMessage().key(getLocale())));
604             content.append("\");\n");
605             // delete error message container in settings
606
getSettings().setErrorMessage(null);
607         }
608
609         // display eventual broadcast message(s)
610
String JavaDoc message = getBroadcastMessageString();
611         if (CmsStringUtil.isNotEmpty(message)) {
612             // display broadcast as JavaScript alert
613
content.append("alert(decodeURIComponent(\"");
614             // the user has pending messages, display them all
615
content.append(CmsEncoder.escapeWBlanks(message, CmsEncoder.ENCODING_UTF_8));
616             content.append("\"));\n");
617         }
618
619         content.append("}\n");
620         return content.toString();
621     }
622
623     /**
624      * Determines the root folder of the current tree dependent on users setting of explorer view restriction.<p>
625      *
626      * @return the root folder resource name to display
627      */

628     public String JavaDoc getRootFolder() {
629
630         String JavaDoc folder = "/";
631         if (getSettings().getUserSettings().getRestrictExplorerView()) {
632             folder = getSettings().getUserSettings().getStartFolder();
633         }
634         try {
635             getCms().readFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION);
636             return folder;
637         } catch (CmsException e) {
638             // should usually never happen
639
if (LOG.isInfoEnabled()) {
640                 LOG.info(e);
641             }
642             return "/";
643         }
644     }
645
646     /**
647      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
648      */

649     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
650
651         String JavaDoc currentResource = request.getParameter(PARAMETER_RESOURCE);
652         String JavaDoc mode = request.getParameter(PARAMETER_MODE);
653         if (CmsStringUtil.isNotEmpty(mode)) {
654             settings.setExplorerMode(mode);
655         } else {
656             // null argument, use explorer view if no other view currently specified
657
if (!(VIEW_GALLERY.equals(settings.getExplorerMode()) || VIEW_LIST.equals(settings.getExplorerMode()))) {
658                 settings.setExplorerMode(VIEW_EXPLORER);
659             }
660         }
661
662         boolean showLinks = Boolean.valueOf(request.getParameter(PARAMETER_SHOWLINKS)).booleanValue();
663
664         if (showLinks) {
665             // "showlinks" parameter found, set resource name
666
settings.setExplorerResource(currentResource);
667         } else {
668             // "showlinks" parameter not found
669
if (currentResource != null && currentResource.startsWith(LOCATION_SIBLING)) {
670                 // given resource starts with "siblings:", list of siblings is shown
671
showLinks = true;
672                 settings.setExplorerResource(currentResource.substring(LOCATION_SIBLING.length()));
673             } else {
674                 if (CmsStringUtil.isNotEmpty(currentResource) && folderExists(getCms(), currentResource)) {
675                     // resource is a folder, set resource name
676
settings.setExplorerResource(currentResource);
677                 } else {
678                     // other cases (resource null, no folder), first get the resource name from settings
679
showLinks = settings.getExplorerShowLinks();
680                     currentResource = settings.getExplorerResource();
681                     if (!resourceExists(getCms(), currentResource)) {
682                         // resource does not exist, display root folder
683
settings.setExplorerResource("/");
684                         showLinks = false;
685                     }
686                 }
687             }
688         }
689         settings.setExplorerShowLinks(showLinks);
690
691         String JavaDoc selectedPage = request.getParameter(PARAMETER_PAGE);
692         if (selectedPage != null) {
693             int page = 1;
694             try {
695                 page = Integer.parseInt(selectedPage);
696             } catch (NumberFormatException JavaDoc e) {
697                 // default is 1
698
if (LOG.isInfoEnabled()) {
699                     LOG.info(e);
700                 }
701             }
702             settings.setExplorerPage(page);
703         }
704
705         // the flaturl
706
settings.setExplorerFlaturl(request.getParameter(PARAMETER_FLATURL));
707     }
708
709     /**
710      * Checks if a folder with a given name exits in the VFS.<p>
711      *
712      * @param cms the current cms context
713      * @param folder the folder to check for
714      * @return true if the folder exists in the VFS
715      */

716     private boolean folderExists(CmsObject cms, String JavaDoc folder) {
717
718         try {
719             CmsFolder test = cms.readFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION);
720             if (test.isFile()) {
721                 return false;
722             }
723             return true;
724         } catch (Exception JavaDoc e) {
725             return false;
726         }
727     }
728
729     /**
730      * Returns a list resources that should be displayed in the
731      * OpenCms Exlorer.<p>
732      *
733      * How the list is build depends on the current Workplace settings
734      * of the user.
735      *
736      * @param resource the resource to read the files from (usually a folder)
737      * @return a list of resources to display
738      */

739     private List JavaDoc getResources(String JavaDoc resource) {
740
741         if (getSettings().getExplorerShowLinks()) {
742             // show all siblings of a resource
743
try {
744                 // also return "invisible" siblings (the user might get confused if not all are returned)
745
return getCms().readSiblings(resource, CmsResourceFilter.ALL);
746             } catch (CmsException e) {
747                 // should usually never happen
748
if (LOG.isInfoEnabled()) {
749                     LOG.info(e);
750                 }
751                 return Collections.EMPTY_LIST;
752             }
753         } else if (VIEW_LIST.equals(getSettings().getExplorerMode())) {
754
755             // check if the list must show the list view or the check content view
756
I_CmsResourceCollector collector = getSettings().getCollector();
757             if (collector != null) {
758                 // is this the collector for the list view
759
try {
760                     return collector.getResults(getCms());
761                 } catch (CmsException e) {
762                     if (LOG.isInfoEnabled()) {
763                         LOG.info(e);
764                     }
765                 }
766             }
767
768             return Collections.EMPTY_LIST;
769         } else if (VIEW_GALLERY.equals(getSettings().getExplorerMode())) {
770
771             // select galleries
772
A_CmsGallery gallery = A_CmsGallery.createInstance(getSettings().getGalleryType(), getJsp());
773             return gallery.getGalleries();
774         } else {
775             // default is to return a list of all files in the folder
776
try {
777                 return getCms().getResourcesInFolder(resource, CmsResourceFilter.ONLY_VISIBLE);
778             } catch (CmsException e) {
779                 // should usually never happen
780
if (LOG.isInfoEnabled()) {
781                     LOG.info(e);
782                 }
783                 return Collections.EMPTY_LIST;
784             }
785         }
786     }
787
788     /**
789      * Sets the default preferences for the current user if those values are not available.<p>
790      *
791      * @return the int value of the default preferences
792      */

793     private int getUserPreferences() {
794
795         CmsUserSettings settings = new CmsUserSettings(getCms());
796         return settings.getExplorerSettings();
797     }
798
799     /**
800      * Checks if a resource with a given name exits in the VFS.<p>
801      *
802      * @param cms the current cms context
803      * @param resource the resource to check for
804      * @return true if the resource exists in the VFS
805      */

806     private boolean resourceExists(CmsObject cms, String JavaDoc resource) {
807
808         try {
809             cms.readResource(resource, CmsResourceFilter.ALL);
810             return true;
811         } catch (CmsException e) {
812             return false;
813         }
814     }
815 }
Popular Tags