Example usage for javax.servlet.jsp PageContext getServletContext

List of usage examples for javax.servlet.jsp PageContext getServletContext

Introduction

In this page you can find the example usage for javax.servlet.jsp PageContext getServletContext.

Prototype


abstract public ServletContext getServletContext();

Source Link

Document

The ServletContext instance.

Usage

From source file:org.osmsurround.tags.NodeEditLinksTag.java

@Override
public void setPageContext(PageContext pageContext) {
    super.setPageContext(pageContext);
    applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(pageContext.getServletContext());
}

From source file:it.scoppelletti.wui.HeadTag.java

/**
 * Implementazione./*from ww w .j a  v a 2 s. c o  m*/
 */
@Override
public void doTag() throws IOException, JspException {
    URI uri;
    UriComponentsBuilder uriBuilder;
    WebApplicationManager applMgr;
    List<String> applList;
    ApplicationContext applCtx;
    PageContext pageCtx = (PageContext) getJspContext();

    applCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(pageCtx.getServletContext());

    applMgr = applCtx.getBean(WebApplicationManager.BEAN_NAME, WebApplicationManager.class);
    applList = applMgr.listRunningApplications();

    for (String ctxPath : applList) {
        uriBuilder = UriComponentsBuilder.fromHttpUrl(applMgr.getBaseUrl());
        uriBuilder.path(ctxPath).path(HeadTag.HEAD_PATH);
        uriBuilder.queryParam(AbstractServerResource.QUERY_LOCALE, pageCtx.getRequest().getLocale().toString());
        uri = uriBuilder.build().toUri();

        try {
            head(uri, pageCtx.getOut());
        } catch (Exception ex) {
            myLogger.error(String.format("Failed to get %1$s.", uri), ex);
        }
    }
}

From source file:org.efs.openreports.util.displaytag.SpringDecoratorFactory.java

@Override
public DisplaytagColumnDecorator loadColumnDecorator(PageContext pageContext, String name)
        throws DecoratorInstantiationException {
    if (StringUtils.isBlank(name))
        return null;

    ApplicationContext appContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(pageContext.getServletContext());

    Object decorator = null;/*  w w  w .j ava2s.c o  m*/

    try {
        decorator = appContext.getBean(name, DisplaytagColumnDecorator.class);
    } catch (NoSuchBeanDefinitionException e) {
        log.debug("Decorator " + name
                + " not found in Spring ApplicationContext. Using DefaultDecoratorFactory.loadTableDecorator. ");
    }

    if (decorator != null && decorator instanceof DisplaytagColumnDecorator)
        return (DisplaytagColumnDecorator) decorator;

    return super.loadColumnDecorator(pageContext, name);
}

From source file:org.efs.openreports.util.displaytag.SpringDecoratorFactory.java

@Override
public TableDecorator loadTableDecorator(PageContext pageContext, String name)
        throws DecoratorInstantiationException {
    if (StringUtils.isBlank(name))
        return null;

    ApplicationContext appContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(pageContext.getServletContext());

    Object decorator = null;/*from w w w  . j  a v a 2  s  . com*/

    try {
        decorator = appContext.getBean(name, TableDecorator.class);
    } catch (NoSuchBeanDefinitionException e) {
        log.debug("Decorator " + name
                + " not found in Spring ApplicationContext. Using DefaultDecoratorFactory.loadTableDecorator. ");
    }

    if (decorator != null && decorator instanceof TableDecorator)
        return (TableDecorator) decorator;

    return super.loadTableDecorator(pageContext, name);
}

From source file:com.ideo.jso.tag.includers.RetentionIncluder.java

public void includeJs(Group group, Writer out, PageContext pageContext) throws IOException {
    includeResource(pageContext, out, RetentionHelper.buildRootRetentionFilePath(group, ".js"), JS_BEGIN_TAG,
            JS_END_TAG);/*from w w  w  .  ja  va  2s .  com*/

    ByteArrayOutputStream outtmp = new ByteArrayOutputStream();
    if (AbstractGroupBuilder.getInstance().buildGroupJsIfNeeded(group, outtmp,
            pageContext.getServletContext())) {
        FileOutputStream fileStream = new FileOutputStream(
                new File(RetentionHelper.buildFullRetentionFilePath(group, ".js")));
        IOUtils.copy(new ByteArrayInputStream(outtmp.toByteArray()), fileStream);
        fileStream.close();
    }
}

From source file:dk.netarkivet.common.webinterface.HTMLUtils.java

/**
 * Forward to our standard error message page with an internationalized message. Note that this <em>doesn't</em>
 * throw ForwardedToErrorPage, it is the job of whoever calls this to do that if not within a JSP page (a JSP page
 * can just return immediately). The text involved must be HTML-escaped before passing to this method.
 *
 * @param context The context that the error happened in (the JSP-defined pageContext, typically)
 * @param i18n The i18n information/*  www  . ja  va  2  s  . c  o  m*/
 * @param label An i18n label for the error. This label should begin with "errormsg;".
 * @param args Any extra args for i18n. These must be valid HTML.
 * @throws IOFailure If the forward fails.
 */
