KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > helper > BasePortletURL


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  * Created on 12 janv. 2004
5  */

6 package org.exoplatform.services.portletcontainer.helper;
7
8 import java.util.Collection JavaDoc;
9 import java.util.Enumeration JavaDoc;
10 import java.util.HashMap JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13 import java.util.Map JavaDoc;
14 import java.util.Set JavaDoc;
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 /**
26  * @author Mestrallet Benjamin
27  * benjmestrallet@users.sourceforge.net
28  */

29 public abstract class BasePortletURL implements PortletURL {
30     
31   private List JavaDoc supports;
32   private String JavaDoc markup;
33   protected Enumeration JavaDoc supportedWindowState;
34   protected List JavaDoc customWindowStates;
35   protected WindowState requiredWindowState;
36   protected PortletMode requiredPortletMode;
37   protected Map JavaDoc parameters = new HashMap JavaDoc();
38   protected boolean isSecure;
39   protected boolean setSecureCalled;
40   protected String JavaDoc type;
41
42   protected boolean isCurrentlySecured;
43
44   public BasePortletURL(String JavaDoc type, String JavaDoc markup,
45                         List JavaDoc supports,
46                         boolean isCurrentlySecured,
47                         List JavaDoc customWindowStates,
48                         Enumeration JavaDoc 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 JavaDoc 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 JavaDoc iterator = supports.iterator(); iterator.hasNext();) {
96       Supports sp = (Supports) iterator.next();
97       if (markup.equals(sp.getMimeType())) {
98         List JavaDoc modeList = sp.getPortletMode();
99         for (Iterator JavaDoc iterator1 = modeList.iterator(); iterator1.hasNext();) {
100           String JavaDoc modeString = (String JavaDoc)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 JavaDoc s, String JavaDoc s1) {
117     if(s == null)
118       throw new IllegalArgumentException JavaDoc("the key given is null");
119     if(s1 == null)
120       throw new IllegalArgumentException JavaDoc("the value given is null");
121     parameters.put(s, s1);
122   }
123
124   public void setParameter(String JavaDoc s, String JavaDoc[] strings) {
125     if(s == null) throw new IllegalArgumentException JavaDoc("the key given is null");
126     if(strings == null) throw new IllegalArgumentException JavaDoc("the value given is null");
127     parameters.put(s, strings);
128   }
129
130   public void setParameters(Map JavaDoc map) {
131     if(map == null)
132       throw new IllegalArgumentException JavaDoc("the map given is null");
133     if(map.containsKey(null))
134       throw new IllegalArgumentException JavaDoc("the map given contains a null key");
135     Set JavaDoc keys = map.keySet();
136     for (Iterator JavaDoc iter = keys.iterator(); iter.hasNext();) {
137       if(! (iter.next() instanceof String JavaDoc ))
138         throw new IllegalArgumentException JavaDoc("the map contains a non String key");
139     }
140     Collection JavaDoc values = map.values();
141     for (Iterator JavaDoc iter = values.iterator(); iter.hasNext();) {
142       if(! (iter.next() instanceof String JavaDoc[] ))
143         throw new IllegalArgumentException JavaDoc("the map contains a non String[] value");
144     }
145     parameters = map;
146   }
147
148   public Object JavaDoc getParameter(String JavaDoc 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 JavaDoc toString();
159 }
Popular Tags