List of usage examples for javax.servlet.http HttpServletRequest setAttribute
public void setAttribute(String name, Object o);
From source file:com.liangc.hq.base.utils.AlertDefUtil.java
/** * Retrieve the alert definition from either the request or from the bizapp * as necessary. First check to see if the alertDef is already in the * request attributes. If it is, return it. If not, look for an "ad" * parameter and then get the alert definition from the bizapp and return * it./* w ww. j a v a 2s. c o m*/ */ public static AlertDefinitionValue getAlertDefinition(HttpServletRequest request, int sessionID, EventsBoss eb) throws Exception { AlertDefinitionValue adv = (AlertDefinitionValue) request.getAttribute(Constants.ALERT_DEFINITION_ATTR); if (null == adv) { String adS = request.getParameter(Constants.ALERT_DEFINITION_PARAM); if (null == adS) { throw new Exception(Constants.ALERT_DEFINITION_PARAM); } else { Integer ad = new Integer(adS); adv = eb.getAlertDefinition(sessionID, ad); request.setAttribute(Constants.ALERT_DEFINITION_ATTR, adv); } log.trace("adv.id=" + adv.getId()); } return adv; }
From source file:common.web.controller.CommonActions.java
/** * executes bind of parameters to command and selecting results that matches criteria * @param service/*from ww w . java 2 s . c o m*/ * @param config * @param val for validation * @param req resulting model (i.e. errors, command objects ...) will be placed here */ public static <T> void doFilteredSelect(IFilterService<T> service, IControllerConfig config, ABindValidator val, HttpServletRequest req) { RequestUtils.copyRequestAttributesFromMap(req, service.initFilter()); IFilterBean<T> command = service.getFilterBean(); BindingResult res = val.bindAndValidate(command, req); if (res.hasErrors()) { common.CommonAttributes.addErrorMessage("form_errors", req); //req.setAttribute(res.MODEL_KEY_PREFIX+config.getContentDataAttribute(), res); //req.setAttribute(config.getContentDataAttribute(), command); } else { //String action = req.getParameter(ControllerConfig.ACTION_PARAM_NAME); //if (action != null && action.equals("filter")){ // req.setAttribute(config.getContentDataAttribute(), command); //} else { req.setAttribute(config.getContentDataAttribute(), command.getItems(service)); //} } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ViewCourseInquiryPublicResults.java
public static ActionForward getCourseResultsActionForward(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { String executionCourseId = request.getParameter("executionCourseOID"); if (executionCourseId == null) { executionCourseId = request.getParameter("executionCourseID"); }/*from w w w .j a va2 s . co m*/ ExecutionCourse executionCourse = FenixFramework.getDomainObject(executionCourseId); ExecutionSemester executionPeriod = executionCourse.getExecutionPeriod(); CurricularCourseInquiryTemplate curricularCourseInquiryTemplate = CurricularCourseInquiryTemplate .getTemplateByExecutionPeriod(executionPeriod); if (curricularCourseInquiryTemplate == null) { request.setAttribute("notAvailableMessage", "message.inquiries.publicResults.notAvailable.m1"); return mapping.findForward("execution-course-student-inquiries-result-notAvailable"); } DegreeCurricularPlan dcp = FenixFramework.getDomainObject(request.getParameter("degreeCurricularPlanOID")); ExecutionDegree executionDegree = dcp .getExecutionDegreeByAcademicInterval(executionPeriod.getAcademicInterval()); List<InquiryResult> results = executionCourse .getInquiryResultsByExecutionDegreeAndForTeachers(executionDegree); boolean hasNotRelevantData = executionCourse.hasNotRelevantDataFor(executionDegree); ResultsInquiryTemplate resultsInquiryTemplate = ResultsInquiryTemplate .getTemplateByExecutionPeriod(executionPeriod); Collection<InquiryBlock> resultBlocks = resultsInquiryTemplate.getInquiryBlocksSet(); GroupResultsSummaryBean ucGroupResultsSummaryBean = getGeneralResults(results, resultBlocks, GroupResultType.COURSE_RESULTS); GroupResultsSummaryBean answersResultsSummaryBean = getGeneralResults(results, resultBlocks, GroupResultType.COURSE_ANSWERS); GroupResultsSummaryBean nonAnswersResultsSummaryBean = getGeneralResults(results, resultBlocks, GroupResultType.COURSE_NON_ANSWERS); if (executionCourse.getAvailableForInquiries()) { Collections.sort(nonAnswersResultsSummaryBean.getQuestionsResults(), new BeanComparator("questionResult.value")); Collections.reverse(nonAnswersResultsSummaryBean.getQuestionsResults()); } CurricularCourse curricularCourse = executionCourse.getCurricularCourseFor(dcp); Double ects = curricularCourse.getEctsCredits(executionPeriod); Double contactLoadEcts = curricularCourse.getContactLoad() / 28; Double autonumousWorkEcts = ects - contactLoadEcts; GroupResultsSummaryBean workLoadSummaryBean = getGeneralResults(results, resultBlocks, GroupResultType.WORKLOAD); request.setAttribute("contactLoadEcts", contactLoadEcts); request.setAttribute("autonumousWorkEcts", autonumousWorkEcts); GroupResultsSummaryBean ucGeneralDataSummaryBean = getGeneralResults(results, resultBlocks, GroupResultType.COURSE_GENERAL_DATA); GroupResultsSummaryBean ucEvaluationsGroupBean = getGeneralResults(results, resultBlocks, GroupResultType.COURSE_EVALUATIONS); InquiryQuestion estimatedEvaluationQuestion = getEstimatedEvaluationsQuestion( curricularCourseInquiryTemplate.getInquiryBlocksSet()); QuestionResultsSummaryBean estimatedEvaluationBeanQuestion = new QuestionResultsSummaryBean( estimatedEvaluationQuestion, getResultsForQuestion(results, estimatedEvaluationQuestion), null, null); InquiryQuestion totalAnswersQuestion = getInquiryQuestion(results, InquiryResultType.COURSE_TOTAL_ANSWERS); request.setAttribute("totalAnswers", new QuestionResultsSummaryBean(totalAnswersQuestion, getResultsForQuestion(results, totalAnswersQuestion).iterator().next())); List<TeacherShiftTypeGeneralResultBean> teachersSummaryBeans = getTeachersShiftsResults(executionCourse); Collections.sort(teachersSummaryBeans, new BeanComparator("professorship.person.name")); Collections.sort(teachersSummaryBeans, new BeanComparator("shiftType")); ResultClassification auditResult = getAuditResult(results); if (auditResult != null) { request.setAttribute("auditResult", auditResult.name()); } request.setAttribute("ucGroupResultsSummaryBean", ucGroupResultsSummaryBean); request.setAttribute("answersResultsSummaryBean", answersResultsSummaryBean); request.setAttribute("nonAnswersResultsSummaryBean", nonAnswersResultsSummaryBean); request.setAttribute("workLoadSummaryBean", workLoadSummaryBean); request.setAttribute("ucGeneralDataSummaryBean", ucGeneralDataSummaryBean); request.setAttribute("ucEvaluationsGroupBean", ucEvaluationsGroupBean); request.setAttribute("estimatedEvaluationBeanQuestion", estimatedEvaluationBeanQuestion); request.setAttribute("teachersSummaryBeans", teachersSummaryBeans); CurricularCourseInquiryTemplate courseInquiryTemplate = CurricularCourseInquiryTemplate .getTemplateByExecutionPeriod(executionPeriod); List<BlockResultsSummaryBean> blockResultsSummaryBeans = new ArrayList<BlockResultsSummaryBean>(); for (InquiryBlock inquiryBlock : courseInquiryTemplate.getInquiryBlocksSet()) { blockResultsSummaryBeans.add(new BlockResultsSummaryBean(inquiryBlock, results, null, null)); } Collections.sort(blockResultsSummaryBeans, new BeanComparator("inquiryBlock.blockOrder")); request.setAttribute("hasNotRelevantData", hasNotRelevantData); request.setAttribute("executionCourse", executionCourse); request.setAttribute("executionPeriod", executionPeriod); request.setAttribute("executionDegree", executionDegree); request.setAttribute("resultsDate", results.iterator().next().getResultDate()); request.setAttribute("blockResultsSummaryBeans", blockResultsSummaryBeans); request.setAttribute("publicContext", true); return new ActionForward(null, "/inquiries/showCourseInquiryResult_v3.jsp", false, "/teacher"); }
From source file:grails.converters.XML.java
/** * Parses the give XML (read from the POST Body of the Request) * * @param request an HttpServletRequest//from w w w. jav a 2 s . c om * @return a groovy.util.XmlSlurper * @throws ConverterException */ public static Object parse(HttpServletRequest request) throws ConverterException { Object xml = request.getAttribute(CACHED_XML); if (xml != null) return xml; String encoding = request.getCharacterEncoding(); if (encoding == null) { encoding = Converter.DEFAULT_REQUEST_ENCODING; } try { if (!request.getMethod().equalsIgnoreCase("GET")) { xml = parse(request.getInputStream(), encoding); request.setAttribute(CACHED_XML, xml); } return xml; } catch (IOException e) { throw new ConverterException("Error parsing XML", e); } }
From source file:cn.vlabs.duckling.vwb.VWBContext.java
public static VWBContext createContext(HttpServletRequest request, String requestContext) { SiteMetaInfo site = VWBContainerImpl.findSite(request); Command command = CommandResolver.findCommand(requestContext); IResourceService resourceService = getContainer().getResourceService(); VWBContext context = new VWBContext(request, site, command, resourceService.getResource(site.getId(), Constant.DEFAULT_FRONT_PAGE)); request.setAttribute(CONTEXT_KEY, context); return context; }
From source file:com.aoindustries.website.signup.SignupTechnicalActionHelper.java
public static void setRequestAttributes(ServletContext servletContext, HttpServletRequest request, SignupTechnicalForm signupTechnicalForm) throws IOException, SQLException { AOServConnector rootConn = SiteSettings.getInstance(servletContext).getRootAOServConnector(); // Build the list of countries List<SignupBusinessActionHelper.CountryOption> countryOptions = SignupBusinessActionHelper .getCountryOptions(rootConn); // Generate random passwords, keeping the selected password at index 0 List<String> passwords = new ArrayList<String>(16); if (!GenericValidator.isBlankOrNull(signupTechnicalForm.getBaPassword())) passwords.add(signupTechnicalForm.getBaPassword()); while (passwords.size() < 16) passwords.add(PasswordGenerator.generatePassword()); // Store to the request request.setAttribute("countryOptions", countryOptions); request.setAttribute("passwords", passwords); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ViewTeacherInquiryPublicResults.java
public static ActionForward getTeacherResultsActionForward(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { Professorship professorship = FenixFramework.getDomainObject(request.getParameter("professorshipOID")); ShiftType shiftType = ShiftType.valueOf(request.getParameter("shiftType")); List<InquiryResult> inquiryResults = professorship.getInquiryResults(shiftType); ExecutionSemester executionPeriod = professorship.getExecutionCourse().getExecutionPeriod(); ResultsInquiryTemplate resultsInquiryTemplate = ResultsInquiryTemplate .getTemplateByExecutionPeriod(executionPeriod); Collection<InquiryBlock> resultBlocks = resultsInquiryTemplate.getInquiryBlocksSet(); GroupResultsSummaryBean teacherGroupResultsSummaryBean = getGeneralResults(inquiryResults, resultBlocks, GroupResultType.TEACHER_RESULTS); request.setAttribute("teacherGroupResultsSummaryBean", teacherGroupResultsSummaryBean); InquiryResult teacherEvaluation = getTeacherEvaluation(inquiryResults); request.setAttribute("teacherEvaluation", teacherEvaluation); StudentTeacherInquiryTemplate teacherInquiryTemplate = StudentTeacherInquiryTemplate .getTemplateByExecutionPeriod(executionPeriod); List<BlockResultsSummaryBean> blockResultsSummaryBeans = new ArrayList<BlockResultsSummaryBean>(); for (InquiryBlock inquiryBlock : teacherInquiryTemplate.getInquiryBlocksSet()) { blockResultsSummaryBeans.add(new BlockResultsSummaryBean(inquiryBlock, inquiryResults, null, null)); }//from w w w. java 2s. c om Collections.sort(blockResultsSummaryBeans, new BeanComparator("inquiryBlock.blockOrder")); request.setAttribute("executionCourse", professorship.getExecutionCourse()); request.setAttribute("shiftType", shiftType); request.setAttribute("professorship", professorship); request.setAttribute("executionPeriod", executionPeriod); request.setAttribute("blockResultsSummaryBeans", blockResultsSummaryBeans); request.setAttribute("resultsDate", inquiryResults.iterator().next().getResultDate()); setTeacherScaleColorException(executionPeriod, request); request.setAttribute("publicContext", true); return new ActionForward(null, "/inquiries/showTeacherInquiryResult_v3.jsp", false, "/teacher"); }
From source file:eu.eidas.node.utils.EidasNodeErrorUtil.java
private static String getErrorReportingUrl(final HttpServletRequest request, IEIDASSession eidasSession) { Object spUrl = request.getSession().getAttribute(EIDASParameters.SP_URL.toString()); Object errorUrl = eidasSession == null ? null : eidasSession.get(EIDASParameters.ERROR_REDIRECT_URL.toString()); Object errorInterceptorUrl = eidasSession == null ? null : eidasSession.get(EIDASParameters.ERROR_INTERCEPTOR_URL.toString()); if (errorUrl != null) { spUrl = errorUrl;// w ww .j av a 2s. c o m } if (errorInterceptorUrl != null) { request.setAttribute("redirectUrl", spUrl); spUrl = errorInterceptorUrl; } return spUrl == null ? null : spUrl.toString(); }
From source file:org.apache.ofbiz.passport.event.GitHubEvents.java
private static String checkLoginGitHubUser(HttpServletRequest request, Map<String, Object> userInfo, String accessToken) {//from w ww. ja v a2 s .com Delegator delegator = (Delegator) request.getAttribute("delegator"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); String productStoreId = ProductStoreWorker.getProductStoreId(request); String gitHubUserId = (String) userInfo.get("login"); GenericValue gitHubUser = null; try { gitHubUser = delegator.findOne("GitHubUser", UtilMisc.toMap("gitHubUserId", gitHubUserId), false); } catch (GenericEntityException e) { request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); return "error"; } if (UtilValidate.isNotEmpty(gitHubUser)) { boolean dataChanged = false; if (!accessToken.equals(gitHubUser.getString("accessToken"))) { gitHubUser.set("accessToken", accessToken); dataChanged = true; } if (!envPrefix.equals(gitHubUser.getString("envPrefix"))) { gitHubUser.set("envPrefix", envPrefix); dataChanged = true; } if (!productStoreId.equals(gitHubUser.getString("productStoreId"))) { gitHubUser.set("productStoreId", productStoreId); dataChanged = true; } if (dataChanged) { try { gitHubUser.store(); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); } } } else { gitHubUser = delegator.makeValue("GitHubUser", UtilMisc.toMap("accessToken", accessToken, "productStoreId", productStoreId, "envPrefix", envPrefix, "gitHubUserId", gitHubUserId)); try { gitHubUser.create(); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); } } try { GenericValue userLogin = EntityUtil.getFirst( delegator.findByAnd("UserLogin", UtilMisc.toMap("externalAuthId", gitHubUserId), null, false)); GitHubAuthenticator authn = new GitHubAuthenticator(); authn.initialize(dispatcher); if (UtilValidate.isEmpty(userLogin)) { String userLoginId = authn.createUser(userInfo); userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", userLoginId), false); } String autoPassword = RandomStringUtils.randomAlphanumeric( EntityUtilProperties.getPropertyAsInteger("security", "password.length.min", 5).intValue()); boolean useEncryption = "true".equals(UtilProperties.getPropertyValue("security", "password.encrypt")); userLogin.set("currentPassword", useEncryption ? HashCrypt.digestHash(LoginServices.getHashType(), null, autoPassword) : autoPassword); userLogin.store(); request.setAttribute("USERNAME", userLogin.getString("userLoginId")); request.setAttribute("PASSWORD", autoPassword); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (AuthenticatorException e) { Debug.logError(e.getMessage(), module); request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } return "success"; }
From source file:com.hihsoft.baseclass.web.controller.BaseController.java
public static <T> T getOrCreateRequestAttribute(HttpServletRequest request, String key, Class<T> clazz) { Object value = request.getAttribute(key); if (value == null) { try {// w w w . j ava 2s . com value = clazz.newInstance(); } catch (Exception e) { ReflectionUtils.handleReflectionException(e); } request.setAttribute(key, value); } return clazz.cast(value); }