KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > CmsDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsDialog.java,v $
3  * Date : $Date: 2006/10/06 14:02:20 $
4  * Version: $Revision: 1.97 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * For further information about Alkacon Software GmbH, please see the
21  * company website: http://www.alkacon.com
22  *
23  * For further information about OpenCms, please see the
24  * project website: http://www.opencms.org
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this library; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  *
30  */

31
32 package org.opencms.workplace;
33
34 import org.opencms.file.CmsResource;
35 import org.opencms.file.CmsResourceFilter;
36 import org.opencms.i18n.CmsMessageContainer;
37 import org.opencms.jsp.CmsJspActionElement;
38 import org.opencms.main.CmsException;
39 import org.opencms.main.CmsLog;
40 import org.opencms.main.OpenCms;
41 import org.opencms.security.CmsPermissionSet;
42 import org.opencms.util.CmsRequestUtil;
43 import org.opencms.util.CmsStringUtil;
44 import org.opencms.workplace.tools.CmsToolDialog;
45 import org.opencms.workplace.tools.CmsToolManager;
46
47 import java.io.IOException JavaDoc;
48 import java.util.HashMap JavaDoc;
49 import java.util.Map JavaDoc;
50
51 import javax.servlet.http.HttpServletRequest JavaDoc;
52 import javax.servlet.http.HttpServletResponse JavaDoc;
53 import javax.servlet.jsp.JspException JavaDoc;
54 import javax.servlet.jsp.JspWriter JavaDoc;
55 import javax.servlet.jsp.PageContext JavaDoc;
56
57 import org.apache.commons.logging.Log;
58
59 /**
60  * Provides methods for building the dialog windows of OpenCms.<p>
61  *
62  * @author Andreas Zahner
63  *
64  * @version $Revision: 1.97 $
65  *
66  * @since 6.0.0
67  */

68 public class CmsDialog extends CmsToolDialog {
69
70     /** Value for the action: cancel. */
71     public static final int ACTION_CANCEL = 4;
72
73     /** Value for the action: close popup window. */
74     public static final int ACTION_CLOSEPOPUP = 6;
75
76     /** Value for the action: save & close popup window. */
77     public static final int ACTION_CLOSEPOPUP_SAVE = 7;
78
79     /** Value for the action: confirmed. */
80     public static final int ACTION_CONFIRMED = 1;
81
82     /** Value for the action: default (show initial dialog form). */
83     public static final int ACTION_DEFAULT = 0;
84
85     /** Value for the action: ok. */
86     public static final int ACTION_OK = 3;
87
88     // note: action values 90 - 99 are reserved for reports
89
/** Value for the action: begin the report. */
90     public static final int ACTION_REPORT_BEGIN = 90;
91
92     /** Value for the action: end the report. */
93     public static final int ACTION_REPORT_END = 92;
94
95     /** Value for the action: update the report. */
96     public static final int ACTION_REPORT_UPDATE = 91;
97
98     /** Value for the action: button "set" clicked. */
99     public static final int ACTION_SET = 5;
100
101     /** Value for the action: wait (show please wait screen). */
102     public static final int ACTION_WAIT = 2;
103
104     /** Constant for the "Advanced" button in the build button methods. */
105     public static final int BUTTON_ADVANCED = 3;
106
107     /** Constant for the "Back" button in the build button methods. */
108     public static final int BUTTON_BACK = 9;
109
110     /** Constant for the "Cancel" button in the build button methods. */
111     public static final int BUTTON_CANCEL = 1;
112
113     /** Constant for the "Close" button in the build button methods. */
114     public static final int BUTTON_CLOSE = 2;
115
116     /** Constant for the "Continue" button in the build button methods. */
117     public static final int BUTTON_CONTINUE = 10;
118
119     /** Constant for the "Details" button in the build button methods. */
120     public static final int BUTTON_DETAILS = 5;
121
122     /** Constant for the "Discard" button in the build button methods (same function as "Cancel" button but different text on button. */
123     public static final int BUTTON_DISCARD = 8;
124
125     /** Constant for the "Edit" button in the build button methods (same function as "Ok" button but different text on button. */
126     public static final int BUTTON_EDIT = 7;
127
128     /** Constant for the "OK" button in the build button methods. */
129     public static final int BUTTON_OK = 0;
130
131     /** Constant for the "OK" button in the build button methods (without form submission). */
132     public static final int BUTTON_OK_NO_SUBMIT = 6;
133
134     /** Constant for the "Set" button in the build button methods. */
135     public static final int BUTTON_SET = 4;
136
137     /** Request parameter value for the action: back. */
138     public static final String JavaDoc DIALOG_BACK = "back";
139
140     /** Request parameter value for the action: cancel. */
141     public static final String JavaDoc DIALOG_CANCEL = "cancel";
142
143     /** Request parameter value for the action: dialog confirmed. */
144     public static final String JavaDoc DIALOG_CONFIRMED = "confirmed";
145
146     /** Request parameter value for the action: continue. */
147     public static final String JavaDoc DIALOG_CONTINUE = "continue";
148
149     /** Request parameter value for the action: initial call. */
150     public static final String JavaDoc DIALOG_INITIAL = "initial";
151
152     /** Request parameter value for the action: ok. */
153     public static final String JavaDoc DIALOG_OK = "ok";
154
155     /** Request parameter value for the action: set. */
156     public static final String JavaDoc DIALOG_SET = "set";
157
158     /** Request parameter value for the action: show please wait screen. */
159     public static final String JavaDoc DIALOG_WAIT = "wait";
160
161     /** Request parameter name for the action. */
162     public static final String JavaDoc PARAM_ACTION = "action";
163
164     /** Request parameter name for the closelink. */
165     public static final String JavaDoc PARAM_CLOSELINK = "closelink";
166
167     /** Request parameter name for the dialog type. */
168     public static final String JavaDoc PARAM_DIALOGTYPE = "dialogtype";
169
170     /** Request parameter name for the error stack. */
171     public static final String JavaDoc PARAM_ERRORSTACK = "errorstack";
172
173     /** Request parameter name for the file. */
174     public static final String JavaDoc PARAM_FILE = "file";
175
176     /** Request parameter name for the frame name. */
177     public static final String JavaDoc PARAM_FRAMENAME = "framename";
178
179     /** Request parameter name for the "is popup" flag. */
180     public static final String JavaDoc PARAM_ISPOPUP = "ispopup";
181
182     /** Request parameter name for the lock. */
183     public static final String JavaDoc PARAM_LOCK = "lock";
184
185     /** Request parameter name for the error message. */
186     public static final String JavaDoc PARAM_MESSAGE = "message";
187
188     /** Request parameter name for the redirect flag. */
189     public static final String JavaDoc PARAM_REDIRECT = "redirect";
190
191     /** Request parameter name for the resource. */
192     public static final String JavaDoc PARAM_RESOURCE = "resource";
193
194     /** Request parameter name for the target. */
195     public static final String JavaDoc PARAM_TARGET = "target";
196
197     /** Request parameter name for the thread id. */
198     public static final String JavaDoc PARAM_THREAD = "thread";
199
200     /** Request parameter name for indicating if another thread is following the current one. */
201     public static final String JavaDoc PARAM_THREAD_HASNEXT = "threadhasnext";
202
203     /** Request parameter name for the dialog title. */
204     public static final String JavaDoc PARAM_TITLE = "title";
205
206     /** Request parameter value for the action: begin the report. */
207     public static final String JavaDoc REPORT_BEGIN = "reportbegin";
208
209     /** Request parameter value for the action: end the report. */
210     public static final String JavaDoc REPORT_END = "reportend";
211
212     /** Request parameter value for the action: update the report. */
213     public static final String JavaDoc REPORT_UPDATE = "reportupdate";
214
215     /** Key name for the throwable attribute. */
216     protected static final String JavaDoc ATTRIBUTE_THROWABLE = "throwable";
217
218     /** The log object for this class. */
219     private static final Log LOG = CmsLog.getLog(CmsDialog.class);
220
221     private int m_action;
222
223     /**
224      * The custom mapping for online help.<p>
225      *
226      * It will be translated to a javascript variable called onlineHelpUriCustom.
227      * If it is set, the top.head javascript for the online help will use this value. <p>
228      *
229      *
230      */

231     private String JavaDoc m_onlineHelpUriCustom;
232     private String JavaDoc m_paramAction;
233     private String JavaDoc m_paramCloseLink;
234     private String JavaDoc m_paramDialogtype;
235     private String JavaDoc m_paramFrameName;
236     private String JavaDoc m_paramIsPopup;
237     private String JavaDoc m_paramMessage;
238     private String JavaDoc m_paramRedirect;
239     private String JavaDoc m_paramResource;
240     private String JavaDoc m_paramTitle;
241
242     /**
243      * Public constructor with JSP action element.<p>
244      *
245      * @param jsp an initialized JSP action element
246      */

247     public CmsDialog(CmsJspActionElement jsp) {
248
249         super(jsp);
250     }
251
252     /**
253      * Public constructor with JSP variables.<p>
254      *
255      * @param context the JSP page context
256      * @param req the JSP request
257      * @param res the JSP response
258      */

259     public CmsDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
260
261         this(new CmsJspActionElement(context, req, res));
262     }
263
264     /**
265      * Returns an initialized CmsDialog instance that is read from the request attributes.<p>
266      *
267      * This method is used by dialog elements.
268      * The dialog elements do not initialize their own workplace class,
269      * but use the initialized instance of the "master" class.
270      * This is required to ensure that parameters of the "master" class
271      * can properly be kept on the dialog elements.<p>
272      *
273      * To prevent null pointer exceptions, an empty dialog is returned if
274      * nothing is found in the request attributes.<p>
275      *
276      * @param context the JSP page context
277      * @param req the JSP request
278      * @param res the JSP response
279      * @return an initialized CmsDialog instance that is read from the request attributes
280      */

