Example usage for javax.servlet.http HttpServletResponse encodeUrl

List of usage examples for javax.servlet.http HttpServletResponse encodeUrl

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse encodeUrl.

Prototype

@Deprecated
public String encodeUrl(String url);

Source Link

Usage

From source file:org.sventon.util.HTMLCreator.java

/**
 * Creates a HTML table containing the changed paths for given revision.
 *
 * @param changedPaths      Paths changed in this revision.
 * @param revision          Revision./*w ww.  j  a v  a 2s  .com*/
 * @param pathAtRevision    The target's path at current revision or <tt>null</tt> if unknown.
 * @param baseURL           Base application URL.
 * @param repositoryName    Repository name.
 * @param showLatestRevInfo If true, the latest revision details DIV will be displayed.
 * @param linkToHead        If true, navigation links will be pointing at HEAD if applicable.
 * @param response          The HTTP response, used to encode the session parameter to the generated URLs. Null if n/a.
 * @return The HTML table.
 */
public static String createChangedPathsTable(final SortedSet<ChangedPath> changedPaths, final long revision,
        final String pathAtRevision, final String baseURL, final RepositoryName repositoryName,
        final boolean showLatestRevInfo, final boolean linkToHead, final HttpServletResponse response) {

    final StringBuilder sb = new StringBuilder("<table class=\"changedPathsTable\">\n");
    sb.append("  <tr>\n");
    sb.append("    <th align=\"left\">Action</th>\n");
    sb.append("    <th align=\"left\">Path</th>\n");
    sb.append("  </tr>\n");

    for (final ChangedPath path : changedPaths) {
        final ChangeType changeType = path.getType();

        sb.append("  <tr>\n");
        sb.append("    <td valign=\"top\"><i>").append(changeType).append("</i></td>\n");

        sb.append("    <td>");

        String goToUrl;
        switch (changeType) {
        case ADDED: // fall thru
        case REPLACED:
            // goToUrl
            goToUrl = createGoToUrl(baseURL, path.getPath(), revision, repositoryName, linkToHead);
            if (response != null) {
                goToUrl = response.encodeURL(goToUrl);
            }
            sb.append("<a href=\"").append(goToUrl);
            if (showLatestRevInfo) {
                sb.append("&showlatestrevinfo=true");
            }
            sb.append("\" title=\"Show\">");
            if (path.getPath().equals(pathAtRevision)) {
                sb.append("<i>").append(path.getPath()).append("</i>").append("</a>");
            } else {
                sb.append(path.getPath()).append("</a>");
            }
            break;
        case MODIFIED:
            // diffUrl
            String diffUrl = createDiffUrl(baseURL, path.getPath(), revision, repositoryName, linkToHead);
            if (response != null) {
                diffUrl = response.encodeURL(diffUrl);
            }
            sb.append("<a href=\"").append(diffUrl);
            if (showLatestRevInfo) {
                sb.append("&showlatestrevinfo=true");
            }
            sb.append("\" title=\"Diff with previous version\">");
            if (path.getPath().equals(pathAtRevision)) {
                sb.append("<i>").append(path.getPath()).append("</i>").append("</a>");
            } else {
                sb.append(path.getPath()).append("</a>");
            }
            break;
        case DELETED:
            // del
            goToUrl = createGoToUrl(baseURL, path.getPath(), revision - 1, repositoryName, false);
            if (response != null) {
                goToUrl = response.encodeURL(goToUrl);
            }
            sb.append("<a href=\"").append(goToUrl);
            sb.append("\" title=\"Show previous revision\"><del>").append(path.getPath()).append("</del></a>");
            break;
        default:
            throw new IllegalArgumentException("Unsupported type: " + changeType);
        }

        if (path.getCopyPath() != null) {
            sb.append("<br>(<i>Copy from</i> ");
            goToUrl = createGoToUrl(baseURL, path.getCopyPath(), path.getCopyRevision(), repositoryName, false);
            if (response != null) {
                goToUrl = response.encodeURL(goToUrl);
            }
            sb.append("<a href=\"").append(goToUrl);
            if (showLatestRevInfo) {
                sb.append("&showlatestrevinfo=true");
            }
            sb.append("\" title=\"Show\">").append(path.getCopyPath()).append("</a>").append(" @ ");
            String revisionInfoUrl = createRevisionInfoUrl(baseURL, path.getCopyRevision(), repositoryName);
            if (response != null) {
                revisionInfoUrl = response.encodeURL(revisionInfoUrl);
            }
            sb.append("<a href=\"").append(revisionInfoUrl);
            sb.append("\">");
            sb.append(path.getCopyRevision()).append("</a>)");
        }
        sb.append("</td>\n");
        sb.append("  </tr>\n");
    }
    sb.append("</table>");
    return sb.toString();
}

From source file:se.trillian.goodies.web.DisableSessionIdInUrlFilterTest.java

public void testSessionIdInEncodeUrlIsRemoved() throws Exception {
    final boolean[] called = new boolean[] { false };

    filter.doFilter(request, response, new FilterChain() {
        public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException {

            HttpServletResponse response = (HttpServletResponse) res;
            assertEquals("/home_en.html", response.encodeRedirectURL("/home_en.html"));
            assertEquals("/home_en.html", response.encodeURL("/home_en.html"));
            called[0] = true;/*from ww  w.j  ava 2  s  . c  o  m*/
        }
    });

    assertTrue(called[0]);
}

From source file:UrlRewrite.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    String contextPath = request.getContextPath();
    String encodedUrl = response.encodeURL(contextPath + "/default.jsp");

    out.println("<html>");
    out.println("<head>");
    out.println("<title>URL Rewriter</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>This page will use URL rewriting if necessary</h2>");
    out.println("Go to the default.jsp page <a href=\"" + encodedUrl + "\">here</a>.");
    out.println("</body>");
    out.println("</html>");

}

