KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > list > CmsListExplorerFrameset


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListExplorerFrameset.java,v $
3  * Date : $Date: 2006/03/28 13:10:02 $
4  * Version: $Revision: 1.4 $
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.list;
33
34 import org.opencms.i18n.CmsEncoder;
35 import org.opencms.i18n.CmsMessages;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.CmsException;
38 import org.opencms.workplace.CmsWorkplaceSettings;
39 import org.opencms.workplace.explorer.CmsExplorer;
40 import org.opencms.workplace.tools.A_CmsHtmlIconButton;
41 import org.opencms.workplace.tools.CmsExplorerDialog;
42 import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum;
43 import org.opencms.workplace.tools.CmsTool;
44 import org.opencms.workplace.tools.CmsToolDialog;
45 import org.opencms.workplace.tools.CmsToolMacroResolver;
46 import org.opencms.workplace.tools.CmsToolManager;
47
48
49 import java.io.IOException JavaDoc;
50 import java.util.HashMap JavaDoc;
51 import java.util.Iterator JavaDoc;
52 import java.util.Map JavaDoc;
53
54 import javax.servlet.ServletException JavaDoc;
55 import javax.servlet.http.HttpServletRequest JavaDoc;
56 import javax.servlet.http.HttpServletResponse JavaDoc;
57 import javax.servlet.jsp.JspException JavaDoc;
58 import javax.servlet.jsp.JspWriter JavaDoc;
59 import javax.servlet.jsp.PageContext JavaDoc;
60
61 /**
62  * Explorer dialog for the project files view.<p>
63  *
64  * @author Michael Moossen
65  *
66  * @version $Revision: 1.4 $
67  *
68  * @since 6.0.0
69  */

70 public class CmsListExplorerFrameset extends CmsExplorerDialog {
71
72     /** Page parameter name. */
73     public static final String JavaDoc PARAM_PAGE = "explorer_page";
74
75     /**
76      * Public constructor with JSP action element.<p>
77      *
78      * @param jsp an initialized JSP action element
79      */

80     public CmsListExplorerFrameset(CmsJspActionElement jsp) {
81
82         super(jsp);
83     }
84
85     /**
86      * Public constructor with JSP variables.<p>
87      *
88      * @param context the JSP page context
89      * @param req the JSP request
90      * @param res the JSP response
91      */

92     public CmsListExplorerFrameset(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
93
94         this(new CmsJspActionElement(context, req, res));
95     }
96
97     /**
98      * Generates the dialog starting html code.<p>
99      *
100      * @return html code
101      */

102     public String JavaDoc defaultActionHtml() {
103
104         String JavaDoc params = allParamsAsRequest();
105         String JavaDoc titleSrc = getFrameSource("tool_title", getJsp().link(
106             CmsToolManager.ADMINVIEW_ROOT_LOCATION + "/list-title.jsp")
107             + "?"
108             + params);
109         String JavaDoc contentSrc = getFrameSource("tool_content", getJsp().link(
110             CmsToolManager.ADMINVIEW_ROOT_LOCATION + "/list-explorer.jsp")
111             + "?"
112             + params);
113         StringBuffer JavaDoc html = new StringBuffer JavaDoc(1024);
114         html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">\n");
115         html.append("<html>\n");
116         html.append("\t<head>\n");
117         html.append("\t\t<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=\"").append(getEncoding()).append(
118             "\">\n");
119         html.append("\t\t<title>\n");
120         html.append("\t\t\t").append(
121             key(org.opencms.workplace.Messages.GUI_LABEL_WPTITLE_2, new Object JavaDoc[] {
122                 getSettings().getUser().getName(),
123                 getJsp().getRequest().getServerName()})).append("\n");
124         html.append("\t\t</title>\n");
125         html.append("\t</head>\n");
126         html.append("\t<frameset rows='57,*' border='0' frameborder='0' framespacing='0'>\n");
127         html.append("\t\t<frame ").append(titleSrc).append(" frameborder='0' border='0' noresize scrolling='no'>\n");
128         html.append("\t\t<frame ").append(contentSrc).append(
129             " frameborder='0' border='0' noresize scrolling='auto' framespacing='0' marginheight='2' marginwidth='2' >\n");
130         html.append("\t</frameset>\n");
131         html.append("</html>\n");
132         return html.toString();
133     }
134
135     /**
136      * @see org.opencms.workplace.tools.CmsToolDialog#dialogTitle()
137      */

