List of usage examples for javax.servlet.http HttpServletResponse encodeUrl
@Deprecated
public String encodeUrl(String url);
From source file:de.laures.cewolf.taglib.tags.ChartImgTag.java
/** * Build the image url/*w ww.j a v a 2 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:org.jasig.cas.client.util.CommonUtils.java
/** * Constructs a service url from the HttpServletRequest or from the given * serviceUrl. Prefers the serviceUrl provided if both a serviceUrl and a * serviceName.//w w w . j ava2 s .c o m * * @param request the HttpServletRequest * @param response the HttpServletResponse * @param service the configured service url (this will be used if not null) * @param serverName the server name to use to constuct the service url if the service param is empty * @param artifactParameterName the artifact parameter name to remove (i.e. ticket) * @param encode whether to encode the url or not (i.e. Jsession). * @return the service url to use. */ public static String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response, final String service, final String serverName, final String artifactParameterName, final boolean encode) { if (CommonUtils.isNotBlank(service)) { return encode ? response.encodeURL(service) : service; } final StringBuffer buffer = new StringBuffer(); synchronized (buffer) { if (!serverName.startsWith("https://") && !serverName.startsWith("http://")) { buffer.append(request.isSecure() ? "https://" : "http://"); } buffer.append(serverName); buffer.append(request.getRequestURI()); if (CommonUtils.isNotBlank(request.getQueryString())) { final int location = request.getQueryString().indexOf(artifactParameterName + "="); if (location == 0) { final String returnValue = encode ? response.encodeURL(buffer.toString()) : buffer.toString(); if (LOG.isDebugEnabled()) { LOG.debug("serviceUrl generated: " + returnValue); } return returnValue; } buffer.append("?"); if (location == -1) { buffer.append(request.getQueryString()); } else if (location > 0) { final int actualLocation = request.getQueryString().indexOf("&" + artifactParameterName + "="); if (actualLocation == -1) { buffer.append(request.getQueryString()); } else if (actualLocation > 0) { buffer.append(request.getQueryString().substring(0, actualLocation)); } } } } final String returnValue = encode ? response.encodeURL(buffer.toString()) : buffer.toString(); if (LOG.isDebugEnabled()) { LOG.debug("serviceUrl generated: " + returnValue); } return returnValue; }
From source file:org.jasig.cas.util.CommonUtils.java
/** * Constructs a service url from the HttpServletRequest or from the given * serviceUrl. Prefers the serviceUrl provided if both a serviceUrl and a * serviceName.// w w w. j a v a2 s .c o m * * @param request the HttpServletRequest * @param response the HttpServletResponse * @param service the configured service url (this will be used if not null) * @param serverName the server name to use to constuct the service url if the service param is empty * @param artifactParameterName the artifact parameter name to remove (i.e. ticket) * @param encode whether to encode the url or not (i.e. Jsession). * @return the service url to use. */ public static String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response, final String service, final String serverName, final String artifactParameterName, final boolean encode) { if (CommonUtils.isNotBlank(service)) { return encode ? response.encodeURL(service) : service; } final StringBuilder buffer = new StringBuilder(); if (!serverName.startsWith("https://") && !serverName.startsWith("http://")) { buffer.append(request.isSecure() ? "https://" : "http://"); } buffer.append(serverName); buffer.append(request.getRequestURI()); if (CommonUtils.isNotBlank(request.getQueryString())) { final int location = request.getQueryString().indexOf(artifactParameterName + "="); if (location == 0) { final String returnValue = encode ? response.encodeURL(buffer.toString()) : buffer.toString(); if (LOG.isDebugEnabled()) { LOG.debug("serviceUrl generated: " + returnValue); } return returnValue; } buffer.append("?"); if (location == -1) { buffer.append(request.getQueryString()); } else if (location > 0) { final int actualLocation = request.getQueryString().indexOf("&" + artifactParameterName + "="); if (actualLocation == -1) { buffer.append(request.getQueryString()); } else if (actualLocation > 0) { buffer.append(request.getQueryString().substring(0, actualLocation)); } } } final String returnValue = encode ? response.encodeURL(buffer.toString()) : buffer.toString(); if (LOG.isDebugEnabled()) { LOG.debug("serviceUrl generated: " + returnValue); } return returnValue; }
From source file:org.apache.myfaces.renderkit.html.util.NonBufferingAddResource.java
protected static void writeJavaScriptReference(HttpServletResponse response, ResponseWriter writer, String resourceUri, boolean encoding, boolean defer) throws IOException { String src = null;//from w w w .j ava 2s. co m if (encoding) { src = response.encodeURL(resourceUri); } else { src = resourceUri; } writeJavaScriptReference(defer, writer, src); }
From source file:org.wings.session.PortletSessionServlet.java
/** * get the Session Encoding, that is appended to each URL. * Basically, this is response.encodeURL(""), but unfortuntatly, this * empty encoding isn't supported by Tomcat 4.x anymore. */// w w w. j a v a 2 s. co m public static String getSessionEncoding(HttpServletResponse response) { if (response == null) return ""; // encode dummy non-empty URL. return response.encodeURL("foo").substring(3); }
From source file:org.apache.myfaces.renderkit.html.util.NonBufferingAddResource.java
protected static void writeStyleReference(HttpServletResponse response, ResponseWriter writer, String resourceUri) throws IOException { writer.startElement(HTML.LINK_ELEM, null); writer.writeAttribute(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.REL_ATTR, org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.STYLESHEET_VALUE, null); writer.writeAttribute(HTML.HREF_ATTR, response.encodeURL(resourceUri), null); writer.writeAttribute(HTML.TYPE_ATTR, HTML.STYLE_TYPE_TEXT_CSS, null); writer.endElement(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.LINK_ELEM); }
From source file:com.exedio.cope.live.ModificationMedia.java
String getURL(final Anchor anchor, final HttpServletResponse response) { return response.encodeURL(anchor.servletPath + MediaServlet.makeURL(getFeature(), item)); }
From source file:com.exedio.cope.live.ModificationMedia.java
String getURL(final HttpServletRequest request, final HttpServletResponse response) { return response.encodeURL(request.getContextPath() + request.getServletPath() + '/' + MediaServlet.makeURL(getFeature(), item)); }
From source file:springapp.web.controller.theme.ResourceController.java
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { String thisControllerUrl = httpServletResponse.encodeURL(httpServletRequest.getRequestURI()); HttpSession session = httpServletRequest.getSession(); ServletContext servletContext = session.getServletContext(); WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); //String resourcesPath = (String)context.getBean("resourcesPath"); ResourcesHolder currentSchema = (ResourcesHolder) session .getAttribute(ApplicationConstants.CURRENT_SCHEMA_ATTRIBUTE_NAME); String resourcesPath = currentSchema.getResourcesPath(); String resourcePath = httpServletRequest.getParameter("resourcePath"); boolean b = null != resourcePath; Integer hashCode = null;//from w w w . j a va2 s . c o m if (b) try { hashCode = new Integer(Integer.parseInt(resourcePath)); } catch (NumberFormatException e) { hashCode = new Integer(resourcePath.hashCode()); } //ResourcesHolder resource = currentSchema.findResourceByPath(resourcePath); ResourcesHolder resource = currentSchema.findResourceByPathHashCode(hashCode); ResourcesLoader loader = loaderFactory.getResourcesLoader(resource, context); OutputStream outputStream = loader.outForWeb(resource, thisControllerUrl, resourcesPath); if (outputStream instanceof ByteArrayOutputStream) { ByteArrayOutputStream byteArrayOutputStream = (ByteArrayOutputStream) outputStream; if (resource instanceof CSSHolderImpl) httpServletResponse.setContentType("text/css"); else if (resource instanceof GIFHolderImpl) httpServletResponse.setContentType("image/gif"); else if (resource instanceof PNGHolderImpl) httpServletResponse.setContentType("image/png"); httpServletResponse.setHeader("Pragma", "no-cache"); httpServletResponse.setHeader("Cache-Control", "no-cache"); httpServletResponse.setHeader("Expires", "-1"); httpServletResponse.setContentLength(byteArrayOutputStream.size()); ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream(); byteArrayOutputStream.writeTo(servletOutputStream); servletOutputStream.flush(); servletOutputStream.close(); } logger.info("ResourceController ! "); return null; }
From source file:eu.eidas.node.AbstractNodeServlet.java
/** * Encodes any given URL.//w ww .ja v a 2 s. c om * * @param url The URL to be encoded. * * @return The encoded URL. */ protected final String encodeURL(final String url, HttpServletResponse response) { return response.encodeURL(url); }