KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > notification > CmsPublishNotification


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/notification/CmsPublishNotification.java,v $
3  * Date : $Date: 2006/11/29 16:31:26 $
4  * Version: $Revision: 1.3 $
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.notification;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsUser;
36 import org.opencms.report.I_CmsReport;
37
38 import java.util.Iterator JavaDoc;
39 import java.util.List JavaDoc;
40
41 /**
42  * Class to send a notification to an OpenCms user with a summary of warnings and
43  * errors occured while publishing the project.<p>
44  *
45  * @author Peter Bonrad
46  *
47  * @version $Revision: 1.3 $
48  *
49  * @since 6.5.3
50  */

51 public class CmsPublishNotification extends A_CmsNotification {
52
53     /** The path to the xml content with the subject, header and footer of the notification e-mail.<p> */
54     public static final String JavaDoc NOTIFICATION_CONTENT = "/system/workplace/admin/notification/publish-notification";
55
56     /** The report containing the errors and warnings to put into the notification. */
57     private I_CmsReport m_report;
58
59     /**
60      * Creates a new CmsPublishNotification.<p>
61      *
62      * @param cms the cms object to use
63      * @param receiver the cms user who should receive the message
64      * @param report the report of the publishing which should be included in the message
65      */

66     public CmsPublishNotification(CmsObject cms, CmsUser receiver, I_CmsReport report) {
67
68         super(cms, receiver);
69         m_report = report;
70     }
71
72     /**
73      * @see org.opencms.notification.A_CmsNotification#generateHtmlMsg()
74      */

75     protected String JavaDoc generateHtmlMsg() {
76
77         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
78
79         // add warnings to the notification
80
if (m_report.hasWarning()) {
81             buffer.append("<b>");
82             buffer.append(Messages.get().getBundle().key(Messages.GUI_PUBLISH_WARNING_HEADER_0));
83             buffer.append("</b><br/>\n");
84             appendList(buffer, m_report.getWarnings());
85             buffer.append("<br/>\n");
86         }
87
88         // add errors to the notification
89
if (m_report.hasError()) {
90             buffer.append("<b>");
91             buffer.append(Messages.get().getBundle().key(Messages.GUI_PUBLISH_ERROR_HEADER_0));
92             buffer.append("</b><br/>\n");
93             appendList(buffer, m_report.getErrors());
94             buffer.append("<br/>\n");
95         }
96
97         return buffer.toString();
98     }
99
100     /**
101      * @see org.opencms.notification.A_CmsNotification#getNotificationContent()
102      */

103     protected String JavaDoc getNotificationContent() {
104
105         return NOTIFICATION_CONTENT;
106     }
107
108     /**
109      * Appends the contents of a list to the buffer with every entry in a new line.<p>
110      *
111      * @param buffer The buffer were the entries of the list will be appended.
112      * @param list The list with the entries to append to the buffer.
113      */

114     private void appendList(StringBuffer JavaDoc buffer, List JavaDoc list) {
115
116         Iterator JavaDoc iter = list.iterator();
117         while (iter.hasNext()) {
118             String JavaDoc entry = (String JavaDoc)iter.next();
119             buffer.append(entry + "<br/>\n");
120         }
121     }
122
123 }
124
Popular Tags