281     public static CmsDialog initCmsDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
282
283         CmsDialog wp = (CmsDialog)req.getAttribute(CmsWorkplace.SESSION_WORKPLACE_CLASS);
284         if (wp == null) {
285             // ensure that we don't get null pointers if the page is directly called
286
wp = new CmsDialog(new CmsJspActionElement(context, req, res));
287             wp.fillParamValues(req);
288         }
289         return wp;
290     }
291
292     /**
293      * Used to close the current JSP dialog.<p>
294      *
295      * This method tries to include the URI stored in the workplace settings.
296      * This URI is determined by the frame name, which has to be set
297      * in the framename parameter.<p>
298      *
299      * @throws JspException if including an element fails
300      */

301     public void actionCloseDialog() throws JspException JavaDoc {
302
303         // create a map with empty "resource" parameter to avoid changing the folder when returning to explorer file list
304
Map JavaDoc params = new HashMap JavaDoc();
305         params.put(PARAM_RESOURCE, "");
306         if (isPopup()) {
307             try {
308                 // try to close the popup
309
JspWriter JavaDoc out = getJsp().getJspContext().getOut();
310                 out.write("<html><head></head>\n");
311                 out.write("<body onload=\"top.close();\">\n");
312                 out.write("</body>\n");
313                 out.write("</html>\n");
314             } catch (IOException JavaDoc e) {
315                 // error redirecting, include explorer file list
316
getJsp().include(FILE_EXPLORER_FILELIST, null, params);
317             }
318         } else if (getParamCloseLink() != null) {
319             // close link parameter present
320
try {
321                 if (Boolean.valueOf(getParamRedirect()).booleanValue()) {
322                     // redirect parameter is true, redirect to given close link
323
getJsp().getResponse().sendRedirect(getParamCloseLink());
324                 } else {
325                     // forward JSP
326
if (!isForwarded()) {
327                         setForwarded(true);
328                         CmsRequestUtil.forwardRequest(
329                             getParamCloseLink(),
330                             getJsp().getRequest(),
331                             getJsp().getResponse());
332                     }
333                 }
334             } catch (Exception JavaDoc e) {
335                 // forward failed
336
throw new JspException JavaDoc(e.getMessage(), e);
337             }
338         } else if (getParamFramename() != null) {
339             // legacy backoffice mode
340
// TODO: remove this if all JSP based pages have been fully ported to the new Administration
341

342             // framename parameter found, get URI
343
String JavaDoc frameUri = (String JavaDoc)getSettings().getFrameUris().get(getParamFramename());
344             if (frameUri != null) {
345                 // URI found, include it
346
if (frameUri.startsWith(OpenCms.getSystemInfo().getOpenCmsContext())) {
347                     // remove context path from URI before inclusion
348
frameUri = frameUri.substring(OpenCms.getSystemInfo().getOpenCmsContext().length());
349                 }
350                 if (frameUri.endsWith("administration_content_top.html")) {
351                     String JavaDoc wpClass = this.getClass().getName();
352                     String JavaDoc wpPackage = this.getClass().getPackage().getName();
353                     if ((wpPackage.endsWith("commons") || wpPackage.endsWith("gallery"))
354                         && (!wpClass.endsWith("Report"))) {
355                         // for returning from common workplace action, show explorer filelist again (i.e. gallery & project views)
356
getJsp().include(FILE_EXPLORER_FILELIST, null, params);
357                     } else {
358                         try {
359                             // redirect to administration body frame with "sender" parameter
360
getJsp().getResponse().sendRedirect(
361                                 getJsp().link(frameUri) + "?sender=/system/workplace/administration/");
362                         } catch (IOException JavaDoc e) {
363                             params.put("sender", "/system/workplace/administration/");
364                             getJsp().include(frameUri, null, params);
365                         }
366                     }
367                 } else {
368                     // include the found frame URI
369
getJsp().include(frameUri, null, params);
370                 }
371             } else {
372                 // no URI found, include the explorer file list
373
getJsp().include(FILE_EXPLORER_FILELIST, null, params);
374             }
375         } else {
376             // no framename parameter found, include the explorer file list
377
getJsp().include(FILE_EXPLORER_FILELIST, null, params);
378         }
379     }
380
381     /**
382      * Builds the outer dialog window border.<p>
383      *
384      * @param segment the HTML segment (START / END)
385      * @param attributes optional additional attributes for the opening dialog table
386      * @return a dialog window start / end segment
387      */

388     public String JavaDoc dialog(int segment, String JavaDoc attributes) {
389
390         if (segment == HTML_START) {
391             StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
392             if (useNewStyle()) {
393                 html.append(dialogTitle());
394             }
395             html.append("<table class=\"dialog\" cellpadding=\"0\" cellspacing=\"0\"");
396             if (attributes != null) {
397                 html.append(" ");
398                 html.append(attributes);
399             }
400             html.append("><tr><td>\n<table class=\"dialogbox\" cellpadding=\"0\" cellspacing=\"0\">\n");
401             html.append("<tr><td>\n");
402             if (useNewStyle() && getToolManager().hasToolPathForUrl(getJsp().getRequestContext().getUri())) {
403                 html.append(getAdminTool().groupHtml(this));
404             }
405             return html.toString();
406         } else {
407             return "</td></tr></table>\n</td></tr></table>\n<p>&nbsp;</p>\n";
408         }
409     }
410
411     /**
412      * Builds a block with 3D border and optional subheadline in the dialog content area.<p>
413      *
414      * @param segment the HTML segment (START / END)
415      * @param headline the headline String for the block
416      * @param error if true, an error block will be created
417      * @return 3D block start / end segment
418      */

419     public String JavaDoc dialogBlock(int segment, String JavaDoc headline, boolean error) {
420
421         if (segment == HTML_START) {
422             StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
423             String JavaDoc errorStyle = "";
424             if (error) {
425                 errorStyle = " dialogerror";
426             }
427             result.append("<!-- 3D block start -->\n");
428             result.append("<fieldset class=\"dialogblock\">\n");
429             if (CmsStringUtil.isNotEmpty(headline)) {
430                 result.append("<legend>");
431                 result.append("<span class=\"textbold");
432                 result.append(errorStyle);
433                 result.append("\" unselectable=\"on\">");
434                 result.append(headline);
435                 result.append("</span></legend>\n");
436             }
437             return result.toString();
438         } else {
439             return "</fieldset>\n<!-- 3D block end -->\n";
440         }
441     }
442
443     /**
444      * Builds the end HTML for a block with 3D border in the dialog content area.<p>
445      *
446      * @return 3D block start / end segment
447      */

448     public String JavaDoc dialogBlockEnd() {
449
450         return dialogBlock(HTML_END, null, false);
451     }
452
453     /**
454      * Builds the start HTML for a block with 3D border and optional subheadline in the dialog content area.<p>
455      *
456      * @param headline the headline String for the block
457      * @return 3D block start / end segment
458      */

459     public String JavaDoc dialogBlockStart(String JavaDoc headline) {
460
461         return dialogBlock(HTML_START, headline, false);
462     }
463
464     /**
465      * Builds the button row under the dialog content area without the buttons.<p>
466      *
467      * @param segment the HTML segment (START / END)
468      * @return the button row start / end segment
469      */

470     public String JavaDoc dialogButtonRow(int segment) {
471
472         if (segment == HTML_START) {
473             return "<!-- button row start -->\n<div class=\"dialogbuttons\" unselectable=\"on\">\n";
474         } else {
475             return "</div>\n<!-- button row end -->\n";
476         }
477     }
478
479     /**
480      * Builds the end of the button row under the dialog content area without the buttons.<p>
481      *
482      * @return the button row end segment
483      */

484     public String JavaDoc dialogButtonRowEnd() {
485
486         return dialogButtonRow(HTML_END);
487     }
488
489     /**
490      * Builds the start of the button row under the dialog content area without the buttons.<p>
491      *
492      * @return the button row start segment
493      */

494     public String JavaDoc dialogButtonRowStart() {
495
496         return dialogButtonRow(HTML_START);
497     }
498
499     /**
500      * Builds the html for the button row under the dialog content area, including buttons.<p>
501      *
502      * @param buttons array of constants of which buttons to include in the row
503      * @param attributes array of Strings for additional button attributes
504      * @return the html for the button row under the dialog content area, including buttons
505      */

506     public String JavaDoc dialogButtons(int[] buttons, String JavaDoc[] attributes) {
507
508         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
509         result.append(dialogButtonRow(HTML_START));
510         for (int i = 0; i < buttons.length; i++) {
511             dialogButtonsHtml(result, buttons[i], attributes[i]);
512         }
513         result.append(dialogButtonRow(HTML_END));
514         return result.toString();
515     }
516
517     /**
518      * Builds a button row with a single "close" button.<p>
519      *
520      * @return the button row
521      */

522     public String JavaDoc dialogButtonsClose() {
523
524         return dialogButtons(new int[] {BUTTON_CLOSE}, new String JavaDoc[1]);
525     }
526
527     /**
528      * Builds a button row with a single "close" button.<p>
529      *
530      * @param closeAttribute additional attributes for the "close" button
531      * @return the button row
532      */

533     public String JavaDoc dialogButtonsClose(String JavaDoc closeAttribute) {
534
535         return dialogButtons(new int[] {BUTTON_CLOSE}, new String JavaDoc[] {closeAttribute});
536     }
537
538     /**
539      * Builds a button row with a "close" and a "details" button.<p>
540      *
541      * @param closeAttribute additional attributes for the "close" button
542      * @param detailsAttribute additional attributes for the "details" button
543      * @return the button row
544      */

545     public String JavaDoc dialogButtonsCloseDetails(String JavaDoc closeAttribute, String JavaDoc detailsAttribute) {
546
547         return dialogButtons(new int[] {BUTTON_CLOSE, BUTTON_DETAILS}, new String JavaDoc[] {closeAttribute, detailsAttribute});
548     }
549
550     /**
551      * Builds a button row with a single "ok" button.<p>
552      *
553      * @return the button row
554      */

555     public String JavaDoc dialogButtonsOk() {
556
557         return dialogButtons(new int[] {BUTTON_OK}, new String JavaDoc[1]);
558     }
559
560     /**
561      * Builds a button row with a single "ok" button.<p>
562      *
563      * @param okAttribute additional attributes for the "ok" button
564      * @return the button row
565      */

566     public String JavaDoc dialogButtonsOk(String JavaDoc okAttribute) {
567
568         return dialogButtons(new int[] {BUTTON_OK}, new String JavaDoc[] {okAttribute});
569     }
570
571     /**
572      * Builds a button row with an "ok" and a "cancel" button.<p>
573      *
574      * @return the button row
575      */

