KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/threads/CmsModuleReplaceThread.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.8 $
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.report.A_CmsReportThread;
38
39 import java.util.ArrayList JavaDoc;
40 import java.util.List JavaDoc;
41 import java.util.Vector JavaDoc;
42
43 import org.apache.commons.logging.Log;
44
45 /**
46  * Replaces a module.<p>
47  *
48  * @author Alexander Kandzior
49  * @author Thomas Weckert
50  *
51  * @version $Revision: 1.8 $
52  *
53  * @since 6.0.0
54  */

55 public class CmsModuleReplaceThread extends A_CmsReportThread {
56
57     /** The log object for this class. */
58     private static final Log LOG = CmsLog.getLog(CmsModuleReplaceThread.class);
59
60     private A_CmsReportThread m_deleteThread;
61     private A_CmsReportThread m_importThread;
62     private String JavaDoc m_moduleName;
63     private int m_phase;
64     private String JavaDoc m_reportContent;
65     private String JavaDoc m_zipName;
66
67     /**
68      * Creates the module replace thread.<p>
69      * @param cms the current cms context
70      * @param moduleName the name of the module
71      * @param zipName the name of the module ZIP file
72      * @param old flag for report mode
73      */

74     public CmsModuleReplaceThread(CmsObject cms, String JavaDoc moduleName, String JavaDoc zipName, boolean old) {
75
76         super(cms, Messages.get().getBundle().key(Messages.GUI_REPLACE_MODULE_THREAD_NAME_1, moduleName));
77         m_moduleName = moduleName;
78         m_zipName = zipName;
79
80         List JavaDoc modules = new ArrayList JavaDoc();
81         modules.add(m_moduleName);
82         m_deleteThread = new CmsModuleDeleteThread(getCms(), modules, true, old);
83         m_importThread = new CmsDatabaseImportThread(getCms(), m_zipName, old);
84         if (LOG.isDebugEnabled()) {
85             LOG.debug(Messages.get().getBundle().key(Messages.LOG_REPLACE_THREAD_CONSTRUCTED_0));
86         }
87         m_phase = 0;
88     }
89
90     /**
91      * Collects all resource names belonging to a module in a Vector.<p>
92      *
93      * @param moduleName the name of the module
94      *
95      * @return Vector with path Strings of resources
96      */

97     public static Vector JavaDoc getModuleResources(String JavaDoc moduleName) {
98
99         Vector JavaDoc resNames = new Vector JavaDoc(OpenCms.getModuleManager().getModule(moduleName).getResources());
100         return resNames;
101     }
102
103     /**
104      * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
105      */

106     public String JavaDoc getReportUpdate() {
107
108         switch (m_phase) {
109             case 1:
110                 return m_deleteThread.getReportUpdate();
111             case 2:
112                 String JavaDoc content;
113                 if (m_reportContent != null) {
114                     content = m_reportContent;
115                     m_reportContent = null;
116                 } else {
117                     content = "";
118                 }
119                 return content + m_importThread.getReportUpdate();
120             default:
121         // noop
122
}
123         return "";
124     }
125
126     /**
127      * @see java.lang.Runnable#run()
128      */

129     public void run() {
130
131         if (LOG.isDebugEnabled()) {
132             LOG.debug(Messages.get().getBundle().key(Messages.LOG_REPLACE_THREAD_START_DELETE_0));
133         }
134         // phase 1: delete the existing module
135
m_phase = 1;
136         m_deleteThread.run();
137         // get remaining report contents
138
m_reportContent = m_deleteThread.getReportUpdate();
139         if (LOG.isDebugEnabled()) {
140             LOG.debug(Messages.get().getBundle().key(Messages.LOG_REPLACE_THREAD_START_IMPORT_0));
141         }
142         // phase 2: import the new module
143
m_phase = 2;
144         m_importThread.run();
145         if (LOG.isDebugEnabled()) {
146             LOG.debug(Messages.get().getBundle().key(Messages.LOG_REPLACE_THREAD_FINISHED_0));
147         }
148     }
149 }
Popular Tags