Source Code Cross Referenced for SiteEmailNotification.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » util » 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 » ERP CRM Financial » sakai » org.sakaiproject.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/event/tags/sakai_2-4-1/event-util/util/src/java/org/sakaiproject/util/SiteEmailNotification.java $
003:         * $Id: SiteEmailNotification.java 13804 2006-08-17 02:47:37Z ggolden@umich.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.util;
021:
022:        import java.util.List;
023:        import java.util.Vector;
024:
025:        import org.sakaiproject.alias.api.Alias;
026:        import org.sakaiproject.alias.cover.AliasService;
027:        import org.sakaiproject.authz.cover.SecurityService;
028:        import org.sakaiproject.component.cover.ServerConfigurationService;
029:        import org.sakaiproject.entity.api.Reference;
030:        import org.sakaiproject.entity.cover.EntityManager;
031:        import org.sakaiproject.event.api.Event;
032:        import org.sakaiproject.event.api.NotificationAction;
033:        import org.sakaiproject.event.cover.NotificationService;
034:        import org.sakaiproject.mailarchive.cover.MailArchiveService;
035:        import org.sakaiproject.site.api.Site;
036:        import org.sakaiproject.site.cover.SiteService;
037:
038:        /**
039:         * <p>
040:         * SiteEmailNotification is an EmailNotification that selects the site's participants (based on site access) as the recipients of the notification.
041:         * </p>
042:         * <p>
043:         * getRecipients() is satified here (although it can be customized by the extensions to this class).
044:         * </p>
045:         * <p>
046:         * The following should be specified to extend the class:
047:         * <ul>
048:         * <li>getResourceAbility() - to require an additional permission to qualify as a recipient (other than site membership)</li>
049:         * <li>addSpecialRecipients() - to add other recipients</li>
050:         * </ul>
051:         * </p>
052:         */
053:        public class SiteEmailNotification extends EmailNotification {
054:            /**
055:             * Construct.
056:             */
057:            public SiteEmailNotification() {
058:            }
059:
060:            /**
061:             * Construct.
062:             * 
063:             * @param siteId
064:             *        The id of the site whose users will get a mailing.
065:             */
066:            public SiteEmailNotification(String siteId) {
067:                super (siteId);
068:            }
069:
070:            /**
071:             * @inheritDoc
072:             */
073:            public NotificationAction getClone() {
074:                SiteEmailNotification clone = new SiteEmailNotification();
075:                clone.set(this );
076:
077:                return clone;
078:            }
079:
080:            /**
081:             * @inheritDoc
082:             */
083:            protected List getRecipients(Event event) {
084:                // get the resource reference
085:                Reference ref = EntityManager.newReference(event.getResource());
086:
087:                // use either the configured site, or if not configured, the site (context) of the resource
088:                String siteId = (getSite() != null) ? getSite() : ref
089:                        .getContext();
090:
091:                // if the site is published, use the list of users who can SITE_VISIT the site,
092:                // else use the list of users who can SITE_VISIT_UNP the site.
093:                try {
094:                    Site site = SiteService.getSite(siteId);
095:                    String ability = SiteService.SITE_VISIT;
096:                    if (!site.isPublished()) {
097:                        ability = SiteService.SITE_VISIT_UNPUBLISHED;
098:                    }
099:
100:                    // get the list of users who can do the right kind of visit
101:                    List users = SecurityService.unlockUsers(ability, ref
102:                            .getReference());
103:
104:                    // get the list of users who have the appropriate access to the resource
105:                    if (getResourceAbility() != null) {
106:                        List users2 = SecurityService.unlockUsers(
107:                                getResourceAbility(), ref.getReference());
108:
109:                        // find intersection of users and user2
110:                        users.retainAll(users2);
111:                    }
112:
113:                    // add any other users
114:                    addSpecialRecipients(users, ref);
115:
116:                    return users;
117:                } catch (Exception any) {
118:                    return new Vector();
119:                }
120:            }
121:
122:            /**
123:             * Add to the user list any other users who should be notified about this ref's change.
124:             * 
125:             * @param users
126:             *        The user list, already populated based on site visit and resource ability.
127:             * @param ref
128:             *        The entity reference.
129:             */
130:            protected void addSpecialRecipients(List users, Reference ref) {
131:            }
132:
133:            /**
134:             * Get the additional security function string needed for the resource that is the target of the notification <br />
135:             * users who get notified need to have this ability with this resource, too.
136:             * 
137:             * @return The additional ability string needed for a user to receive notification.
138:             */
139:            protected String getResourceAbility() {
140:                return null;
141:            }
142:
143:            /**
144:             * Format a to address, sensitive to the notification service's replyable configuration.
145:             * 
146:             * @param event
147:             * @return
148:             */
149:            protected String getTo(Event event) {
150:                if (NotificationService.isNotificationToReplyable()) {
151:                    // to site title <email>
152:                    return "To: " + getToSite(event);
153:                } else {
154:                    // to the site, but with no reply
155:                    return "To: " + getToSiteNoReply(event);
156:                }
157:            }
158:
159:            /**
160:             * Format a to address, to the related site, but with no reply.
161:             * 
162:             * @param event
163:             *        The event that matched criteria to cause the notification.
164:             * @return a to address, to the related site, but with no reply.
165:             */
166:            protected String getToSiteNoReply(Event event) {
167:                Reference ref = EntityManager.newReference(event.getResource());
168:
169:                // use either the configured site, or if not configured, the site (context) of the resource
170:                String siteId = (getSite() != null) ? getSite() : ref
171:                        .getContext();
172:
173:                // get a site title
174:                String title = siteId;
175:                try {
176:                    Site site = SiteService.getSite(siteId);
177:                    title = site.getTitle();
178:                } catch (Exception ignore) {
179:                }
180:
181:                return "\"" + title + "\"<no-reply@"
182:                        + ServerConfigurationService.getServerName() + ">";
183:            }
184:
185:            /**
186:             * Format the to site email address.
187:             * 
188:             * @param event
189:             *        The event that matched criteria to cause the notification.
190:             * @return the email address attribution for the site.
191:             */
192:            protected String getToSite(Event event) {
193:                Reference ref = EntityManager.newReference(event.getResource());
194:
195:                // use either the configured site, or if not configured, the site (context) of the resource
196:                String siteId = (getSite() != null) ? getSite() : ref
197:                        .getContext();
198:
199:                // get a site title
200:                String title = siteId;
201:                String email = null;
202:                try {
203:                    Site site = SiteService.getSite(siteId);
204:                    title = site.getTitle();
205:
206:                    // check that the channel exists
207:                    String channel = "/mailarchive/channel/" + siteId + "/main";
208:                    MailArchiveService.getChannel(channel);
209:
210:                    // find the alias for this site's mail channel
211:                    List all = AliasService.getAliases(channel);
212:                    if (!all.isEmpty())
213:                        email = ((Alias) all.get(0)).getId();
214:                } catch (Exception ignore) {
215:                }
216:
217:                // if for any reason we did not find an email, setup for the no-reply for email
218:                if (email == null)
219:                    email = "no-reply";
220:
221:                String rv = "\"" + title + "\" <" + email + "@"
222:                        + ServerConfigurationService.getServerName() + ">";
223:
224:                return rv;
225:            }
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.