Example usage for javax.servlet.jsp PageContext getResponse

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

Introduction

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

Prototype


abstract public ServletResponse getResponse();

Source Link

Document

The current value of the response object (a ServletResponse).

Usage

From source file:de.laures.cewolf.taglib.tags.ChartImgTag.java

/**
 * Build the image url/* w w w .j  a  v a2 s . c o  m*/
 * @param renderer the url of the renderer
 * @param pageContext Page context
 * @param sessionKey The session key for the image stored.
 * @param width The width 
 * @param height The height
 * @param mimeType the mime-type (for example png) of it
 * @return The full url 
 */
public static String buildImgURL(String renderer, PageContext pageContext, String sessionKey, int width,
        int height, String mimeType, boolean forceSessionId, boolean removeAfterRender) {
    renderer = fixAbsolutURL(renderer, pageContext);
    final HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
    StringBuffer url = new StringBuffer(response.encodeURL(renderer));
    if (url.toString().indexOf(WebConstants.SESSIONID_KEY) == -1) {
        if (forceSessionId) {
            final String sessionId = pageContext.getSession().getId();
            url.append(";" + WebConstants.SESSIONID_KEY + "=" + sessionId);
        }
    }
    url.append("?" + WebConstants.IMG_PARAM + "=" + sessionKey);
    url.append(WebConstants.AMPERSAND + WebConstants.WIDTH_PARAM + "=" + width);
    url.append(WebConstants.AMPERSAND + WebConstants.HEIGHT_PARAM + "=" + height);
    if (removeAfterRender) {
        url.append(WebConstants.AMPERSAND + WebConstants.REMOVE_AFTER_RENDERING + "=true");
    }
    url.append(WebConstants.AMPERSAND + "iehack=" + MIMEExtensionHelper.getExtensionForMimeType(mimeType));
    return url.toString();
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagUtil.java

/**
 * Includes arbitrary _local_ url as content
 * @param ctx caller's page context//from w w  w.ja va 2 s .co  m
 * @param url local url
 * @throws JspException if something goes wrong
 *
 * Note: Local means Urls in the same application
 */
public static void includeContent(PageContext ctx, String url) throws JspException {
    HttpServletRequest request = (HttpServletRequest) ctx.getRequest();
    HttpServletResponse response = (HttpServletResponse) ctx.getResponse();
    RequestDispatcher rd = request.getSession(true).getServletContext().getRequestDispatcher(url);
    if (rd == null) {
        ListTagUtil.write(ctx, "<!-- " + url + " not found -->");
    } else {
        try {
            BufferedResponseWrapper wrapper = new BufferedResponseWrapper(response);
            rd.include(request, wrapper);
            wrapper.flush();
            ListTagUtil.write(ctx, wrapper.getBufferedOutput());
        } catch (Exception e) {
            throw new JspException(e);
        }
    }
}

From source file:dk.netarkivet.archive.webinterface.BitpreserveFileState.java

/**
 * Processes a checksum request./*  w  w  w.  j  a  v  a  2s .  c  o m*/
 * <p>
 * The name of a bitarchive must always be given in parameter Constants.BITARCHIVE_NAME_PARAM.
 * <p>
 * If parameter Constants.FILENAME_PARAM is given, file info for that file will be returned, and all actions will
 * work on that file.
 * <p>
 * If parameter Constants.FIX_ADMIN_CHECKSUM_PARAM is given, the admin data checksum will be fixed for the file.
 * <p>
 * If parameter Constants.CREDENTIALS and Constants.CHECKSUM_PARAM is given, removes and reuploads a file with that
 * checksum in the given bitarchive, using the credentials for authorisation.
 *
 * @param res the result object. This is updated with result information, and expected to be printed to the
 * resulting page.
 * @param context the current JSP pagecontext.
 * @return The file preservation state for a file, if a filename is given in the request. Null otherwise.
 * @throws ArgumentNotValid If the context or res is null.
 */
public static PreservationState processChecksumRequest(StringBuilder res, PageContext context)
        throws ArgumentNotValid {
    ArgumentNotValid.checkNotNull(res, "StringBuilder res");
    ArgumentNotValid.checkNotNull(context, "PageContext context");
    ServletRequest request = context.getRequest();
    Locale l = context.getResponse().getLocale();
    HTMLUtils.forwardOnIllegalParameter(context, Constants.BITARCHIVE_NAME_PARAM, Replica.getKnownNames());
    String bitarchiveName = request.getParameter(Constants.BITARCHIVE_NAME_PARAM);
    Replica bitarchive = Replica.getReplicaFromName(bitarchiveName);
    String filename = request.getParameter(Constants.FILENAME_PARAM);
    String fixadminchecksum = request.getParameter(Constants.FIX_ADMIN_CHECKSUM_PARAM);
    String credentials = request.getParameter(Constants.CREDENTIALS_PARAM);
    String checksum = request.getParameter(Constants.CHECKSUM_PARAM);

    // Parameter validation. Get filename. Complain about missing filename
    // if we are trying to do actions.
    if (filename == null) { // param "file" not set - no action to take
        if (fixadminchecksum != null || credentials != null || checksum != null) {
            // Only if an action was intended do we complain about
            // a missing file.
            res.append(I18N.getString(l, "errormsg;lack.name.for.file.to.be.corrected.in.0", bitarchiveName));
        }
        return null;
    }

    // At this point we know that the parameter filename is given.
    // Now we check for actions.
    ActiveBitPreservation preserve = ActiveBitPreservationFactory.getInstance();
    if (fixadminchecksum != null) {
        // Action to fix admin.data checksum.
        preserve.changeStateForAdminData(filename);
        res.append(I18N.getString(l, "file.0.now.has.correct.checksum.in.admin.data", filename));
        res.append("<br/>");
    } else if (checksum != null || credentials != null) {
        // Action to replace a broken file with a correct file.
        // Both parameters must be given.
        if (checksum == null) { // param CHECKSUM_PARAM not set
            res.append(I18N.getString(l, "errormsg;lack.checksum.for.corrupted.file.0", filename));
            res.append("<br/>");
        } else if (credentials == null) { // param CREDENTIALS_PARAM not set
            res.append(I18N.getString(l, "errormsg;lacking.privileges.to.correct.in.replica"));
            res.append("<br/>");
        } else {
            // Parameters are correct. Fix the file and report result.
            try {
                preserve.replaceChangedFile(bitarchive, filename, credentials, checksum);
                res.append(I18N.getString(l, "file.0.has.been.replaced.in.1", filename, bitarchive));
                res.append("<br/>");
            } catch (Exception e) {
                res.append(I18N.getString(l, "errormsg;attempt.at.restoring.0.in.replica" + ".at.1.failed",
                        filename, bitarchive));
                res.append("<br/>");
                res.append(e.getMessage());
                res.append("<br/>");
                log.warn("Attempt at restoring '" + filename + "' in bitarchive on replica '" + bitarchive
                        + "' failed", e);
            }
        }
    }

    return preserve.getPreservationState(filename);
}

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

/**
 * Get the locale according to header context information.
 *
 * @param context The context of the web page request.
 * @return The locale given in the the page response.
 *///from  www  .  j a v  a  2s. c om
public static Locale getLocaleObject(PageContext context) {
    ArgumentNotValid.checkNotNull(context, "context");
    return context.getResponse().getLocale();
}

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

/**
 * Prints the header information for the webpages in the GUI. This includes the navigation menu, and links for
 * changing the language. The title of the page is generated internationalised from sitesections. If you want to
 * specify it, use the overloaded method.
 *
 * @param context The context of the web page request.
 * @throws IOException if an error occurs during writing of output.
 *///  w ww  . j a v  a 2 s. c om
public static void generateHeader(PageContext context) throws IOException {
    ArgumentNotValid.checkNotNull(context, "context");
    String url = ((HttpServletRequest) context.getRequest()).getRequestURL().toString();
    Locale locale = context.getResponse().getLocale();
    String title = getTitle(url, locale);
    generateHeader(title, context);
}

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

/**
 * Prints the header information for the webpages in the GUI. This includes the navigation menu, and links for
 * changing the language. The title of the page is generated internationalised from sitesections. If you want to
 * specify it, use the overloaded method.
 *
 * @param context The context of the web page request.
 * @throws IOException if an error occurs during writing of output.
 *//*from www  . j  a va 2s .  co m*/
public static void generateHeader(PageContext context, String... jsToInclude) throws IOException {
    ArgumentNotValid.checkNotNull(context, "context");
    String url = ((HttpServletRequest) context.getRequest()).getRequestURL().toString();
    Locale locale = context.getResponse().getLocale();
    String title = getTitle(url, locale);
    generateHeader(title, context, jsToInclude);
}

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

/**
 * Prints the header information for the webpages in the GUI. This includes the navigation menu, and links for
 * changing the language. The title of the page is generated internationalised from sitesections. If you want to
 * specify it, use the overloaded method.
 *
 * @param context The context of the web page request.
 * @param refreshInSeconds auto-refresh time in seconds
 * @throws IOException if an error occurs during writing of output.
 *///from   www .  j av  a 2s.c o m
public static void generateHeader(PageContext context, long refreshInSeconds) throws IOException {
    ArgumentNotValid.checkNotNull(context, "context");
    String url = ((HttpServletRequest) context.getRequest()).getRequestURL().toString();
    Locale locale = context.getResponse().getLocale();
    String title = getTitle(url, locale);
    generateHeader(title, refreshInSeconds, context);
}

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

/**
 * Prints the header information for the webpages in the GUI. This includes the navigation menu, and links for
 * changing the language.//from www  . java2s.  c  om
 *
 * @param title An internationalised title of the page.
 * @param context The context of the web page request.
 * @param refreshInSeconds auto-refresh time in seconds
 * @throws IOException if an error occurs during writing to output.
 */
public static void generateHeader(String title, long refreshInSeconds, PageContext context) throws IOException {
    ArgumentNotValid.checkNotNull(title, "title");
    ArgumentNotValid.checkNotNull(context, "context");

    JspWriter out = context.getOut();
    String url = ((HttpServletRequest) context.getRequest()).getRequestURL().toString();
    Locale locale = context.getResponse().getLocale();
    title = escapeHtmlValues(title);
    log.debug("Loaded URL '" + url + "' with title '" + title + "'");
    out.print(WEBPAGE_HEADER_TEMPLATE_TOP);
    if (refreshInSeconds > 0) {
        out.print(WEBPAGE_HEADER_AUTOREFRESH.replace(TITLE_PLACEHOLDER, Long.toString(refreshInSeconds)));
    }
    out.print(WEBPAGE_HEADER_TEMPLATE_BOTTOM.replace(TITLE_PLACEHOLDER, title).replace(JS_PLACEHOLDER, ""));
    // Start the two column / one row table which fills the page
    out.print("<table id =\"main_table\"><tr>\n");
    // fill in data in the left column
    generateNavigationTree(out, url, locale);
    // The right column contains the active form content for this page
    out.print("<td valign = \"top\" >\n");
    // Language links
    generateLanguageLinks(out);
}

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

/**
 * Prints the header information for the webpages in the GUI. This includes the navigation menu, and links for
 * changing the language./*from   w w w  .jav a  2 s . c  om*/
 *
 * @param title An internationalised title of the page.
 * @param context The context of the web page request.
 * @param jsToInclude path(s) to external .js files to include in header.
 * @throws IOException if an error occurs during writing to output.
 */
public static void generateHeader(String title, PageContext context, String... jsToInclude) throws IOException {
    ArgumentNotValid.checkNotNull(title, "title");
    ArgumentNotValid.checkNotNull(context, "context");

    JspWriter out = context.getOut();
    String url = ((HttpServletRequest) context.getRequest()).getRequestURL().toString();
    Locale locale = context.getResponse().getLocale();
    title = escapeHtmlValues(title);
    log.debug("Loaded URL '" + url + "' with title '" + title + "'");
    out.print(WEBPAGE_HEADER_TEMPLATE_TOP);

    String includeJs = "";
    if (jsToInclude != null && jsToInclude.length > 0) {
        for (String js : jsToInclude) {
            includeJs += "<script type=\"text/javascript\" src=\"" + js + "\"></script>\n";
        }
    }

    out.print(WEBPAGE_HEADER_TEMPLATE_BOTTOM.replace(TITLE_PLACEHOLDER, title).replace(JS_PLACEHOLDER,
            includeJs));
    // Start the two column / one row table which fills the page
    out.print("<table id =\"main_table\"><tr>\n");
    // fill in data in the left column
    generateNavigationTree(out, url, locale);
    // The right column contains the active form content for this page
    out.print("<td valign = \"top\" >\n");
    // Language links
    generateLanguageLinks(out);
}

From source file:net.jcreate.xkins.Context.java

/**
 * Constructor que recibe el pageContext y de ah saca el request, session y servletContext.
 * @param pctx//from  w ww  .  j av a 2 s.co m
 */
public Context(PageContext pctx) {
    this.servletRequest = pctx.getRequest();
    this.servletResponse = pctx.getResponse();
}