1 package org.jahia.clipbuilder.html.web.Url.Impl; 2 3 import javax.servlet.http.*; 4 5 import org.jahia.clipbuilder.html.util.*; 6 import org.jahia.clipbuilder.html.web.Url.*; 7 import org.jahia.clipbuilder.html.web.Constant.*; 8 import org.jahia.clipbuilder.html.*; 9 10 15 public class UrlEncoder extends BaseUrlEncoder { 16 private HttpServletResponse httpServletResponse; 17 private HttpServletRequest httpServletRequest; 18 private String encodedUrl = null; 19 private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(UrlEncoder.class); 20 21 22 23 30 public UrlEncoder(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { 31 setHttpServletResponse(httpServletResponse); 32 setHttpServletRequest(httpServletRequest); 33 } 34 35 36 41 public void setHttpServletResponse(HttpServletResponse httpServletResponse) { 42 this.httpServletResponse = httpServletResponse; 43 } 44 45 46 47 52 public void setHttpServletRequest(HttpServletRequest httpServletRequest) { 53 this.httpServletRequest = httpServletRequest; 54 } 55 56 57 58 63 public String getEncodedUrl() { 64 encodeUrl(); 65 return encodedUrl; 66 } 67 68 69 75 public String getLocalUriResource(String resourcePath) { 76 String uri = getHttpServletRequest().getContextPath() + resourcePath; 77 return uri; 78 } 79 80 81 87 public String getLocalUrl(String url) { 88 String localUrl = getHttpServletRequest().getContextPath() + url; 89 return getHttpServletResponse().encodeURL(localUrl); 90 } 91 92 93 94 99 public HttpServletResponse getHttpServletResponse() { 100 return httpServletResponse; 101 } 102 103 104 109 public HttpServletRequest getHttpServletRequest() { 110 return httpServletRequest; 111 } 112 113 114 117 public void encodeUrl() { 118 try { 119 logger.debug("[ Encoding the url ]"); 120 String action = getAction(); 121 String nameSpace = getNameSpace(); 122 encodedUrl = getHttpServletRequest().getContextPath(); 123 124 String hash = getUrlWrapper().getHash(); 126 URLMap map = SessionManager.getHTMLDocumentBuilder(getHttpServletRequest()).getUrlMap(); 127 map.addSourceUrl(getUrlWrapper(), hash); 128 129 encodedUrl = encodedUrl + "/webBrowser.do?show=" + action + "&" + "nameSpace=" + nameSpace + "&" + org.jahia.clipbuilder.html.struts.Util.Constants.LINK_HASH + "=" + hash; 131 encodedUrl = getHttpServletResponse().encodeURL(encodedUrl); 132 } 133 catch (Exception ex) { 134 logger.error("Error Exception: " + ex.toString()); 135 } 137 } 138 139 140 145 private String getNameSpace() { 146 String nameSpace = RequestParameterManager.getNameSpace(getHttpServletRequest()); 147 return nameSpace; 148 } 149 } 150 | Popular Tags |