Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCallMeta.java @ 92:73d0ebae81d7
Last bunch of javadoc
artifacts/trunk@848 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 28 Mar 2010 14:16:05 +0000 |
parents | 730ff077a58c |
children | e27cf9c84eb8 |
rev | line source |
---|---|
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.artifactdatabase; |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
49
823850c63d95
Convenience method in call meta to get preferred language.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
3 import java.util.Locale; |
823850c63d95
Convenience method in call meta to get preferred language.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
4 |
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import de.intevation.artifacts.CallMeta; |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import de.intevation.artifacts.PreferredLocale; |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 /** |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
9 * Default implementation of CallMeta. It provides a list of |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
10 * preferred langauages and implements an intersection mechanism |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
11 * to figure out the best matching language given a list of server |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
12 * provided languages. |
77
48d1a9a082c2
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
51
diff
changeset
|
13 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 */ |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public class DefaultCallMeta |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 implements CallMeta |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 { |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
18 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
19 * The list of preferred languages. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
20 */ |
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 protected PreferredLocale [] languages; |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
23 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
24 * Default constructor. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
25 */ |
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 public DefaultCallMeta() { |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 } |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
29 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
30 * Creates new DefaultCallMeta with a given list of languages. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
31 * @param languages The list of preferred languages. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
32 */ |
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 public DefaultCallMeta(PreferredLocale [] languages) { |
51
3a668da76463
Fixed problem with non-initialized languages in call meta.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
50
diff
changeset
|
34 this.languages = languages; |
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 public PreferredLocale [] getLanguages() { |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 return languages; |
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 } |
49
823850c63d95
Convenience method in call meta to get preferred language.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
40 |
823850c63d95
Convenience method in call meta to get preferred language.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
41 public Locale getPreferredLocale(Locale [] locales) { |
823850c63d95
Convenience method in call meta to get preferred language.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
42 if (locales == null || locales.length == 0) { |
823850c63d95
Convenience method in call meta to get preferred language.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
43 return null; |
823850c63d95
Convenience method in call meta to get preferred language.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
44 } |
823850c63d95
Convenience method in call meta to get preferred language.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
45 |
50
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
46 Locale best = null; |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
47 float quality = -Float.MAX_VALUE; |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
48 |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
49 for (int i = 0; i < locales.length; ++i) { |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
50 Locale wish = locales[i]; |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
51 String wishLanguage = wish.getLanguage(); |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
52 |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
53 for (int j = 0; j < languages.length; ++j) { |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
54 PreferredLocale have = languages[j]; |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
55 Locale haveLocale = have.getLocale(); |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
56 if (haveLocale.getLanguage().equals(wishLanguage)) { |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
57 float haveQuality = have.getQuality(); |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
58 if (haveQuality > quality) { |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
59 quality = haveQuality; |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
60 best = wish; |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
61 } |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
62 break; // Languages should not contain |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
63 // same locale twice. |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
64 } |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
65 } |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
66 } |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
67 |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
68 return best == null |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
69 ? locales[0] |
0b04fa8a19c6
Better implementation for fetching the preferred locale via meta of call context.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
49
diff
changeset
|
70 : best; |
49
823850c63d95
Convenience method in call meta to get preferred language.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
71 } |
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 } |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
87
diff
changeset
|
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |