001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/tools/CmsToolDialog.java,v $
003: * Date : $Date: 2008-02-27 12:05:31 $
004: * Version: $Revision: 1.39 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools;
033:
034: import org.opencms.i18n.CmsEncoder;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.OpenCms;
037: import org.opencms.security.CmsRoleViolationException;
038: import org.opencms.util.CmsStringUtil;
039: import org.opencms.workplace.CmsDialog;
040: import org.opencms.workplace.CmsWorkplace;
041: import org.opencms.workplace.CmsWorkplaceSettings;
042:
043: import java.util.HashMap;
044: import java.util.Map;
045:
046: import javax.servlet.http.HttpServletRequest;
047:
048: /**
049: * Helper class that encapsulates all the code for the "new"
050: * style of the administration dialogs.<p>
051: *
052: * @author Michael Moossen
053: *
054: * @version $Revision: 1.39 $
055: *
056: * @since 6.0.0
057: */
058: public class CmsToolDialog extends CmsWorkplace {
059:
060: /** Request parameter name for the base tool path in the navegation, should be a parent tool of path. */
061: public static final String PARAM_BASE = "base";
062:
063: /** Request parameter name for the tool path, should be an accesible tool under the given root. */
064: public static final String PARAM_PATH = "path";
065:
066: /** Request parameter name for the root tool path. */
067: public static final String PARAM_ROOT = "root";
068:
069: /** Request parameter name for the style type. */
070: public static final String PARAM_STYLE = "style";
071:
072: /** Request parameter value for the 'new' dialog style. */
073: public static final String STYLE_NEW = "new";
074:
075: /** Base parameter value. */
076: private String m_paramBase;
077:
078: /** Path parameter value. */
079: private String m_paramPath;
080:
081: /** Root parameter value. */
082: private String m_paramRoot;
083:
084: /** Style parameter value. */
085: private String m_paramStyle;
086:
087: /**
088: * Default Constructor.<p>
089: *
090: * @param jsp the jsp action element
091: */
092: public CmsToolDialog(CmsJspActionElement jsp) {
093:
094: super (jsp);
095: }
096:
097: /**
098: * Builds the standard javascript for submitting the dialog.<p>
099: *
100: * Should only be used by the <code>{@link CmsDialog#dialogScriptSubmit()}</code> method.<p>
101: *
102: * @return the standard javascript for submitting the dialog
103: */
104: public String dialogScriptSubmit() {
105:
106: StringBuffer html = new StringBuffer(512);
107: html
108: .append("function submitAction(actionValue, theForm, formName) {\n");
109: html.append("\tif (theForm == null) {\n");
110: html.append("\t\ttheForm = document.forms[formName];\n");
111: html.append("\t}\n");
112: html.append("\ttry {\n");
113: html.append("\t\ttheForm.").append(CmsDialog.PARAM_FRAMENAME)
114: .append(".value = window.name;\n");
115: html.append("\t} catch (e) {}\n");
116: html.append("\tif (actionValue == '" + CmsDialog.DIALOG_OK
117: + "') {\n");
118: html.append("\t\tloadingOn();\n");
119: html.append("\t\treturn true;\n");
120: html.append("\t}\n");
121: html.append("\ttheForm." + CmsDialog.PARAM_ACTION
122: + ".value = actionValue;\n");
123: html.append("\tsubmitForm(theForm);\n");
124: html.append("\treturn true;\n");
125: html.append("}\n");
126: return html.toString();
127: }
128:
129: /**
130: * Generates the standard new style dialog title row, and tool grouping.<p>
131: *
132: * It is called by the <code>{@link org.opencms.workplace.CmsDialog#dialog(int, String)}</code> method.<p>
133: *
134: * @return a dialog window start / end segment
135: */
136: public String dialogTitle() {
137:
138: StringBuffer html = new StringBuffer(512);
139: String toolPath = getCurrentToolPath();
140: String parentPath = getParentPath();
141: String rootKey = getToolManager().getCurrentRoot(this ).getKey();
142: CmsTool parentTool = getToolManager().resolveAdminTool(rootKey,
143: parentPath);
144: String upLevelLink = CmsToolManager
145: .linkForToolPath(getJsp(), parentPath, parentTool
146: .getHandler().getParameters(this ));
147: String parentName = getToolManager().resolveAdminTool(rootKey,
148: parentPath).getHandler().getName();
149:
150: html.append(getToolManager().generateNavBar(toolPath, this ));
151: // build title
152: html.append("<div class='screenTitle'>\n");
153: html.append("\t<table width='100%' cellspacing='0'>\n");
154: html.append("\t\t<tr>\n");
155: html.append("\t\t\t<td>\n");
156: html.append(CmsEncoder.decode(CmsToolMacroResolver
157: .resolveMacros(getAdminTool().getHandler().getName(),
158: this )));
159: html.append("\n\t\t\t</td>");
160: // uplevel button only if needed
161: if (!getParentPath().equals(toolPath)) {
162: html.append("\t\t\t<td class='uplevel'>\n\t\t\t\t");
163: html.append(A_CmsHtmlIconButton.defaultButtonHtml(
164: CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
165: "id-up-level", Messages.get()
166: .getBundle(getLocale()).key(
167: Messages.GUI_ADMIN_VIEW_UPLEVEL_0),
168: parentName, true, "admin/images/up.png", null,
169: "openPage('" + upLevelLink + "');"));
170: html.append("\n\t\t\t</td>\n");
171: }
172: html.append("\t\t</tr>\n");
173: html.append("\t</table>\n");
174: html.append("</div>\n");
175: return CmsToolMacroResolver
176: .resolveMacros(html.toString(), this );
177: }
178:
179: /**
180: * Returns the admin tool.<p>
181: *
182: * @return the admin tool
183: */
184: public CmsTool getAdminTool() {
185:
186: return getToolManager().getCurrentTool(this );
187: }
188:
189: /**
190: * Returns the current tool path.<p>
191: *
192: * @return the current tool path
193: */
194: public String getCurrentToolPath() {
195:
196: return getToolManager().getCurrentToolPath(this );
197: }
198:
199: /**
200: * Returns the value for the base parameter.<p>
201: *
202: * @return the value for the base parameter
203: */
204: public String getParamBase() {
205:
206: return m_paramBase;
207: }
208:
209: /**
210: * Returns the path parameter value.<p>
211: *
212: * @return the path parameter value
213: */
214: public String getParamPath() {
215:
216: return m_paramPath;
217: }
218:
219: /**
220: * Returns the root parameter value.<p>
221: *
222: * @return the root parameter value
223: */
224: public String getParamRoot() {
225:
226: return m_paramRoot;
227: }
228:
229: /**
230: * Returns the style parameter value.<p>
231: *
232: * @return the style parameter value
233: */
234: public String getParamStyle() {
235:
236: return m_paramStyle;
237: }
238:
239: /**
240: * Returns the path to the parent tool.<p>
241: *
242: * @return tha path to the parent tool
243: */
244: public String getParentPath() {
245:
246: return getToolManager().getParent(this , getCurrentToolPath());
247: }
248:
249: /**
250: * Returns the tool manager.<p>
251: *
252: * @return the tool manager
253: */
254: public CmsToolManager getToolManager() {
255:
256: return OpenCms.getWorkplaceManager().getToolManager();
257: }
258:
259: /**
260: * Builds an block area for icons.<p>
261: *
262: * @param segment the HTML segment (START / END)
263: * @param headline the headline String for the block
264:
265: * @return block area start / end segment
266: *
267: * @see CmsDialog#dialogBlock(int, String, boolean)
268: */
269: public String iconsBlockArea(int segment, String headline) {
270:
271: StringBuffer result = new StringBuffer(512);
272: if (segment == HTML_START) {
273: result.append("<!-- icons block area start -->\n");
274: result
275: .append("<div class=\"dialogcontent\" unselectable=\"on\">");
276: result.append("<fieldset class=\"dialogblock\">\n");
277: result.append("<legend>");
278: result.append("<span class=\"textbold");
279: result.append("\" unselectable=\"on\">");
280: result.append(headline);
281: result.append("</span></legend>\n");
282: result
283: .append("\t\t<table class='toolsArea' width='100%' cellspacing='0' cellpadding='0' border='0'>\n");
284: result.append("\t\t\t<tr><td>\n");
285: } else {
286: result.append("\t\t\t</td></tr>\n");
287: result.append("\t\t</table>\n");
288: result.append("</fieldset></div>\n");
289: result.append("<p> </p>\n");
290: result.append("<!-- icons block area end -->\n");
291: }
292: return result.toString();
293: }
294:
295: /**
296: * Builds the end HTML for a block area with border in the dialog content area.<p>
297: *
298: * @return block area end segment
299: *
300: * @see CmsDialog#dialogBlockEnd()
301: */
302: public String iconsBlockAreaEnd() {
303:
304: return iconsBlockArea(HTML_END, null);
305: }
306:
307: /**
308: * Builds the start HTML for a block area with border and optional subheadline in the dialog content area.<p>
309: *
310: * @param headline the headline String for the block
311: *
312: * @return block area start segment
313: *
314: * @see CmsDialog#dialogBlockStart(String)
315: */
316: public String iconsBlockAreaStart(String headline) {
317:
318: return iconsBlockArea(HTML_START, headline);
319: }
320:
321: /**
322: * Initializes the admin tool main view.<p>
323: *
324: * @return the new modified params array
325: * @throws CmsRoleViolationException in case the dialog is opened by a user without the necessary privileges
326: */
327: public Map initAdminTool() throws CmsRoleViolationException {
328:
329: Map params = new HashMap(getParameterMap());
330: // initialize
331: getToolManager().initParams(this );
332:
333: // adjust params if called as default
334: if (!useNewStyle()) {
335: params.put(PARAM_STYLE,
336: new String[] { CmsToolDialog.STYLE_NEW });
337: setParamStyle(CmsToolDialog.STYLE_NEW);
338: }
339:
340: try {
341: // a dialog just for the close link param accessors
342: CmsDialog wp = (CmsDialog) this ;
343: // set close link
344: if (CmsStringUtil.isEmptyOrWhitespaceOnly(wp
345: .getParamCloseLink())) {
346: if (!getToolManager().getBaseToolPath(this ).equals(
347: getToolManager().getCurrentToolPath(this ))) {
348: Map args = getToolManager().resolveAdminTool(
349: getParamRoot(), getParentPath())
350: .getHandler().getParameters(wp);
351: wp.setParamCloseLink(CmsToolManager
352: .linkForToolPath(getJsp(), getParentPath(),
353: args));
354: params.put(CmsDialog.PARAM_CLOSELINK,
355: new String[] { wp.getParamCloseLink() });
356: }
357: }
358: } catch (Exception e) {
359: // ignore
360: }
361:
362: if (!getToolManager().getCurrentTool(this ).getHandler()
363: .isEnabled(this )) {
364: throw new CmsRoleViolationException(
365: Messages.get().container(
366: Messages.ERR_ADMIN_INSUFFICIENT_RIGHTS_0));
367: }
368:
369: return params;
370: }
371:
372: /**
373: * @see org.opencms.workplace.CmsWorkplace#pageBody(int, java.lang.String, java.lang.String)
374: */
375: public String pageBody(int segment, String className,
376: String parameters) {
377:
378: if (!useNewStyle()) {
379: return super .pageBody(segment, className, parameters);
380: } else {
381: Map data = CmsStringUtil.extendAttribute(parameters,
382: "onLoad", "bodyLoad();");
383: String onLoad = (String) data.get("value");
384: String myPars = (String) data.get("text");
385: data = CmsStringUtil.extendAttribute(myPars, "onUnload",
386: "bodyUnload();");
387: String onUnload = (String) data.get("value");
388: myPars = (String) data.get("text");
389: if (segment == HTML_START) {
390: StringBuffer html = new StringBuffer(512);
391: html.append("</head>\n");
392: html.append("<body onLoad=");
393: html.append(onLoad);
394: html.append(" onUnload=");
395: html.append(onUnload);
396: html
397: .append(CmsStringUtil.isNotEmpty(className) ? " class='"
398: + className + "'"
399: : "");
400: html.append(CmsStringUtil.isNotEmpty(myPars) ? " "
401: + myPars : "");
402: html.append(">\n");
403: html
404: .append("\t<table border='0' cellspacing='0' cellpadding='0' id='loaderContainer' onClick='return false;'>\n");
405: html
406: .append("\t\t<tr><td id='loaderContainerH'><div id='loader'>\n");
407: html
408: .append("\t\t\t<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td>\n");
409: html.append("\t\t\t\t<p><img src='");
410: html.append(getSkinUri());
411: html.append("commons/wait.gif");
412: html.append("' height='32' width='32' alt=''/>\n");
413: html.append("\t\t\t\t<strong>");
414: html.append(Messages.get().getBundle(getLocale()).key(
415: Messages.GUI_ADMIN_VIEW_LOADING_0));
416: html.append("</strong></p>\n");
417: html.append("\t\t\t</td></tr></table>\n");
418: html.append("\t\t</div></td></tr>\n");
419: html.append("\t</table>\n");
420: html
421: .append("\t<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td id='screenH'>\n");
422: return html.toString();
423: } else {
424: StringBuffer html = new StringBuffer(128);
425: html.append("\t</td></tr></table>\n");
426: html.append("</body>");
427: return html.toString();
428: }
429: }
430: }
431:
432: /**
433: * @see org.opencms.workplace.CmsWorkplace#pageHtmlStyle(int, java.lang.String, java.lang.String)
434: */
435: public String pageHtmlStyle(int segment, String title,
436: String stylesheet) {
437:
438: if (!useNewStyle() || (segment != HTML_START)) {
439: return super .pageHtmlStyle(segment, title, stylesheet);
440: }
441:
442: StringBuffer html = new StringBuffer(512);
443: html
444: .append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
445: html.append("<html>\n");
446: html.append("<head>\n");
447: html
448: .append("<meta http-equiv='Content-Type' content='text/html; charset=");
449: html.append(getEncoding());
450: html.append("' >\n");
451: if (title != null) {
452: html.append("<title>");
453: html.append(title);
454: html.append("</title>\n");
455: } else {
456: // the title tag is required for valid HTML
457: html.append("<title></title>\n");
458: }
459: html.append("<link rel='stylesheet' type='text/css' href='");
460: html.append(getStyleUri(getJsp()));
461: html.append("new_admin.css'>\n");
462: html.append("<script type='text/javascript' src='");
463: html.append(getSkinUri());
464: html.append("admin/javascript/general.js'></script>\n");
465: html.append("<script type='text/javascript' src='");
466: html.append(getResourceUri());
467: html.append("editors/xmlcontent/help.js'></script>\n\n");
468: html.append("<script type='text/javascript'>\n");
469: html.append("\tfunction bodyLoad() {\n");
470: html.append("\t\tsetContext(\"");
471: html.append(CmsStringUtil
472: .escapeJavaScript(resolveMacros(getAdminTool()
473: .getHandler().getHelpText())));
474: html.append("\");\n");
475: html.append("\t\tsetActiveItemByName(\"");
476: html.append(getCurrentToolPath());
477: html.append("\");\n");
478: html.append("\t\tloadingOff();\n");
479: html.append("\t\ttry {\n");
480: html
481: .append("\t\t\tdocument.getElementById('loaderContainerH').height = wHeight();\n");
482: html.append("\t\t} catch (e) {}\n");
483: html.append("\t}\n");
484: html.append("\tfunction bodyUnload() {\n");
485: html.append("\t\tloadingOn();\n");
486: html.append("\t}\n");
487: html.append("</script>\n");
488: return html.toString();
489: }
490:
491: /**
492: * Sets the value of the base parameter.<p>
493: *
494: * @param paramBase the value of the base parameter to set
495: */
496: public void setParamBase(String paramBase) {
497:
498: m_paramBase = paramBase;
499: }
500:
501: /**
502: * Sets the path parameter value.<p>
503: *
504: * @param paramPath the path parameter value to set
505: */
506: public void setParamPath(String paramPath) {
507:
508: m_paramPath = paramPath;
509: }
510:
511: /**
512: * Sets the root parameter value.<p>
513: *
514: * @param paramRoot the root parameter value to set
515: */
516: public void setParamRoot(String paramRoot) {
517:
518: m_paramRoot = paramRoot;
519: }
520:
521: /**
522: * Sets the style parameter value.<p>
523: *
524: * @param paramStyle the style parameter value to set
525: */
526: public void setParamStyle(String paramStyle) {
527:
528: m_paramStyle = paramStyle;
529: }
530:
531: /**
532: * Tests if we are working with the new administration dialog style.<p>
533: *
534: * The default is the new style, this param is not intented for external use.<p>
535: *
536: * @return <code>true</code> if using the new style
537: */
538: public boolean useNewStyle() {
539:
540: return (getParamStyle() != null)
541: && getParamStyle().equals(CmsToolDialog.STYLE_NEW);
542: }
543:
544: /**
545: * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
546: */
547: protected void initWorkplaceRequestValues(
548: CmsWorkplaceSettings settings, HttpServletRequest request) {
549:
550: fillParamValues(request);
551: }
552: }
|