001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.tools.workplace.rfsfile; 029 030import org.opencms.jsp.CmsJspActionElement; 031 032import java.io.IOException; 033import java.util.LinkedList; 034import java.util.List; 035 036import javax.servlet.ServletException; 037import javax.servlet.http.HttpServletRequest; 038import javax.servlet.http.HttpServletResponse; 039import javax.servlet.jsp.JspException; 040import javax.servlet.jsp.JspWriter; 041import javax.servlet.jsp.PageContext; 042 043/** 044 * Displays a certain amount of lines starting from a certain starting line 045 * which are specified in the <code>{@link org.opencms.workplace.CmsWorkplaceManager}'s</code> 046 * <code>{@link org.opencms.util.CmsRfsFileViewer}</code>.<p> 047 * 048 * @since 6.0.0 049 */ 050public class CmsRfsFileViewDialog extends A_CmsRfsFileWidgetDialog { 051 052 /** 053 * Boolean request parameter that switches between serving the content of the file 054 * to the iframe of the page that is generated if the switch is false. <p> 055 */ 056 String m_paramShowlog; 057 058 /** 059 * Public constructor with JSP action element.<p> 060 * 061 * @param jsp the CmsJspActionElement 062 */ 063 public CmsRfsFileViewDialog(CmsJspActionElement jsp) { 064 065 super(jsp); 066 067 } 068 069 /** 070 * Public constructor with JSP variables.<p> 071 * 072 * @param context the JSP page context 073 * @param req the JSP request 074 * @param res the JSP response 075 */ 076 public CmsRfsFileViewDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 077 078 this(new CmsJspActionElement(context, req, res)); 079 } 080 081 /** 082 * @see org.opencms.workplace.CmsWidgetDialog#displayDialog() 083 */ 084 @Override 085 public void displayDialog() throws JspException, IOException, ServletException { 086 087 if (!Boolean.valueOf(getParamShowlog()).booleanValue()) { 088 super.displayDialog(); 089 } else { 090 StringBuffer result = new StringBuffer(1024); 091 // wrap a box with scrollbars around the file content: 092 try { 093 result.append("<pre>"); 094 result.append(m_logView.readFilePortion()); 095 result.append("</pre>"); 096 } catch (Throwable f) { 097 List<Throwable> commitErrors = getCommitErrors(); 098 if (commitErrors == null) { 099 commitErrors = new LinkedList<Throwable>(); 100 } 101 commitErrors.add(f); 102 setCommitErrors(commitErrors); 103 } 104 JspWriter out = getJsp().getJspContext().getOut(); 105 out.print(result.toString()); 106 } 107 } 108 109 /** 110 * Returns true whether the content of the file should be written to the response or false 111 * if the page content should be generated.<p> 112 * 113 * @return true whether the content of the file should be written to the response or false 114 * if the page content should be generated 115 */ 116 public String getParamShowlog() { 117 118 return m_paramShowlog; 119 } 120 121 /** 122 * Set the value to decide whether page content or the file content has to be shown to the response.<p> 123 * 124 * @param value the value to decide whether page content or the file content has to be shown to the response to set 125 */ 126 public void setParamShowlog(String value) { 127 128 m_paramShowlog = value; 129 } 130 131 /** 132 * Returns the dialog HTML for all defined widgets of the named dialog (page).<p> 133 * 134 * This overwrites the method from the super class to create a layout variation for the widgets.<p> 135 * 136 * @param dialog the dialog (page) to get the HTML for 137 * @return dialog HTML for all defined widgets of the named dialog (page) 138 */ 139 @Override 140 protected String createDialogHtml(String dialog) { 141 142 StringBuffer result = new StringBuffer(1024); 143 144 // create widget table 145 result.append(createWidgetTableStart()); 146 147 // show error header once if there were validation errors 148 result.append(createWidgetErrorHeader()); 149 150 String fileContentHeader; 151 if (m_logView.getFilePath() == null) { 152 fileContentHeader = key(Messages.GUI_WORKPLACE_LOGVIEW_NO_FILE_SELECTED_0); 153 } else { 154 fileContentHeader = m_logView.getFilePath().replace('\\', '/'); 155 } 156 result.append(createWidgetBlockStart(fileContentHeader)); 157 result.append("<iframe style=\"overflow: auto;\" src=\""); 158 result.append(getJsp().link("/system/workplace/admin/workplace/logfileview/index.jsp?showlog=true")); 159 result.append("\" width=\"100%\" height=\"400\" border=\"0\" frameborder=\"0\"></iframe>"); 160 result.append(createWidgetBlockEnd()); 161 162 // result.append(createFileContentBoxEnd()); 163 // close widget table 164 165 result.append(createWidgetTableEnd()); 166 return result.toString(); 167 } 168 169 /** 170 * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets() 171 */ 172 @Override 173 protected void defineWidgets() { 174 175 super.defineWidgets(); 176 // no widgets as controls on the front page are just links to "Edit Settings" 177 } 178}