KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsWorkplaceAction


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsWorkplaceAction.java,v $
3  * Date : $Date: 2005/06/27 23:22:07 $
4  * Version: $Revision: 1.1 $
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 com.opencms.workplace;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.OpenCms;
36 import org.opencms.workplace.CmsFrameset;
37 import org.opencms.workplace.CmsWorkplace;
38 import org.opencms.workplace.CmsWorkplaceManager;
39 import org.opencms.workplace.CmsWorkplaceSettings;
40
41
42 import javax.servlet.http.HttpServletRequest JavaDoc;
43 import javax.servlet.http.HttpSession JavaDoc;
44
45 /**
46  * Utility class with static methods, mainly intended for the transition of
47  * functionality from the old XML based workplace to the new JSP workplace.<p>
48  *
49  * @author Alexander Kandzior
50  *
51  * @version $Revision: 1.1 $
52  *
53  * @since 6.0.0
54  */

55 public final class CmsWorkplaceAction {
56
57     /** File name of explorer file list loader (same for JSP and XML). */
58     public static final String JavaDoc FILE_WORKPLACE_FILELIST = "explorer_files.jsp";
59
60     /** Relative path to the JSP explorer. */
61     public static final String JavaDoc JSP_WORKPLACE_FILELIST = "../views/explorer/" + FILE_WORKPLACE_FILELIST;
62
63     /** Path to the different workplace views. */
64     public static final String JavaDoc PATH_VIEWS_WORKPLACE = CmsWorkplace.VFS_PATH_WORKPLACE + "views/";
65     
66     /** Path to the explorer workplace view. */
67     public static final String JavaDoc PATH_VIEW_EXPLORER = PATH_VIEWS_WORKPLACE + "explorer/";
68
69     /** Path to the XML workplace. */
70     public static final String JavaDoc PATH_XML_WORKPLACE = CmsWorkplace.VFS_PATH_WORKPLACE + "action/";
71
72     /** Path to the XML workplace frame loader file. */
73     public static final String JavaDoc XML_WORKPLACE_URI = PATH_XML_WORKPLACE + "index.html";
74
75     /** Session attribute for the file list. */
76     private static final String JavaDoc FILELIST_ATTRIBUTE = "__filelist";
77
78     /**
79      * Constructor is private since there must be no instances of this class.<p>
80      */

81     private CmsWorkplaceAction() {
82
83         // empty
84
}
85
86     /**
87      * Returns the folder currently selected in the explorer.<p>
88      *
89      * @param req the current http request
90      * @return the folder currently selected in the explorer
91      */

92     public static String JavaDoc getCurrentFolder(HttpServletRequest JavaDoc req) {
93
94         HttpSession JavaDoc session = req.getSession(false);
95         if (session == null) {
96             return null;
97         }
98         CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
99         if (settings != null) {
100             return settings.getExplorerResource();
101         } else {
102             return (String JavaDoc)session.getAttribute(FILELIST_ATTRIBUTE);
103         }
104     }
105
106     /**
107      * Returns the full uri (absoluth path with servlet context) of the file explorer.<p>
108      *
109      * @param cms the current cms context
110      * @param req the current http request
111      * @return the uri of the file explorer
112      */

113     public static String JavaDoc getExplorerFileFullUri(CmsObject cms, HttpServletRequest JavaDoc req) {
114
115         HttpSession JavaDoc session = req.getSession(false);
116         String JavaDoc link = PATH_XML_WORKPLACE + FILE_WORKPLACE_FILELIST;
117         if (session == null) {
118             return OpenCms.getLinkManager().substituteLink(cms, link);
119         }
120         CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
121         if (settings == null) {
122             return OpenCms.getLinkManager().substituteLink(cms, link);
123         }
124         return OpenCms.getLinkManager().substituteLink(cms, PATH_VIEW_EXPLORER + FILE_WORKPLACE_FILELIST);
125     }
126
127     /**
128      * Returns the uri of the file explorer.<p>
129      *
130      * @param req the current http request
131      * @return the uri of the file explorer
132      */

133     public static String JavaDoc getExplorerFileUri(HttpServletRequest JavaDoc req) {
134
135         HttpSession JavaDoc session = req.getSession(false);
136         if (session == null) {
137             return CmsWorkplaceDefault.C_WP_EXPLORER_FILELIST;
138         }
139         CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
140         if (settings == null) {
141             return CmsWorkplaceDefault.C_WP_EXPLORER_FILELIST;
142         }
143         return JSP_WORKPLACE_FILELIST;
144     }
145
146     /**
147      * Returns the uri of the top workplace frameset.<p>
148      *
149      * @param req the current http request
150      * @return the uri of the top workplace frameset
151      */

152     public static String JavaDoc getWorkplaceUri(HttpServletRequest JavaDoc req) {
153
154         HttpSession JavaDoc session = req.getSession(false);
155         if (session == null) {
156             return XML_WORKPLACE_URI;
157         }
158         CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
159         if (settings == null) {
160             return XML_WORKPLACE_URI;
161         }
162         return CmsFrameset.JSP_WORKPLACE_URI;
163     }
164
165     /**
166      * Sets the folder currently selected in the explorer.<p>
167      *
168      * @param req the current http request
169      * @param currentFolder the folder to set
170      */

171     public static void setCurrentFolder(String JavaDoc currentFolder, HttpServletRequest JavaDoc req) {
172
173         HttpSession JavaDoc session = req.getSession(false);
174         if (session == null) {
175             return;
176         }
177         CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
178         if (settings != null) {
179             settings.setExplorerResource(currentFolder);
180         }
181         session.setAttribute(FILELIST_ATTRIBUTE, currentFolder);
182     }
183 }
184
Popular Tags