Mercurial > dive4elements > framework
view artifact-database/src/main/java/de/intevation/artifactdatabase/rest/BaseResource.java @ 59:8cd770330f1b
Added path to chart template and added a method to retrieve its configuration.
artifacts/trunk@361 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 23 Nov 2009 16:56:47 +0000 |
parents | 41c225c8bd41 |
children | 48d1a9a082c2 |
line wrap: on
line source
package de.intevation.artifactdatabase.rest; import de.intevation.artifacts.CallMeta; import de.intevation.artifacts.PreferredLocale; import org.apache.log4j.Logger; import org.restlet.resource.ServerResource; import org.restlet.resource.ResourceException; import org.restlet.representation.Representation; import org.restlet.data.Language; import org.restlet.data.ClientInfo; import org.restlet.data.Preference; import java.util.List; import java.util.Iterator; import de.intevation.artifactdatabase.DefaultCallMeta; import de.intevation.artifactdatabase.DefaultPreferredLocale; /** * @author Sascha L. Teichmann (sascha.teichmann@intevation) */ public class BaseResource extends ServerResource { private static Logger logger = Logger.getLogger(BaseResource.class); public BaseResource() { } protected Representation post(Representation requestRepr) throws ResourceException { try { return innerPost(requestRepr); } catch (ResourceException re) { throw re; } catch (RuntimeException re) { logger.error(re.getLocalizedMessage(), re); throw re; } } protected Representation innerPost(Representation requestRepr) throws ResourceException { return super.post(requestRepr); } protected Representation get() throws ResourceException { try { return innerGet(); } catch (ResourceException re) { throw re; } catch (RuntimeException re) { logger.error(re.getLocalizedMessage(), re); throw re; } } protected Representation innerGet() throws ResourceException { return super.get(); } protected CallMeta getCallMeta() { ClientInfo clientInfo = getClientInfo(); List<Preference<Language>> pl = clientInfo.getAcceptedLanguages(); PreferredLocale [] languages = new PreferredLocale[pl.size()]; int index = 0; for (Iterator<Preference<Language>> iter = pl.iterator(); iter.hasNext();) { Preference p = iter.next(); String lang = p.getMetadata().getName(); float quality = p.getQuality(); languages[index++] = new DefaultPreferredLocale(lang, quality); } return new DefaultCallMeta(languages); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: