KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsAdminSyncProperties


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminSyncProperties.java,v $
3 * Date : $Date: 2005/06/25 11:19:03 $
4 * Version: $Revision: 1.6 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
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 OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29 package com.opencms.workplace;
30
31 import org.opencms.db.CmsUserSettings;
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsRequestContext;
34 import org.opencms.main.CmsException;
35 import org.opencms.main.CmsLog;
36 import org.opencms.synchronize.CmsSynchronizeSettings;
37
38 import com.opencms.core.I_CmsSession;
39 import com.opencms.legacy.CmsXmlTemplateLoader;
40 import com.opencms.template.CmsXmlTemplateFile;
41
42 import java.util.ArrayList JavaDoc;
43 import java.util.Hashtable JavaDoc;
44 import java.util.Iterator JavaDoc;
45 import java.util.StringTokenizer JavaDoc;
46 import java.util.Vector JavaDoc;
47
48 /**
49  * Template class for displaying OpenCms workplace administration synchronisation properties.
50  *
51  * Creation date: ()
52  * @author Edna Falkenhan
53  *
54  * @deprecated Will not be supported past the OpenCms 6 release.
55  */

56 public class CmsAdminSyncProperties extends CmsWorkplaceDefault {
57
58     private final String JavaDoc C_STEP = "step";
59     private final String JavaDoc C_SYNCPROJECT = "syncproject";
60     private final String JavaDoc C_SYNCPATH = "syncpath";
61     private final String JavaDoc C_SYNCRESOURCES = "syncresources";
62     private final String JavaDoc C_ADDFOLDER = "addfolder";
63
64     /**
65      * Gets the content of a defined section in a given template file and its subtemplates
66      * with the given parameters.
67      *
68      * @see #getContent(CmsObject, String, String, Hashtable, String)
69      * @param cms CmsObject Object for accessing system resources.
70      * @param templateFile Filename of the template file.
71      * @param elementName Element name of this template in our parent template.
72      * @param parameters Hashtable with all template class parameters.
73      * @param templateSelector template section that should be processed.
74      */

75     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
76         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
77             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
78             CmsLog.getLog(this).debug("Template file is: " + templateFile);
79             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
80         }
81
82         CmsXmlTemplateFile templateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
83         CmsRequestContext reqCont = cms.getRequestContext();
84         I_CmsSession session = CmsXmlTemplateLoader.getSession(reqCont, true);
85         CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
86
87         String JavaDoc syncPath = new String JavaDoc();
88         String JavaDoc allResources = new String JavaDoc();
89
90         // clear session values on first load
91
String JavaDoc step = (String JavaDoc)parameters.get(C_STEP);
92         syncPath = (String JavaDoc)parameters.get(C_SYNCPATH);
93         allResources = (String JavaDoc)parameters.get(C_SYNCRESOURCES);
94
95         if(step == null) {
96             // if the dialog was opened the first time remove the session values
97
// and get the id of the current project
98
if(session.getValue(C_STEP) == null){
99                 // remove all session values
100
session.removeValue(C_SYNCPATH);
101                 session.removeValue(C_SYNCRESOURCES);
102                 session.removeValue(C_ADDFOLDER);
103                 session.removeValue("lasturl");
104                 session.putValue(C_STEP, "nextstep");
105             }
106         } else {
107             if("OK".equalsIgnoreCase(step)) {
108                 syncPath = (String JavaDoc)parameters.get(C_SYNCPATH);
109                 allResources = (String JavaDoc)parameters.get(C_SYNCRESOURCES);
110                 Vector JavaDoc folders = null;
111                 // the form has just been submitted, store the data in the session
112
if(((syncPath == null) || syncPath.equals("")) ||
113                     ((allResources == null) || allResources.equals(""))) {
114                     templateSelector = "datamissing";
115                 } else {
116                     // all the required data has been entered
117
session.putValue(C_SYNCPATH, syncPath);
118                     session.putValue(C_SYNCRESOURCES, allResources);
119                     // 'allResources' has the "form res1;res2;...resk;"
120
// this is because the simpler 'getParameterValues' method doesn't work with Silverstream
121
folders = parseResources(allResources);
122                     
123                     Vector JavaDoc notWriteable = new Vector JavaDoc();
124                     Iterator JavaDoc it = folders.iterator();
125                     while (it.hasNext()) {
126                         
127                         String JavaDoc source = (String JavaDoc)it.next();
128
129                         // modify the foldername if nescessary (the root folder is always given
130
// as a nice name)
131
if (lang.getLanguageValue("title.rootfolder").equals(source)) {
132                             source = "/";
133                         }
134                     }
135
136                     if("errorsyncproperties".equals(templateSelector)){
137                         // at least one of the choosen folders was not writeable
138
templateDocument.setData("details", "The following folders were not readable:"
139                                 + notWriteable.toString());
140                     }
141                 }
142                 if(templateSelector == null || "".equals(templateSelector)){
143
144                     // now update the settings
145
CmsSynchronizeSettings settings = new CmsSynchronizeSettings();
146                     settings.setEnabled(! "-".equals(syncPath));
147                     settings.setDestinationPathInRfs(settings.isEnabled() ? syncPath : null);
148                     if (folders != null) {
149                         settings.setSourceListInVfs(new ArrayList JavaDoc(folders));
150                     }
151                     
152                     // check the settings
153
settings.checkValues(cms);
154                     
155                     CmsUserSettings userSettings = new CmsUserSettings(cms);
156                     userSettings.setSynchronizeSettings(settings);
157                     userSettings.save(cms);
158
159                     templateSelector = "done";
160                     
161                     // remove the values from the session
162
session.removeValue(C_STEP);
163                 }
164             } else if("fromerrorpage".equals(step)) {
165                 // after an error fill in the data from the session into the template
166
templateDocument.setData(C_SYNCPROJECT, "" + cms.getRequestContext().currentProject().getId());
167                 templateDocument.setData(C_SYNCPATH, (String JavaDoc)session.getValue(C_SYNCPATH));
168                 templateDocument.setData(C_ADDFOLDER, "");
169                 templateDocument.setData(C_SYNCRESOURCES, (String JavaDoc)session.getValue(C_SYNCRESOURCES));
170                 templateSelector = "";
171             } else if("cancel".equals(step)){
172                 // remove the values from the session
173
session.removeValue(C_STEP);
174                 templateSelector = "done";
175             }
176         }
177         // if there are still values in the session (like after an error), use them
178
if((syncPath == null) || ("".equals(syncPath))) {
179             syncPath = (String JavaDoc)session.getValue(C_SYNCPATH);
180         }
181         if((allResources == null) || ("".equals(allResources))) {
182             allResources = (String JavaDoc)session.getValue(C_SYNCRESOURCES);
183         }
184
185         CmsUserSettings userSettings = new CmsUserSettings(cms);
186         CmsSynchronizeSettings settings = userSettings.getSynchronizeSettings();
187         if (settings == null) {
188             settings = new CmsSynchronizeSettings();
189         }
190         
191         if((syncPath == null) || ("".equals(syncPath))) {
192             syncPath = settings.getDestinationPathInRfs();
193             if(syncPath == null){
194                 syncPath = "";
195             }
196         }
197         if((allResources == null) || ("".equals(allResources))) {
198             if (settings.getSourceListInVfs().size() > 0) {
199                 StringBuffer JavaDoc result = new StringBuffer JavaDoc();
200                 Iterator JavaDoc it = settings.getSourceListInVfs().iterator();
201                 while (it.hasNext()) {
202                     result.append(it.next());
203                     if (it.hasNext()) {
204                         result.append(';');
205                     }
206                 }
207                 allResources = result.toString();
208             }
209             if (allResources == null) {
210                 allResources = "";
211             }
212             // remove the last semikolon
213
if (allResources.endsWith(";")){
214                 allResources = allResources.substring(0,allResources.lastIndexOf(";"));
215             }
216         }
217
218         templateDocument.setData(C_SYNCPROJECT, "" + cms.getRequestContext().currentProject().getId());
219         templateDocument.setData(C_SYNCRESOURCES, allResources);
220         templateDocument.setData(C_SYNCPATH, syncPath);
221         session.putValue(C_SYNCPATH, syncPath);
222         session.putValue(C_SYNCRESOURCES, allResources);
223
224         // Now load the template file and start the processing
225
return startProcessing(cms, templateDocument, elementName, parameters, templateSelector);
226     }
227
228     /**
229      * Indicates if the results of this class are cacheable.
230      *
231      * @param cms CmsObject Object for accessing system resources
232      * @param templateFile Filename of the template file
233      * @param elementName Element name of this template in our parent template.
234      * @param parameters Hashtable with all template class parameters.
235      * @param templateSelector template section that should be processed.
236      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
237      */

