KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > CmsToolDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/tools/CmsToolDialog.java,v $
3  * Date : $Date: 2006/10/06 14:02:20 $
4  * Version: $Revision: 1.36 $
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.tools;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.OpenCms;
36 import org.opencms.security.CmsRoleViolationException;
37 import org.opencms.util.CmsStringUtil;
38 import org.opencms.workplace.CmsDialog;
39 import org.opencms.workplace.CmsWorkplace;
40 import org.opencms.workplace.CmsWorkplaceSettings;
41
42 import java.util.HashMap JavaDoc;
43 import java.util.Map JavaDoc;
44
45 import javax.servlet.http.HttpServletRequest JavaDoc;
46
47 /**
48  * Helper class that encapsulates all the code for the "new"
49  * style of the administration dialogs.<p>
50  *
51  * @author Michael Moossen
52  *
53  * @version $Revision: 1.36 $
54  *
55  * @since 6.0.0
56  */

57 public class CmsToolDialog extends CmsWorkplace {
58
59     /** Request parameter name for the base tool path in the navegation, should be a parent tool of path. */
60     public static final String JavaDoc PARAM_BASE = "base";
61
62     /** Request parameter name for the tool path, should be an accesible tool under the given root. */
63     public static final String JavaDoc PARAM_PATH = "path";
64
65     /** Request parameter name for the root tool path. */
66     public static final String JavaDoc PARAM_ROOT = "root";
67
68     /** Request parameter name for the style type. */
69     public static final String JavaDoc PARAM_STYLE = "style";
70
71     /** Request parameter value for the 'new' dialog style. */
72     public static final String JavaDoc STYLE_NEW = "new";
73
74     /** Base parameter value. */
75     private String JavaDoc m_paramBase;
76
77     /** Path parameter value. */
78     private String JavaDoc m_paramPath;
79
80     /** Root parameter value. */
81     private String JavaDoc m_paramRoot;
82
83     /** Style parameter value. */
84     private String JavaDoc m_paramStyle;
85
86     /**
87      * Default Constructor.<p>
88      *
89      * @param jsp the jsp action element
90      */

91     public CmsToolDialog(CmsJspActionElement jsp) {
92
93         super(jsp);
94     }
95
96     /**
97      * Builds the standard javascript for submitting the dialog.<p>
98      *
99      * Should only be used by the <code>{@link CmsDialog#dialogScriptSubmit()}</code> method.<p>
100      *
101      * @return the standard javascript for submitting the dialog
102      */

103     public String JavaDoc dialogScriptSubmit() {
104
105         StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
106         html.append("function submitAction(actionValue, theForm, formName) {\n");
107         html.append("\tif (theForm == null) {\n");
108         html.append("\t\ttheForm = document.forms[formName];\n");
109         html.append("\t}\n");
110         html.append("\ttry {\n");
111         html.append("\t\ttheForm.").append(CmsDialog.PARAM_FRAMENAME).append(".value = window.name;\n");
112         html.append("\t} catch (e) {}\n");
113         html.append("\tif (actionValue == '" + CmsDialog.DIALOG_OK + "') {\n");
114         html.append("\t\tloadingOn();\n");
115         html.append("\t\treturn true;\n");
116         html.append("\t}\n");
117         html.append("\ttheForm." + CmsDialog.PARAM_ACTION + ".value = actionValue;\n");
118         html.append("\tsubmitForm(theForm);\n");
119         html.append("\treturn true;\n");
120         html.append("}\n");
121         return html.toString();
122     }
123
124     /**
125      * Generates the standard new style dialog title row, and tool grouping.<p>
126      *
127      * It is called by the <code>{@link org.opencms.workplace.CmsDialog#dialog(int, String)}</code> method.<p>
128      *
129      * @return a dialog window start / end segment
130      */

131     public String JavaDoc dialogTitle() {
132
133         StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
134         String JavaDoc toolPath = getCurrentToolPath();
135         String JavaDoc parentPath = getParentPath();
136         String JavaDoc rootKey = getToolManager().getCurrentRoot(this).getKey();
137         CmsTool parentTool = getToolManager().resolveAdminTool(rootKey, parentPath);
138         String JavaDoc upLevelLink = CmsToolManager.linkForToolPath(
139             getJsp(),
140             parentPath,
141             parentTool.getHandler().getParameters(this));
142         String JavaDoc parentName = getToolManager().resolveAdminTool(rootKey, parentPath).getHandler().getName();
143
144         html.append(getToolManager().generateNavBar(toolPath, this));
145         // build title
146
html.append("<div class='screenTitle'>\n");
147         html.append("\t<table width='100%' cellspacing='0'>\n");
148         html.append("\t\t<tr>\n");
149         html.append("\t\t\t<td>\n");
150         html.append(getAdminTool().getHandler().getName());
151         html.append("\n\t\t\t</td>");
152         // uplevel button only if needed
153
if (getParentPath() != toolPath) {
154             html.append("\t\t\t<td class='uplevel'>\n\t\t\t\t");
155             html.append(A_CmsHtmlIconButton.defaultButtonHtml(
156                 getJsp(),
157                 CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
158                 "id-up-level",
159                 Messages.get().getBundle(getLocale()).key(Messages.GUI_ADMIN_VIEW_UPLEVEL_0),
160                 parentName,
161                 true,
162                 "admin/images/up.png",
163                 null,
164                 "openPage('" + upLevelLink + "');"));
165             html.append("\n\t\t\t</td>\n");
166         }
167         html.append("\t\t</tr>\n");
168         html.append("\t</table>\n");
169         html.append("</div>\n");
170         return CmsToolMacroResolver.resolveMacros(html.toString(), this);
171     }
172
173     /**
174      * Returns the admin tool.<p>
175      *
176      * @return the admin tool
177      */

178     public CmsTool getAdminTool() {
179
180         return getToolManager().getCurrentTool(this);
181     }
182
183     /**
184      * Returns the current tool path.<p>
185      *
186      * @return the current tool path
187      */

188     public String JavaDoc getCurrentToolPath() {
189
190         return getToolManager().getCurrentToolPath(this);
191     }
192
193     /**
194      * Returns the value for the base parameter.<p>
195      *
196      * @return the value for the base parameter
197      */

198     public String JavaDoc getParamBase() {
199
200         return m_paramBase;
201     }
202
203     /**
204      * Returns the path parameter value.<p>
205      *
206      * @return the path parameter value
207      */

208     public String JavaDoc getParamPath() {
209
210         return m_paramPath;
211     }
212
213     /**
214      * Returns the root parameter value.<p>
215      *
216      * @return the root parameter value
217      */

218     public String JavaDoc getParamRoot() {
219
220         return m_paramRoot;
221     }
222
223     /**
224      * Returns the style parameter value.<p>
225      *
226      * @return the style parameter value
227      */

228     public String JavaDoc getParamStyle() {
229
230         return m_paramStyle;
231     }
232
233     /**
234      * Returns the path to the parent tool.<p>
235      *
236      * @return tha path to the parent tool
237      */

238     public String JavaDoc getParentPath() {
239
240         return getToolManager().getParent(this, getCurrentToolPath());
241     }
242
243     /**
244      * Returns the tool manager.<p>
245      *
246      * @return the tool manager
247      */

248     public CmsToolManager getToolManager() {
249
250         return OpenCms.getWorkplaceManager().getToolManager();
251     }
252
253     /**
254      * Builds an block area for icons.<p>
255      *
256      * @param segment the HTML segment (START / END)
257      * @param headline the headline String for the block
258
259      * @return block area start / end segment
260      *
261      * @see CmsDialog#dialogBlock(int, String, boolean)
262      */

263     public String JavaDoc iconsBlockArea(int segment, String JavaDoc headline) {
264
265         StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
266         if (segment == HTML_START) {
267             result.append("<!-- icons block area start -->\n");
268             result.append("<div class=\"dialogcontent\" unselectable=\"on\">");
269             result.append("<fieldset class=\"dialogblock\">\n");
270             result.append("<legend>");
271             result.append("<span class=\"textbold");
272             result.append("\" unselectable=\"on\">");
273             result.append(headline);
274             result.append("</span></legend>\n");
275             result.append("\t\t<table class='toolsArea' width='100%' cellspacing='0' cellpadding='0' border='0'>\n");
276             result.append("\t\t\t<tr><td>\n");
277         } else {
278             result.append("\t\t\t</td></tr>\n");
279             result.append("\t\t</table>\n");
280             result.append("</fieldset></div>\n");
281             result.append("<p>&nbsp;</p>\n");
282             result.append("<!-- icons block area end -->\n");
283         }
284         return result.toString();
285     }
286
287     /**
288      * Builds the end HTML for a block area with border in the dialog content area.<p>
289      *
290      * @return block area end segment
291      *
292      * @see CmsDialog#dialogBlockEnd()
293      */

294     public String JavaDoc iconsBlockAreaEnd() {
295
296         return iconsBlockArea(HTML_END, null);
297     }
298
299     /**
300      * Builds the start HTML for a block area with border and optional subheadline in the dialog content area.<p>
301      *
302      * @param headline the headline String for the block
303      *
304      * @return block area start segment
305      *
306      * @see CmsDialog#dialogBlockStart(String)
307      */

308     public String JavaDoc iconsBlockAreaStart(String JavaDoc headline) {
309
310         return iconsBlockArea(HTML_START, headline);
311     }
312
313     /**
314      * Initializes the admin tool main view.<p>
315      *
316      * @return the new modified params array
317      * @throws CmsRoleViolationException in case the dialog is opened by a user without the necessary privileges
318      */

319     public Map JavaDoc initAdminTool() throws CmsRoleViolationException {
320
321         Map JavaDoc params = new HashMap JavaDoc(getParameterMap());
322         // initialize
323
getToolManager().initParams(this);
324
325         // adjust params if called as default
326
if (!useNewStyle()) {
327             params.put(PARAM_STYLE, new String JavaDoc[] {CmsToolDialog.STYLE_NEW});
328             setParamStyle(CmsToolDialog.STYLE_NEW);
329         }
330
331         try {
332             // a dialog just for the close link param accessors
333
CmsDialog wp = (CmsDialog)this;
334             // set close link
335
if (CmsStringUtil.isEmptyOrWhitespaceOnly(wp.getParamCloseLink())) {
336                 if (!getToolManager().getBaseToolPath(this).equals(getToolManager().getCurrentToolPath(this))) {
337                     Map JavaDoc args = getToolManager().resolveAdminTool(getParamRoot(), getParentPath()).getHandler().getParameters(
338                         wp);
339                     wp.setParamCloseLink(CmsToolManager.linkForToolPath(getJsp(), getParentPath(), args));
340                     params.put(CmsDialog.PARAM_CLOSELINK, new String JavaDoc[] {wp.getParamCloseLink()});
341                 }
342             }
343         } catch (Exception JavaDoc e) {
344             // ignore
345
}
346
347         if (!getToolManager().getCurrentTool(this).getHandler().isEnabled(getCms())) {
348             throw new CmsRoleViolationException(Messages.get().container(Messages.ERR_ADMIN_INSUFFICIENT_RIGHTS_0));
349         }
350
351         return params;
352     }
353
354     /**
355      * @see org.opencms.workplace.CmsWorkplace#pageBody(int, java.lang.String, java.lang.String)
356      */

357     public String JavaDoc pageBody(int segment, String JavaDoc className, String JavaDoc parameters) {
358
359         if (!useNewStyle()) {
360             return super.pageBody(segment, className, parameters);
361         } else {
362             Map JavaDoc data = CmsStringUtil.extendAttribute(parameters, "onLoad", "bodyLoad();");
363             String JavaDoc onLoad = (String JavaDoc)data.get("value");
364             String JavaDoc myPars = (String JavaDoc)data.get("text");
365             data = CmsStringUtil.extendAttribute(myPars, "onUnload", "bodyUnload();");
366             String JavaDoc onUnload = (String JavaDoc)data.get("value");
367             myPars = (String JavaDoc)data.get("text");
368             if (segment == HTML_START) {
369                 StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
370                 html.append("</head>\n");
371                 html.append("<body onLoad=");
372                 html.append(onLoad);
373                 html.append(" onUnload=");
374                 html.append(onUnload);
375                 html.append(CmsStringUtil.isNotEmpty(className) ? " class='" + className + "'" : "");
376                 html.append(CmsStringUtil.isNotEmpty(myPars) ? " " + myPars : "");
377                 html.append(">\n");
378                 html.append("\t<table border='0' cellspacing='0' cellpadding='0' id='loaderContainer' onClick='return false;'>\n");
379                 html.append("\t\t<tr><td id='loaderContainerH'><div id='loader'>\n");
380                 html.append("\t\t\t<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td>\n");
381                 html.append("\t\t\t\t<p><img SRC='");
382                 html.append(getSkinUri());
383                 html.append("commons/wait.gif");
384                 html.append("' height='32' width='32' alt=''/>\n");
385                 html.append("\t\t\t\t<strong>");
386                 html.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_ADMIN_VIEW_LOADING_0));
387                 html.append("</strong></p>\n");
388                 html.append("\t\t\t</td></tr></table>\n");
389                 html.append("\t\t</div></td></tr>\n");
390                 html.append("\t</table>\n");
391                 html.append("\t<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td id='screenH'>\n");
392                 return html.toString();
393             } else {
394                 StringBuffer JavaDoc html = new StringBuffer JavaDoc(128);
395                 html.append("\t</td></tr></table>\n");
396                 html.append("</body>");
397                 return html.toString();
398             }
399         }
400     }
401
402     /**
403      * @see org.opencms.workplace.CmsWorkplace#pageHtmlStyle(int, java.lang.String, java.lang.String)
404      */

