Source Code Cross Referenced for EMailForm.java in  » Content-Management-System » contineo » org » contineo » web » document » 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 » contineo » org.contineo.web.document 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.contineo.web.document;
002:
003:        import org.apache.commons.lang.builder.ReflectionToStringBuilder;
004:        import org.apache.commons.logging.Log;
005:        import org.apache.commons.logging.LogFactory;
006:
007:        import org.contineo.core.FileBean;
008:        import org.contineo.core.communication.Attachment;
009:        import org.contineo.core.communication.EMail;
010:        import org.contineo.core.communication.EMailSender;
011:        import org.contineo.core.communication.Recipient;
012:        import org.contineo.core.communication.dao.EMailDAO;
013:        import org.contineo.core.document.Document;
014:        import org.contineo.core.document.DownloadTicket;
015:        import org.contineo.core.security.Menu;
016:        import org.contineo.core.security.User;
017:        import org.contineo.core.security.dao.MenuDAO;
018:
019:        import org.contineo.util.Context;
020:        import org.contineo.util.config.MimeTypeConfig;
021:        import org.contineo.util.config.SettingsConfig;
022:
023:        import org.contineo.web.SessionManagement;
024:        import org.contineo.web.i18n.Messages;
025:        import org.contineo.web.navigation.PageContentBean;
026:
027:        import java.util.ArrayList;
028:        import java.util.Collection;
029:        import java.util.Date;
030:
031:        /**
032:         * This form is used ro send emails
033:         *
034:         * @author Michael Scholz, Marco Meschieri
035:         * @version $Id: EMailForm.java,v 1.2 2006/09/03 16:24:37 marco Exp $
036:         * @since 1.0
037:         */
038:        public class EMailForm {
039:            protected static Log log = LogFactory.getLog(EMailForm.class);
040:            private String author;
041:            private String recipient;
042:            private String subject;
043:            private String text;
044:            private Document selectedDocument;
045:            private Collection<Menu> attachments = new ArrayList<Menu>();
046:            private DownloadTicket downloadTicket;
047:            private DocumentNavigation documentNavigation;
048:
049:            public EMailForm() {
050:            }
051:
052:            public String getAuthor() {
053:                return author;
054:            }
055:
056:            public void setAuthor(String author) {
057:                this .author = author;
058:            }
059:
060:            public String getRecipient() {
061:                return recipient;
062:            }
063:
064:            public void setRecipient(String recipient) {
065:                this .recipient = recipient;
066:            }
067:
068:            public String getSubject() {
069:                return subject;
070:            }
071:
072:            public void setSubject(String subject) {
073:                this .subject = subject;
074:            }
075:
076:            public String getText() {
077:                return text;
078:            }
079:
080:            public void setText(String text) {
081:                this .text = text;
082:            }
083:
084:            public Collection<Menu> getAttachments() {
085:                return attachments;
086:            }
087:
088:            public void setAttachments(Collection<Menu> attachments) {
089:                this .attachments = attachments;
090:            }
091:
092:            public void reset() {
093:                author = "";
094:                recipient = "";
095:                subject = "";
096:                text = "";
097:                attachments.clear();
098:                downloadTicket = null;
099:                selectedDocument = null;
100:            }
101:
102:            public Document getSelectedDocument() {
103:                return selectedDocument;
104:            }
105:
106:            public void setSelectedDocument(Document selectedDocument) {
107:                this .selectedDocument = selectedDocument;
108:            }
109:
110:            public DownloadTicket getDownloadTicket() {
111:                return downloadTicket;
112:            }
113:
114:            public void setDownloadTicket(DownloadTicket downloadTicket) {
115:                this .downloadTicket = downloadTicket;
116:            }
117:
118:            public String toString() {
119:                return (new ReflectionToStringBuilder(this ) {
120:                    protected boolean accept(java.lang.reflect.Field f) {
121:                        return super .accept(f);
122:                    }
123:                }).toString();
124:            }
125:
126:            public String send() {
127:                EMail email;
128:
129:                if (SessionManagement.isValid()) {
130:                    try {
131:                        User user = SessionManagement.getUser();
132:                        email = new EMail();
133:
134:                        EMailDAO emailDao = (EMailDAO) Context.getInstance()
135:                                .getBean(EMailDAO.class);
136:                        email.setAccountId(1);
137:                        email.setAuthor(user.getUserName());
138:                        email.setAuthorAddress(user.getEmail());
139:
140:                        Recipient recipient = new Recipient();
141:                        recipient.setAddress(getRecipient());
142:                        email.addRecipient(recipient);
143:                        email.setFolder("outbox");
144:                        email.setMessageText(getText());
145:                        email.setRead(1);
146:                        email.setSentDate(String.valueOf(new Date().getTime()));
147:                        email.setSubject(getSubject());
148:                        email.setUserName(user.getUserName());
149:                        emailDao.store(email);
150:
151:                        SettingsConfig conf = (SettingsConfig) Context
152:                                .getInstance().getBean(SettingsConfig.class);
153:
154:                        String udir = conf.getValue("userdir");
155:                        String maildir = udir + "/mails/"
156:                                + String.valueOf(email.getMessageId()) + "/";
157:                        FileBean.createDir(maildir);
158:                        FileBean.writeFile(email.getMessageText(), maildir
159:                                + "email.mail");
160:
161:                        int i = 2;
162:
163:                        for (Menu menu : attachments) {
164:                            createAttachment(email, menu.getMenuId(), i++);
165:                        }
166:
167:                        emailDao.store(email);
168:
169:                        try {
170:                            EMailSender sender = (EMailSender) Context
171:                                    .getInstance().getBean(EMailSender.class);
172:                            sender.send(email);
173:                            Messages.addLocalizedInfo("msg.action.saveemail");
174:                        } catch (Exception ex) {
175:                            log.error(ex.getMessage(), ex);
176:                            Messages
177:                                    .addLocalizedError("errors.action.saveemail");
178:                        }
179:
180:                        setAuthor(user.getEmail());
181:                    } catch (Exception e) {
182:                        log.error(e.getMessage(), e);
183:                        Messages.addLocalizedError("errors.action.saveemail");
184:                    }
185:                } else {
186:                    return "login";
187:                }
188:
189:                documentNavigation.setSelectedPanel(new PageContentBean(
190:                        "documents"));
191:                reset();
192:
193:                return null;
194:            }
195:
196:            private void createAttachment(EMail email, int menuId, int partid) {
197:                Attachment att = new Attachment();
198:                MenuDAO menuDao = (MenuDAO) Context.getInstance().getBean(
199:                        MenuDAO.class);
200:                Menu menu = menuDao.findByPrimaryKey(menuId);
201:
202:                if (menuDao.isReadEnable(menu.getMenuId(), email.getUserName())) {
203:                    att.setIcon(menu.getMenuIcon());
204:                    att.setFilename(menu.getMenuRef());
205:
206:                    String extension = menu.getMenuRef().substring(
207:                            menu.getMenuRef().lastIndexOf(".") + 1);
208:                    MimeTypeConfig mtc = (MimeTypeConfig) Context.getInstance()
209:                            .getBean(MimeTypeConfig.class);
210:                    String mimetype = mtc.getMimeApp(extension);
211:
212:                    if ((mimetype == null) || mimetype.equals("")) {
213:                        mimetype = "application/octet-stream";
214:                    }
215:
216:                    att.setMimeType(mimetype);
217:
218:                    SettingsConfig conf = (SettingsConfig) Context
219:                            .getInstance().getBean(SettingsConfig.class);
220:                    String docdir = conf.getValue("docdir");
221:                    String doc = docdir + "/" + menu.getMenuPath() + "/"
222:                            + menu.getMenuId() + "/" + menu.getMenuRef();
223:                    String userdir = conf.getValue("userdir");
224:                    String mail = userdir + "/mails/"
225:                            + String.valueOf(email.getMessageId()) + "/";
226:                    FileBean.copyFile(doc, mail + menu.getMenuRef());
227:
228:                    if (att != null) {
229:                        email.addAttachment(partid, att);
230:                    }
231:                }
232:            }
233:
234:            public void setDocumentNavigation(
235:                    DocumentNavigation documentNavigation) {
236:                this.documentNavigation = documentNavigation;
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.