public static void forwardWithRawErrorMessage(PageContext context, I18n i18n, String label, Object... args) {
    // Note that we may not want to be to strict here
    // as otherwise information could be lost.
    ArgumentNotValid.checkNotNull(context, "context");
    ArgumentNotValid.checkNotNull(I18N, "I18N");
    ArgumentNotValid.checkNotNull(label, "label");
    ArgumentNotValid.checkNotNull(args, "args");

    String msg = i18n.getString(context.getResponse().getLocale(), label, args);
    context.getRequest().setAttribute("message", msg);
    RequestDispatcher rd = context.getServletContext().getRequestDispatcher("/message.jsp");
    try {
        rd.forward(context.getRequest(), context.getResponse());
    } catch (IOException e) {
        final String errormsg = "Failed to forward on error " + msg;
        log.warn(errormsg, e);
        throw new IOFailure(errormsg, e);
    } catch (ServletException e) {
        final String errormsg = "Failed to forward on error " + msg;
        log.warn(errormsg, e);
        throw new IOFailure(errormsg, e);
    }
}

From source file:dk.netarkivet.common.webinterface.HTMLUtils.java

/**
 * Forward to our standard error message page with an internationalized message. Note that this <em>doesn't</em>
 * throw ForwardedToErrorPage, it is the job of whoever calls this to do that if not within a JSP page (a JSP page
 * can just return immediately). All text involved will be HTML-escaped.
 *
 * @param context The context that the error happened in (the JSP-defined pageContext, typically)
 * @param I18N The i18n information// w  w w .j a va  2  s . c  om
 * @param label An i18n label for the error. This label should begin with "errormsg;".
 * @param args Any extra args for i18n
 * @throws IOFailure If the forward fails
 */
public static void forwardWithErrorMessage(PageContext context, I18n I18N, String label, Object... args) {
    // Note that we may not want to be to strict here
    // as otherwise information could be lost.
    ArgumentNotValid.checkNotNull(context, "context");
    ArgumentNotValid.checkNotNull(I18N, "I18N");
    ArgumentNotValid.checkNotNull(label, "label");
    ArgumentNotValid.checkNotNull(args, "args");

    String msg = HTMLUtils.escapeHtmlValues(I18N.getString(context.getResponse().getLocale(), label, args));
    context.getRequest().setAttribute("message", msg);
    RequestDispatcher rd = context.getServletContext().getRequestDispatcher("/message.jsp");
    final String errormsg = "Failed to forward on error " + msg;
    try {
        rd.forward(context.getRequest(), context.getResponse());
    } catch (IOException e) {
        log.warn(errormsg, e);
        throw new IOFailure(errormsg, e);
    } catch (ServletException e) {
        log.warn(errormsg, e);
        throw new IOFailure(errormsg, e);
    }
}

From source file:dk.netarkivet.common.webinterface.HTMLUtils.java

/**
 * Forward to our standard error message page with an internationalized message, in case of exception. Note that
 * this <em>doesn't</em> throw ForwardedToErrorPage, it is the job of whoever calls this to do that if not within a
 * JSP page (a JSP page can just return immediately). All text involved will be HTML-escaped.
 *
 * @param context The context that the error happened in (the JSP-defined pageContext, typically)
 * @param i18n The i18n information/* ww  w. j av  a  2  s. c  o  m*/
 * @param e The exception that is being handled.
 * @param label An i18n label for the error. This label should begin with "errormsg;".
 * @param args Any extra args for i18n
 * @throws IOFailure If the forward fails
 */
public static void forwardWithErrorMessage(PageContext context, I18n i18n, Throwable e, String label,
        Object... args) {
    // Note that we may not want to be to strict here
    // as otherwise information could be lost.
    ArgumentNotValid.checkNotNull(context, "context");
    ArgumentNotValid.checkNotNull(I18N, "I18N");
    ArgumentNotValid.checkNotNull(label, "label");
    ArgumentNotValid.checkNotNull(args, "args");

    String msg = HTMLUtils.escapeHtmlValues(i18n.getString(context.getResponse().getLocale(), label, args));
    context.getRequest().setAttribute("message", msg + "\n" + e.getLocalizedMessage());
    RequestDispatcher rd = context.getServletContext().getRequestDispatcher("/message.jsp");
    final String errormsg = "Failed to forward on error " + msg;
    try {
        rd.forward(context.getRequest(), context.getResponse());
    } catch (IOException e1) {
        log.warn(errormsg, e1);
        throw new IOFailure(errormsg, e1);
    } catch (ServletException e1) {
        log.warn(errormsg, e1);
        throw new IOFailure(errormsg, e1);
    }
}

From source file:com.ideo.jso.tag.includers.RetentionIncluder.java

public void includeCss(Group group, Writer out, PageContext pageContext) throws IOException {
    /*includeCssResource(pageContext, 
             out, //from  w ww.j  av a2  s .c o m
             RetentionHelper.buildRootRetentionFilePath(group, ".css"), 
             "<link rel=\"stylesheet\" type=\"text/css\" href=\"", 
             "\"/>");
    */
    ByteArrayOutputStream outtmp = new ByteArrayOutputStream();
    if (AbstractGroupBuilder.getInstance().buildGroupJsIfNeeded(group, outtmp,
            pageContext.getServletContext())) {

        FileOutputStream fileStream = null;
        try {
            fileStream = new FileOutputStream(
                    new File(RetentionHelper.buildFullRetentionFilePath(group, ".css")));
            IOUtils.copy(new ByteArrayInputStream(outtmp.toByteArray()), fileStream);

        } finally {
            if (fileStream != null)
                fileStream.close();
        }
    }
}