Example usage for javax.servlet.http HttpServletRequest getParameterValues

List of usage examples for javax.servlet.http HttpServletRequest getParameterValues

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameterValues.

Prototype

public String[] getParameterValues(String name);

Source Link

Document

Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

Usage

From source file:net.duckling.ddl.web.controller.pan.LynxPanController.java

@WebLog(method = "PandeleteResources", params = "rids[]")
@RequestMapping(params = "func=deleteResources")
public void deleteResources(HttpServletRequest request, HttpServletResponse response) {
    String[] ridStrs = request.getParameterValues("rids[]");
    List<String> rids = new ArrayList<String>();
    for (String r : ridStrs) {
        rids.add(decode(r));//from www .  j av  a  2  s .c  o m
    }
    List<String> errorList = new ArrayList<String>();
    List<String> successList = new ArrayList<>();
    PanAcl acl = PanAclUtil.getInstance(request);
    for (String r : rids) {
        try {
            boolean result = service.rm(acl, r);
            if (!result) {
                errorList.add(encode(r));
            } else {
                successList.add(encode(r));
            }
        } catch (MeePoException e) {
            LOG.error("", e);
            errorList.add(encode(r));
        }
    }
    JSONObject o = new JSONObject();
    o.put("result", errorList.isEmpty());
    if (!errorList.isEmpty()) {
        JSONArray array = new JSONArray();
        for (String s : errorList) {
            array.add(s);
        }
        o.put("errorRids", array);
        JSONArray suc = new JSONArray();
        for (String s : successList) {
            suc.add(s);
        }
        o.put("sucRids", suc);
    }
    LOG.info(acl.getUid() + " delete " + successList + " ;delete error" + errorList);
    JsonUtil.writeJSONObject(response, o);
}

From source file:com.adito.security.actions.ShowAvailableAccountsDispatchAction.java

/**
 * Confirm the reset of a users private key.
 * @param mapping/*from   ww w. ja  v a  2 s  .  co m*/
 * @param form
 * @param request
 * @param response
 * @return forward
 * @throws Exception
 */
public ActionForward confirmResetPrivateKey(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String[] accounts = request.getParameterValues("username");
    if (accounts != null && accounts.length == 1) {
        int resourceId = getSessionInfo(request).getUser().getRealm().getResourceId();
        User account = UserDatabaseManager.getInstance().getUserDatabase(resourceId).getAccount(accounts[0]);
        request.getSession().setAttribute(Constants.EDITING_ITEM, account);
        return mapping.findForward("confirmResetPrivateKey");
    }
    return list(mapping, form, request, response);
}

From source file:net.centro.rtb.monitoringcenter.MonitoringCenterServlet.java

