1 31 32 package org.opencms.workplace.tools.workplace.rfsfile; 33 34 import org.opencms.configuration.CmsWorkplaceConfiguration; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.main.CmsSystemInfo; 37 import org.opencms.main.OpenCms; 38 import org.opencms.util.CmsStringUtil; 39 import org.opencms.widgets.CmsCheckboxWidget; 40 import org.opencms.widgets.CmsComboWidget; 41 import org.opencms.widgets.CmsSelectWidgetOption; 42 import org.opencms.workplace.CmsWidgetDialogParameter; 43 44 import java.io.ByteArrayOutputStream ; 45 import java.io.File ; 46 import java.io.OutputStreamWriter ; 47 import java.nio.charset.Charset ; 48 import java.util.ArrayList ; 49 import java.util.Iterator ; 50 import java.util.LinkedList ; 51 import java.util.List ; 52 import java.util.SortedMap ; 53 54 import javax.servlet.http.HttpServletRequest ; 55 import javax.servlet.http.HttpServletResponse ; 56 import javax.servlet.jsp.PageContext ; 57 58 69 public class CmsRfsFileViewSettingsDialog extends A_CmsRfsFileWidgetDialog { 70 71 72 public static final String KEY_PREFIX = "logfile"; 73 74 77 public CmsRfsFileViewSettingsDialog(CmsJspActionElement jsp) { 78 79 super(jsp); 80 } 81 82 89 public CmsRfsFileViewSettingsDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 90 91 this(new CmsJspActionElement(context, req, res)); 92 } 93 94 100 public void actionCommit() { 101 102 List errors = new ArrayList (); 103 104 try { 105 OpenCms.getWorkplaceManager().setFileViewSettings(getCms(), m_logView); 107 OpenCms.writeConfiguration(CmsWorkplaceConfiguration.class); 109 setDialogObject(null); 110 } catch (Throwable t) { 111 errors.add(t); 112 } 113 114 setCommitErrors(errors); 116 } 117 118 126 protected String createDialogHtml(String dialog) { 127 128 StringBuffer result = new StringBuffer (1024); 129 130 result.append(createWidgetTableStart()); 132 133 result.append(createWidgetErrorHeader()); 135 136 result.append(dialogBlockStart(key(Messages.GUI_WORKPLACE_LOGVIEW_SETTINGS_NAME_0))); 138 result.append(createWidgetTableStart()); 139 result.append(createDialogRowsHtml(0, 4)); 140 result.append(createWidgetTableEnd()); 141 result.append(dialogBlockEnd()); 142 143 result.append(createWidgetTableEnd()); 144 145 return result.toString(); 146 147 } 148 149 152 protected void defineWidgets() { 153 154 setKeyPrefix(KEY_PREFIX); 155 super.defineWidgets(); 156 addWidget(new CmsWidgetDialogParameter(m_logView, "isLogfile", "page1", new CmsCheckboxWidget( 157 CmsStringUtil.TRUE))); 158 addWidget(new CmsWidgetDialogParameter(m_logView, "filePath", "page1", new CmsComboWidget( 159 createComboConfigurationFileChoice()))); 160 161 List comboOptions = new LinkedList (); 163 comboOptions.add(new CmsSelectWidgetOption("100")); 164 comboOptions.add(new CmsSelectWidgetOption("200")); 165 comboOptions.add(new CmsSelectWidgetOption("400")); 166 comboOptions.add(new CmsSelectWidgetOption("600")); 167 comboOptions.add(new CmsSelectWidgetOption("800")); 168 addWidget(new CmsWidgetDialogParameter(m_logView, "windowSize", "page1", new CmsComboWidget(comboOptions))); 169 170 addWidget(new CmsWidgetDialogParameter(m_logView, "fileEncoding", "page1", new CmsComboWidget( 172 createComboConfigurationEncodingChoice()))); 173 174 addWidget(new CmsWidgetDialogParameter(m_logView, "enabled", "page1", new CmsCheckboxWidget())); 175 176 } 177 178 187 private List createComboConfigurationEncodingChoice() { 188 189 List result = new LinkedList (); 190 SortedMap csMap = Charset.availableCharsets(); 191 Charset defaultCs = Charset.forName(new OutputStreamWriter (new ByteArrayOutputStream ()).getEncoding()); 194 Charset cs; 195 Iterator it = csMap.values().iterator(); 196 while (it.hasNext()) { 197 cs = (Charset )it.next(); 198 if (cs == defaultCs) { 200 result.add(new CmsSelectWidgetOption( 201 cs.name(), 202 true, 203 null, 204 key(Messages.GUI_WORKPLACE_LOGVIEW_FILE_CHARSET_DEF_HELP_0))); 205 } else { 206 if (!cs.name().startsWith("x")) { 207 result.add(new CmsSelectWidgetOption( 208 cs.name(), 209 false, 210 null, 211 key(Messages.GUI_WORKPLACE_LOGVIEW_FILE_CHARSET_HELP_0))); 212 } 213 } 214 } 215 216 return result; 217 218 } 219 220 228 private List createComboConfigurationFileChoice() { 229 230 List result = new LinkedList (); 231 CmsSystemInfo sysInfo = OpenCms.getSystemInfo(); 232 result.add(new CmsSelectWidgetOption( 234 sysInfo.getLogFileRfsPath(), 235 true, 236 null, 237 key(Messages.GUI_WORKPLACE_LOGVIEW_FILE_LOG_HELP_0))); 238 result.add(new CmsSelectWidgetOption( 240 sysInfo.getConfigurationFileRfsPath(), 241 false, 242 null, 243 key(Messages.GUI_WORKPLACE_LOGVIEW_FILE_CONF_HELP_0))); 244 String configPath = sysInfo.getAbsoluteRfsPathRelativeToWebInf(CmsSystemInfo.FOLDER_CONFIG); 246 if (configPath != null) { 247 File configFolder = new File (configPath); 248 File [] configFiles = configFolder.listFiles(); 249 File configFile; 250 for (int i = 0; i < configFiles.length; i++) { 251 configFile = configFiles[i]; 252 if (configFile.isFile()) { 253 if (configFile.getName().endsWith(".xml")) { 254 result.add(new CmsSelectWidgetOption( 255 configFile.getAbsolutePath(), 256 false, 257 null, 258 key(Messages.GUI_WORKPLACE_LOGVIEW_FILE_XMLCONF_HELP_0))); 259 } 260 } 261 } 262 } 263 return result; 264 } 265 } | Popular Tags |