KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsExplorerResources.java,v $
3  * Date : $Date: 2005/06/27 23:22:07 $
4  * Version: $Revision: 1.4 $
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.CmsFile;
33 import org.opencms.file.CmsObject;
34 import org.opencms.main.CmsException;
35 import org.opencms.main.CmsLog;
36 import org.opencms.workplace.CmsWorkplace;
37
38 import com.opencms.legacy.CmsXmlTemplateLoader;
39
40 import java.util.Hashtable JavaDoc;
41 import java.util.List JavaDoc;
42
43 import javax.servlet.http.HttpServletRequest JavaDoc;
44
45 /**
46  * Template class for generating the java script.
47  * Creation date: (06.09.00 09:30:25)
48  * @author Hanjo Riege
49  *
50  * @deprecated Will not be supported past the OpenCms 6 release.
51  */

52
53 public class CmsExplorerResources extends CmsWorkplaceDefault {
54
55     private final static String JavaDoc C_RESTYPES_FOLDER = CmsWorkplace.VFS_PATH_WORKPLACE + "restypes/";
56
57     /**
58      * Gets the content of a defined section in a given template file and its subtemplates
59      * with the given parameters.
60      *
61      * @see #getContent(CmsObject, String, String, Hashtable, String)
62      * @param cms CmsObject Object for accessing system resources.
63      * @param templateFile Filename of the template file.
64      * @param elementName Element name of this template in our parent template.
65      * @param parameters Hashtable with all template class parameters.
66      * @param templateSelector template section that should be processed.
67      */

68
69     public byte[] getContent(
70         CmsObject cms,
71         String JavaDoc templateFile,
72         String JavaDoc elementName,
73         Hashtable JavaDoc parameters,
74         String JavaDoc templateSelector) throws CmsException {
75
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(
80                 "Selected template section is: " + ((templateSelector == null) ? "<default>" : templateSelector));
81         }
82         CmsXmlWpTemplateFile templateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
83         CmsXmlLanguageFile lang = templateDocument.getLanguageFile();
84         String JavaDoc servletPath = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl();
85         StringBuffer JavaDoc jsOutput = new StringBuffer JavaDoc();
86
87         // function vars_resources
88
jsOutput.append("function vars_resources() { \n this.stati = new Array(\"");
89         jsOutput.append(lang.getLanguageValue("explorer.state0") + "\",\"");
90         jsOutput.append(lang.getLanguageValue("explorer.state1") + "\",\"");
91         jsOutput.append(lang.getLanguageValue("explorer.state2") + "\",\"");
92         jsOutput.append(lang.getLanguageValue("explorer.state3") + "\");\n");
93         jsOutput.append(" this.descr = new Array(\"");
94         jsOutput.append(lang.getLanguageValue("title.name") + "\",\"");
95         jsOutput.append(lang.getLanguageValue("title.title") + "\",\"");
96         jsOutput.append(lang.getLanguageValue("title.type") + "\",\"");
97         jsOutput.append(lang.getLanguageValue("title.changed") + "\",\"");
98         jsOutput.append(lang.getLanguageValue("title.size") + "\",\"");
99         jsOutput.append(lang.getLanguageValue("title.state") + "\",\"");
100         jsOutput.append(lang.getLanguageValue("title.owner") + "\",\"");
101         jsOutput.append(lang.getLanguageValue("title.group") + "\",\"");
102         jsOutput.append(lang.getLanguageValue("title.access") + "\",\"");
103         jsOutput.append(lang.getLanguageValue("title.locked") + "\");\n");
104         jsOutput.append(" this.actProject; \n this.onlineProject;\n this.lockedBy=\""
105             + lang.getLanguageValue("title.locked"));
106         jsOutput.append("\";\n this.titleString=\""
107             + lang.getLanguageValue("label.wptitle")
108             + "\" \n this.actDirectory;");
109         jsOutput.append("\n this.userName = \"" + cms.getRequestContext().currentUser().getName() + "\";\n");
110         jsOutput.append("\n this.serverName = \""
111             + ((HttpServletRequest JavaDoc)CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()).getServerName()
112             + "\";\n");
113         jsOutput.append(" this.langback=\"" + lang.getLanguageValue("button.back") + "\";\n");
114         jsOutput.append(" this.langsearch=\"" + lang.getLanguageValue("button.search") + "\";\n");
115         jsOutput.append(" this.langup=\"" + lang.getLanguageValue("button.parent") + "\";\n");
116         jsOutput.append(" this.langnew=\"" + lang.getLanguageValue("button.new") + "\";\n");
117         jsOutput.append(" this.langadress=\"" + lang.getLanguageValue("input.adress") + ":\";\n");
118         jsOutput.append(" this.langpage=\"" + lang.getLanguageValue("input.page") + "\";\n");
119         jsOutput.append(" this.langloading=\"" + lang.getLanguageValue("label.loading") + "\";\n");
120         jsOutput.append(" this.altlockedby=\"" + lang.getLanguageValue("explorer.lockedby") + "\";\n");
121         jsOutput.append(" this.altlockedin=\"" + lang.getLanguageValue("explorer.lockedin") + "\";\n");
122         jsOutput.append(" this.altbelongto=\"" + lang.getLanguageValue("explorer.altbelongto") + "\";\n");
123         jsOutput.append(" this.servpath=\"" + servletPath + "\";\n");
124         int filelist = getDefaultPreferences(cms);
125         jsOutput.append(" this.viewcfg = " + filelist + ";\n");
126         jsOutput.append(" this.actDirId;\n} \n");
127
128         // function initialize_resources
129
jsOutput.append("function initialize_resources() {\n vi.iconPath=\""
130             + (String JavaDoc)resourcesUri(cms, "", null, null)
131             + "\";\n");
132
133         // get the resources from /system/workplace/restypes/
134
List JavaDoc resTypes = cms.getFilesInFolder(C_RESTYPES_FOLDER);
135         for (int i = 0; i < resTypes.size(); i++) {
136             CmsFile resourceTyp = (CmsFile)resTypes.get(i);
137             try {
138                 int resId = resourceTyp.getTypeId();
139                 jsOutput.append(getResourceEntry(lang, new String JavaDoc(
140                     cms.readFile(cms.getSitePath(resourceTyp)).getContents()), resId));
141             } catch (CmsException e) {
142
143             }
144         }
145         jsOutput.append("}");
146         templateDocument.setData("js", jsOutput.toString());
147
148         // Now load the template file and start the processing
149
return startProcessing(cms, templateDocument, elementName, parameters, templateSelector);
150     }
151
152     /**
153      * Sets the default preferences for the current user if those values are not available.
154      * @return Hashtable with default preferences.
155      */

