KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsChtype.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 Management 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.file.CmsFile;
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsRequestContext;
34 import org.opencms.main.CmsException;
35 import org.opencms.main.OpenCms;
36
37 import com.opencms.core.I_CmsSession;
38 import com.opencms.legacy.CmsLegacyException;
39 import com.opencms.legacy.CmsXmlTemplateLoader;
40
41 import java.util.Hashtable JavaDoc;
42 import java.util.Vector JavaDoc;
43
44 /**
45  * Template class for displaying the type screen of the OpenCms workplace.<p>
46  *
47  * @author Michael Emmerich
48  * @version $Revision: 1.4 $ $Date: 2005/06/27 23:22:07 $
49  *
50  * @deprecated Will not be supported past the OpenCms 6 release.
51  */

52 public class CmsChtype extends CmsWorkplaceDefault {
53
54     /** Definition of the Datablock RADIOSIZE */
55     private final static String JavaDoc C_RADIOSIZE = "RADIOSIZE";
56
57     /** Vector containing all names of the radiobuttons */
58     private Vector JavaDoc m_names = null;
59
60     /** Vector containing all links attached to the radiobuttons */
61     private Vector JavaDoc m_values = null;
62
63     /**
64      * Gets the content of the chtype template and processes the data input.<p>
65      *
66      * @param cms The CmsObject.
67      * @param templateFile The chtype template file
68      * @param elementName not used
69      * @param parameters Parameters of the request and the template.
70      * @param templateSelector Selector of the template tag to be displayed.
71      * @return Bytearray containing the processed data of the template.
72      * @throws CmsException if something goes wrong.
73      */

74     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
75             Hashtable JavaDoc parameters, String JavaDoc templateSelector)
76     throws CmsException {
77         CmsRequestContext requestContext = cms.getRequestContext();
78         I_CmsSession session = CmsXmlTemplateLoader.getSession(requestContext, true);
79
80         // the template to be displayed
81
String JavaDoc template = null;
82
83         // clear session values on first load
84
String JavaDoc initial = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_INITIAL);
85         if (initial != null) {
86
87             // remove all session values
88
session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
89             session.removeValue("lasturl");
90         }
91
92         // get the lasturl parameter
93
String JavaDoc lasturl = getLastUrl(cms, parameters);
94         String JavaDoc newtype = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_NEWTYPE);
95
96         // get the filename
97
String JavaDoc filename = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_RESOURCE);
98         if (filename != null) {
99             session.putValue(CmsWorkplaceDefault.C_PARA_RESOURCE, filename);
100         }
101         filename = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
102         CmsFile file = (CmsFile)cms.readResource(filename);
103
104         // check if the newtype parameter is available. This parameter is set when
105
// the new file type is selected
106
if (newtype != null) {
107
108             // get the new resource type
109

110             int type = OpenCms.getResourceManager().getResourceType(newtype).getTypeId();
111             
112             // check the autolock resource setting and lock the resource if necessary
113
if (OpenCms.getWorkplaceManager().autoLockResources()) {
114                 if (cms.getLock(filename).isNullLock()) {
115                     // resource is not locked, lock it automatically
116
cms.lockResource(filename);
117                 }
118             }
119             
120             // change the file type
121
cms.chtype(cms.getSitePath(file), type);
122             session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
123
124             // return to filelist
125
try {
126                 if (lasturl == null || "".equals(lasturl)) {
127                     CmsXmlTemplateLoader.getResponse(requestContext).sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath()
128                     + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()));
129                 } else {
130                     CmsXmlTemplateLoader.getResponse(requestContext).sendRedirect(lasturl);
131                 }
132             } catch (Exception JavaDoc e) {
133                 throw new CmsLegacyException("Redirect fails :" + getConfigFile(cms).getWorkplaceActionPath()
134                         + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()), e);
135             }
136             return null;
137         }
138         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
139
140         // set all required datablocks
141
xmlTemplateDocument.setData("OWNER", "" /* Utils.getFullName(cms.readOwner(file)) */);
142         xmlTemplateDocument.setData("GROUP", "" /* cms.readGroup(file).getName() */);
143         xmlTemplateDocument.setData("FILENAME", file.getName());
144         getResources(cms, null, null, null, null, null);
145         if (m_names != null) {
146             xmlTemplateDocument.setData(C_RADIOSIZE, new Integer JavaDoc(m_names.size()).toString());
147         }
148
149         // process the selected template
150
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
151     }
152
153     /**
154      * Gets the resources displayed in the Radiobutton group on the chtype dialog.<p>
155      *
156      * @param cms The CmsObject.
157      * @param lang The langauge definitions.
158      * @param names The names of the new rescources (used for optional images).
159      * @param values The links that are connected with each resource.
160      * @param descriptions Description that will be displayed for the new resource.
161      * @param parameters Hashtable of parameters (not used yet).
162      * @return The vectors names and values filled with the information found in the
163      * workplace.ini.
164      * @throws CmsException if something goes wrong.
165      */

166     public void getResources(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names,
167             Vector JavaDoc values, Vector JavaDoc descriptions, Hashtable JavaDoc parameters)
168     throws CmsException {
169
170         // check if the list of available resources is not yet loaded from the workplace.ini
171
if(m_names == null || m_values == null) {
172             m_names = new Vector JavaDoc();
173             m_values = new Vector JavaDoc();
174             CmsXmlWpConfigFile configFile = new CmsXmlWpConfigFile(cms);
175             configFile.getWorkplaceIniData(m_names, m_values, "RESOURCETYPES", "RESOURCE");
176         }
177
178         // check if the temportary name and value vectors are not initialized,
179
// create them if nescessary.
180
if(names == null) names = new Vector JavaDoc();
181         if(values == null) values = new Vector JavaDoc();
182         if(descriptions == null) descriptions = new Vector JavaDoc();
183
184         // now m_names and m_values contain all available resource information
185
// Loop through the vectors and fill the result vectors
186
int numViews = m_names.size();
187         for(int i = 0;i < numViews;i++) {
188             String JavaDoc loopValue = (String JavaDoc)m_values.elementAt(i);
189             String JavaDoc loopName = (String JavaDoc)m_names.elementAt(i);
190             values.addElement(loopValue);
191             names.addElement("file_" + loopName);
192             String JavaDoc descr;
193             if(lang != null) {
194                 descr = lang.getLanguageValue("fileicon." + loopName);
195             }
196             else {
197                 descr = loopName;
198             }
199             descriptions.addElement(descr);
200         }
201     }
202
203     /**
204      * Indicates if the results of this class are cacheable,
205      * which is not the case for this class.<p>
206      *
207      * @param cms CmsObject Object for accessing system resources
208      * @param templateFile Filename of the template file
209      * @param elementName Element name of this template in our parent template.
210      * @param parameters Hashtable with all template class parameters.
211      * @param templateSelector template section that should be processed.
212      * @return <code>false</code>
213      */

214     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
215         Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
216         return false;
217     }
218 }
219
Popular Tags