Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java?rev=833247&r1=833246&r2=833247&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java (original) +++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java Thu Nov 5 23:54:25 2009 @@ -39,8 +39,8 @@ import org.apache.struts2.StrutsException; import org.apache.struts2.portlet.context.PortletActionContext; +import org.apache.commons.lang.xwork.StringUtils; -import com.opensymphony.xwork2.util.TextUtils; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; /** @@ -88,7 +88,7 @@ LOG.debug("Creating url. Action = " + action + ", Namespace = " + namespace + ", Type = " + type); namespace = prependNamespace(namespace, portletMode); - if (!TextUtils.stringSet(portletMode)) { + if (StringUtils.isEmpty(portletMode)) { portletMode = PortletActionContext.getRequest().getPortletMode().toString(); } String result = null; @@ -105,30 +105,30 @@ params.put(key, new String[] { val }); } } - if (TextUtils.stringSet(namespace)) { + if (StringUtils.isNotEmpty(namespace)) { resultingAction.append(namespace); if(!action.startsWith("/") && !namespace.endsWith("/")) { resultingAction.append("/"); } } resultingAction.append(action); - if(TextUtils.stringSet(method)) { + if(StringUtils.isNotEmpty(method)) { resultingAction.append("!").append(method); } - LOG.debug("Resulting actionPath: " + resultingAction); + if (LOG.isDebugEnabled()) LOG.debug("Resulting actionPath: " + resultingAction); params.put(ACTION_PARAM, new String[] { resultingAction.toString() }); BaseURL url = null; if ("action".equalsIgnoreCase(type)) { - LOG.debug("Creating action url"); + if (LOG.isDebugEnabled()) LOG.debug("Creating action url"); url = response.createActionURL(); } else if("resource".equalsIgnoreCase(type)) { - LOG.debug("Creating resource url"); + if (LOG.isDebugEnabled()) LOG.debug("Creating resource url"); url = response.createResourceURL(); } else { - LOG.debug("Creating render url"); + if (LOG.isDebugEnabled()) LOG.debug("Creating render url"); url = response.createRenderURL(); } @@ -144,8 +144,9 @@ } if(url instanceof PortletURL) { try { - ((PortletURL)url).setPortletMode(getPortletMode(request, portletMode)); - ((PortletURL)url).setWindowState(getWindowState(request, windowState)); + final PortletURL portletUrl = (PortletURL) url; + portletUrl.setPortletMode(getPortletMode(request, portletMode)); + portletUrl.setWindowState(getWindowState(request, windowState)); } catch (Exception e) { LOG.error("Unable to set mode or state:" + e.getMessage(), e); } @@ -171,28 +172,28 @@ private static String prependNamespace(String namespace, String portletMode) { StringBuffer sb = new StringBuffer(); PortletMode mode = PortletActionContext.getRequest().getPortletMode(); - if(TextUtils.stringSet(portletMode)) { + if(StringUtils.isNotEmpty(portletMode)) { mode = new PortletMode(portletMode); } String portletNamespace = PortletActionContext.getPortletNamespace(); String modeNamespace = (String)PortletActionContext.getModeNamespaceMap().get(mode); - LOG.debug("PortletNamespace: " + portletNamespace + ", modeNamespace: " + modeNamespace); - if(TextUtils.stringSet(portletNamespace)) { + if (LOG.isDebugEnabled()) LOG.debug("PortletNamespace: " + portletNamespace + ", modeNamespace: " + modeNamespace); + if(StringUtils.isNotEmpty(portletNamespace)) { sb.append(portletNamespace); } - if(TextUtils.stringSet(modeNamespace)) { + if(StringUtils.isNotEmpty(modeNamespace)) { if(!modeNamespace.startsWith("/")) { sb.append("/"); } sb.append(modeNamespace); } - if(TextUtils.stringSet(namespace)) { + if(StringUtils.isNotEmpty(namespace)) { if(!namespace.startsWith("/")) { sb.append("/"); } sb.append(namespace); } - LOG.debug("Resulting namespace: " + sb); + if (LOG.isDebugEnabled()) LOG.debug("Resulting namespace: " + sb); return sb.toString(); } @@ -264,13 +265,12 @@ * @param portletReq The PortletRequest. * @param windowState The WindowState as a String. * @return The WindowState that mathces the <tt>windowState</tt> String, or if - * the Sring is blank, the current WindowState. + * the String is blank, the current WindowState. */ private static WindowState getWindowState(PortletRequest portletReq, String windowState) { WindowState state = portletReq.getWindowState(); - if (TextUtils.stringSet(windowState)) { - state = portletReq.getWindowState(); + if (StringUtils.isNotEmpty(windowState)) { if ("maximized".equalsIgnoreCase(windowState)) { state = WindowState.MAXIMIZED; } else if ("normal".equalsIgnoreCase(windowState)) { @@ -291,14 +291,13 @@ * @param portletReq The PortletRequest. * @param portletMode The PortletMode as a String. * @return The PortletMode that mathces the <tt>portletMode</tt> String, or if - * the Sring is blank, the current PortletMode. + * the String is blank, the current PortletMode. */ private static PortletMode getPortletMode(PortletRequest portletReq, String portletMode) { PortletMode mode = portletReq.getPortletMode(); - if (TextUtils.stringSet(portletMode)) { - mode = portletReq.getPortletMode(); + if (StringUtils.isNotEmpty(portletMode)) { if ("edit".equalsIgnoreCase(portletMode)) { mode = PortletMode.EDIT; } else if ("view".equalsIgnoreCase(portletMode)) {
Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java?rev=833247&r1=833246&r2=833247&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java (original) +++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java Thu Nov 5 23:54:25 2009 @@ -94,7 +94,7 @@ Enumeration names = new Enumeration() { - List keys = Arrays.asList(new Object[] { "key1", "key2" }); + List keys = Arrays.asList("key1", "key2"); Iterator it = keys.iterator(); @@ -109,7 +109,7 @@ }; Enumeration initParamNames = new Enumeration() { - List keys = Arrays.asList(new Object[] { "key3" }); + List keys = Arrays.asList("key3"); Iterator it = keys.iterator(); @@ -156,7 +156,7 @@ mockPortletContext.expects(once()).method("removeAttribute").with(eq("key1")); mockPortletContext.expects(once()).method("removeAttribute").with(eq("key2")); - ArrayList dummy = new ArrayList(); + ArrayList<String> dummy = new ArrayList<String>(); dummy.add("key1"); dummy.add("key2"); Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java?rev=833247&r1=833246&r2=833247&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java (original) +++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java Thu Nov 5 23:54:25 2009 @@ -20,42 +20,23 @@ */ package org.apache.struts2.portlet.dispatcher; -import java.io.File; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.ListResourceBundle; -import java.util.Locale; -import java.util.Map; - -import javax.portlet.ActionRequest; -import javax.portlet.ActionResponse; -import javax.portlet.PortletConfig; -import javax.portlet.PortletContext; -import javax.portlet.PortletMode; -import javax.portlet.PortletSession; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; -import javax.portlet.WindowState; - +import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.ActionProxy; +import com.opensymphony.xwork2.ActionProxyFactory; +import com.opensymphony.xwork2.util.ValueStack; import org.apache.struts2.StrutsConstants; import org.apache.struts2.dispatcher.mapper.ActionMapping; +import static org.apache.struts2.portlet.PortletContstants.*; import org.easymock.EasyMock; import org.jmock.Mock; import org.jmock.cglib.MockObjectTestCase; import org.jmock.core.Constraint; -import org.springframework.mock.web.portlet.MockActionRequest; -import org.springframework.mock.web.portlet.MockActionResponse; import org.springframework.mock.web.portlet.MockPortletConfig; import org.springframework.mock.web.portlet.MockPortletContext; -import com.opensymphony.xwork2.Action; -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.ActionProxy; -import com.opensymphony.xwork2.ActionProxyFactory; -import com.opensymphony.xwork2.util.ValueStack; - -import static org.apache.struts2.portlet.PortletContstants.*; +import javax.portlet.*; +import java.util.*; /** * Jsr168DispatcherTest. Insert description. @@ -244,10 +225,8 @@ private void setupParamStub(Map<String, String[]> requestParams, Mock mockRequest, String method) { Map<String, String> newMap = new HashMap<String, String>(); - Iterator<String> it = requestParams.keySet().iterator(); - while(it.hasNext()) { - String key = it.next(); - String[] val = (String[])requestParams.get(key); + for ( String key : requestParams.keySet() ) { + String[] val = requestParams.get(key); newMap.put(key, val[0]); } setupStub(newMap, mockRequest, method); @@ -263,9 +242,7 @@ * @param method The name of the method to stub. */ private void setupStub(Map map, Mock mock, String method) { - Iterator it = map.keySet().iterator(); - while(it.hasNext()) { - Object key = it.next(); + for ( Object key : map.keySet() ) { Object val = map.get(key); mock.stubs().method(method).with(eq(key)).will(returnValue(val)); } @@ -307,23 +284,4 @@ } } - public void testMultipartRequest_parametersAreCopiedToActionInvocation() throws Exception { - MockPortletContext ctx = new MockPortletContext(); - ctx.setAttribute("javax.servlet.context.tempdir", new File("target").getAbsoluteFile()); - MockActionRequest request = new MockActionRequest(ctx); - request.setContent(MULTIPART_REQUEST.getBytes("US-ASCII")); - request.setContentType("multipart/form-data; boundary=---------------------------4827543632391"); - request.setProperty("Content-Length", "" + MULTIPART_REQUEST.length()); - MockActionResponse response = new MockActionResponse(); - Map<String, Object> requestMap = new HashMap<String, Object>(); - Map<String, String[]> paramMap = new HashMap<String, String[]>(); - Map<String, Object> sessionMap = new HashMap<String, Object>(); - Map<String, Object> applicationMap = new HashMap<String, Object>(); - initPortletConfig(new HashMap<String, String>(), new HashMap<String, Object>()); - MockPortletConfig config = new MockPortletConfig(ctx); - dispatcher.init(config); - dispatcher.createContextMap(requestMap, paramMap, sessionMap, applicationMap, request, response, config, ACTION_PHASE); - assertNotNull("Caption was not found in parameter map!", paramMap.get("caption")); - assertEquals("TestCaption", paramMap.get("caption")[0]); - } }
