cmsreport.java

来自「找了很久才找到到源代码」· Java 代码 · 共 585 行 · 第 1/2 页

JAVA
585
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsReport.java,v $
 * Date   : $Date: 2007-08-13 16:30:06 $
 * Version: $Revision: 1.28 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.workplace;

import org.opencms.i18n.CmsMessageContainer;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.report.A_CmsReportThread;
import org.opencms.report.I_CmsReport;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;

import org.apache.commons.logging.Log;

/**
 * Provides an output window for a CmsReport.<p> 
 *
 * @author  Alexander Kandzior 
 * 
 * @version $Revision: 1.28 $ 
 * 
 * @since 6.0.0 
 */
public class CmsReport extends CmsMultiDialog {

    /** Request parameter key for the type of the report. */
    public static final String PARAM_REPORT_CONTINUEKEY = "reportcontinuekey";

    /** Request parameter key for the type of the report. */
    public static final String PARAM_REPORT_TYPE = "reporttype";

    /** Max. byte size of report output on client. */
    public static final int REPORT_UPDATE_SIZE = 512000;

    /** Update time for report reloading. */
    public static final int REPORT_UPDATE_TIME = 2000;

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsReport.class);

    /** Flag for refreching workplace .*/
    private String m_paramRefreshWorkplace;

    /** The key name which contains the localized message for the continue checkbox. */
    private String m_paramReportContinueKey;

    /** The type of this report. */
    private String m_paramReportType;

    /** The thread to display in this report. */
    private CmsUUID m_paramThread;

    /** The next thread to display after this report. */
    private String m_paramThreadHasNext;

    /**
     * Public constructor.<p>
     * 
     * @param jsp an initialized JSP action element
     */
    public CmsReport(CmsJspActionElement jsp) {

        super(jsp);
    }

    /**
     * Public constructor with JSP variables.<p>
     * 
     * @param context the JSP page context
     * @param req the JSP request
     * @param res the JSP response
     */
    public CmsReport(PageContext context, HttpServletRequest req, HttpServletResponse res) {

        this(new CmsJspActionElement(context, req, res));
    }

    /**
     * Returns the style sheets for the report.<p>
     * 
     * @return the style sheets for the report
     */
    public static String generateCssStyle() {

        StringBuffer result = new StringBuffer(128);
        result.append("<style type='text/css'>\n");
        result.append("body       { box-sizing: border-box; -moz-box-sizing: border-box; padding: 2px; margin: 0; color: #000000; background-color:#ffffff; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }\n");
        result.append("div.main   { box-sizing: border-box; -moz-box-sizing: border-box; color: #000000; white-space: nowrap; }\n");
        result.append("span.head  { color: #000099; font-weight: bold; }\n");
        result.append("span.note  { color: #666666; }\n");
        result.append("span.ok    { color: #009900; }\n");
        result.append("span.warn  { color: #990000; padding-left: 40px; }\n");
        result.append("span.err   { color: #990000; font-weight: bold; padding-left: 40px; }\n");
        result.append("span.throw { color: #990000; font-weight: bold; }\n");
        result.append("span.link1 { color: #666666; }\n");
        result.append("span.link2 { color: #666666; padding-left: 40px; }\n");
        result.append("span.link2 { color: #990000; }\n");
        result.append("</style>\n");
        return result.toString();
    }

    /**
     * Generates the footer for the extended report view.<p>
     * 
     * @return html code
     */
    public static String generatePageEndExtended() {

        StringBuffer result = new StringBuffer(128);
        result.append("</div>\n");
        result.append("</body>\n");
        result.append("</html>\n");
        return result.toString();
    }

    /**
     * Generates the footer for the simple report view.<p>
     * 
     * @return html code
     */
    public static String generatePageEndSimple() {

        StringBuffer result = new StringBuffer(128);
        result.append("</td></tr>\n");
        result.append("</table></div>\n");
        result.append("</body>\n</html>");
        return result.toString();
    }

    /**
     * Generates the header for the extended report view.<p>
     * 
     * @param encoding the encoding string
     * 
     * @return html code
     */
    public static String generatePageStartExtended(String encoding) {

        StringBuffer result = new StringBuffer(128);
        result.append("<html>\n<head>\n");
        result.append("<meta HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=");
        result.append(encoding);
        result.append("'>\n");
        result.append(generateCssStyle());
        result.append("</head>\n");
        result.append("<body style='overflow: auto;'>\n");
        result.append("<div class='main'>\n");
        return result.toString();
    }

    /**
     * Generates the header for the simple report view.<p>
     * 
     * @param wp the workplace instance
     * 
     * @return html code
     */
    public static String generatePageStartSimple(CmsWorkplace wp) {

        StringBuffer result = new StringBuffer(128);
        result.append("<html>\n<head>\n");
        result.append("<meta HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=");
        result.append(wp.getEncoding());
        result.append("'>\n");
        result.append("<link rel='stylesheet' type='text/css' href='");
        result.append(wp.getStyleUri("workplace.css"));
        result.append("'>\n");
        result.append(generateCssStyle());
        result.append("</head>\n");
        result.append("<body style='background-color:Menu;'>\n");
        result.append("<div style='vertical-align:middle; height: 100%;'>\n");
        result.append("<table border='0' style='vertical-align:middle; height: 100%;'>\n");
        result.append("<tr><td width='40' align='center' valign='middle'><img name='report_img' src='");
        result.append(CmsWorkplace.getSkinUri());
        result.append("commons/wait.gif' width='32' height='32' alt=''></td>\n");
        result.append("<td valign='middle'>");
        return result.toString();
    }

    /**
     * Returns an initialized CmsReport instance that is read from the request attributes.<p>
     * 
     * This method is used by dialog elements. 
     * The dialog elements do not initialize their own workplace class, 
     * but use the initialized instance of the "master" class.
     * This is required to ensure that parameters of the "master" class
     * can properly be kept on the dialog elements.<p>
     * 
     * To prevent null pointer exceptions, an empty dialog is returned if 
     * nothing is found in the request attributes.<p>
     *  
     * @param context the JSP page context
     * @param req the JSP request
     * @param res the JSP response
     * @return an initialized CmsDialog instance that is read from the request attributes
     */
    public static CmsReport initCmsReport(PageContext context, HttpServletRequest req, HttpServletResponse res) {

        CmsReport wp = (CmsReport)req.getAttribute(CmsWorkplace.SESSION_WORKPLACE_CLASS);
        if (wp == null) {
            // ensure that we don't get null pointers if the page is directly called
            wp = new CmsReport(new CmsJspActionElement(context, req, res));
        }
        return wp;
    }

    /**
     * Builds a button row with an "Ok", a "Cancel" and a "Details" button.<p>
     * 
     * This row is displayed when the first report is running.<p>
     * 
     * @param okAttrs optional attributes for the ok button
     * @param cancelAttrs optional attributes for the cancel button
     * @param detailsAttrs optional attributes for the details button
     * @return the button row
     */
    public String dialogButtonsContinue(String okAttrs, String cancelAttrs, String detailsAttrs) {

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(detailsAttrs)) {
            detailsAttrs = "";
        } else {
            detailsAttrs += " ";
        }
        return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL, BUTTON_DETAILS}, new String[] {
            okAttrs,
            cancelAttrs,
            detailsAttrs + "onclick=\"switchOutputFormat();\""});
    }

    /**
     * Builds a button row with an "Ok", a "Cancel" and a "Details" button.<p>
     * 
     * This row is used when a single report is running or after the first report has finished.<p>
     * 
     * @param okAttrs optional attributes for the ok button
     * @param cancelAttrs optional attributes for the cancel button
     * @param detailsAttrs optional attributes for the details button
     * @return the button row
     */
    public String dialogButtonsOkCancelDetails(String okAttrs, String cancelAttrs, String detailsAttrs) {

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(detailsAttrs)) {
            detailsAttrs = "";
        } else {
            detailsAttrs += " ";
        }

        if (Boolean.valueOf(getParamThreadHasNext()).booleanValue()
            && CmsStringUtil.isNotEmpty(getParamReportContinueKey())) {
            return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL, BUTTON_DETAILS}, new String[] {
                okAttrs,
                cancelAttrs,
                detailsAttrs + "onclick=\"switchOutputFormat();\""});
        }
        return dialogButtons(new int[] {BUTTON_OK, BUTTON_DETAILS}, new String[] {
            okAttrs,
            detailsAttrs + "onclick=\"switchOutputFormat();\""});
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?