1 6 package org.exoplatform.services.portletcontainer.helper; 7 8 import java.util.Collection ; 9 import java.util.Enumeration ; 10 import java.util.HashMap ; 11 import java.util.Iterator ; 12 import java.util.List ; 13 import java.util.Map ; 14 import java.util.Set ; 15 16 import javax.portlet.PortletMode; 17 import javax.portlet.PortletModeException; 18 import javax.portlet.PortletSecurityException; 19 import javax.portlet.PortletURL; 20 import javax.portlet.WindowState; 21 import javax.portlet.WindowStateException; 22 import org.exoplatform.services.portletcontainer.pci.model.*; 23 24 25 29 public abstract class BasePortletURL implements PortletURL { 30 31 private List supports; 32 private String markup; 33 protected Enumeration supportedWindowState; 34 protected List customWindowStates; 35 protected WindowState requiredWindowState; 36 protected PortletMode requiredPortletMode; 37 protected Map parameters = new HashMap (); 38 protected boolean isSecure; 39 protected boolean setSecureCalled; 40 protected String type; 41 42 protected boolean isCurrentlySecured; 43 44 public BasePortletURL(String type, String markup, 45 List supports, 46 boolean isCurrentlySecured, 47 List customWindowStates, 48 Enumeration supportedWindowState) { 49 this.type = type; 50 this.markup = markup; 51 this.supports = supports; 52 this.isCurrentlySecured = isCurrentlySecured; 53 this.customWindowStates = customWindowStates; 54 this.supportedWindowState = supportedWindowState; 55 } 56 57 public void setWindowState(WindowState windowState) 58 throws WindowStateException { 59 if(windowState == null){ 60 throw new WindowStateException("The portlet mode is null", windowState); 61 } 62 if (windowState == WindowState.NORMAL || windowState == WindowState.MINIMIZED || 63 windowState == WindowState.MAXIMIZED) { 64 requiredWindowState = windowState; 65 return; 66 } 67 68 while (supportedWindowState.hasMoreElements()) { 69 WindowState state = (WindowState) supportedWindowState.nextElement(); 70 if (state.toString().equals(windowState.toString())) { 71 for (Iterator iter = customWindowStates.iterator(); iter.hasNext();) { 72 CustomWindowState customState = (CustomWindowState) iter.next(); 73 if(customState.getWindowState().equals(windowState.toString())){ 74 requiredWindowState = windowState; 75 return; 76 } 77 } 78 } 79 } 80 throw new WindowStateException("The window state " + windowState.toString() + " is not supported by the portlet container", 81 windowState); 82 } 83 84 public void setPortletMode(PortletMode portletMode) throws PortletModeException { 85 86 if(portletMode == null) 87 throw new PortletModeException("The portlet mode is null", portletMode); 88 89 if (portletMode == PortletMode.VIEW) { 90 requiredPortletMode = portletMode; 91 return; 92 } 93 94 boolean supported = false; 95 for (Iterator iterator = supports.iterator(); iterator.hasNext();) { 96 Supports sp = (Supports) iterator.next(); 97 if (markup.equals(sp.getMimeType())) { 98 List modeList = sp.getPortletMode(); 99 for (Iterator iterator1 = modeList.iterator(); iterator1.hasNext();) { 100 String modeString = (String )iterator1.next(); 101 if (modeString != null && modeString.equalsIgnoreCase(portletMode.toString())) { 102 supported = true; 103 break; 104 } 105 } 106 break; 107 } 108 } 109 if (!supported) 110 throw new PortletModeException("The mode " + portletMode.toString() + " is not supported by that portlet", 111 portletMode); 112 113 requiredPortletMode = portletMode; 114 } 115 116 public void setParameter(String s, String s1) { 117 if(s == null) 118 throw new IllegalArgumentException ("the key given is null"); 119 if(s1 == null) 120 throw new IllegalArgumentException ("the value given is null"); 121 parameters.put(s, s1); 122 } 123 124 public void setParameter(String s, String [] strings) { 125 if(s == null) throw new IllegalArgumentException ("the key given is null"); 126 if(strings == null) throw new IllegalArgumentException ("the value given is null"); 127 parameters.put(s, strings); 128 } 129 130 public void setParameters(Map map) { 131 if(map == null) 132 throw new IllegalArgumentException ("the map given is null"); 133 if(map.containsKey(null)) 134 throw new IllegalArgumentException ("the map given contains a null key"); 135 Set keys = map.keySet(); 136 for (Iterator iter = keys.iterator(); iter.hasNext();) { 137 if(! (iter.next() instanceof String )) 138 throw new IllegalArgumentException ("the map contains a non String key"); 139 } 140 Collection values = map.values(); 141 for (Iterator iter = values.iterator(); iter.hasNext();) { 142 if(! (iter.next() instanceof String [] )) 143 throw new IllegalArgumentException ("the map contains a non String[] value"); 144 } 145 parameters = map; 146 } 147 148 public Object getParameter(String key) { 149 return parameters.get(key); 150 } 151 152 public void setSecure(boolean b) 153 throws PortletSecurityException { 154 isSecure = b; 155 setSecureCalled = true; 156 } 157 158 public abstract String toString(); 159 } | Popular Tags |