private void handleMetrics(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
        throws IOException {
    String format = StringUtils.trimToNull(httpServletRequest.getParameter("format"));
    String[] startsWithFilters = httpServletRequest.getParameterValues("startsWithFilter");

    if (FORMAT_GRAPHITE.equalsIgnoreCase(format)) {
        httpServletResponse.setContentType(CONTENT_TYPE_TEXT_PLAIN);

        try (PrintWriter printWriter = httpServletResponse.getWriter()) {
            SortedMap<String, Metric> metricsByNames = MonitoringCenter.getMetricsByNames(true,
                    startsWithFilters);/*from  w w  w  .  j a va  2  s .  c om*/
            printWriter.write(graphiteMetricFormatter.format(metricsByNames));
        }
    } else {
        boolean appendPrefix = Boolean.TRUE.toString()
                .equalsIgnoreCase(StringUtils.trimToNull(httpServletRequest.getParameter("appendPrefix")));

        Map<String, SortedMap<String, ? extends Metric>> responseMap = new LinkedHashMap<>();
        responseMap.put("gauges", MonitoringCenter.getGaugesByNames(appendPrefix, startsWithFilters));
        responseMap.put("counters", MonitoringCenter.getCountersByNames(appendPrefix, startsWithFilters));
        responseMap.put("histograms", MonitoringCenter.getHistogramsByNames(appendPrefix, startsWithFilters));
        responseMap.put("meters", MonitoringCenter.getMetersByNames(appendPrefix, startsWithFilters));
        responseMap.put("timers", MonitoringCenter.getTimersByNames(appendPrefix, startsWithFilters));

        writeAsJson(httpServletRequest, httpServletResponse, responseMap);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

public static void setPermissions(Session session, HttpServletRequest request) throws ServiceException {
    try {/*from  ww w  .j a va2s.  c om*/
        String id = request.getParameter("roleid");
        String[] features = request.getParameterValues("features");
        String[] permissions = request.getParameterValues("permissions");
        String sql = "delete from UserPermission where role.ID=?";
        HibernateUtil.executeUpdate(session, sql, id);
        Role role = (Role) session.load(Role.class, id);
        for (int i = 0; i < features.length; i++) {
            if (permissions[i].equals("0")) {
                continue;
            }
            UserPermission permission = new UserPermission();
            permission.setRole(role);
            permission.setFeature((ProjectFeature) session.load(ProjectFeature.class, features[i]));
            permission.setPermissionCode(Long.parseLong(permissions[i]));
            session.save(permission);
        }
        // insertAuditLog(session, AuditAction.PERMISSIONS_MODIFIED, AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has changed the permissions of role " + role.getName(), request);
    } catch (Exception e) {
        throw ServiceException.FAILURE("ProfileHandler.setPermissions", e);
    }
}

From source file:de.iteratec.turm.servlets.TurmServlet.java

/**
 * Parameters that are contained in the current request are used to fill
 * a given Java Bean. This is similar to the way Struts fills its ActionForms.
 * /* w ww  .  j  a v  a  2  s  .  c o m*/
 * @param request The current Serlvet Request
 * @param bean A JavaBean that is to be populated.
 * @throws TurmException If the JavaBean could not be populated.
 */
@SuppressWarnings("unchecked")
protected final void populate(HttpServletRequest request, Object bean) throws TurmException {
    HashMap<String, String[]> map = new HashMap<String, String[]>();
    Enumeration<String> names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        map.put(name, request.getParameterValues(name));
    }
    try {
        BeanUtils.populate(bean, map);
    } catch (IllegalAccessException e) {
        throw new TurmException("error.internal", e);
    } catch (InvocationTargetException e) {
        throw new TurmException("error.internal", e);
    }
}

From source file:com.sun.faban.harness.webclient.Uploader.java

/**
 * Checks the existence of the runs on the repository.
 * @param request/*from w w w .j  a  v  a 2  s  .  c  o m*/
 * @param response
 * @return String
 * @throws java.io.IOException
 * @throws javax.servlet.ServletException
 */
public String checkRuns(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    HashSet<String> duplicateSet = new HashSet<String>();
    String host = request.getParameter("host");
    String[] runIds = request.getParameterValues("runId");
    String[] ts = request.getParameterValues("ts");
    for (int r = 0; r < runIds.length; r++) {
        String runId = runIds[r];
        if (checkIfArchived(host + "." + runId)) {
            //check for runId timestamp
            String reposTs = getRunIdTimestamp(host + "." + runId, Config.OUT_DIR);
            if (ts[r].equals(reposTs)) {
                duplicateSet.add(runId);
            }
        }
        response.setStatus(HttpServletResponse.SC_OK);
    }
    request.setAttribute("duplicates", duplicateSet);
    return "/duplicates.jsp";
}

From source file:fr.paris.lutece.plugins.directory.modules.pdfproducerarchive.web.ZipBasketJspBean.java

/**
 * Gets the confirmation to create zip//from w  ww.j a  va2 s  .  c  o  m
 * @param request request
 * @return message of confirmation
 * @throws AccessDeniedException AccessDeniedException
 */
public String getConfirmAddZipBasket(HttpServletRequest request) throws AccessDeniedException {
    String[] listIdsDirectoryRecord = request.getParameterValues(PARAMETER_ID_DIRECTORY_RECORD);

    if ((listIdsDirectoryRecord != null) && (listIdsDirectoryRecord.length > 0)) {
        String strIdDirectory = request.getParameter(PARAMETER_ID_DIRECTORY);

        // If the id directory is not in the parameter, then fetch it from the first record
        // assuming all records are from the same directory 
        if (StringUtils.isBlank(strIdDirectory) || !StringUtils.isNumeric(strIdDirectory)) {
            String strIdDirectoryRecord = listIdsDirectoryRecord[0];
            int nIdDirectoryRecord = DirectoryUtils.convertStringToInt(strIdDirectoryRecord);
            Record record = _manageZipBasketService.getRecord(nIdDirectoryRecord);

            if (record != null) {
                strIdDirectory = Integer.toString(record.getDirectory().getIdDirectory());
            }
        }

        if (!RBACService.isAuthorized(Directory.RESOURCE_TYPE, strIdDirectory,
                DirectoryPDFProducerArchiveResourceIdService.PERMISSION_GENERATE_ZIP, getUser())
                || StringUtils.isBlank(strIdDirectory) || !StringUtils.isNumeric(strIdDirectory)) {
            return AdminMessageService.getMessageUrl(request, Messages.USER_ACCESS_DENIED,
                    AdminMessage.TYPE_CONFIRMATION);
        }

        int nIdDirectory = DirectoryUtils.convertStringToInt(strIdDirectory);
        UrlItem url = new UrlItem(JSP_DO_ADD_ZIP_TO_BASKET);
        url.addParameter(PARAMETER_ID_DIRECTORY, nIdDirectory);

        for (String strIdDirectoryRecord : listIdsDirectoryRecord) {
            int nIdDirectoryRecord = DirectoryUtils.convertStringToInt(strIdDirectoryRecord);
            Record record = _manageZipBasketService.getRecord(nIdDirectoryRecord);

            if ((record == null) || (record.getDirectory().getIdDirectory() != nIdDirectory)) {
                return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS,
                        AdminMessage.TYPE_STOP);
            }

            url.addParameter(PARAMETER_ID_DIRECTORY_RECORD, nIdDirectoryRecord);
        }

        return AdminMessageService.getMessageUrl(request, MESSAGE_CONFIRM_ADD_ZIP_TO_BASKET, url.getUrl(),
                AdminMessage.TYPE_CONFIRMATION);
    }

    return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP);
}

