KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > threads > CmsModuleDeleteThread


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/threads/CmsModuleDeleteThread.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.12 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
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 Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.threads;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.CmsLog;
36 import org.opencms.main.OpenCms;
37 import org.opencms.module.CmsModuleManager;
38 import org.opencms.report.A_CmsReportThread;
39 import org.opencms.report.I_CmsReport;
40
41 import java.util.Collections JavaDoc;
42 import java.util.Iterator JavaDoc;
43 import java.util.List JavaDoc;
44
45 import org.apache.commons.logging.Log;
46
47 /**
48  * Deletes a module.<p>
49  *
50  * @author Alexander Kandzior
51  *
52  * @version $Revision: 1.12 $
53  *
54  * @since 6.0.0
55  */

56 public class CmsModuleDeleteThread extends A_CmsReportThread {
57
58     /** The log object for this class. */
59     private static final Log LOG = CmsLog.getLog(CmsModuleDeleteThread.class);
60
61     /** A list of module name to delete. */
62     private List JavaDoc m_moduleNames;
63
64     /** mode indicating if pre-replacement or final deletion. */
65     private boolean m_replaceMode;
66
67     /**
68      * Creates the module delete thread.<p>
69      *
70      * @param cms the current cms context
71      * @param moduleNames the name of the module
72      * @param replaceMode the replace mode
73      * @param old flag for report mode
74      */

75     public CmsModuleDeleteThread(CmsObject cms, List JavaDoc moduleNames, boolean replaceMode, boolean old) {
76
77         super(cms, Messages.get().getBundle().key(Messages.GUI_DELETE_MODULE_THREAD_NAME_1, moduleNames));
78         m_moduleNames = moduleNames;
79         m_replaceMode = replaceMode;
80         if (old) {
81             initOldHtmlReport(cms.getRequestContext().getLocale());
82         } else {
83             initHtmlReport(cms.getRequestContext().getLocale());
84         }
85         if (LOG.isDebugEnabled()) {
86             LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_CONSTRUCTED_0));
87         }
88     }
89
90     /**
91      * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
92      */

93     public String JavaDoc getReportUpdate() {
94
95         return getReport().getReportUpdate();
96     }
97
98     /**
99      * @see java.lang.Runnable#run()
100      */

101     public void run() {
102
103         I_CmsReport report = getReport();
104         try {
105             if (LOG.isDebugEnabled()) {
106                 LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_STARTED_0));
107             }
108             if (!m_replaceMode) {
109                 OpenCms.getModuleManager().checkModuleSelectionList(m_moduleNames, null, true);
110             }
111             m_moduleNames = CmsModuleManager.topologicalSort(m_moduleNames, null);
112             Collections.reverse(m_moduleNames);
113
114             Iterator JavaDoc j = m_moduleNames.iterator();
115             while (j.hasNext()) {
116                 String JavaDoc moduleName = (String JavaDoc)j.next();
117
118                 moduleName = moduleName.replace('\\', '/');
119
120                 // now delete the module
121
OpenCms.getModuleManager().deleteModule(getCms(), moduleName, m_replaceMode, report);
122             }
123
124             if (LOG.isDebugEnabled()) {
125                 LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_FINISHED_0));
126             }
127         } catch (Exception JavaDoc e) {
128             report.println(e);
129             LOG.error(Messages.get().getBundle().key(Messages.LOG_MODULE_DELETE_FAILED_1, m_moduleNames), e);
130         }
131     }
132 }
Popular Tags