576     public String JavaDoc dialogButtonsOkCancel() {
577
578         return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL}, new String JavaDoc[2]);
579     }
580
581     /**
582      * Builds a button row with an "ok" and a "cancel" button.<p>
583      *
584      * @param okAttributes additional attributes for the "ok" button
585      * @param cancelAttributes additional attributes for the "cancel" button
586      * @return the button row
587      */

588     public String JavaDoc dialogButtonsOkCancel(String JavaDoc okAttributes, String JavaDoc cancelAttributes) {
589
590         return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL}, new String JavaDoc[] {okAttributes, cancelAttributes});
591     }
592
593     /**
594      * Builds a button row with an "ok", a "cancel" and an "advanced" button.<p>
595      *
596      * @param okAttributes additional attributes for the "ok" button
597      * @param cancelAttributes additional attributes for the "cancel" button
598      * @param advancedAttributes additional attributes for the "advanced" button
599      * @return the button row
600      */

601     public String JavaDoc dialogButtonsOkCancelAdvanced(String JavaDoc okAttributes, String JavaDoc cancelAttributes, String JavaDoc advancedAttributes) {
602
603         return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL, BUTTON_ADVANCED}, new String JavaDoc[] {
604             okAttributes,
605             cancelAttributes,
606             advancedAttributes});
607     }
608
609     /**
610      * Builds a button row with a "set", an "ok", and a "cancel" button.<p>
611      *
612      * @param setAttributes additional attributes for the "set" button
613      * @param okAttributes additional attributes for the "ok" button
614      * @param cancelAttributes additional attributes for the "cancel" button
615      * @return the button row
616      */

617     public String JavaDoc dialogButtonsSetOkCancel(String JavaDoc setAttributes, String JavaDoc okAttributes, String JavaDoc cancelAttributes) {
618
619         return dialogButtons(new int[] {BUTTON_SET, BUTTON_OK, BUTTON_CANCEL}, new String JavaDoc[] {
620             setAttributes,
621             okAttributes,
622             cancelAttributes});
623     }
624
625     /**
626      * Builds the content area of the dialog window.<p>
627      *
628      * @param segment the HTML segment (START / END)
629      * @param title the title String for the dialog window
630      * @return a content area start / end segment
631      */

632     public String JavaDoc dialogContent(int segment, String JavaDoc title) {
633
634         if (segment == HTML_START) {
635             StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
636             // null title is ok, we always want the title headline
637
result.append(dialogHead(title));
638             result.append("<div class=\"dialogcontent\" unselectable=\"on\">\n");
639             result.append("<!-- dialogcontent start -->\n");
640             return result.toString();
641         } else {
642             return "<!-- dialogcontent end -->\n</div>\n";
643         }
644     }
645
646     /**
647      * Returns the end html for the content area of the dialog window.<p>
648      *
649      * @return the end html for the content area of the dialog window
650      */

651     public String JavaDoc dialogContentEnd() {
652
653         return dialogContent(HTML_END, null);
654     }
655
656     /**
657      * Returns the start html for the content area of the dialog window.<p>
658      *
659      * @param title the title for the dialog
660      * @return the start html for the content area of the dialog window
661      */

662     public String JavaDoc dialogContentStart(String JavaDoc title) {
663
664         return dialogContent(HTML_START, title);
665     }
666
667     /**
668      * Returns the end html for the outer dialog window border.<p>
669      *
670      * @return the end html for the outer dialog window border
671      */

672     public String JavaDoc dialogEnd() {
673
674         return dialog(HTML_END, null);
675     }
676
677     /**
678      * Builds the title of the dialog window.<p>
679      *
680      * @param title the title String for the dialog window
681      * @return the HTML title String for the dialog window
682      */

683     public String JavaDoc dialogHead(String JavaDoc title) {
684
685         return "<div class=\"dialoghead\" unselectable=\"on\">" + (title == null ? "" : title) + "</div>";
686     }
687
688     /**
689      * Builds an invisible horiziontal spacer with the specified width.<p>
690      * @param width the width of the spacer in pixels
691      * @return an invisible horiziontal spacer with the specified width
692      */

693     public String JavaDoc dialogHorizontalSpacer(int width) {
694
695         return "<td><span style=\"display:block; height: 1px; width: " + width + "px;\"></span></td>";
696     }
697
698     /**
699      * Builds a dialog line without break (display: block).<p>
700      *
701      * @param segment the HTML segment (START / END)
702      * @return a row start / end segment
703      */

704     public String JavaDoc dialogRow(int segment) {
705
706         if (segment == HTML_START) {
707             return "<div class=\"dialogrow\">";
708         } else {
709             return "</div>\n";
710         }
711     }
712
713     /**
714      * Builds the end of a dialog line without break (display: block).<p>
715      *
716      * @return the row end segment
717      */

718     public String JavaDoc dialogRowEnd() {
719
720         return dialogRow(HTML_END);
721     }
722
723     /**
724      * Builds the start of a dialog line without break (display: block).<p>
725      *
726      * @return the row start segment
727      */

728     public String JavaDoc dialogRowStart() {
729
730         return dialogRow(HTML_START);
731     }
732
733     /**
734      * Builds the standard javascript for submitting the dialog.<p>
735      *
736      * @return the standard javascript for submitting the dialog
737      */

738     public String JavaDoc dialogScriptSubmit() {
739
740         if (useNewStyle()) {
741             return super.dialogScriptSubmit();
742         }
743         StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
744         result.append("function submitAction(actionValue, theForm, formName) {\n");
745         result.append("\tif (theForm == null) {\n");
746         result.append("\t\ttheForm = document.forms[formName];\n");
747         result.append("\t}\n");
748         result.append("\ttheForm." + PARAM_FRAMENAME + ".value = window.name;\n");
749         result.append("\tif (actionValue == \"" + DIALOG_OK + "\") {\n");
750         result.append("\t\treturn true;\n");
751         result.append("\t}\n");
752         result.append("\ttheForm." + PARAM_ACTION + ".value = actionValue;\n");
753         result.append("\ttheForm.submit();\n");
754         result.append("\treturn false;\n");
755         result.append("}\n");
756
757         return result.toString();
758     }
759
760     /**
761      * Builds a horizontal separator line in the dialog content area.<p>
762      *
763      * @return a separator element
764      */

765     public String JavaDoc dialogSeparator() {
766
767         return "<div class=\"dialogseparator\" unselectable=\"on\"></div>";
768     }
769
770     /**
771      * Builds a space between two elements in the dialog content area.<p>
772      *
773      * @return a space element
774      */

775     public String JavaDoc dialogSpacer() {
776
777         return "<div class=\"dialogspacer\" unselectable=\"on\">&nbsp;</div>";
778     }
779
780     /**
781      * Returns the start html for the outer dialog window border.<p>
782      *
783      * @return the start html for the outer dialog window border
784      */

