1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package org.apache.pluto.portalImpl.om.window.impl;
35
36 import org.apache.pluto.om.common.ObjectID;
37 import org.apache.pluto.om.entity.PortletEntity;
38 import org.apache.pluto.om.window.PortletWindow;
39 import org.apache.pluto.om.window.PortletWindowCtrl;
40 import org.apache.pluto.portalImpl.services.log.Log;
41
42 import java.util.Collections;
43 import java.util.HashMap;
44 import java.util.Iterator;
45 import java.util.Map;
46
47 import javax.portlet.PortletMode;
48 import javax.portlet.WindowState;
49
50
51
52 public class PortletWindowImpl implements PortletWindow, PortletWindowCtrl
53 {
54 private ObjectID _objectId;
55 private String _id;
56 private PortletEntity _portletEntity;
57 final private Map _renderParameters;
58 private WindowState _windowState;
59 private PortletMode _portletMode;
60 final private Map _prevRenderParameters;
61 private WindowState _prevWindowState;
62 private PortletMode _prevPortletMode;
63
64 public PortletWindowImpl( final String id )
65 {
66 _renderParameters = new HashMap( );
67 _prevRenderParameters = new HashMap( );
68 _id = id;
69 _portletMode = PortletMode.VIEW;
70 _prevPortletMode = PortletMode.VIEW;
71 _windowState = WindowState.NORMAL;
72 _prevWindowState = WindowState.NORMAL;
73 }
74
75 public Map getRenderParameters( )
76 {
77 return Collections.unmodifiableMap( _renderParameters );
78 }
79
80 public String getParameter( final String paramName )
81 {
82 final String[] values = (String[]) _renderParameters.get( paramName );
83
84 if ( values != null )
85 {
86 return values[0];
87 }
88
89 return null;
90 }
91
92 public String[] getParameterValues( final String paramName )
93 {
94 final String[] values = (String[]) _renderParameters.get( paramName );
95
96 return values;
97 }
98
99 synchronized public void setRenderParameter( final Map parameters )
100 {
101 if ( parameters == null )
102 {
103 throw new IllegalArgumentException( "Parameter 'parameters' can't be null." );
104 }
105
106 Log.debug(
107 "portlet " + _id + " old render params " + _renderParameters.size( ) + " / " + _renderParameters );
108 Log.debug(
109 "portlet " + _id + " new render params " + parameters.size( ) + " / " + parameters );
110
111 _renderParameters.clear( );
112
113 final Iterator itEntries = parameters.entrySet( ).iterator( );
114
115 while ( itEntries.hasNext( ) )
116 {
117 final Map.Entry entry = (Map.Entry) itEntries.next( );
118 final Object name = entry.getKey( );
119 final Object value = entry.getValue( );
120
121 if ( !( name instanceof String ) )
122 {
123 throw new IllegalArgumentException( "Key name must be a String (key '" + name + "' (" +
124 name.getClass( ).getName( ) + "))." );
125 }
126
127 if ( value instanceof String )
128 {
129 _renderParameters.put( name, new String[] { (String) value } );
130 }
131 else if ( value instanceof String[] )
132 {
133 _renderParameters.put( name, value );
134 }
135 else
136 {
137 throw new IllegalArgumentException(
138 "Values must be a String or String[] type String ou String[] (key '" + name + "' value is " +
139 value.getClass( ).getName( ) + ")." );
140 }
141 }
142 }
143
144 public void setPortletMode( final PortletMode portletMode )
145 {
146 if ( _portletMode != null )
147 {
148 _portletMode = portletMode;
149 }
150 else
151 {
152 _portletMode = PortletMode.VIEW;
153 }
154 }
155
156 public PortletMode getPortletMode( )
157 {
158 return _portletMode;
159 }
160
161 public void setWindowState( final WindowState windowState )
162 {
163 if ( windowState != null )
164 {
165 _windowState = windowState;
166 }
167 else
168 {
169 _windowState = WindowState.NORMAL;
170 }
171 }
172
173 public WindowState getWindowState( )
174 {
175 return _windowState;
176 }
177
178
179
180
181
182
183
184
185 public ObjectID getId( )
186 {
187 if ( _objectId == null )
188 {
189 _objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString( _id );
190 }
191
192 return _objectId;
193 }
194
195
196
197
198
199
200 public PortletEntity getPortletEntity( )
201 {
202 return _portletEntity;
203 }
204
205
206
207
208
209
210
211 public void setId( String id )
212 {
213 _id = id;
214 _objectId = null;
215 }
216
217
218
219
220
221
222 public void setPortletEntity( PortletEntity portletEntity )
223 {
224 _portletEntity = portletEntity;
225 }
226
227 public void saveValues( )
228 {
229 _prevPortletMode = _portletMode;
230 _prevWindowState = _windowState;
231 _prevRenderParameters.clear( );
232 _prevRenderParameters.putAll( _renderParameters );
233 }
234
235 public void restoreValues( )
236 {
237 _portletMode = _prevPortletMode;
238 _windowState = _prevWindowState;
239 _renderParameters.clear( );
240 _renderParameters.putAll( _prevRenderParameters );
241 }
242
243
244
245
246
247
248 public PortletMode getPrevPortletMode( )
249 {
250 return _prevPortletMode;
251 }
252
253
254
255
256
257
258 public WindowState getPrevWindowState( )
259 {
260 return _prevWindowState;
261 }
262 }