1 package org.exoplatform.portal.portlet.struts; 2 3 import java.util.HashMap ; 4 import org.exoplatform.services.portletcontainer.helper.URLEncoder; 5 6 7 public class StrutsURLEncoder implements URLEncoder { 8 private static String STATIC_RESOURCE = "static"; 9 private static HashMap staticResource_; 10 11 static { 12 staticResource_ = new HashMap (); 13 staticResource_.put("gif", STATIC_RESOURCE); 14 staticResource_.put("jpg", STATIC_RESOURCE); 15 staticResource_.put("png", STATIC_RESOURCE); 16 staticResource_.put("bmp", STATIC_RESOURCE); 17 staticResource_.put("txt", STATIC_RESOURCE); 18 staticResource_.put("html", STATIC_RESOURCE); 19 staticResource_.put("xml", STATIC_RESOURCE); 20 staticResource_.put("xsl", STATIC_RESOURCE); 21 } 22 23 private String contextPath_; 24 private String portalRequestUrl_; 25 26 public StrutsURLEncoder(String contextPath, String portalUrl) { 27 contextPath_ = contextPath; 28 portalRequestUrl_ = portalUrl; 29 } 30 31 public String encodeURL(String url) { 32 if (url.startsWith("http://")) return url; 33 34 int ml_index = url.indexOf("/", 1); 35 String ml_ext = url.substring(ml_index); 36 url = contextPath_ + ml_ext; 37 38 int index = url.lastIndexOf("."); 39 String ext = null; 40 if (index > 0) { 41 ext = url.substring(index + 1, url.length()); 42 } 43 if (isStaticResource(ext)) { 44 return url; 45 } else { 46 url = url.replace('?', '&'); 47 return portalRequestUrl_ + "&requestUri=" + url; 48 } 49 50 51 } 52 53 private boolean isStaticResource(String ext) { 54 if (ext == null) return false; 55 Object o = staticResource_.get(ext); 56 return o != null; 57 } 58 } 59 | Popular Tags |