0001: /*
0002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsDialog.java,v $
0003: * Date : $Date: 2008-02-27 12:05:45 $
0004: * Version: $Revision: 1.101 $
0005: *
0006: * This library is part of OpenCms -
0007: * the Open Source Content Management System
0008: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
0009: *
0010: * This library is free software; you can redistribute it and/or
0011: * modify it under the terms of the GNU Lesser General Public
0012: * License as published by the Free Software Foundation; either
0013: * version 2.1 of the License, or (at your option) any later version.
0014: *
0015: * This library is distributed in the hope that it will be useful,
0016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0018: * Lesser General Public License for more details.
0019: *
0020: * For further information about Alkacon Software GmbH, please see the
0021: * company website: http://www.alkacon.com
0022: *
0023: * For further information about OpenCms, please see the
0024: * project website: http://www.opencms.org
0025: *
0026: * You should have received a copy of the GNU Lesser General Public
0027: * License along with this library; if not, write to the Free Software
0028: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0029: *
0030: */
0031:
0032: package org.opencms.workplace;
0033:
0034: import org.opencms.file.CmsResource;
0035: import org.opencms.file.CmsResourceFilter;
0036: import org.opencms.i18n.CmsMessageContainer;
0037: import org.opencms.jsp.CmsJspActionElement;
0038: import org.opencms.lock.CmsLockFilter;
0039: import org.opencms.main.CmsException;
0040: import org.opencms.main.CmsLog;
0041: import org.opencms.main.OpenCms;
0042: import org.opencms.security.CmsPermissionSet;
0043: import org.opencms.util.CmsRequestUtil;
0044: import org.opencms.util.CmsStringUtil;
0045: import org.opencms.workplace.commons.CmsLock;
0046: import org.opencms.workplace.editors.CmsPreEditorAction;
0047: import org.opencms.workplace.tools.CmsToolDialog;
0048: import org.opencms.workplace.tools.CmsToolManager;
0049:
0050: import java.io.IOException;
0051: import java.util.HashMap;
0052: import java.util.Map;
0053:
0054: import javax.servlet.http.HttpServletRequest;
0055: import javax.servlet.http.HttpServletResponse;
0056: import javax.servlet.jsp.JspException;
0057: import javax.servlet.jsp.JspWriter;
0058: import javax.servlet.jsp.PageContext;
0059:
0060: import org.apache.commons.logging.Log;
0061:
0062: /**
0063: * Provides methods for building the dialog windows of OpenCms.<p>
0064: *
0065: * @author Andreas Zahner
0066: *
0067: * @version $Revision: 1.101 $
0068: *
0069: * @since 6.0.0
0070: */
0071: public class CmsDialog extends CmsToolDialog {
0072:
0073: /** Value for the action: cancel. */
0074: public static final int ACTION_CANCEL = 4;
0075:
0076: /** Value for the action: close popup window. */
0077: public static final int ACTION_CLOSEPOPUP = 6;
0078:
0079: /** Value for the action: save & close popup window. */
0080: public static final int ACTION_CLOSEPOPUP_SAVE = 7;
0081:
0082: /** Value for the action: confirmed. */
0083: public static final int ACTION_CONFIRMED = 1;
0084:
0085: /** Value for the action: continue. */
0086: public static final int ACTION_CONTINUE = 8;
0087:
0088: /** Value for the action: default (show initial dialog form). */
0089: public static final int ACTION_DEFAULT = 0;
0090:
0091: /** Value for the action: locks confirmed. */
0092: public static final int ACTION_LOCKS_CONFIRMED = 99;
0093:
0094: /** Value for the action: ok. */
0095: public static final int ACTION_OK = 3;
0096:
0097: // note: action values 90 - 99 are reserved for reports
0098: /** Value for the action: begin the report. */
0099: public static final int ACTION_REPORT_BEGIN = 90;
0100:
0101: /** Value for the action: end the report. */
0102: public static final int ACTION_REPORT_END = 92;
0103:
0104: /** Value for the action: update the report. */
0105: public static final int ACTION_REPORT_UPDATE = 91;
0106:
0107: /** Value for the action: button "set" clicked. */
0108: public static final int ACTION_SET = 5;
0109:
0110: /** Value for the action: wait (show please wait screen). */
0111: public static final int ACTION_WAIT = 2;
0112:
0113: /** Constant for the "Advanced" button in the build button methods. */
0114: public static final int BUTTON_ADVANCED = 3;
0115:
0116: /** Constant for the "Back" button in the build button methods. */
0117: public static final int BUTTON_BACK = 9;
0118:
0119: /** Constant for the "Cancel" button in the build button methods. */
0120: public static final int BUTTON_CANCEL = 1;
0121:
0122: /** Constant for the "Close" button in the build button methods. */
0123: public static final int BUTTON_CLOSE = 2;
0124:
0125: /** Constant for the "Continue" button in the build button methods. */
0126: public static final int BUTTON_CONTINUE = 10;
0127:
0128: /** Constant for the "Details" button in the build button methods. */
0129: public static final int BUTTON_DETAILS = 5;
0130:
0131: /** Constant for the "Discard" button in the build button methods (same function as "Cancel" button but different text on button. */
0132: public static final int BUTTON_DISCARD = 8;
0133:
0134: /** Constant for the "Edit" button in the build button methods (same function as "Ok" button but different text on button. */
0135: public static final int BUTTON_EDIT = 7;
0136:
0137: /** Constant for the "OK" button in the build button methods. */
0138: public static final int BUTTON_OK = 0;
0139:
0140: /** Constant for the "OK" button in the build button methods (without form submission). */
0141: public static final int BUTTON_OK_NO_SUBMIT = 6;
0142:
0143: /** Constant for the "Set" button in the build button methods. */
0144: public static final int BUTTON_SET = 4;
0145:
0146: /** Request parameter value for the action: back. */
0147: public static final String DIALOG_BACK = "back";
0148:
0149: /** Request parameter value for the action: cancel. */
0150: public static final String DIALOG_CANCEL = "cancel";
0151:
0152: /** Request parameter value for the action: dialog confirmed. */
0153: public static final String DIALOG_CONFIRMED = "confirmed";
0154:
0155: /** Request parameter value for the action: continue. */
0156: public static final String DIALOG_CONTINUE = "continue";
0157:
0158: /** Request parameter value for the action: initial call. */
0159: public static final String DIALOG_INITIAL = "initial";
0160:
0161: /** Request parameter value for the action: dialog locks confirmed. */
0162: public static final String DIALOG_LOCKS_CONFIRMED = "locksconfirmed";
0163:
0164: /** Request parameter value for the action: ok. */
0165: public static final String DIALOG_OK = "ok";
0166:
0167: /** Request parameter value for the action: set. */
0168: public static final String DIALOG_SET = "set";
0169:
0170: /** Request parameter value for the action: show please wait screen. */
0171: public static final String DIALOG_WAIT = "wait";
0172:
0173: /** Request parameter name for the action. */
0174: public static final String PARAM_ACTION = "action";
0175:
0176: /** Request parameter name for the closelink. */
0177: public static final String PARAM_CLOSELINK = "closelink";
0178:
0179: /** Request parameter name for the dialog type. */
0180: public static final String PARAM_DIALOGTYPE = "dialogtype";
0181:
0182: /** Request parameter name for the error stack. */
0183: public static final String PARAM_ERRORSTACK = "errorstack";
0184:
0185: /** Request parameter name for the file. */
0186: public static final String PARAM_FILE = "file";
0187:
0188: /** Request parameter name for the frame name. */
0189: public static final String PARAM_FRAMENAME = "framename";
0190:
0191: /** Request parameter name for the "is popup" flag. */
0192: public static final String PARAM_ISPOPUP = "ispopup";
0193:
0194: /** Request parameter name for the lock. */
0195: public static final String PARAM_LOCK = "lock";
0196:
0197: /** Request parameter name for the error message. */
0198: public static final String PARAM_MESSAGE = "message";
0199:
0200: /** Request parameter name for the originalparams. */
0201: public static final String PARAM_ORIGINALPARAMS = "originalparams";
0202:
0203: /** Request parameter name for the preactiondone. */
0204: public static final String PARAM_PREACTIONDONE = "preactiondone";
0205:
0206: /** Request parameter name for the redirect flag. */
0207: public static final String PARAM_REDIRECT = "redirect";
0208:
0209: /** Request parameter name for the resource. */
0210: public static final String PARAM_RESOURCE = "resource";
0211:
0212: /** Request parameter name for the target. */
0213: public static final String PARAM_TARGET = "target";
0214:
0215: /** Request parameter name for the thread id. */
0216: public static final String PARAM_THREAD = "thread";
0217:
0218: /** Request parameter name for indicating if another thread is following the current one. */
0219: public static final String PARAM_THREAD_HASNEXT = "threadhasnext";
0220:
0221: /** Request parameter name for the dialog title. */
0222: public static final String PARAM_TITLE = "title";
0223:
0224: /** Request parameter value for the action: begin the report. */
0225: public static final String REPORT_BEGIN = "reportbegin";
0226:
0227: /** Request parameter value for the action: end the report. */
0228: public static final String REPORT_END = "reportend";
0229:
0230: /** Request parameter value for the action: update the report. */
0231: public static final String REPORT_UPDATE = "reportupdate";
0232:
0233: /** Key name for the throwable attribute. */
0234: protected static final String ATTRIBUTE_THROWABLE = "throwable";
0235:
0236: /** The log object for this class. */
0237: private static final Log LOG = CmsLog.getLog(CmsDialog.class);
0238:
0239: private int m_action;
0240:
0241: /**
0242: * The custom mapping for online help.<p>
0243: *
0244: * It will be translated to a javascript variable called onlineHelpUriCustom.
0245: * If it is set, the top.head javascript for the online help will use this value. <p>
0246: */
0247: private String m_onlineHelpUriCustom;
0248:
0249: private String m_paramAction;
0250: private String m_paramCloseLink;
0251: private String m_paramDialogtype;
0252: private String m_paramFrameName;
0253: private String m_paramIsPopup;
0254: private String m_paramMessage;
0255: private String m_paramOriginalParams;
0256: private String m_paramPreActionDone;
0257: private String m_paramRedirect;
0258: private String m_paramResource;
0259: private String m_paramTitle;
0260:
0261: /**
0262: * Public constructor with JSP action element.<p>
0263: *
0264: * @param jsp an initialized JSP action element
0265: */
0266: public CmsDialog(CmsJspActionElement jsp) {
0267:
0268: super (jsp);
0269: }
0270:
0271: /**
0272: * Public constructor with JSP variables.<p>
0273: *
0274: * @param context the JSP page context
0275: * @param req the JSP request
0276: * @param res the JSP response
0277: */
0278: public CmsDialog(PageContext context, HttpServletRequest req,
0279: HttpServletResponse res) {
0280:
0281: this (new CmsJspActionElement(context, req, res));
0282: }
0283:
0284: /**
0285: * Returns an initialized CmsDialog instance that is read from the request attributes.<p>
0286: *
0287: * This method is used by dialog elements.
0288: * The dialog elements do not initialize their own workplace class,
0289: * but use the initialized instance of the "master" class.
0290: * This is required to ensure that parameters of the "master" class
0291: * can properly be kept on the dialog elements.<p>
0292: *
0293: * To prevent null pointer exceptions, an empty dialog is returned if
0294: * nothing is found in the request attributes.<p>
0295: *
0296: * @param context the JSP page context
0297: * @param req the JSP request
0298: * @param res the JSP response
0299: * @return an initialized CmsDialog instance that is read from the request attributes
0300: */
0301: public static CmsDialog initCmsDialog(PageContext context,
0302: HttpServletRequest req, HttpServletResponse res) {
0303:
0304: CmsDialog wp = (CmsDialog) req
0305: .getAttribute(CmsWorkplace.SESSION_WORKPLACE_CLASS);
0306: if (wp == null) {
0307: // ensure that we don't get null pointers if the page is directly called
0308: wp = new CmsDialog(new CmsJspActionElement(context, req,
0309: res));
0310: wp.fillParamValues(req);
0311: }
0312: return wp;
0313: }
0314:
0315: /**
0316: * Used to close the current JSP dialog.<p>
0317: *
0318: * This method tries to include the URI stored in the workplace settings.
0319: * This URI is determined by the frame name, which has to be set
0320: * in the framename parameter.<p>
0321: *
0322: * @throws JspException if including an element fails
0323: */
0324: public void actionCloseDialog() throws JspException {
0325:
0326: // create a map with empty "resource" parameter to avoid changing the folder when returning to explorer file list
0327: Map params = new HashMap();
0328: params.put(PARAM_RESOURCE, "");
0329: if (isPopup()) {
0330: try {
0331: // try to close the popup
0332: JspWriter out = getJsp().getJspContext().getOut();
0333: out.write("<html><head></head>\n");
0334: out.write("<body onload=\"top.close();\">\n");
0335: out.write("</body>\n");
0336: out.write("</html>\n");
0337: } catch (IOException e) {
0338: // error redirecting, include explorer file list
0339: getJsp().include(FILE_EXPLORER_FILELIST, null, params);
0340: }
0341: } else if (getParamCloseLink() != null) {
0342: // close link parameter present
0343: try {
0344: if (Boolean.valueOf(getParamRedirect()).booleanValue()) {
0345: // redirect parameter is true, redirect to given close link
0346: getJsp().getResponse().sendRedirect(
0347: getParamCloseLink());
0348: } else {
0349: // forward JSP
0350: if (!isForwarded()) {
0351: setForwarded(true);
0352: CmsRequestUtil.forwardRequest(
0353: getParamCloseLink(), getJsp()
0354: .getRequest(), getJsp()
0355: .getResponse());
0356: }
0357: }
0358: } catch (Exception e) {
0359: // forward failed
0360: throw new JspException(e.getMessage(), e);
0361: }
0362: } else if (getParamFramename() != null) {
0363: // non wp frame mode (currently used for galleries)
0364: // framename parameter found, get URI
0365: String frameUri = (String) getSettings().getFrameUris()
0366: .get(getParamFramename());
0367: if (frameUri != null) {
0368: // URI found, include it
0369: if (frameUri.startsWith(OpenCms.getSystemInfo()
0370: .getOpenCmsContext())) {
0371: // remove context path from URI before inclusion
0372: frameUri = frameUri.substring(OpenCms
0373: .getSystemInfo().getOpenCmsContext()
0374: .length());
0375: }
0376: // include the found frame URI
0377: getJsp().include(frameUri, null, params);
0378: } else {
0379: // no URI found, include the explorer file list
0380: getJsp().include(FILE_EXPLORER_FILELIST, null, params);
0381: }
0382: } else {
0383: // no framename parameter found, include the explorer file list
0384: getJsp().include(FILE_EXPLORER_FILELIST, null, params);
0385: }
0386: }
0387:
0388: /**
0389: * Returns the html code to build the ajax report container.<p>
0390: *
0391: * @param title the title of the report box
0392: *
0393: * @return html code
0394: */
0395: public String buildAjaxResultContainer(String title) {
0396:
0397: StringBuffer html = new StringBuffer(512);
0398: html.append(dialogBlockStart(title));
0399: html.append(dialogWhiteBoxStart());
0400: html.append("<div id='ajaxreport' >");
0401: html.append(buildAjaxWaitMessage());
0402: html.append("</div>\n");
0403: html.append(dialogWhiteBoxEnd());
0404: html.append(dialogBlockEnd());
0405: html.append(" <br>\n");
0406: return html.toString();
0407: }
0408:
0409: /**
0410: * Override to display additional options in the lock dialog.<p>
0411: *
0412: * @return html code to display additional options
0413: */
0414: public String buildLockAdditionalOptions() {
0415:
0416: return "";
0417: }
0418:
0419: /**
0420: * Returns the html code to build the confirmation messages.<p>
0421: *
0422: * @return html code
0423: */
0424: public String buildLockConfirmationMessageJS() {
0425:
0426: StringBuffer html = new StringBuffer(512);
0427: html.append("<script type='text/javascript'><!--\n");
0428: html
0429: .append("function setConfirmationMessage(locks, blockinglocks) {\n");
0430: html
0431: .append("\tvar confMsg = document.getElementById('conf-msg');\n");
0432: html.append("\tif (locks > -1) {\n");
0433: html.append("\t\tif (blockinglocks > '0') {\n");
0434: html.append("\t\t\tshowAjaxReportContent();\n");
0435: html
0436: .append("\t\t\tdocument.getElementById('lock-body-id').className = '';\n");
0437: html
0438: .append("\t\t\tdocument.getElementById('butClose').className = '';\n");
0439: html
0440: .append("\t\t\tdocument.getElementById('butContinue').className = 'hide';\n");
0441: html.append("\t\t\tconfMsg.innerHTML = '");
0442: html
0443: .append(key(org.opencms.workplace.commons.Messages.GUI_OPERATION_BLOCKING_LOCKS_0));
0444: html.append("';\n");
0445: html.append("\t\t} else {\n");
0446: html.append("\t\t\tsubmitAction('");
0447: html.append(CmsDialog.DIALOG_OK);
0448: html.append("', null, 'main');\n");
0449: html.append("\t\t\tdocument.forms['main'].submit();\n");
0450: html.append("\t\t}\n");
0451: html.append("\t} else {\n");
0452: html
0453: .append("\t\tdocument.getElementById('butClose').className = '';\n");
0454: html
0455: .append("\t\tdocument.getElementById('butContinue').className = 'hide';\n");
0456: html.append("\t\tconfMsg.innerHTML = '");
0457: html.append(key(Messages.GUI_AJAX_REPORT_WAIT_0));
0458: html.append("';\n");
0459: html.append("\t}\n");
0460: html.append("}\n");
0461: html.append("// -->\n");
0462: html.append("</script>\n");
0463: return html.toString();
0464: }
0465:
0466: /**
0467: * Returns the html code to build the lock dialog.<p>
0468: *
0469: * @return html code
0470: *
0471: * @throws CmsException if something goes wrong
0472: */
0473: public String buildLockDialog() throws CmsException {
0474:
0475: return buildLockDialog(null, null, 2000, false);
0476: }
0477:
0478: /**
0479: * Returns the html code to build the lock dialog.<p>
0480: *
0481: * @param nonBlockingFilter the filter to get all non blocking locks
0482: * @param blockingFilter the filter to get all blocking locks
0483: * @param hiddenTimeout the maximal number of millis the dialog will be hidden
0484: * @param includeRelated indicates if the report should include related resources
0485: *
0486: * @return html code
0487: *
0488: * @throws CmsException if something goes wrong
0489: */
0490: public String buildLockDialog(CmsLockFilter nonBlockingFilter,
0491: CmsLockFilter blockingFilter, int hiddenTimeout,
0492: boolean includeRelated) throws CmsException {
0493:
0494: setParamAction(CmsDialog.DIALOG_LOCKS_CONFIRMED);
0495: CmsLock lockwp = new CmsLock(getJsp());
0496: lockwp.setBlockingFilter(blockingFilter);
0497: lockwp.setNonBlockingFilter(nonBlockingFilter);
0498:
0499: StringBuffer html = new StringBuffer(512);
0500: html.append(htmlStart("help.explorer.contextmenu.lock"));
0501: html.append(lockwp.buildIncludeJs());
0502: html.append(buildLockConfirmationMessageJS());
0503: html.append(bodyStart("dialog"));
0504: html.append("<div id='lock-body-id' class='hide'>\n");
0505: html.append(dialogStart());
0506: html.append(dialogContentStart(getParamTitle()));
0507: html.append(buildLockHeaderBox());
0508: html.append(dialogSpacer());
0509: html.append("<form name='main' action='");
0510: html.append(getDialogUri());
0511: html
0512: .append("' method='post' class='nomargin' onsubmit=\"return submitAction('");
0513: html.append(CmsDialog.DIALOG_OK);
0514: html.append("', null, 'main');\">\n");
0515: html.append(paramsAsHidden());
0516: html.append("<input type='hidden' name='");
0517: html.append(CmsDialog.PARAM_FRAMENAME);
0518: html.append("' value=''>\n");
0519: html
0520: .append(buildAjaxResultContainer(key(org.opencms.workplace.commons.Messages.GUI_LOCK_RESOURCES_TITLE_0)));
0521: html.append("<div id='conf-msg'></div>\n");
0522: html.append(buildLockAdditionalOptions());
0523: html.append(dialogContentEnd());
0524: html.append(dialogLockButtons());
0525: html.append("</form>\n");
0526: html.append(dialogEnd());
0527: html.append("</div>\n");
0528: html.append(bodyEnd());
0529: html.append(lockwp.buildLockRequest(hiddenTimeout,
0530: includeRelated));
0531: html.append(htmlEnd());
0532: return html.toString();
0533: }
0534:
0535: /**
0536: * Returns the html code to build the header box.<p>
0537: *
0538: * @return html code
0539: *
0540: * @throws CmsException if something goes wrong
0541: */
0542: public String buildLockHeaderBox() throws CmsException {
0543:
0544: StringBuffer html = new StringBuffer(512);
0545: // include resource info
0546: html.append(dialogBlockStart(null));
0547: html
0548: .append(key(org.opencms.workplace.commons.Messages.GUI_LABEL_TITLE_0));
0549: html.append(": ");
0550: html.append(getJsp().property("Title", getParamResource(), ""));
0551: html.append("<br>\n");
0552: html
0553: .append(key(org.opencms.workplace.commons.Messages.GUI_LABEL_STATE_0));
0554: html.append(": ");
0555: html.append(getState());
0556: html.append("<br>\n");
0557: html
0558: .append(key(org.opencms.workplace.commons.Messages.GUI_LABEL_PERMALINK_0));
0559: html.append(": ");
0560: html.append(OpenCms.getLinkManager().getPermalink(getCms(),
0561: getParamResource()));
0562: html.append(dialogBlockEnd());
0563: return html.toString();
0564: }
0565:
0566: /**
0567: * Builds the outer dialog window border.<p>
0568: *
0569: * @param segment the HTML segment (START / END)
0570: * @param attributes optional additional attributes for the opening dialog table
0571: * @return a dialog window start / end segment
0572: */
0573: public String dialog(int segment, String attributes) {
0574:
0575: if (segment == HTML_START) {
0576: StringBuffer html = new StringBuffer(512);
0577: if (useNewStyle()) {
0578: html.append(dialogTitle());
0579: }
0580: html
0581: .append("<table class=\"dialog\" cellpadding=\"0\" cellspacing=\"0\"");
0582: if (attributes != null) {
0583: html.append(" ");
0584: html.append(attributes);
0585: }
0586: html
0587: .append("><tr><td>\n<table class=\"dialogbox\" cellpadding=\"0\" cellspacing=\"0\">\n");
0588: html.append("<tr><td>\n");
0589: if (useNewStyle()
0590: && getToolManager().hasToolPathForUrl(
0591: getJsp().getRequestContext().getUri())) {
0592: html.append(getAdminTool().groupHtml(this ));
0593: }
0594: return html.toString();
0595: } else {
0596: return "</td></tr></table>\n</td></tr></table>\n<p> </p>\n";
0597: }
0598: }
0599:
0600: /**
0601: * Builds a block with 3D border and optional subheadline in the dialog content area.<p>
0602: *
0603: * @param segment the HTML segment (START / END)
0604: * @param headline the headline String for the block
0605: * @param error if true, an error block will be created
0606: * @return 3D block start / end segment
0607: */
0608: public String dialogBlock(int segment, String headline,
0609: boolean error) {
0610:
0611: if (segment == HTML_START) {
0612: StringBuffer result = new StringBuffer(512);
0613: String errorStyle = "";
0614: if (error) {
0615: errorStyle = " dialogerror";
0616: }
0617: result.append("<!-- 3D block start -->\n");
0618: result.append("<fieldset class=\"dialogblock\">\n");
0619: if (CmsStringUtil.isNotEmpty(headline)) {
0620: result.append("<legend>");
0621: result.append("<span class=\"textbold");
0622: result.append(errorStyle);
0623: result.append("\" unselectable=\"on\">");
0624: result.append(headline);
0625: result.append("</span></legend>\n");
0626: }
0627: return result.toString();
0628: } else {
0629: return "</fieldset>\n<!-- 3D block end -->\n";
0630: }
0631: }
0632:
0633: /**
0634: * Builds the end HTML for a block with 3D border in the dialog content area.<p>
0635: *
0636: * @return 3D block start / end segment
0637: */
0638: public String dialogBlockEnd() {
0639:
0640: return dialogBlock(HTML_END, null, false);
0641: }
0642:
0643: /**
0644: * Builds the start HTML for a block with 3D border and optional subheadline in the dialog content area.<p>
0645: *
0646: * @param headline the headline String for the block
0647: * @return 3D block start / end segment
0648: */
0649: public String dialogBlockStart(String headline) {
0650:
0651: return dialogBlock(HTML_START, headline, false);
0652: }
0653:
0654: /**
0655: * Builds the button row under the dialog content area without the buttons.<p>
0656: *
0657: * @param segment the HTML segment (START / END)
0658: * @return the button row start / end segment
0659: */
0660: public String dialogButtonRow(int segment) {
0661:
0662: if (segment == HTML_START) {
0663: return "<!-- button row start -->\n<div class=\"dialogbuttons\" unselectable=\"on\">\n";
0664: } else {
0665: return "</div>\n<!-- button row end -->\n";
0666: }
0667: }
0668:
0669: /**
0670: * Builds the end of the button row under the dialog content area without the buttons.<p>
0671: *
0672: * @return the button row end segment
0673: */
0674: public String dialogButtonRowEnd() {
0675:
0676: return dialogButtonRow(HTML_END);
0677: }
0678:
0679: /**
0680: * Builds the start of the button row under the dialog content area without the buttons.<p>
0681: *
0682: * @return the button row start segment
0683: */
0684: public String dialogButtonRowStart() {
0685:
0686: return dialogButtonRow(HTML_START);
0687: }
0688:
0689: /**
0690: * Builds the html for the button row under the dialog content area, including buttons.<p>
0691: *
0692: * @param buttons array of constants of which buttons to include in the row
0693: * @param attributes array of Strings for additional button attributes
0694: * @return the html for the button row under the dialog content area, including buttons
0695: */
0696: public String dialogButtons(int[] buttons, String[] attributes) {
0697:
0698: StringBuffer result = new StringBuffer(256);
0699: result.append(dialogButtonRow(HTML_START));
0700: for (int i = 0; i < buttons.length; i++) {
0701: dialogButtonsHtml(result, buttons[i], attributes[i]);
0702: }
0703: result.append(dialogButtonRow(HTML_END));
0704: return result.toString();
0705: }
0706:
0707: /**
0708: * Builds a button row with a single "close" button.<p>
0709: *
0710: * @return the button row
0711: */
0712: public String dialogButtonsClose() {
0713:
0714: return dialogButtons(new int[] { BUTTON_CLOSE }, new String[1]);
0715: }
0716:
0717: /**
0718: * Builds a button row with a single "close" button.<p>
0719: *
0720: * @param closeAttribute additional attributes for the "close" button
0721: * @return the button row
0722: */
0723: public String dialogButtonsClose(String closeAttribute) {
0724:
0725: return dialogButtons(new int[] { BUTTON_CLOSE },
0726: new String[] { closeAttribute });
0727: }
0728:
0729: /**
0730: * Builds a button row with a "close" and a "details" button.<p>
0731: *
0732: * @param closeAttribute additional attributes for the "close" button
0733: * @param detailsAttribute additional attributes for the "details" button
0734: * @return the button row
0735: */
0736: public String dialogButtonsCloseDetails(String closeAttribute,
0737: String detailsAttribute) {
0738:
0739: return dialogButtons(
0740: new int[] { BUTTON_CLOSE, BUTTON_DETAILS },
0741: new String[] { closeAttribute, detailsAttribute });
0742: }
0743:
0744: /**
0745: * Builds a button row with a single "ok" button.<p>
0746: *
0747: * @return the button row
0748: */
0749: public String dialogButtonsOk() {
0750:
0751: return dialogButtons(new int[] { BUTTON_OK }, new String[1]);
0752: }
0753:
0754: /**
0755: * Builds a button row with a single "ok" button.<p>
0756: *
0757: * @param okAttribute additional attributes for the "ok" button
0758: * @return the button row
0759: */
0760: public String dialogButtonsOk(String okAttribute) {
0761:
0762: return dialogButtons(new int[] { BUTTON_OK },
0763: new String[] { okAttribute });
0764: }
0765:
0766: /**
0767: * Builds a button row with an "ok" and a "cancel" button.<p>
0768: *
0769: * @return the button row
0770: */
0771: public String dialogButtonsOkCancel() {
0772:
0773: return dialogButtons(new int[] { BUTTON_OK, BUTTON_CANCEL },
0774: new String[2]);
0775: }
0776:
0777: /**
0778: * Builds a button row with an "ok" and a "cancel" button.<p>
0779: *
0780: * @param okAttributes additional attributes for the "ok" button
0781: * @param cancelAttributes additional attributes for the "cancel" button
0782: * @return the button row
0783: */
0784: public String dialogButtonsOkCancel(String okAttributes,
0785: String cancelAttributes) {
0786:
0787: return dialogButtons(new int[] { BUTTON_OK, BUTTON_CANCEL },
0788: new String[] { okAttributes, cancelAttributes });
0789: }
0790:
0791: /**
0792: * Builds a button row with an "ok", a "cancel" and an "advanced" button.<p>
0793: *
0794: * @param okAttributes additional attributes for the "ok" button
0795: * @param cancelAttributes additional attributes for the "cancel" button
0796: * @param advancedAttributes additional attributes for the "advanced" button
0797: * @return the button row
0798: */
0799: public String dialogButtonsOkCancelAdvanced(String okAttributes,
0800: String cancelAttributes, String advancedAttributes) {
0801:
0802: return dialogButtons(new int[] { BUTTON_OK, BUTTON_CANCEL,
0803: BUTTON_ADVANCED }, new String[] { okAttributes,
0804: cancelAttributes, advancedAttributes });
0805: }
0806:
0807: /**
0808: * Builds a button row with a "set", an "ok", and a "cancel" button.<p>
0809: *
0810: * @param setAttributes additional attributes for the "set" button
0811: * @param okAttributes additional attributes for the "ok" button
0812: * @param cancelAttributes additional attributes for the "cancel" button
0813: * @return the button row
0814: */
0815: public String dialogButtonsSetOkCancel(String setAttributes,
0816: String okAttributes, String cancelAttributes) {
0817:
0818: return dialogButtons(new int[] { BUTTON_SET, BUTTON_OK,
0819: BUTTON_CANCEL }, new String[] { setAttributes,
0820: okAttributes, cancelAttributes });
0821: }
0822:
0823: /**
0824: * Builds the content area of the dialog window.<p>
0825: *
0826: * @param segment the HTML segment (START / END)
0827: * @param title the title String for the dialog window
0828: * @return a content area start / end segment
0829: */
0830: public String dialogContent(int segment, String title) {
0831:
0832: if (segment == HTML_START) {
0833: StringBuffer result = new StringBuffer(512);
0834: // null title is ok, we always want the title headline
0835: result.append(dialogHead(title));
0836: result
0837: .append("<div class=\"dialogcontent\" unselectable=\"on\">\n");
0838: result.append("<!-- dialogcontent start -->\n");
0839: return result.toString();
0840: } else {
0841: return "<!-- dialogcontent end -->\n</div>\n";
0842: }
0843: }
0844:
0845: /**
0846: * Returns the end html for the content area of the dialog window.<p>
0847: *
0848: * @return the end html for the content area of the dialog window
0849: */
0850: public String dialogContentEnd() {
0851:
0852: return dialogContent(HTML_END, null);
0853: }
0854:
0855: /**
0856: * Returns the start html for the content area of the dialog window.<p>
0857: *
0858: * @param title the title for the dialog
0859: * @return the start html for the content area of the dialog window
0860: */
0861: public String dialogContentStart(String title) {
0862:
0863: return dialogContent(HTML_START, title);
0864: }
0865:
0866: /**
0867: * Returns the end html for the outer dialog window border.<p>
0868: *
0869: * @return the end html for the outer dialog window border
0870: */
0871: public String dialogEnd() {
0872:
0873: return dialog(HTML_END, null);
0874: }
0875:
0876: /**
0877: * Builds the title of the dialog window.<p>
0878: *
0879: * @param title the title String for the dialog window
0880: * @return the HTML title String for the dialog window
0881: */
0882: public String dialogHead(String title) {
0883:
0884: return "<div class=\"dialoghead\" unselectable=\"on\">"
0885: + (title == null ? "" : title) + "</div>";
0886: }
0887:
0888: /**
0889: * Builds an invisible horiziontal spacer with the specified width.<p>
0890: * @param width the width of the spacer in pixels
0891: * @return an invisible horiziontal spacer with the specified width
0892: */
0893: public String dialogHorizontalSpacer(int width) {
0894:
0895: return "<td><span style=\"display:block; height: 1px; width: "
0896: + width + "px;\"></span></td>";
0897: }
0898:
0899: /**
0900: * Builds the necessary button row.<p>
0901: *
0902: * @return the button row
0903: */
0904: public String dialogLockButtons() {
0905:
0906: StringBuffer html = new StringBuffer(512);
0907: html.append("<div id='butClose' >\n");
0908: html.append(dialogButtonsClose());
0909: html.append("</div>\n");
0910: html.append("<div id='butContinue' class='hide' >\n");
0911: html.append(dialogButtons(new int[] { BUTTON_CONTINUE,
0912: BUTTON_CANCEL }, new String[] {
0913: " onclick=\"submitAction('" + DIALOG_OK
0914: + "', form); form.submit();\"", "" }));
0915: html.append("</div>\n");
0916: return html.toString();
0917: }
0918:
0919: /**
0920: * Builds a dialog line without break (display: block).<p>
0921: *
0922: * @param segment the HTML segment (START / END)
0923: * @return a row start / end segment
0924: */
0925: public String dialogRow(int segment) {
0926:
0927: if (segment == HTML_START) {
0928: return "<div class=\"dialogrow\">";
0929: } else {
0930: return "</div>\n";
0931: }
0932: }
0933:
0934: /**
0935: * Builds the end of a dialog line without break (display: block).<p>
0936: *
0937: * @return the row end segment
0938: */
0939: public String dialogRowEnd() {
0940:
0941: return dialogRow(HTML_END);
0942: }
0943:
0944: /**
0945: * Builds the start of a dialog line without break (display: block).<p>
0946: *
0947: * @return the row start segment
0948: */
0949: public String dialogRowStart() {
0950:
0951: return dialogRow(HTML_START);
0952: }
0953:
0954: /**
0955: * Builds the standard javascript for submitting the dialog.<p>
0956: *
0957: * @return the standard javascript for submitting the dialog
0958: */
0959: public String dialogScriptSubmit() {
0960:
0961: if (useNewStyle()) {
0962: return super .dialogScriptSubmit();
0963: }
0964: StringBuffer result = new StringBuffer(512);
0965: result
0966: .append("function submitAction(actionValue, theForm, formName) {\n");
0967: result.append("\tif (theForm == null) {\n");
0968: result.append("\t\ttheForm = document.forms[formName];\n");
0969: result.append("\t}\n");
0970: result.append("\ttheForm." + PARAM_FRAMENAME
0971: + ".value = window.name;\n");
0972: result
0973: .append("\tif (actionValue == \"" + DIALOG_OK
0974: + "\") {\n");
0975: result.append("\t\treturn true;\n");
0976: result.append("\t}\n");
0977: result.append("\ttheForm." + PARAM_ACTION
0978: + ".value = actionValue;\n");
0979: result.append("\ttheForm.submit();\n");
0980: result.append("\treturn false;\n");
0981: result.append("}\n");
0982:
0983: return result.toString();
0984: }
0985:
0986: /**
0987: * Builds a horizontal separator line in the dialog content area.<p>
0988: *
0989: * @return a separator element
0990: */
0991: public String dialogSeparator() {
0992:
0993: return "<div class=\"dialogseparator\" unselectable=\"on\"></div>";
0994: }
0995:
0996: /**
0997: * Builds a space between two elements in the dialog content area.<p>
0998: *
0999: * @return a space element
1000: */
1001: public String dialogSpacer() {
1002:
1003: return "<div class=\"dialogspacer\" unselectable=\"on\"> </div>";
1004: }
1005:
1006: /**
1007: * Returns the start html for the outer dialog window border.<p>
1008: *
1009: * @return the start html for the outer dialog window border
1010: */
1011: public String dialogStart() {
1012:
1013: return dialog(HTML_START, null);
1014: }
1015:
1016: /**
1017: * Returns the start html for the outer dialog window border.<p>
1018: *
1019: * @param attributes optional html attributes to insert
1020: * @return the start html for the outer dialog window border
1021: */
1022: public String dialogStart(String attributes) {
1023:
1024: return dialog(HTML_START, attributes);
1025: }
1026:
1027: /**
1028: * Builds a subheadline in the dialog content area.<p>
1029: *
1030: * @param headline the desired headline string
1031: * @return a subheadline element
1032: */
1033: public String dialogSubheadline(String headline) {
1034:
1035: StringBuffer retValue = new StringBuffer(128);
1036: retValue
1037: .append("<div class=\"dialogsubheader\" unselectable=\"on\">");
1038: retValue.append(headline);
1039: retValue.append("</div>\n");
1040: return retValue.toString();
1041: }
1042:
1043: /**
1044: * Builds the HTML code to fold and unfild a white-box.<p>
1045: *
1046: * @param headline the heading to display
1047: * @param id the id of the toggle
1048: * @param show true if the white box is open at the beginning
1049: *
1050: * @return HTML code to fold and unfild a white-box
1051: */
1052: public String dialogToggleStart(String headline, String id,
1053: boolean show) {
1054:
1055: StringBuffer result = new StringBuffer(512);
1056: // set icon and style class to use: hide user permissions
1057: String image = "plus.png";
1058: String styleClass = "hide";
1059: if (show) {
1060: // show user permissions
1061: image = "minus.png";
1062: styleClass = "show";
1063: }
1064:
1065: result
1066: .append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
1067: result.append("<tr>\n");
1068: result
1069: .append("\t<td style=\"vertical-align: bottom; padding-bottom: 2px;\"><a href=\"javascript:toggleDetail('");
1070: result.append(id);
1071: result.append("');\"><img src=\"");
1072: result.append(getSkinUri());
1073: result.append("commons/");
1074: result.append(image);
1075: result.append("\" class=\"noborder\" id=\"ic-");
1076: result.append(id);
1077: result.append("\"></a></td>\n");
1078: result.append("\t<td>");
1079: result.append(dialogSubheadline(headline));
1080: result.append("</td>\n");
1081: result.append("</tr>\n");
1082: result.append("</table>\n");
1083:
1084: result.append("<div class=\"");
1085: result.append(styleClass);
1086: result.append("\" id=\"");
1087: result.append(id);
1088: result.append("\">\n");
1089: return result.toString();
1090: }
1091:
1092: /**
1093: * Builds a white box in the dialog content area.<p>
1094: *
1095: * @param segment the HTML segment (START / END)
1096: * @return the white box start / end segment
1097: */
1098: public String dialogWhiteBox(int segment) {
1099:
1100: if (segment == HTML_START) {
1101: return "<!-- white box start -->\n"
1102: + "<div class=\"dialoginnerboxborder\">\n"
1103: + "<div class=\"dialoginnerbox\" unselectable=\"off\">\n";
1104: } else {
1105: return "</div>\n</div>\n<!-- white box end -->\n";
1106: }
1107: }
1108:
1109: /**
1110: * Builds the end of a white box in the dialog content area.<p>
1111: *
1112: * @return the white box end segment
1113: */
1114: public String dialogWhiteBoxEnd() {
1115:
1116: return dialogWhiteBox(HTML_END);
1117: }
1118:
1119: /**
1120: * Builds the start of a white box in the dialog content area.<p>
1121: *
1122: * @return the white box start segment
1123: */
1124: public String dialogWhiteBoxStart() {
1125:
1126: return dialogWhiteBox(HTML_START);
1127: }
1128:
1129: /**
1130: * Returns the action value.<p>
1131: *
1132: * The action value is used on JSP pages to select the proper action
1133: * in a large "switch" statement.<p>
1134: *
1135: * @return the action value
1136: */
1137: public int getAction() {
1138:
1139: return m_action;
1140: }
1141:
1142: /**
1143: * Returns the action to be carried out after a click on the cancel button..<p>
1144: *
1145: * @return the action to be carried out after a click on the cancel button.
1146: */
1147: public String getCancelAction() {
1148:
1149: return DIALOG_CANCEL;
1150: }
1151:
1152: /**
1153: * Returns the http URI of the current dialog, to be used
1154: * as value for the "action" attribute of a html form.<p>
1155: *
1156: * This URI is the real one.<p>
1157: *
1158: * @return the http URI of the current dialog
1159: */
1160: public String getDialogRealUri() {
1161:
1162: return getJsp().link(getJsp().getRequestContext().getUri());
1163: }
1164:
1165: /**
1166: * Returns the http URI of the current dialog, to be used
1167: * as value for the "action" attribute of a html form.<p>
1168: *
1169: * This URI could not be really the real one... <p>
1170: *
1171: * @return the http URI of the current dialog
1172: */
1173: public String getDialogUri() {
1174:
1175: if (!useNewStyle()) {
1176: return getDialogRealUri();
1177: } else {
1178: return CmsToolManager.linkForToolPath(getJsp(),
1179: getCurrentToolPath());
1180: }
1181: }
1182:
1183: /**
1184: * Returns the custom mapping for the online help.<p>
1185: *
1186: * @return the custom mapping for the online help
1187: */
1188: public String getOnlineHelpUriCustom() {
1189:
1190: if (m_onlineHelpUriCustom == null) {
1191: return null;
1192: }
1193: StringBuffer result = new StringBuffer(m_onlineHelpUriCustom
1194: .length() + 4);
1195: result.append("\"");
1196: result.append(m_onlineHelpUriCustom);
1197: result.append("\"");
1198: return result.toString();
1199: }
1200:
1201: /**
1202: * Returns the value of the action parameter,
1203: * or null if this parameter was not provided.<p>
1204: *
1205: * The action parameter is very important,
1206: * it will select the dialog action to perform.
1207: * The value of the {@link #getAction()} method will be
1208: * initialized from the action parameter.<p>
1209: *
1210: * @return the value of the action parameter
1211: */
1212: public String getParamAction() {
1213:
1214: return m_paramAction;
1215: }
1216:
1217: /**
1218: * Returns the value of the closelink parameter,
1219: * or null if this parameter was not provided.<p>
1220: *
1221: * @return the value of the closelink parameter
1222: */
1223: public String getParamCloseLink() {
1224:
1225: if ((m_paramCloseLink == null)
1226: || "null".equals(m_paramCloseLink)) {
1227: return null;
1228: }
1229: return m_paramCloseLink;
1230: }
1231:
1232: /**
1233: * Returns the value of the dialogtype parameter,
1234: * or null if this parameter was not provided.<p>
1235: *
1236: * This parameter is very important.
1237: * It must match to the localization keys,
1238: * e.g. "copy" for the copy dialog.<p>
1239: *
1240: * This parameter must be set manually by the subclass during
1241: * first initialization.<p>
1242: *
1243: * @return the value of the dialogtype parameter
1244: */
1245: public String getParamDialogtype() {
1246:
1247: return m_paramDialogtype;
1248: }
1249:
1250: /**
1251: * Returns the value of the frame name parameter.<p>
1252: *
1253: * @return the value of the errorstack parameter
1254: */
1255: public String getParamFramename() {
1256:
1257: if ((m_paramFrameName != null)
1258: && !"null".equals(m_paramFrameName)) {
1259: return m_paramFrameName;
1260: } else {
1261: return null;
1262: }
1263: }
1264:
1265: /**
1266: * Returns the ispopup parameter.<p>
1267: *
1268: * Use this parameter to indicate that the dialog is shown in a popup window.<p>
1269: *
1270: * @return the ispopup parameter
1271: */
1272: public String getParamIsPopup() {
1273:
1274: return m_paramIsPopup;
1275: }
1276:
1277: /**
1278: * Returns the value of the message parameter,
1279: * or null if this parameter was not provided.<p>
1280: *
1281: * The message parameter is used on dialogs to
1282: * show any text message.<p>
1283: *
1284: * @return the value of the message parameter
1285: */
1286: public String getParamMessage() {
1287:
1288: return m_paramMessage;
1289: }
1290:
1291: /**
1292: * Returns the value of the originalparams parameter.<p>
1293: *
1294: * This stores the request parameter values from a previous dialog, if necessary.<p>
1295: *
1296: * @return the value of the originalparams parameter
1297: */
1298: public String getParamOriginalParams() {
1299:
1300: return m_paramOriginalParams;
1301: }
1302:
1303: /**
1304: * Returns the value of the preactiondone parameter.<p>
1305: *
1306: * @return the value of the preactiondone parameter
1307: */
1308: public String getParamPreActionDone() {
1309:
1310: return m_paramPreActionDone;
1311: }
1312:
1313: /**
1314: * Returns the value of the redirect flag parameter.<p>
1315: *
1316: * @return the value of the redirect flag parameter
1317: */
1318: public String getParamRedirect() {
1319:
1320: return m_paramRedirect;
1321: }
1322:
1323: /**
1324: * Returns the value of the file parameter,
1325: * or null if this parameter was not provided.<p>
1326: *
1327: * The file parameter selects the file on which the dialog action
1328: * is to be performed.<p>
1329: *
1330: * @return the value of the file parameter
1331: */
1332: public String getParamResource() {
1333:
1334: if ((m_paramResource != null)
1335: && !"null".equals(m_paramResource)) {
1336: return m_paramResource;
1337: } else {
1338: return null;
1339: }
1340: }
1341:
1342: /**
1343: * Returns the value of the title parameter,
1344: * or null if this parameter was not provided.<p>
1345: *
1346: * This parameter is used to build the title
1347: * of the dialog. It is a parameter so that the title
1348: * can be passed to included elements.<p>
1349: *
1350: * @return the value of the title parameter
1351: */
1352: public String getParamTitle() {
1353:
1354: return m_paramTitle;
1355: }
1356:
1357: /**
1358: * Gets a formatted file state string.<p>
1359: *
1360: * @return formatted state string
1361: * @throws CmsException if something goes wrong
1362: */
1363: public String getState() throws CmsException {
1364:
1365: if (CmsStringUtil.isNotEmpty(getParamResource())) {
1366: CmsResource file = getCms().readResource(
1367: getParamResource(), CmsResourceFilter.ALL);
1368: if (getCms().isInsideCurrentProject(getParamResource())) {
1369: return key(Messages.getStateKey(file.getState()));
1370: } else {
1371: return key(Messages.GUI_EXPLORER_STATENIP_0);
1372: }
1373: }
1374: return "+++ resource parameter not found +++";
1375: }
1376:
1377: /**
1378: * Checks if the current resource has lock state exclusive or inherited.<p>
1379: *
1380: * This is used to determine whether the dialog shows the option to delete all
1381: * siblings of the resource or not.
1382: *
1383: * @return true if lock state is exclusive or inherited, otherwise false
1384: */
1385: public boolean hasCorrectLockstate() {
1386:
1387: org.opencms.lock.CmsLock lock = null;
1388: try {
1389: // get the lock state for the current resource
1390: lock = getCms().getLock(getParamResource());
1391: } catch (CmsException e) {
1392: // error getting lock state, log the error and return false
1393: LOG.error(e.getLocalizedMessage(getLocale()), e);
1394: return false;
1395: }
1396: // check if autolock feature is enabled
1397: boolean autoLockFeature = lock.isNullLock()
1398: && OpenCms.getWorkplaceManager().autoLockResources();
1399: return autoLockFeature || lock.isExclusive()
1400: || lock.isInherited();
1401: }
1402:
1403: /**
1404: * Checks if this resource has siblings.<p>
1405: *
1406: * @return true if this resource has siblings
1407: */
1408: public boolean hasSiblings() {
1409:
1410: try {
1411: return getCms().readResource(getParamResource(),
1412: CmsResourceFilter.ALL).getSiblingCount() > 1;
1413: } catch (CmsException e) {
1414: LOG.error(e.getLocalizedMessage(getLocale()), e);
1415: return false;
1416: }
1417:
1418: }
1419:
1420: /**
1421: * Builds the start html of the page, including setting of DOCTYPE and
1422: * inserting a header with the content-type.<p>
1423: *
1424: * @return the start html of the page
1425: */
1426: public String htmlStart() {
1427:
1428: return pageHtml(HTML_START, null);
1429: }
1430:
1431: /**
1432: * Builds the start html of the page, including setting of DOCTYPE and
1433: * inserting a header with the content-type.<p>
1434: *
1435: * This overloads the default method of the parent class.<p>
1436: *
1437: * @param helpUrl the key for the online help to include on the page
1438: * @return the start html of the page
1439: */
1440: public String htmlStart(String helpUrl) {
1441:
1442: return pageHtml(HTML_START, helpUrl);
1443: }
1444:
1445: /**
1446: * Builds the start html of the page, including setting of DOCTYPE and
1447: * inserting a header with the content-type.<p>
1448: *
1449: * @param helpUrl the key for the online help to include on the page
1450: * @param title the title for the page
1451: * @return the start html of the page
1452: */
1453: public String htmlStart(String helpUrl, String title) {
1454:
1455: return pageHtml(HTML_START, helpUrl, title);
1456: }
1457:
1458: /**
1459: * Builds the start html of the page, including setting of DOCTYPE,
1460: * inserting a header with the content-type and choosing an individual style sheet.<p>
1461: *
1462: * @param title the title for the page
1463: * @param stylesheet the style sheet to include
1464: * @return the start html of the page
1465: */
1466: public String htmlStartStyle(String title, String stylesheet) {
1467:
1468: return pageHtmlStyle(HTML_START, title, stylesheet);
1469: }
1470:
1471: /**
1472: * Displays the throwable on the error page and logs the error.<p>
1473: *
1474: * @param wp the workplace class
1475: * @param t the throwable to be displayed on the error page
1476: * @throws JspException if the include of the error page jsp fails
1477: */
1478: public void includeErrorpage(CmsWorkplace wp, Throwable t)
1479: throws JspException {
1480:
1481: CmsLog.getLog(wp).error(
1482: Messages.get().getBundle().key(
1483: Messages.ERR_WORKPLACE_DIALOG_0), t);
1484: getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, wp);
1485: getJsp().getRequest().setAttribute(ATTRIBUTE_THROWABLE, t);
1486: getJsp().include(FILE_DIALOG_SCREEN_ERRORPAGE);
1487: }
1488:
1489: /**
1490: * Returns the "isPopup" flag.<p>
1491: *
1492: * @return the "isPopup" flag
1493: */
1494: public boolean isPopup() {
1495:
1496: return Boolean.valueOf(getParamIsPopup()).booleanValue();
1497: }
1498:
1499: /**
1500: * Returns if the dialog is called in direct edit mode before the editor is opened.<p>
1501: *
1502: * @return true if the dialog is called in direct edit mode before the editor is opened
1503: */
1504: public boolean isPreEditor() {
1505:
1506: return CmsPreEditorAction.isPreEditorMode(this );
1507: }
1508:
1509: /**
1510: * Builds the start html of the page, including setting of DOCTYPE and
1511: * inserting a header with the content-type.<p>
1512: *
1513: * This overloads the default method of the parent class.<p>
1514: *
1515: * @param segment the HTML segment (START / END)
1516: * @param helpUrl the url for the online help to include on the page
1517: * @return the start html of the page
1518: */
1519: public String pageHtml(int segment, String helpUrl) {
1520:
1521: return pageHtml(segment, helpUrl, null);
1522: }
1523:
1524: /**
1525: * Builds the start html of the page, including setting of DOCTYPE and
1526: * inserting a header with the content-type.<p>
1527: *
1528: * This overloads the default method of the parent class.<p>
1529: *
1530: * @param segment the HTML segment (START / END)
1531: * @param helpUrl the url for the online help to include on the page
1532: * @param title the title for the page
1533: * @return the start html of the page
1534: */
1535: public String pageHtml(int segment, String helpUrl, String title) {
1536:
1537: if (segment == HTML_START) {
1538: String stylesheet = null;
1539: if (isPopup() && !useNewStyle()) {
1540: stylesheet = "popup.css";
1541: }
1542: StringBuffer result = new StringBuffer(pageHtmlStyle(
1543: segment, title, stylesheet));
1544: if (getSettings().isViewExplorer()) {
1545: result
1546: .append("<script type=\"text/javascript\" src=\"");
1547: result.append(getSkinUri());
1548: result.append("commons/explorer.js\"></script>\n");
1549: }
1550: result.append("<script type=\"text/javascript\">\n");
1551: result.append(dialogScriptSubmit());
1552: if (helpUrl != null) {
1553: result.append("if (top.head && top.head.helpUrl) {\n");
1554: result.append("\ttop.head.helpUrl=\"");
1555: result.append(helpUrl + "\";\n");
1556: result.append("}\n\n");
1557: }
1558: // the variable that may be set as path: if non-null this will be
1559: // used as path for the online help window. This is needed because there are pages
1560: // e.g. /administration/accounts/users/new that perform a jsp - forward while leaving the
1561: // path param on the old page: no correct online help possible.
1562: result.append("var onlineHelpUriCustom = ");
1563: result.append(getOnlineHelpUriCustom());
1564: result.append(";\n");
1565:
1566: result.append("</script>\n");
1567: return result.toString();
1568: } else {
1569: return super .pageHtml(segment, null);
1570: }
1571: }
1572:
1573: /**
1574: * Set the custom mapping for the online help. <p>
1575: *
1576: * This value will be set to a javascript variable called onlineHelpUriCustom.
1577: * If it is set, the top.head javascript for the online help will use this value. <p>
1578: *
1579: * This method should be called from <code>{@link #initWorkplaceRequestValues(CmsWorkplaceSettings, HttpServletRequest)}</code>,
1580: * <code>{@link CmsWorkplace#initWorkplaceMembers(CmsJspActionElement)}</code>
1581: * or from the jsp if the dialog class is used for several actions.
1582: * It should be used whenever the online help mapping does not work (due to jsp - forwards).<p>
1583: *
1584: * @param uri the left hand value in mapping.properties for the online help pages
1585: */
1586: public void setOnlineHelpUriCustom(String uri) {
1587:
1588: m_onlineHelpUriCustom = uri;
1589: }
1590:
1591: /**
1592: * Sets the value of the action parameter.<p>
1593: *
1594: * @param value the value to set
1595: */
1596: public void setParamAction(String value) {
1597:
1598: m_paramAction = value;
1599: }
1600:
1601: /**
1602: * Sets the value of the closelink parameter.<p>
1603: *
1604: * @param value the value to set
1605: */
1606: public void setParamCloseLink(String value) {
1607:
1608: // ensure decoded chars are re-encoded again properly
1609:
1610: m_paramCloseLink = value;
1611: }
1612:
1613: /**
1614: * Sets the value of the dialogtype parameter.<p>
1615: *
1616: * @param value the value to set
1617: */
1618: public void setParamDialogtype(String value) {
1619:
1620: m_paramDialogtype = value;
1621: }
1622:
1623: /**
1624: * Sets the value of the frame name parameter.<p>
1625: *
1626: * @param value the value to set
1627: */
1628: public void setParamFramename(String value) {
1629:
1630: m_paramFrameName = value;
1631: }
1632:
1633: /**
1634: * Sets the ispopup parameter.<p>
1635: *
1636: * @param value the ispopup parameter value
1637: */
1638: public void setParamIsPopup(String value) {
1639:
1640: m_paramIsPopup = value;
1641: }
1642:
1643: /**
1644: * Sets the value of the message parameter.<p>
1645: *
1646: * @param value the value to set
1647: */
1648: public void setParamMessage(String value) {
1649:
1650: m_paramMessage = value;
1651: }
1652:
1653: /**
1654: * Sets the value of the originalparams parameter.<p>
1655: *
1656: * @param paramOriginalParams the value of the originalparams parameter
1657: */
1658: public void setParamOriginalParams(String paramOriginalParams) {
1659:
1660: m_paramOriginalParams = paramOriginalParams;
1661: }
1662:
1663: /**
1664: * Sets the value of the preactiondone parameter.<p>
1665: *
1666: * @param paramPreActionDone the value of the preactiondone parameter
1667: */
1668: public void setParamPreActionDone(String paramPreActionDone) {
1669:
1670: m_paramPreActionDone = paramPreActionDone;
1671: }
1672:
1673: /**
1674: * Sets the value of the redirect flag parameter.<p>
1675: *
1676: * @param redirect the value of the redirect flag parameter
1677: */
1678: public void setParamRedirect(String redirect) {
1679:
1680: m_paramRedirect = redirect;
1681: }
1682:
1683: /**
1684: * Sets the value of the file parameter.<p>
1685: *
1686: * @param value the value to set
1687: */
1688: public void setParamResource(String value) {
1689:
1690: m_paramResource = value;
1691: }
1692:
1693: /**
1694: * Sets the value of the title parameter.<p>
1695: *
1696: * @param value the value to set
1697: */
1698: public void setParamTitle(String value) {
1699:
1700: m_paramTitle = value;
1701: }
1702:
1703: /**
1704: * Appends a space char. between tag attribs.<p>
1705: *
1706: * @param attribute a tag attribute
1707: * @return the tag attribute with a leading space char.
1708: */
1709: protected String appendDelimiter(String attribute) {
1710:
1711: if (CmsStringUtil.isNotEmpty(attribute)) {
1712: if (!attribute.startsWith(" ")) {
1713: // add a delimiter space between the beginning button HTML and the button tag attribs
1714: return " " + attribute;
1715: } else {
1716: return attribute;
1717: }
1718: }
1719:
1720: return "";
1721: }
1722:
1723: /**
1724: * Returns ajax wait message.<p>
1725: *
1726: * @return html code
1727: */
1728: protected String buildAjaxWaitMessage() {
1729:
1730: StringBuffer html = new StringBuffer(512);
1731: html
1732: .append("<table border='0' style='vertical-align:middle; height: 150px;'>\n");
1733: html
1734: .append("<tr><td width='40' align='center' valign='middle'><img src='");
1735: html.append(CmsWorkplace.getSkinUri());
1736: html
1737: .append("commons/wait.gif' id='ajaxreport-img' width='32' height='32' alt=''></td>\n");
1738: html
1739: .append("<td valign='middle'><span id='ajaxreport-txt' style='color: #000099; font-weight: bold;'>\n");
1740: html
1741: .append(key(org.opencms.workplace.Messages.GUI_AJAX_REPORT_WAIT_0));
1742: html.append("</span><br></td></tr></table>\n");
1743: return html.toString();
1744: }
1745:
1746: /**
1747: * Checks if the permissions of the current user on the resource to use in the dialog are sufficient.<p>
1748: *
1749: * Automatically generates a CmsMessageContainer object with an error message and stores it in the users session.<p>
1750: *
1751: * @param required the required permissions for the dialog
1752: * @param neededForFolder if true, the permissions are required for the parent folder of the resource (e.g. for editors)
1753: * @return true if the permissions are sufficient, otherwise false
1754: */
1755: protected boolean checkResourcePermissions(
1756: CmsPermissionSet required, boolean neededForFolder) {
1757:
1758: return checkResourcePermissions(required, neededForFolder,
1759: Messages.get().container(
1760: Messages.GUI_ERR_RESOURCE_PERMISSIONS_2,
1761: getParamResource(),
1762: required.getPermissionString()));
1763: }
1764:
1765: /**
1766: * Checks if the permissions of the current user on the resource to use in the dialog are sufficient.<p>
1767: *
1768: * Automatically generates a CmsMessageContainer object with an error message and stores it in the users session.<p>
1769: *
1770: * @param required the required permissions for the dialog
1771: * @param neededForFolder if true, the permissions are required for the parent folder of the resource (e.g. for editors)
1772: * @param errorMessage the message container that is stored in the session in case the permissions are not sufficient
1773: * @return true if the permissions are sufficient, otherwise false
1774: */
1775: protected boolean checkResourcePermissions(
1776: CmsPermissionSet required, boolean neededForFolder,
1777: CmsMessageContainer errorMessage) {
1778:
1779: boolean hasPermissions = false;
1780: try {
1781: CmsResource res;
1782: if (neededForFolder) {
1783: // check permissions for the folder the resource is in
1784: res = getCms()
1785: .readResource(
1786: CmsResource
1787: .getParentFolder(getParamResource()),
1788: CmsResourceFilter.ALL);
1789: } else {
1790: res = getCms().readResource(getParamResource(),
1791: CmsResourceFilter.ALL);
1792: }
1793: hasPermissions = getCms().hasPermissions(res, required,
1794: false, CmsResourceFilter.ALL);
1795: } catch (CmsException e) {
1796: // should usually never happen
1797: if (LOG.isInfoEnabled()) {
1798: LOG.info(e);
1799: }
1800: }
1801:
1802: if (!hasPermissions) {
1803: // store the error message in the users session
1804: getSettings().setErrorMessage(errorMessage);
1805: }
1806:
1807: return hasPermissions;
1808: }
1809:
1810: /**
1811: * Returns the full path of the current workplace folder.<p>
1812: *
1813: * @return the full path of the current workplace folder
1814: */
1815: protected String computeCurrentFolder() {
1816:
1817: String currentFolder = getSettings().getExplorerResource();
1818: if (currentFolder == null) {
1819: // set current folder to root folder
1820: try {
1821: currentFolder = getCms().getSitePath(
1822: getCms().readFolder("/",
1823: CmsResourceFilter.IGNORE_EXPIRATION));
1824: } catch (CmsException e) {
1825: // can usually be ignored
1826: if (LOG.isInfoEnabled()) {
1827: LOG.info(e);
1828: }
1829: currentFolder = "/";
1830: }
1831: }
1832: if (!currentFolder.endsWith("/")) {
1833: // add folder separator to currentFolder
1834: currentFolder += "/";
1835: }
1836: return currentFolder;
1837: }
1838:
1839: /**
1840: * Renders the HTML for a single input button of a specified type.<p>
1841: *
1842: * @param result a string buffer where the rendered HTML gets appended to
1843: * @param button a integer key to identify the button
1844: * @param attribute an optional string with possible tag attributes, or null
1845: */
1846: protected void dialogButtonsHtml(StringBuffer result, int button,
1847: String attribute) {
1848:
1849: attribute = appendDelimiter(attribute);
1850:
1851: switch (button) {
1852: case BUTTON_OK:
1853: result.append("<input name=\"ok\" value=\"");
1854: result.append(key(Messages.GUI_DIALOG_BUTTON_OK_0) + "\"");
1855: if (attribute.toLowerCase().indexOf("onclick") == -1) {
1856: result.append(" type=\"submit\"");
1857: } else {
1858: result.append(" type=\"button\"");
1859: }
1860: result.append(" class=\"dialogbutton\"");
1861: result.append(attribute);
1862: result.append(">\n");
1863: break;
1864: case BUTTON_CANCEL:
1865: result
1866: .append("<input name=\"cancel\" type=\"button\" value=\"");
1867: result.append(key(Messages.GUI_DIALOG_BUTTON_CANCEL_0)
1868: + "\"");
1869: if (attribute.toLowerCase().indexOf("onclick") == -1) {
1870: result.append(" onclick=\"submitAction('"
1871: + DIALOG_CANCEL + "', form);\"");
1872: }
1873: result.append(" class=\"dialogbutton\"");
1874: result.append(attribute);
1875: result.append(">\n");
1876: break;
1877: case BUTTON_EDIT:
1878: result.append("<input name=\"ok\" value=\"");
1879: result
1880: .append(key(Messages.GUI_DIALOG_BUTTON_EDIT_0)
1881: + "\"");
1882: if (attribute.toLowerCase().indexOf("onclick") == -1) {
1883: result.append(" type=\"submit\"");
1884: } else {
1885: result.append(" type=\"button\"");
1886: }
1887: result.append(" class=\"dialogbutton\"");
1888: result.append(attribute);
1889: result.append(">\n");
1890: break;
1891: case BUTTON_DISCARD:
1892: result
1893: .append("<input name=\"cancel\" type=\"button\" value=\"");
1894: result.append(key(Messages.GUI_DIALOG_BUTTON_DISCARD_0)
1895: + "\"");
1896: if (attribute.toLowerCase().indexOf("onclick") == -1) {
1897: result.append(" onclick=\"submitAction('"
1898: + DIALOG_CANCEL + "', form);\"");
1899: }
1900: result.append(" class=\"dialogbutton\"");
1901: result.append(attribute);
1902: result.append(">\n");
1903: break;
1904: case BUTTON_CLOSE:
1905: result
1906: .append("<input name=\"close\" type=\"button\" value=\"");
1907: result.append(key(Messages.GUI_DIALOG_BUTTON_CLOSE_0)
1908: + "\"");
1909: if (attribute.toLowerCase().indexOf("onclick") == -1) {
1910: result.append(" onclick=\"submitAction('"
1911: + DIALOG_CANCEL + "', form);\"");
1912: }
1913: result.append(" class=\"dialogbutton\"");
1914: result.append(attribute);
1915: result.append(">\n");
1916: break;
1917: case BUTTON_ADVANCED:
1918: result
1919: .append("<input name=\"advanced\" type=\"button\" value=\"");
1920: result.append(key(Messages.GUI_DIALOG_BUTTON_ADVANCED_0)
1921: + "\"");
1922: result.append(" class=\"dialogbutton\"");
1923: result.append(attribute);
1924: result.append(">\n");
1925: break;
1926: case BUTTON_SET:
1927: result
1928: .append("<input name=\"set\" type=\"button\" value=\"");
1929: result.append(key(Messages.GUI_DIALOG_BUTTON_SET_0) + "\"");
1930: if (attribute.toLowerCase().indexOf("onclick") == -1) {
1931: result.append(" onclick=\"submitAction('" + DIALOG_SET
1932: + "', form);\"");
1933: }
1934: result.append(" class=\"dialogbutton\"");
1935: result.append(attribute);
1936: result.append(">\n");
1937: break;
1938: case BUTTON_BACK:
1939: result
1940: .append("<input name=\"set\" type=\"button\" value=\"");
1941: result
1942: .append(key(Messages.GUI_DIALOG_BUTTON_BACK_0)
1943: + "\"");
1944: if (attribute.toLowerCase().indexOf("onclick") == -1) {
1945: result.append(" onclick=\"submitAction('" + DIALOG_BACK
1946: + "', form);\"");
1947: }
1948: result.append(" class=\"dialogbutton\"");
1949: result.append(attribute);
1950: result.append(">\n");
1951: break;
1952: case BUTTON_CONTINUE:
1953: result
1954: .append("<input name=\"set\" type=\"button\" value=\"");
1955: result.append(key(Messages.GUI_DIALOG_BUTTON_CONTINUE_0)
1956: + "\"");
1957: if (attribute.toLowerCase().indexOf("onclick") == -1) {
1958: result.append(" onclick=\"submitAction('"
1959: + DIALOG_CONTINUE + "', form);\"");
1960: }
1961: result.append(" class=\"dialogbutton\"");
1962: result.append(attribute);
1963: result.append(">\n");
1964: break;
1965: case BUTTON_DETAILS:
1966: result
1967: .append("<input name=\"details\" type=\"button\" value=\"");
1968: result.append(key(Messages.GUI_DIALOG_BUTTON_DETAIL_0)
1969: + "\"");
1970: result.append(" class=\"dialogbutton\"");
1971: result.append(attribute);
1972: result.append(">\n");
1973: break;
1974: default:
1975: // not a valid button code, just insert a warning in the HTML
1976: result.append("<!-- invalid button code: ");
1977: result.append(button);
1978: result.append(" -->\n");
1979: }
1980: }
1981:
1982: /**
1983: * Returns the link URL to get back one folder in the administration view.<p>
1984: *
1985: * @return the link URL to get back one folder in the administration view
1986: */
1987: protected String getAdministrationBackLink() {
1988:
1989: return CmsWorkplace.VFS_PATH_WORKPLACE
1990: + "action/administration_content_top.html"
1991: + "?sender="
1992: + CmsResource.getParentFolder(getJsp()
1993: .getRequestContext().getFolderUri());
1994: }
1995:
1996: /**
1997: * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
1998: */
1999: protected void initWorkplaceRequestValues(
2000: CmsWorkplaceSettings settings, HttpServletRequest request) {
2001:
2002: fillParamValues(request);
2003: if (DIALOG_CANCEL.equals(getParamAction())) {
2004: setAction(ACTION_CANCEL);
2005: }
2006: }
2007:
2008: /**
2009: * Sets the action value.<p>
2010: *
2011: * @param value the action value
2012: */
2013: protected void setAction(int value) {
2014:
2015: m_action = value;
2016: }
2017: }
|