1 31 32 package org.opencms.workplace; 33 34 import org.opencms.jsp.CmsJspActionElement; 35 import org.opencms.main.CmsLog; 36 import org.opencms.main.OpenCms; 37 import org.opencms.report.A_CmsReportThread; 38 import org.opencms.report.I_CmsReport; 39 import org.opencms.util.CmsStringUtil; 40 import org.opencms.util.CmsUUID; 41 42 import javax.servlet.http.HttpServletRequest ; 43 import javax.servlet.http.HttpServletResponse ; 44 import javax.servlet.jsp.PageContext ; 45 46 import org.apache.commons.logging.Log; 47 48 57 public class CmsReport extends CmsMultiDialog { 58 59 60 public static final String PARAM_REPORT_CONTINUEKEY = "reportcontinuekey"; 61 62 63 public static final String PARAM_REPORT_TYPE = "reporttype"; 64 65 66 public static final int REPORT_UPDATE_SIZE = 512000; 67 68 69 public static final int REPORT_UPDATE_TIME = 2000; 70 71 72 private static final Log LOG = CmsLog.getLog(CmsReport.class); 73 74 75 private String m_paramRefreshWorkplace; 76 77 78 private String m_paramReportContinueKey; 79 80 81 private String m_paramReportType; 82 83 84 private CmsUUID m_paramThread; 85 86 87 private String m_paramThreadHasNext; 88 89 94 public CmsReport(CmsJspActionElement jsp) { 95 96 super(jsp); 97 } 98 99 106 public CmsReport(PageContext context, HttpServletRequest req, HttpServletResponse res) { 107 108 this(new CmsJspActionElement(context, req, res)); 109 } 110 111 128 public static CmsReport initCmsReport(PageContext context, HttpServletRequest req, HttpServletResponse res) { 129 130 CmsReport wp = (CmsReport)req.getAttribute(CmsWorkplace.SESSION_WORKPLACE_CLASS); 131 if (wp == null) { 132 wp = new CmsReport(new CmsJspActionElement(context, req, res)); 134 } 135 return wp; 136 } 137 138 148 public String dialogButtonsContinue(String okAttrs, String cancelAttrs, String detailsAttrs) { 149 150 if (CmsStringUtil.isEmptyOrWhitespaceOnly(detailsAttrs)) { 151 detailsAttrs = ""; 152 } else { 153 detailsAttrs += " "; 154 } 155 return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL, BUTTON_DETAILS}, new String [] { 156 okAttrs, 157 cancelAttrs, 158 detailsAttrs + "onclick=\"switchOutputFormat();\""}); 159 } 160 161 171 public String dialogButtonsOkCancelDetails(String okAttrs, String cancelAttrs, String detailsAttrs) { 172 173 if (CmsStringUtil.isEmptyOrWhitespaceOnly(detailsAttrs)) { 174 detailsAttrs = ""; 175 } else { 176 detailsAttrs += " "; 177 } 178 179 if (Boolean.valueOf(getParamThreadHasNext()).booleanValue() 180 && CmsStringUtil.isNotEmpty(getParamReportContinueKey())) { 181 return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL, BUTTON_DETAILS}, new String [] { 182 okAttrs, 183 cancelAttrs, 184 detailsAttrs + "onclick=\"switchOutputFormat();\""}); 185 } 186 return dialogButtons(new int[] {BUTTON_OK, BUTTON_DETAILS}, new String [] { 187 okAttrs, 188 detailsAttrs + "onclick=\"switchOutputFormat();\""}); 189 } 190 191 196 public String getParamRefreshWorkplace() { 197 198 return m_paramRefreshWorkplace; 199 } 200 201 206 public String getParamReportContinueKey() { 207 208 if (m_paramReportContinueKey == null) { 209 m_paramReportContinueKey = ""; 210 } 211 return m_paramReportContinueKey; 212 } 213 214 219 public String getParamReportType() { 220 221 if (m_paramReportType == null) { 222 setParamReportType(getSettings().getUserSettings().getWorkplaceReportType()); 224 } 225 226 return m_paramReportType; 227 } 228 229 234 public String getParamThread() { 235 236 if ((m_paramThread != null) && (!m_paramThread.equals(CmsUUID.getNullUUID()))) { 237 return m_paramThread.toString(); 238 } else { 239 return null; 240 } 241 } 242 243 248 public String getParamThreadHasNext() { 249 250 if (m_paramThreadHasNext == null) { 251 m_paramThreadHasNext = ""; 252 } 253 return m_paramThreadHasNext; 254 } 255 256 261 public String getReportUpdate() { 262 263 A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); 264 if (thread != null) { 265 return thread.getReportUpdate(); 266 } else { 267 return ""; 268 } 269 } 270 271 276 public boolean hasError() { 277 278 A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); 279 if (thread != null) { 280 return thread.hasError(); 281 } else { 282 return false; 283 } 284 } 285 286 294 public String htmlStart() { 295 296 return pageHtml(HTML_START, true); 297 } 298 299 308 public String htmlStart(boolean loadStyles) { 309 310 return pageHtml(HTML_START, loadStyles); 311 } 312 313 318 public boolean isAlive() { 319 320 A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); 321 if (thread != null) { 322 return thread.isAlive(); 323 } else { 324 return false; 325 } 326 } 327 328 333 public boolean isSimpleReport() { 334 335 return getParamReportType().equalsIgnoreCase(I_CmsReport.REPORT_TYPE_SIMPLE); 336 } 337 338 348 public String pageHtml(int segment, boolean loadStyles) { 349 350 if (useNewStyle()) { 351 return super.pageHtml(segment, null, getParamTitle()); 352 } 353 if (segment == HTML_START) { 354 StringBuffer result = new StringBuffer (512); 355 result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n"); 356 result.append("<html>\n<head>\n"); 357 result.append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset="); 358 result.append(getEncoding()); 359 result.append("\">\n"); 360 if (loadStyles) { 361 result.append("<link rel=\"stylesheet\" type=\"text/css\" HREF=\""); 362 result.append(getStyleUri(getJsp(), "workplace.css")); 363 result.append("\">\n"); 364 result.append("<script type=\"text/javascript\">\n"); 365 result.append(dialogScriptSubmit()); 366 result.append("</script>\n"); 367 } 368 return result.toString(); 369 } else { 370 return "</html>"; 371 } 372 373 } 374 375 380 public void setParamRefreshWorkplace(String value) { 381 382 m_paramRefreshWorkplace = value; 383 } 384 385 390 public void setParamReportContinueKey(String key) { 391 392 m_paramReportContinueKey = key; 393 } 394 395 400 public void setParamReportType(String value) { 401 402 m_paramReportType = value; 403 } 404 405 410 public void setParamThread(String value) { 411 412 m_paramThread = CmsUUID.getNullUUID(); 413 if (value != null) { 414 try { 415 m_paramThread = new CmsUUID(value); 416 } catch (Exception e) { 417 if (LOG.isInfoEnabled()) { 419 LOG.info( 420 Messages.get().getBundle().key(Messages.LOG_THREAD_CREATION_FAILED_1, new Integer (value)), 421 e); 422 } 423 } 424 } 425 } 426 427 432 public void setParamThreadHasNext(String value) { 433 434 m_paramThreadHasNext = value; 435 } 436 437 440 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 441 442 fillParamValues(request); 444 if (REPORT_UPDATE.equals(getParamAction())) { 446 setAction(ACTION_REPORT_UPDATE); 447 } else { 448 setAction(ACTION_REPORT_BEGIN); 449 } 450 } 451 452 457 protected boolean performDialogOperation() { 458 459 return true; 461 } 462 463 }
| Popular Tags
|