785     public String JavaDoc dialogStart() {
786
787         return dialog(HTML_START, null);
788     }
789
790     /**
791      * Returns the start html for the outer dialog window border.<p>
792      *
793      * @param attributes optional html attributes to insert
794      * @return the start html for the outer dialog window border
795      */

796     public String JavaDoc dialogStart(String JavaDoc attributes) {
797
798         return dialog(HTML_START, attributes);
799     }
800
801     /**
802      * Builds a subheadline in the dialog content area.<p>
803      *
804      * @param headline the desired headline string
805      * @return a subheadline element
806      */

807     public String JavaDoc dialogSubheadline(String JavaDoc headline) {
808
809         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc(128);
810         retValue.append("<div class=\"dialogsubheader\" unselectable=\"on\">");
811         retValue.append(headline);
812         retValue.append("</div>\n");
813         return retValue.toString();
814     }
815
816     /**
817      * Builds the HTML code to fold and unfild a white-box.<p>
818      *
819      * @param headline the heading to display
820      * @param id the id of the toggle
821      * @param show true if the white box is open at the beginning
822      *
823      * @return HTML code to fold and unfild a white-box
824      */

825     public String JavaDoc dialogToggleStart(String JavaDoc headline, String JavaDoc id, boolean show) {
826
827         StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
828         // set icon and style class to use: hide user permissions
829
String JavaDoc image = "plus.png";
830         String JavaDoc styleClass = "hide";
831         if (show) {
832             // show user permissions
833
image = "minus.png";
834             styleClass = "show";
835         }
836
837         result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
838         result.append("<tr>\n");
839         result.append("\t<td style=\"vertical-align: bottom; padding-bottom: 2px;\"><a HREF=\"javascript:toggleDetail('");
840         result.append(id);
841         result.append("');\"><img SRC=\"");
842         result.append(getSkinUri());
843         result.append("commons/");
844         result.append(image);
845         result.append("\" class=\"noborder\" id=\"ic-");
846         result.append(id);
847         result.append("\"></a></td>\n");
848         result.append("\t<td>");
849         result.append(dialogSubheadline(headline));
850         result.append("</td>\n");
851         result.append("</tr>\n");
852         result.append("</table>\n");
853
854         result.append("<div class=\"");
855         result.append(styleClass);
856         result.append("\" id=\"");
857         result.append(id);
858         result.append("\">\n");
859         return result.toString();
860     }
861
862     /**
863      * Builds a white box in the dialog content area.<p>
864      *
865      * @param segment the HTML segment (START / END)
866      * @return the white box start / end segment
867      */

868     public String JavaDoc dialogWhiteBox(int segment) {
869
870         if (segment == HTML_START) {
871             return "<!-- white box start -->\n"
872                 + "<div class=\"dialoginnerboxborder\">\n"
873                 + "<div class=\"dialoginnerbox\" unselectable=\"off\">\n";
874         } else {
875             return "</div>\n</div>\n<!-- white box end -->\n";
876         }
877     }
878
879     /**
880      * Builds the end of a white box in the dialog content area.<p>
881      *
882      * @return the white box end segment
883      */

884     public String JavaDoc dialogWhiteBoxEnd() {
885
886         return dialogWhiteBox(HTML_END);
887     }
888
889     /**
890      * Builds the start of a white box in the dialog content area.<p>
891      *
892      * @return the white box start segment
893      */

894     public String JavaDoc dialogWhiteBoxStart() {
895
896         return dialogWhiteBox(HTML_START);
897     }
898
899     /**
900      * Returns the action value.<p>
901      *
902      * The action value is used on JSP pages to select the proper action
903      * in a large "switch" statement.<p>
904      *
905      * @return the action value
906      */

907     public int getAction() {
908
909         return m_action;
910     }
911
912     /**
913      * Returns the action to be carried out after a click on the cancel button..<p>
914      *
915      * @return the action to be carried out after a click on the cancel button.
916      */

917     public String JavaDoc getCancelAction() {
918
919         return DIALOG_CANCEL;
920     }
921
922     /**
923      * Returns the http URI of the current dialog, to be used
924      * as value for the "action" attribute of a html form.<p>
925      *
926      * This URI is the real one.<p>
927      *
928      * @return the http URI of the current dialog
929      */

930     public String JavaDoc getDialogRealUri() {
931
932         return getJsp().link(getJsp().getRequestContext().getUri());
933     }
934
935     /**
936      * Returns the http URI of the current dialog, to be used
937      * as value for the "action" attribute of a html form.<p>
938      *
939      * This URI could not be really the real one... <p>
940      *
941      * @return the http URI of the current dialog
942      */

943     public String JavaDoc getDialogUri() {
944
945         if (!useNewStyle()) {
946             return getDialogRealUri();
947         } else {
948             return CmsToolManager.linkForToolPath(getJsp(), getCurrentToolPath());
949         }
950     }
951
952     /**
953      * Returns the custom mapping for the online help.<p>
954      *
955      * @return the custom mapping for the online help
956      */

957     public String JavaDoc getOnlineHelpUriCustom() {
958
959         if (m_onlineHelpUriCustom == null) {
960             return null;
961         }
962         StringBuffer JavaDoc result = new StringBuffer JavaDoc(m_onlineHelpUriCustom.length() + 4);
963         result.append("\"");
964         result.append(m_onlineHelpUriCustom);
965         result.append("\"");
966         return result.toString();
967     }
968
969     /**
970      * Returns the value of the action parameter,
971      * or null if this parameter was not provided.<p>
972      *
973      * The action parameter is very important,
974      * it will select the dialog action to perform.
975      * The value of the {@link #getAction()} method will be
976      * initialized from the action parameter.<p>
977      *
978      * @return the value of the action parameter
979      */

980     public String JavaDoc getParamAction() {
981
982         return m_paramAction;
983     }
984
985     /**
986      * Returns the value of the closelink parameter,
987      * or null if this parameter was not provided.<p>
988      *
989      * @return the value of the closelink parameter
990      */

991     public String JavaDoc getParamCloseLink() {
992
993         if ((m_paramCloseLink == null) || "null".equals(m_paramCloseLink)) {
994             return null;
995         }
996         return m_paramCloseLink;
997     }
998
999     /**
1000     * Returns the value of the dialogtype parameter,
1001     * or null if this parameter was not provided.<p>
1002     *
1003     * This parameter is very important.
1004     * It must match to the localization keys,
1005     * e.g. "copy" for the copy dialog.<p>
1006     *
1007     * This parameter must be set manually by the subclass during
1008     * first initialization.<p>
1009     *
1010     * @return the value of the dialogtype parameter
1011     */

1012    public String JavaDoc getParamDialogtype() {
1013
1014        return m_paramDialogtype;
1015    }
1016
1017    /**
1018     * Returns the value of the frame name parameter.<p>
1019     *
1020     * @return the value of the errorstack parameter
1021     */

