KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsCopyToProject.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
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.CmsResource;
34 import org.opencms.main.CmsException;
35 import org.opencms.security.CmsSecurityException;
36
37 import com.opencms.core.I_CmsSession;
38 import com.opencms.legacy.CmsXmlTemplateLoader;
39
40 import java.util.Hashtable JavaDoc;
41
42 /**
43  * Template class for displaying the copy to project screen of the OpenCms workplace.<P>
44  * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
45  *
46  * @author Edna Falkenhan
47  * @version $Revision: 1.2 $ $Date: 2005/06/27 23:22:07 $
48  *
49  * @deprecated Will not be supported past the OpenCms 6 release.
50  */

51
52 public class CmsCopyToProject extends CmsWorkplaceDefault {
53
54     /**
55      * Overwrites the getContent method of the CmsWorkplaceDefault.<br>
56      * Gets the content of the undelete template and processed the data input.
57      * @param cms The CmsObject.
58      * @param templateFile The undelete template file
59      * @param elementName not used
60      * @param parameters Parameters of the request and the template.
61      * @param templateSelector Selector of the template tag to be displayed.
62      * @return Bytearre containgine the processed data of the template.
63      * @throws Throws CmsException if something goes wrong.
64      */

65
66     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
67             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
68         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
69         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
70
71         // the template to be displayed
72
String JavaDoc template = null;
73
74         // clear session values on first load
75
String JavaDoc initial = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_INITIAL);
76         if(initial != null) {
77             // remove all session values
78
session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
79             session.removeValue("copy");
80             session.removeValue("lasturl");
81         }
82         // save the lasturl parameter in the session
83
getLastUrl(cms, parameters);
84         String JavaDoc copy = (String JavaDoc)parameters.get("copy");
85         if(copy != null) {
86             session.putValue("copy", copy);
87         }
88         copy = (String JavaDoc)session.getValue("copy");
89         String JavaDoc filename = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_RESOURCE);
90         if(filename != null) {
91             session.putValue(CmsWorkplaceDefault.C_PARA_RESOURCE, filename);
92         }
93         filename = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
94         String JavaDoc action = (String JavaDoc)parameters.get("action");
95
96         CmsResource file = null;
97         if(filename.endsWith("/")){
98             file = cms.readFolder(filename);
99         } else {
100             file = cms.readResource(filename);
101         }
102         //check if the name parameter was included in the request
103
// if not, the copyToProject page is shown for the first time
104
if (copy != null) {
105             if (action != null) {
106                 // copy the resource to the current project
107
try {
108                     if (cms.isManagerOfProject()) {
109                         cms.copyResourceToProject(cms.getSitePath(file));
110                         session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
111                         template = "done";
112                     } else {
113                         throw new CmsSecurityException(Messages.get().container(Messages.ERR_SECURITY_PROJECTMANAGER_PRIVILEGES_REQUIRED_0));
114                     }
115                 } catch (CmsException e) {
116                     session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
117                     xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(e));
118                     return startProcessing(cms, xmlTemplateDocument, "", parameters, "error");
119                 }
120             } else {
121                 template = "wait";
122             }
123         }
124         // set the required datablocks
125
if (action == null) {
126             xmlTemplateDocument.setData("FILENAME", cms.getSitePath(file));
127         }
128         // process the selected template
129
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
130     }
131
132     /**
133      * Indicates if the results of this class are cacheable.
134      *
135      * @param cms CmsObject Object for accessing system resources
136      * @param templateFile Filename of the template file
137      * @param elementName Element name of this template in our parent template.
138      * @param parameters Hashtable with all template class parameters.
139      * @param templateSelector template section that should be processed.
140      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
141      */

142
143     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
144             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
145         return false;
146     }
147 }
148
Popular Tags