405     public String JavaDoc pageHtmlStyle(int segment, String JavaDoc title, String JavaDoc stylesheet) {
406
407         if (!useNewStyle() || segment != HTML_START) {
408             return super.pageHtmlStyle(segment, title, stylesheet);
409         }
410
411         StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
412         html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
413         html.append("<html>\n");
414         html.append("<head>\n");
415         html.append("<meta http-equiv='Content-Type' content='text/html; charset=");
416         html.append(getEncoding());
417         html.append("' >\n");
418         if (title != null) {
419             html.append("<title>");
420             html.append(title);
421             html.append("</title>\n");
422         } else {
423             // the title tag is required for valid HTML
424
html.append("<title></title>\n");
425         }
426         html.append("<link rel='stylesheet' type='text/css' HREF='");
427         html.append(getStyleUri(getJsp()));
428         html.append("new_admin.css'>\n");
429         html.append("<script type='text/javascript' SRC='");
430         html.append(getSkinUri());
431         html.append("admin/javascript/general.js'></script>\n");
432         html.append("<script type='text/javascript' SRC='");
433         html.append(getResourceUri());
434         html.append("editors/xmlcontent/help.js'></script>\n\n");
435         html.append("<script type='text/javascript'>\n");
436         html.append("\tfunction bodyLoad() {\n");
437         html.append("\t\tsetContext(\"");
438         html.append(CmsStringUtil.escapeJavaScript(resolveMacros(getAdminTool().getHandler().getHelpText())));
439         html.append("\");\n");
440         html.append("\t\tsetActiveItemByName(\"");
441         html.append(getCurrentToolPath());
442         html.append("\");\n");
443         html.append("\t\tloadingOff();\n");
444         html.append("\t\ttry {\n");
445         html.append("\t\t\tdocument.getElementById('loaderContainerH').height = wHeight();\n");
446         html.append("\t\t} catch (e) {}\n");
447         html.append("\t}\n");
448         html.append("\tfunction bodyUnload() {\n");
449         html.append("\t\tloadingOn();\n");
450         html.append("\t}\n");
451         html.append("</script>\n");
452         return html.toString();
453     }
454
455     /**
456      * Sets the value of the base parameter.<p>
457      *
458      * @param paramBase the value of the base parameter to set
459      */

