|
|||||||||||||||||||
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 | |||||||||||||||
LocalizedPropertySource.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.services.impl;
|
|
16 |
|
|
17 |
import java.util.Locale;
|
|
18 |
|
|
19 |
import org.apache.hivemind.util.Defense;
|
|
20 |
import org.apache.hivemind.util.LocalizedNameGenerator;
|
|
21 |
import org.apache.tapestry.engine.IPropertySource;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* Wraps around a {@link org.apache.tapestry.engine.IPropertySource}to query a series of localized
|
|
25 |
* keys.
|
|
26 |
* <p>
|
|
27 |
* This is much simpler than the old {@link org.apache.tapestry.util.LocalizedPropertySource}, and
|
|
28 |
* allows the locale to be specified on a thread-safe, per-invocation basis.
|
|
29 |
*
|
|
30 |
* @author Howard M. Lewis Ship
|
|
31 |
* @since 4.0
|
|
32 |
*/
|
|
33 |
public class LocalizedPropertySource |
|
34 |
{ |
|
35 |
private IPropertySource _source;
|
|
36 |
|
|
37 | 174 |
public LocalizedPropertySource(IPropertySource source)
|
38 |
{ |
|
39 | 174 |
Defense.notNull(source, "source");
|
40 |
|
|
41 | 174 |
_source = source; |
42 |
} |
|
43 |
|
|
44 |
/**
|
|
45 |
* Get the property from the source, trying different variations of propertyName (adding
|
|
46 |
* suffixes).
|
|
47 |
*
|
|
48 |
* @param propertyName
|
|
49 |
* the base property name to search with.
|
|
50 |
* @param local
|
|
51 |
* the Locale used to generate suffixes (may be null).
|
|
52 |
*/
|
|
53 |
|
|
54 | 231 |
public String getPropertyValue(String propertyName, Locale locale)
|
55 |
{ |
|
56 | 231 |
Defense.notNull(propertyName, "propertyName");
|
57 |
|
|
58 | 231 |
LocalizedNameGenerator g = new LocalizedNameGenerator(propertyName, locale, ""); |
59 |
|
|
60 | 231 |
while (g.more())
|
61 |
{ |
|
62 | 272 |
String localizedName = g.next(); |
63 |
|
|
64 | 272 |
String result = _source.getPropertyValue(localizedName); |
65 |
|
|
66 | 272 |
if (result != null) |
67 | 12 |
return result;
|
68 |
} |
|
69 |
|
|
70 | 219 |
return null; |
71 |
} |
|
72 |
} |
|