1 16 package org.apache.cocoon.portal.wsrp.consumer; 17 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import org.apache.cocoon.portal.PortalService; 23 import org.apache.cocoon.portal.coplet.CopletInstanceData; 24 import org.apache.cocoon.portal.wsrp.adapter.WSRPAdapter; 25 import org.apache.cocoon.portal.wsrp.adapter.WSRPEventAspect; 26 import org.apache.wsrp4j.consumer.URLGenerator; 27 import org.apache.wsrp4j.util.Constants; 28 29 38 public class URLGeneratorImpl 39 implements URLGenerator, RequiresPortalService, RequiresWSRPAdapter { 40 41 42 protected PortalService service; 43 44 45 protected WSRPAdapter adapter; 46 47 50 public void setWSRPAdapter(WSRPAdapter adapter) { 51 this.adapter = adapter; 52 } 53 54 57 public void setPortalService(PortalService service) { 58 this.service = service; 59 } 60 61 64 public String getBlockingActionURL(Map params) { 65 return this.generateUrl(params); 66 } 67 68 71 public String getRenderURL(Map params) { 72 return this.generateUrl(params); 73 } 74 75 78 public String getResourceURL(Map params) { 79 String portalLink = this.generateUrl(params); 83 84 int linkEndPos = portalLink.indexOf('?'); 87 int pipelineStartPos = portalLink.lastIndexOf('/', linkEndPos); 88 89 StringBuffer buffer = new StringBuffer (); 90 buffer.append(portalLink.substring(0, pipelineStartPos+1)); 91 buffer.append("wsrprsc"); 92 buffer.append(portalLink.substring(linkEndPos)); 93 return buffer.toString(); 94 } 95 96 99 public String getNamespacedToken(String token) { 100 final CopletInstanceData coplet = this.adapter.getCurrentCopletInstanceData(); 101 return coplet.getId(); 102 } 103 104 111 protected String generateUrl(Map params) { 112 if ( params == null ) { 113 params = new HashMap (); 114 } 115 Boolean secureLink = null; 116 if ( "true".equalsIgnoreCase((String )params.get(Constants.SECURE_URL)) ) { 117 secureLink = Boolean.TRUE; 118 } 119 final CopletInstanceData coplet = this.adapter.getCurrentCopletInstanceData(); 120 params.put(WSRPEventAspect.REQUEST_PARAMETER_NAME, coplet.getId()); 121 final StringBuffer buffer = new StringBuffer (this.service.getComponentManager().getLinkService().getRefreshLinkURI(secureLink)); 122 boolean hasParams = buffer.toString().indexOf("?") > 0; 123 Iterator i = params.entrySet().iterator(); 124 while ( i.hasNext() ) { 125 final Map.Entry entry = (Map.Entry )i.next(); 126 if ( hasParams ) { 127 buffer.append('&'); 128 } else { 129 hasParams = true; 130 buffer.append('?'); 131 } 132 buffer.append(entry.getKey()).append('=').append(entry.getValue()); 133 } 134 Map consumerParameters = (Map )coplet.getTemporaryAttribute(WSRPAdapter.ATTRIBUTE_NAME_CONSUMER_MAP); 136 if ( consumerParameters != null ) { 137 i = consumerParameters.entrySet().iterator(); 138 while (i.hasNext()) { 139 final Map.Entry entry = (Map.Entry )i.next(); 140 if ( hasParams ) { 141 buffer.append('&'); 142 } else { 143 hasParams = true; 144 buffer.append('?'); 145 } 146 buffer.append(entry.getKey()).append('=').append(entry.getValue()); 147 } 148 } 149 return buffer.toString(); 150 } 151 } 152 | Popular Tags |