Example usage for org.springframework.web.bind ServletRequestUtils getBooleanParameter

List of usage examples for org.springframework.web.bind ServletRequestUtils getBooleanParameter

Introduction

In this page you can find the example usage for org.springframework.web.bind ServletRequestUtils getBooleanParameter.

Prototype

public static boolean getBooleanParameter(ServletRequest request, String name, boolean defaultVal) 

Source Link

Document

Get a boolean parameter, with a fallback value.

Usage

From source file:net.testdriven.psiprobe.jsp.ParamToggleTag.java

@Override
public int doStartTag() throws JspException {
    boolean getSize = ServletRequestUtils.getBooleanParameter(pageContext.getRequest(), param, false);
    StringBuffer query = new StringBuffer();
    query.append(param).append("=").append(!getSize);
    for (Enumeration en = pageContext.getRequest().getParameterNames(); en.hasMoreElements();) {
        String name = (String) en.nextElement();
        if (!param.equals(name)) {
            query.append("&").append(name).append("=")
                    .append(ServletRequestUtils.getStringParameter(pageContext.getRequest(), name, ""));
        }//from  w  w  w. ja  va  2 s .  c  om
    }
    try {
        pageContext.getOut().print(query);
    } catch (IOException e) {
        logger.debug("Exception printing query string to JspWriter", e);
        throw new JspException(e);
    }
    return EVAL_BODY_INCLUDE;
}

From source file:com.googlecode.psiprobe.jsp.ParamToggleTag.java

public int doStartTag() throws JspException {
    boolean getSize = ServletRequestUtils.getBooleanParameter(pageContext.getRequest(), param, false);
    StringBuffer query = new StringBuffer();
    query.append(param).append("=").append(!getSize);
    String encoding = pageContext.getResponse().getCharacterEncoding();
    for (Enumeration en = pageContext.getRequest().getParameterNames(); en.hasMoreElements();) {
        String name = (String) en.nextElement();
        if (!param.equals(name)) {
            try {
                String value = ServletRequestUtils.getStringParameter(pageContext.getRequest(), name, "");
                String encodedValue = URLEncoder.encode(value, encoding);
                query.append("&").append(name).append("=").append(encodedValue);
            } catch (UnsupportedEncodingException e) {
                throw new JspException(e);
            }// w  w  w .ja  va 2s.  c o  m
        }
    }
    try {
        pageContext.getOut().print(query);
    } catch (IOException e) {
        logger.debug("Exception printing query string to JspWriter", e);
        throw new JspException(e);
    }
    return EVAL_BODY_INCLUDE;
}

From source file:com.googlecode.psiprobe.controllers.jsp.DisplayJspController.java

protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    boolean compile = ServletRequestUtils.getBooleanParameter(request, "compile", false);

    HttpSession session = request.getSession(true);
    Summary summary = (Summary) session.getAttribute(SUMMARY_ATTRIBUTE);
    if (summary == null || !contextName.equals(summary.getName())) {
        summary = new Summary();
        summary.setName(contextName);/*from   w w w  . j  a va2s. c  om*/
    }
    getContainerWrapper().getTomcatContainer().listContextJsps(context, summary, compile);

    session.setAttribute(SUMMARY_ATTRIBUTE, summary);

    if (compile) {
        return new ModelAndView(new RedirectView(
                request.getRequestURI() + "?webapp=" + (contextName.length() == 0 ? "/" : contextName)));
    } else {
        return new ModelAndView(getViewName(), "summary", summary);
    }
}

From source file:psiprobe.jsp.ParamToggleTag.java

@Override
public int doStartTag() throws JspException {
    boolean getSize = ServletRequestUtils.getBooleanParameter(pageContext.getRequest(), param, false);
    StringBuilder query = new StringBuilder();
    query.append(param).append("=").append(!getSize);
    String encoding = pageContext.getResponse().getCharacterEncoding();
    for (String name : Collections.list(pageContext.getRequest().getParameterNames())) {
        if (!param.equals(name)) {
            try {
                String value = ServletRequestUtils.getStringParameter(pageContext.getRequest(), name, "");
                String encodedValue = URLEncoder.encode(value, encoding);
                query.append("&").append(name).append("=").append(encodedValue);
            } catch (UnsupportedEncodingException e) {
                throw new JspException(e);
            }//www  .j  ava2s . c  om
        }
    }
    try {
        pageContext.getOut().print(query);
    } catch (IOException e) {
        logger.debug("Exception printing query string to JspWriter", e);
        throw new JspException(e);
    }
    return EVAL_BODY_INCLUDE;
}

From source file:psiprobe.controllers.jsp.DisplayJspController.java

@Override
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    boolean compile = ServletRequestUtils.getBooleanParameter(request, "compile", false);

    HttpSession session = request.getSession(false);
    Summary summary = (Summary) session.getAttribute(SUMMARY_ATTRIBUTE);
    if (summary == null || !contextName.equals(summary.getName())) {
        summary = new Summary();
        summary.setName(contextName);// ww  w  . j a  va  2s  .  com
    }
    getContainerWrapper().getTomcatContainer().listContextJsps(context, summary, compile);

    session.setAttribute(SUMMARY_ATTRIBUTE, summary);

    if (compile) {
        return new ModelAndView(new RedirectView(
                request.getRequestURI() + "?webapp=" + (contextName.length() == 0 ? "/" : contextName)));
    }
    return new ModelAndView(getViewName(), "summary", summary);
}

From source file:psiprobe.controllers.sessions.ListSessionAttributesController.java

@Override
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    boolean privileged = SecurityUtils.hasAttributeValueRole(getServletContext(), request);
    boolean calcSize = ServletRequestUtils.getBooleanParameter(request, "size", false) && privileged;
    String sid = ServletRequestUtils.getStringParameter(request, "sid");

    ApplicationSession appSession = ApplicationUtils
            .getApplicationSession(context.getManager().findSession(sid), calcSize, true);

    if (appSession != null) {
        appSession.setAllowedToViewValues(privileged);
        return new ModelAndView(getViewName(), "session", appSession);
    }/*  w ww .j av  a  2  s.c om*/
    return new ModelAndView(getViewName());
}

From source file:com.googlecode.psiprobe.controllers.system.AdviseGCController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    boolean finalization = ServletRequestUtils.getBooleanParameter(request, "fin", false);

    String referer = request.getHeader("Referer");
    String redirectURL;//w  ww  .j  av a 2  s .c om
    if (referer != null) {
        redirectURL = referer.replaceAll(replacePattern, "");
    } else {
        redirectURL = request.getContextPath() + getViewName();
    }
    if (finalization) {
        Runtime.getRuntime().runFinalization();
        logger.debug("Advised finalization");
    } else {
        Runtime.getRuntime().gc();
        logger.debug("Advised Garbage Collection");
    }
    logger.debug("Redirected to " + redirectURL);
    return new ModelAndView(new RedirectView(redirectURL));
}

From source file:psiprobe.controllers.apps.ListWebappsController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    boolean calcSize = ServletRequestUtils.getBooleanParameter(request, "size", false)
            && SecurityUtils.hasAttributeValueRole(getServletContext(), request);

    List<Context> apps;
    try {/*from   w w  w. j  av  a2  s .  c  om*/
        apps = getContainerWrapper().getTomcatContainer().findContexts();
    } catch (NullPointerException ex) {
        throw new IllegalStateException(
                "No container found for your server: " + getServletContext().getServerInfo(), ex);
    }
    List<Application> applications = new ArrayList<>(apps.size());
    boolean showResources = getContainerWrapper().getResourceResolver().supportsPrivateResources();
    for (Context appContext : apps) {
        // check if this is not the ROOT webapp
        if (appContext.getName() != null) {
            applications.add(ApplicationUtils.getApplication(appContext,
                    getContainerWrapper().getResourceResolver(), calcSize, getContainerWrapper()));
        }
    }
    if (!applications.isEmpty() && !showResources) {
        request.setAttribute("no_resources", Boolean.TRUE);
    }
    return new ModelAndView(getViewName(), "apps", applications);
}

From source file:com.googlecode.psiprobe.controllers.apps.ListWebappsController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    boolean calcSize = ServletRequestUtils.getBooleanParameter(request, "size", false)
            && SecurityUtils.hasAttributeValueRole(getServletContext(), request);

    List apps;/*ww w . j  a v  a 2s  . c  o m*/
    try {
        apps = getContainerWrapper().getTomcatContainer().findContexts();
    } catch (NullPointerException ex) {
        throw new IllegalStateException(
                "No container found for your server: " + getServletContext().getServerInfo(), ex);
    }
    List applications = new ArrayList(apps.size());
    boolean showResources = getContainerWrapper().getResourceResolver().supportsPrivateResources();
    for (int i = 0; i < apps.size(); i++) {
        Context appContext = (Context) apps.get(i);
        //
        // check if this is not the ROOT webapp
        //
        if (appContext.getName() != null) {
            applications.add(ApplicationUtils.getApplication(appContext,
                    getContainerWrapper().getResourceResolver(), calcSize, getContainerWrapper()));
        }
    }
    if (!applications.isEmpty() && !showResources) {
        request.setAttribute("no_resources", Boolean.TRUE);
    }
    return new ModelAndView(getViewName(), "apps", applications);
}

From source file:net.testdriven.psiprobe.controllers.apps.ListWebappsController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    boolean calcSize = ServletRequestUtils.getBooleanParameter(request, "size", false)
            && SecurityUtils.hasAttributeValueRole(getServletContext(), request);

    List apps;/* ww  w.  jav  a 2  s.  c o m*/
    try {
        apps = getContainerWrapper().getTomcatContainer().findContexts();
    } catch (NullPointerException ex) {
        throw new IllegalStateException(
                "No container found for your server: " + getServletContext().getServerInfo(), ex);
    }
    List applications = new ArrayList(apps.size());
    boolean showResources = getContainerWrapper().getResourceResolver().supportsPrivateResources();
    for (int i = 0; i < apps.size(); i++) {
        Context appContext = (Context) apps.get(i);
        //
        // check if this is not the ROOT webapp
        //
        if (appContext.getName() != null) {
            applications.add(ApplicationUtils.getApplication(appContext,
                    getContainerWrapper().getResourceResolver(), calcSize));
        }
    }
    if (!applications.isEmpty() && !showResources) {
        request.setAttribute("no_resources", Boolean.TRUE);
    }
    return new ModelAndView(getViewName(), "apps", applications);
}