1 16 17 package org.springframework.mock.web.portlet; 18 19 import java.util.Map ; 20 import java.util.Set ; 21 22 import javax.portlet.PortalContext; 23 import javax.portlet.PortletResponse; 24 25 import org.springframework.core.CollectionFactory; 26 import org.springframework.util.Assert; 27 28 35 public class MockPortletResponse implements PortletResponse { 36 37 private final PortalContext portalContext; 38 39 private final Map properties = CollectionFactory.createLinkedMapIfPossible(16); 40 41 42 46 public MockPortletResponse() { 47 this(null); 48 } 49 50 55 public MockPortletResponse(PortalContext portalContext) { 56 this.portalContext = (portalContext != null ? portalContext : new MockPortalContext()); 57 } 58 59 63 public PortalContext getPortalContext() { 64 return portalContext; 65 } 66 67 68 72 public void addProperty(String key, String value) { 73 Assert.notNull(key, "Property key must not be null"); 74 String [] oldArr = (String []) this.properties.get(key); 75 if (oldArr != null) { 76 String [] newArr = new String [oldArr.length + 1]; 77 System.arraycopy(oldArr, 0, newArr, 0, oldArr.length); 78 newArr[oldArr.length] = value; 79 this.properties.put(key, newArr); 80 } 81 else { 82 this.properties.put(key, new String [] {value}); 83 } 84 } 85 86 public void setProperty(String key, String value) { 87 Assert.notNull(key, "Property key must not be null"); 88 this.properties.put(key, new String [] {value}); 89 } 90 91 public Set getPropertyNames() { 92 return this.properties.keySet(); 93 } 94 95 public String getProperty(String key) { 96 Assert.notNull(key, "Property key must not be null"); 97 String [] arr = (String []) this.properties.get(key); 98 return (arr != null && arr.length > 0 ? arr[0] : null); 99 } 100 101 public String [] getProperties(String key) { 102 Assert.notNull(key, "Property key must not be null"); 103 return (String []) this.properties.get(key); 104 } 105 106 public String encodeURL(String path) { 107 return path; 108 } 109 110 } 111 | Popular Tags |