1 5 6 package org.exoplatform.services.wsrp.consumer.impl; 7 8 9 import java.net.URLEncoder ; 10 import java.util.Iterator ; 11 import java.util.Map ; 12 import java.util.Set ; 13 import org.exoplatform.Constants; 14 import org.exoplatform.services.wsrp.WSRPConstants; 15 import org.exoplatform.services.wsrp.consumer.URLGenerator; 16 17 23 24 public class URLGeneratorImpl implements URLGenerator{ 25 26 public String getBlockingActionURL(String baseURL, Map params) { 27 return getURL(baseURL, params); 28 } 29 30 public String getRenderURL(String baseURL, Map params) { 31 return getURL(baseURL, params); 32 } 33 34 public String getResourceURL(String baseURL, Map params) { 35 return getURL(baseURL, params); 36 } 37 38 private String getURL(String baseURL, Map params){ 39 StringBuffer sB = new StringBuffer (); 40 sB.append(baseURL); 41 return computeParameters(sB, params); 42 } 43 44 public String getNamespacedToken(String token) { 45 return token; 46 } 47 48 private String computeParameters(StringBuffer sB, Map parameters){ 49 Set names = parameters.keySet(); 50 for (Iterator iterator = names.iterator(); iterator.hasNext();) { 51 String name = (String ) iterator.next() ; 52 Object obj = parameters.get(name) ; 53 if (obj instanceof String ) { 54 String value = (String ) obj ; 55 sB.append("&"); 56 sB.append(URLEncoder.encode(replaceName(name))); 57 sB.append("="); 58 sB.append(URLEncoder.encode(replaceValue(value))); 59 } else { 60 String [] values = (String []) obj ; 61 for (int i=0; i < values.length ; i++) { 62 name = replaceName(name); 63 sB.append("&"); 64 sB.append(URLEncoder.encode(name)); 65 sB.append("="); 66 sB.append(URLEncoder.encode(values[i])); 67 } 68 } 69 } 70 return sB.toString(); 71 } 72 73 private String replaceName(String name){ 74 if(WSRPConstants.WSRP_MODE.equals(name)) 75 return Constants.PORTLET_MODE_PARAMETER; 76 else if(WSRPConstants.WSRP_WINDOW_STATE.equals(name)) 77 return Constants.WINDOW_STATE_PARAMETER; 78 else if(WSRPConstants.WSRP_PORTLET_HANDLE.equals(name)) 79 return Constants.COMPONENT_PARAMETER; 80 else if(WSRPConstants.WSRP_SECURE_URL.equals(name)) 81 return Constants.SECURE_PARAMETER; 82 else if(WSRPConstants.WSRP_URL_TYPE.equals(name)) 83 return Constants.TYPE_PARAMETER; 84 return name; 85 } 86 87 private String replaceValue(String value){ 88 if(value.startsWith(WSRPConstants.WSRP_PREFIX)) 89 value = value.substring(WSRPConstants.WSRP_PREFIX.length()); 90 if(WSRPConstants.URL_TYPE_BLOCKINGACTION.equals(value)) 91 value = "action"; 92 return value; 93 } 94 95 } | Popular Tags |