KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > workplace > rfsfile > CmsRfsFileViewSettingsDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/rfsfile/CmsRfsFileViewSettingsDialog.java,v $
3  * Date : $Date: 2006/03/27 14:52:59 $
4  * Version: $Revision: 1.10 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

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 JavaDoc;
45 import java.io.File JavaDoc;
46 import java.io.OutputStreamWriter JavaDoc;
47 import java.nio.charset.Charset JavaDoc;
48 import java.util.ArrayList JavaDoc;
49 import java.util.Iterator JavaDoc;
50 import java.util.LinkedList JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.SortedMap JavaDoc;
53
54 import javax.servlet.http.HttpServletRequest JavaDoc;
55 import javax.servlet.http.HttpServletResponse JavaDoc;
56 import javax.servlet.jsp.PageContext JavaDoc;
57
58 /**
59  * A <code>{@link org.opencms.workplace.CmsWidgetDialog}</code> that allows
60  * modification of the properties of the
61  * <code>{@link org.opencms.util.CmsRfsFileViewer}</code> bean.<p>
62  *
63  * @author Achim Westermann
64  *
65  * @version $Revision: 1.10 $
66  *
67  * @since 6.0.0
68  */

69 public class CmsRfsFileViewSettingsDialog extends A_CmsRfsFileWidgetDialog {
70
71     /** localized messages Keys prefix. */
72     public static final String JavaDoc KEY_PREFIX = "logfile";
73
74     /**
75      * @param jsp the CmsJspActionElement.
76      */

77     public CmsRfsFileViewSettingsDialog(CmsJspActionElement jsp) {
78
79         super(jsp);
80     }
81
82     /**
83      * Public constructor with JSP variables.<p>
84      *
85      * @param context the JSP page context
86      * @param req the JSP request
87      * @param res the JSP response
88      */

89     public CmsRfsFileViewSettingsDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
90
91         this(new CmsJspActionElement(context, req, res));
92     }
93
94     /**
95      * Commits the <code>{@link org.opencms.util.CmsRfsFileViewer}</code> to the
96      * <code>{@link org.opencms.workplace.CmsWorkplaceManager}</code>. <p>
97      *
98      * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
99      */

100     public void actionCommit() {
101
102         List JavaDoc errors = new ArrayList JavaDoc();
103
104         try {
105             // set the edited settings
106
OpenCms.getWorkplaceManager().setFileViewSettings(getCms(), m_logView);
107             // write the configuration
108
OpenCms.writeConfiguration(CmsWorkplaceConfiguration.class);
109             setDialogObject(null);
110         } catch (Throwable JavaDoc t) {
111             errors.add(t);
112         }
113
114         // set the list of errors to display when saving failed
115
setCommitErrors(errors);
116     }
117
118     /**
119      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
120      *
121      * This overwrites the method from the super class to create a layout variation for the widgets.<p>
122      *
123      * @param dialog the dialog (page) to get the HTML for
124      * @return the dialog HTML for all defined widgets of the named dialog (page)
125      */

126     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
127
128         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
129
130         // create widget table
131
result.append(createWidgetTableStart());
132
133         // show error header once if there were validation errors
134
result.append(createWidgetErrorHeader());
135
136         // create the widgets for the settings page
137
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     /**
150      * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
151      */

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         // options for windowsize combowidget:
162
List JavaDoc comboOptions = new LinkedList JavaDoc();
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         // file encoding combowidget;
171
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     /**
179      * Returns a list of <code>{@link org.opencms.widgets.CmsSelectWidgetOption}</code> instances for the
180      * <code>{@link CmsComboWidget}</code> with the supported encodings of the
181      * current system and the default encoding set as default combo option.<p>
182      *
183      * @return a list of <code>{@link org.opencms.widgets.CmsSelectWidgetOption}</code> instances for the
184      * <code>{@link CmsComboWidget}</code> with the supported encodings of the
185      * current system and the default encoding set as default combo option.<p>
186      */

187     private List JavaDoc createComboConfigurationEncodingChoice() {
188
189         List JavaDoc result = new LinkedList JavaDoc();
190         SortedMap JavaDoc csMap = Charset.availableCharsets();
191         // default charset: see http://java.sun.com/j2se/corejava/intl/reference/faqs/index.html#default-encoding
192
// before java 1.5 there is no other way (System property "file.encoding" is implementation detail not in vmspec.
193
Charset JavaDoc defaultCs = Charset.forName(new OutputStreamWriter JavaDoc(new ByteArrayOutputStream JavaDoc()).getEncoding());
194         Charset JavaDoc cs;
195         Iterator JavaDoc it = csMap.values().iterator();
196         while (it.hasNext()) {
197             cs = (Charset JavaDoc)it.next();
198             // default? no equals required: safety by design!
199
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     /**
221      * Returns a list of <code>{@link org.opencms.widgets.CmsSelectWidgetOption}</code> instances for the
222      * <code>{@link CmsComboWidget}</code> with default file locations of OpenCms.<p>
223      *
224      * @return a list of <code>{@link org.opencms.widgets.CmsSelectWidgetOption}</code> instances for the
225      * <code>{@link CmsComboWidget}</code> with default file locations of OpenCms
226      *
227      */

228     private List JavaDoc createComboConfigurationFileChoice() {
229
230         List JavaDoc result = new LinkedList JavaDoc();
231         CmsSystemInfo sysInfo = OpenCms.getSystemInfo();
232         // log file, default
233
result.add(new CmsSelectWidgetOption(
234             sysInfo.getLogFileRfsPath(),
235             true,
236             null,
237             key(Messages.GUI_WORKPLACE_LOGVIEW_FILE_LOG_HELP_0)));
238         // opencms.properties
239
result.add(new CmsSelectWidgetOption(
240             sysInfo.getConfigurationFileRfsPath(),
241             false,
242             null,
243             key(Messages.GUI_WORKPLACE_LOGVIEW_FILE_CONF_HELP_0)));
244         // config xml
245
String JavaDoc configPath = sysInfo.getAbsoluteRfsPathRelativeToWebInf(CmsSystemInfo.FOLDER_CONFIG);
246         if (configPath != null) {
247             File JavaDoc configFolder = new File JavaDoc(configPath);
248             File JavaDoc[] configFiles = configFolder.listFiles();
249             File JavaDoc 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