KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminProjectDelete.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
4 * Version: $Revision: 1.3 $
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.file.CmsObject;
32 import org.opencms.file.CmsProject;
33 import org.opencms.main.CmsException;
34 import org.opencms.main.CmsLog;
35 import org.opencms.report.A_CmsReportThread;
36 import org.opencms.workplace.threads.CmsProjectDeleteThread;
37
38 import com.opencms.core.I_CmsSession;
39 import com.opencms.legacy.CmsXmlTemplateLoader;
40
41 import java.util.Hashtable JavaDoc;
42
43 /**
44  * Template class for displaying OpenCms workplace admin project resent.
45  * <P>
46  *
47  * @author Andreas Schouten
48  * @version $Revision: 1.3 $ $Date: 2005/06/27 23:22:07 $
49  * @see com.opencms.workplace.CmsXmlWpTemplateFile
50  *
51  * @deprecated Will not be supported past the OpenCms 6 release.
52  */

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

69
70     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters,
71             String JavaDoc templateSelector) throws CmsException {
72         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
73             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
74             CmsLog.getLog(this).debug("Template file is: " + templateFile);
75             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
76         }
77         CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms,
78                 templateFile, elementName, parameters, templateSelector);
79
80         CmsProject project = null;
81         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
82         String JavaDoc action = (String JavaDoc)parameters.get("action");
83         String JavaDoc projectId = (String JavaDoc)parameters.get("projectid");
84         if(projectId == null || "".equals(projectId)){
85             projectId = (String JavaDoc)session.getValue("delprojectid");
86         } else {
87             session.putValue("delprojectid", projectId);
88         }
89         if(parameters.get("ok") != null) {
90             if(action == null){
91                 // start the deleting
92
A_CmsReportThread doDelete = new CmsProjectDeleteThread(cms, Integer.parseInt(projectId));
93                 doDelete.start();
94                 session.putValue(C_DELETE_THREAD, doDelete);
95                 xmlTemplateDocument.setData("time", "10");
96                 templateSelector = "wait";
97             } else if("working".equals(action)) {
98                 // still working?
99
A_CmsReportThread doDelete = (A_CmsReportThread)session.getValue(C_DELETE_THREAD);
100                 if(doDelete.isAlive()) {
101                     String JavaDoc time = (String JavaDoc)parameters.get("time");
102                     int wert = Integer.parseInt(time);
103                     wert += 2;
104                     xmlTemplateDocument.setData("time", "" + wert);
105                     templateSelector = "wait";
106                 } else {
107                     // thread has come to an end, was there an error?
108
Throwable JavaDoc error = doDelete.getError();
109                     if(error == null) {
110                         // clear the languagefile cache
111
templateSelector = "done";
112                         if (cms.getRequestContext().currentProject().getId() == CmsProject.ONLINE_PROJECT_ID) {
113                             // in online project, submit the head project selector with "Online" selected to avoid an infinite loop
114
xmlTemplateDocument.setData("onlineId", "" + CmsProject.ONLINE_PROJECT_ID);
115                             xmlTemplateDocument.setData("switchjavascript", xmlTemplateDocument.getProcessedDataValue("switchheadproject"));
116                         } else {
117                             // in an offline project, the javascript for setting the project is not needed
118
xmlTemplateDocument.setData("switchjavascript", xmlTemplateDocument.getProcessedDataValue("dontswitchheadproject"));
119                         }
120                         session.removeValue("delprojectid");
121                     } else {
122                         // get errorpage
123
xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(error));
124                         templateSelector = "error";
125                         session.removeValue("delprojectid");
126                     }
127                 }
128             }
129         } else {
130             // show details about the project
131
project = cms.readProject(Integer.parseInt(projectId));
132             
133             // set project to online project if current project is the one which will be deleted
134
if (project.getId() == cms.getRequestContext().currentProject().getId()) {
135                 cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
136             }
137             
138             CmsXmlLanguageFile lang = xmlTemplateDocument.getLanguageFile();
139             CmsProjectlist.setListEntryData(cms, lang, xmlTemplateDocument, project);
140
141         // Now load the template file and start the processing
142
}
143         return startProcessing(cms, xmlTemplateDocument, elementName, parameters,
144                 templateSelector);
145     }
146
147     /**
148      * Indicates if the results of this class are cacheable.
149      *
150      * @param cms CmsObject Object for accessing system resources
151      * @param templateFile Filename of the template file
152      * @param elementName Element name of this template in our parent template.
153      * @param parameters Hashtable with all template class parameters.
154      * @param templateSelector template section that should be processed.
155      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
156      */

157
158     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
159             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
160         return false;
161     }
162 }
163
Popular Tags