460     public void setParamBase(String JavaDoc paramBase) {
461
462         m_paramBase = paramBase;
463     }
464
465     /**
466      * Sets the path parameter value.<p>
467      *
468      * @param paramPath the path parameter value to set
469      */

470     public void setParamPath(String JavaDoc paramPath) {
471
472         m_paramPath = paramPath;
473     }
474
475     /**
476      * Sets the root parameter value.<p>
477      *
478      * @param paramRoot the root parameter value to set
479      */

480     public void setParamRoot(String JavaDoc paramRoot) {
481
482         m_paramRoot = paramRoot;
483     }
484
485     /**
486      * Sets the style parameter value.<p>
487      *
488      * @param paramStyle the style parameter value to set
489      */

490     public void setParamStyle(String JavaDoc paramStyle) {
491
492         m_paramStyle = paramStyle;
493     }
494
495     /**
496      * Tests if we are working with the new administration dialog style.<p>
497      *
498      * The default is the new style, this param is not intented for external use.<p>
499      *
500      * @return <code>true</code> if using the new style
501      */

502     public boolean useNewStyle() {
503
504         return getParamStyle() != null && getParamStyle().equals(CmsToolDialog.STYLE_NEW);
505     }
506
507     /**
508      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
509      */

510     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
511
512         fillParamValues(request);
513     }
514 }
Popular Tags