Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/BaseResource.java @ 48:41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
artifacts/trunk@168 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 01 Oct 2009 16:03:12 +0000 |
parents | 4ae4dc99127d |
children | 48d1a9a082c2 |
comparison
equal
deleted
inserted
replaced
47:4ae4dc99127d | 48:41c225c8bd41 |
---|---|
1 package de.intevation.artifactdatabase.rest; | 1 package de.intevation.artifactdatabase.rest; |
2 | |
3 import de.intevation.artifacts.CallMeta; | |
4 import de.intevation.artifacts.PreferredLocale; | |
2 | 5 |
3 import org.apache.log4j.Logger; | 6 import org.apache.log4j.Logger; |
4 | 7 |
5 import org.restlet.resource.ServerResource; | 8 import org.restlet.resource.ServerResource; |
6 import org.restlet.resource.ResourceException; | 9 import org.restlet.resource.ResourceException; |
7 | 10 |
8 import org.restlet.representation.Representation; | 11 import org.restlet.representation.Representation; |
12 | |
13 import org.restlet.data.Language; | |
14 import org.restlet.data.ClientInfo; | |
15 import org.restlet.data.Preference; | |
16 | |
17 import java.util.List; | |
18 import java.util.Iterator; | |
19 | |
20 import de.intevation.artifactdatabase.DefaultCallMeta; | |
21 import de.intevation.artifactdatabase.DefaultPreferredLocale; | |
9 | 22 |
10 /** | 23 /** |
11 * @author Sascha L. Teichmann (sascha.teichmann@intevation) | 24 * @author Sascha L. Teichmann (sascha.teichmann@intevation) |
12 */ | 25 */ |
13 public class BaseResource | 26 public class BaseResource |
57 protected Representation innerGet() | 70 protected Representation innerGet() |
58 throws ResourceException | 71 throws ResourceException |
59 { | 72 { |
60 return super.get(); | 73 return super.get(); |
61 } | 74 } |
75 | |
76 protected CallMeta getCallMeta() { | |
77 ClientInfo clientInfo = getClientInfo(); | |
78 | |
79 List<Preference<Language>> pl = clientInfo.getAcceptedLanguages(); | |
80 | |
81 PreferredLocale [] languages = new PreferredLocale[pl.size()]; | |
82 | |
83 int index = 0; | |
84 | |
85 for (Iterator<Preference<Language>> iter = pl.iterator(); iter.hasNext();) { | |
86 Preference p = iter.next(); | |
87 String lang = p.getMetadata().getName(); | |
88 float quality = p.getQuality(); | |
89 languages[index++] = new DefaultPreferredLocale(lang, quality); | |
90 } | |
91 | |
92 return new DefaultCallMeta(languages); | |
93 } | |
62 } | 94 } |
63 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: | 95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |