From: Chris L. <chr...@jb...> - 2006-05-07 00:46:32
|
User: claprun Date: 06/05/06 20:46:30 Modified: wsrp/src/main/org/jboss/portal/wsrp/consumer WSRPConsumerImpl.java Log: - Updated Consumer MarkupTestCase so that it provides the needed value. - Fixed [JBPORTAL-856]: was not checking if the URL needed rewrite before attempting to rewrite. Revision Changes Path 1.19 +41 -13 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java (In the diff below, changes in quantity of whitespace are not shown.) Index: WSRPConsumerImpl.java =================================================================== RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -b -r1.18 -r1.19 --- WSRPConsumerImpl.java 6 May 2006 22:18:46 -0000 1.18 +++ WSRPConsumerImpl.java 7 May 2006 00:46:30 -0000 1.19 @@ -90,7 +90,7 @@ /** * @author <a href="mailto:bol...@jb...">Boleslaw Dawidowicz</a> * @author <a href="mailto:chr...@jb...">Chris Laprun</a> - * @version $Revision: 1.18 $ + * @version $Revision: 1.19 $ * @since 2.4 */ public class WSRPConsumerImpl extends AbstractJBossService implements WSRPConsumer @@ -112,6 +112,7 @@ /** The service factory. */ private ServiceFactory serviceFactory; + private static final WSRPURLRewriter WSRP_URL_REWRITER = new WSRPURLRewriter(); public WSRPConsumerImpl() { @@ -380,16 +381,11 @@ if (rewriteURLs) { - final InvocationContext context = invocation.getContext(); - final boolean secure = invocation.getSecurityContext().isSecure(); + WSRP_URL_REWRITER.setContext(invocation.getContext()); + WSRP_URL_REWRITER.setSecure(invocation.getSecurityContext().isSecure()); + WSRP_URL_REWRITER.setAuthenticated(false); // fix-me - return WSRPPortletURL.replaceURLsBy(markup, new WSRPPortletURL.URLReplacementGenerator() - { - public String getReplacementFor(int currentIndex, WSRPPortletURL.URLMatch currentMatch) - { - return context.encodeURL(currentMatch.getUrl(), Boolean.valueOf(secure), Boolean.FALSE, true); - } - }); + return WSRPPortletURL.replaceURLsBy(markup, WSRP_URL_REWRITER); } return markup; @@ -599,14 +595,14 @@ if (portletDescriptions != null) { int length = portletDescriptions.length; - log.info("Extracting " + length + " portlets."); + log.debug("Extracting " + length + " portlets."); Map portlets = new LinkedHashMap(length); for (int i = 0; i < length; i++) { PortletDescription portletDescription = portletDescriptions[i]; String portletHandle = portletDescription.getPortletHandle(); - log.info("Extracting info for '" + portletHandle + "' portlet"); + log.debug("Extracting info for '" + portletHandle + "' portlet"); WSRPPortletInfo info = new WSRPPortletInfo(portletDescription); portlets.put(portletHandle, new WSRPPortlet(portletHandle, info)); } @@ -637,7 +633,7 @@ // retrieve handle portletHandle = (String)invocation.getAttribute(PortletInvocation.PORTLET_ID_ATTRIBUTE); throwIllegalArgExcIfNull(portletHandle, PORTLET_HANDLE); - log.info("About to invoke on portlet: " + portletHandle); + log.debug("About to invoke on portlet: " + portletHandle); // create runtime context SecurityContext securityContext = invocation.getSecurityContext(); @@ -672,4 +668,36 @@ } } } + + private static class WSRPURLRewriter extends WSRPPortletURL.URLReplacementGenerator + { + private InvocationContext context; + private Boolean secure; + private Boolean authenticated; + + public void setContext(InvocationContext context) + { + this.context = context; + } + + public void setSecure(boolean secure) + { + this.secure = Boolean.valueOf(secure); + } + + public void setAuthenticated(boolean authenticated) + { + this.authenticated = Boolean.valueOf(authenticated); + } + + public String getReplacementFor(int currentIndex, WSRPPortletURL.URLMatch currentMatch) + { + String urlAsString = currentMatch.getUrlAsString(); + if (urlAsString.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE)) + { + return context.encodeURL(new WSRPPortletURL(urlAsString), secure, authenticated, true); + } + return urlAsString; + } + } } |