List of usage examples for javax.servlet ServletRequest getParameter
public String getParameter(String name);
String
, or null
if the parameter does not exist. From source file:com.netspective.sparx.form.DialogContext.java
/** * Calculate what the next state or stage of the dialog should be. *///from w w w . java 2 s . c om public void calcState() { dialog.makeStateChanges(this, STATECALCSTAGE_BEFORE_VALIDATION); ServletRequest request = getRequest(); DialogFlags dialogFlags = dialog.getDialogFlags(); boolean ignoreValidation = false; if (dialog.getDialogFlags().flagIsSet(DialogFlags.ALLOW_PENDING_DATA)) { String ignoreValidationOption = request.getParameter(dialog.getPendDataParamName()); if (ignoreValidationOption != null && !ignoreValidationOption.equals("no")) { ignoreValidation = true; validationContext.setValidationStage(DialogValidationContext.VALSTAGE_IGNORE); } } autoExecuteRequested = dialog.isAutoExecByDefault(); if (!autoExecuteRequested && !dialog.getDialogFlags().flagIsSet(DialogFlags.DISABLE_AUTO_EXECUTE)) { String autoExecOption = request.getParameter(Dialog.PARAMNAME_AUTOEXECUTE); if (autoExecOption == null || autoExecOption.length() == 0) // if no autoexec is defined in the request parameter, look for it also in the request attribute autoExecOption = (String) request.getAttribute(Dialog.PARAMNAME_AUTOEXECUTE); if (dialog.isAutoExec(this, autoExecOption)) autoExecuteRequested = true; } boolean executeButtonPressed = (request.getParameter(dialog.getSubmitDataParamName()) != null) || (request.getParameter(dialog.getCancelDataParamName()) != null && dialog.getDialogFlags().flagIsSet(DialogFlags.ALLOW_EXECUTE_WITH_CANCEL_BUTTON)); if (autoExecuteRequested || executeButtonPressed || ignoreValidation) { if (!dialogFlags.flagIsSet(DialogFlags.ALLOW_MULTIPLE_EXECUTES) && state.isAlreadyExecuted()) { getValidationContext().addError(dialog.getMultipleExecErrorMessage().getTextValue(this)); state.reset(this); return; } if (dialog.isValid(this)) { state.setExecuteMode(true); autoExecuted = autoExecuteRequested; } else state.setExecuteMode(false); } dialog.makeStateChanges(this, STATECALCSTAGE_AFTER_VALIDATION); }
From source file:com.spshop.web.ShoppingController.java
@SuppressWarnings("unchecked") private List<UserOption> retriveUserOptions(ServletRequest request) { List<UserOption> options = new ArrayList<UserOption>(); Enumeration<String> params = request.getParameterNames(); while (params.hasMoreElements()) { String param = params.nextElement(); String[] ps = param.split(SPLITER_AT); if (ps.length > 1) { UserOption option = new UserOption(); option.setCreateDate(new Date()); option.setOptionName(ps[1]); if (COLOR.equals(ps[0])) { option.setValue(request.getParameter(param)); option.setOptionType(SelectType.COLOR_SINGLE); options.add(option);//from w w w. j a v a 2 s .c om } if (TEXT.equals(ps[0])) { option.setValue(request.getParameter(param)); option.setOptionType(SelectType.SINGLE_LIST); options.add(option); } if (TEXTS.equals(ps[0])) { } } } return options; }
From source file:com.netspective.sparx.form.DialogContext.java
/** * Returns a HTML string which contains hidden form fields representing the dialog's information *//*w w w . j a v a2 s . c om*/ public String getStateHiddens() { final TextUtils textUtils = TextUtils.getInstance(); ServletRequest request = getRequest(); StringBuffer hiddens = new StringBuffer(); hiddens.append("<input type='hidden' name='" + dialog.getDialogStateIdentifierParamName() + "' value='" + textUtils.escapeHTML(state.getIdentifier()) + "'>\n"); String pageCmd = request.getParameter(AbstractHttpServletCommand.PAGE_COMMAND_REQUEST_PARAM_NAME); if (pageCmd != null) hiddens.append( "<input type='hidden' name='" + AbstractHttpServletCommand.PAGE_COMMAND_REQUEST_PARAM_NAME + "' value='" + textUtils.escapeHTML(pageCmd) + "'>\n"); // this hidden field should be filled in by the 'triggering' form field before submission of the form hiddens.append("<input type=\"hidden\" name=\"" + dialog.getDialogValidateTriggerFieldParamName() + "\" value=\"\"/>"); String redirectUrlParamValue = (state.isInitialEntry() ? request.getParameter(dialog.getPostExecuteRedirectUrlParamName()) : request.getParameter(DialogContext.DEFAULT_REDIRECT_PARAM_NAME)); if (redirectUrlParamValue != null) hiddens.append("<input type='hidden' name='" + dialog.getPostExecuteRedirectUrlParamName() + "' value='" + textUtils.escapeHTML(redirectUrlParamValue) + "'>\n"); Set retainedParams = null; if (retainReqParams != null) { retainedParams = new HashSet(); for (int i = 0; i < retainReqParams.length; i++) { String paramName = retainReqParams[i]; Object paramValue = request.getParameter(paramName); if (paramValue == null) continue; hiddens.append("<input type='hidden' name='"); hiddens.append(paramName); hiddens.append("' value='"); hiddens.append(textUtils.escapeHTML(paramValue.toString())); hiddens.append("'>\n"); retainedParams.add(paramName); } } boolean retainedAnyParams = retainedParams != null; if (dialog.retainRequestParams()) { if (dialog.getDialogFlags().flagIsSet(DialogFlags.RETAIN_ALL_REQUEST_PARAMS)) { for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) { String paramName = (String) e.nextElement(); if (paramName.startsWith(Dialog.PARAMNAME_DIALOGPREFIX) || paramName.startsWith(Dialog.PARAMNAME_CONTROLPREFIX) || (retainedAnyParams && retainedParams.contains(paramName))) continue; hiddens.append("<input type='hidden' name='"); hiddens.append(paramName); hiddens.append("' value='"); hiddens.append(request.getParameter(paramName) != null ? textUtils.escapeHTML(request.getParameter(paramName)) : ""); hiddens.append("'>\n"); } } else { String[] retainParams = dialog.getRetainParams(); int retainParamsCount = retainParams.length; for (int i = 0; i < retainParamsCount; i++) { String paramName = retainParams[i]; if (retainedAnyParams && retainedParams.contains(paramName)) continue; hiddens.append("<input type='hidden' name='"); hiddens.append(paramName); hiddens.append("' value='"); hiddens.append(request.getParameter(paramName) != null ? textUtils.escapeHTML(request.getParameter(paramName)) : ""); hiddens.append("'>\n"); } } } return hiddens.toString(); }
From source file:com.school.exam.rest.MakeExmRestController.java
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8) public List<TeExamQuestionVO> get(@PathVariable(value = "id") Long id, @RequestParam(value = "page", defaultValue = "1") int pageNumber, @RequestParam(value = "page.size", defaultValue = "10") int pageSize, @RequestParam(value = "sortType", defaultValue = "auto") String sortType, ServletRequest request) { //Map<String, Object> searchParams = Maps.newHashMap(); //searchParams.put("search_LIKE_questionCont", ""); //searchParams.put("", value) //Map<String, SearchFilter> filters = SearchFilter.parse(searchParams); //filters.put("project.id", new SearchFilter("project.id", Operator.EQ, id)); //new SearchFilter("project.id", Operator.EQ, id).parse(searchParams); Map<String, Object> searchParams = Servlets.getParametersStartingWith(request, "search_"); //List<TeExamQuestionVO> questions =questionService.findByid(id); //return questions; //List<TeExamQuestionVO> questions = questionService.findAllQuestionByProjectId(id, searchParams, pageNumber, pageSize, sortType); List<TeExamQuestionVO> questions = questionService.findValidQuestionByProjectId(id); if (questions == null) { String message = "?(id:" + id + ")"; logger.warn(message);//from w w w . j av a 2 s.co m throw new RestException(HttpStatus.NOT_FOUND, message); } String ids = request.getParameter("questionIds"); if (StringUtils.isNotEmpty(ids)) { for (TeExamQuestionVO vo : questions) { if (ids.indexOf(vo.getId() + "") > -1) { vo.setChecked("1"); } else { vo.setChecked("0"); } } } return questions; }
From source file:cn.vlabs.duckling.vwb.PromitionLogFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { chain.doFilter(request, response); return;//from w w w .ja v a2 s . c o m } HttpServletRequest httpRequest = (HttpServletRequest) request; String serverName = request.getServerName(); if (!StringUtils.equals(serverName, VWBContext.getContainer().getDomainService().getSiteDefaultDomain(ADMIN_SITE_ID))) { chain.doFilter(request, response); return; } HttpSession session = httpRequest.getSession(); String promotionHost = (String) session.getAttribute(PROMOTION_HOST); String requestUrl = httpRequest.getRequestURI(); if (StringUtils.equals(requestUrl, createUrl)) { logCreateJson(promotionHost, requestUrl); } if (StringUtils.isNotBlank(promotionHost)) { chain.doFilter(request, response); return; } String paramRef = request.getParameter(PARAM_REF); if (StringUtils.isNotBlank(paramRef)) { session.setAttribute(PROMOTION_HOST, paramRef); logAccessJson("", paramRef, paramRef, requestUrl); chain.doFilter(request, response); return; } String referer = httpRequest.getHeader("Referer"); String referHost = getRefererHost(referer); if (StringUtils.isNotBlank(referHost)) { session.setAttribute(PROMOTION_HOST, getRefererNameByHost(referHost)); logAccessJson(referer, referHost, getRefererNameByHost(referHost), requestUrl); chain.doFilter(request, response); } }
From source file:cc.kune.core.server.searcheable.SearchEngineServletFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException, DefaultException { if (filterConfig == null) { return;/* w ww . j a v a 2 s. c o m*/ } if (request instanceof HttpServletRequest) { final HttpServletRequest httpReq = (HttpServletRequest) request; final StringBuffer url = httpReq.getRequestURL(); final String queryString = httpReq.getQueryString(); if ((queryString != null) && (queryString.contains(SiteParameters.ESCAPED_FRAGMENT_PARAMETER))) { if (!enabled) { final HttpServletResponse httpRes = (HttpServletResponse) response; httpRes.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Search Engine service disabled temporally"); return; } // rewrite the URL back to the original #! version // remember to unescape any %XX characters final String urlWithEscapedFragment = request .getParameter(SiteParameters.ESCAPED_FRAGMENT_PARAMETER); final String newUrl = url.append("?").append(queryString).toString() .replaceFirst(SiteParameters.ESCAPED_FRAGMENT_PARAMETER, SiteParameters.NO_UA_CHECK) .replaceFirst("/ws", "") + "#" + urlWithEscapedFragment; LOG.info("New url with hash: " + newUrl); final String page = "In development"; // return the snapshot response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); response.getOutputStream().write(page.getBytes()); } else { try { // not an _escaped_fragment_ URL, so move up the chain of // servlet (filters) chain.doFilter(request, response); } catch (final ServletException e) { LOG.error("Servlet exception caught: " + e); } } } }
From source file:org.kuali.rice.krad.web.bind.UifServletRequestDataBinder.java
/** * Calls {@link org.kuali.rice.krad.web.form.UifFormBase#preBind(HttpServletRequest)}, Performs data binding * from servlet request parameters to the form, initializes view object, then calls * {@link org.kuali.rice.krad.web.form.UifFormBase#postBind(javax.servlet.http.HttpServletRequest)} * * <p>/*from w w w .jav a2s .c o m*/ * The view is initialized by first looking for the {@code viewId} parameter in the request. If found, the view is * retrieved based on this id. If the id is not present, then an attempt is made to find a view by type. In order * to retrieve a view based on type, the view request parameter {@code viewTypeName} must be present. If all else * fails and the viewId is populated on the form (could be populated from a previous request), this is used to * retrieve the view. * </p> * * @param request - HTTP Servlet Request instance */ @Override public void bind(ServletRequest request) { UifFormBase form = (UifFormBase) UifServletRequestDataBinder.this.getTarget(); request.setAttribute(UifConstants.REQUEST_FORM, form); form.preBind((HttpServletRequest) request); _bind(request); request.setAttribute(UifConstants.PROPERTY_EDITOR_REGISTRY, this.bindingResult.getPropertyEditorRegistry()); executeAutomaticLinking(request, form); if (!form.isUpdateNoneRequest()) { // attempt to retrieve a view by unique identifier first, either as request attribute or parameter String viewId = (String) request.getAttribute(UifParameters.VIEW_ID); if (StringUtils.isBlank(viewId)) { viewId = request.getParameter(UifParameters.VIEW_ID); } View view = null; if (StringUtils.isNotBlank(viewId)) { view = getViewService().getViewById(viewId); } // attempt to get view instance by type parameters if (view == null) { view = getViewByType(request, form); } // if view not found attempt to find one based on the cached form if (view == null) { view = getViewFromPreviousModel(form); if (view != null) { LOG.warn("Obtained viewId from cached form, this may not be safe!"); } } if (view != null) { form.setViewId(view.getId()); } else { form.setViewId(null); } form.setView(view); } // invoke form callback for custom binding form.postBind((HttpServletRequest) request); }
From source file:ru.org.linux.site.Message.java
public Message(Connection db, Message original, ServletRequest request) throws BadGroupException, SQLException, UtilException, UserErrorException { userAgent = original.userAgent;//from w ww. jav a2 s. c o m postIP = original.postIP; guid = original.guid; Group group = new Group(db, guid); groupCommentsRestriction = group.getCommentsRestriction(); if (request.getParameter("linktext") != null) { linktext = request.getParameter("linktext"); } else { linktext = original.linktext; } if (request.getParameter("url") != null) { url = request.getParameter("url"); } else { url = original.url; } // if (request.getParameter("tags")!=null) { // List<String> newTags = Tags.parseTags(request.getParameter("tags")); // // tags = new Tags(newTags); // } else { // tags = original.tags; // } // url check if (!group.isImagePostAllowed()) { if (url != null && !"".equals(url)) { if (linktext == null) { throw new BadInputException(" URL ?"); } url = URLUtil.fixURL(url); } } if (request.getParameter("title") != null) { title = HTMLFormatter.htmlSpecialChars(request.getParameter("title")); } else { title = original.title; } if (request.getParameter("resolve") != null) { resolved = "yes".equals(request.getParameter("resolve")); } else { resolved = original.resolved; } havelink = original.havelink; sectionid = group.getSectionId(); msgid = original.msgid; postscore = original.getPostScore(); votepoll = original.votepoll; sticky = original.sticky; deleted = original.deleted; expired = original.expired; commitby = original.commitby; postdate = original.postdate; commitDate = original.commitDate; groupTitle = original.groupTitle; groupUrl = original.groupUrl; lastModified = new Timestamp(System.currentTimeMillis()); commentCount = original.commentCount; moderate = original.moderate; notop = original.notop; userid = original.userid; lorcode = original.lorcode; minor = original.minor; if (request.getParameter("newmsg") != null) { message = request.getParameter("newmsg"); } else { message = original.message; } try { section = new Section(db, sectionid); } catch (SectionNotFoundException ex) { throw new RuntimeException(ex); } }
From source file:fr.paris.lutece.plugins.directory.modules.rest.service.DirectoryRestService.java
/** * {@inheritDoc}//www . j av a 2s . co m */ @Override public Record addToDirectory(String strIdDirectory, ServletRequest request) throws DirectoryErrorException { int nDirectoryId = Integer.parseInt(strIdDirectory); Directory directory = DirectoryHome.findByPrimaryKey(nDirectoryId, getPlugin()); Record record = new Record(); record.setDirectory(directory); record.setDateCreation(DirectoryUtils.getCurrentTimestamp()); record.setEnabled(directory.isRecordActivated()); List<RecordField> listRecordFields = getRecordFields((HttpServletRequest) request, record); record.setListRecordField(listRecordFields); // do not use the workflow if creation is partial String strNoWorkflowInit = request.getParameter(PARAMETER_NO_WORKFLOW); TransactionManager.beginTransaction(getPlugin()); try { //save the Record and the RecordFiels record.setIdRecord(RecordHome.create(record, getPlugin())); if (StringUtils.isBlank(strNoWorkflowInit) && isEntrySet(listRecordFields, nDirectoryId)) { doWorkflowActions(record, directory); } TransactionManager.commitTransaction(getPlugin()); } catch (Exception e) { TransactionManager.rollBack(getPlugin()); throw new AppException(e.getMessage(), e); } return record; }
From source file:org.wso2.carbon.identity.captcha.connector.recaptcha.PasswordRecoveryReCaptchaConnector.java
@Override public CaptchaPreValidationResponse preValidate(ServletRequest servletRequest, ServletResponse servletResponse) throws CaptchaException { CaptchaPreValidationResponse preValidationResponse = new CaptchaPreValidationResponse(); HttpServletRequest httpServletRequestWrapper; try {/*from ww w . j a v a 2s . c om*/ httpServletRequestWrapper = new CaptchaHttpServletRequestWrapper((HttpServletRequest) servletRequest); preValidationResponse.setWrappedHttpServletRequest(httpServletRequestWrapper); } catch (IOException e) { log.error("Error occurred while wrapping ServletRequest.", e); return preValidationResponse; } String path = httpServletRequestWrapper.getRequestURI(); User user = new User(); boolean initializationFlow = false; if (CaptchaUtil.isPathAvailable(path, ACCOUNT_SECURITY_QUESTION_URL) || CaptchaUtil.isPathAvailable(path, ACCOUNT_SECURITY_QUESTIONS_URL)) { user.setUserName(servletRequest.getParameter("username")); if (StringUtils.isNotBlank(servletRequest.getParameter("realm"))) { user.setUserStoreDomain(servletRequest.getParameter("realm")); } else { user.setUserStoreDomain(IdentityUtil.getPrimaryDomainName()); } user.setTenantDomain(servletRequest.getParameter("tenant-domain")); initializationFlow = true; } else { JsonObject requestObject; try { try (InputStream in = httpServletRequestWrapper.getInputStream()) { requestObject = new JsonParser().parse(IOUtils.toString(in)).getAsJsonObject(); } } catch (IOException e) { return preValidationResponse; } UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance(); try { UserRecoveryData userRecoveryData = userRecoveryDataStore .load(requestObject.get("key").getAsString()); if (userRecoveryData != null) { user = userRecoveryData.getUser(); } } catch (IdentityRecoveryException e) { return preValidationResponse; } } if (StringUtils.isBlank(user.getUserName())) { // Invalid Request return preValidationResponse; } if (StringUtils.isBlank(user.getTenantDomain())) { user.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); } Property[] connectorConfigs; try { connectorConfigs = identityGovernanceService .getConfiguration( new String[] { RECOVERY_QUESTION_PASSWORD_RECAPTCHA_ENABLE, RECOVERY_QUESTION_PASSWORD_RECAPTCHA_MAX_FAILED_ATTEMPTS }, user.getTenantDomain()); } catch (IdentityGovernanceException e) { throw new CaptchaServerException("Unable to retrieve connector configs.", e); } String connectorEnabled = null; String maxAttemptsStr = null; for (Property connectorConfig : connectorConfigs) { if ((RECOVERY_QUESTION_PASSWORD_RECAPTCHA_ENABLE).equals(connectorConfig.getName())) { connectorEnabled = connectorConfig.getValue(); } else if ((RECOVERY_QUESTION_PASSWORD_RECAPTCHA_MAX_FAILED_ATTEMPTS) .equals(connectorConfig.getName())) { maxAttemptsStr = connectorConfig.getValue(); } } if (!Boolean.parseBoolean(connectorEnabled)) { return preValidationResponse; } if (StringUtils.isBlank(maxAttemptsStr) || !NumberUtils.isNumber(maxAttemptsStr)) { log.warn("Invalid configuration found in the PasswordRecoveryReCaptchaConnector for the tenant - " + user.getTenantDomain()); return preValidationResponse; } int maxFailedAttempts = Integer.parseInt(maxAttemptsStr); int tenantId; try { tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain()); } catch (Exception e) { //Invalid tenant return preValidationResponse; } Map<String, String> claimValues = CaptchaUtil.getClaimValues(user, tenantId, new String[] { FAIL_ATTEMPTS_CLAIM, ACCOUNT_LOCKED_CLAIM }); if (claimValues == null || claimValues.isEmpty()) { // Invalid user return preValidationResponse; } if (Boolean.parseBoolean(claimValues.get(ACCOUNT_LOCKED_CLAIM))) { return preValidationResponse; } int currentFailedAttempts = 0; if (NumberUtils.isNumber(claimValues.get(FAIL_ATTEMPTS_CLAIM))) { currentFailedAttempts = Integer.parseInt(claimValues.get(FAIL_ATTEMPTS_CLAIM)); } HttpServletResponse httpServletResponse = ((HttpServletResponse) servletResponse); if (currentFailedAttempts > maxFailedAttempts) { if (initializationFlow) { httpServletResponse.setHeader("reCaptcha", "true"); httpServletResponse.setHeader("reCaptchaKey", CaptchaDataHolder.getInstance().getReCaptchaSiteKey()); httpServletResponse.setHeader("reCaptchaAPI", CaptchaDataHolder.getInstance().getReCaptchaAPIUrl()); } else { preValidationResponse.setCaptchaValidationRequired(true); preValidationResponse.setMaxFailedLimitReached(true); addPostValidationData(servletRequest); } } else if (currentFailedAttempts == maxFailedAttempts && !initializationFlow) { addPostValidationData(servletRequest); } return preValidationResponse; }