KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsTree.java,v $
3  * Date : $Date: 2006/03/27 14:52:30 $
4  * Version: $Revision: 1.23 $
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.file.CmsFolder;
35 import org.opencms.file.CmsObject;
36 import org.opencms.file.CmsProject;
37 import org.opencms.file.CmsProperty;
38 import org.opencms.file.CmsPropertyDefinition;
39 import org.opencms.file.CmsResource;
40 import org.opencms.file.CmsResourceFilter;
41 import org.opencms.file.types.I_CmsResourceType;
42 import org.opencms.i18n.CmsMessages;
43 import org.opencms.jsp.CmsJspActionElement;
44 import org.opencms.main.CmsException;
45 import org.opencms.main.CmsLog;
46 import org.opencms.main.OpenCms;
47 import org.opencms.security.CmsPermissionSet;
48 import org.opencms.site.CmsSite;
49 import org.opencms.site.CmsSiteManager;
50 import org.opencms.workplace.CmsWorkplace;
51 import org.opencms.workplace.CmsWorkplaceSettings;
52
53 import java.util.ArrayList JavaDoc;
54 import java.util.Iterator JavaDoc;
55 import java.util.List JavaDoc;
56 import java.util.Locale JavaDoc;
57 import java.util.StringTokenizer JavaDoc;
58
59 import javax.servlet.http.HttpServletRequest JavaDoc;
60
61 import org.apache.commons.logging.Log;
62
63 /**
64  * Generates the tree view for the OpenCms Workplace.<p>
65  *
66  * The following Workplace files use this class:
67  * <ul>
68  * <li>/views/explorer/tree_fs.jsp
69  * <li>/views/explorer/tree_files.jsp
70  * </ul>
71  * <p>
72  *
73  * @author Alexander Kandzior
74  *
75  * @version $Revision: 1.23 $
76  *
77  * @since 6.0.0
78  */

