KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminProperties.java,v $
3 * Date : $Date: 2005/05/31 15:51:19 $
4 * Version: $Revision: 1.2 $
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
30 package com.opencms.workplace;
31
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsPropertyDefinition;
34 import org.opencms.file.types.I_CmsResourceType;
35 import org.opencms.i18n.CmsEncoder;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsLog;
38 import org.opencms.main.OpenCms;
39
40 import com.opencms.template.A_CmsXmlContent;
41 import com.opencms.template.CmsXmlTemplateFile;
42
43 import java.util.Hashtable JavaDoc;
44 import java.util.Iterator JavaDoc;
45 import java.util.List JavaDoc;
46
47 /**
48  * Template class for displaying OpenCms workplace admin properties
49  * <P>
50  *
51  * @author Mario Stanke
52  * @version $Revision: 1.2 $ $Date: 2005/05/31 15:51:19 $
53  * @see com.opencms.workplace.CmsXmlWpTemplateFile
54  *
55  * @deprecated Will not be supported past the OpenCms 6 release.
56  */

57
58 public class CmsAdminProperties extends CmsWorkplaceDefault {
59
60
61     /** XML datablock tag used for setting the resource type name */
62     private static final String JavaDoc C_TAG_RESTYPE = "restype";
63
64
65     /** XML datablock tag used for setting an entry in the list of datatypes */
66     private static final String JavaDoc C_TYPELISTENTRY = "typelistentry";
67
68
69     /** XML datablock tag used for setting all collected entries */
70     private static final String JavaDoc C_TAG_ALLENTRIES = "allentries";
71
72
73     /** XML datablock tag used for getting a processed resource type entry */
74     private static final String JavaDoc C_TAG_RESTYPEENTRY = "restypeentry";
75
76
77     /** XML datablock tag used for getting a processed separator entry */
78     private static final String JavaDoc C_TAG_SEPARATORENTRY = "separatorentry";
79
80
81     /** XML datablock tag used for getting the complete and processed content to be returned */
82     private static final String JavaDoc C_TAG_SCROLLERCONTENT = "scrollercontent";
83
84     /**
85      * Gets the content of a defined section in a given template file and its subtemplates
86      * with the given parameters.
87      *
88      * @see #getContent(CmsObject, String, String, Hashtable, String)
89      * @param cms CmsObject Object for accessing system resources.
90      * @param templateFile Filename of the template file.
91      * @param elementName Element name of this template in our parent template.
92      * @param parameters Hashtable with all template class parameters.
93      * @param templateSelector template section that should be processed.
94      */

95
96     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
97             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
98         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
99             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
100             CmsLog.getLog(this).debug("Template file is: " + templateFile);
101             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
102         }
103
104         //CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
105
//CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
106
CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
107         CmsXmlLanguageFile lang = xmlTemplateDocument.getLanguageFile();
108         String JavaDoc action = (String JavaDoc)parameters.get("action");
109         String JavaDoc resTypeName = (String JavaDoc)parameters.get("restype");
110         String JavaDoc propDefName = (String JavaDoc)parameters.get("propdef");
111         xmlTemplateDocument.setData("RESTYPE", resTypeName);
112         if("new".equals(action)) {
113             templateSelector = "newtype";
114             String JavaDoc name = (String JavaDoc)parameters.get("NAME");
115             if(name == null || name.equals("")) {
116
117
118             // form has not yet been submitted
119
}
120             else {
121                 try {
122                     cms.createPropertyDefinition(name);
123                     templateSelector = "";
124                 }
125                 catch(CmsException e) {
126                     StringBuffer JavaDoc errmesg = new StringBuffer JavaDoc();
127                     errmesg.append(lang.getLanguageValue("error.reason.newprop1") + " '"
128                             + name + "' " + lang.getLanguageValue("error.reason.newprop2")
129                             + " '" + resTypeName + "' "
130                             + lang.getLanguageValue("error.reason.newprop3") + "\n\n");
131                     errmesg.append(CmsException.getStackTraceAsString(e));
132                     xmlTemplateDocument.setData("NEWDETAILS", errmesg.toString());
133                     templateSelector = "newerror";
134                 }
135             }
136         }
137         else {
138             if("delete".equals(action)) {
139                 if("true".equals(parameters.get("sure"))) {
140
141                     // the user is sure to delete the property definition
142
cms.deletePropertyDefinition(propDefName);
143                     templateSelector = "";
144                 }
145                 else {
146                     templateSelector = "RUsuredelete";
147                 }
148                 xmlTemplateDocument.setData("PROPERTY_NAME", propDefName);
149             }
150         }
151
152         // Now load the template file and start the processing
153
return startProcessing(cms, xmlTemplateDocument, elementName, parameters,
154                 templateSelector);
155     }
156
157     /**
158      * Used by the <code>&lt;PREFSSCROLLER&gt;</code> tag for getting
159      * the content of the scroller window.
160      * <P>
161      * Gets all available resource types and returns a list
162      * using the datablocks defined in the own template file.
163      *
164      * @param cms CmsObject Object for accessing system resources.
165      * @param lang reference to the currently valid language file
166      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
167      * @return Index representing the user's current filter view in the vectors.
168      * @throws CmsException
169      */

