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


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/mailarchive/tags/sakai_2-4-1/mailarchive-impl/impl/src/java/org/sakaiproject/mailarchive/impl/BaseMailArchiveService.java $
0003:         * $Id: BaseMailArchiveService.java 9905 2006-05-24 20:01:54Z ggolden@umich.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
0007:         * 
0008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
0009:         * you may not use this file except in compliance with the License. 
0010:         * You may obtain a copy of the License at
0011:         * 
0012:         *      http://www.opensource.org/licenses/ecl1.php
0013:         * 
0014:         * Unless required by applicable law or agreed to in writing, software 
0015:         * distributed under the License is distributed on an "AS IS" BASIS, 
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
0017:         * See the License for the specific language governing permissions and 
0018:         * limitations under the License.
0019:         *
0020:         **********************************************************************************/package org.sakaiproject.mailarchive.impl;
0021:
0022:        import java.util.List;
0023:        import java.util.Stack;
0024:        import java.util.Vector;
0025:
0026:        import org.apache.commons.logging.Log;
0027:        import org.apache.commons.logging.LogFactory;
0028:        import org.sakaiproject.alias.cover.AliasService;
0029:        import org.sakaiproject.authz.cover.FunctionManager;
0030:        import org.sakaiproject.authz.cover.SecurityService;
0031:        import org.sakaiproject.entity.api.ContextObserver;
0032:        import org.sakaiproject.entity.api.Edit;
0033:        import org.sakaiproject.entity.api.Entity;
0034:        import org.sakaiproject.entity.api.Reference;
0035:        import org.sakaiproject.entity.api.ResourceProperties;
0036:        import org.sakaiproject.event.api.NotificationEdit;
0037:        import org.sakaiproject.event.api.NotificationService;
0038:        import org.sakaiproject.exception.IdInvalidException;
0039:        import org.sakaiproject.exception.IdUnusedException;
0040:        import org.sakaiproject.exception.IdUsedException;
0041:        import org.sakaiproject.exception.InUseException;
0042:        import org.sakaiproject.exception.PermissionException;
0043:        import org.sakaiproject.mailarchive.api.MailArchiveChannel;
0044:        import org.sakaiproject.mailarchive.api.MailArchiveChannelEdit;
0045:        import org.sakaiproject.mailarchive.api.MailArchiveMessage;
0046:        import org.sakaiproject.mailarchive.api.MailArchiveMessageEdit;
0047:        import org.sakaiproject.mailarchive.api.MailArchiveMessageHeader;
0048:        import org.sakaiproject.mailarchive.api.MailArchiveMessageHeaderEdit;
0049:        import org.sakaiproject.mailarchive.api.MailArchiveService;
0050:        import org.sakaiproject.message.api.Message;
0051:        import org.sakaiproject.message.api.MessageChannel;
0052:        import org.sakaiproject.message.api.MessageChannelEdit;
0053:        import org.sakaiproject.message.api.MessageHeader;
0054:        import org.sakaiproject.message.api.MessageHeaderEdit;
0055:        import org.sakaiproject.message.impl.BaseMessageService;
0056:        import org.sakaiproject.site.cover.SiteService;
0057:        import org.sakaiproject.time.api.Time;
0058:        import org.sakaiproject.time.cover.TimeService;
0059:        import org.sakaiproject.user.api.User;
0060:        import org.sakaiproject.util.StringUtil;
0061:        import org.w3c.dom.Document;
0062:        import org.w3c.dom.Element;
0063:        import org.w3c.dom.Node;
0064:        import org.w3c.dom.NodeList;
0065:
0066:        /**
0067:         * <p>
0068:         * BaseMailArchiveService extends the BaseMessageService for the specifics of MailArchive.
0069:         * </p>
0070:         */
0071:        public abstract class BaseMailArchiveService extends BaseMessageService
0072:                implements  MailArchiveService, ContextObserver {
0073:            /** Our logger. */
0074:            private static Log M_log = LogFactory
0075:                    .getLog(BaseMailArchiveService.class);
0076:
0077:            /**********************************************************************************************************************************************************************************************************************************************************
0078:             * Constructors, Dependencies and their setter methods
0079:             *********************************************************************************************************************************************************************************************************************************************************/
0080:
0081:            /** Dependency: NotificationService. */
0082:            protected NotificationService m_notificationService = null;
0083:
0084:            /**
0085:             * Dependency: NotificationService.
0086:             * 
0087:             * @param service
0088:             *        The NotificationService.
0089:             */
0090:            public void setNotificationService(NotificationService service) {
0091:                m_notificationService = service;
0092:            }
0093:
0094:            /**********************************************************************************************************************************************************************************************************************************************************
0095:             * Init and Destroy
0096:             *********************************************************************************************************************************************************************************************************************************************************/
0097:
0098:            /**
0099:             * Final initialization, once all dependencies are set.
0100:             */
0101:            public void init() {
0102:                try {
0103:                    super .init();
0104:
0105:                    // register a transient notification for mail
0106:                    NotificationEdit edit = m_notificationService
0107:                            .addTransientNotification();
0108:
0109:                    // set function
0110:                    edit.setFunction(eventId(SECURE_ADD));
0111:
0112:                    // set the filter to any email resource (see messageReference())
0113:                    edit.setResourceFilter(getAccessPoint(true)
0114:                            + Entity.SEPARATOR + REF_TYPE_MESSAGE);
0115:
0116:                    // set the action
0117:                    edit.setAction(new SiteEmailNotificationMail());
0118:
0119:                    // register functions
0120:                    FunctionManager.registerFunction(eventId(SECURE_READ));
0121:                    FunctionManager.registerFunction(eventId(SECURE_ADD));
0122:                    FunctionManager
0123:                            .registerFunction(eventId(SECURE_REMOVE_ANY));
0124:
0125:                    // entity producer registration
0126:                    m_entityManager
0127:                            .registerEntityProducer(this , REFERENCE_ROOT);
0128:
0129:                    M_log.info("init()");
0130:                } catch (Throwable t) {
0131:                    M_log.warn("init(): ", t);
0132:                }
0133:
0134:            } // init
0135:
0136:            /**********************************************************************************************************************************************************************************************************************************************************
0137:             * StorageUser implementation
0138:             *********************************************************************************************************************************************************************************************************************************************************/
0139:
0140:            /**
0141:             * Construct a new continer given just ids.
0142:             * 
0143:             * @param ref
0144:             *        The channel reference.
0145:             * @return The new containe Resource.
0146:             */
0147:            public Entity newContainer(String ref) {
0148:                return new BaseMailArchiveChannelEdit(ref);
0149:            }
0150:
0151:            /**
0152:             * Construct a new container resource, from an XML element.
0153:             * 
0154:             * @param element
0155:             *        The XML.
0156:             * @return The new container resource.
0157:             */
0158:            public Entity newContainer(Element element) {
0159:                return new BaseMailArchiveChannelEdit(element);
0160:            }
0161:
0162:            /**
0163:             * Construct a new container resource, as a copy of another
0164:             * 
0165:             * @param other
0166:             *        The other contianer to copy.
0167:             * @return The new container resource.
0168:             */
0169:            public Entity newContainer(Entity other) {
0170:                return new BaseMailArchiveChannelEdit((MessageChannel) other);
0171:            }
0172:
0173:            /**
0174:             * Construct a new rsource given just an id.
0175:             * 
0176:             * @param container
0177:             *        The Resource that is the container for the new resource (may be null).
0178:             * @param id
0179:             *        The id for the new object.
0180:             * @param others
0181:             *        (options) array of objects to load into the Resource's fields.
0182:             * @return The new resource.
0183:             */
0184:            public Entity newResource(Entity container, String id,
0185:                    Object[] others) {
0186:                return new BaseMailArchiveMessageEdit(
0187:                        (MessageChannel) container, id);
0188:            }
0189:
0190:            /**
0191:             * Construct a new resource, from an XML element.
0192:             * 
0193:             * @param container
0194:             *        The Resource that is the container for the new resource (may be null).
0195:             * @param element
0196:             *        The XML.
0197:             * @return The new resource from the XML.
0198:             */
0199:            public Entity newResource(Entity container, Element element) {
0200:                return new BaseMailArchiveMessageEdit(
0201:                        (MessageChannel) container, element);
0202:            }
0203:
0204:            /**
0205:             * Construct a new resource from another resource of the same type.
0206:             * 
0207:             * @param container
0208:             *        The Resource that is the container for the new resource (may be null).
0209:             * @param other
0210:             *        The other resource.
0211:             * @return The new resource as a copy of the other.
0212:             */
0213:            public Entity newResource(Entity container, Entity other) {
0214:                return new BaseMailArchiveMessageEdit(
0215:                        (MessageChannel) container, (Message) other);
0216:            }
0217:
0218:            /**
0219:             * Construct a new continer given just ids.
0220:             * 
0221:             * @param ref
0222:             *        The channel reference.
0223:             * @return The new containe Resource.
0224:             */
0225:            public Edit newContainerEdit(String ref) {
0226:                BaseMailArchiveChannelEdit rv = new BaseMailArchiveChannelEdit(
0227:                        ref);
0228:                rv.activate();
0229:                return rv;
0230:            }
0231:
0232:            /**
0233:             * Construct a new container resource, from an XML element.
0234:             * 
0235:             * @param element
0236:             *        The XML.
0237:             * @return The new container resource.
0238:             */
0239:            public Edit newContainerEdit(Element element) {
0240:                BaseMailArchiveChannelEdit rv = new BaseMailArchiveChannelEdit(
0241:                        element);
0242:                rv.activate();
0243:                return rv;
0244:            }
0245:
0246:            /**
0247:             * Construct a new container resource, as a copy of another
0248:             * 
0249:             * @param other
0250:             *        The other contianer to copy.
0251:             * @return The new container resource.
0252:             */
0253:            public Edit newContainerEdit(Entity other) {
0254:                BaseMailArchiveChannelEdit rv = new BaseMailArchiveChannelEdit(
0255:                        (MessageChannel) other);
0256:                rv.activate();
0257:                return rv;
0258:            }
0259:
0260:            /**
0261:             * Construct a new rsource given just an id.
0262:             * 
0263:             * @param container
0264:             *        The Resource that is the container for the new resource (may be null).
0265:             * @param id
0266:             *        The id for the new object.
0267:             * @param others
0268:             *        (options) array of objects to load into the Resource's fields.
0269:             * @return The new resource.
0270:             */
0271:            public Edit newResourceEdit(Entity container, String id,
0272:                    Object[] others) {
0273:                BaseMailArchiveMessageEdit rv = new BaseMailArchiveMessageEdit(
0274:                        (MessageChannel) container, id);
0275:                rv.activate();
0276:                return rv;
0277:            }
0278:
0279:            /**
0280:             * Construct a new resource, from an XML element.
0281:             * 
0282:             * @param container
0283:             *        The Resource that is the container for the new resource (may be null).
0284:             * @param element
0285:             *        The XML.
0286:             * @return The new resource from the XML.
0287:             */
0288:            public Edit newResourceEdit(Entity container, Element element) {
0289:                BaseMailArchiveMessageEdit rv = new BaseMailArchiveMessageEdit(
0290:                        (MessageChannel) container, element);
0291:                rv.activate();
0292:                return rv;
0293:            }
0294:
0295:            /**
0296:             * Construct a new resource from another resource of the same type.
0297:             * 
0298:             * @param container
0299:             *        The Resource that is the container for the new resource (may be null).
0300:             * @param other
0301:             *        The other resource.
0302:             * @return The new resource as a copy of the other.
0303:             */
0304:            public Edit newResourceEdit(Entity container, Entity other) {
0305:                BaseMailArchiveMessageEdit rv = new BaseMailArchiveMessageEdit(
0306:                        (MessageChannel) container, (Message) other);
0307:                rv.activate();
0308:                return rv;
0309:            }
0310:
0311:            /**
0312:             * Collect the fields that need to be stored outside the XML (for the resource).
0313:             * 
0314:             * @return An array of field values to store in the record outside the XML (for the resource).
0315:             */
0316:            public Object[] storageFields(Entity r) {
0317:                Object[] rv = new Object[4];
0318:                rv[0] = ((Message) r).getHeader().getDate();
0319:                rv[1] = ((Message) r).getHeader().getFrom().getId();
0320:                rv[2] = "0";
0321:                rv[3] = r.getProperties().getProperty(
0322:                        ResourceProperties.PROP_PUBVIEW) == null ? "0" : "1";
0323:
0324:                return rv;
0325:            }
0326:
0327:            /**
0328:             * Check if this resource is in draft mode.
0329:             * 
0330:             * @param r
0331:             *        The resource.
0332:             * @return true if the resource is in draft mode, false if not.
0333:             */
0334:            public boolean isDraft(Entity r) {
0335:                return false;
0336:            }
0337:
0338:            /**
0339:             * Access the resource owner user id.
0340:             * 
0341:             * @param r
0342:             *        The resource.
0343:             * @return The resource owner user id.
0344:             */
0345:            public String getOwnerId(Entity r) {
0346:                return ((Message) r).getHeader().getFrom().getId();
0347:            }
0348:
0349:            /**
0350:             * Access the resource date.
0351:             * 
0352:             * @param r
0353:             *        The resource.
0354:             * @return The resource date.
0355:             */
0356:            public Time getDate(Entity r) {
0357:                return ((Message) r).getHeader().getDate();
0358:            }
0359:
0360:            /**********************************************************************************************************************************************************************************************************************************************************
0361:             * Abstractions, etc. satisfied
0362:             *********************************************************************************************************************************************************************************************************************************************************/
0363:
0364:            /**
0365:             * Report the Service API name being implemented.
0366:             */
0367:            protected String serviceName() {
0368:                return MailArchiveService.class.getName();
0369:            }
0370:
0371:            /**
0372:             * Construct a new message header from XML in a DOM element.
0373:             * 
0374:             * @param id
0375:             *        The message Id.
0376:             * @return The new message header.
0377:             */
0378:            protected MessageHeaderEdit newMessageHeader(Message msg, String id) {
0379:                return new BaseMailArchiveMessageHeaderEdit(msg, id);
0380:
0381:            } // newMessageHeader
0382:
0383:            /**
0384:             * Construct a new message header from XML in a DOM element.
0385:             * 
0386:             * @param el
0387:             *        The XML DOM element that has the header information.
0388:             * @return The new message header.
0389:             */
0390:            protected MessageHeaderEdit newMessageHeader(Message msg, Element el) {
0391:                return new BaseMailArchiveMessageHeaderEdit(msg, el);
0392:
0393:            } // newMessageHeader
0394:
0395:            /**
0396:             * Construct a new message header as a copy of another.
0397:             * 
0398:             * @param other
0399:             *        The other header to copy.
0400:             * @return The new message header.
0401:             */
0402:            protected MessageHeaderEdit newMessageHeader(Message msg,
0403:                    MessageHeader other) {
0404:                return new BaseMailArchiveMessageHeaderEdit(msg, other);
0405:
0406:            } // newMessageHeader
0407:
0408:            /**
0409:             * Form a tracking event string based on a security function string.
0410:             * 
0411:             * @param secure
0412:             *        The security function string.
0413:             * @return The event tracking string.
0414:             */
0415:            protected String eventId(String secure) {
0416:                return SECURE_MAIL_ROOT + secure;
0417:
0418:            } // eventId
0419:
0420:            /**
0421:             * Return the reference rooot for use in resource references and urls.
0422:             * 
0423:             * @return The reference rooot for use in resource references and urls.
0424:             */
0425:            protected String getReferenceRoot() {
0426:                return REFERENCE_ROOT;
0427:
0428:            } // getReferenceRoot
0429:
0430:            /**
0431:             * {@inheritDoc}
0432:             */
0433:            public boolean parseEntityReference(String reference, Reference ref) {
0434:                if (reference.startsWith(REFERENCE_ROOT)) {
0435:                    String[] parts = StringUtil.split(reference,
0436:                            Entity.SEPARATOR);
0437:
0438:                    String id = null;
0439:                    String subType = null;
0440:                    String context = null;
0441:                    String container = null;
0442:
0443:                    // the first part will be null, then next the service, the third will be "msg" or "channel"
0444:                    if (parts.length > 2) {
0445:                        subType = parts[2];
0446:                        if (REF_TYPE_CHANNEL.equals(subType)) {
0447:                            // next is the context id
0448:                            if (parts.length > 3) {
0449:                                context = parts[3];
0450:
0451:                                // next is the channel id
0452:                                if (parts.length > 4) {
0453:                                    id = parts[4];
0454:                                }
0455:                            }
0456:                        } else if (REF_TYPE_MESSAGE.equals(subType)) {
0457:                            // next three parts are context, channel (container) and mesage id
0458:                            if (parts.length > 5) {
0459:                                context = parts[3];
0460:                                container = parts[4];
0461:                                id = parts[5];
0462:                            }
0463:                        } else
0464:                            M_log.warn("parse(): unknown message subtype: "
0465:                                    + subType + " in ref: " + reference);
0466:                    }
0467:
0468:                    ref.set(APPLICATION_ID, subType, id, container, context);
0469:
0470:                    return true;
0471:                }
0472:
0473:                return false;
0474:            }
0475:
0476:            /**
0477:             * {@inheritDoc}
0478:             */
0479:            public void contextCreated(String context, boolean toolPlacement) {
0480:                if (toolPlacement)
0481:                    enableMailbox(context);
0482:            }
0483:
0484:            /**
0485:             * {@inheritDoc}
0486:             */
0487:            public void contextUpdated(String context, boolean toolPlacement) {
0488:                if (toolPlacement)
0489:                    enableMailbox(context);
0490:            }
0491:
0492:            /**
0493:             * {@inheritDoc}
0494:             */
0495:            public void contextDeleted(String context, boolean toolPlacement) {
0496:                disableMailbox(context);
0497:            }
0498:
0499:            /**
0500:             * {@inheritDoc}
0501:             */
0502:            public String[] myToolIds() {
0503:                String[] toolIds = { "sakai.mailbox" };
0504:                return toolIds;
0505:            }
0506:
0507:            /**
0508:             * Setup the mailbox for an active site.
0509:             * 
0510:             * @param siteId
0511:             *        The site id.
0512:             */
0513:            protected void enableMailbox(String siteId) {
0514:                // form the email channel name
0515:                String channelRef = channelReference(siteId,
0516:                        SiteService.MAIN_CONTAINER);
0517:
0518:                // see if there's a channel
0519:                MessageChannel channel = null;
0520:                try {
0521:                    channel = getChannel(channelRef);
0522:                } catch (IdUnusedException e) {
0523:                } catch (PermissionException e) {
0524:                }
0525:
0526:                // if it exists, make sure it's enabled
0527:                if (channel != null) {
0528:                    if (channel.getProperties().getProperty(
0529:                            ResourceProperties.PROP_CHANNEL_ENABLED) == null) {
0530:                        try {
0531:                            MessageChannelEdit edit = (MessageChannelEdit) editChannel(channelRef);
0532:                            edit.getPropertiesEdit().addProperty(
0533:                                    ResourceProperties.PROP_CHANNEL_ENABLED,
0534:                                    "true");
0535:                            commitChannel(edit);
0536:                            channel = edit;
0537:                        } catch (IdUnusedException ignore) {
0538:                        } catch (PermissionException ignore) {
0539:                        } catch (InUseException ignore) {
0540:                        }
0541:                    }
0542:                }
0543:
0544:                // otherwise create it
0545:                else {
0546:                    try {
0547:                        // create a channel and mark it as enabled
0548:                        MessageChannelEdit edit = addMailArchiveChannel(channelRef);
0549:                        edit
0550:                                .getPropertiesEdit()
0551:                                .addProperty(
0552:                                        ResourceProperties.PROP_CHANNEL_ENABLED,
0553:                                        "true");
0554:                        commitChannel(edit);
0555:                        channel = edit;
0556:                    } catch (IdUsedException e) {
0557:                    } catch (IdInvalidException e) {
0558:                    } catch (PermissionException e) {
0559:                    }
0560:                }
0561:            }
0562:
0563:            /**
0564:             * Set a site's mailbox to inactive - it remains in existance, just disabled
0565:             * 
0566:             * @param siteId
0567:             *        The site id.
0568:             */
0569:            protected void disableMailbox(String siteId) {
0570:                // form the email channel name
0571:                String channelRef = channelReference(siteId,
0572:                        SiteService.MAIN_CONTAINER);
0573:
0574:                // see if there's a channel
0575:                MessageChannel channel = null;
0576:                try {
0577:                    channel = getChannel(channelRef);
0578:                } catch (IdUnusedException e) {
0579:                } catch (PermissionException e) {
0580:                }
0581:
0582:                // if it exists, make sure it's disabled
0583:                if (channel != null) {
0584:                    if (channel.getProperties().getProperty(
0585:                            ResourceProperties.PROP_CHANNEL_ENABLED) != null) {
0586:                        try {
0587:                            MessageChannelEdit edit = (MessageChannelEdit) editChannel(channelRef);
0588:                            edit.getPropertiesEdit().removeProperty(
0589:                                    ResourceProperties.PROP_CHANNEL_ENABLED);
0590:                            commitChannel(edit);
0591:                            channel = edit;
0592:                        } catch (IdUnusedException ignore) {
0593:                        } catch (PermissionException ignore) {
0594:                        } catch (InUseException ignore) {
0595:                        }
0596:                    }
0597:                }
0598:
0599:                // remove any alias
0600:                try {
0601:                    AliasService.removeTargetAliases(channelRef);
0602:                } catch (PermissionException e) {
0603:                }
0604:            }
0605:
0606:            /**********************************************************************************************************************************************************************************************************************************************************
0607:             * MailArchiveService implementation
0608:             *********************************************************************************************************************************************************************************************************************************************************/
0609:
0610:            /**
0611:             * Return a specific mail message channel.
0612:             * 
0613:             * @param ref
0614:             *        The channel reference.
0615:             * @return the MailArchiveChannel that has the specified name.
0616:             * @exception IdUnusedException
0617:             *            If this name is not defined for a mail message channel.
0618:             * @exception PermissionException
0619:             *            If the user does not have any permissions to the channel.
0620:             */
0621:            public MailArchiveChannel getMailArchiveChannel(String ref)
0622:                    throws IdUnusedException, PermissionException {
0623:                return (MailArchiveChannel) getChannel(ref);
0624:
0625:            } // getMailArchiveChannel
0626:
0627:            /**
0628:             * Add a new mail message channel.
0629:             * 
0630:             * @param ref
0631:             *        The channel reference.
0632:             * @return The newly created channel.
0633:             * @exception IdUsedException
0634:             *            if the id is not unique.
0635:             * @exception IdInvalidException
0636:             *            if the id is not made up of valid characters.
0637:             * @exception PermissionException
0638:             *            if the user does not have permission to add a channel.
0639:             */
0640:            public MailArchiveChannelEdit addMailArchiveChannel(String ref)
0641:                    throws IdUsedException, IdInvalidException,
0642:                    PermissionException {
0643:                return (MailArchiveChannelEdit) addChannel(ref);
0644:
0645:            } // addMailArchiveChannel
0646:
0647:            /**********************************************************************************************************************************************************************************************************************************************************
0648:             * ResourceService implementation
0649:             *********************************************************************************************************************************************************************************************************************************************************/
0650:
0651:            /**
0652:             * {@inheritDoc}
0653:             */
0654:            public String getLabel() {
0655:                return "email";
0656:            }
0657:
0658:            /**********************************************************************************************************************************************************************************************************************************************************
0659:             * MailArchiveChannel implementation
0660:             *********************************************************************************************************************************************************************************************************************************************************/
0661:
0662:            public class BaseMailArchiveChannelEdit extends
0663:                    BaseMessageChannelEdit implements  MailArchiveChannelEdit {
0664:                /**
0665:                 * Construct with an id.
0666:                 * 
0667:                 * @param ref
0668:                 *        The channel reference.
0669:                 */
0670:                public BaseMailArchiveChannelEdit(String ref) {
0671:                    super (ref);
0672:
0673:                } // BaseMailArchiveChannelEdit
0674:
0675:                /**
0676:                 * Construct as a copy of another message.
0677:                 * 
0678:                 * @param other
0679:                 *        The other message to copy.
0680:                 */
0681:                public BaseMailArchiveChannelEdit(MessageChannel other) {
0682:                    super (other);
0683:
0684:                } // BaseMailArchiveChannelEdit
0685:
0686:                /**
0687:                 * Construct from a channel (and possibly messages) already defined in XML in a DOM tree. The Channel is added to storage.
0688:                 * 
0689:                 * @param el
0690:                 *        The XML DOM element defining the channel.
0691:                 */
0692:                public BaseMailArchiveChannelEdit(Element el) {
0693:                    super (el);
0694:
0695:                } // BaseMailArchiveChannelEdit
0696:
0697:                /**
0698:                 * Return a specific mail message channel message, as specified by message name.
0699:                 * 
0700:                 * @param messageId
0701:                 *        The id of the message to get.
0702:                 * @return the MailArchiveMessage that has the specified id.
0703:                 * @exception IdUnusedException
0704:                 *            If this name is not a defined message in this mail message channel.
0705:                 * @exception PermissionException
0706:                 *            If the user does not have any permissions to read the message.
0707:                 */
0708:                public MailArchiveMessage getMailArchiveMessage(String messageId)
0709:                        throws IdUnusedException, PermissionException {
0710:                    MailArchiveMessage msg = (MailArchiveMessage) getMessage(messageId);
0711:
0712:                    return msg;
0713:
0714:                } // getMailArchiveMessage
0715:
0716:                /**
0717:                 * A (MailArchiveMessageEdit) cover for editMessage. Return a specific channel message, as specified by message name, locked for update. Must commitEdit() to make official, or cancelEdit() when done!
0718:                 * 
0719:                 * @param messageId
0720:                 *        The id of the message to get.
0721:                 * @return the Message that has the specified id.
0722:                 * @exception IdUnusedException
0723:                 *            If this name is not a defined message in this channel.
0724:                 * @exception PermissionException
0725:                 *            If the user does not have any permissions to read the message.
0726:                 * @exception InUseException
0727:                 *            if the current user does not have permission to mess with this user.
0728:                 */
0729:                public MailArchiveMessageEdit editMailArchiveMessage(
0730:                        String messageId) throws IdUnusedException,
0731:                        PermissionException, InUseException {
0732:                    return (MailArchiveMessageEdit) editMessage(messageId);
0733:
0734:                } // editMailArchiveMessage
0735:
0736:                /**
0737:                 * A (MailArchiveMessageEdit) cover for addMessage. Add a new message to this channel. Must commitEdit() to make official, or cancelEdit() when done!
0738:                 * 
0739:                 * @return The newly added message, locked for update.
0740:                 * @exception PermissionException
0741:                 *            If the user does not have write permission to the channel.
0742:                 */
0743:                public MailArchiveMessageEdit addMailArchiveMessage()
0744:                        throws PermissionException {
0745:                    return (MailArchiveMessageEdit) addMessage();
0746:
0747:                } // addMailArchiveMessage
0748:
0749:                /**
0750:                 * a (MailArchiveMessage) cover for addMessage to add a new message to this channel.
0751:                 * 
0752:                 * @param subject
0753:                 *        The message header subject.
0754:                 * @param fromAddress
0755:                 *        The mail from: address from the message.
0756:                 * @param dateSent
0757:                 *        The date: sent from the message.
0758:                 * @param mailHeaders
0759:                 *        The full set of mail headers from the message.
0760:                 * @param attachments
0761:                 *        The message header attachments, a vector of Reference objects.
0762:                 * @param body
0763:                 *        The message body.
0764:                 * @return The newly added message.
0765:                 * @exception PermissionException
0766:                 *            If the user does not have write permission to the channel.
0767:                 */
0768:                public MailArchiveMessage addMailArchiveMessage(String subject,
0769:                        String fromAddress, Time dateSent, List mailHeaders,
0770:                        List attachments, String body)
0771:                        throws PermissionException {
0772:                    MailArchiveMessageEdit edit = (MailArchiveMessageEdit) addMessage();
0773:                    MailArchiveMessageHeaderEdit header = edit
0774:                            .getMailArchiveHeaderEdit();
0775:                    edit.setBody(body);
0776:                    header.replaceAttachments(attachments);
0777:                    header.setSubject(subject);
0778:                    header.setFromAddress(fromAddress);
0779:                    header.setDateSent(dateSent);
0780:                    header.setMailHeaders(mailHeaders);
0781:
0782:                    // lets make sure that folks who have signed up for email get it
0783:                    commitMessage(edit, NotificationService.NOTI_OPTIONAL);
0784:
0785:                    return edit;
0786:
0787:                } // addMailArchiveMessage
0788:
0789:                /** @return true if the channel enabled, false if not. */
0790:                public boolean getEnabled() {
0791:                    boolean enabled = false;
0792:                    try {
0793:                        enabled = getProperties().getBooleanProperty(
0794:                                ResourceProperties.PROP_CHANNEL_ENABLED);
0795:                    } catch (Exception ignore) {
0796:                    }
0797:
0798:                    return enabled;
0799:
0800:                } // getEnabled
0801:
0802:                /** @return true if the channel is open to messages from outside the membership, false if not. */
0803:                public boolean getOpen() {
0804:                    boolean open = false;
0805:                    try {
0806:                        open = getProperties().getBooleanProperty(
0807:                                ResourceProperties.PROP_MAIL_CHANNEL_OPEN);
0808:                    } catch (Exception ignore) {
0809:                    }
0810:
0811:                    return open;
0812:
0813:                } // getOpen
0814:
0815:                /**
0816:                 * Set the enabled status of the channe. Disabled channels will not recieve email.
0817:                 * 
0818:                 * @param setting
0819:                 *        The new setting.
0820:                 */
0821:                public void setEnabled(boolean setting) {
0822:                    if (setting) {
0823:                        getPropertiesEdit()
0824:                                .addProperty(
0825:                                        ResourceProperties.PROP_CHANNEL_ENABLED,
0826:                                        "true");
0827:                    } else {
0828:                        getPropertiesEdit().removeProperty(
0829:                                ResourceProperties.PROP_CHANNEL_ENABLED);
0830:                    }
0831:
0832:                } // setEnabled
0833:
0834:                /**
0835:                 * Set the open status of the channe. Open channels will recieve email from anyone - otherwise messages will be accepted only from users (based on the main from email address) with add permission.
0836:                 * 
0837:                 * @param setting
0838:                 *        The new setting.
0839:                 */
0840:                public void setOpen(boolean setting) {
0841:                    if (setting) {
0842:                        getPropertiesEdit().addProperty(
0843:                                ResourceProperties.PROP_MAIL_CHANNEL_OPEN,
0844:                                "true");
0845:                    } else {
0846:                        getPropertiesEdit().removeProperty(
0847:                                ResourceProperties.PROP_MAIL_CHANNEL_OPEN);
0848:                    }
0849:                }
0850:
0851:                /**
0852:                 * check permissions for addMessage() for the given user.
0853:                 * 
0854:                 * @param user
0855:                 *        The user.
0856:                 * @return true if the specified user is allowed to addMessage(...), false if not.
0857:                 */
0858:                public boolean allowAddMessage(User user) {
0859:                    if (!SecurityService.unlock(user, eventId(SECURE_ADD),
0860:                            getReference())) {
0861:                        return false;
0862:                    }
0863:
0864:                    return true;
0865:
0866:                }
0867:
0868:            } // class BaseMailArchiveChannelEdit
0869:
0870:            /**********************************************************************************************************************************************************************************************************************************************************
0871:             * MailArchiveMessage implementation
0872:             *********************************************************************************************************************************************************************************************************************************************************/
0873:
0874:            public class BaseMailArchiveMessageEdit extends BaseMessageEdit
0875:                    implements  MailArchiveMessageEdit {
0876:                /**
0877:                 * Construct.
0878:                 * 
0879:                 * @param channel
0880:                 *        The channel in which this message lives.
0881:                 * @param id
0882:                 *        The message id.
0883:                 */
0884:                public BaseMailArchiveMessageEdit(MessageChannel channel,
0885:                        String id) {
0886:                    super (channel, id);
0887:
0888:                } // BaseMailArchiveMessageEdit
0889:
0890:                /**
0891:                 * Construct as a copy of another message.
0892:                 * 
0893:                 * @param other
0894:                 *        The other message to copy.
0895:                 */
0896:                public BaseMailArchiveMessageEdit(MessageChannel channel,
0897:                        Message other) {
0898:                    super (channel, other);
0899:
0900:                } // BaseMailArchiveMessageEdit
0901:
0902:                /**
0903:                 * Construct from an existing definition, in xml.
0904:                 * 
0905:                 * @param channel
0906:                 *        The channel in which this message lives.
0907:                 * @param el
0908:                 *        The message in XML in a DOM element.
0909:                 */
0910:                public BaseMailArchiveMessageEdit(MessageChannel channel,
0911:                        Element el) {
0912:                    super (channel, el);
0913:
0914:                } // BaseMailArchiveMessageEdit
0915:
0916:                /**
0917:                 * Access the mail message message header.
0918:                 * 
0919:                 * @return The mail message message header.
0920:                 */
0921:                public MailArchiveMessageHeader getMailArchiveHeader() {
0922:                    return (MailArchiveMessageHeader) getHeader();
0923:
0924:                } // getMailArchiveHeader
0925:
0926:                /**
0927:                 * Access the mail message message header.
0928:                 * 
0929:                 * @return The mail message message header.
0930:                 */
0931:                public MailArchiveMessageHeaderEdit getMailArchiveHeaderEdit() {
0932:                    return (MailArchiveMessageHeaderEdit) getHeader();
0933:
0934:                } // getMailArchiveHeaderEdit
0935:
0936:            } // class BasicMailArchiveMessageEdit
0937:
0938:            /**********************************************************************************************************************************************************************************************************************************************************
0939:             * MailArchiveMessageHeaderEdit implementation
0940:             *********************************************************************************************************************************************************************************************************************************************************/
0941:
0942:            public class BaseMailArchiveMessageHeaderEdit extends
0943:                    BaseMessageHeaderEdit implements 
0944:                    MailArchiveMessageHeaderEdit {
0945:                /** The subject for the mail message. */
0946:                protected String m_subject = null;
0947:
0948:                /** The from: address for the message. */
0949:                protected String m_fromAddress = null;
0950:
0951:                /** The date: sent for the message. */
0952:                protected Time m_dateSent = null;
0953:
0954:                /** The entire set of mail headers. */
0955:                protected List m_mailHeaders = new Vector();
0956:
0957:                /**
0958:                 * Construct.
0959:                 * 
0960:                 * @param id
0961:                 *        The unique (within the channel) message id.
0962:                 * @param from
0963:                 *        The User who sent the message to the channel.
0964:                 * @param attachments
0965:                 *        The message header attachments, a vector of Reference objects.
0966:                 */
0967:                public BaseMailArchiveMessageHeaderEdit(Message msg, String id) {
0968:                    super (msg, id);
0969:
0970:                } // BaseMailArchiveMessageHeaderEdit
0971:
0972:                /**
0973:                 * Construct, from an already existing XML DOM element.
0974:                 * 
0975:                 * @param el
0976:                 *        The header in XML in a DOM element.
0977:                 */
0978:                public BaseMailArchiveMessageHeaderEdit(Message msg, Element el) {
0979:                    super (msg, el);
0980:
0981:                    // now extract the subject, from address, date sent
0982:                    m_subject = el.getAttribute("subject");
0983:                    m_fromAddress = el.getAttribute("mail-from");
0984:                    m_dateSent = TimeService.newTimeGmt(el
0985:                            .getAttribute("mail-date"));
0986:
0987:                    // mail headers
0988:                    NodeList children = el.getChildNodes();
0989:                    final int length = children.getLength();
0990:                    for (int i = 0; i < length; i++) {
0991:                        Node child = children.item(i);
0992:                        if (child.getNodeType() != Node.ELEMENT_NODE)
0993:                            continue;
0994:                        Element element = (Element) child;
0995:
0996:                        // look for a header
0997:                        if (!element.getTagName().equals("mail-header"))
0998:                            continue;
0999:
1000:                        m_mailHeaders.add(element.getAttribute("value"));
1001:                    }
1002:
1003:                } // BaseMailArchiveMessageHeaderEdit
1004:
1005:                /**
1006:                 * Construct as a copy of another header.
1007:                 * 
1008:                 * @param other
1009:                 *        The other message header to copy.
1010:                 */
1011:                public BaseMailArchiveMessageHeaderEdit(Message msg,
1012:                        MessageHeader other) {
1013:                    super (msg, other);
1014:
1015:                    m_subject = ((MailArchiveMessageHeader) other).getSubject();
1016:                    m_fromAddress = ((MailArchiveMessageHeader) other)
1017:                            .getFromAddress();
1018:                    m_dateSent = ((MailArchiveMessageHeader) other)
1019:                            .getDateSent();
1020:                    m_mailHeaders.addAll(((MailArchiveMessageHeader) other)
1021:                            .getMailHeaders());
1022:
1023:                } // BaseMailArchiveMessageHeaderEdit
1024:
1025:                /**
1026:                 * Access the subject of the mail message.
1027:                 * 
1028:                 * @return The subject of the mail message.
1029:                 */
1030:                public String getSubject() {
1031:                    return ((m_subject == null) ? "" : m_subject);
1032:
1033:                } // getSubject
1034:
1035:                /**
1036:                 * Set the subject of the mail message.
1037:                 * 
1038:                 * @param subject
1039:                 *        The subject of the mail message.
1040:                 */
1041:                public void setSubject(String subject) {
1042:                    m_subject = subject;
1043:
1044:                } // setSubject
1045:
1046:                /**
1047:                 * Access the from: address of the message.
1048:                 * 
1049:                 * @return The from: address of the message.
1050:                 */
1051:                public String getFromAddress() {
1052:                    return ((m_fromAddress == null) ? "" : m_fromAddress);
1053:
1054:                } // getFromAddress
1055:
1056:                /**
1057:                 * Set the the from: address of the message.
1058:                 * 
1059:                 * @param from
1060:                 *        The from: address of the message.
1061:                 */
1062:                public void setFromAddress(String from) {
1063:                    m_fromAddress = from;
1064:
1065:                } // setFromAddress
1066:
1067:                /**
1068:                 * Access the date: sent of the message.
1069:                 * 
1070:                 * @return The date: sent of the message.
1071:                 */
1072:                public Time getDateSent() {
1073:                    return ((m_dateSent == null) ? this .getDate() : m_dateSent);
1074:
1075:                } // getDateSent
1076:
1077:                /**
1078:                 * Set the date: sent of the message.
1079:                 * 
1080:                 * @param sent
1081:                 *        The the date: sent of the message.
1082:                 */
1083:                public void setDateSent(Time sent) {
1084:                    m_dateSent = TimeService.newTime(sent.getTime());
1085:
1086:                } // setDateSent
1087:
1088:                /**
1089:                 * Access the entire set of mail headers the message.
1090:                 * 
1091:                 * @return The entire set of mail headers of the message (List of String).
1092:                 */
1093:                public List getMailHeaders() {
1094:                    return m_mailHeaders;
1095:
1096:                } // getMailHeaders
1097:
1098:                /**
1099:                 * Set the entire set of mail headers of the message.
1100:                 * 
1101:                 * @param headers
1102:                 *        The the entire set of mail headers of the message.
1103:                 */
1104:                public void setMailHeaders(List headers) {
1105:                    m_mailHeaders.clear();
1106:                    m_mailHeaders.addAll(headers);
1107:
1108:                } // setMailHeaders
1109:
1110:                /**
1111:                 * Serialize the resource into XML, adding an element to the doc under the top of the stack element.
1112:                 * 
1113:                 * @param doc
1114:                 *        The DOM doc to contain the XML (or null for a string return).
1115:                 * @param stack
1116:                 *        The DOM elements, the top of which is the containing element of the new "resource" element.
1117:                 * @return The newly added element.
1118:                 */
1119:                public Element toXml(Document doc, Stack stack) {
1120:                    // get the basic work done
1121:                    Element header = super .toXml(doc, stack);
1122:
1123:                    // add draft, subject
1124:                    header.setAttribute("subject", getSubject());
1125:                    header.setAttribute("mail-from", getFromAddress());
1126:                    header.setAttribute("mail-date", getDateSent().toString());
1127:                    for (int i = 0; i < m_mailHeaders.size(); i++) {
1128:                        Element mailHeader = doc.createElement("mail-header");
1129:                        header.appendChild(mailHeader);
1130:                        mailHeader.setAttribute("value", (String) m_mailHeaders
1131:                                .get(i));
1132:                    }
1133:
1134:                    return header;
1135:
1136:                } // toXml
1137:
1138:            } // BaseMailArchiveMessageHeader
1139:
1140:        } // BaseMailArchiveService
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.