138     public String JavaDoc dialogTitle() {
139
140         StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
141         String JavaDoc toolPath = getCurrentToolPath();
142         String JavaDoc parentPath = getParentPath();
143         String JavaDoc rootKey = getToolManager().getCurrentRoot(this).getKey();
144         CmsTool parentTool = getToolManager().resolveAdminTool(rootKey, parentPath);
145         String JavaDoc upLevelLink = CmsToolManager.linkForToolPath(
146             getJsp(),
147             parentPath,
148             parentTool.getHandler().getParameters(this));
149         String JavaDoc listLevelLink = CmsToolManager.linkForToolPath(getJsp(), toolPath, getToolManager().resolveAdminTool(
150             rootKey,
151             toolPath).getHandler().getParameters(this));
152         String JavaDoc parentName = getToolManager().resolveAdminTool(rootKey, parentPath).getHandler().getName();
153
154         html.append(getToolManager().generateNavBar(toolPath, this));
155
156         // check if page switch needed
157
int size = 1;
158         try {
159             size = getSettings().getCollector().getResults(getCms()).size()
160                 / getSettings().getUserSettings().getExplorerFileEntries()
161                 + 1;
162         } catch (CmsException e) {
163             // ignore
164
}
165         // build title
166
html.append("<div class='screenTitle'>\n");
167         html.append("\t<table width='100%' cellspacing='0'>\n");
168         html.append("\t\t<tr>\n");
169         html.append("\t\t\t<td>\n");
170         html.append(getAdminTool().getHandler().getName());
171         html.append("\n\t\t\t</td>\n");
172         html.append("\t\t\t<td class='uplevel'>\n");
173         // if page switch needed
174
if (size > 1) {
175             html.append("<form name='page_switch' method='post' target='admin_content' action='");
176             html.append(getJsp().link(A_CmsListExplorerDialog.PATH_EXPLORER_LIST)).append("'>\n");
177         }
178         // list view button
179
CmsMessages messages = Messages.get().getBundle(getLocale());
180         html.append(A_CmsHtmlIconButton.defaultButtonHtml(
181             getJsp(),
182             CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
183             "id-list-switch",
184             messages.key(Messages.GUI_LIST_ACTION_LIST_SWITCH_NAME_0),
185             messages.key(Messages.GUI_LIST_ACTION_LIST_SWITCH_HELP_0),
186             true,
187             "list/list.png",
188             null,
189             "openPage('" + listLevelLink + "');"));
190         html.append("\n");
191         // if page switch needed
192
if (size > 1) {
193             Map JavaDoc params = new HashMap JavaDoc(getJsp().getRequest().getParameterMap());
194             params.remove(CmsListExplorerFrameset.PARAM_PAGE);
195             Iterator JavaDoc it = params.keySet().iterator();
196             while (it.hasNext()) {
197                 String JavaDoc param = (String JavaDoc)it.next();
198                 String JavaDoc[] value = (String JavaDoc[])params.get(param);
199                 for (int i = 0; i < value.length; i++) {
200                     html.append("<input type=\"hidden\" name=\"");
201                     html.append(param);
202                     html.append("\" value=\"");
203                     String JavaDoc encoded = CmsEncoder.encode(value[i], getCms().getRequestContext().getEncoding());
204                     html.append(encoded);
205                     html.append("\">\n");
206                 }
207             }
208
209             html.append("<span class='menu'>&nbsp;&nbsp;Page:&nbsp;</span>\n");
210             html.append("<select name='explorer_page' class='location' onchange='this.form.submit()'>\n");
211             for (int i = 1; i <= size; i++) {
212                 String JavaDoc selected = "";
213                 if (getSettings().getExplorerPage() == i) {
214                     selected = " selected";
215                 }
216                 html.append("<option value='").append(i).append("'").append(selected).append(">");
217                 html.append(i).append("</option>\n");
218             }
219             html.append("</select>\n");
220         }
221         // uplevel button only if needed
222
if (getParentPath() != toolPath) {
223             html.append(A_CmsHtmlIconButton.defaultButtonHtml(
224                 getJsp(),
225                 CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
226                 "id-up-level",
227                 org.opencms.workplace.tools.Messages.get().getBundle(getLocale()).key(
228                     org.opencms.workplace.tools.Messages.GUI_ADMIN_VIEW_UPLEVEL_0),
229                 parentName,
230                 true,
231                 "admin/images/up.png",
232                 null,
233                 "openPage('" + upLevelLink + "');"));
234         }
235         // if page switch needed
236
if (size > 1) {
237             html.append("</form>");
238         }
239         html.append("\n\t\t\t</td>\n");
240         html.append("\t\t</tr>\n");
241         html.append("\t</table>\n");
242         html.append("</div>\n");
243         return CmsToolMacroResolver.resolveMacros(html.toString(), this);
244     }
245
246     /**
247      * Performs the dialog actions depending on the initialized action and displays the dialog form.<p>
248      *
249      * @throws ServletException if forwarding explorer view fails
250      * @throws IOException if forwarding explorer view fails
251      */

252     public void displayDialog() throws IOException JavaDoc, ServletException JavaDoc {
253
254         getSettings().setExplorerMode(CmsExplorer.VIEW_LIST);
255         getToolManager().jspForwardPage(this, FILE_EXPLORER_FILELIST, null);
256     }
257
258     /**
259      * Validates the needed parameters and display the frameset.<p>
260      *
261      * @throws JspException if close action fail
262      * @throws IOException in case of errros displaying to the required page
263      */

264     public void displayFrameSet() throws JspException JavaDoc, IOException JavaDoc {
265
266         try {
267             // validate parameters
268
} catch (Exception JavaDoc e) {
269             setAction(ACTION_CANCEL);
270             actionCloseDialog();
271             return;
272         }
273
274         if (getJsp().getRequest().getParameter(CmsListExplorerFrameset.PARAM_PAGE) != null) {
275             int page = Integer.parseInt(getJsp().getRequest().getParameter(CmsListExplorerFrameset.PARAM_PAGE));
276             getSettings().setExplorerPage(page);
277         }
278         JspWriter JavaDoc out = getJsp().getJspContext().getOut();
279         out.print(defaultActionHtml());
280     }
281
282     /**
283      * @see org.opencms.workplace.CmsDialog#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
284      */

285     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
286
287         setParamStyle(CmsToolDialog.STYLE_NEW);
288         super.initWorkplaceRequestValues(settings, request);
289     }
290
291 }
292
Popular Tags