1 5 6 package org.exoplatform.services.wsrp.consumer.impl; 7 8 import org.exoplatform.Constants; 9 import org.exoplatform.services.wsrp.WSRPConstants; 10 import org.exoplatform.services.wsrp.consumer.URLTemplateComposer; 11 12 18 19 public class URLTemplateComposerImpl implements URLTemplateComposer{ 20 21 private static final String SECURE_PROTOCOL = "https://"; 22 private static final String NON_SECURE_PROTOCOL = "http://"; 23 private String host = "localhost"; 24 private int port = 8080; 25 26 public void setHost(String host) { 27 this.host = host; 28 } 29 30 public void setPort(int port) { 31 this.port = port; 32 } 33 34 public String createBlockingActionTemplate(String path) { 35 StringBuffer sB = new StringBuffer (); 36 sB.append(NON_SECURE_PROTOCOL); 37 manageServerPath(sB, path); 38 appendParameters(sB); 39 return sB.toString(); 40 } 41 42 public String createSecureBlockingActionTemplate(String path) { 43 StringBuffer sB = new StringBuffer (); 44 sB.append(SECURE_PROTOCOL); 45 manageServerPath(sB, path); 46 appendParameters(sB); 47 return sB.toString(); 48 } 49 50 public String createRenderTemplate(String path) { 51 StringBuffer sB = new StringBuffer (); 52 sB.append(NON_SECURE_PROTOCOL); 53 manageServerPath(sB, path); 54 appendParameters(sB); 55 return sB.toString(); 56 } 57 58 public String createSecureRenderTemplate(String path) { 59 StringBuffer sB = new StringBuffer (); 60 sB.append(SECURE_PROTOCOL); 61 manageServerPath(sB, path); 62 appendParameters(sB); 63 return sB.toString(); 64 } 65 66 public String createResourceTemplate(String path) { 67 StringBuffer sB = new StringBuffer (); 68 sB.append(NON_SECURE_PROTOCOL); 69 manageServerPath(sB, path); 70 appendParameters(sB); 71 return sB.toString(); 72 } 73 74 public String createSecureResourceTemplate(String path) { 75 StringBuffer sB = new StringBuffer (); 76 sB.append(SECURE_PROTOCOL); 77 manageServerPath(sB, path); 78 appendParameters(sB); 79 return sB.toString(); 80 } 81 82 public String createDefaultTemplate(String path) { 83 StringBuffer sB = new StringBuffer (); 84 sB.append(NON_SECURE_PROTOCOL); 85 manageServerPath(sB, path); 86 appendParameters(sB); 87 return sB.toString(); 88 } 89 90 public String createSecureDefaultTemplate(String path) { 91 StringBuffer sB = new StringBuffer (); 92 sB.append(SECURE_PROTOCOL); 93 manageServerPath(sB, path); 94 appendParameters(sB); 95 return sB.toString(); 96 } 97 98 public String getNamespacePrefix() { 99 return ""; 100 } 101 102 private void manageServerPath(StringBuffer stringBuffer, String path) { 103 stringBuffer.append(host); 104 if(port > 0) 105 stringBuffer.append(":").append(port); 106 stringBuffer.append(path); 107 } 108 109 private void appendParameters(StringBuffer stringBuffer){ 110 stringBuffer.append("&" + Constants.PARAMETER_ENCODER + "type={" + WSRPConstants.WSRP_URL_TYPE + "}" ); 111 stringBuffer.append("&" + Constants.PARAMETER_ENCODER + "mode={" + WSRPConstants.WSRP_MODE + "}" ); 112 stringBuffer.append("&" + Constants.PARAMETER_ENCODER + "windowState={" + WSRPConstants.WSRP_WINDOW_STATE + "}" ); 113 stringBuffer.append("&" + Constants.PARAMETER_ENCODER + "isSecure={" + WSRPConstants.WSRP_SECURE_URL + "}" ); 114 115 stringBuffer.append("&" + WSRPConstants.WSRP_PORTLET_HANDLE + "={" 116 + WSRPConstants.WSRP_PORTLET_HANDLE + "}" ); 117 stringBuffer.append("&" + WSRPConstants.WSRP_PORTLET_INSTANCE_KEY + "={" 118 + WSRPConstants.WSRP_PORTLET_INSTANCE_KEY + "}" ); 119 stringBuffer.append("&" + WSRPConstants.WSRP_NAVIGATIONAL_STATE + "={" 120 + WSRPConstants.WSRP_NAVIGATIONAL_STATE + "}" ); 121 stringBuffer.append("&" + WSRPConstants.WSRP_SESSION_ID + "={" 122 + WSRPConstants.WSRP_SESSION_ID + "}" ); 123 stringBuffer.append("&" + WSRPConstants.WSRP_USER_CONTEXT_KEY + "={" 124 + WSRPConstants.WSRP_USER_CONTEXT_KEY + "}" ); 125 stringBuffer.append("&" + WSRPConstants.WSRP_URL + "={" 126 + WSRPConstants.WSRP_URL + "}" ); 127 stringBuffer.append("&" + WSRPConstants.WSRP_REQUIRES_REWRITE + "={" 128 + WSRPConstants.WSRP_REQUIRES_REWRITE + "}" ); 129 stringBuffer.append("&" + WSRPConstants.WSRP_INTERACTION_STATE + "={" 130 + WSRPConstants.WSRP_INTERACTION_STATE + "}" ); 131 stringBuffer.append("&" + WSRPConstants.WSRP_FRAGMENT_ID + "={" 132 + WSRPConstants.WSRP_FRAGMENT_ID + "}" ); 133 } 134 135 } | Popular Tags |