Source Code Cross Referenced for CmsTree.java in  » Content-Management-System » opencms » org » opencms » workplace » explorer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » org.opencms.workplace.explorer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsTree.java,v $
003:         * Date   : $Date: 2008-02-28 17:20:09 $
004:         * Version: $Revision: 1.29 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         * 
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.workplace.explorer;
033:
034:        import org.opencms.db.CmsResourceState;
035:        import org.opencms.file.CmsFolder;
036:        import org.opencms.file.CmsObject;
037:        import org.opencms.file.CmsProject;
038:        import org.opencms.file.CmsProperty;
039:        import org.opencms.file.CmsPropertyDefinition;
040:        import org.opencms.file.CmsResource;
041:        import org.opencms.file.CmsResourceFilter;
042:        import org.opencms.file.types.CmsResourceTypePlain;
043:        import org.opencms.file.types.I_CmsResourceType;
044:        import org.opencms.i18n.CmsMessages;
045:        import org.opencms.jsp.CmsJspActionElement;
046:        import org.opencms.loader.CmsLoaderException;
047:        import org.opencms.main.CmsException;
048:        import org.opencms.main.CmsLog;
049:        import org.opencms.main.OpenCms;
050:        import org.opencms.site.CmsSite;
051:        import org.opencms.util.CmsStringUtil;
052:        import org.opencms.workplace.CmsWorkplace;
053:        import org.opencms.workplace.CmsWorkplaceSettings;
054:
055:        import java.util.ArrayList;
056:        import java.util.Iterator;
057:        import java.util.List;
058:        import java.util.Locale;
059:        import java.util.StringTokenizer;
060:
061:        import javax.servlet.http.HttpServletRequest;
062:
063:        import org.apache.commons.logging.Log;
064:
065:        /**
066:         * Generates the tree view for the OpenCms Workplace.<p> 
067:         * 
068:         * The following Workplace files use this class:
069:         * <ul>
070:         * <li>/views/explorer/tree_fs.jsp
071:         * <li>/views/explorer/tree_files.jsp
072:         * </ul>
073:         * <p>
074:         *
075:         * @author  Alexander Kandzior 
076:         * 
077:         * @version $Revision: 1.29 $ 
078:         * 
079:         * @since 6.0.0 
080:         */
081:        public class CmsTree extends CmsWorkplace {
082:
083:            /** Request parameter name for the includesfiles parameter. */
084:            public static final String PARAM_INCLUDEFILES = "includefiles";
085:
086:            /** Request parameter name for the lastknown parameter. */
087:            public static final String PARAM_LASTKNOWN = "lastknown";
088:
089:            /** Request parameter name for the projectaware parameter. */
090:            public static final String PARAM_PROJECTAWARE = "projectaware";
091:
092:            /** Request parameter name for the resource parameter. */
093:            public static final String PARAM_RESOURCE = "resource";
094:
095:            /** Request parameter name for the rootloaded parameter. */
096:            public static final String PARAM_ROOTLOADED = "rootloaded";
097:
098:            /** Request parameter name for the showsiteselector parameter. */
099:            public static final String PARAM_SHOWSITESELECTOR = "showsiteselector";
100:
101:            /** Request parameter name for the treesite parameter. */
102:            public static final String PARAM_TREESITE = "treesite";
103:
104:            /** Request parameter name for the type parameter. */
105:            public static final String PARAM_TYPE = "type";
106:
107:            /** The log object for this class. */
108:            private static final Log LOG = CmsLog.getLog(CmsTree.class);
109:
110:            /** Type name for showing the tree when copying resources. */
111:            private static final String TYPE_COPY = "copy";
112:
113:            /** Type name for showing the tree when creating page links in the editor. */
114:            private static final String TYPE_PAGELINK = "pagelink";
115:
116:            /** Type name for showing the tree in preferences dialog. */
117:            private static final String TYPE_PREFERENCES = "preferences";
118:
119:            /** Type name for showing the tree when creating siblings. */
120:            private static final String TYPE_SIBLING = "sibling";
121:
122:            /** Type name for showing the tree in a widget dialog. */
123:            private static final String TYPE_VFSWIDGET = "vfswidget";
124:
125:            /** Indicates if only folders or files and folders should be included in the tree. */
126:            private boolean m_includeFiles;
127:
128:            /** Indicates if a complete new tree should be created. */
129:            private boolean m_newTree;
130:
131:            /** Indicates project awareness, ie. if resources outside of the current project should be displayed as normal. */
132:            private boolean m_projectAware = true;
133:
134:            /** The name of the root folder to display the tree from, usually "/". */
135:            private String m_rootFolder;
136:
137:            /** Flag to indicate if the site selector should be shown in popup tree window. */
138:            private boolean m_showSiteSelector;
139:
140:            /** The name of the start folder (or "last known" folder) to be loaded. */
141:            private String m_startFolder;
142:
143:            /** The name of the target folder to be loaded. */
144:            private String m_targetFolder;
145:
146:            /** The type of the tree (e.g. "copy", "project" etc.). */
147:            private String m_treeType;
148:
149:            /**
150:             * Public constructor.<p>
151:             * 
152:             * @param jsp an initialized JSP action element
153:             */
154:            public CmsTree(CmsJspActionElement jsp) {
155:
156:                super (jsp);
157:            }
158:
159:            /**
160:             * Returns the HTML for the tree initialization.<p>
161:             * 
162:             * @param cms the CmsObject
163:             * @param encoding the current encoding
164:             * @param skinUri the current skin URI
165:             * @return the HTML for the tree initialization
166:             */
167:            public static String initTree(CmsObject cms, String encoding,
168:                    String skinUri) {
169:
170:                StringBuffer retValue = new StringBuffer(512);
171:                String servletUrl = OpenCms.getSystemInfo().getOpenCmsContext();
172:
173:                // get the localized workplace messages
174:                // TODO: Why a new message object, can it not be obtained from session?
175:                Locale locale = cms.getRequestContext().getLocale();
176:                CmsMessages messages = OpenCms.getWorkplaceManager()
177:                        .getMessages(locale);
178:
179:                retValue.append("function initTreeResources() {\n");
180:                retValue.append("\tinitResources(\"");
181:                retValue.append(encoding);
182:                retValue.append("\", \"");
183:                retValue.append(PATH_WORKPLACE);
184:                retValue.append("\", \"");
185:                retValue.append(skinUri);
186:                retValue.append("\", \"");
187:                retValue.append(servletUrl);
188:                retValue.append("\");\n");
189:
190:                // get all available resource types
191:                List allResTypes = OpenCms.getResourceManager()
192:                        .getResourceTypes();
193:                for (int i = 0; i < allResTypes.size(); i++) {
194:                    // loop through all types
195:                    I_CmsResourceType type = (I_CmsResourceType) allResTypes
196:                            .get(i);
197:                    int curTypeId = type.getTypeId();
198:                    String curTypeName = type.getTypeName();
199:                    // get the settings for the resource type
200:                    CmsExplorerTypeSettings settings = OpenCms
201:                            .getWorkplaceManager().getExplorerTypeSetting(
202:                                    curTypeName);
203:                    if (settings == null) {
204:                        if (LOG.isWarnEnabled()) {
205:                            LOG.warn(Messages.get().getBundle().key(
206:                                    Messages.LOG_MISSING_SETTINGS_ENTRY_1,
207:                                    curTypeName));
208:                        }
209:                        settings = OpenCms.getWorkplaceManager()
210:                                .getExplorerTypeSetting(
211:                                        CmsResourceTypePlain
212:                                                .getStaticTypeName());
213:                    }
214:                    retValue.append("\taddResourceType(");
215:                    retValue.append(curTypeId);
216:                    retValue.append(", \"");
217:                    retValue.append(curTypeName);
218:                    retValue.append("\",\t\"");
219:                    retValue.append(messages.key(settings.getKey()));
220:                    retValue.append("\",\t\"filetypes/");
221:                    retValue.append(settings.getIcon());
222:                    retValue.append("\");\n");
223:                }
224:
225:                retValue.append("}\n\n");
226:                retValue.append("initTreeResources();\n");
227:
228:                return retValue.toString();
229:            }
230:
231:            /**
232:             * Determines the root folder of the current tree dependent on users setting of explorer view restriction.<p>
233:             * 
234:             * @return the root folder resource name to display
235:             */
236:            public String getRootFolder() {
237:
238:                if (m_rootFolder == null) {
239:                    String folder = "/";
240:                    if ((getTreeType() == null)
241:                            && getSettings().getUserSettings()
242:                                    .getRestrictExplorerView()) {
243:                        folder = getSettings().getUserSettings()
244:                                .getStartFolder();
245:                    }
246:                    try {
247:                        getCms().readFolder(folder,
248:                                CmsResourceFilter.IGNORE_EXPIRATION);
249:                    } catch (CmsException e) {
250:                        if (LOG.isInfoEnabled()) {
251:                            LOG.info(e);
252:                        }
253:                        folder = "/";
254:                    }
255:                    m_rootFolder = folder;
256:                }
257:                return m_rootFolder;
258:            }
259:
260:            /**
261:             * Returns the HTML for the site selector box for the explorer tree window.<p>
262:             * 
263:             * @param htmlAttributes optional attributes for the &lt;select&gt; tag
264:             * @return HTML code for the site selector box
265:             */
266:            public String getSiteSelector(String htmlAttributes) {
267:
268:                List options = new ArrayList();
269:                List values = new ArrayList();
270:                int selectedIndex = 0;
271:                String preSelection = getSettings().getTreeSite(getTreeType());
272:                if (preSelection == null) {
273:                    if ("".equals(getCms().getRequestContext().getSiteRoot())) {
274:                        // we are in the root site, getCurrentSite(CmsObject) includes NOT the root site
275:                        preSelection = "";
276:                    } else {
277:                        // get the site root of the current site
278:                        preSelection = OpenCms.getSiteManager().getCurrentSite(
279:                                getCms()).getSiteRoot();
280:                    }
281:                    // set the tree site to avoid discrepancies between selector and tree
282:                    getSettings().setTreeSite(getTreeType(), preSelection);
283:                }
284:
285:                boolean includeRootSite = true;
286:                boolean showSiteUrls = false;
287:                if (TYPE_PAGELINK.equals(getTreeType())) {
288:                    // in wysiwyg editor link dialog, don't show root site, but show site URLs
289:                    includeRootSite = false;
290:                    showSiteUrls = true;
291:                }
292:                List sites = OpenCms.getSiteManager().getAvailableSites(
293:                        getCms(), includeRootSite);
294:
295:                Iterator i = sites.iterator();
296:                int pos = 0;
297:                while (i.hasNext()) {
298:                    CmsSite site = (CmsSite) i.next();
299:                    values.add(site.getSiteRoot());
300:                    String curOption = site.getTitle();
301:                    if (showSiteUrls) {
302:                        // show the site URL in editor link dialog tree 
303:                        curOption = site.getUrl() + " (" + curOption + ")";
304:                        if (getCms().getRequestContext().getSiteRoot().equals(
305:                                site.getSiteRoot())) {
306:                            // mark the current workplace site in selector
307:                            curOption = "*" + curOption;
308:                        }
309:                    }
310:
311:                    if (site.getSiteRoot().equals(preSelection)) {
312:                        // this is the user's currently selected site
313:                        selectedIndex = pos;
314:                    }
315:                    options.add(curOption);
316:                    pos++;
317:                }
318:
319:                return buildSelect(htmlAttributes, options, values,
320:                        selectedIndex);
321:            }
322:
323:            /**
324:             * Returns the html for the explorer tree.<p>
325:             *
326:             * @return the html for the explorer tree
327:             */
328:            public String getTree() {
329:
330:                StringBuffer result = new StringBuffer(2048);
331:
332:                List targetFolderList = new ArrayList();
333:                if (getTargetFolder() != null) {
334:                    // check if there is more than one folder to update (e.g. move operation)
335:                    StringTokenizer T = new StringTokenizer(getTargetFolder(),
336:                            "|");
337:                    while (T.hasMoreTokens()) {
338:                        String currentFolder = T.nextToken().trim();
339:                        targetFolderList.add(currentFolder);
340:                    }
341:                } else {
342:                    targetFolderList.add(null);
343:                }
344:
345:                String storedSiteRoot = null;
346:                try {
347:                    CmsFolder folder = null;
348:                    List resources = new ArrayList();
349:                    String oldSiteRoot = getCms().getRequestContext()
350:                            .getSiteRoot();
351:
352:                    Iterator targets = targetFolderList.iterator();
353:                    while (targets.hasNext()) {
354:                        // iterate over all given target folders
355:                        String currentTargetFolder = (String) targets.next();
356:
357:                        if (getSettings().getTreeSite(getTreeType()) != null) {
358:                            // change the site root for popup window with site selector
359:                            storedSiteRoot = getCms().getRequestContext()
360:                                    .getSiteRoot();
361:                            if (newTree() && (currentTargetFolder == null)) {
362:                                currentTargetFolder = "/";
363:                            }
364:                            getCms().getRequestContext().setSiteRoot(
365:                                    getSettings().getTreeSite(getTreeType()));
366:                            try {
367:                                // check presence of target folder
368:                                getCms()
369:                                        .readFolder(
370:                                                currentTargetFolder,
371:                                                CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
372:                            } catch (CmsException e) {
373:                                // target folder not found, set it to "/"
374:                                if (LOG.isInfoEnabled()) {
375:                                    LOG.info(e);
376:                                }
377:                                currentTargetFolder = "/";
378:                            }
379:                        }
380:
381:                        // read the selected folder
382:                        try {
383:                            folder = getCms().readFolder(currentTargetFolder,
384:                                    CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
385:                        } catch (CmsException e) {
386:                            // return with error
387:                            return printError(e);
388:                        }
389:
390:                        String startFolder = getStartFolder();
391:                        if ((startFolder == null)
392:                                || (!currentTargetFolder
393:                                        .startsWith(startFolder))) {
394:                            // no (valid) start folder given, just load current folder        
395:                            try {
396:                                if (includeFiles()) {
397:                                    resources
398:                                            .addAll(getCms()
399:                                                    .getResourcesInFolder(
400:                                                            currentTargetFolder,
401:                                                            CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
402:                                } else {
403:                                    resources
404:                                            .addAll(getCms()
405:                                                    .getSubFolders(
406:                                                            currentTargetFolder,
407:                                                            CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
408:                                }
409:                            } catch (CmsException e) {
410:                                // return with error
411:                                return printError(e);
412:                            }
413:                        } else {
414:                            // valid start folder given, load all folders between start and current folder
415:                            try {
416:                                if (includeFiles()) {
417:                                    resources
418:                                            .addAll(getCms()
419:                                                    .getResourcesInFolder(
420:                                                            startFolder,
421:                                                            CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
422:                                } else {
423:                                    resources
424:                                            .addAll(getCms()
425:                                                    .getSubFolders(
426:                                                            startFolder,
427:                                                            CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
428:                                }
429:                                StringTokenizer tok = new StringTokenizer(
430:                                        currentTargetFolder
431:                                                .substring(startFolder.length()),
432:                                        "/");
433:                                while (tok.hasMoreTokens()) {
434:                                    startFolder += tok.nextToken() + "/";
435:                                    if (includeFiles()) {
436:                                        resources
437:                                                .addAll(getCms()
438:                                                        .getResourcesInFolder(
439:                                                                startFolder,
440:                                                                CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
441:                                    } else {
442:                                        resources
443:                                                .addAll(getCms()
444:                                                        .getSubFolders(
445:                                                                startFolder,
446:                                                                CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
447:                                    }
448:                                }
449:                            } catch (CmsException e) {
450:                                // return with error 
451:                                return printError(e);
452:                            }
453:                        }
454:                    }
455:
456:                    result.append("function init() {\n");
457:
458:                    if (newTree()) {
459:                        // new tree must be reloaded
460:                        result.append("parent.initTree();\n");
461:                        result.append(getRootNode());
462:                    }
463:
464:                    // read the list of project resource to select which resource is "inside" or "outside" 
465:                    List projectResources = new ArrayList();
466:                    if (isProjectAware()) {
467:                        try {
468:                            projectResources = getCms().readProjectResources(
469:                                    getCms().getRequestContext()
470:                                            .currentProject());
471:                        } catch (CmsException e) {
472:                            // use an empty list (all resources are "outside")
473:                            if (LOG.isInfoEnabled()) {
474:                                LOG.info(e);
475:                            }
476:                        }
477:                    }
478:
479:                    // now output all the tree nodes
480:                    Iterator i = resources.iterator();
481:                    while (i.hasNext()) {
482:                        CmsResource resource = (CmsResource) i.next();
483:                        boolean grey = false;
484:                        if (isProjectAware()) {
485:                            grey = !CmsProject.isInsideProject(
486:                                    projectResources, resource);
487:                        }
488:                        if (!grey) {
489:                            try {
490:                                OpenCms.getResourceManager().getResourceType(
491:                                        resource.getTypeId());
492:                            } catch (CmsLoaderException e) {
493:                                // if resource type is not found
494:                                grey = true;
495:                            }
496:                        }
497:
498:                        result.append(getNode(resource.getRootPath(), resource
499:                                .getName(), resource.getTypeId(), resource
500:                                .isFolder(), resource.getState(), grey));
501:                    }
502:
503:                    if (includeFiles()) {
504:                        result.append("parent.setIncludeFiles(true);\n");
505:                    }
506:                    result.append("parent.setProjectAware(").append(
507:                            isProjectAware()).append(");\n");
508:                    if (getTreeType() != null) {
509:                        // this is a popup window tree
510:                        result.append("parent.setTreeType(\"");
511:                        result.append(getTreeType());
512:                        result.append("\");\n");
513:                        String curSite = getSettings().getTreeSite(
514:                                getTreeType());
515:                        if (curSite != null) {
516:                            // add the current site as prefix if present
517:                            result.append("parent.setSitePrefix(\"");
518:                            result.append(getSitePrefix(curSite, oldSiteRoot));
519:                            result.append("\");\n");
520:                        }
521:                    }
522:                    // set the root folder in javascript
523:                    result.append("parent.setRootFolder(\"");
524:                    result.append(getRootFolder());
525:                    result.append("\");\n");
526:
527:                    if (folder != null) {
528:                        if (newTree()) {
529:                            // new tree 
530:                            result
531:                                    .append("parent.showTree(parent.tree_display.document, \"");
532:                            result.append(folder.getRootPath().hashCode());
533:                            result.append("\");\n");
534:                        } else {
535:                            // update the current tree with the children of the selected node
536:                            if (resources.size() == 0) {
537:                                // the node had no children 
538:                                result.append("parent.setNoChilds(\"");
539:                                result.append(folder.getRootPath().hashCode());
540:                                result.append("\");\n");
541:                            }
542:                            result
543:                                    .append("parent.showLoadedNodes(parent.tree_display.document,\"");
544:                            result.append(folder.getRootPath().hashCode());
545:                            result.append("\");\n");
546:                        }
547:                    }
548:
549:                    result.append("}\n");
550:                } finally {
551:                    if (storedSiteRoot != null) {
552:                        getCms().getRequestContext()
553:                                .setSiteRoot(storedSiteRoot);
554:                    }
555:                }
556:                return result.toString();
557:            }
558:
559:            /**
560:             * Returns the type of this tree (e.g. "copy", "project" etc.),
561:             * if null this is the default explorer version.<p>
562:             * 
563:             * @return the current type of the tree (e.g. "copy", "project" etc.)
564:             */
565:            public String getTreeType() {
566:
567:                return m_treeType;
568:            }
569:
570:            /**
571:             * Indicates if only folders or files and folders should be included in the tree.<p>
572:             * 
573:             * @return true if files and folders should be included in the tree
574:             */
575:            public boolean includeFiles() {
576:
577:                return m_includeFiles;
578:            }
579:
580:            /**
581:             * Returns the HTML for the tree initialization.<p>
582:             * 
583:             * @return the HTML for the tree initialization
584:             */
585:            public String initTree() {
586:
587:                return initTree(getCms(), getEncoding(), getSkinUri());
588:            }
589:
590:            /**
591:             * Returns the project awareness flag.<p>
592:             *
593:             * @return the project awareness flag
594:             */
595:            public boolean isProjectAware() {
596:
597:                return m_projectAware;
598:            }
599:
600:            /**
601:             * Sets the project awareness flag.<p>
602:             *
603:             * @param projectAware the project awareness flag to set
604:             */
605:            public void setProjectAware(boolean projectAware) {
606:
607:                m_projectAware = projectAware;
608:            }
609:
610:            /**
611:             * Indicates if the site selector should be shown depending on the tree type, initial settings and the count of accessible sites.<p>
612:             * 
613:             * @return true if site selector should be shown, otherwise false
614:             */
615:            public boolean showSiteSelector() {
616:
617:                return m_showSiteSelector;
618:            }
619:
620:            /**
621:             * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
622:             */
623:            protected void initWorkplaceRequestValues(
624:                    CmsWorkplaceSettings settings, HttpServletRequest request) {
625:
626:                setIncludeFiles(Boolean.valueOf(
627:                        request.getParameter(PARAM_INCLUDEFILES))
628:                        .booleanValue());
629:                setProjectAware(Boolean.valueOf(
630:                        request.getParameter(PARAM_PROJECTAWARE))
631:                        .booleanValue());
632:                boolean rootloaded = Boolean.valueOf(
633:                        request.getParameter(PARAM_ROOTLOADED)).booleanValue();
634:                String resource = request.getParameter(PARAM_RESOURCE);
635:
636:                if (!getCms().existsResource(resource)) {
637:                    resource = null;
638:                }
639:
640:                setTreeType(request.getParameter(PARAM_TYPE));
641:                String treeSite = request.getParameter(PARAM_TREESITE);
642:                computeSiteSelector(request);
643:
644:                String currentResource;
645:                if (getTreeType() == null) {
646:                    currentResource = getSettings().getExplorerResource();
647:                } else {
648:                    // get the current tree resource from the settings for a special tree type
649:                    currentResource = getSettings().getTreeResource(
650:                            getTreeType());
651:                }
652:
653:                String lastknown = request.getParameter(PARAM_LASTKNOWN);
654:                // both "resource" and "lastknown" must be folders
655:
656:                if (resource != null) {
657:                    resource = CmsResource.getFolderPath(resource);
658:                }
659:                if ((lastknown != null) && (!lastknown.endsWith("/"))) {
660:                    lastknown += "/";
661:                }
662:
663:                String rootFolder = getRootFolder();
664:                if (rootFolder.equals(resource)
665:                        && !rootFolder.equals(currentResource)
666:                        && (lastknown == null) && !rootloaded) {
667:                    // direct load of a new tree with subtree (e.g. when returning from an editor)
668:                    lastknown = getRootFolder();
669:                    resource = CmsResource.getFolderPath(currentResource);
670:                    setNewTree(true);
671:                } else if (rootFolder.equals(resource)) {
672:                    // load new tree if not already loaded
673:                    setNewTree(!rootloaded);
674:                } else {
675:                    setNewTree(false);
676:                }
677:
678:                if (getTreeType() != null) {
679:                    getSettings().setTreeResource(getTreeType(), resource);
680:                    if (treeSite != null) {
681:                        getSettings().setTreeSite(getTreeType(), treeSite);
682:                    }
683:                }
684:
685:                setTargetFolder(resource);
686:                setStartFolder(lastknown);
687:            }
688:
689:            /**
690:             * Determines if the site selector frame should be shown depending on the tree type or the value of a request parameter.<p>
691:             * 
692:             * If only one site is available, the site selector is not displayed.<p>
693:             * 
694:             * @param request the HttpServletRequest to check
695:             */
696:            private void computeSiteSelector(HttpServletRequest request) {
697:
698:                boolean selectorForType = TYPE_SIBLING.equals(getTreeType())
699:                        || TYPE_COPY.equals(getTreeType())
700:                        || TYPE_PAGELINK.equals(getTreeType())
701:                        || TYPE_PREFERENCES.equals(getTreeType());
702:                boolean showFromRequest = Boolean.valueOf(
703:                        request.getParameter(PARAM_SHOWSITESELECTOR))
704:                        .booleanValue();
705:                if (selectorForType || showFromRequest) {
706:                    // get all available sites
707:                    int siteCount = OpenCms.getSiteManager().getAvailableSites(
708:                            getCms(), true).size();
709:                    setShowSiteSelector(siteCount > 1);
710:                    return;
711:                }
712:                setShowSiteSelector(false);
713:            }
714:
715:            /**
716:             * Creates the output for a tree node.<p>
717:             * 
718:             * @param path the path of the resource represented by this tree node
719:             * @param title the resource name
720:             * @param type the resource type 
721:             * @param folder if the resource is a folder
722:             * @param state the resource state
723:             * @param grey if true, the node is displayed in grey
724:             *
725:             * @return the output for a tree node
726:             */
727:            private String getNode(String path, String title, int type,
728:                    boolean folder, CmsResourceState state, boolean grey) {
729:
730:                StringBuffer result = new StringBuffer(64);
731:                String parent = CmsResource.getParentFolder(path);
732:                result.append("parent.aC(\"");
733:                // name
734:                result.append(title);
735:                result.append("\",");
736:                // type
737:                result.append(type);
738:                result.append(",");
739:                // folder 
740:                if (folder) {
741:                    result.append(1);
742:                } else {
743:                    result.append(0);
744:                }
745:                result.append(",");
746:                // hashcode of path
747:                result.append(path.hashCode());
748:                result.append(",");
749:                // hashcode of parent path
750:                result.append((parent != null) ? parent.hashCode() : 0);
751:                result.append(",");
752:                // resource state
753:                result.append(state);
754:                result.append(",");
755:                // project status
756:                if (grey) {
757:                    result.append(1);
758:                } else {
759:                    result.append(0);
760:                }
761:                result.append(");\n");
762:                return result.toString();
763:            }
764:
765:            /**
766:             * Creates a node entry for the root node of the current site.<p>
767:             *  
768:             * @return a node entry for the root node of the current site
769:             */
770:            private String getRootNode() {
771:
772:                CmsResource resource = null;
773:                String title = null;
774:                String folder = getRootFolder();
775:                try {
776:                    resource = getCms().readFolder(folder,
777:                            CmsResourceFilter.IGNORE_EXPIRATION);
778:                    // get the title information of the folder
779:                    CmsProperty titleProperty = getCms()
780:                            .readPropertyObject(folder,
781:                                    CmsPropertyDefinition.PROPERTY_TITLE, false);
782:
783:                    if ((titleProperty == null)
784:                            || titleProperty.isNullProperty()) {
785:                        getCms().getSitePath(resource);
786:                        title = resource.getRootPath();
787:                    } else {
788:                        title = titleProperty.getValue();
789:                    }
790:                    return getNode(resource.getRootPath(), title, resource
791:                            .getTypeId(), true, resource.getState(), false);
792:                } catch (CmsException e) {
793:                    // should usually never happen
794:                    if (LOG.isInfoEnabled()) {
795:                        LOG.info(e);
796:                    }
797:                }
798:                return "";
799:            }
800:
801:            /**
802:             * Calculates the prefix that has to be added when selecting a resource in a popup tree window.<p>
803:             * 
804:             * This is needed for the link dialog in editors 
805:             * as well as the copy, move and link popup dialogs for resources in the VFS.<p>
806:             * 
807:             * @param prefix the current prefix of the resource
808:             * @param storedSiteRoot the site root in which the workplace (not the tree!) is
809:             * @return the prefix which is added to the resource name
810:             */
811:            private String getSitePrefix(String prefix, String storedSiteRoot) {
812:
813:                if (TYPE_PAGELINK.equals(getTreeType())) {
814:                    // in editor link dialog, create a special prefix for internal links
815:                    if (!storedSiteRoot.equals(prefix)) {
816:                        // stored site is not selected site, create complete URL as prefix
817:                        CmsSite site = OpenCms.getSiteManager()
818:                                .getSiteForSiteRoot(prefix);
819:                        prefix = getCms().getRequestContext().removeSiteRoot(
820:                                prefix);
821:                        prefix = site.getUrl()
822:                                + OpenCms.getSystemInfo().getOpenCmsContext()
823:                                + prefix;
824:                    } else {
825:                        // stored site is selected site, don't show prefix at all
826:                        prefix = "";
827:                    }
828:
829:                } else if (TYPE_COPY.equals(getTreeType())
830:                        || TYPE_SIBLING.equals(getTreeType())
831:                        || TYPE_VFSWIDGET.equals(getTreeType())) {
832:                    // in vfs copy|move|link or vfs widget mode, don't add the prefix for the current workplace site
833:                    if (storedSiteRoot.equals(prefix)) {
834:                        prefix = "";
835:                    }
836:                } else if (TYPE_PREFERENCES.equals(getTreeType())) {
837:                    prefix = "";
838:                }
839:
840:                return prefix;
841:            }
842:
843:            /**
844:             * Returns the name of the start folder (or "last known" folder) to be loaded.<p>
845:             *
846:             * @return the name of the start folder (or "last known" folder) to be loaded
847:             */
848:            private String getStartFolder() {
849:
850:                return m_startFolder;
851:            }
852:
853:            /**
854:             * Returns the target folder name.<p>
855:             * 
856:             * @return the target folder name
857:             */
858:            private String getTargetFolder() {
859:
860:                return m_targetFolder;
861:            }
862:
863:            /**
864:             * Returns true if a complete new tree must be loaded, false if an existing 
865:             * tree is updated or extended.<p>
866:             *  
867:             * @return true if a complete new tree must be loaded
868:             */
869:            private boolean newTree() {
870:
871:                return m_newTree;
872:            }
873:
874:            /**
875:             * Creates error information output.<p>
876:             * 
877:             * @param t an error that occurred
878:             * @return error information output
879:             */
880:            private String printError(Throwable t) {
881:
882:                StringBuffer result = new StringBuffer(1024);
883:                result.append("/*\n");
884:                result.append(CmsStringUtil.escapeHtml(t.getMessage()));
885:                result.append("\n*/\n");
886:                result.append("function init() {\n");
887:                result.append("}\n");
888:                return result.toString();
889:            }
890:
891:            /**
892:             * Sets the value to indicate if only folders or files and folders should be included in the tree.<p>
893:             * 
894:             * @param includeFiles if true if files and folders should be included in the tree
895:             */
896:            private void setIncludeFiles(boolean includeFiles) {
897:
898:                m_includeFiles = includeFiles;
899:            }
900:
901:            /**
902:             * Sets if a complete tree must be loaded.<p>
903:             * 
904:             * @param newTree if true, a complete tree must be loaded
905:             */
906:            private void setNewTree(boolean newTree) {
907:
908:                m_newTree = newTree;
909:            }
910:
911:            /**
912:             * Sets if the site selector should be shown depending on the tree type and the count of accessible sites.<p>
913:             *
914:             * @param showSiteSelector true if site selector should be shown, otherwise false
915:             */
916:            private void setShowSiteSelector(boolean showSiteSelector) {
917:
918:                m_showSiteSelector = showSiteSelector;
919:            }
920:
921:            /**
922:             * Sets the name of the start folder (or "last known" folder) to be loaded.<p>
923:             * 
924:             * @param startFolder the name of the start folder (or "last known" folder) to be loaded
925:             */
926:            private void setStartFolder(String startFolder) {
927:
928:                m_startFolder = startFolder;
929:            }
930:
931:            /**
932:             * Sets the target folder name.<p>
933:             * 
934:             * @param targetFolder the target folder name
935:             */
936:            private void setTargetFolder(String targetFolder) {
937:
938:                m_targetFolder = targetFolder;
939:            }
940:
941:            /**
942:             * Sets the type of this tree.<p>
943:             * 
944:             * @param type the type of this tree
945:             */
946:            private void setTreeType(String type) {
947:
948:                m_treeType = type;
949:            }
950:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.