List of usage examples for javax.servlet.http HttpServletRequest getParameter
public String getParameter(String name);
String
, or null
if the parameter does not exist. From source file:fr.paris.lutece.plugins.search.solr.web.SolrSearchApp.java
/** * Performs a search and fills the model (useful when a page needs to remind * search parameters/results)//ww w.j a v a2 s . c o m * * @param request the request * @param conf the configuration * @return the model * @throws SiteMessageException if an error occurs */ public static Map<String, Object> getSearchResultModel(HttpServletRequest request, SolrSearchAppConf conf) throws SiteMessageException { String strQuery = request.getParameter(PARAMETER_QUERY); String[] facetQuery = request.getParameterValues(PARAMETER_FACET_QUERY); String sort = request.getParameter(PARAMETER_SORT_NAME); String order = request.getParameter(PARAMETER_SORT_ORDER); String strCurrentPageIndex = request.getParameter(PARAMETER_PAGE_INDEX); String fname = StringUtils.isBlank(request.getParameter(PARAMETER_FACET_NAME)) ? null : request.getParameter(PARAMETER_FACET_LABEL).trim(); String flabel = StringUtils.isBlank(request.getParameter(PARAMETER_FACET_LABEL)) ? null : request.getParameter(PARAMETER_FACET_LABEL).trim(); String strConfCode = request.getParameter(PARAMETER_CONF); Locale locale = request.getLocale(); if (conf == null) { //Use default conf if not provided conf = SolrSearchAppConfService.loadConfiguration(null); } StringBuilder sbFacetQueryUrl = new StringBuilder(); SolrFieldManager sfm = new SolrFieldManager(); List<String> lstSingleFacetQueries = new ArrayList<String>(); Hashtable<String, Boolean> switchType = getSwitched(); ArrayList<String> facetQueryTmp = new ArrayList<String>(); if (facetQuery != null) { for (String fq : facetQuery) { if (sbFacetQueryUrl.indexOf(fq) == -1) { String strFqNameIHM = getFacetNameFromIHM(fq); String strFqValueIHM = getFacetValueFromIHM(fq); if (fname == null || !switchType.containsKey(fname) || (strFqNameIHM != null && strFqValueIHM != null && strFqValueIHM.equalsIgnoreCase(flabel) && strFqNameIHM.equalsIgnoreCase(fname))) { sbFacetQueryUrl.append("&fq=" + fq); sfm.addFacet(fq); facetQueryTmp.add(fq); lstSingleFacetQueries.add(fq); } } } // for (String fq : facetQuery) // { // if (sbFacetQueryUrl.indexOf(fq) == -1) // { // // sbFacetQueryUrl.append("&fq=" + fq); // sfm.addFacet(fq); // lstSingleFacetQueries.add(fq); // } // } } facetQuery = new String[facetQueryTmp.size()]; facetQuery = facetQueryTmp.toArray(facetQuery); if (StringUtils.isNotBlank(conf.getFilterQuery())) { int nNewLength = (facetQuery == null) ? 1 : (facetQuery.length + 1); String[] newFacetQuery = new String[nNewLength]; for (int i = 0; i < (nNewLength - 1); i++) { newFacetQuery[i] = facetQuery[i]; } newFacetQuery[newFacetQuery.length - 1] = conf.getFilterQuery(); facetQuery = newFacetQuery; } boolean bEncodeUri = Boolean.parseBoolean( AppPropertiesService.getProperty(PROPERTY_ENCODE_URI, Boolean.toString(DEFAULT_ENCODE_URI))); String strSearchPageUrl = AppPropertiesService.getProperty(PROPERTY_SEARCH_PAGE_URL); String strError = SolrConstants.CONSTANT_EMPTY_STRING; int nLimit = SOLR_RESPONSE_MAX; // Check XSS characters if ((strQuery != null) && (StringUtil.containsXssCharacters(strQuery))) { strError = I18nService.getLocalizedString(MESSAGE_INVALID_SEARCH_TERMS, locale); } if (StringUtils.isNotBlank(strError) || StringUtils.isBlank(strQuery)) { strQuery = ALL_SEARCH_QUERY; String strOnlyFacets = AppPropertiesService.getProperty(PROPERTY_ONLY_FACTES); if (StringUtils.isNotBlank(strError) || (((facetQuery == null) || (facetQuery.length <= 0)) && StringUtils.isNotBlank(strOnlyFacets) && SolrConstants.CONSTANT_TRUE.equals(strOnlyFacets))) { //no request and no facet selected : we show the facets but no result nLimit = 0; } } // paginator & session related elements int nDefaultItemsPerPage = AppPropertiesService.getPropertyInt(PROPERTY_RESULTS_PER_PAGE, DEFAULT_RESULTS_PER_PAGE); String strCurrentItemsPerPage = request.getParameter(PARAMETER_NB_ITEMS_PER_PAGE); int nCurrentItemsPerPage = strCurrentItemsPerPage != null ? Integer.parseInt(strCurrentItemsPerPage) : 0; int nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE, nCurrentItemsPerPage, nDefaultItemsPerPage); strCurrentPageIndex = (strCurrentPageIndex != null) ? strCurrentPageIndex : DEFAULT_PAGE_INDEX; SolrSearchEngine engine = SolrSearchEngine.getInstance(); SolrFacetedResult facetedResult = engine.getFacetedSearchResults(strQuery, facetQuery, sort, order, nLimit, Integer.parseInt(strCurrentPageIndex), nItemsPerPage, SOLR_SPELLCHECK); List<SolrSearchResult> listResults = facetedResult.getSolrSearchResults(); List<HashMap<String, Object>> points = null; if (conf.getExtraMappingQuery()) { List<SolrSearchResult> listResultsGeoloc = engine.getGeolocSearchResults(strQuery, facetQuery, nLimit); points = getGeolocModel(listResultsGeoloc); } // The page should not be added to the cache // Notify results infos to QueryEventListeners notifyQueryListeners(strQuery, listResults.size(), request); UrlItem url = new UrlItem(strSearchPageUrl); String strQueryForPaginator = strQuery; if (bEncodeUri) { strQueryForPaginator = SolrUtil.encodeUrl(request, strQuery); } url.addParameter(PARAMETER_QUERY, strQueryForPaginator); url.addParameter(PARAMETER_NB_ITEMS_PER_PAGE, nItemsPerPage); if (strConfCode != null) { url.addParameter(PARAMETER_CONF, strConfCode); } for (String strFacetName : lstSingleFacetQueries) { url.addParameter(PARAMETER_FACET_QUERY, SolrUtil.encodeUrl(strFacetName)); } // nb items per page IPaginator<SolrSearchResult> paginator = new DelegatePaginator<SolrSearchResult>(listResults, nItemsPerPage, url.getUrl(), PARAMETER_PAGE_INDEX, strCurrentPageIndex, facetedResult.getCount()); Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_RESULTS_LIST, paginator.getPageItems()); // put the query only if it's not *.* model.put(MARK_QUERY, ALL_SEARCH_QUERY.equals(strQuery) ? SolrConstants.CONSTANT_EMPTY_STRING : strQuery); model.put(MARK_FACET_QUERY, sbFacetQueryUrl.toString()); model.put(MARK_PAGINATOR, paginator); model.put(MARK_NB_ITEMS_PER_PAGE, nItemsPerPage); model.put(MARK_ERROR, strError); model.put(MARK_FACETS, facetedResult.getFacetFields()); model.put(MARK_SOLR_FIELDS, SolrFieldManager.getFacetList()); model.put(MARK_FACETS_DATE, facetedResult.getFacetDateList()); model.put(MARK_HISTORIQUE, sfm.getCurrentFacet()); model.put(MARK_FACETS_LIST, lstSingleFacetQueries); model.put(MARK_CONF_QUERY, strConfCode); model.put(MARK_CONF, conf); model.put(MARK_POINTS, points); if (SOLR_SPELLCHECK && (strQuery != null) && (strQuery.compareToIgnoreCase(ALL_SEARCH_QUERY) != 0)) { SpellCheckResponse checkResponse = engine.getSpellChecker(strQuery); if (checkResponse != null) { model.put(MARK_SUGGESTION, checkResponse.getCollatedResults()); //model.put(MARK_SUGGESTION, facetedResult.getSolrSpellCheckResponse().getCollatedResults()); } } model.put(MARK_SORT_NAME, sort); model.put(MARK_SORT_ORDER, order); model.put(MARK_SORT_LIST, SolrFieldManager.getSortList()); model.put(MARK_FACET_TREE, facetedResult.getFacetIntersection()); model.put(MARK_ENCODING, SolrUtil.getEncoding()); String strRequestUrl = request.getRequestURL().toString(); model.put(FULL_URL, strRequestUrl); model.put(SOLR_FACET_DATE_GAP, SolrSearchEngine.SOLR_FACET_DATE_GAP); return model; }
From source file:arena.utils.ServletUtils.java
public static String replaceWildcards(String pattern, boolean allowRequestArgs, Map<String, Object> model, HttpServletRequest request) { int firstWildcard = pattern.indexOf("###"); if (firstWildcard == -1) { return pattern; }/*w w w. ja v a 2s . co m*/ int endOfFirstWildcard = pattern.indexOf("###", firstWildcard + 3); if (endOfFirstWildcard == -1) { return pattern; } String key = pattern.substring(firstWildcard + 3, endOfFirstWildcard); boolean escapeToken = key.startsWith("!"); if (escapeToken) { key = key.substring(1); } Object out = model.get(key); if ((out == null) && allowRequestArgs) { out = request.getParameter(key); } if (out == null) { out = ""; } return pattern.substring(0, firstWildcard) + (escapeToken ? URLUtils.encodeURLToken(out.toString(), request.getCharacterEncoding()) : out) + replaceWildcards(pattern.substring(endOfFirstWildcard + 3), allowRequestArgs, model, request); }
From source file:com.concursive.connect.web.portal.ProjectPortalURLParserImpl.java
public static void addAllParameters(HttpServletRequest request, PortalURL portalURL) { Enumeration params = request.getParameterNames(); while (params.hasMoreElements()) { String parameter = (String) params.nextElement(); String value = request.getParameter(parameter); if (StringUtils.hasText(value)) { if (!parameter.startsWith(PREFIX + RENDER_PARAM) && !parameter.equals("portletWindowState1") && !parameter.startsWith("portlet-") && !(parameter.equals("command") && "ProjectCenter".equals(value))) { if (StringUtils.hasText(value)) { LOG.debug("Made a parameter available to the portlet: " + parameter); portalURL.addParameter(new PortalURLParameter(portalURL.getRenderPath(), parameter, value)); }/* w w w .j av a 2 s . co m*/ } else { if ("portlet-command".equals(parameter)) { LOG.debug("Made a parameter available to the portlet: " + parameter); portalURL.addParameter(new PortalURLParameter(portalURL.getRenderPath(), parameter, value)); } } } } }
From source file:com.lm.lic.manager.util.GenUtil.java
/** * @param request/*from ww w. j a va 2 s . c o m*/ */ @SuppressWarnings("unchecked") public static void debugRequestParams(HttpServletRequest request) { Enumeration<String> en = request.getParameterNames(); while (en.hasMoreElements()) { String p = en.nextElement(); String v = request.getParameter(p); System.out.println("\nPARAM: " + p); System.out.println("VALUE: " + v); } en = request.getHeaderNames(); while (en.hasMoreElements()) { String p = en.nextElement(); String v = request.getParameter(p); System.out.println("\nPHEADER: " + p); System.out.println("VALUE: " + v); } String qs = request.getQueryString(); System.out.println("QueryString: " + qs); String method = request.getMethod(); System.out.println("Method: " + method); }
From source file:org.tapestry.surveys.DoSurveyAction.java
/** * @return the next url to go to, excluding contextPath *//*from ww w . jav a2s . c o m*/ public static ModelAndView execute(HttpServletRequest request, String documentId, TapestryPHRSurvey currentSurvey, PHRSurvey templateSurvey) throws Exception { ModelAndView m = new ModelAndView(); final String questionId = request.getParameter("questionid"); String direction = request.getParameter("direction"); String observerNotes = request.getParameter("observernote"); if (direction == null) direction = "forward"; if (documentId == null) { logger.error("no selected survey? documentId=" + documentId); m.setViewName("failed"); return m; } String[] answerStrs = request.getParameterValues("answer"); String nextQuestionId = questionId; //if requested survey does not exist if (currentSurvey == null) { logger.error("Cannot find requested survey. documentId=" + documentId); m.setViewName("failed"); return m; } //if requested survey is completed if (currentSurvey.isComplete()) logger.error("trying to complete already completed survey?"); boolean saved = false; //if starting/continuing survey, clear session if (questionId == null) { //if just starting/continuing(from before) the survey, direct to last question String lastQuestionId; if (currentSurvey.getQuestions().size() == 0) { boolean moreQuestions = addNextQuestion(null, currentSurvey, templateSurvey); if (!moreQuestions) { logger.error("Survey has no questions?"); m.setViewName("failed"); return m; } } if (currentSurvey.isComplete()) { //if complete show first question lastQuestionId = currentSurvey.getQuestions().get(0).getId(); m.addObject("hideObservernote", true); } else { //if not complete show next question lastQuestionId = currentSurvey.getQuestions().get(currentSurvey.getQuestions().size() - 1).getId(); //logic for displaying Observer Notes button if (isFirstQuestionId(lastQuestionId, '0')) m.addObject("hideObservernote", true); else m.addObject("hideObservernote", false); } m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", lastQuestionId); m.addObject("resultid", documentId); m.setViewName("/surveys/show_survey"); return m; } //end of questionId == null; String errMsg = null; //if continuing survey (just submitted an answer) if (questionId != null && direction.equalsIgnoreCase("forward")) { if (currentSurvey.getQuestionById(questionId).getQuestionType().equals(SurveyQuestion.ANSWER_CHECK) && answerStrs == null) answerStrs = new String[0]; if (answerStrs != null && (currentSurvey.getQuestionById(questionId).getQuestionType() .equals(SurveyQuestion.ANSWER_CHECK) || !answerStrs[0].equals(""))) { SurveyQuestion question = currentSurvey.getQuestionById(questionId); String questionText = question.getQuestionText(); //append observernote to question text if (!Utils.isNullOrEmpty(questionText)) { String separator = "/observernote/ "; StringBuffer sb = new StringBuffer(); sb.append(questionText); sb.append(separator); sb.append(observerNotes); questionText = sb.toString(); question.setQuestionText(questionText); } ArrayList<SurveyAnswer> answers = convertToSurveyAnswers(answerStrs, question); boolean goodAnswerFormat = true; if (answers == null) goodAnswerFormat = false; //check each answer for validation if (goodAnswerFormat && question.validateAnswers(answers)) { boolean moreQuestions; //see if the user went back (if current question the last question in user's question profile) if (!currentSurvey.getQuestions().get(currentSurvey.getQuestions().size() - 1) .equals(question)) { ArrayList<SurveyAnswer> existingAnswers = currentSurvey.getQuestionById(questionId) .getAnswers(); //if user hit back, and then forward, and answer wasn't changed if (StringUtils.join(answerStrs, ", ").equals(StringUtils.join(existingAnswers, ", ")) || currentSurvey.isComplete()) { logger.debug("user hit back and went forward, no answer was changed"); moreQuestions = true; //if the user hit "back" and changed the answer - remove all questions after it } else { ArrayList<SurveyQuestion> tempquestions = new ArrayList<SurveyQuestion>(); //Create a temp array list to transfer answered questions //remove all future answers logger.debug("user hit back and changed an answer"); //clear all questions following it int currentSurveySize = currentSurvey.getQuestions().size(); //stores number of questions int currentQuestionIndex = currentSurvey.getQuestions().indexOf(question); //gets the current question index for (int i = currentQuestionIndex + 1; i < currentSurveySize; i++) { tempquestions.add(currentSurvey.getQuestions().get(currentQuestionIndex + 1)); currentSurvey.getQuestions().remove(currentQuestionIndex + 1); //goes through quesitons list and removes each question after it } //save answers modified/input by user into question question.setAnswers(answers); saved = true; //add new question moreQuestions = addNextQuestion(questionId, currentSurvey, templateSurvey); //check if old index and new index contain same questions in the same list int sizeofcurrentquestionslist = currentSurvey.getQuestions().size(); //Size of new getQuestions aftre removing future questions if (currentSurvey.getQuestions().get(sizeofcurrentquestionslist - 1).getId() .equals(tempquestions.get(0).getId())) { currentSurvey.getQuestions().remove(sizeofcurrentquestionslist - 1); for (int y = 0; y < tempquestions.size(); y++) currentSurvey.getQuestions().add(tempquestions.get(y)); moreQuestions = addNextQuestion(questionId, currentSurvey, templateSurvey); } //if same then replace temp list with new list //if not then add the one new item. } //if user didn't go back, and requesting the next question } else { logger.debug("user hit forward, and requested the next question"); question.setAnswers(answers); saved = true; moreQuestions = addNextQuestion(questionId, currentSurvey, templateSurvey); } //finished survey if (!moreQuestions) { if (!currentSurvey.isComplete()) { SurveyAction.updateSurveyResult(currentSurvey); m.addObject("survey_completed", true); m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", questionId); m.addObject("resultid", documentId); m.addObject("message", "SURVEY FINISHED - Please click SUBMIT"); m.addObject("hideObservernote", false); m.setViewName("/surveys/show_survey"); return m; } else { m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", questionId); m.addObject("resultid", documentId); m.addObject("message", "End of Survey"); m.addObject("hideObservernote", false); m.setViewName("/surveys/show_survey"); return m; } } int questionIndex = currentSurvey.getQuestionIndexbyId(questionId); nextQuestionId = currentSurvey.getQuestions().get(questionIndex + 1).getId(); logger.debug("Next question id: " + nextQuestionId); //save to indivo if (saved && questionIndex % SAVE_INTERVAL == 0 && !currentSurvey.isComplete()) SurveyAction.updateSurveyResult(currentSurvey); //if answer fails validation } // end of validation answers else { m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", questionId); m.addObject("resultid", documentId); if (question.getRestriction() != null && question.getRestriction().getInstruction() != null) m.addObject("message", question.getRestriction().getInstruction()); m.addObject("hideObservernote", false); m.setViewName("/surveys/show_survey"); return m; } //if answer not specified, and hit forward } else errMsg = "You must supply an answer"; } //end of forward action else if (direction.equalsIgnoreCase("backward")) { int questionIndex = currentSurvey.getQuestionIndexbyId(questionId); if (questionIndex > 0) nextQuestionId = currentSurvey.getQuestions().get(questionIndex - 1).getId(); } //backward to the description page(before the first qustion) if ((questionId != null) && ("backward".equals(direction)) && (isFirstQuestionId(questionId, '0'))) m.addObject("hideObservernote", true); else m.addObject("hideObservernote", false); m.addObject("survey", currentSurvey); m.addObject("templateSurvey", templateSurvey); m.addObject("questionid", nextQuestionId); m.addObject("resultid", documentId); if (errMsg != null) m.addObject("message", errMsg); m.setViewName("/surveys/show_survey"); return m; }
From source file:org.eclipse.userstorage.tests.util.USSServer.java
private static int getIntParameter(HttpServletRequest request, String name, int defaultValue) { String parameter = request.getParameter(name); if (parameter != null) { try {/* ww w .j a va2s .c om*/ return Integer.parseInt(parameter); } catch (NumberFormatException ex) { //$FALL-THROUGH$ } } return defaultValue; }
From source file:CertStreamCallback.java
public static void toJustepBiz(HttpServletRequest request, HttpServletResponse response, String url) throws FileUploadException, IOException { Callback callback = new CertStreamCallback(request, response); String accept = NetUtils.getAccept(request); String contentType = NetUtils.getContentType(request); String language = NetUtils.getLanguage(request); String sessionID = null;/*w ww.ja va2 s .co m*/ StringBuffer params = new StringBuffer(); for (Object n : request.getParameterMap().keySet()) { String p = URLEncoder.encode(request.getParameter((String) n), "UTF-8"); if (0 != params.length()) { params.append("&" + n + "=" + p); } else { params.append(n + "=" + p); } } if (NetUtils.isRequestMultipart(request)) { Part[] parts = NetUtils.generateParts(request); invokeActions(url, params.toString(), null, parts, accept, contentType, sessionID, language, "post", callback); } else { String postData = JavaServer.getPostData(request); invokeActions(url, params.toString(), postData.getBytes("UTF-8"), null, accept, contentType, sessionID, language, "post", callback); } }
From source file:com.gtwm.pb.servlets.ServletDataMethods.java
public static void globalEdit(SessionDataInfo sessionData, HttpServletRequest request, DatabaseInfo databaseDefn, List<FileItem> multipartItems) throws DisallowedException, ObjectNotFoundException, CodingErrorException, SQLException, CantDoThatException, InputRecordException, FileUploadException, MissingParametersException { String internalTableName = request.getParameter("internaltablename"); TableInfo table;/*from w w w . ja v a 2s.com*/ if (internalTableName == null) { table = sessionData.getTable(); } else { table = databaseDefn.getTable(request, internalTableName); } if (table == null) { throw new ObjectNotFoundException( "'internaltablename' was not provided and there is no table in the session"); } if (!(databaseDefn.getAuthManager().getAuthenticator().loggedInUserAllowedTo(request, PrivilegeType.MANAGE_TABLE, table))) { throw new DisallowedException(databaseDefn.getAuthManager().getLoggedInUser(request), PrivilegeType.MANAGE_TABLE, table); } // clear the cached record data: sessionData.setFieldInputValues(new HashMap<BaseField, BaseValue>()); // false means we're editing existing records, not adding a new one // so only values for specified fields will be set, not all table fields ServletSessionMethods.setFieldInputValues(sessionData, request, false, databaseDefn, table, multipartItems); int affectedRecords = databaseDefn.getDataManagement().globalEdit(request, table, new LinkedHashMap<BaseField, BaseValue>(sessionData.getFieldInputValues()), sessionData, multipartItems); logDataChanges(request, databaseDefn, "globally edited " + affectedRecords + " records in " + table.getTableName() + " (" + table.getInternalTableName() + ")"); // clear the cached record data: sessionData.setFieldInputValues(new HashMap<BaseField, BaseValue>()); }
From source file:com.lily.dap.web.util.Struts2Utils.java
/** * Gets a parameter as a boolean.//from w ww. ja v a 2 s. c o m * * @param request * The HttpServletRequest object, known as "request" in a JSP * page. * @param name * The name of the parameter you want to get * @return True if the value of the parameter was "true", false otherwise. */ public static boolean getBooleanParameter(String name, boolean defaultVal) { HttpServletRequest request = getRequest(); String temp = request.getParameter(name); if ("true".equals(temp) || "on".equals(temp)) { return true; } else if ("false".equals(temp) || "off".equals(temp)) { return false; } else { return defaultVal; } }
From source file:com.lily.dap.web.util.Struts2Utils.java
public static String getParameter_Ext(String name, boolean NULLStringOK) { HttpServletRequest request = getRequest(); String temp = request.getParameter(name); if (temp == null) { if (!NULLStringOK) { return ""; } else {//from www. j a va 2 s . c om return null; } } else { return temp; } }