KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > portal > generic > PortalURL


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution, if
19  * any, must include the following acknowlegement:
20  * "This product includes software developed by the
21  * Caucho Technology (http://www.caucho.com/)."
22  * Alternately, this acknowlegement may appear in the software itself,
23  * if and wherever such third-party acknowlegements normally appear.
24  *
25  * 4. The names "Hessian", "Resin", and "Caucho" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * info@caucho.com.
29  *
30  * 5. Products derived from this software may not be called "Resin"
31  * nor may "Resin" appear in their names without prior written
32  * permission of Caucho Technology.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
38  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
40  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
44  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  * @author Sam
47  */

48
49
50 package com.caucho.portal.generic;
51
52 import com.caucho.portal.generic.context.ConnectionContext;
53
54 import javax.portlet.PortletMode;
55 import javax.portlet.PortletModeException;
56 import javax.portlet.PortletSecurityException;
57 import javax.portlet.PortletURL;
58 import javax.portlet.WindowState;
59 import javax.portlet.WindowStateException;
60 import java.util.Map JavaDoc;
61
62 public class PortalURL
63   implements PortletURL
64 {
65   private ConnectionContext _context;
66   private InvocationURL _invocationURL;
67
68   private String JavaDoc _url;
69
70   public PortalURL( ConnectionContext context,
71                     InvocationURL invocationURL)
72   {
73     _context = context;
74     _invocationURL = invocationURL;
75   }
76
77   protected void checkWindowState(String JavaDoc namespace, WindowState windowState)
78     throws WindowStateException
79   {
80     if (!_context.isWindowStateAllowed(namespace, windowState))
81       throw new WindowStateException(
82           "WindowState `" + windowState
83           + "' not allowed for namespace `" + namespace + "'",
84           windowState);
85   }
86
87   public void setWindowState(WindowState windowState)
88     throws WindowStateException
89   {
90     _url = null;
91     checkWindowState(_invocationURL.getNamespace(), windowState);
92     _invocationURL.setWindowState(windowState);
93   }
94
95   public void setWindowState(String JavaDoc namespace, WindowState windowState)
96     throws WindowStateException
97   {
98     _url = null;
99     checkWindowState(namespace, windowState);
100     _invocationURL.setWindowState(namespace, windowState);
101   }
102
103   protected void checkPortletMode(String JavaDoc namespace, PortletMode portletMode)
104     throws PortletModeException
105   {
106     if (!_context.isPortletModeAllowed(namespace, portletMode))
107       throw new PortletModeException(
108           "PortletMode `" + portletMode
109           + "' not allowed for namespace `" + namespace + "'",
110           portletMode);
111   }
112
113   public void setPortletMode(PortletMode portletMode)
114     throws PortletModeException
115   {
116     _url = null;
117     checkPortletMode(_invocationURL.getNamespace(), portletMode);
118     _invocationURL.setPortletMode(portletMode);
119   }
120
121   public void setPortletMode(String JavaDoc namespace, PortletMode portletMode)
122     throws PortletModeException
123   {
124     _url = null;
125     checkPortletMode(namespace, portletMode);
126     _invocationURL.setPortletMode(namespace, portletMode);
127   }
128
129   public void setParameters(Map JavaDoc parameters)
130   {
131     _url = null;
132     _invocationURL.setParameters(parameters);
133   }
134
135   public void setParameter(String JavaDoc name, String JavaDoc value)
136   {
137     _url = null;
138     _invocationURL.setParameter(name, value);
139   }
140
141   public void setParameter(String JavaDoc name, String JavaDoc[] values)
142   {
143     _url = null;
144     _invocationURL.setParameter(name, values);
145   }
146
147   public void setParameter(String JavaDoc namespace, String JavaDoc name, String JavaDoc value)
148   {
149     _url = null;
150     _invocationURL.setParameter(namespace, name, value);
151   }
152
153   public void setParameter(String JavaDoc namespace, String JavaDoc name, String JavaDoc[] values)
154   {
155     _url = null;
156     _invocationURL.setParameter(namespace, name, values);
157   }
158
159   public void setParameters(String JavaDoc namespace, Map JavaDoc<String JavaDoc, String JavaDoc[]> parameters)
160   {
161     _url = null;
162     _invocationURL.setParameters(namespace, parameters);
163   }
164
165   public void setSecure(boolean secure)
166     throws PortletSecurityException
167   {
168     _url = null;
169
170     _invocationURL.setSecure(secure);
171
172     if (secure == true)
173       getURL();
174   }
175
176   /**
177    * True if setSecure() was called for this url, even if it was
178    * called with setSecure(false)
179    */

180   protected boolean isSecureSpecified()
181   {
182     return _invocationURL.isSecureSpecified();
183   }
184
185   protected boolean isSecure()
186   {
187     return _invocationURL.isSecure();
188   }
189
190   protected String JavaDoc getURL()
191     throws PortletSecurityException
192   {
193     if (_url != null)
194       return _url;
195
196     String JavaDoc url = _invocationURL.getURL();
197  
198  
199     if (isSecureSpecified())
200       _url = _context.resolveURL(url, isSecure());
201     else
202       _url = _context.resolveURL(url);
203  
204     return _url;
205   }
206  
207   public String JavaDoc toString()
208   {
209     try {
210       return getURL();
211     }
212     catch (PortletSecurityException ex) {
213       throw new RuntimeException JavaDoc(ex);
214     }
215   }
216 }
217
Popular Tags