KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > projects > CmsPublishProjectReport


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/projects/CmsPublishProjectReport.java,v $
3  * Date : $Date: 2006/10/10 09:07:47 $
4  * Version: $Revision: 1.10 $
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.tools.projects;
33
34 import org.opencms.db.CmsPublishList;
35 import org.opencms.file.CmsProject;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsRuntimeException;
39 import org.opencms.util.CmsStringUtil;
40 import org.opencms.workplace.CmsReport;
41 import org.opencms.workplace.CmsWorkplaceSettings;
42 import org.opencms.workplace.commons.Messages;
43 import org.opencms.workplace.threads.CmsPublishThread;
44 import org.opencms.workplace.threads.CmsXmlDocumentLinkValidatorThread;
45
46 import javax.servlet.http.HttpServletRequest JavaDoc;
47 import javax.servlet.http.HttpServletResponse JavaDoc;
48 import javax.servlet.jsp.JspException JavaDoc;
49 import javax.servlet.jsp.PageContext JavaDoc;
50
51 /**
52  * Provides a report for publishing a project.<p>
53  *
54  * @author Michael Moossen
55  * @author Peter Bonrad
56  *
57  * @version $Revision: 1.10 $
58  *
59  * @since 6.0.0
60  */

61 public class CmsPublishProjectReport extends CmsReport {
62
63     /** Request parameter name for the project id. */
64     public static final String JavaDoc PARAM_PROJECTID = "projectid";
65
66     /** list of project id. */
67     private String JavaDoc m_paramProjectid;
68
69     /**
70      * Public constructor with JSP action element.<p>
71      *
72      * @param jsp an initialized JSP action element
73      */

74     public CmsPublishProjectReport(CmsJspActionElement jsp) {
75
76         super(jsp);
77     }
78
79     /**
80      * Public constructor with JSP variables.<p>
81      *
82      * @param context the JSP page context
83      * @param req the JSP request
84      * @param res the JSP response
85      */

86     public CmsPublishProjectReport(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
87
88         this(new CmsJspActionElement(context, req, res));
89     }
90
91     /**
92      * Performs the dialog actions depending on the initialized action.<p>
93      *
94      * @throws JspException if dialog actions fail
95      */

96     public void displayReport() throws JspException JavaDoc {
97
98         // save initialized instance of this class in request attribute for included sub-elements
99
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
100         switch (getAction()) {
101             case ACTION_REPORT_END:
102                 actionCloseDialog();
103                 break;
104             case ACTION_CANCEL:
105                 actionCloseDialog();
106                 break;
107             case ACTION_REPORT_UPDATE:
108                 setParamAction(REPORT_UPDATE);
109                 getJsp().include(FILE_REPORT_OUTPUT);
110                 break;
111             case ACTION_REPORT_BEGIN:
112             case ACTION_CONFIRMED:
113             case ACTION_DEFAULT:
114             default:
115                 try {
116                     if (getCms().readProject(new Integer JavaDoc(getParamProjectid()).intValue()).getType() == CmsProject.PROJECT_TYPE_TEMPORARY) {
117                         // set the flag that this is a temporary project
118
setParamRefreshWorkplace(CmsStringUtil.TRUE);
119                     }
120                 } catch (Exception JavaDoc e) {
121                     // ignore
122
}
123
124                 CmsPublishList list = null;
125                 try {
126                     CmsProject currentProject = getCms().getRequestContext().currentProject();
127                     getCms().getRequestContext().setCurrentProject(
128                         getCms().readProject(new Integer JavaDoc(getParamProjectid()).intValue()));
129                     list = getCms().getPublishList();
130                     getCms().getRequestContext().setCurrentProject(currentProject);
131                 } catch (CmsException e) {
132                     throw new CmsRuntimeException(e.getMessageContainer(), e);
133                 }
134
135                 // start validation check
136
startValidationThread(list);
137                 getJsp().include(FILE_REPORT_OUTPUT);
138         }
139     }
140
141     /**
142      * Gets the project id parameter.<p>
143      *
144      * @return the project id parameter
145      */

146     public String JavaDoc getParamProjectid() {
147
148         return m_paramProjectid;
149     }
150
151     /**
152      * Sets the project id parameter.<p>
153      *
154      * @param projectId the project id parameter
155      */

156     public void setParamProjectid(String JavaDoc projectId) {
157
158         m_paramProjectid = projectId;
159     }
160
161     /**
162      * @see org.opencms.workplace.list.A_CmsListReport#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
163      */

164     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
165
166         // fill the parameter values in the get/set methods
167
fillParamValues(request);
168
169         if (REPORT_UPDATE.equals(getParamAction())) {
170             setAction(ACTION_REPORT_UPDATE);
171         } else if (REPORT_BEGIN.equals(getParamAction())) {
172             setAction(ACTION_REPORT_BEGIN);
173         } else if (REPORT_END.equals(getParamAction())) {
174             if (Boolean.valueOf(getParamThreadHasNext()).booleanValue()) {
175                 // after the link check start the publish thread
176
startPublishThread();
177             } else {
178                 // ends the publish thread
179
setAction(ACTION_REPORT_END);
180             }
181         } else if (DIALOG_CANCEL.equals(getParamAction())) {
182             setAction(ACTION_CANCEL);
183         } else {
184             // set the default action
185
setAction(ACTION_DEFAULT);
186         }
187     }
188
189     /**
190      * Starts the publish thread for the project.<p>
191      */

192     private void startPublishThread() {
193
194         // create a publish thread from the current publish list
195
CmsPublishList publishList = getSettings().getPublishList();
196         CmsPublishThread thread = new CmsPublishThread(getCms(), publishList, getSettings());
197
198         // set the new thread id and flag that no thread is following
199
setParamThread(thread.getUUID().toString());
200         setParamThreadHasNext(CmsStringUtil.FALSE);
201
202         setParamAction(REPORT_UPDATE);
203         setAction(ACTION_REPORT_UPDATE);
204
205         // start the publish thread
206
thread.start();
207     }
208
209     /**
210      * Starts the link validation thread for the project.<p>
211      */

212     private void startValidationThread(CmsPublishList publishList) throws JspException JavaDoc {
213
214         try {
215             CmsXmlDocumentLinkValidatorThread thread = new CmsXmlDocumentLinkValidatorThread(getCms(), publishList, getSettings());
216
217             setParamThread(thread.getUUID().toString());
218             setParamThreadHasNext(CmsStringUtil.TRUE);
219
220             setParamAction(REPORT_BEGIN);
221
222             // set the key name for the continue checkbox
223
setParamReportContinueKey(Messages.GUI_PUBLISH_CONTINUE_BROKEN_LINKS_0);
224         } catch (Throwable JavaDoc e) {
225
226             // error while link validation, show error screen
227
includeErrorpage(this, e);
228         }
229     }
230 }
231
Popular Tags