use of net.jforum.context.RequestContext 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();
}
}
use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.
the class ModerationHelper method moveTopicsSave.
public int moveTopicsSave(String successUrl) {
int status = SUCCESS;
if (!SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_TOPIC_MOVE)) {
status = FAILURE;
} else {
RequestContext request = JForumExecutionContext.getRequest();
String topics = request.getParameter("topics");
if (topics != null) {
int fromForumId = Integer.parseInt(request.getParameter("forum_id"));
int toForumId = Integer.parseInt(request.getParameter("to_forum"));
String[] topicList = topics.split(",");
DataAccessDriver.getInstance().newForumDAO().moveTopics(topicList, fromForumId, toForumId);
ModerationLog log = this.buildModerationLogFromRequest();
for (int i = 0; i < topicList.length; i++) {
int topicId = Integer.parseInt(topicList[i]);
log.setTopicId(topicId);
this.saveModerationLog(log);
}
ForumRepository.reloadForum(fromForumId);
ForumRepository.reloadForum(toForumId);
TopicRepository.clearCache(fromForumId);
TopicRepository.clearCache(toForumId);
TopicRepository.loadMostRecentTopics();
TopicRepository.loadHottestTopics();
}
}
if (status == FAILURE) {
this.denied();
} else {
this.moderationDone(successUrl);
}
return status;
}
use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.
the class ModerationHelper method doModeration.
public int doModeration(String returnUrl) {
int status = FAILURE;
if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION)) {
// Deleting topics
RequestContext request = JForumExecutionContext.getRequest();
if (request.getParameter("topicRemove") != null) {
if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_REMOVE)) {
this.removeTopics();
status = SUCCESS;
}
} else if (request.getParameter("topicMove") != null) {
if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_TOPIC_MOVE)) {
this.moveTopics();
status = IGNORE;
}
} else if (request.getParameter("topicLock") != null) {
if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_TOPIC_LOCK_UNLOCK)) {
this.lockUnlockTopics(Topic.STATUS_LOCKED);
status = SUCCESS;
}
} else if (request.getParameter("topicUnlock") != null) {
if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_TOPIC_LOCK_UNLOCK)) {
this.lockUnlockTopics(Topic.STATUS_UNLOCKED);
status = SUCCESS;
}
}
}
if (status == ModerationHelper.FAILURE) {
this.denied();
} else if (status == ModerationHelper.SUCCESS && returnUrl != null) {
JForumExecutionContext.setRedirect(returnUrl);
}
return status;
}
use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.
the class OnlineUsersTest method setUp.
protected void setUp() throws Exception {
new SessionFacade().setCacheEngine(new DefaultCacheEngine());
RequestContext requestContext = new WebRequestContext(new FakeHttpRequest());
ResponseContext responseContext = new WebResponseContext(new FakeHttpResponse());
ForumContext forumContext = new JForumContext(requestContext.getContextPath(), SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION), requestContext, responseContext, false);
JForumExecutionContext ex = JForumExecutionContext.get();
ex.setForumContext(forumContext);
JForumExecutionContext.set(ex);
SystemGlobals.setValue(ConfigKeys.ANONYMOUS_USER_ID, Integer.toString(ANONYMOUS));
}
use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.
the class PollCommon method fillPollFromRequest.
public static Poll fillPollFromRequest() {
RequestContext request = JForumExecutionContext.getRequest();
String label = request.getParameter("poll_label");
if (label == null || label.length() == 0) {
return null;
}
Poll poll = new Poll();
poll.setStartTime(new Date());
poll.setLabel(label);
int count = request.getIntParameter("poll_option_count");
for (int i = 0; i <= count; i++) {
String option = request.getParameter("poll_option_" + i);
if (option == null) {
continue;
}
option = option.trim();
if (option.length() > 0) {
PollOption po = new PollOption();
po.setId(i);
po.setText(option);
poll.addOption(po);
}
}
String pollLength = request.getParameter("poll_length");
if (pollLength != null && pollLength.length() > 0) {
poll.setLength(Integer.parseInt(pollLength));
}
return poll;
}
Aggregations