From source file:de.hybris.platform.b2bdocumentsfilter.B2BDocumentsSecureMediaFilter.java

private void setSecureURLRendererForThread(final HttpServletResponse httpResponse) {
    final String urlEncoded = httpResponse.encodeURL(this.secureMediaToken);

    MediaUtil.setCurrentSecureMediaURLRenderer(new MediaUtil.SecureMediaURLRenderer()

    {//  w  w  w.j  a  v a2  s  .c  om
        public String renderSecureMediaURL(final AbstractMedia media) {
            return urlEncoded + "?" + MEDIA_PK + "=" + media.getPK().toString();
        }

        @Override
        public String renderSecureMediaURL(MediaSource mediaSource) {
            return null;
        }

    });
}

From source file:org.shredzone.cilla.web.renderer.PaginatorFragmentRenderer.java

/**
 * Creates the URL to a page of the paginator.
 *
 * @param resp/*from w  ww.j  a v a  2 s .  c  o  m*/
 *            {@link HttpServletResponse} for creating the link
 * @param filter
 *            {@link FilterModel} for the contents
 * @param page
 *            page number
 * @return URL of the page
 */
private String getUrl(HttpServletResponse resp, FilterModel filter, int page) {
    LinkBuilder lb = linkService.linkTo().ref(filter);
    if (page != 0) {
        lb.query("p", String.valueOf(page));
    }
    return HtmlUtils.htmlEscape(resp.encodeURL(lb.toString()));
}

From source file:eu.eidas.node.AbstractSpecificServlet.java

/**
 * Encodes any given URL.//from  w  w  w  . j a  va 2s . c  o  m
 *
 * @param url      The URL to be encoded.
 * @param request
 * @param response @return The encoded URL.
 */
protected final String encodeURL(final String url, HttpServletRequest request, HttpServletResponse response) {

    if (request.getSession(false) == null) {
        // If the session doesn't exist, then we must create it.
        request.getSession();
    }
    return response.encodeURL(url);
}

From source file:org.osmsurround.ae.oauth.OauthService.java

public String getRequestTokenUrl(HttpServletResponse response) {

    try {//  ww  w  . j av a2  s . c  o m

        // fetches a request token from the service provider and builds
        // a url based on AUTHORIZE_WEBSITE_URL and CALLBACK_URL to
        // which your app must now send the user
        return provider.retrieveRequestToken(consumer, response.encodeURL(callbackUrl));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.jahia.bin.JahiaAdministration.java

/**
 * Static method to generate URLs for the administration. This should be
 * used by all JSPs and java code that is called by the administration.
 *
 * @param request          the current request object, used to generate the context
 *                         path part of the URL
 * @param response         the current response object, used to make a call to
 *                         encodeURL to generate session information in the case that cookies cannot
 *                         be used/*from   w w w.ja  v a  2s  .com*/
 * @param doAction         a String representing the action we are linking to. This
 *                         is then encoded as a ?do=doAction string
 * @param extraQueryParams a string including any other parameters that will
 *                         be directly appended after the doAction string. This is done because this
 *                         way we offer the possibility to do an encodeURL over the whole string.
 *                         Note that this string may be null.
 * @return a String containing an URL with jsessionid generated and in the
 *         form : /contextPath/servletPath/?do=doActionextraQueryParams
 */
public static String composeActionURL(HttpServletRequest request, HttpServletResponse response, String doAction,
        String extraQueryParams) {
    String internalDoAction = "";
    String internalQueryParams = "";

    if (doAction != null) {
        internalDoAction = "/?do=" + doAction;
    }

    if (extraQueryParams != null) {
        internalQueryParams = extraQueryParams;
    }

    StringBuffer actionURL = new StringBuffer();
    actionURL.append(request.getContextPath()).append(getServletPath()).append(internalDoAction)
            .append(internalQueryParams);
    return response.encodeURL(StringUtils.replace(actionURL.toString(), "//", "/"));
}

From source file:org.jahia.services.seo.urlrewrite.UrlRewriteEngine.java

public String rewriteOutbound(String url, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException, InvocationTargetException {

    RewrittenOutboundUrl rou = processEncodeURL(response, request, false, url);
    if (rou == null) {
        return response.encodeURL(url);
    }//from w w  w.java2  s. co m
    if (rou.isEncode()) {
        rou.setTarget(response.encodeURL(rou.getTarget()));
    }
    return processEncodeURL(response, request, true, rou.getTarget()).getTarget();

}

From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.AbstractPageController.java

/**
 * Checks request URL against properly resolved URL and returns null if url is proper or redirection string if not.
 * /* w w  w .  ja  v  a 2 s. co m*/
 * @param request
 *           - request that contains current URL
 * @param response
 *           - response to write "301 Moved Permanently" status to if redirected
 * @param resolvedUrlPath
 *           - properly resolved URL
 * @return null if url is properly resolved or redirection string if not
 * @throws UnsupportedEncodingException
 */
protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response,
        final String resolvedUrlPath) throws UnsupportedEncodingException {
    try {
        final String resolvedUrl = response.encodeURL(request.getContextPath() + resolvedUrlPath);
        final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8");
        final String decoded = URIUtil.decode(resolvedUrl, "utf-8");
        if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) {
            return null;
        } else {
            request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.MOVED_PERMANENTLY);
            final String queryString = request.getQueryString();
            if (queryString != null && !queryString.isEmpty()) {
                return "redirect:" + resolvedUrlPath + "?" + queryString;
            }
            return "redirect:" + resolvedUrlPath;
        }
    } catch (final URIException e) {
        throw new UnsupportedEncodingException();
    }
}