All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.workplace.CmsReport Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (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 & Co. KG, 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.file.CmsObject;
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.

* * @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.

* * @param jsp an initialized JSP action element */ public CmsReport(CmsJspActionElement jsp) { super(jsp); } /** * Public constructor with JSP variables.

* * @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.

* * @param cms the current users context * @return the style sheets for the report */ public static String generateCssStyle(CmsObject cms) { StringBuffer result = new StringBuffer(128); result.append("\n"); return result.toString(); } /** * Generates the footer for the extended report view.

* * @return html code */ public static String generatePageEndExtended() { StringBuffer result = new StringBuffer(128); result.append("

\n"); result.append("\n"); result.append("\n"); return result.toString(); } /** * Generates the footer for the simple report view.

* * @return html code */ public static String generatePageEndSimple() { StringBuffer result = new StringBuffer(128); result.append("\n"); result.append("

\n"); result.append("\n"); return result.toString(); } /** * Generates the header for the extended report view.

* * @param cms the current users context * @param encoding the encoding string * * @return html code */ public static String generatePageStartExtended(CmsObject cms, String encoding) { StringBuffer result = new StringBuffer(128); result.append("\n\n"); result.append("\n"); result.append(generateCssStyle(cms)); result.append("\n"); result.append("\n"); result.append("

\n"); return result.toString(); } /** * Generates the header for the simple report view.

* * @param wp the workplace instance * * @return html code */ public static String generatePageStartSimple(CmsWorkplace wp) { StringBuffer result = new StringBuffer(128); result.append("\n\n"); result.append("\n"); result.append("\n"); result.append(generateCssStyle(wp.getCms())); result.append("\n"); result.append("\n"); result.append("

\n"); result.append("\n"); result.append("\n"); result.append("
"); return result.toString(); } /** * Returns an initialized CmsReport instance that is read from the request attributes.

* * 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.

* * To prevent null pointer exceptions, an empty dialog is returned if * nothing is found in the request attributes.

* * @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.

* * This row is displayed when the first report is running.

* * @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.

* * This row is used when a single report is running or after the first report has finished.

* * @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();\""}); } /** * Returns if the workplace must be refreshed.

* * @return "true" if the workplace must be refreshed. */ public String getParamRefreshWorkplace() { return m_paramRefreshWorkplace; } /** * Returns the key name which contains the localized message for the continue checkbox.

* * @return the key name which contains the localized message for the continue checkbox */ public String getParamReportContinueKey() { if (m_paramReportContinueKey == null) { m_paramReportContinueKey = ""; } return m_paramReportContinueKey; } /** * Returns the type of this report.

* * @return the type of this report */ public String getParamReportType() { if (m_paramReportType == null) { // the default report type is the simple report setParamReportType(getSettings().getUserSettings().getWorkplaceReportType()); } return m_paramReportType; } /** * Returns the Thread id to display in this report.

* * @return the Thread id to display in this report */ public String getParamThread() { if ((m_paramThread != null) && (!m_paramThread.equals(CmsUUID.getNullUUID()))) { return m_paramThread.toString(); } else { return null; } } /** * Returns if another report is following this report.

* * @return "true" if another report is following this report */ public String getParamThreadHasNext() { if (m_paramThreadHasNext == null) { m_paramThreadHasNext = ""; } return m_paramThreadHasNext; } /** * Returns the part of the report that is ready for output.

* * @return the part of the report that is ready for output */ public String getReportUpdate() { A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); if (thread != null) { return thread.getReportUpdate(); } else { return ""; } } /** * Returns if the report generated an error output.

* * @return true if the report generated an error, otherwise false */ public boolean hasError() { A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); if (thread != null) { return thread.hasError(); } else { return false; } } /** * Builds the start html of the page, including setting of DOCTYPE and * inserting a header with the content-type.

* * This overloads the default method of the parent class.

* * @return the start html of the page */ @Override public String htmlStart() { return pageHtml(HTML_START, true); } /** * Builds the start html of the page, including setting of DOCTYPE and * inserting a header with the content-type.

* * This overloads the default method of the parent class.

* * @param loadStyles if true, the defaul style sheet will be loaded * @return the start html of the page */ public String htmlStart(boolean loadStyles) { return pageHtml(HTML_START, loadStyles); } /** * Returns true if the report Thread is still alive (i.e. running), false otherwise.

* * @return true if the report Thread is still alive */ public boolean isAlive() { A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); if (thread != null) { return thread.isAlive(); } else { return false; } } /** * Checks whether this is a simple report.

* * @return true, if the type of this report is a "simple" */ public boolean isSimpleReport() { return getParamReportType().equalsIgnoreCase(I_CmsReport.REPORT_TYPE_SIMPLE); } /** * Builds the start html of the page, including setting of DOCTYPE and * inserting a header with the content-type.

* * This overloads the default method of the parent class.

* * @param segment the HTML segment (START / END) * @param loadStyles if true, the defaul style sheet will be loaded * @return the start html of the page */ public String pageHtml(int segment, boolean loadStyles) { if (useNewStyle()) { return super.pageHtml(segment, null, getParamTitle()); } if (segment == HTML_START) { StringBuffer result = new StringBuffer(512); result.append("\n"); result.append("\n\n"); result.append("\n"); if (loadStyles) { result.append("\n"); result.append("\n"); } return result.toString(); } else { return ""; } } /** * Returns an optional conclusion text to be displayed below the report output.

* * @return an optional conclusion text */ public String reportConclusionText() { return ""; } /** * Returns an optional introduction text to be displayed above the report output.

* * @return an optional introduction text */ public String reportIntroductionText() { return ""; } /** * Sets if the workplace must be refreshed.

* * @param value "true" (String) if the workplace must be refreshed. */ public void setParamRefreshWorkplace(String value) { m_paramRefreshWorkplace = value; } /** * Sets the key name which contains the localized message for the continue checkbox.

* * @param key the key name which contains the localized message for the continue checkbox */ public void setParamReportContinueKey(String key) { m_paramReportContinueKey = key; } /** * Sets the type of this report.

* * @param value the type of this report */ public void setParamReportType(String value) { m_paramReportType = value; } /** * Sets the Thread id to display in this report.

* * @param value the Thread id to display in this report */ public void setParamThread(String value) { m_paramThread = CmsUUID.getNullUUID(); if (value != null) { try { m_paramThread = new CmsUUID(value); } catch (Exception e) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key(Messages.LOG_THREAD_CREATION_FAILED_1, new Integer(value)), e); } } } } /** * Sets if another report is following this report.

* * @param value "true" if another report is following this report */ public void setParamThreadHasNext(String value) { m_paramThreadHasNext = value; } /** * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest) */ @Override protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { // fill the parameter values in the get/set methods fillParamValues(request); // set the action for the JSP switch if (REPORT_UPDATE.equals(getParamAction())) { setAction(ACTION_REPORT_UPDATE); } else { setAction(ACTION_REPORT_BEGIN); } } /** * Returns always true and does nothing else, has to be implemented.

* * @see org.opencms.workplace.CmsMultiDialog#performDialogOperation() */ @Override protected boolean performDialogOperation() throws CmsException { throw new CmsException(new CmsMessageContainer(null, "")); } }