79 public class CmsTree extends CmsWorkplace {
80
81     /** Request parameter name for the includesfiles parameter. */
82     public static final String JavaDoc PARAM_INCLUDEFILES = "includefiles";
83
84     /** Request parameter name for the lastknown parameter. */
85     public static final String JavaDoc PARAM_LASTKNOWN = "lastknown";
86
87     /** Request parameter name for the resource parameter. */
88     public static final String JavaDoc PARAM_RESOURCE = "resource";
89
90     /** Request parameter name for the rootloaded parameter. */
91     public static final String JavaDoc PARAM_ROOTLOADED = "rootloaded";
92
93     /** Request parameter name for the showsiteselector parameter. */
94     public static final String JavaDoc PARAM_SHOWSITESELECTOR = "showsiteselector";
95
96     /** Request parameter name for the treesite parameter. */
97     public static final String JavaDoc PARAM_TREESITE = "treesite";
98
99     /** Request parameter name for the type parameter. */
100     public static final String JavaDoc PARAM_TYPE = "type";
101
102     /** The log object for this class. */
103     private static final Log LOG = CmsLog.getLog(CmsTree.class);
104
105     /** Type name for showing the tree when copying resources. */
106     private static final String JavaDoc TYPE_COPY = "copy";
107
108     /** Type name for showing the tree when creating page links in the editor. */
109     private static final String JavaDoc TYPE_PAGELINK = "pagelink";
110
111     /** Type name for showing the tree in preferences dialog. */
112     private static final String JavaDoc TYPE_PREFERENCES = "preferences";
113
114     /** Type name for showing the tree when creating siblings. */
115     private static final String JavaDoc TYPE_SIBLING = "sibling";
116
117     /** Type name for showing the tree in a widget dialog. */
118     private static final String JavaDoc TYPE_VFSWIDGET = "vfswidget";
119
120     /** Indicates if only folders or files and folders should be included in the tree. */
121     private boolean m_includeFiles;
122
123     /** Indicates if a complete new tree should be created. */
124     private boolean m_newTree;
125
126     /** The name of the root folder to dsiplay the tree from, usually "/". */
127     private String JavaDoc m_rootFolder;
128
129     /** Flag to indicate if the site selector should be shown in popup tree window. */
130     private boolean m_showSiteSelector;
131
132     /** The name of the start folder (or "last known" folder) to be loaded. */
133     private String JavaDoc m_startFolder;
134
135     /** The name of the target folder to be loaded. */
136     private String JavaDoc m_targetFolder;
137
138     /** The type of the tree (e.g. "copy", "project" etc.). */
139     private String JavaDoc m_treeType;
140
141     /**
142      * Public constructor.<p>
143      *
144      * @param jsp an initialized JSP action element
145      */

146     public CmsTree(CmsJspActionElement jsp) {
147
148         super(jsp);
149     }
150
151     /**
152      * Returns the HTML for the tree initialization.<p>
153      *
154      * @param cms the CmsObject
155      * @param encoding the current encoding
156      * @param skinUri the current skin URI
157      * @return the HTML for the tree initialization
158      */

159     public static String JavaDoc initTree(CmsObject cms, String JavaDoc encoding, String JavaDoc skinUri) {
160
161         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc(512);
162         String JavaDoc servletUrl = OpenCms.getSystemInfo().getOpenCmsContext();
163
164         // get the localized workplace messages
165
// TODO: Why a new message object, can it not be obtained from session?
166
Locale JavaDoc locale = cms.getRequestContext().getLocale();
167         CmsMessages messages = OpenCms.getWorkplaceManager().getMessages(locale);
168
169         retValue.append("function initTreeResources() {\n");
170         retValue.append("\tinitResources(\"");
171         retValue.append(encoding);
172         retValue.append("\", \"");
173         retValue.append(PATH_WORKPLACE);
174         retValue.append("\", \"");
175         retValue.append(skinUri);
176         retValue.append("\", \"");
177         retValue.append(servletUrl);
178         retValue.append("\");\n");
179
180         // get all available resource types
181
List JavaDoc allResTypes = OpenCms.getResourceManager().getResourceTypes();
182         for (int i = 0; i < allResTypes.size(); i++) {
183             // loop through all types
184
I_CmsResourceType type = (I_CmsResourceType)allResTypes.get(i);
185             int curTypeId = type.getTypeId();
186             String JavaDoc curTypeName = type.getTypeName();
187             // get the settings for the resource type
188
CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(curTypeName);
189             // determine if this resource type is editable for the current user
190
CmsPermissionSet permissions = settings.getAccess().getPermissions(cms);
191             if (permissions.requiresWritePermission()) {
192                 // user is allowed to write this resource type
193
retValue.append("\taddResourceType(");
194                 retValue.append(curTypeId);
195                 retValue.append(", \"");
196                 retValue.append(curTypeName);
197                 retValue.append("\",\t\"");
198                 retValue.append(messages.key(settings.getKey()));
199                 retValue.append("\",\t\"filetypes/");
200                 retValue.append(settings.getIcon());
201                 retValue.append("\");\n");
202             }
203         }
204
205         retValue.append("}\n\n");
206         retValue.append("initTreeResources();\n");
207
208         return retValue.toString();
209     }
210
211     /**
212      * Determines the root folder of the current tree dependent on users setting of explorer view restriction.<p>
213      *
214      * @return the root folder resource name to display
215      */

216     public String JavaDoc getRootFolder() {
217
218         if (m_rootFolder == null) {
219             String JavaDoc folder = "/";
220             if (getTreeType() == null && getSettings().getUserSettings().getRestrictExplorerView()) {
221                 folder = getSettings().getUserSettings().getStartFolder();
222             }
223             try {
224                 getCms().readFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION);
225             } catch (CmsException e) {
226                 if (LOG.isInfoEnabled()) {
227                     LOG.info(e);
228                 }
229                 folder = "/";
230             }
231             m_rootFolder = folder;
232         }
233         return m_rootFolder;
234     }
235
236     /**
237      * Returns the HTML for the site selector box for the explorer tree window.<p>
238      *
239      * @param htmlAttributes optional attributes for the &lt;select&gt; tag
240      * @return HTML code for the site selector box
241      */