156
157     private int getDefaultPreferences(CmsObject cms) {
158
159         int filelist;
160         String JavaDoc explorerSettings = (String JavaDoc)cms.getRequestContext().currentUser().getAdditionalInfo(
161             CmsUserSettings.ADDITIONAL_INFO_EXPLORERSETTINGS);
162         if (explorerSettings != null) {
163             filelist = new Integer JavaDoc(explorerSettings).intValue();
164         } else {
165             filelist = CmsUserSettings.FILELIST_NAME + CmsUserSettings.FILELIST_TITLE + CmsUserSettings.FILELIST_TYPE + CmsUserSettings.FILELIST_DATE_LASTMODIFIED;
166         }
167         return filelist;
168     }
169
170     /**
171      * Insert the method's description here.
172      * Creation date: (17.11.00 16:05:08)
173      * @return java.lang.String
174      * @param lang com.opencms.workplace.CmsXmlLanguageFile
175      * @param data java.lang.String
176      * @param name java.lang.String
177      */

178
179     private String JavaDoc getResourceEntry(CmsXmlLanguageFile lang, String JavaDoc data, int id) {
180
181         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
182         String JavaDoc resId = Integer.toString(id);
183
184         // first replace "resource_id" with the id
185
int index = 0;
186         String JavaDoc myToken = "resource_id";
187         int foundAt = data.indexOf(myToken, index);
188         while (foundAt != -1) {
189             result.append(data.substring(index, foundAt) + resId);
190             index = foundAt + myToken.length();
191             foundAt = data.indexOf(myToken, index);
192         }
193         result.append(data.substring(index));
194
195         // now set in the language values
196
data = result.toString();
197         result = new StringBuffer JavaDoc();
198         myToken = "language_key";
199         index = 0;
200         foundAt = data.indexOf(myToken, index);
201         while (foundAt != -1) {
202             int endIndex = data.indexOf(")", foundAt);
203             String JavaDoc langKey = data.substring(data.indexOf("(", foundAt) + 1, endIndex);
204             langKey = lang.getLanguageValue(langKey);
205             result.append(data.substring(index, foundAt) + langKey);
206             index = endIndex + 1;
207             foundAt = data.indexOf(myToken, index);
208         }
209         result.append(data.substring(index));
210
211         // at last we have to remove the spaces in the rules parameter
212
data = result.toString();
213         result = new StringBuffer JavaDoc();
214         myToken = "rules_key";
215         index = 0;
216         foundAt = data.indexOf(myToken, index);
217         while (foundAt != -1) {
218             int endIndex = data.indexOf(")", foundAt);
219             String JavaDoc rulesKey = data.substring(data.indexOf("(", foundAt) + 1, endIndex).trim();
220             int nextSpace = rulesKey.indexOf(" ");
221             while (nextSpace > -1) {
222                 rulesKey = rulesKey.substring(0, nextSpace) + rulesKey.substring(nextSpace + 1);
223                 nextSpace = rulesKey.indexOf(" ");
224             }
225             result.append(data.substring(index, foundAt) + rulesKey);
226             index = endIndex + 1;
227             foundAt = data.indexOf(myToken, index);
228         }
229         result.append(data.substring(index));
230
231         return result.toString();
232     }
233
234     /**
235      * Indicates if the results of this class are cacheable.
236      *
237      * @param cms CmsObject Object for accessing system resources
238      * @param templateFile Filename of the template file
239      * @param elementName Element name of this template in our parent template.
240      * @param parameters Hashtable with all template class parameters.
241      * @param templateSelector template section that should be processed.
242      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
243      */

244
245     public boolean isCacheable(
246         CmsObject cms,
247         String JavaDoc templateFile,
248         String JavaDoc elementName,
249         Hashtable JavaDoc parameters,
250         String JavaDoc templateSelector) {
251
252         return false;
253     }
254 }
255
Popular Tags