1 16 package org.apache.cocoon.portal.wsrp.consumer; 17 18 import org.apache.cocoon.portal.coplet.CopletInstanceData; 19 import org.apache.cocoon.portal.wsrp.adapter.WSRPAdapter; 20 import org.apache.wsrp4j.consumer.URLGenerator; 21 import org.apache.wsrp4j.consumer.URLTemplateComposer; 22 import org.apache.wsrp4j.util.Constants; 23 24 36 public class URLTemplateComposerImpl 37 implements URLTemplateComposer, RequiresWSRPAdapter { 38 39 40 protected URLGenerator urlGenerator; 41 42 43 protected WSRPAdapter adapter; 44 45 48 public void setWSRPAdapter(WSRPAdapter adapter) { 49 this.adapter = adapter; 50 } 51 52 55 public void setURLGenerator(URLGenerator urlGenerator) { 56 this.urlGenerator = urlGenerator; 57 } 58 59 62 public String createBlockingActionTemplate(boolean includePortletHandle, 63 boolean includeUserContextKey, 64 boolean includePortletInstanceKey, 65 boolean includeSessionID) { 66 67 return createTemplate( 68 urlGenerator.getBlockingActionURL(null), 69 true, 70 true, 71 true, 72 true, 73 true, 74 false, 75 false, 76 false, 77 includePortletHandle, 78 includeUserContextKey, 79 includePortletInstanceKey, 80 includeSessionID); 81 } 82 83 86 public String createSecureBlockingActionTemplate(boolean includePortletHandle, 87 boolean includeUserContextKey, 88 boolean includePortletInstanceKey, 89 boolean includeSessionID) { 90 return createTemplate( 91 urlGenerator.getBlockingActionURL(null), 92 true, 93 true, 94 true, 95 true, 96 true, 97 true, 98 false, 99 false, 100 includePortletHandle, 101 includeUserContextKey, 102 includePortletInstanceKey, 103 includeSessionID); 104 } 105 106 109 public String createRenderTemplate(boolean includePortletHandle, 110 boolean includeUserContextKey, 111 boolean includePortletInstanceKey, 112 boolean includeSessionID) { 113 return createTemplate( 114 urlGenerator.getRenderURL(null), 115 true, 116 true, 117 true, 118 true, 119 true, 120 false, 121 false, 122 false, 123 includePortletHandle, 124 includeUserContextKey, 125 includePortletInstanceKey, 126 includeSessionID); 127 } 128 129 132 public String createSecureRenderTemplate(boolean includePortletHandle, 133 boolean includeUserContextKey, 134 boolean includePortletInstanceKey, 135 boolean includeSessionID) { 136 return createTemplate( 137 urlGenerator.getRenderURL(null), 138 true, 139 true, 140 true, 141 true, 142 true, 143 true, 144 false, 145 false, 146 includePortletHandle, 147 includeUserContextKey, 148 includePortletInstanceKey, 149 includeSessionID); 150 } 151 152 155 public String createResourceTemplate(boolean includePortletHandle, 156 boolean includeUserContextKey, 157 boolean includePortletInstanceKey, 158 boolean includeSessionID) { 159 return createTemplate( 160 urlGenerator.getResourceURL(null), 161 true, 162 false, 163 false, 164 false, 165 false, 166 false, 167 true, 168 true, 169 includePortletHandle, 170 includeUserContextKey, 171 includePortletInstanceKey, 172 includeSessionID); 173 } 174 175 178 public String createSecureResourceTemplate(boolean includePortletHandle, 179 boolean includeUserContextKey, 180 boolean includePortletInstanceKey, 181 boolean includeSessionID) { 182 return createTemplate( 183 urlGenerator.getResourceURL(null), 184 true, 185 false, 186 false, 187 false, 188 false, 189 true, 190 true, 191 true, 192 includePortletHandle, 193 includeUserContextKey, 194 includePortletInstanceKey, 195 includeSessionID); 196 } 197 198 201 public String createDefaultTemplate(boolean includePortletHandle, 202 boolean includeUserContextKey, 203 boolean includePortletInstanceKey, 204 boolean includeSessionID) { 205 return createTemplate( 206 urlGenerator.getRenderURL(null), 207 true, 208 true, 209 true, 210 true, 211 true, 212 false, 213 true, 214 true, 215 includePortletHandle, 216 includeUserContextKey, 217 includePortletInstanceKey, 218 includeSessionID); 219 } 220 221 224 public String createSecureDefaultTemplate(boolean includePortletHandle, 225 boolean includeUserContextKey, 226 boolean includePortletInstanceKey, 227 boolean includeSessionID) { 228 return createTemplate( 229 urlGenerator.getRenderURL(null), 230 true, 231 true, 232 true, 233 true, 234 true, 235 true, 236 true, 237 true, 238 includePortletHandle, 239 includeUserContextKey, 240 includePortletInstanceKey, 241 includeSessionID); 242 } 243 244 247 public String getNamespacePrefix() { 248 final CopletInstanceData coplet = this.adapter.getCurrentCopletInstanceData(); 249 return coplet.getId(); 250 } 251 252 270 protected String createTemplate(String url, 271 boolean needsURLType, 272 boolean needsPortletMode, 273 boolean needsNavState, 274 boolean needsInteractionState, 275 boolean needsWinState, 276 boolean needsSecURL, 277 boolean needsURL, 278 boolean needsRewriteResource, 279 boolean needsPortletHandle, 280 boolean needsUserContextKey, 281 boolean needsPortletInstanceKey, 282 boolean needsSessionID) { 283 284 StringBuffer template = new StringBuffer (); 285 StringBuffer remainder = null; 286 287 boolean isFirstParam = true; 288 int index; 289 290 if ((index = url.indexOf(Constants.PARAMS_START)) != -1) { 292 template.append(url.substring(0, index)); 293 remainder = new StringBuffer (url.substring(index + 1)); 294 } else { 295 template.append(url.toString()); 296 } 297 298 if (needsURLType) { 299 if (isFirstParam) { 300 template.append(Constants.PARAMS_START); 301 isFirstParam = false; 302 } 303 template.append(insertPair(Constants.URL_TYPE)); 304 } 305 306 if (needsPortletMode) { 307 if (isFirstParam) { 308 template.append(Constants.PARAMS_START); 309 isFirstParam = false; 310 } else { 311 template.append(Constants.NEXT_PARAM); 312 } 313 template.append(insertPair(Constants.PORTLET_MODE)); 314 } 315 316 if (needsNavState) { 317 if (isFirstParam) { 318 template.append(Constants.PARAMS_START); 319 isFirstParam = false; 320 } else { 321 template.append(Constants.NEXT_PARAM); 322 } 323 template.append(insertPair(Constants.NAVIGATIONAL_STATE)); 324 } 325 326 if (needsInteractionState) { 327 if (isFirstParam) { 328 template.append(Constants.PARAMS_START); 329 isFirstParam = false; 330 } else { 331 template.append(Constants.NEXT_PARAM); 332 } 333 template.append(insertPair(Constants.INTERACTION_STATE)); 334 } 335 336 if (needsWinState) { 337 if (isFirstParam) { 338 template.append(Constants.PARAMS_START); 339 isFirstParam = false; 340 } else { 341 template.append(Constants.NEXT_PARAM); 342 } 343 template.append(insertPair(Constants.WINDOW_STATE)); 344 } 345 346 if (needsSecURL) { 347 if (isFirstParam) { 348 template.append(Constants.PARAMS_START); 349 isFirstParam = false; 350 } else { 351 template.append(Constants.NEXT_PARAM); 352 } 353 template.append(insertPair(Constants.SECURE_URL)); 354 } 355 356 if (needsURL) { 357 if (isFirstParam) { 358 template.append(Constants.PARAMS_START); 359 isFirstParam = false; 360 } else { 361 template.append(Constants.NEXT_PARAM); 362 } 363 template.append(insertPair(Constants.URL)); 364 } 365 366 if (needsRewriteResource) { 367 if (isFirstParam) { 368 template.append(Constants.PARAMS_START); 369 isFirstParam = false; 370 } else { 371 template.append(Constants.NEXT_PARAM); 372 } 373 template.append(insertPair(Constants.REWRITE_RESOURCE)); 374 } 375 376 if (needsPortletHandle) { 377 if (isFirstParam) { 378 template.append(Constants.PARAMS_START); 379 isFirstParam = false; 380 } else { 381 template.append(Constants.NEXT_PARAM); 382 } 383 template.append(insertPair(Constants.PORTLET_HANDLE)); 384 } 385 386 if (needsUserContextKey) { 387 if (isFirstParam) { 388 template.append(Constants.PARAMS_START); 389 isFirstParam = false; 390 } else { 391 template.append(Constants.NEXT_PARAM); 392 } 393 template.append(insertPair(Constants.USER_CONTEXT_KEY)); 394 } 395 396 if (needsPortletInstanceKey) { 397 if (isFirstParam) { 398 template.append(Constants.PARAMS_START); 399 isFirstParam = false; 400 } else { 401 template.append(Constants.NEXT_PARAM); 402 } 403 template.append(insertPair(Constants.PORTLET_INSTANCE_KEY)); 404 } 405 406 if (needsSessionID) { 407 if (isFirstParam) { 408 template.append(Constants.PARAMS_START); 409 isFirstParam = false; 410 } else { 411 template.append(Constants.NEXT_PARAM); 412 } 413 template.append(insertPair(Constants.SESSION_ID)); 414 } 415 416 if (remainder != null) { 418 template.append(Constants.NEXT_PARAM); 419 template.append(remainder); 420 } 421 422 return template.toString(); 423 } 424 425 431 protected String insertPair(String token) { 432 StringBuffer result = new StringBuffer (token); 433 result.append(Constants.EQUALS); 434 result.append(Constants.REPLACE_START); 435 result.append(token); 436 result.append(Constants.REPLACE_END); 437 438 return result.toString(); 439 } 440 } 441 | Popular Tags |