From source file:fr.paris.lutece.portal.service.search.LuceneSearchEngine.java

/**
 * Return search results//from  w w w  . j a v  a2 s  . c  o m
 * 
 * @param strQuery The search query
 * @param request The HTTP request
 * @return Results as a collection of SearchResult
 */
public List<SearchResult> getSearchResults(String strQuery, HttpServletRequest request) {
    ArrayList<SearchItem> listResults = new ArrayList<SearchItem>();
    ArrayList<Filter> listFilter = new ArrayList<Filter>();
    Searcher searcher = null;
    boolean bFilterResult = false;
    LuteceUser user = null;
    String[] typeFilter = request.getParameterValues(PARAMETER_TYPE_FILTER);
    String strDateAfter = request.getParameter(PARAMETER_DATE_AFTER);
    String strDateBefore = request.getParameter(PARAMETER_DATE_BEFORE);
    boolean bDateAfter = false;
    boolean bDateBefore = false;
    Filter allFilter = null;
    String strTagFilter = request.getParameter(PARAMETER_TAG_FILTER);

    if (SecurityService.isAuthenticationEnable()) {
        user = SecurityService.getInstance().getRegisteredUser(request);

        Filter[] filtersRole = null;

        if (user != null) {
            String[] userRoles = SecurityService.getInstance().getRolesByUser(user);

            if (userRoles != null) {
                filtersRole = new Filter[userRoles.length + 1];

                for (int i = 0; i < userRoles.length; i++) {
                    Query queryRole = new TermQuery(new Term(SearchItem.FIELD_ROLE, userRoles[i]));
                    filtersRole[i] = new CachingWrapperFilter(new QueryWrapperFilter(queryRole));
                }
            } else {
                bFilterResult = true;
            }
        } else {
            filtersRole = new Filter[1];
        }

        if (!bFilterResult) {
            Query queryRole = new TermQuery(new Term(SearchItem.FIELD_ROLE, Page.ROLE_NONE));
            filtersRole[filtersRole.length - 1] = new CachingWrapperFilter(new QueryWrapperFilter(queryRole));
            listFilter.add(new ChainedFilter(filtersRole, ChainedFilter.OR));
        }
    }

    if (StringUtils.isNotBlank(strDateAfter) || StringUtils.isNotBlank(strDateBefore)) {
        String strAfter = null;
        String strBefore = null;

        if (StringUtils.isNotBlank(strDateAfter)) {
            Date dateAfter = DateUtil.formatDate(strDateAfter, request.getLocale());
            strAfter = DateTools.dateToString(dateAfter, Resolution.DAY);
            bDateAfter = true;
        }

        if (StringUtils.isNotBlank(strDateBefore)) {
            Date dateBefore = DateUtil.formatDate(strDateBefore, request.getLocale());
            strBefore = DateTools.dateToString(dateBefore, Resolution.DAY);
            bDateBefore = true;
        }

        Query queryDate = new TermRangeQuery(SearchItem.FIELD_DATE, strAfter, strBefore, bDateAfter,
                bDateBefore);
        listFilter.add(new CachingWrapperFilter(new QueryWrapperFilter(queryDate)));
    }

    if ((typeFilter != null) && (typeFilter.length > 0)
            && !typeFilter[0].equals(SearchService.TYPE_FILTER_NONE)) {
        Filter[] filtersType = new Filter[typeFilter.length];

        for (int i = 0; i < typeFilter.length; i++) {
            Query queryType = new TermQuery(new Term(SearchItem.FIELD_TYPE, typeFilter[i]));
            filtersType[i] = new CachingWrapperFilter(new QueryWrapperFilter(queryType));
        }

        listFilter.add(new ChainedFilter(filtersType, ChainedFilter.OR));
    }

    if (!listFilter.isEmpty()) {
        allFilter = new ChainedFilter(listFilter.toArray(new Filter[1]), ChainedFilter.AND);
    }

    try {
        searcher = new IndexSearcher(IndexationService.getDirectoryIndex(), true);

        Query query = null;

        if (StringUtils.isNotBlank(strTagFilter)) {
            BooleanQuery bQuery = new BooleanQuery();
            QueryParser parser = new QueryParser(IndexationService.LUCENE_INDEX_VERSION,
                    SearchItem.FIELD_METADATA, IndexationService.getAnalyser());

            Query queryMetaData = parser.parse((strQuery != null) ? strQuery : "");
            bQuery.add(queryMetaData, BooleanClause.Occur.SHOULD);

            parser = new QueryParser(IndexationService.LUCENE_INDEX_VERSION, SearchItem.FIELD_SUMMARY,
                    IndexationService.getAnalyser());

            Query querySummary = parser.parse((strQuery != null) ? strQuery : "");
            bQuery.add(querySummary, BooleanClause.Occur.SHOULD);
            query = bQuery;
        } else {
            QueryParser parser = new QueryParser(IndexationService.LUCENE_INDEX_VERSION,
                    SearchItem.FIELD_CONTENTS, IndexationService.getAnalyser());

            String operator = request.getParameter(PARAMETER_DEFAULT_OPERATOR);

            if (StringUtils.isNotEmpty(operator) && operator.equals(PARAMETER_OPERATOR_AND)) {
                parser.setDefaultOperator(QueryParser.AND_OPERATOR);
            }

            query = parser.parse((strQuery != null) ? strQuery : "");
        }

        // Get results documents
        TopDocs topDocs = searcher.search(query, allFilter, MAX_RESPONSES);
        ScoreDoc[] hits = topDocs.scoreDocs;

        for (int i = 0; i < hits.length; i++) {
            int docId = hits[i].doc;
            Document document = searcher.doc(docId);
            SearchItem si = new SearchItem(document);

            if ((!bFilterResult) || (si.getRole().equals(Page.ROLE_NONE))
                    || (SecurityService.getInstance().isUserInRole(request, si.getRole()))) {
                listResults.add(si);
            }
        }

        searcher.close();
    } catch (Exception e) {
        AppLogService.error(e.getMessage(), e);
    }

    return convertList(listResults);
}