1022    public String JavaDoc getParamFramename() {
1023
1024        if (m_paramFrameName != null && !"null".equals(m_paramFrameName)) {
1025            return m_paramFrameName;
1026        } else {
1027            return null;
1028        }
1029    }
1030
1031    /**
1032     * Returns the ispopup parameter.<p>
1033     *
1034     * Use this parameter to indicate that the dialog is shown in a popup window.<p>
1035     *
1036     * @return the ispopup parameter
1037     */

1038    public String JavaDoc getParamIsPopup() {
1039
1040        return m_paramIsPopup;
1041    }
1042
1043    /**
1044     * Returns the value of the message parameter,
1045     * or null if this parameter was not provided.<p>
1046     *
1047     * The message parameter is used on dialogs to
1048     * show any text message.<p>
1049     *
1050     * @return the value of the message parameter
1051     */

1052    public String JavaDoc getParamMessage() {
1053
1054        return m_paramMessage;
1055    }
1056
1057    /**
1058     * Returns the value of the redirect flag parameter.<p>
1059     *
1060     * @return the value of the redirect flag parameter
1061     */

1062    public String JavaDoc getParamRedirect() {
1063
1064        return m_paramRedirect;
1065    }
1066
1067    /**
1068     * Returns the value of the file parameter,
1069     * or null if this parameter was not provided.<p>
1070     *
1071     * The file parameter selects the file on which the dialog action
1072     * is to be performed.<p>
1073     *
1074     * @return the value of the file parameter
1075     */

1076    public String JavaDoc getParamResource() {
1077
1078        if (m_paramResource != null && !"null".equals(m_paramResource)) {
1079            return m_paramResource;
1080        } else {
1081            return null;
1082        }
1083    }
1084
1085    /**
1086     * Returns the value of the title parameter,
1087     * or null if this parameter was not provided.<p>
1088     *
1089     * This parameter is used to build the title
1090     * of the dialog. It is a parameter so that the title
1091     * can be passed to included elements.<p>
1092     *
1093     * @return the value of the title parameter
1094     */

1095    public String JavaDoc getParamTitle() {
1096
1097        return m_paramTitle;
1098    }
1099
1100    /**
1101     * Gets a formatted file state string.<p>
1102     *
1103     * @return formatted state string
1104     * @throws CmsException if something goes wrong
1105     */

1106    public String JavaDoc getState() throws CmsException {
1107
1108        if (CmsStringUtil.isNotEmpty(getParamResource())) {
1109            CmsResource file = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
1110            if (getCms().isInsideCurrentProject(getParamResource())) {
1111                return key(Messages.getStateKey(file.getState()));
1112            } else {
1113                return key(Messages.GUI_EXPLORER_STATENIP_0);
1114            }
1115        }
1116        return "+++ resource parameter not found +++";
1117    }
1118
1119    /**
1120     * Builds the start html of the page, including setting of DOCTYPE and
1121     * inserting a header with the content-type.<p>
1122     *
1123     * @return the start html of the page
1124     */

1125    public String JavaDoc htmlStart() {
1126
1127        return pageHtml(HTML_START, null);
1128    }
1129
1130    /**
1131     * Builds the start html of the page, including setting of DOCTYPE and
1132     * inserting a header with the content-type.<p>
1133     *
1134     * This overloads the default method of the parent class.<p>
1135     *
1136     * @param helpUrl the key for the online help to include on the page
1137     * @return the start html of the page
1138     */

1139    public String JavaDoc htmlStart(String JavaDoc helpUrl) {
1140
1141        return pageHtml(HTML_START, helpUrl);
1142    }
1143
1144    /**
1145     * Builds the start html of the page, including setting of DOCTYPE and
1146     * inserting a header with the content-type.<p>
1147     *
1148     * @param helpUrl the key for the online help to include on the page
1149     * @param title the title for the page
1150     * @return the start html of the page
1151     */

1152    public String JavaDoc htmlStart(String JavaDoc helpUrl, String JavaDoc title) {
1153
1154        return pageHtml(HTML_START, helpUrl, title);
1155    }
1156
1157    /**
1158     * Builds the start html of the page, including setting of DOCTYPE,
1159     * inserting a header with the content-type and choosing an individual style sheet.<p>
1160     *
1161     * @param title the title for the page
1162     * @param stylesheet the style sheet to include
1163     * @return the start html of the page
1164     */

1165    public String JavaDoc htmlStartStyle(String JavaDoc title, String JavaDoc stylesheet) {
1166
1167        return pageHtmlStyle(HTML_START, title, stylesheet);
1168    }
1169
1170    /**
1171     * Displays the throwable on the error page and logs the error.<p>
1172     *
1173     * @param wp the workplace class
1174     * @param t the throwable to be displayed on the errorpage
1175     * @throws JspException if the include of the errorpage jsp fails
1176     */

1177    public void includeErrorpage(CmsWorkplace wp, Throwable JavaDoc t) throws JspException JavaDoc {
1178
1179        CmsLog.getLog(wp).error(Messages.get().getBundle().key(Messages.ERR_WORKPLACE_DIALOG_0), t);
1180        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, wp);
1181        getJsp().getRequest().setAttribute(ATTRIBUTE_THROWABLE, t);
1182        getJsp().include(FILE_DIALOG_SCREEN_ERRORPAGE);
1183    }
1184
1185    /**
1186     * Returns the "isPopup" flag.<p>
1187     *
1188     * @return the "isPopup" flag
1189     */

1190    public boolean isPopup() {
1191
1192        return Boolean.valueOf(getParamIsPopup()).booleanValue();
1193    }
1194
1195    /**
1196     * Builds the start html of the page, including setting of DOCTYPE and
1197     * inserting a header with the content-type.<p>
1198     *
1199     * This overloads the default method of the parent class.<p>
1200     *
1201     * @param segment the HTML segment (START / END)
1202     * @param helpUrl the url for the online help to include on the page
1203     * @return the start html of the page
1204     */

1205    public String JavaDoc pageHtml(int segment, String JavaDoc helpUrl) {
1206
1207        return pageHtml(segment, helpUrl, null);
1208    }
1209
1210    /**
1211     * Builds the start html of the page, including setting of DOCTYPE and
1212     * inserting a header with the content-type.<p>
1213     *
1214     * This overloads the default method of the parent class.<p>
1215     *
1216     * @param segment the HTML segment (START / END)
1217     * @param helpUrl the url for the online help to include on the page
1218     * @param title the title for the page
1219     * @return the start html of the page
1220     */

