Source Code Cross Referenced for CmsSendEmailDialog.java in  » Content-Management-System » opencms » org » opencms » workplace » tools » workplace » broadcast » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » org.opencms.workplace.tools.workplace.broadcast 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/broadcast/CmsSendEmailDialog.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:53 $
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.workplace.broadcast;
033:
034:        import org.opencms.file.CmsUser;
035:        import org.opencms.jsp.CmsJspActionElement;
036:        import org.opencms.main.CmsIllegalStateException;
037:        import org.opencms.main.CmsLog;
038:        import org.opencms.main.CmsSessionInfo;
039:        import org.opencms.main.OpenCms;
040:        import org.opencms.util.CmsStringUtil;
041:        import org.opencms.widgets.CmsDisplayWidget;
042:        import org.opencms.widgets.CmsInputWidget;
043:        import org.opencms.widgets.CmsTextareaWidget;
044:        import org.opencms.workplace.CmsWidgetDialogParameter;
045:
046:        import java.util.ArrayList;
047:        import java.util.Collections;
048:        import java.util.Iterator;
049:        import java.util.List;
050:
051:        import javax.servlet.http.HttpServletRequest;
052:        import javax.servlet.http.HttpServletResponse;
053:        import javax.servlet.jsp.PageContext;
054:
055:        import org.apache.commons.logging.Log;
056:
057:        /**
058:         * Dialog to edit an email to send in the administration view.<p>
059:         * 
060:         * @author Michael Moossen 
061:         * 
062:         * @version $Revision: 1.13 $ 
063:         * 
064:         * @since 6.0.0 
065:         */
066:        public class CmsSendEmailDialog extends A_CmsMessageDialog {
067:
068:            /** localized messages Keys prefix. */
069:            public static final String KEY_PREFIX = "email";
070:
071:            /** The static log object for this class. */
072:            private static final Log LOG = CmsLog
073:                    .getLog(CmsSendEmailDialog.class);
074:
075:            /** a warning about excluded users with no email. */
076:            private String m_excludedUsers = "";
077:
078:            /**
079:             * Public constructor with JSP action element.<p>
080:             * 
081:             * @param jsp an initialized JSP action element
082:             */
083:            public CmsSendEmailDialog(CmsJspActionElement jsp) {
084:
085:                super (jsp);
086:            }
087:
088:            /**
089:             * Public constructor with JSP variables.<p>
090:             * 
091:             * @param context the JSP page context
092:             * @param req the JSP request
093:             * @param res the JSP response
094:             */
095:            public CmsSendEmailDialog(PageContext context,
096:                    HttpServletRequest req, HttpServletResponse res) {
097:
098:                this (new CmsJspActionElement(context, req, res));
099:            }
100:
101:            /**
102:             * Commits the edited project to the db.<p>
103:             */
104:            public void actionCommit() {
105:
106:                List errors = new ArrayList();
107:
108:                if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_msgInfo.getTo())) {
109:                    setCommitErrors(Collections
110:                            .singletonList(new CmsIllegalStateException(
111:                                    Messages
112:                                            .get()
113:                                            .container(
114:                                                    Messages.ERR_NO_SELECTED_USER_WITH_EMAIL_0))));
115:                    return;
116:                }
117:                try {
118:                    m_msgInfo.setTo(getEmailAddresses());
119:                    m_msgInfo.sendEmail(getCms());
120:                } catch (Throwable t) {
121:                    errors.add(t);
122:                } finally {
123:                    m_msgInfo.setTo(getToNames());
124:                }
125:                // set the list of errors to display when saving failed
126:                setCommitErrors(errors);
127:            }
128:
129:            /**
130:             * Returns a warning if users have been excluded.<p>
131:             * 
132:             * @return a warning
133:             */
134:            public String getExcludedUsers() {
135:
136:                return m_excludedUsers;
137:            }
138:
139:            /**
140:             * Sets the warning message if users have been excluded.<p>
141:             * 
142:             * @param excludedUsers the warning message
143:             */
144:            public void setExcludedUsers(String excludedUsers) {
145:
146:                m_excludedUsers = excludedUsers;
147:            }
148:
149:            /**
150:             * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
151:             */
152:            protected String createDialogHtml(String dialog) {
153:
154:                StringBuffer result = new StringBuffer(1024);
155:
156:                result.append(createWidgetTableStart());
157:                // show error header once if there were validation errors
158:                result.append(createWidgetErrorHeader());
159:
160:                int n = 4;
161:                getToNames(); // need it to fill the exclude users property 
162:                if (CmsStringUtil
163:                        .isNotEmptyOrWhitespaceOnly(getExcludedUsers())) {
164:                    n++;
165:                }
166:                if (dialog.equals(PAGES[0])) {
167:                    // create the widgets for the first dialog page
168:                    result
169:                            .append(dialogBlockStart(key(Messages.GUI_MESSAGE_EDITOR_LABEL_HEADER_BLOCK_0)));
170:                    result.append(createWidgetTableStart());
171:                    result.append(createDialogRowsHtml(0, n - 1));
172:                    result.append(createWidgetTableEnd());
173:                    result.append(dialogBlockEnd());
174:                    result
175:                            .append(dialogBlockStart(key(Messages.GUI_MESSAGE_EDITOR_LABEL_CONTENT_BLOCK_0)));
176:                    result.append(createWidgetTableStart());
177:                    result.append(createDialogRowsHtml(n, n));
178:                    result.append(createWidgetTableEnd());
179:                    result.append(dialogBlockEnd());
180:                }
181:
182:                result.append(createWidgetTableEnd());
183:                return result.toString();
184:            }
185:
186:            /**
187:             * Creates the list of widgets for this dialog.<p>
188:             */
189:            protected void defineWidgets() {
190:
191:                // initialize the project object to use for the dialog
192:                initMessageObject();
193:
194:                setKeyPrefix(KEY_PREFIX);
195:
196:                addWidget(new CmsWidgetDialogParameter(m_msgInfo, "from",
197:                        PAGES[0], new CmsDisplayWidget()));
198:                if (CmsStringUtil
199:                        .isNotEmptyOrWhitespaceOnly(getExcludedUsers())) {
200:                    addWidget(new CmsWidgetDialogParameter(this ,
201:                            "excludedUsers", PAGES[0], new CmsDisplayWidget()));
202:                }
203:                addWidget(new CmsWidgetDialogParameter(m_msgInfo, "to",
204:                        PAGES[0], new CmsDisplayWidget()));
205:                addWidget(new CmsWidgetDialogParameter(m_msgInfo, "cc",
206:                        PAGES[0], "", new CmsInputWidget(), 0, 1));
207:                addWidget(new CmsWidgetDialogParameter(m_msgInfo, "subject",
208:                        PAGES[0], new CmsInputWidget()));
209:                addWidget(new CmsWidgetDialogParameter(m_msgInfo, "msg",
210:                        PAGES[0], new CmsTextareaWidget(12)));
211:            }
212:
213:            /**
214:             * Returns a semicolon separated list of user names.<p>
215:             * 
216:             * @return a semicolon separated list of user names
217:             */
218:            protected String getToNames() {
219:
220:                List excluded = new ArrayList();
221:                List users = new ArrayList();
222:                Iterator itIds = idsList().iterator();
223:                while (itIds.hasNext()) {
224:                    String id = itIds.next().toString();
225:                    CmsSessionInfo session = OpenCms.getSessionManager()
226:                            .getSessionInfo(id);
227:                    if (session != null) {
228:                        try {
229:                            CmsUser user = getCms().readUser(
230:                                    session.getUserId());
231:                            String userName = user.getFullName();
232:                            if (!users.contains(userName)) {
233:                                String emailAddress = user.getEmail();
234:                                if (CmsStringUtil
235:                                        .isNotEmptyOrWhitespaceOnly(emailAddress)) {
236:                                    users.add(userName);
237:                                } else {
238:                                    excluded.add(userName);
239:                                }
240:                            }
241:                        } catch (Exception e) {
242:                            LOG.error(e.getLocalizedMessage(), e);
243:                        }
244:                    }
245:                }
246:                if (!excluded.isEmpty()) {
247:                    StringBuffer text = new StringBuffer(500);
248:                    text.append(Messages.get().container(
249:                            Messages.GUI_EXCLUDED_USERS_WARNING_0).key(
250:                            getLocale()));
251:                    text.append("\n");
252:                    Iterator it = excluded.iterator();
253:                    while (it.hasNext()) {
254:                        text.append("- ");
255:                        text.append(it.next());
256:                        text.append("\n");
257:                    }
258:                    setExcludedUsers(text.toString());
259:                }
260:                if (users.isEmpty()) {
261:                    setCommitErrors(Collections
262:                            .singletonList(new CmsIllegalStateException(
263:                                    Messages
264:                                            .get()
265:                                            .container(
266:                                                    Messages.ERR_NO_SELECTED_USER_WITH_EMAIL_0))));
267:                    return "";
268:                }
269:                StringBuffer result = new StringBuffer(256);
270:                Iterator itUsers = users.iterator();
271:                while (itUsers.hasNext()) {
272:                    result.append(itUsers.next().toString());
273:                    if (itUsers.hasNext()) {
274:                        result.append("; ");
275:                    }
276:                }
277:                return result.toString();
278:            }
279:
280:            /**
281:             * Returns a semicolon separated list of email addresses.<p>
282:             * 
283:             * @return a semicolon separated list of email addresses
284:             */
285:            private String getEmailAddresses() {
286:
287:                List emails = new ArrayList();
288:                Iterator itIds = idsList().iterator();
289:                while (itIds.hasNext()) {
290:                    String id = itIds.next().toString();
291:                    CmsSessionInfo session = OpenCms.getSessionManager()
292:                            .getSessionInfo(id);
293:                    if (session != null) {
294:                        try {
295:                            String emailAddress = getCms().readUser(
296:                                    session.getUserId()).getEmail();
297:                            if (CmsStringUtil
298:                                    .isNotEmptyOrWhitespaceOnly(emailAddress)
299:                                    && !emails.contains(emailAddress)) {
300:                                emails.add(emailAddress);
301:                            }
302:                        } catch (Exception e) {
303:                            LOG.error(e.getLocalizedMessage(), e);
304:                        }
305:                    }
306:                }
307:                StringBuffer result = new StringBuffer(256);
308:                Iterator itEmails = emails.iterator();
309:                while (itEmails.hasNext()) {
310:                    result.append(itEmails.next().toString());
311:                    if (itEmails.hasNext()) {
312:                        result.append("; ");
313:                    }
314:                }
315:                return result.toString();
316:            }
317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.