Source Code Cross Referenced for POPPostAction.java in  » Forum » JForum-2.1.8 » net » jforum » api » integration » mail » pop » 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 » Forum » JForum 2.1.8 » net.jforum.api.integration.mail.pop 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 26/08/2006 22:20:46
003:         */
004:        package net.jforum.api.integration.mail.pop;
005:
006:        import java.util.HashMap;
007:        import java.util.Iterator;
008:
009:        import org.apache.log4j.Logger;
010:
011:        import freemarker.template.SimpleHash;
012:
013:        import net.jforum.JForumExecutionContext;
014:        import net.jforum.SessionFacade;
015:        import net.jforum.context.JForumContext;
016:        import net.jforum.context.RequestContext;
017:        import net.jforum.context.standard.StandardRequestContext;
018:        import net.jforum.context.standard.StandardSessionContext;
019:        import net.jforum.dao.DataAccessDriver;
020:        import net.jforum.dao.ForumDAO;
021:        import net.jforum.entities.Topic;
022:        import net.jforum.entities.User;
023:        import net.jforum.entities.UserSession;
024:        import net.jforum.util.preferences.ConfigKeys;
025:        import net.jforum.view.forum.PostAction;
026:
027:        /**
028:         * @author Rafael Steil
029:         * @version $Id: POPPostAction.java,v 1.10 2007/07/31 13:52:47 rafaelsteil Exp $
030:         */
031:        public class POPPostAction {
032:            private static Logger logger = Logger
033:                    .getLogger(POPPostAction.class);
034:
035:            public void insertMessages(POPParser parser) {
036:                long ms = System.currentTimeMillis();
037:                int counter = 0;
038:
039:                try {
040:                    JForumExecutionContext ex = JForumExecutionContext.get();
041:
042:                    RequestContext request = new StandardRequestContext();
043:                    ex
044:                            .setForumContext(new JForumContext("/", "",
045:                                    request, null));
046:
047:                    JForumExecutionContext.set(ex);
048:
049:                    SessionFacade.setAttribute(ConfigKeys.TOPICS_READ_TIME,
050:                            new HashMap());
051:
052:                    for (Iterator iter = parser.getMessages().iterator(); iter
053:                            .hasNext();) {
054:                        POPMessage m = (POPMessage) iter.next();
055:                        String sessionId = ms + m.getSender() + counter++;
056:
057:                        request.getSessionContext().setAttribute(
058:                                StandardSessionContext.SESSION_ID, sessionId);
059:
060:                        User user = this .findUser(m.getSender());
061:
062:                        if (user == null) {
063:                            logger
064:                                    .warn("Could not find user with email "
065:                                            + m.getSender()
066:                                            + ". Ignoring his message.");
067:                            continue;
068:                        }
069:
070:                        try {
071:                            UserSession us = new UserSession();
072:                            us.setUserId(user.getId());
073:                            us.setUsername(us.getUsername());
074:                            us.setSessionId(sessionId);
075:
076:                            SessionFacade.add(us, sessionId);
077:                            SessionFacade.setAttribute(ConfigKeys.LOGGED, "1");
078:
079:                            SessionFacade
080:                                    .removeAttribute(ConfigKeys.LAST_POST_TIME);
081:                            SessionFacade.setAttribute(
082:                                    ConfigKeys.REQUEST_IGNORE_CAPTCHA, "1");
083:
084:                            this .insertMessage(m, user);
085:                        } finally {
086:                            SessionFacade.remove(sessionId);
087:                        }
088:                    }
089:                } finally {
090:                    JForumExecutionContext.finish();
091:                }
092:            }
093:
094:            /**
095:             * Calls {@link PostAction#insertSave()}
096:             * @param m the mail message
097:             * @param user the user who's sent the message
098:             */
099:            private void insertMessage(POPMessage m, User user) {
100:                this .addDataToRequest(m, user);
101:
102:                PostAction postAction = new PostAction(JForumExecutionContext
103:                        .getRequest(), new SimpleHash());
104:                postAction.insertSave();
105:            }
106:
107:            /**
108:             * Extracts information from a mail message and adds it to the request context
109:             * @param m the mail message
110:             * @param user the user who's sending the message
111:             */
112:            private void addDataToRequest(POPMessage m, User user) {
113:                RequestContext request = JForumExecutionContext.getRequest();
114:
115:                request.addParameter("forum_id", Integer.toString(this 
116:                        .discoverForumId(m.getListEmail())));
117:                request.addParameter("topic_type", Integer
118:                        .toString(Topic.TYPE_NORMAL));
119:                request.addParameter("quick", "1");
120:                request.addParameter("subject", m.getSubject());
121:                request.addParameter("message", m.getMessage());
122:
123:                int topicId = this .discoverTopicId(m);
124:
125:                if (topicId > 0) {
126:                    request.addParameter("topic_id", Integer.toString(topicId));
127:                }
128:
129:                if (!user.isBbCodeEnabled()) {
130:                    request.addParameter("disable_bbcode", "on");
131:                }
132:
133:                if (!user.isSmiliesEnabled()) {
134:                    request.addParameter("disable_smilies", "on");
135:                }
136:
137:                if (!user.isHtmlEnabled()) {
138:                    request.addParameter("disable_html", "on");
139:                }
140:            }
141:
142:            /**
143:             * Tries to extract message relationship from the headers
144:             * @param m the message to extract headers from
145:             * @return the topic id, if found, or 0 (zero) othwerwise
146:             */
147:            private int discoverTopicId(POPMessage m) {
148:                int topicId = 0;
149:
150:                String inReplyTo = m.getInReplyTo();
151:
152:                if (inReplyTo != null) {
153:                    topicId = MessageId.parse(inReplyTo).getTopicId();
154:                }
155:
156:                return topicId;
157:            }
158:
159:            /**
160:             * Given an email address, finds the forum instance associated to it
161:             * @param listEmail the forum's email address to search for
162:             * @return the forum's id, or 0 (zero) if nothing was found
163:             */
164:            private int discoverForumId(String listEmail) {
165:                ForumDAO dao = DataAccessDriver.getInstance().newForumDAO();
166:                return dao.discoverForumId(listEmail);
167:            }
168:
169:            /**
170:             * Finds an user by his email address
171:             * @param email the email address to use in the search
172:             * @return the matching record, or null if nothing was found
173:             */
174:            private User findUser(String email) {
175:                return DataAccessDriver.getInstance().newUserDAO().findByEmail(
176:                        email);
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.