170
171     public String JavaDoc getDatatypes(CmsObject cms, A_CmsXmlContent doc, CmsXmlLanguageFile lang,
172             Hashtable JavaDoc parameters, Object JavaDoc callingObj) throws CmsException {
173         
174         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
175         CmsXmlTemplateFile templateFile = (CmsXmlTemplateFile)doc;
176                    
177         List JavaDoc allResTypes = OpenCms.getResourceManager().getResourceTypes();
178         for (int i=0; i<allResTypes.size(); i++) {
179             // loop through all types
180
I_CmsResourceType type = (I_CmsResourceType)allResTypes.get(i);
181             result.append(getResourceEntry(cms, doc, lang, parameters, callingObj, type));
182             if(i < (allResTypes.size() - 1)) {
183                 result.append(templateFile.getProcessedDataValue(C_TAG_SEPARATORENTRY,
184                         callingObj));
185             }
186         }
187         templateFile.setData(C_TAG_ALLENTRIES, result.toString());
188         return templateFile.getProcessedDataValue(C_TAG_SCROLLERCONTENT, callingObj);
189     }
190
191     /**
192      *
193      * gets the HTML code for entry in the lists of resources.
194      *
195      * @param cms CmsObject Object for accessing system resources.
196      * @param doc the template file which is used
197      * @param lang reference to the currently valid language file
198      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
199      * @param callingObject Object for accessing system resources.
200      * @param resType resource type (file type)
201      * @return String which holds a HTML table
202      * @throws CmsException
203      */

204
205     private String JavaDoc getResourceEntry(CmsObject cms, A_CmsXmlContent doc,
206             CmsXmlLanguageFile lang, Hashtable JavaDoc parameters, Object JavaDoc callingObject,
207             I_CmsResourceType resType) throws CmsException {
208         StringBuffer JavaDoc output = new StringBuffer JavaDoc();
209         CmsXmlWpTemplateFile templateFile = (CmsXmlWpTemplateFile)doc;
210         List JavaDoc properties = cms.readAllPropertyDefinitions();
211         templateFile.setData(C_TAG_RESTYPE, resType.getTypeName());
212
213         templateFile.setData(C_TAG_RESTYPE + "_esc",
214                 CmsEncoder.escapeWBlanks(resType.getTypeName(),
215                 cms.getRequestContext().getEncoding()));
216         output.append(templateFile.getProcessedDataValue(C_TAG_RESTYPEENTRY, callingObject));
217         Iterator JavaDoc i = properties.iterator();
218         while (i.hasNext()) {
219             CmsPropertyDefinition propdef = (CmsPropertyDefinition)i.next();
220             templateFile.setData("PROPERTY_NAME", propdef.getName());
221             templateFile.setData("PROPERTY_NAME_ESC", CmsEncoder.escapeWBlanks(propdef.getName(),
222                 cms.getRequestContext().getEncoding()));
223             output.append(templateFile.getProcessedDataValue(C_TYPELISTENTRY, callingObject));
224         }
225         return output.toString();
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
239     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
240             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
241         return false;
242     }
243 }
244
Popular Tags