242     public String JavaDoc getSiteSelector(String JavaDoc htmlAttributes) {
243
244         List JavaDoc options = new ArrayList JavaDoc();
245         List JavaDoc values = new ArrayList JavaDoc();
246         int selectedIndex = 0;
247         String JavaDoc preSelection = getSettings().getTreeSite(getTreeType());
248         if (preSelection == null) {
249             if ("".equals(getCms().getRequestContext().getSiteRoot())) {
250                 // we are in the root site, getCurrentSite(CmsObject) includes NOT the root site
251
preSelection = "";
252             } else {
253                 // get the site root of the current site
254
preSelection = CmsSiteManager.getCurrentSite(getCms()).getSiteRoot();
255             }
256             // set the tree site to avoid discrepancies between selector and tree
257
getSettings().setTreeSite(getTreeType(), preSelection);
258         }
259
260         boolean includeRootSite = true;
261         boolean showSiteUrls = false;
262         if (TYPE_PAGELINK.equals(getTreeType())) {
263             // in wysiwyg editor link dialog, don't show root site, but show site URLs
264
includeRootSite = false;
265             showSiteUrls = true;
266         }
267         List JavaDoc sites = CmsSiteManager.getAvailableSites(getCms(), includeRootSite);
268
269         Iterator JavaDoc i = sites.iterator();
270         int pos = 0;
271         while (i.hasNext()) {
272             CmsSite site = (CmsSite)i.next();
273             values.add(site.getSiteRoot());
274             String JavaDoc curOption = site.getTitle();
275             if (showSiteUrls) {
276                 // show the site URL in editor link dialog tree
277
curOption = site.getUrl() + " (" + curOption + ")";
278                 if (getCms().getRequestContext().getSiteRoot().equals(site.getSiteRoot())) {
279                     // mark the current workplace site in selector
280
curOption = "*" + curOption;
281                 }
282             }
283
284             if (site.getSiteRoot().equals(preSelection)) {
285                 // this is the user's currently selected site
286
selectedIndex = pos;
287             }
288             options.add(curOption);
289             pos++;
290         }
291
292         return buildSelect(htmlAttributes, options, values, selectedIndex);
293     }
294
295     /**
296      * Returns the html for the explorer tree.<p>
297      *
298      * @return the html for the explorer tree
299      */