1221    public String JavaDoc pageHtml(int segment, String JavaDoc helpUrl, String JavaDoc title) {
1222
1223        if (segment == HTML_START) {
1224            String JavaDoc stylesheet = null;
1225            if (isPopup() && !useNewStyle()) {
1226                stylesheet = "popup.css";
1227            }
1228            StringBuffer JavaDoc result = new StringBuffer JavaDoc(pageHtmlStyle(segment, title, stylesheet));
1229            if (getSettings().isViewExplorer()) {
1230                result.append("<script type=\"text/javascript\" SRC=\"");
1231                result.append(getSkinUri());
1232                result.append("commons/explorer.js\"></script>\n");
1233            }
1234            result.append("<script type=\"text/javascript\">\n");
1235            result.append(dialogScriptSubmit());
1236            if (helpUrl != null) {
1237                result.append("if (top.head && top.head.helpUrl) {\n");
1238                result.append("\ttop.head.helpUrl=\"");
1239                result.append(helpUrl + "\";\n");
1240                result.append("}\n\n");
1241            }
1242            // the variable that may be set as path: if non-null this will be
1243
// used as path for the online help window. This is needed because there are pages
1244
// e.g. /administration/accounts/users/new that perform a jsp - forward while leaving the
1245
// path param on the old page: no correct online help possible.
1246
result.append("var onlineHelpUriCustom = ");
1247            result.append(getOnlineHelpUriCustom());
1248            result.append(";\n");
1249
1250            result.append("</script>\n");
1251            return result.toString();
1252        } else {
1253            return super.pageHtml(segment, null);
1254        }
1255    }
1256
1257    /**
1258     * Set the custom mapping for the online help. <p>
1259     *
1260     * This value will be set to a javascript variable called onlineHelpUriCustom.
1261     * If it is set, the top.head javascript for the online help will use this value. <p>
1262     *
1263     * This method should be called from <code>{@link #initWorkplaceRequestValues(CmsWorkplaceSettings, HttpServletRequest)}</code>,
1264     * <code>{@link CmsWorkplace#initWorkplaceMembers(CmsJspActionElement)}</code>
1265     * or from the jsp if the dialog class is used for several actions.
1266     * It should be used whenever the online help mapping does not work (due to jsp - forwards).<p>
1267     *
1268     * @param uri the left hand value in mapping.properties for the online help pages
1269     */

1270    public void setOnlineHelpUriCustom(String JavaDoc uri) {
1271
1272        m_onlineHelpUriCustom = uri;
1273    }
1274
1275    /**
1276     * Sets the value of the action parameter.<p>
1277     *
1278     * @param value the value to set
1279     */

1280    public void setParamAction(String JavaDoc value) {
1281
1282        m_paramAction = value;
1283    }
1284
1285    /**
1286     * Sets the value of the closelink parameter.<p>
1287     *
1288     * @param value the value to set
1289     */

1290    public void setParamCloseLink(String JavaDoc value) {
1291
1292        // ensure decoded chars are re-encoded again properly
1293

1294        m_paramCloseLink = value;
1295    }
1296
1297    /**
1298     * Sets the value of the dialogtype parameter.<p>
1299     *
1300     * @param value the value to set
1301     */

1302    public void setParamDialogtype(String JavaDoc value) {
1303
1304        m_paramDialogtype = value;
1305    }
1306
1307    /**
1308     * Sets the value of the frame name parameter.<p>
1309     *
1310     * @param value the value to set
1311     */

1312    public void setParamFramename(String JavaDoc value) {
1313
1314        m_paramFrameName = value;
1315    }
1316
1317    /**
1318     * Sets the ispopup parameter.<p>
1319     *
1320     * @param value the ispopup parameter value
1321     */

1322    public void setParamIsPopup(String JavaDoc value) {
1323
1324        m_paramIsPopup = value;
1325    }
1326
1327    /**
1328     * Sets the value of the message parameter.<p>
1329     *
1330     * @param value the value to set
1331     */

1332    public void setParamMessage(String JavaDoc value) {
1333
1334        m_paramMessage = value;
1335    }
1336
1337    /**
1338     * Sets the value of the redirect flag parameter.<p>
1339     *
1340     * @param redirect the value of the redirect flag parameter
1341     */

1342    public void setParamRedirect(String JavaDoc redirect) {
1343
1344        m_paramRedirect = redirect;
1345    }
1346
1347    /**
1348     * Sets the value of the file parameter.<p>
1349     *
1350     * @param value the value to set
1351     */

1352    public void setParamResource(String JavaDoc value) {
1353
1354        m_paramResource = value;
1355    }
1356
1357    /**
1358     * Sets the value of the title parameter.<p>
1359     *
1360     * @param value the value to set
1361     */

1362    public void setParamTitle(String JavaDoc value) {
1363
1364        m_paramTitle = value;
1365    }
1366
1367    /**
1368     * Appends a space char. between tag attribs.<p>
1369     *
1370     * @param attribute a tag attribute
1371     * @return the tag attribute with a leading space char.
1372     */

1373    protected String JavaDoc appendDelimiter(String JavaDoc attribute) {
1374
1375        if (CmsStringUtil.isNotEmpty(attribute)) {
1376            if (!attribute.startsWith(" ")) {
1377                // add a delimiter space between the beginning button HTML and the button tag attribs
1378
return " " + attribute;
1379            } else {
1380                return attribute;
1381            }
1382        }
1383
1384        return "";
1385    }
1386
1387    /**
1388     * Checks if the permissions of the current user on the resource to use in the dialog are sufficient.<p>
1389     *
1390     * Automatically generates a CmsMessageContainer object with an error message and stores it in the users session.<p>
1391     *
1392     * @param required the required permissions for the dialog
1393     * @param neededForFolder if true, the permissions are required for the parent folder of the resource (e.g. for editors)
1394     * @return true if the permissions are sufficient, otherwise false
1395     */

1396    protected boolean checkResourcePermissions(CmsPermissionSet required, boolean neededForFolder) {
1397
1398        return checkResourcePermissions(required, neededForFolder, Messages.get().container(
1399            Messages.GUI_ERR_RESOURCE_PERMISSIONS_2,
1400            getParamResource(),
1401            required.getPermissionString()));
1402    }
1403
1404    /**
1405     * Checks if the permissions of the current user on the resource to use in the dialog are sufficient.<p>
1406     *
1407     * Automatically generates a CmsMessageContainer object with an error message and stores it in the users session.<p>
1408     *
1409     * @param required the required permissions for the dialog
1410     * @param neededForFolder if true, the permissions are required for the parent folder of the resource (e.g. for editors)
1411     * @param errorMessage the message container that is stored in the session in case the permissions are not sufficient
1412     * @return true if the permissions are sufficient, otherwise false
1413     */

1414    protected boolean checkResourcePermissions(
1415        CmsPermissionSet required,
1416        boolean neededForFolder,
1417        CmsMessageContainer errorMessage) {
1418
1419        boolean hasPermissions = false;
1420        try {
1421            CmsResource res;
1422            if (neededForFolder) {
1423                // check permissions for the folder the resource is in
1424
res = getCms().readResource(CmsResource.getParentFolder(getParamResource()), CmsResourceFilter.ALL);
1425            } else {
1426                res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
1427            }
1428            hasPermissions = getCms().hasPermissions(res, required, false, CmsResourceFilter.ALL);
1429        } catch (CmsException e) {
1430            // should usually never happen
1431
if (LOG.isInfoEnabled()) {
1432                LOG.info(e);
1433            }
1434        }
1435
1436        if (!hasPermissions) {
1437            // store the error message in the users session
1438
getSettings().setErrorMessage(errorMessage);
1439        }
1440
1441        return hasPermissions;
1442    }
1443
1444    /**
1445     * Renders the HTML for a single input button of a specified type.<p>
1446     *
1447     * @param result a string buffer where the rendered HTML gets appended to
1448     * @param button a integer key to identify the button
1449     * @param attribute an optional string with possible tag attributes, or null
1450     */

