|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
UserAttributeBinding.java | 100% | 100% | 100% | 100% |
|
1 |
// Copyright 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.tapestry.portlet.bindings;
|
|
16 |
|
|
17 |
import java.util.Map;
|
|
18 |
|
|
19 |
import javax.portlet.PortletRequest;
|
|
20 |
|
|
21 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
22 |
import org.apache.hivemind.Location;
|
|
23 |
import org.apache.hivemind.util.Defense;
|
|
24 |
import org.apache.tapestry.binding.AbstractBinding;
|
|
25 |
import org.apache.tapestry.coerce.ValueConverter;
|
|
26 |
|
|
27 |
/**
|
|
28 |
* Allows access to a Portlet user attrbute.
|
|
29 |
*
|
|
30 |
* @author Howard M. Lewis Ship
|
|
31 |
* @since 4.0
|
|
32 |
*/
|
|
33 |
public class UserAttributeBinding extends AbstractBinding |
|
34 |
{ |
|
35 |
private PortletRequest _request;
|
|
36 |
|
|
37 |
private String _attributeName;
|
|
38 |
|
|
39 | 3 |
public UserAttributeBinding(String description, ValueConverter valueConverter,
|
40 |
Location location, PortletRequest request, String attributeName) |
|
41 |
{ |
|
42 | 3 |
super(description, valueConverter, location);
|
43 |
|
|
44 | 3 |
Defense.notNull(request, "request");
|
45 | 3 |
Defense.notNull(attributeName, "attributeName");
|
46 |
|
|
47 | 3 |
_request = request; |
48 | 3 |
_attributeName = attributeName; |
49 |
} |
|
50 |
|
|
51 | 1 |
public boolean isInvariant() |
52 |
{ |
|
53 |
// These can always be changed.
|
|
54 | 1 |
return false; |
55 |
} |
|
56 |
|
|
57 | 3 |
private Map getUserInfo()
|
58 |
{ |
|
59 | 3 |
Map result = (Map) _request.getAttribute(PortletRequest.USER_INFO); |
60 |
|
|
61 | 3 |
if (result == null) |
62 | 1 |
throw new ApplicationRuntimeException(BindingsMessages.noUserInfo(), getLocation(), |
63 |
null);
|
|
64 |
|
|
65 | 2 |
return result;
|
66 |
} |
|
67 |
|
|
68 | 2 |
public Object getObject()
|
69 |
{ |
|
70 | 2 |
return getUserInfo().get(_attributeName);
|
71 |
} |
|
72 |
|
|
73 | 1 |
public void setObject(Object value) |
74 |
{ |
|
75 | 1 |
String asString = (String) getValueConverter().coerceValue(value, String.class);
|
76 |
|
|
77 | 1 |
getUserInfo().put(_attributeName, asString); |
78 |
} |
|
79 |
} |
|
80 |
|
|