238     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
239         return false;
240     }
241
242     /**
243      * Gets the resources.
244      * <P>
245      * The given vectors <code>names</code> and <code>values</code> will
246      * be filled with the appropriate information to be used for building
247      * a select box.
248      *
249      * @param cms CmsObject Object for accessing system resources.
250      * @param names Vector to be filled with the appropriate values in this method.
251      * @param values Vector to be filled with the appropriate values in this method.
252      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
253      * @return Index representing the current value in the vectors.
254      * @throws CmsException
255      */

256
257     public Integer JavaDoc getResources(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names,
258             Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
259
260         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
261         String JavaDoc enteredResources = (String JavaDoc)session.getValue(C_SYNCRESOURCES);
262         Vector JavaDoc resources = parseResources(enteredResources);
263         // fill the names and values
264
for(int z = 0;z < resources.size();z++) {
265             String JavaDoc resourceName = (String JavaDoc)resources.elementAt(z);
266             names.addElement(resourceName);
267             values.addElement(resourceName);
268         }
269         return new Integer JavaDoc(-1);
270     }
271
272     /** Parse the string which holds all resources
273      *
274      * @param resources containts the full pathnames of all the resources, separated by semicolons
275      * @return A vector with the same resources
276      */

277     private Vector JavaDoc parseResources(String JavaDoc resources) {
278         Vector JavaDoc ret = new Vector JavaDoc();
279         if(resources != null) {
280             StringTokenizer JavaDoc resTokenizer = new StringTokenizer JavaDoc(resources, ";");
281             while(resTokenizer.hasMoreElements()) {
282                 String JavaDoc path = (String JavaDoc)resTokenizer.nextElement();
283                 ret.addElement(path);
284             }
285         }
286         return ret;
287     }
288 }
Popular Tags