Example usage for javax.servlet.http HttpServletRequest setAttribute

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

Introduction

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

Prototype

public void setAttribute(String name, Object o);

Source Link

Document

Stores an attribute in this request.

Usage

From source file:org.hdiv.util.HDIVUtil.java

/**
 * Set the BaseURL/* ww w.  jav a 2  s.c  om*/
 * 
 * @param baseURL
 *            BaseURL to set
 * @param request
 *            {@link HttpServletRequest} object
 */
public static void setBaseURL(String baseURL, HttpServletRequest request) {

    request.setAttribute(BASEURL_REQUEST_KEY, baseURL);

}

From source file:com.stratelia.silverpeas.pdcPeas.servlets.PdcSearchRequestRouterHelper.java

public static void processSearchDomains(PdcSearchSessionController pdcSC, HttpServletRequest request,
        String currentDomain) {//from w  w  w. ja v  a2s .co  m
    // Set search domains
    request.setAttribute("searchDomains", pdcSC.getSearchDomains());
    request.setAttribute("currentSearchDomainId", currentDomain);
}

From source file:com.runwaysdk.controller.ErrorUtility.java

public static void prepareInformation(List<InformationDTO> list, HttpServletRequest req) {
    List<String> messages = new LinkedList<String>();

    for (InformationDTO problem : list) {
        messages.add(problem.getMessage());
    }//from w w  w.j a  v a2  s.  co  m

    if (messages.size() > 0) {
        req.setAttribute(ErrorUtility.MESSAGE_ARRAY, messages.toArray(new String[messages.size()]));
    }
}

From source file:com.redhat.rhn.common.util.RecurringEventPicker.java

/**
 * Prepopulate the request with the picker
 * @param request the http request//from  w  w  w.ja  v a 2s. com
 * @param name the name of the picker
 * @param cronEntry if non-null, will set the picker to this.
 * @return The created picker
 */
public static RecurringEventPicker prepopulatePicker(HttpServletRequest request, String name,
        String cronEntry) {

    RecurringEventPicker p = new RecurringEventPicker(name);
    request.setAttribute(name, p);

    String tmpStatus = request.getParameter(name + "_status");
    if (tmpStatus != null) {
        p.setStatus(tmpStatus);
        if (tmpStatus.equals(STATUS_DAILY)) {
            DatePicker timePicker = p.getDailyTimePicker();
            timePicker.readMap(request.getParameterMap());
            String hour = String.valueOf(timePicker.getHourOfDay());
            String minute = String.valueOf(timePicker.getMinute());
            p.setCronEntry(buildCron(minute, hour, null, null, STATUS_DAILY));

        } else if (tmpStatus.equals(STATUS_WEEKLY)) {
            DatePicker timePicker = p.getWeeklyTimePicker();
            timePicker.readMap(request.getParameterMap());
            String hour = String.valueOf(timePicker.getHourOfDay());
            String minute = String.valueOf(timePicker.getMinute());
            String day = request.getParameter(name + WEEKLY_DAY_OF_WEEK);
            p.setCronEntry(buildCron(minute, hour, null, day, STATUS_WEEKLY));
        } else if (tmpStatus.equals(STATUS_MONTHLY)) {
            DatePicker timePicker = p.getMonthlyTimePicker();
            timePicker.readMap(request.getParameterMap());
            String hour = String.valueOf(timePicker.getHourOfDay());
            String minute = String.valueOf(timePicker.getMinute());
            String day = request.getParameter(name + MONTHLY_DAY_OF_MONTH);
            p.setCronEntry(buildCron(minute, hour, day, null, STATUS_MONTHLY));
        } else if (tmpStatus.equals(STATUS_CRON)) {
            p.setCronEntry(request.getParameter(name + CRON_ENTRY));
        } else if (tmpStatus.equals(STATUS_DISABLED)) {
            p.setStatus(STATUS_DISABLED);
        }
    } else if (cronEntry != null) {
        if (cronEntry.split(WHITE_SPACE).length < 6) {
            //The Cron Entry is too short
            return null;
        }

        // here do it the other way around, set the time pickers from
        // the cron time
        if (matches(cronEntry, DAILY_REGEX)) {
            p.setStatus(STATUS_DAILY);
            p.setCronEntry(cronEntry);
            DatePicker timePicker = p.getDailyTimePicker();
            timePicker.setHourOfDay(p.getHourLong().intValue());
            timePicker.setMinute(p.getMinuteLong().intValue());
        } else if (matches(cronEntry, WEEKLY_REGEX)) {
            p.setStatus(STATUS_WEEKLY);
            p.setCronEntry(cronEntry);
            DatePicker timePicker = p.getWeeklyTimePicker();
            timePicker.setHourOfDay(p.getHourLong().intValue());
            timePicker.setMinute(p.getMinuteLong().intValue());
        } else if (matches(cronEntry, MONTHLY_REGEX)) {
            p.setStatus(STATUS_MONTHLY);
            p.setCronEntry(cronEntry);
            DatePicker timePicker = p.getMonthlyTimePicker();
            timePicker.setHourOfDay(p.getHourLong().intValue());
            timePicker.setMinute(p.getMinuteLong().intValue());
        } else {
            p.setStatus(STATUS_CRON);
            p.setCronEntry(cronEntry);
        }
    }

    return p;
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.MultipartRequestWrapper.java

/**
 * Parse the raw request into a list of parts.
 * //  w w  w. j  ava 2  s  . c  om
 * If there is a parsing error, let the strategy handle it. If the strategy
 * throws it back, wrap it in an IOException and throw it on up.
 */
@SuppressWarnings("unchecked")
private static List<FileItem> parseRequestIntoFileItems(HttpServletRequest req, ServletFileUpload upload,
        ParsingStrategy strategy) throws IOException {
    try {
        return upload.parseRequest(req);
    } catch (FileSizeLimitExceededException | SizeLimitExceededException e) {
        if (strategy.stashFileSizeException()) {
            req.setAttribute(ATTRIBUTE_FILE_SIZE_EXCEPTION, e);
            return Collections.emptyList();
        } else {
            throw new IOException(e);
        }
    } catch (FileUploadException e) {
        throw new IOException(e);
    }
}

From source file:net.intelliant.util.UtilCommon.java

private static void addMessage(HttpServletRequest request, String messageType, String resource, String label) {
    String message = UtilProperties.getMessage(resource, label, UtilHttp.getLocale(request));
    request.setAttribute(messageType, message);
}

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;/*from  ww  w  . j  a  v 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:filter.MultipartRequestFilter.java

private static void addAttributeValue(HttpServletRequest request, String name, final Object value) {
    System.out.println("Add attribute value: name=" + name + ", value = " + value);
    if (value == null) {
        return;/*  w w w  .  j ava2 s .  c o m*/
    }
    final Object attrValue = request.getAttribute(name);
    System.out.println("oldValue = " + attrValue);
    if (attrValue == null) {
        request.setAttribute(name, value);
    } else if (attrValue instanceof List) {
        ((List) attrValue).add(value);
    } else {
        request.setAttribute(name, new ArrayList() {
            {
                add(attrValue);
                add(value);
            }
        });
    }

}

From source file:com.mmd.mssp.util.WebUtil.java

public static String getHttpQueryParam(HttpServletRequest request, String key, String charset)
        throws UnsupportedEncodingException {
    String queryString = request.getQueryString();
    if (!StringUtils.isAsciiPrintable(queryString)) {// ? ASCII ??
        byte[] bytes = queryString.getBytes("iso-8859-1");
        queryString = new String(bytes, charset);
    }// w  w w  .j  av  a 2  s .  c  o  m
    String val = StringUtil.searchKeyValue(queryString, key);
    if (val != null) {
        val = URLDecoder.decode(val, charset);
    }
    request.setAttribute("QueryDecodeCharset", val);
    return val;
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.java

public static ModelAccess on(HttpServletRequest req) {
    Object o = req.getAttribute(ATTRIBUTE_NAME);
    if (o instanceof ModelAccess) {
        return (ModelAccess) o;
    } else {//from   w  w  w  .  ja v a 2 s .  com
        ModelAccess parent = on(req.getSession());
        ModelAccess ma = new ModelAccess(Scope.REQUEST, parent);
        req.setAttribute(ATTRIBUTE_NAME, ma);
        return ma;
    }
}