List of usage examples for javax.servlet.http HttpServletRequest getParameterValues
public String[] getParameterValues(String name);
String
objects containing all of the values the given request parameter has, 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)/*from w w w . j a va 2 s.co 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:jeeves.server.sources.ServiceRequestFactory.java
@SuppressWarnings("unchecked") private static Element extractParameters(HttpServletRequest req, String uploadDir, int maxUploadSize) throws Exception { //--- set parameters from multipart request if (ServletFileUpload.isMultipartContent(req)) return getMultipartParams(req, uploadDir, maxUploadSize); Element params = new Element(Jeeves.Elem.REQUEST); //--- add parameters from POST request for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();) { String name = e.nextElement(); String values[] = req.getParameterValues(name); //--- we don't overwrite params given in the url if (!name.equals("")) if (params.getChild(name) == null) for (int i = 0; i < values.length; i++) params.addContent(new Element(name).setText(values[i])); }//from www . ja va2 s. c o m return params; }
From source file:com.ziduye.base.web.Servlets.java
/** * ???Request Parameters, copy from spring WebUtils. * /*from ww w . j a v a 2 s . c o m*/ * Parameter???. */ public static Map<String, Object> getParametersStartingWith(HttpServletRequest request, String prefix) { Validate.notNull(request, "Request must not be null"); Enumeration paramNames = request.getParameterNames(); Map<String, Object> params = new TreeMap<String, Object>(); if (prefix == null) { prefix = ""; } while ((paramNames != null) && paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); if ("".equals(prefix) || paramName.startsWith(prefix)) { String unprefixed = paramName.substring(prefix.length()); String[] values = request.getParameterValues(paramName); if ((values == null) || (values.length == 0)) { // Do nothing, no values found at all. } else if (values.length > 1) { params.put(unprefixed, values); } else { params.put(unprefixed, values[0]); } } } return params; }
From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java
/** * Look for parameters provided by the client. * * @param req HttpServletRequest/*from w w w . j a v a 2s.c om*/ * @return Map<String,Object> */ public static Map<String, Object> extractParameters(HttpServletRequest req) { Map<String, Object> parameters = new HashMap<String, Object>(); Enumeration penum = req.getParameterNames(); while (penum.hasMoreElements()) { String pname = (String) penum.nextElement(); if (pname.startsWith("P_")) { parameters.put(pname.substring(2), req.getParameter(pname)); } else if (pname.startsWith("PL_")) { parameters.put(pname.substring(3), Arrays.asList(req.getParameterValues(pname))); } } return parameters; }
From source file:com.jolira.testing.CachingRESTProxy.java
private static Map<String, String[]> getSortedParameters(final HttpServletRequest request) { final Map<String, String[]> params = new TreeMap<String, String[]>(); @SuppressWarnings("unchecked") final Enumeration<String> names = request.getParameterNames(); if (names == null) { return params; }/*from w w w .ja v a2 s . c om*/ while (names.hasMoreElements()) { final String name = names.nextElement(); final String[] vals = request.getParameterValues(name); params.put(name, vals); } return params; }
From source file:com.easyjf.web.core.FrameworkEngine.java
/** * reuqest?map?//from ww w . j av a 2 s . com * * @param request * @return Map */ public static Map request2map(HttpServletRequest request) { Map map = new HashMap(); java.util.Enumeration s = request.getParameterNames(); // System.out.println("?"+request.getParameterMap().size()); while (s.hasMoreElements()) { String name = (String) s.nextElement(); // eliminateScript((String)request.getParameter(name)));//? String[] vs = request.getParameterValues(name); if (vs == null || vs.length < 1) map.put(name, null); else map.put(name, vs.length > 1 ? vs : vs[0]); } return map; }
From source file:com.netspective.sparx.util.HttpUtils.java
public static void assignParamToInstance(HttpServletRequest req, XmlDataModelSchema schema, Object instance, String paramName, String defaultValue) throws IllegalAccessException, InvocationTargetException, DataModelException { boolean required = false; if (paramName.endsWith("!")) { required = true;/*from www. j ava 2s.c o m*/ paramName = paramName.substring(0, paramName.length() - 1); } Method method = (Method) schema.getAttributeSetterMethods().get(paramName); if (method != null) { Class[] args = method.getParameterTypes(); if (args.length == 1) { Class arg = args[0]; if (java.lang.String.class.equals(arg) && arg.isArray()) { String[] paramValues = req.getParameterValues(paramName); if ((paramValues == null || paramValues.length == 0) && required) throw new ServletParameterRequiredException( "Servlet parameter list '" + paramName + "' is required but not available."); method.invoke(instance, new Object[] { paramValues }); } else { XmlDataModelSchema.AttributeSetter as = (XmlDataModelSchema.AttributeSetter) schema .getAttributeSetters().get(paramName); String paramValue = req.getParameter(paramName); if (paramValue == null) { if (required) throw new ServletParameterRequiredException( "Servlet parameter '" + paramName + "' is required but not available."); paramValue = defaultValue; } as.set(null, instance, paramValue); } } else if (log.isDebugEnabled()) log.debug("Attempting to assign '" + paramName + "' to a method in '" + instance.getClass() + "' but the method has more than one argument."); } else if (log.isDebugEnabled()) log.debug("Attempting to assign '" + paramName + "' to a method in '" + instance.getClass() + "' but there is no mutator available."); }
From source file:eionet.gdem.conversion.ssr.SaveHandler.java
static void handleWorkqueue(HttpServletRequest req, String action) { AppUser user = SecurityUtil.getUser(req, Names.USER_ATT); String user_name = null;/* w ww. j av a2 s . co m*/ if (user != null) { user_name = user.getUserName(); } if (action.equals(Names.WQ_DEL_ACTION)) { try { if (!SecurityUtil.hasPerm(user_name, "/" + Names.ACL_WQ_PATH, "d")) { req.setAttribute(Names.ERROR_ATT, "You don't have permissions to delete jobs!"); return; } } catch (Exception e) { req.setAttribute(Names.ERROR_ATT, "Cannot read permissions: " + e.toString()); return; } StringBuffer err_buf = new StringBuffer(); // String del_id = (String)req.getParameter("ID"); String[] jobs = req.getParameterValues("jobID"); try { if (jobs.length > 0) { // delete also result files from file system tmp folder try { for (int i = 0; i < jobs.length; i++) { String jobData[] = GDEMServices.getDaoService().getXQJobDao().getXQJobData(jobs[i]); if (jobData == null || jobData.length < 3) { continue; } String resultFile = jobData[2]; try { Utils.deleteFile(resultFile); } catch (Exception e) { LOGGER.error( "Could not delete job result file: " + resultFile + "." + e.getMessage()); } // delete xquery files, if they are stored in tmp folder String xqFile = jobData[1]; try { // Important!!!: delete only, when the file is stored in tmp folder if (xqFile.startsWith(Properties.tmpFolder)) { Utils.deleteFile(xqFile); } } catch (Exception e) { LOGGER.error( "Could not delete XQuery script file: " + xqFile + "." + e.getMessage()); } } } catch (Exception e) { LOGGER.error("Could not delete job result files!" + e.getMessage()); } GDEMServices.getDaoService().getXQJobDao().endXQJobs(jobs); } } catch (Exception e) { err_buf.append("Cannot delete job: " + e.toString() + jobs); } if (err_buf.length() > 0) { req.setAttribute(Names.ERROR_ATT, err_buf.toString()); } } else if (action.equals(Names.WQ_RESTART_ACTION)) { try { if (!SecurityUtil.hasPerm(user_name, "/" + Names.ACL_WQ_PATH, "u")) { req.setAttribute(Names.ERROR_ATT, "You don't have permissions to restart the jobs!"); return; } } catch (Exception e) { req.setAttribute(Names.ERROR_ATT, "Cannot read permissions: " + e.toString()); return; } StringBuffer err_buf = new StringBuffer(); String[] jobs = req.getParameterValues("jobID"); try { if (jobs.length > 0) { GDEMServices.getDaoService().getXQJobDao().changeXQJobsStatuses(jobs, Constants.XQ_RECEIVED); } } catch (Exception e) { err_buf.append("Cannot restart jobs: " + e.toString() + jobs); } if (err_buf.length() > 0) { req.setAttribute(Names.ERROR_ATT, err_buf.toString()); } } }
From source file:com.mapviewer.business.UserRequestManager.java
/** * Updates the selection of vector layers * * @param request/*from w w w.jav a2s . co m*/ * @param session * @return */ public static String[] manageVectorLayersOptions(HttpServletRequest request, HttpSession session) throws XMLFilesException, Exception { String solicitudWCS = request.getParameter("isWCS");//indicates if the request is wcs or not. String[] layersSelected = null; if (Boolean.valueOf(solicitudWCS)) { //if it is a wcs then we look for the parameter of the dropdown menu //this is done becuase we can not send the data directly to get. //in the case of having three levels we need to modify the ajax.js. layersSelected = StringAndNumbers.strArrayFromStringColon(request.getParameter("valoresOpcionales")); } else { //if the request is not wcs we need to obtain the user selection. layersSelected = request.getParameterValues("vectorLayersSelected"); } LayerMenuManagerSingleton menuManager = LayerMenuManagerSingleton.getInstance(); TreeNode vectorLayerOptions = menuManager.getRootVectorMenu(); String[] selectedValues = null; selectedValues = ConvertionTools.convertObjectArrayToStringArray(layersSelected); //in case nothing is selected or doesnt exist then the object vactorLayers in session just returns //the initial menu. if (selectedValues == null) { selectedValues = menuManager.getDefVectorLayers(); } vectorLayerOptions = HtmlTools.actualizaOpcionesVectoriales(selectedValues, vectorLayerOptions); session.setAttribute("vectorLayers", vectorLayerOptions); return selectedValues; }
From source file:com.mapviewer.business.UserRequestManager.java
/** * Generates a new menu depending on the request. * * * @param {HttpServletRequest} request/*from w w w . ja v a2 s .c o m*/ * @param {HttpSession} session * @return Treenode */ public static TreeNode createNewRootMenu(HttpServletRequest request, HttpSession session) throws XMLFilesException { String solicitudWCS = request.getParameter("isWCS");//Indicates if the request is WCS or normal WMS String[] levelsSelected = null; if (Boolean.valueOf(solicitudWCS)) { //if it is wcs then we look for the parameter valoresDropDown //This is done becuase data can't be send directly throught get //in case we had three levels then ajax.js needs to be modified. levelsSelected = StringAndNumbers.strArrayFromStringColon(request.getParameter("valoresDropDown")); } else { //if the request is not wcs then we obtain the layers that the user selected. levelsSelected = request.getParameterValues("dropDownLevels"); } //Obtain the menu of the user that is in session. TreeNode rootMenu = (TreeNode) session.getAttribute("MenuDelUsuario"); String[] selectedValues = ConvertionTools.convertObjectArrayToStringArray(levelsSelected); LayerMenuManagerSingleton menuManager = LayerMenuManagerSingleton.getInstance(); boolean update = menuManager.refreshTree(false);//Search for any update on the XML files //If is the first time the user access the webpage then we // return the default menu. if (rootMenu == null || selectedValues == null || update) { rootMenu = menuManager.getRootMenu(); } //If something goes wrong updating the menu, we return the default menu try { if (selectedValues != null) { rootMenu = HtmlTools.actualizaMenu(selectedValues, rootMenu); } } catch (Exception e) { System.out.println("ERROR!!!!! Building the menu in UserRequestmananger" + e.getMessage()); rootMenu = menuManager.getRootMenu(); } session.setAttribute("MenuDelUsuario", rootMenu); return rootMenu; }