001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/projects/CmsPublishProjectReport.java,v $
003: * Date : $Date: 2008-02-27 12:05:51 $
004: * Version: $Revision: 1.13 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.projects;
033:
034: import org.opencms.db.CmsPublishList;
035: import org.opencms.file.CmsProject;
036: import org.opencms.jsp.CmsJspActionElement;
037: import org.opencms.main.CmsException;
038: import org.opencms.main.CmsRuntimeException;
039: import org.opencms.main.OpenCms;
040: import org.opencms.report.CmsHtmlReport;
041: import org.opencms.util.CmsStringUtil;
042: import org.opencms.util.CmsUUID;
043: import org.opencms.workplace.CmsReport;
044: import org.opencms.workplace.CmsWorkplaceSettings;
045: import org.opencms.workplace.commons.Messages;
046: import org.opencms.workplace.threads.CmsRelationsValidatorThread;
047:
048: import javax.servlet.http.HttpServletRequest;
049: import javax.servlet.http.HttpServletResponse;
050: import javax.servlet.jsp.JspException;
051: import javax.servlet.jsp.PageContext;
052:
053: /**
054: * Provides a report for publishing a project.<p>
055: *
056: * @author Michael Moossen
057: * @author Peter Bonrad
058: *
059: * @version $Revision: 1.13 $
060: *
061: * @since 6.0.0
062: */
063: public class CmsPublishProjectReport extends CmsReport {
064:
065: /** Request parameter name for the project id. */
066: public static final String PARAM_PROJECTID = "projectid";
067:
068: /** list of project id. */
069: private String m_paramProjectid;
070:
071: /**
072: * Public constructor with JSP action element.<p>
073: *
074: * @param jsp an initialized JSP action element
075: */
076: public CmsPublishProjectReport(CmsJspActionElement jsp) {
077:
078: super (jsp);
079: }
080:
081: /**
082: * Public constructor with JSP variables.<p>
083: *
084: * @param context the JSP page context
085: * @param req the JSP request
086: * @param res the JSP response
087: */
088: public CmsPublishProjectReport(PageContext context,
089: HttpServletRequest req, HttpServletResponse res) {
090:
091: this (new CmsJspActionElement(context, req, res));
092: }
093:
094: /**
095: * Performs the dialog actions depending on the initialized action.<p>
096: *
097: * @throws JspException if dialog actions fail
098: */
099: public void displayReport() throws JspException {
100:
101: // save initialized instance of this class in request attribute for included sub-elements
102: getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS,
103: this );
104: switch (getAction()) {
105: case ACTION_REPORT_END:
106: actionCloseDialog();
107: break;
108: case ACTION_CANCEL:
109: actionCloseDialog();
110: break;
111: case ACTION_REPORT_UPDATE:
112: setParamAction(REPORT_UPDATE);
113: getJsp().include(FILE_REPORT_OUTPUT);
114: break;
115: case ACTION_REPORT_BEGIN:
116: case ACTION_CONFIRMED:
117: case ACTION_DEFAULT:
118: default:
119: try {
120: if (getCms().readProject(
121: new CmsUUID(getParamProjectid())).getType() == CmsProject.PROJECT_TYPE_TEMPORARY) {
122: // set the flag that this is a temporary project
123: setParamRefreshWorkplace(CmsStringUtil.TRUE);
124: }
125: } catch (Exception e) {
126: // ignore
127: }
128:
129: CmsPublishList list = null;
130: try {
131: CmsProject currentProject = getCms()
132: .getRequestContext().currentProject();
133: getCms().getRequestContext().setCurrentProject(
134: getCms().readProject(
135: new CmsUUID(getParamProjectid())));
136: list = OpenCms.getPublishManager().getPublishList(
137: getCms());
138: getCms().getRequestContext().setCurrentProject(
139: currentProject);
140: } catch (CmsException e) {
141: throw new CmsRuntimeException(e.getMessageContainer(),
142: e);
143: }
144:
145: // start validation check
146: startValidationThread(list);
147: getJsp().include(FILE_REPORT_OUTPUT);
148: }
149: }
150:
151: /**
152: * Gets the project id parameter.<p>
153: *
154: * @return the project id parameter
155: */
156: public String getParamProjectid() {
157:
158: return m_paramProjectid;
159: }
160:
161: /**
162: * Sets the project id parameter.<p>
163: *
164: * @param projectId the project id parameter
165: */
166: public void setParamProjectid(String projectId) {
167:
168: m_paramProjectid = projectId;
169: }
170:
171: /**
172: * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
173: */
174: protected void initWorkplaceRequestValues(
175: CmsWorkplaceSettings settings, HttpServletRequest request) {
176:
177: // fill the parameter values in the get/set methods
178: fillParamValues(request);
179:
180: if (REPORT_UPDATE.equals(getParamAction())) {
181: setAction(ACTION_REPORT_UPDATE);
182: } else if (REPORT_BEGIN.equals(getParamAction())) {
183: setAction(ACTION_REPORT_BEGIN);
184: } else if (REPORT_END.equals(getParamAction())) {
185: if (Boolean.valueOf(getParamThreadHasNext()).booleanValue()) {
186: // after the link check start the publish thread
187: startPublishThread();
188: } else {
189: // ends the publish thread
190: setAction(ACTION_REPORT_END);
191: }
192: } else if (DIALOG_CANCEL.equals(getParamAction())) {
193: setAction(ACTION_CANCEL);
194: } else {
195: // set the default action
196: setAction(ACTION_DEFAULT);
197: }
198: }
199:
200: /**
201: * Starts the publish thread for the project.<p>
202: */
203: private void startPublishThread() {
204:
205: // create a publish thread from the current publish list
206: CmsPublishList publishList = getSettings().getPublishList();
207: try {
208: OpenCms.getPublishManager().publishProject(
209: getCms(),
210: new CmsHtmlReport(getLocale(), getCms()
211: .getRequestContext().getSiteRoot()),
212: publishList);
213: } catch (CmsException e) {
214: throw new CmsRuntimeException(e.getMessageContainer());
215: }
216: setParamAction(REPORT_END);
217: setAction(ACTION_REPORT_END);
218: setParamThreadHasNext(CmsStringUtil.FALSE);
219: }
220:
221: /**
222: * Starts the link validation thread for the project.<p>
223: *
224: * @param publishList the list of resources to publish
225: *
226: * @throws JspException if something goes wrong
227: */
228: private void startValidationThread(CmsPublishList publishList)
229: throws JspException {
230:
231: try {
232: CmsRelationsValidatorThread thread = new CmsRelationsValidatorThread(
233: getCms(), publishList, getSettings());
234: thread.start();
235:
236: setParamThread(thread.getUUID().toString());
237: setParamThreadHasNext(CmsStringUtil.TRUE);
238:
239: setParamAction(REPORT_BEGIN);
240:
241: // set the key name for the continue checkbox
242: setParamReportContinueKey(Messages.GUI_PUBLISH_CONTINUE_BROKEN_LINKS_0);
243: } catch (Throwable e) {
244: // error while link validation, show error screen
245: includeErrorpage(this, e);
246: }
247: }
248: }
|