KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/threads/CmsPublishThread.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.db.CmsPublishList;
35 import org.opencms.file.CmsObject;
36 import org.opencms.file.CmsProject;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsLog;
39 import org.opencms.main.CmsSessionInfo;
40 import org.opencms.main.CmsSessionManager;
41 import org.opencms.main.OpenCms;
42 import org.opencms.report.A_CmsReportThread;
43 import org.opencms.report.I_CmsReport;
44 import org.opencms.workplace.CmsWorkplaceSettings;
45
46 import java.util.Iterator JavaDoc;
47 import java.util.List JavaDoc;
48
49 import org.apache.commons.logging.Log;
50
51 /**
52  * Publishes a resource or the users current project.<p>
53  *
54  * @author Alexander Kandzior
55  *
56  * @version $Revision: 1.8 $
57  *
58  * @since 6.0.0
59  */

60 public class CmsPublishThread extends A_CmsReportThread {
61
62     /** The log object for this class. */
63     private static final Log LOG = CmsLog.getLog(CmsPublishThread.class);
64
65     /** The CmsObject used to start this thread. */
66     private CmsObject m_cms;
67
68     /** The list of resources to publish. */
69     private CmsPublishList m_publishList;
70
71     /** The workplace settings of the current user. */
72     private CmsWorkplaceSettings m_settings;
73
74     /** Flag for updating the user info. */
75     private boolean m_updateSessionInfo;
76
77     /**
78      * Creates a Thread that publishes the Cms resources contained in the specified Cms publish
79      * list.<p>
80      *
81      * @param cms the current OpenCms context object
82      * @param publishList a Cms publish list
83      * @param settings the workplace settings of the current user
84      * @see org.opencms.file.CmsObject#getPublishList(org.opencms.file.CmsResource, boolean)
85      * @see org.opencms.file.CmsObject#getPublishList()
86      */

87     public CmsPublishThread(CmsObject cms, CmsPublishList publishList, CmsWorkplaceSettings settings) {
88
89         super(cms, Messages.get().getBundle().key(Messages.GUI_PUBLISH_TRHEAD_NAME_0));
90         m_cms = cms;
91         m_publishList = publishList;
92         m_settings = settings;
93
94         // if the project to publish is a temporary project, we have to update the
95
// user info after publishing
96
if (m_cms.getRequestContext().currentProject().getType() == CmsProject.PROJECT_TYPE_TEMPORARY) {
97             m_updateSessionInfo = true;
98         } else {
99             m_updateSessionInfo = false;
100         }
101
102         initHtmlReport(cms.getRequestContext().getLocale());
103     }
104
105     /**
106      * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
107      */

108     public String JavaDoc getReportUpdate() {
109
110         return getReport().getReportUpdate();
111     }
112
113     /**
114      * @see java.lang.Runnable#run()
115      */

116     public void run() {
117
118         try {
119             getReport().println(
120                 Messages.get().container(Messages.RPT_PUBLISH_RESOURCE_BEGIN_0),
121                 I_CmsReport.FORMAT_HEADLINE);
122             getCms().publishProject(getReport(), m_publishList);
123             if (m_updateSessionInfo) {
124                 updateSessionInfo();
125             }
126             getReport().println(
127                 Messages.get().container(Messages.RPT_PUBLISH_RESOURCE_END_0),
128                 I_CmsReport.FORMAT_HEADLINE);
129         } catch (Exception JavaDoc e) {
130             getReport().println(e);
131             LOG.error(Messages.get().getBundle().key(Messages.LOG_PUBLISH_PROJECT_FAILED_0), e);
132         }
133     }
134
135     /**
136      * Updates the project information in the user session and the workplace settings
137      * after a temporary project is published and deleted.<p>
138      *
139      * This is nescessary to prevent the access to a nonexisting project.<p>
140      */

141     private void updateSessionInfo() {
142
143         // get the session menager
144
CmsSessionManager sessionManager = OpenCms.getSessionManager();
145
146         // get all sessions
147
List userSessions = sessionManager.getSessionInfos();
148         Iterator JavaDoc i = userSessions.iterator();
149         while (i.hasNext()) {
150             CmsSessionInfo sessionInfo = (CmsSessionInfo)i.next();
151             // check is the project stored in this session is not existing anymore
152
// if so, set it to the online project
153
int projectId = sessionInfo.getProject();
154             try {
155                 m_cms.readProject(projectId);
156             } catch (CmsException e) {
157                 // the project does not longer exist, update the project information with the online project
158
sessionInfo.setProject(CmsProject.ONLINE_PROJECT_ID);
159                 // update the workplace settings as well
160
m_settings.setProject(CmsProject.ONLINE_PROJECT_ID);
161                 getReport().println(
162                     Messages.get().container(
163                         Messages.RPT_PUBLISH_RESOURCE_SWITCH_PROJECT_1,
164                         m_cms.getRequestContext().currentProject().getName()),
165                     I_CmsReport.FORMAT_DEFAULT);
166             }
167         }
168     }
169 }
Popular Tags