1451    protected void dialogButtonsHtml(StringBuffer JavaDoc result, int button, String JavaDoc attribute) {
1452
1453        attribute = appendDelimiter(attribute);
1454
1455        switch (button) {
1456            case BUTTON_OK:
1457                result.append("<input name=\"ok\" value=\"");
1458                result.append(key(Messages.GUI_DIALOG_BUTTON_OK_0) + "\"");
1459                if (attribute.toLowerCase().indexOf("onclick") == -1) {
1460                    result.append(" type=\"submit\"");
1461                } else {
1462                    result.append(" type=\"button\"");
1463                }
1464                result.append(" class=\"dialogbutton\"");
1465                result.append(attribute);
1466                result.append(">\n");
1467                break;
1468            case BUTTON_CANCEL:
1469                result.append("<input name=\"cancel\" type=\"button\" value=\"");
1470                result.append(key(Messages.GUI_DIALOG_BUTTON_CANCEL_0) + "\"");
1471                if (attribute.toLowerCase().indexOf("onclick") == -1) {
1472                    result.append(" onclick=\"submitAction('" + DIALOG_CANCEL + "', form);\"");
1473                }
1474                result.append(" class=\"dialogbutton\"");
1475                result.append(attribute);
1476                result.append(">\n");
1477                break;
1478            case BUTTON_EDIT:
1479                result.append("<input name=\"ok\" value=\"");
1480                result.append(key(Messages.GUI_DIALOG_BUTTON_EDIT_0) + "\"");
1481                if (attribute.toLowerCase().indexOf("onclick") == -1) {
1482                    result.append(" type=\"submit\"");
1483                } else {
1484                    result.append(" type=\"button\"");
1485                }
1486                result.append(" class=\"dialogbutton\"");
1487                result.append(attribute);
1488                result.append(">\n");
1489                break;
1490            case BUTTON_DISCARD:
1491                result.append("<input name=\"cancel\" type=\"button\" value=\"");
1492                result.append(key(Messages.GUI_DIALOG_BUTTON_DISCARD_0) + "\"");
1493                if (attribute.toLowerCase().indexOf("onclick") == -1) {
1494                    result.append(" onclick=\"submitAction('" + DIALOG_CANCEL + "', form);\"");
1495                }
1496                result.append(" class=\"dialogbutton\"");
1497                result.append(attribute);
1498                result.append(">\n");
1499                break;
1500            case BUTTON_CLOSE:
1501                result.append("<input name=\"close\" type=\"button\" value=\"");
1502                result.append(key(Messages.GUI_DIALOG_BUTTON_CLOSE_0) + "\"");
1503                if (attribute.toLowerCase().indexOf("onclick") == -1) {
1504                    result.append(" onclick=\"submitAction('" + DIALOG_CANCEL + "', form);\"");
1505                }
1506                result.append(" class=\"dialogbutton\"");
1507                result.append(attribute);
1508                result.append(">\n");
1509                break;
1510            case BUTTON_ADVANCED:
1511                result.append("<input name=\"advanced\" type=\"button\" value=\"");
1512                result.append(key(Messages.GUI_DIALOG_BUTTON_ADVANCED_0) + "\"");
1513                result.append(" class=\"dialogbutton\"");
1514                result.append(attribute);
1515                result.append(">\n");
1516                break;
1517            case BUTTON_SET:
1518                result.append("<input name=\"set\" type=\"button\" value=\"");
1519                result.append(key(Messages.GUI_DIALOG_BUTTON_SET_0) + "\"");
1520                if (attribute.toLowerCase().indexOf("onclick") == -1) {
1521                    result.append(" onclick=\"submitAction('" + DIALOG_SET + "', form);\"");
1522                }
1523                result.append(" class=\"dialogbutton\"");
1524                result.append(attribute);
1525                result.append(">\n");
1526                break;
1527            case BUTTON_BACK:
1528                result.append("<input name=\"set\" type=\"button\" value=\"");
1529                result.append(key(Messages.GUI_DIALOG_BUTTON_BACK_0) + "\"");
1530                if (attribute.toLowerCase().indexOf("onclick") == -1) {
1531                    result.append(" onclick=\"submitAction('" + DIALOG_BACK + "', form);\"");
1532                }
1533                result.append(" class=\"dialogbutton\"");
1534                result.append(attribute);
1535                result.append(">\n");
1536                break;
1537            case BUTTON_CONTINUE:
1538                result.append("<input name=\"set\" type=\"button\" value=\"");
1539                result.append(key(Messages.GUI_DIALOG_BUTTON_CONTINUE_0) + "\"");
1540                if (attribute.toLowerCase().indexOf("onclick") == -1) {
1541                    result.append(" onclick=\"submitAction('" + DIALOG_CONTINUE + "', form);\"");
1542                }
1543                result.append(" class=\"dialogbutton\"");
1544                result.append(attribute);
1545                result.append(">\n");
1546                break;
1547            case BUTTON_DETAILS:
1548                result.append("<input name=\"details\" type=\"button\" value=\"");
1549                result.append(key(Messages.GUI_DIALOG_BUTTON_DETAIL_0) + "\"");
1550                result.append(" class=\"dialogbutton\"");
1551                result.append(attribute);
1552                result.append(">\n");
1553                break;
1554            default:
1555                // not a valid button code, just insert a warning in the HTML
1556
result.append("<!-- invalid button code: ");
1557                result.append(button);
1558                result.append(" -->\n");
1559        }
1560    }
1561
1562    /**
1563     * Returns the link URL to get back one folder in the administration view.<p>
1564     *
1565     * @return the link URL to get back one folder in the administration view
1566     */

1567    protected String JavaDoc getAdministrationBackLink() {
1568
1569        return CmsWorkplace.VFS_PATH_WORKPLACE
1570            + "action/administration_content_top.html"
1571            + "?sender="
1572            + CmsResource.getParentFolder(getJsp().getRequestContext().getFolderUri());
1573    }
1574
1575    /**
1576     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
1577     */

1578    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
1579
1580        fillParamValues(request);
1581        if (DIALOG_CANCEL.equals(getParamAction())) {
1582            setAction(ACTION_CANCEL);
1583        }
1584    }
1585
1586    /**
1587     * Sets the action value.<p>
1588     *
1589     * @param value the action value
1590     */

1591    protected void setAction(int value) {
1592
1593        m_action = value;
1594    }
1595}
Popular Tags