Search in sources :

Example 1 with StandardRequestContext

use of net.jforum.context.standard.StandardRequestContext in project jforum2 by rafaelsteil.

the class POPPostAction method insertMessages.

public void insertMessages(POPParser parser) {
    long ms = System.currentTimeMillis();
    int counter = 0;
    try {
        JForumExecutionContext ex = JForumExecutionContext.get();
        RequestContext request = new StandardRequestContext();
        ex.setForumContext(new JForumContext("/", "", request, null));
        JForumExecutionContext.set(ex);
        SessionFacade.setAttribute(ConfigKeys.TOPICS_READ_TIME, new HashMap());
        for (Iterator iter = parser.getMessages().iterator(); iter.hasNext(); ) {
            POPMessage m = (POPMessage) iter.next();
            String sessionId = ms + m.getSender() + counter++;
            request.getSessionContext().setAttribute(StandardSessionContext.SESSION_ID, sessionId);
            User user = this.findUser(m.getSender());
            if (user == null) {
                logger.warn("Could not find user with email " + m.getSender() + ". Ignoring his message.");
                continue;
            }
            try {
                UserSession us = new UserSession();
                us.setUserId(user.getId());
                us.setUsername(us.getUsername());
                us.setSessionId(sessionId);
                SessionFacade.add(us, sessionId);
                SessionFacade.setAttribute(ConfigKeys.LOGGED, "1");
                SessionFacade.removeAttribute(ConfigKeys.LAST_POST_TIME);
                SessionFacade.setAttribute(ConfigKeys.REQUEST_IGNORE_CAPTCHA, "1");
                this.insertMessage(m, user);
            } finally {
                SessionFacade.remove(sessionId);
            }
        }
    } finally {
        JForumExecutionContext.finish();
    }
}
Also used : User(net.jforum.entities.User) JForumExecutionContext(net.jforum.JForumExecutionContext) HashMap(java.util.HashMap) UserSession(net.jforum.entities.UserSession) Iterator(java.util.Iterator) RequestContext(net.jforum.context.RequestContext) StandardRequestContext(net.jforum.context.standard.StandardRequestContext) StandardRequestContext(net.jforum.context.standard.StandardRequestContext) JForumContext(net.jforum.context.JForumContext)

Aggregations

HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 JForumExecutionContext (net.jforum.JForumExecutionContext)1 JForumContext (net.jforum.context.JForumContext)1 RequestContext (net.jforum.context.RequestContext)1 StandardRequestContext (net.jforum.context.standard.StandardRequestContext)1 User (net.jforum.entities.User)1 UserSession (net.jforum.entities.UserSession)1