300     public String JavaDoc getTree() {
301
302         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
303         String JavaDoc targetFolder = getTargetFolder();
304         String JavaDoc startFolder = getStartFolder();
305         List JavaDoc targetFolderList = new ArrayList JavaDoc();
306         boolean grey;
307         List JavaDoc resources = new ArrayList JavaDoc();
308         CmsFolder folder = null;
309         String JavaDoc oldSiteRoot = getCms().getRequestContext().getSiteRoot();
310         boolean restoreSiteRoot = false;
311
312         if (targetFolder != null) {
313             // check if there is more than one folder to update (e.g. move operation)
314
StringTokenizer JavaDoc T = new StringTokenizer JavaDoc(targetFolder, "|");
315             while (T.hasMoreTokens()) {
316                 String JavaDoc currentFolder = T.nextToken().trim();
317                 targetFolderList.add(currentFolder);
318             }
319         } else {
320             targetFolderList.add(null);
321         }
322
323         Iterator JavaDoc targets = targetFolderList.iterator();
324         try {
325
326             while (targets.hasNext()) {
327                 // iterate over all given target folders
328
String JavaDoc currentTargetFolder = (String JavaDoc)targets.next();
329
330                 if ("channelselector".equals(getTreeType())) {
331                     // change the site root for channel tree window
332
restoreSiteRoot = true;
333                     getCms().getRequestContext().saveSiteRoot();
334                     getCms().getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
335                 } else if (getSettings().getTreeSite(getTreeType()) != null) {
336                     // change the site root for popup window with site selector
337
restoreSiteRoot = true;
338                     getCms().getRequestContext().saveSiteRoot();
339                     if (newTree() && currentTargetFolder == null) {
340                         currentTargetFolder = "/";
341                     }
342                     getCms().getRequestContext().setSiteRoot(getSettings().getTreeSite(getTreeType()));
343                     try {
344                         // check presence of target folder
345
getCms().readFolder(currentTargetFolder, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
346                     } catch (CmsException e) {
347                         // target folder not found, set it to "/"
348
if (LOG.isInfoEnabled()) {
349                             LOG.info(e);
350                         }
351                         currentTargetFolder = "/";
352                     }
353                 }
354
355                 // read the selected folder
356

357                 try {
358                     folder = getCms().readFolder(currentTargetFolder, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
359                 } catch (CmsException e) {
360                     // return with error
361
return printError(e);
362                 }
363
364                 if ((startFolder == null) || (!currentTargetFolder.startsWith(startFolder))) {
365                     // no (valid) start folder given, just load current folder
366
try {
367                         if (includeFiles()) {
368                             resources.addAll(getCms().getResourcesInFolder(
369                                 currentTargetFolder,
370                                 CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
371                         } else {
372                             resources.addAll(getCms().getSubFolders(
373                                 currentTargetFolder,
374                                 CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
375                         }
376                     } catch (CmsException e) {
377                         // return with error
378
return printError(e);
379                     }
380                 } else {
381                     // valid start folder given, load all folders between start and current folder
382
try {
383                         if (includeFiles()) {
384                             resources.addAll(getCms().getResourcesInFolder(
385                                 startFolder,
386                                 CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
387                         } else {
388                             resources.addAll(getCms().getSubFolders(
389                                 startFolder,
390                                 CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
391                         }
392                         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(
393                             currentTargetFolder.substring(startFolder.length()),
394                             "/");
395                         while (tok.hasMoreTokens()) {
396                             startFolder += tok.nextToken() + "/";
397                             if (includeFiles()) {
398                                 resources.addAll(getCms().getResourcesInFolder(
399                                     startFolder,
400                                     CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
401                             } else {
402                                 resources.addAll(getCms().getSubFolders(
403                                     startFolder,
404                                     CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
405                             }
406                         }
407                     } catch (CmsException e) {
408                         // return with error
409
return printError(e);
410                     }
411                 }
412             }
413
414             result.append("function init() {\n");
415
416             if (newTree()) {
417                 // new tree must be reloaded
418
result.append("parent.initTree();\n");
419                 result.append(getRootNode());
420             }
421
422             // read the list of project resource to select which resource is "inside" or "outside"
423
List JavaDoc projectResources;
424             try {
425                 projectResources = getCms().readProjectResources(getCms().getRequestContext().currentProject());
426             } catch (CmsException e) {
427                 // use an empty list (all resources are "outside")
428
if (LOG.isInfoEnabled()) {
429                     LOG.info(e);
430                 }
431                 projectResources = new ArrayList JavaDoc();
432             }
433
434             // now output all the tree nodes
435
Iterator JavaDoc i = resources.iterator();
436             while (i.hasNext()) {
437                 CmsResource resource = (CmsResource)i.next();
438                 grey = !CmsProject.isInsideProject(projectResources, resource);
439                 if ((!grey) && (!getSettings().getResourceTypes().containsKey(new Integer JavaDoc(resource.getTypeId())))) {
440                     grey = true;
441                 }
442
443                 result.append(getNode(
444                     resource.getRootPath(),
445                     resource.getName(),
446                     resource.getTypeId(),
447                     resource.isFolder(),
448                     resource.getState(),
449                     grey));
450             }
451
452             if (includeFiles()) {
453                 result.append("parent.setIncludeFiles(true);\n");
454             }
455             if (getTreeType() != null) {
456                 // this is a popup window tree
457
result.append("parent.setTreeType(\"");
458                 result.append(getTreeType());
459                 result.append("\");\n");
460                 String JavaDoc curSite = getSettings().getTreeSite(getTreeType());
461                 if (curSite != null) {
462                     // add the current site as prefix if present
463
result.append("parent.setSitePrefix(\"");
464                     result.append(getSitePrefix(curSite, oldSiteRoot));
465                     result.append("\");\n");
466                 }
467             }
468             // set the root folder in javascript
469
result.append("parent.setRootFolder(\"");
470             result.append(getRootFolder());
471             result.append("\");\n");
472
473             if (newTree()) {
474                 // new tree
475
result.append("parent.showTree(parent.tree_display.document, \"");
476                 result.append(folder.getRootPath().hashCode());
477                 result.append("\");\n");
478             } else {
479                 // update the current tree with the childs of the selected node
480
if (resources.size() == 0) {
481                     // the node had no childs
482
result.append("parent.setNoChilds(\"");
483                     result.append(folder.getRootPath().hashCode());
484                     result.append("\");\n");
485                 }
486                 result.append("parent.showLoadedNodes(parent.tree_display.document,\"");
487                 result.append(folder.getRootPath().hashCode());
488                 result.append("\");\n");
489             }
490
491             result.append("}\n");
492         } finally {
493             if (restoreSiteRoot) {
494                 getCms().getRequestContext().restoreSiteRoot();
495             }
496         }
497         return result.toString();
498     }
499
500     /**
501      * Returns the type of this tree (e.g. "copy", "project" etc.),
502      * if null this is the default explorer version.<p>
503      *
504      * @return the current type of the tree (e.g. "copy", "project" etc.)
505      */

506     public String JavaDoc getTreeType() {
507
508         return m_treeType;
509     }
510
511     /**
512      * Indicates if only folders or files and folders should be included in the tree.<p>
513      *
514      * @return true if files and folders should be included in the tree
515      */

516     public boolean includeFiles() {
517
518         return m_includeFiles;
519     }
520
521     /**
522      * Returns the HTML for the tree initialization.<p>
523      *
524      * @return the HTML for the tree initialization
525      */

526     public String JavaDoc initTree() {
527
528         return initTree(getCms(), getEncoding(), getSkinUri());
529     }
530
531     /**
532      * Indicates if the site selector should be shown depending on the tree type, initial settings and the count of accessible sites.<p>
533      *
534      * @return true if site selector should be shown, otherwise false
535      */

536     public boolean showSiteSelector() {
537
538         return m_showSiteSelector;
539     }
540
541     /**
542      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
543      */

544     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
545
546         setIncludeFiles(Boolean.valueOf(request.getParameter(PARAM_INCLUDEFILES)).booleanValue());
547         boolean rootloaded = Boolean.valueOf(request.getParameter(PARAM_ROOTLOADED)).booleanValue();
548         String JavaDoc resource = request.getParameter(PARAM_RESOURCE);
549         setTreeType(request.getParameter(PARAM_TYPE));
550         String JavaDoc treeSite = request.getParameter(PARAM_TREESITE);
551         computeSiteSelector(request);
552
553         String JavaDoc currentResource;
554         if (getTreeType() == null) {
555             currentResource = getSettings().getExplorerResource();
556         } else {
557             // get the current tree resource from the settings for a special tree type
558
currentResource = getSettings().getTreeResource(getTreeType());
559         }
560
561         String JavaDoc lastknown = request.getParameter(PARAM_LASTKNOWN);
562         // both "resource" and "lastknown" must be folders
563
if (resource != null) {
564             resource = CmsResource.getFolderPath(resource);
565         }
566         if ((lastknown != null) && (!lastknown.endsWith("/"))) {
567             lastknown += "/";
568         }
569
570         String JavaDoc rootFolder = getRootFolder();
571         if (rootFolder.equals(resource) && !rootFolder.equals(currentResource) && (lastknown == null) && !rootloaded) {
572             // direct load of a new tree with subtree (e.g. when returning from an editor)
573
lastknown = getRootFolder();
574             resource = CmsResource.getFolderPath(currentResource);
575             setNewTree(true);
576         } else if (rootFolder.equals(resource)) {
577             // load new tree if not already loaded
578
setNewTree(!rootloaded);
579         } else {
580             setNewTree(false);
581         }
582
583         if (getTreeType() != null) {
584             getSettings().setTreeResource(getTreeType(), resource);
585             if (treeSite != null) {
586                 getSettings().setTreeSite(getTreeType(), treeSite);
587             }
588         }
589
590         setTargetFolder(resource);
591         setStartFolder(lastknown);
592     }
593
594     /**
595      * Determines if the site selector frame should be shown depending on the tree type or the value of a request parameter.<p>
596      *
597      * If only one site is available, the site selector is not displayed.<p>
598      *
599      * @param request the HttpServletRequest to check
600      */

601     private void computeSiteSelector(HttpServletRequest JavaDoc request) {
602
603         boolean selectorForType = TYPE_SIBLING.equals(getTreeType())
604             || TYPE_COPY.equals(getTreeType())
605             || TYPE_PAGELINK.equals(getTreeType())
606             || TYPE_PREFERENCES.equals(getTreeType());
607         boolean showFromRequest = Boolean.valueOf(request.getParameter(PARAM_SHOWSITESELECTOR)).booleanValue();
608         if (selectorForType || showFromRequest) {
609             // get all available sites
610
int siteCount = CmsSiteManager.getAvailableSites(getCms(), true).size();
611             setShowSiteSelector(siteCount > 1);
612             return;
613         }
614         setShowSiteSelector(false);
615     }
616
617     /**
618      * Creates the output for a tree node.<p>
619      *
620      * @param path the path of the resource represented by this tree node
621      * @param title the resource name
622      * @param type the resource type
623      * @param folder if the resource is a folder
624      * @param state the resource state
625      * @param grey if true, the node is displayed in grey
626      *
627      * @return the output for a tree node
628      */

629     private String JavaDoc getNode(String JavaDoc path, String JavaDoc title, int type, boolean folder, int state, boolean grey) {
630
631         StringBuffer JavaDoc result = new StringBuffer JavaDoc(64);
632         String JavaDoc parent = CmsResource.getParentFolder(path);
633         result.append("parent.aC(\"");
634         // name
635
result.append(title);
636         result.append("\",");
637         // type
638
result.append(type);
639         result.append(",");
640         // folder
641
if (folder) {
642             result.append(1);
643         } else {
644             result.append(0);
645         }
646         result.append(",");
647         // hashcode of path
648
result.append(path.hashCode());
649         result.append(",");
650         // hashcode of parent path
651
result.append((parent != null) ? parent.hashCode() : 0);
652         result.append(",");
653         // resource state
654
result.append(state);
655         result.append(",");
656         // project status
657
if (grey) {
658             result.append(1);
659         } else {
660             result.append(0);
661         }
662         result.append(");\n");
663         return result.toString();
664     }
665
666     /**
667      * Creates a node entry for the root node of the current site.<p>
668      *
669      * @return a node entry for the root node of the current site
670      */

671     private String JavaDoc getRootNode() {
672
673         CmsResource resource = null;
674         String JavaDoc title = null;
675         String JavaDoc folder = getRootFolder();
676         try {
677             resource = getCms().readFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION);
678             // get the title information of the folder
679
CmsProperty titleProperty = getCms().readPropertyObject(folder, CmsPropertyDefinition.PROPERTY_TITLE, false);
680
681             if (titleProperty == null || titleProperty.isNullProperty()) {
682                 getCms().getSitePath(resource);
683                 title = resource.getRootPath();
684             } else {
685                 title = titleProperty.getValue();
686             }
687         } catch (CmsException e) {
688             // should usually never happen
689
if (LOG.isInfoEnabled()) {
690                 LOG.info(e);
691             }
692         }
693         return getNode(resource.getRootPath(), title, resource.getTypeId(), true, resource.getState(), false);
694     }
695
696     /**
697      * Calculates the prefix that has to be added when selecting a resource in a popup tree window.<p>
698      *
699      * This is needed for the link dialog in editors
700      * as well as the copy, move and link popup dialogs for resources in the VFS.<p>
701      *
702      * @param prefix the current prefix of the resource
703      * @param storedSiteRoot the site root in which the workplace (not the tree!) is
704      * @return the prefix which is added to the resource name
705      */

706     private String JavaDoc getSitePrefix(String JavaDoc prefix, String JavaDoc storedSiteRoot) {
707
708         if (TYPE_PAGELINK.equals(getTreeType())) {
709             // in editor link dialog, create a special prefix for internal links
710
if (!storedSiteRoot.equals(prefix)) {
711                 // stored site is not selected site, create complete URL as prefix
712
CmsSite site = CmsSiteManager.getSite(prefix);
713                 prefix = getCms().getRequestContext().removeSiteRoot(prefix);
714                 prefix = site.getUrl() + OpenCms.getSystemInfo().getOpenCmsContext() + prefix;
715             } else {
716                 // stored site is selected site, don't show prefix at all
717
prefix = "";
718             }
719
720         } else if (TYPE_COPY.equals(getTreeType())
721             || TYPE_SIBLING.equals(getTreeType())
722             || TYPE_VFSWIDGET.equals(getTreeType())) {
723             // in vfs copy|move|link or vfs widget mode, don't add the prefix for the current workplace site
724
if (storedSiteRoot.equals(prefix)) {
725                 prefix = "";
726             }
727         } else if (TYPE_PREFERENCES.equals(getTreeType())) {
728             prefix = "";
729         }
730
731         return prefix;
732     }
733
734     /**
735      * Returns the name of the start folder (or "last known" folder) to be loaded.<p>
736      *
737      * @return the name of the start folder (or "last known" folder) to be loaded
738      */

739     private String JavaDoc getStartFolder() {
740
741         return m_startFolder;
742     }
743
744     /**
745      * Returns the target folder name.<p>
746      *
747      * @return the target folder name
748      */

749     private String JavaDoc getTargetFolder() {
750
751         return m_targetFolder;
752     }
753
754     /**
755      * Returns true if a complete new tree must be loaded, false if an existing
756      * tree is updated or extended.<p>
757      *
758      * @return true if a complete new tree must be loaded
759      */

760     private boolean newTree() {
761
762         return m_newTree;
763     }
764
765     /**
766      * Creates error information output.<p>
767      *
768      * @param t an error that occured
769      * @return error information output
770      */

771     private String JavaDoc printError(Throwable JavaDoc t) {
772
773         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
774         result.append("/*\n");
775         result.append(t.getMessage());
776         result.append("\n*/\n");
777         result.append("function init() {\n");
778         result.append("}\n");
779         return result.toString();
780     }
781
782     /**
783      * Sets the value to indicate if only folders or files and folders should be included in the tree.<p>
784      *
785      * @param includeFiles if true if files and folders should be included in the tree
786      */

787     private void setIncludeFiles(boolean includeFiles) {
788
789         m_includeFiles = includeFiles;
790     }
791
792     /**
793      * Sets if a complete tree must be loaded.<p>
794      *
795      * @param newTree if true, a complete tree must be loaded
796      */

797     private void setNewTree(boolean newTree) {
798
799         m_newTree = newTree;
800     }
801
802     /**
803      * Sets if the site selector should be shown depending on the tree type and the count of accessible sites.<p>
804      *
805      * @param showSiteSelector true if site selector should be shown, otherwise false
806      */

807     private void setShowSiteSelector(boolean showSiteSelector) {
808
809         m_showSiteSelector = showSiteSelector;
810     }
811
812     /**
813      * Sets the name of the start folder (or "last known" folder) to be loaded.<p>
814      *
815      * @param startFolder the name of the start folder (or "last known" folder) to be loaded
816      */

817     private void setStartFolder(String JavaDoc startFolder) {
818
819         m_startFolder = startFolder;
820     }
821
822     /**
823      * Sets the target folder name.<p>
824      *
825      * @param targetFolder the target folder name
826      */

827     private void setTargetFolder(String JavaDoc targetFolder) {
828
829         m_targetFolder = targetFolder;
830     }
831
832     /**
833      * Sets the type of this tree.<p>
834      *
835      * @param type the type of this tree
836      */

837     private void setTreeType(String JavaDoc type) {
838
839         m_treeType = type;
840     }
841 }
Popular Tags