1 48 49 50 package com.caucho.portal.generic; 51 52 import javax.portlet.PortletMode; 53 import javax.portlet.PortletModeException; 54 import javax.portlet.PortletSecurityException; 55 import javax.portlet.WindowState; 56 import javax.portlet.WindowStateException; 57 import java.util.Collections ; 58 import java.util.Enumeration ; 59 import java.util.Iterator ; 60 import java.util.Map ; 61 62 abstract public class InvocationURL 63 { 64 private InvocationFactory _invocationFactory; 65 private String _namespace; 66 private Invocation _invocation; 67 68 private Boolean _isSecure; 69 70 76 public InvocationURL( InvocationFactory invocationFactory, 77 String namespace ) 78 { 79 _invocationFactory = invocationFactory; 80 _namespace = namespace; 81 } 82 83 public String getNamespace() 84 { 85 return _namespace; 86 } 87 88 protected Invocation getInvocation() 89 { 90 if (_invocation == null) 91 _invocation = _invocationFactory.getInvocation(_namespace); 92 93 return _invocation; 94 } 95 96 protected Invocation getInvocation(String namespace) 97 { 98 return _invocationFactory.getInvocation(namespace); 99 } 100 101 protected void setWindowState(Invocation invocation, WindowState windowState) 102 throws WindowStateException 103 { 104 invocation.setWindowState(windowState); 105 } 106 107 public void setWindowState(WindowState windowState) 108 throws WindowStateException 109 { 110 setWindowState(getInvocation(), windowState); 111 } 112 113 public void setWindowState(String namespace, WindowState windowState) 114 throws WindowStateException 115 { 116 setWindowState(getInvocation(namespace), windowState); 117 } 118 119 protected void setPortletMode(Invocation invocation, PortletMode portletMode) 120 throws PortletModeException 121 { 122 invocation.setPortletMode(portletMode); 123 } 124 125 public void setPortletMode(PortletMode portletMode) 126 throws PortletModeException 127 { 128 setPortletMode(getInvocation(), portletMode); 129 } 130 131 public void setPortletMode(String namespace, PortletMode portletMode) 132 throws PortletModeException 133 { 134 setPortletMode(getInvocation(namespace), portletMode); 135 } 136 137 protected Map <String , String []> getRenderParameterMap() 138 { 139 return getInvocation().getParameterMap(); 140 } 141 142 protected Map <String , String []> getRenderParameterMap(String namespace) 143 { 144 return getInvocation(namespace).getParameterMap(); 145 } 146 147 private void checkNullName(String name) 148 { 149 if (name == null) 150 throw new IllegalArgumentException ("parameter name cannot be null"); 151 } 152 153 private void checkNullValue(Object value) 154 { 155 if (value == null) 156 throw new IllegalArgumentException ("parameter value cannot be null"); 157 } 158 159 protected String getParameterValue(Map <String , String []> map, String name) 160 { 161 checkNullName(name); 162 163 String values[] = map.get(name); 164 165 return values == null || values.length == 0 ? null : values[0]; 166 } 167 168 protected String [] getParameterValues( Map <String , String []> map, 169 String name) 170 { 171 checkNullName(name); 172 return map.get(name); 173 } 174 175 protected Enumeration getParameterNames(Map <String , String []> map) 176 { 177 return Collections.enumeration(map.keySet()); 178 } 179 180 protected void setParameter( Map <String , String []> map, 181 String name, 182 String value) 183 { 184 checkNullName(name); 185 checkNullValue(value); 186 187 map.put(name, new String [] { value }); 188 } 189 190 protected void setParameters( Map <String , String []> destMap, 191 Map <String , String []> srcMap) 192 { 193 checkNullValue(srcMap); 194 destMap.clear(); 195 196 Iterator <Map.Entry <String , String []>> iter 197 = srcMap.entrySet().iterator(); 198 199 while (iter.hasNext()) 200 { 201 Map.Entry <String , String []> entry = iter.next(); 202 203 setParameter(destMap, entry.getKey(), entry.getValue()); 204 } 205 } 206 207 protected void setParameter( Map <String , String []> map, 208 String name, 209 String [] values) 210 { 211 checkNullName(name); 212 checkNullValue(values); 213 214 if (values.length == 0) 215 map.remove(name); 216 else 217 map.put(name, values); 218 } 219 220 public void setParameter(String name, String value) 221 { 222 setParameter(getRenderParameterMap(), name, value); 223 } 224 225 public void setParameter(String name, String [] values) 226 { 227 setParameter(getRenderParameterMap(), name, values); 228 } 229 230 public void setParameters(Map <String , String []> parameters) 231 { 232 setParameters(getRenderParameterMap(), parameters); 233 } 234 235 public void setParameter(String namespace, String name, String value) 236 { 237 setParameter(getRenderParameterMap(namespace), name, value); 238 } 239 240 public void setParameter(String namespace, String name, String [] values) 241 { 242 setParameter(getRenderParameterMap(namespace), name, values); 243 } 244 245 public void setParameters(String namespace, Map <String , String []> parameters) 246 { 247 setParameters(getRenderParameterMap(namespace), parameters); 248 } 249 250 public void setSecure(boolean secure) 251 throws PortletSecurityException 252 { 253 _isSecure = secure ? Boolean.TRUE : Boolean.FALSE; 254 } 255 256 260 protected boolean isSecureSpecified() 261 { 262 return _isSecure != null; 263 } 264 265 protected boolean isSecure() 266 { 267 return _isSecure == null || _isSecure == Boolean.FALSE; 268 } 269 270 274 abstract public String getURL(); 275 } 276 | Popular Tags |