KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > widget > PortletWidgetURL


1 /*
2  * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Sam
27  */

28
29
30 package com.caucho.widget;
31
32 import com.caucho.util.L10N;
33
34 import javax.portlet.*;
35 import java.util.LinkedHashMap JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38
39 public class PortletWidgetURL
40   extends WidgetURL
41 {
42   private static L10N L = new L10N( PortletWidgetURL.class );
43
44   static protected final Logger JavaDoc log =
45     Logger.getLogger( PortletWidgetURL.class.getName() );
46
47   private PortletWidgetConnection _connection;
48
49   private Map JavaDoc<String JavaDoc,String JavaDoc[]> _parameterMap;
50   private PortletMode _portletMode;
51   private WindowState _windowState;
52   private Boolean JavaDoc _isSecure;
53   private boolean _isAction;
54
55   private PortletURL _portletURL;
56   private String JavaDoc _url;
57
58   public PortletWidgetURL( PortletWidgetConnection connection )
59   {
60     _connection = connection;
61
62   }
63
64   public void setParameter( String JavaDoc name, String JavaDoc value )
65   {
66     String JavaDoc[] values = new String JavaDoc[] { value };
67
68     setParameter( name, values );
69   }
70
71   public void setParameter( String JavaDoc name, String JavaDoc[] values )
72   {
73     if ( _parameterMap == null )
74       _parameterMap = new LinkedHashMap JavaDoc<String JavaDoc,String JavaDoc[]>();
75
76     _parameterMap.put( name, values );
77
78     _url = null;
79
80     if ( _portletURL != null )
81       _portletURL.setParameter( name, values );
82   }
83
84   public void setParameters( Map JavaDoc<String JavaDoc,String JavaDoc[]> parameters )
85   {
86     if ( _parameterMap == null )
87       _parameterMap = new LinkedHashMap JavaDoc<String JavaDoc, String JavaDoc[]>();
88     else
89       _parameterMap.clear();
90
91     _url = null;
92
93     _parameterMap.putAll( parameters );
94
95     if ( _portletURL != null )
96       _portletURL.setParameters( parameters );
97   }
98
99   public void setPortletMode( PortletMode portletMode )
100     throws PortletModeException
101   {
102     if ( portletMode.equals( _portletMode ) )
103       return;
104
105     _portletMode = portletMode;
106
107     _url = null;
108
109     if ( _portletURL != null )
110       _portletURL.setPortletMode( portletMode );
111   }
112
113   public void setWindowState( WindowState windowState )
114     throws WindowStateException
115   {
116     if ( windowState.equals( _windowState ) )
117       return;
118
119     _windowState = windowState;
120
121     _url = null;
122
123     if ( _portletURL != null )
124       _portletURL.setWindowState( windowState );
125   }
126
127   public void setSecure( boolean secure )
128   {
129     if ( _isSecure != null && _isSecure.booleanValue() == secure )
130       return;
131
132     _isSecure = secure ? Boolean.TRUE : Boolean.FALSE;
133
134     _url = null;
135
136     if ( _portletURL != null ) {
137       try {
138         _portletURL.setSecure( secure );
139       }
140       catch ( PortletException ex ) {
141         throw new RuntimeException JavaDoc( ex );
142       }
143     }
144   }
145
146   public void setAction( boolean isAction )
147   {
148     if ( isAction != _isAction) {
149       _url = null;
150       _portletURL = null;
151
152       _isAction = isAction;
153     }
154   }
155
156   public String JavaDoc toString()
157   {
158     if ( _url != null )
159       return _url;
160
161     if ( _portletURL != null )
162       return _portletURL.toString();
163
164     try {
165       RenderResponse response = _connection.getRenderResponse();
166
167       _portletURL = _isAction ? response.createActionURL()
168         : response.createRenderURL();
169
170       if ( _windowState != null )
171         _portletURL.setWindowState( _windowState );
172       if ( _portletMode != null )
173         _portletURL.setPortletMode( _portletMode );
174
175       if ( _isSecure != null )
176         _portletURL.setSecure( _isSecure.booleanValue() );
177
178       if ( _parameterMap != null ) {
179         for ( Map.Entry JavaDoc<String JavaDoc,String JavaDoc[]> entry : _parameterMap.entrySet() ) {
180           _portletURL.setParameter( entry.getKey(), entry.getValue() );
181         }
182       }
183     }
184     catch ( PortletException ex ) {
185       throw new RuntimeException JavaDoc( ex );
186     }
187
188       _url = _portletURL.toString();
189
190       return _url;
191     }
192   }
193
Popular Tags