use of org.apache.struts.action.ActionForward in project zoj by licheng.
the class TestSubmitAction method execute.
/**
* SubmitAction.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
if (!this.isLogin(context, true)) {
return this.handleSuccess(mapping, context, "login");
}
boolean isProblemset = context.getRequest().getRequestURI().endsWith("submit.do");
ActionForward forward = this.checkProblemParticipatePermission(mapping, context, isProblemset);
if (forward != null) {
return forward;
}
AbstractContest contest = context.getContest();
Problem problem = context.getProblem();
long languageId = Utility.parseLong(context.getRequest().getParameter("languageId"));
Language language = PersistenceManager.getInstance().getLanguagePersistence().getLanguage(languageId);
if (language == null) {
return this.handleSuccess(mapping, context, "submit");
}
String source = context.getRequest().getParameter("source");
if (source == null || source.length() == 0) {
return this.handleSuccess(mapping, context, "submit");
}
List refrance = PersistenceManager.getInstance().getReferencePersistence().getProblemReferences(problem.getId(), ReferenceType.HEADER);
if (refrance.size() != 0) {
Reference r = (Reference) refrance.get(0);
String percode = new String(r.getContent());
source = percode + "\n" + source;
}
UserProfile user = context.getUserProfile();
if (submitCache != null && submitCache.contains(user.getId())) {
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.submit.interval"));
this.saveErrors(context.getRequest(), messages);
context.setAttribute("source", source);
return handleSuccess(mapping, context, "submit");
}
if (contest.isCheckIp()) {
forward = this.checkLastLoginIP(mapping, context, isProblemset);
if (forward != null) {
return forward;
}
}
Submission submission = new Submission();
submission.setContestId(contest.getId());
submission.setLanguage(language);
submission.setProblemId(problem.getId());
submission.setUserProfileId(user.getId());
submission.setContent(source);
submission.setMemoryConsumption(0);
submission.setTimeConsumption(0);
submission.setSubmitDate(new Date());
SubmissionPersistence submissionPersistence = PersistenceManager.getInstance().getSubmissionPersistence();
if (contest.getEndTime() != null && new Date().after(contest.getEndTime())) {
submission.setJudgeReply(JudgeReply.OUT_OF_CONTEST_TIME);
submissionPersistence.createSubmission(submission, user.getId());
} else if (source.getBytes().length > problem.getLimit().getSubmissionLimit() * 1024) {
submission.setContent(source.substring(0, problem.getLimit().getSubmissionLimit() * 1024));
submission.setJudgeReply(JudgeReply.SUBMISSION_LIMIT_EXCEEDED);
submissionPersistence.createSubmission(submission, user.getId());
} else {
Random ran = new Random();
submission.setJudgeReply(ran.nextInt() % 2 == 0 ? JudgeReply.WRONG_ANSWER : JudgeReply.ACCEPTED);
submissionPersistence.createSubmission(submission, user.getId());
JudgeService.getInstance().judge(submission, Priority.NORMAL);
}
context.setAttribute("contestOrder", submission.getContestOrder());
if (submitCache != null) {
submitCache.put(user.getId(), user.getId());
}
return this.handleSuccess(mapping, context, "success");
}
use of org.apache.struts.action.ActionForward in project zoj by licheng.
the class UserSearchAction method execute.
/**
* ShowRunsAction.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
context.setAttribute("UserSearchForm", form);
context.getRequest().setAttribute("Countries", PersistenceManager.getInstance().getUserPersistence().getAllCountries());
context.getRequest().setAttribute("Roles", PersistenceManager.getInstance().getAuthorizationPersistence().getAllRoles());
UserSearchForm userForm = (UserSearchForm) form;
if (this.empty(userForm.getCountryId()) && this.empty(userForm.getEmail()) && this.empty(userForm.getFirstName()) && this.empty(userForm.getHandle()) && this.empty(userForm.getLastName()) && this.empty(userForm.getRoleId()) && this.empty(userForm.getSchool())) {
return this.handleSuccess(mapping, context, "success");
}
UserCriteria criteria = userForm.toUserCriteria();
String export = context.getRequest().getParameter("exportFormat");
if ("txt".equalsIgnoreCase(export)) {
List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0, Integer.MAX_VALUE);
return this.export(context, criteria, users, export);
} else if ("xls".equalsIgnoreCase(export)) {
List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0, Integer.MAX_VALUE);
return this.export(context, criteria, users, export);
}
long paging = Utility.parseLong(userForm.getPaging(), 10, 50);
;
long usersNumber = PersistenceManager.getInstance().getUserPersistence().searchUserProfilesCount(criteria);
if (usersNumber == 0) {
context.setAttribute("users", new ArrayList<UserProfile>());
context.setAttribute("pageNumber", new Long(0));
context.setAttribute("totalPages", new Long(0));
context.setAttribute("paging", new Long(paging));
context.setAttribute("total", new Long(0));
return this.handleSuccess(mapping, context, "success");
}
long totalPages = (usersNumber - 1) / paging + 1;
long pageNumber = Utility.parseLong(userForm.getPageNumber(), 1, totalPages);
long startIndex = paging * (pageNumber - 1);
List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, (int) startIndex, (int) paging);
context.setAttribute("users", users);
context.setAttribute("pageNumber", new Long(pageNumber));
context.setAttribute("totalPages", new Long(totalPages));
context.setAttribute("paging", new Long(paging));
context.setAttribute("total", new Long(usersNumber));
return this.handleSuccess(mapping, context, "success");
}
use of org.apache.struts.action.ActionForward in project sonarqube by SonarSource.
the class TestMockBase method setUpSecondApp.
protected void setUpSecondApp() {
ActionFormBean formBean = null;
ActionMapping mapping = null;
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
moduleConfig2 = factoryObject.createModuleConfig("/2");
context.setAttribute(Globals.MODULE_KEY + "/2", moduleConfig2);
// Forward "external" to "http://jakarta.apache.org/"
moduleConfig2.addForwardConfig(new ActionForward("external", "http://jakarta.apache.org/", false));
// Forward "foo" to "/baz.jsp" (different from default)
moduleConfig2.addForwardConfig(new ActionForward("foo", "/baz.jsp", false));
// Forward "relative1" to "relative.jsp" non-context-relative
moduleConfig2.addForwardConfig(new ActionForward("relative1", "relative.jsp", false));
// Forward "relative2" to "relative.jsp" context-relative
moduleConfig2.addForwardConfig(new ActionForward("relative2", "relative.jsp", false));
// Form Bean "static" is a standard ActionForm subclass (same as default)
formBean = new ActionFormBean("static", "org.apache.struts.mock.MockFormBean");
moduleConfig2.addFormBeanConfig(formBean);
// Action "/static" uses the "static" form bean in request scope (same as default)
mapping = new ActionMapping();
mapping.setInput("/static.jsp");
mapping.setName("static");
mapping.setPath("/static");
mapping.setScope("request");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig2.addActionConfig(mapping);
// Form Bean "dynamic2" is a DynaActionForm with the same properties
formBean = new ActionFormBean("dynamic2", "org.apache.struts.action.DynaActionForm");
formBean.addFormPropertyConfig(new FormPropertyConfig("booleanProperty", "boolean", "false"));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringProperty", "java.lang.String", null));
moduleConfig2.addFormBeanConfig(formBean);
// Action "/dynamic2" uses the "dynamic2" form bean in session scope
mapping = new ActionMapping();
mapping.setInput("/dynamic2.jsp");
mapping.setName("dynamic2");
mapping.setPath("/dynamic2");
mapping.setScope("session");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig2.addActionConfig(mapping);
// Action "/noform" has no form bean associated with it (same as default)
mapping = new ActionMapping();
mapping.setPath("/noform");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig2.addActionConfig(mapping);
// Configure global forward declarations
moduleConfig2.addForwardConfig(new ForwardConfig("moduleForward", "/module/forward", // No redirect, same module
false));
moduleConfig2.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", // Redirect, same module
true));
moduleConfig2.addForwardConfig(new ForwardConfig("contextForward", // No redirect
"/forward", // No redirect
false, // Specify module
"/context"));
moduleConfig2.addForwardConfig(new ForwardConfig("contextRedirect", // Redirect
"/redirect", // Redirect
true, // Specify module
"/context"));
moduleConfig2.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", // No redirect, same module
false));
moduleConfig2.addForwardConfig(new ForwardConfig("contextNoslash", // No redirect
"noslash", // No redirect
false, // Specify module
"/context"));
}
use of org.apache.struts.action.ActionForward in project sonarqube by SonarSource.
the class TestMockBase method setUpDefaultApp.
protected void setUpDefaultApp() {
ActionFormBean formBean = null;
ActionMapping mapping = null;
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
moduleConfig = factoryObject.createModuleConfig("");
context.setAttribute(Globals.MODULE_KEY, moduleConfig);
// Forward "external" to "http://jakarta.apache.org/"
moduleConfig.addForwardConfig(new ActionForward("external", "http://jakarta.apache.org/", false));
// Forward "foo" to "/bar.jsp"
moduleConfig.addForwardConfig(new ActionForward("foo", "/bar.jsp", false));
// Forward "relative1" to "relative.jsp" non-context-relative
moduleConfig.addForwardConfig(new ActionForward("relative1", "relative.jsp", false));
// Forward "relative2" to "relative.jsp" context-relative
moduleConfig.addForwardConfig(new ActionForward("relative2", "relative.jsp", false));
// Form Bean "static" is a standard ActionForm subclass
formBean = new ActionFormBean("static", "org.apache.struts.mock.MockFormBean");
moduleConfig.addFormBeanConfig(formBean);
// Action "/static" uses the "static" form bean in request scope
mapping = new ActionMapping();
mapping.setInput("/static.jsp");
mapping.setName("static");
mapping.setPath("/static");
mapping.setScope("request");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Form Bean "dynamic" is a DynaActionForm with the same properties
formBean = new ActionFormBean("dynamic", "org.apache.struts.action.DynaActionForm");
formBean.addFormPropertyConfig(new FormPropertyConfig("booleanProperty", "boolean", "false"));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringProperty", "java.lang.String", null));
moduleConfig.addFormBeanConfig(formBean);
// Action "/dynamic" uses the "dynamic" form bean in session scope
mapping = new ActionMapping();
mapping.setInput("/dynamic.jsp");
mapping.setName("dynamic");
mapping.setPath("/dynamic");
mapping.setScope("session");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Form Bean "/dynamic0" is a DynaActionForm with initializers
formBean = new ActionFormBean("dynamic0", "org.apache.struts.action.DynaActionForm");
formBean.addFormPropertyConfig(new FormPropertyConfig("booleanProperty", "boolean", "true"));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringProperty", "java.lang.String", "String Property"));
formBean.addFormPropertyConfig(new FormPropertyConfig("intArray1", "int[]", "{1,2,3}", // 4 should be ignored
4));
formBean.addFormPropertyConfig(new FormPropertyConfig("intArray2", "int[]", null, // 5 should be respected
5));
formBean.addFormPropertyConfig(new FormPropertyConfig("principal", "org.apache.struts.mock.MockPrincipal", null));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray1", "java.lang.String[]", "{aaa,bbb,ccc}", // 2 should be ignored
2));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray2", "java.lang.String[]", null, // 3 should be respected
3));
moduleConfig.addFormBeanConfig(formBean);
// Action "/dynamic0" uses the "dynamic0" form bean in request scope
mapping = new ActionMapping();
mapping.setName("dynamic0");
mapping.setPath("/dynamic0");
mapping.setScope("request");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Action "/noform" has no form bean associated with it
mapping = new ActionMapping();
mapping.setPath("/noform");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Configure global forward declarations
moduleConfig.addForwardConfig(new ForwardConfig("moduleForward", "/module/forward", // No redirect, same module
false));
moduleConfig.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", // Redirect, same module
true));
moduleConfig.addForwardConfig(new ForwardConfig("contextForward", // No redirect
"/forward", // No redirect
false, // Specify module
"/context"));
moduleConfig.addForwardConfig(new ForwardConfig("contextRedirect", // Redirect
"/redirect", // Redirect
true, // Specify module
"/context"));
moduleConfig.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", // No redirect, same module
false));
moduleConfig.addForwardConfig(new ForwardConfig("contextNoslash", // No redirect
"noslash", // No redirect
false, // Specify module
"/context"));
}
use of org.apache.struts.action.ActionForward in project sonarqube by SonarSource.
the class ForwardTag method doEndTag.
/**
* Look up the ActionForward associated with the specified name, and
* perform a forward or redirect to that path as indicated.
*
* @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
// Look up the desired ActionForward entry
ActionForward forward = null;
ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
if (config != null) {
forward = (ActionForward) config.findForwardConfig(name);
}
if (forward == null) {
JspException e = new JspException(messages.getMessage("forward.lookup", name));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
// Forward or redirect to the corresponding actual path
String path = forward.getPath();
path = config.getPrefix() + path;
if (forward.getRedirect()) {
this.doRedirect(path);
} else {
this.doForward(path);
}
// Skip the remainder of this page
return (SKIP_PAGE);
}
Aggregations