From source file:fr.paris.lutece.plugins.workflow.modules.ticketing.service.task.TaskEditTicket.java

/**
 * Process the task for agent side//ww  w  .  j  av a2 s  .c  o m
 * @param nIdResourceHistory the ResourceHistory id
 * @param request the request
 * @param locale the locale
 * @param config the task configuration
 * @return the information message to store
 */
private String processAgentTask(int nIdResourceHistory, HttpServletRequest request, Locale locale,
        TaskEditTicketConfig config) {
    String strTaskInformation = StringUtils.EMPTY;

    String strAgentMessage = request.getParameter(PARAMETER_MESSAGE + UNDERSCORE + getId());
    String[] listIdsEntry = request.getParameterValues(PARAMETER_IDS_ENTRY + UNDERSCORE + getId());

    // We get the ticket to modify
    Ticket ticket = getTicket(nIdResourceHistory);

    boolean bCreate = false;
    List<EditableTicketField> listEditableTicketFields = new ArrayList<EditableTicketField>();

    EditableTicket editableTicket = _editableTicketService.find(nIdResourceHistory, getId());

    if (editableTicket == null) {
        editableTicket = new EditableTicket();
        editableTicket.setIdHistory(nIdResourceHistory);
        editableTicket.setIdTask(getId());
        editableTicket.setIdTicket(ticket.getId());
        bCreate = true;
    }

    StringBuilder sbEntries = new StringBuilder();

    if (listIdsEntry != null) {
        for (String strIdEntry : listIdsEntry) {
            if (StringUtils.isNotBlank(strIdEntry) && StringUtils.isNumeric(strIdEntry)) {
                int nIdEntry = Integer.parseInt(strIdEntry);
                EditableTicketField editableTicketField = new EditableTicketField();
                editableTicketField.setIdEntry(nIdEntry);

                listEditableTicketFields.add(editableTicketField);

                Entry entry = EntryHome.findByPrimaryKey(nIdEntry);
                sbEntries.append(entry.getTitle()).append(SEPARATOR);
            }
        }

        if (sbEntries.length() != 0) {
            sbEntries.delete(sbEntries.length() - SEPARATOR.length(), sbEntries.length());
        }
    }

    editableTicket.setMessage(StringUtils.isNotBlank(strAgentMessage) ? strAgentMessage : StringUtils.EMPTY);
    editableTicket.setListEditableTicketFields(listEditableTicketFields);
    editableTicket.setIsEdited(false);

    if (bCreate) {
        _editableTicketService.create(editableTicket);
    } else {
        _editableTicketService.update(editableTicket);
    }

    if (ticket != null) {
        ticket.setUrl(buildEditUrl(request, nIdResourceHistory, getId(), config.getIdUserEditionAction()));
        TicketHome.update(ticket);
    }

    if (sbEntries.length() == 0) {
        strTaskInformation = MessageFormat.format(I18nService.getLocalizedString(
                MESSAGE_EDIT_TICKET_INFORMATION_VIEW_AGENT_NO_FIELD_EDITED, Locale.FRENCH), strAgentMessage);
    } else {
        strTaskInformation = MessageFormat.format(
                I18nService.getLocalizedString(MESSAGE_EDIT_TICKET_INFORMATION_VIEW_AGENT, Locale.FRENCH),
                sbEntries.toString(), strAgentMessage);
    }

    return strTaskInformation;
}

From source file:org.esgf.legacydatacart.WgetGeneratorController.java

/**
 * queryStringInfo(HttpServletRequest request)
 * Private method printing out the contents of the request.  Used mainly for debugging.
 * //from w  w w .j a v  a  2  s  . c  o m
 * @param request
 */
private void queryStringInfo(HttpServletRequest request) {

    LOG.debug("Query parameters");
    LOG.debug("\tId");
    LOG.debug("\t\t" + request.getParameterValues("id")[0]);
    LOG.debug("\tType");
    LOG.debug("\t\t" + request.getParameterValues("type")[0]);
    LOG.debug("\tChild urls");
    if (request.getParameterValues("child_url") != null) {
        for (int i = 0; i < request.getParameterValues("child_url").length; i++) {
            LOG.debug("\t\t" + request.getParameterValues("child_url")[i]);
        }
    } else {
        LOG.debug("There are no child urls");
    }
    LOG.debug("\tChild ids");
    if (request.getParameterValues("child_id") != null) {
        for (int i = 0; i < request.getParameterValues("child_id").length; i++) {
            LOG.debug("\t\t" + request.getParameterValues("child_id")[i]);
        }
    } else {
        LOG.debug("There are no child ids");
    }

}