KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > setup > xml > CmsSetupXmlManager


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/setup/xml/CmsSetupXmlManager.java,v $
3  * Date : $Date: 2006/04/28 15:20:52 $
4  * Version: $Revision: 1.3 $
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.setup.xml;
33
34 import org.opencms.i18n.CmsEncoder;
35 import org.opencms.setup.CmsSetupBean;
36 import org.opencms.util.CmsStringUtil;
37
38 import java.util.ArrayList JavaDoc;
39 import java.util.Collections JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.Iterator JavaDoc;
42 import java.util.List JavaDoc;
43 import java.util.Map JavaDoc;
44
45 /**
46  * Manages all changes to be made to xml configuration files.<p>
47  *
48  * @author Michael Moossen
49  *
50  * @version $Revision: 1.3 $
51  *
52  * @since 6.1.8
53  */

54 public class CmsSetupXmlManager {
55
56     /** List of xml update plugins. */
57     private List JavaDoc m_plugins;
58
59     /** User selected plugins to execute. */
60     private List JavaDoc m_selectedPlugins;
61
62     /** Map of file sorted plugins. */
63     private Map JavaDoc m_sortedPlugins;
64
65     /**
66      * Default constructor.<p>
67      */

68     public CmsSetupXmlManager() {
69
70         m_selectedPlugins = new ArrayList JavaDoc();
71         m_plugins = new ArrayList JavaDoc();
72         // put the plugins here in chronological order (or first remove then add)
73

74         // search
75
m_plugins.add(new CmsXmlRemovePageSearchIndexSource1());
76         m_plugins.add(new CmsXmlRemoveSysSearchIndex());
77         m_plugins.add(new CmsXmlAddDEHelpSearchIndex());
78
79         // system
80
m_plugins.add(new CmsXmlAddBackupResourceHandler());
81         m_plugins.add(new CmsXmlAddContentNotification());
82
83         // vfs
84
m_plugins.add(new CmsXmlReplaceHtmlAreaWidgets());
85         m_plugins.add(new CmsXmlAddImageLoader());
86         m_plugins.add(new CmsXmlAddImgGalleryParam());
87         m_plugins.add(new CmsXmlAddXmlContentWidgets());
88
89         // workplace
90
m_plugins.add(new CmsXmlAddAvailabilityContextMenu());
91         m_plugins.add(new CmsXmlAddMultiContextMenu());
92         m_plugins.add(new CmsXmlUpdateHistoryContextMenu());
93         m_plugins.add(new CmsXmlAddImgGalleryContextMenues());
94         m_plugins.add(new CmsXmlAddPublishButtonAppearance());
95         m_plugins.add(new CmsXmlUpdateDefaultPermissions());
96         m_plugins.add(new CmsXmlAddAutoSetFeatures());
97         m_plugins.add(new CmsXmlUpdateLocalizationKeys());
98
99         setup();
100     }
101
102     /**
103      * Executes all user selected plugins.<p>
104      *
105      * @param setupBean the setup bean
106      *
107      * @throws Exception if something goes wrong
108      */

109     public void execute(CmsSetupBean setupBean) throws Exception JavaDoc {
110
111         Iterator JavaDoc it = m_selectedPlugins.iterator();
112         while (it.hasNext()) {
113             String JavaDoc id = (String JavaDoc)it.next();
114             int d = id.lastIndexOf(".xml") + ".xml".length();
115             String JavaDoc fileName = id.substring(0, d);
116             int pos = Integer.parseInt(id.substring(d));
117             List JavaDoc plugins = (List JavaDoc)m_sortedPlugins.get(fileName);
118             I_CmsSetupXmlUpdate plugin = (I_CmsSetupXmlUpdate)plugins.get(pos);
119             plugin.execute(setupBean);
120         }
121         setupBean.getXmlHelper().writeAll();
122     }
123
124     /**
125      * Returns the plugins.<p>
126      *
127      * @return a map of [filenames, list of plugins]
128      */

129     public Map JavaDoc getPlugins() {
130
131         return Collections.unmodifiableMap(m_sortedPlugins);
132     }
133
134     /**
135      * Returns html for displaying a plugin selection box.<p>
136      *
137      * @param setupBean the setup bean
138      *
139      * @return html code
140      *
141      * @throws Exception if something goes wrong
142      */

143     public String JavaDoc htmlAvailablePlugins(CmsSetupBean setupBean) throws Exception JavaDoc {
144
145         StringBuffer JavaDoc html = new StringBuffer JavaDoc(1024);
146         Iterator JavaDoc itFiles = m_sortedPlugins.keySet().iterator();
147         while (itFiles.hasNext()) {
148             String JavaDoc fileName = (String JavaDoc)itFiles.next();
149             Iterator JavaDoc itPlugins = ((List JavaDoc)m_sortedPlugins.get(fileName)).iterator();
150             StringBuffer JavaDoc code = new StringBuffer JavaDoc(256);
151             for (int i = 0; itPlugins.hasNext(); i++) {
152                 I_CmsSetupXmlUpdate plugin = (I_CmsSetupXmlUpdate)itPlugins.next();
153                 if (plugin.validate(setupBean)) {
154                     code.append(htmlPlugin(setupBean, plugin, i));
155                 }
156             }
157             if (code.length() > 0) {
158                 html.append("<tr><th colspan='2' align='left'>");
159                 html.append(fileName);
160                 html.append("</th></tr>\n");
161                 html.append(code.toString());
162             }
163         }
164         return html.toString();
165     }
166
167     /**
168      * Bean property setter method user from the <code>step_5_xmlupdate.jsp</code>.<p>
169      *
170      * @param value the value to set
171      */

172     public void setSelectedPlugins(String JavaDoc value) {
173
174         m_selectedPlugins = CmsStringUtil.splitAsList(value, "|", true);
175     }
176
177     /**
178      * Generates html code for the given plugin at the given position.<p>
179      *
180      * @param plugin the plugin
181      * @param pos the position
182      * @param setupBean the setup bean
183      *
184      * @return html code
185      *
186      * @throws Exception if something goes wrong
187      */

188     private String JavaDoc htmlPlugin(CmsSetupBean setupBean, I_CmsSetupXmlUpdate plugin, int pos) throws Exception JavaDoc {
189
190         StringBuffer JavaDoc html = new StringBuffer JavaDoc(256);
191         String JavaDoc id = plugin.getXmlFilename() + pos;
192         html.append("\t<tr>\n");
193         html.append("\t\t<td style='vertical-align: top;' nowrap>\n");
194         html.append("\t\t\t<input type='checkbox' name='availablePlugins' value='");
195         html.append(id);
196         html.append("' checked='checked'>\n");
197         html.append("\t\t</td>\n");
198         html.append("\t\t<td style='vertical-align: top; width: 100%; padding-top: 4px;'>\n\t\t\t");
199         html.append("<a HREF=\"javascript:switchview('").append(id).append("');\">");
200         html.append(plugin.getName()).append("</a><br>\n");
201         html.append("\t<div id='").append(id).append("' style='display: none;'>\n");
202         String JavaDoc codeToChange = plugin.getCodeToChange(setupBean);
203         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(codeToChange)) {
204             html.append("<pre class='code'>");
205             html.append(CmsEncoder.escapeXml(codeToChange));
206             html.append("</pre>\n");
207         }
208         html.append("\t</div>\n");
209         html.append("\n\t\t</td>\n");
210         html.append("\t</tr>\n");
211         return html.toString();
212     }
213
214     /**
215      * Sort the plugins by filename.<p>
216      */

217     private void setup() {
218
219         m_sortedPlugins = new HashMap JavaDoc();
220         Iterator JavaDoc it = m_plugins.iterator();
221         while (it.hasNext()) {
222             I_CmsSetupXmlUpdate plugin = (I_CmsSetupXmlUpdate)it.next();
223             List JavaDoc list = (List JavaDoc)m_sortedPlugins.get(plugin.getXmlFilename());
224             if (list == null) {
225                 list = new ArrayList JavaDoc();
226                 m_sortedPlugins.put(plugin.getXmlFilename(), list);
227             }
228             list.add(plugin);
229         }
230     }
231 }
Popular Tags