sascha@40: package de.intevation.artifactdatabase.rest; sascha@40: sascha@48: import de.intevation.artifacts.CallMeta; sascha@48: import de.intevation.artifacts.PreferredLocale; sascha@48: sascha@40: import org.apache.log4j.Logger; sascha@40: sascha@40: import org.restlet.resource.ServerResource; sascha@40: import org.restlet.resource.ResourceException; sascha@40: sascha@40: import org.restlet.representation.Representation; sascha@40: sascha@48: import org.restlet.data.Language; sascha@48: import org.restlet.data.ClientInfo; sascha@48: import org.restlet.data.Preference; sascha@48: sascha@48: import java.util.List; sascha@48: import java.util.Iterator; sascha@48: sascha@48: import de.intevation.artifactdatabase.DefaultCallMeta; sascha@48: import de.intevation.artifactdatabase.DefaultPreferredLocale; sascha@48: sascha@40: /** sascha@77: * @author Sascha L. Teichmann sascha@40: */ sascha@40: public class BaseResource sascha@40: extends ServerResource sascha@40: { sascha@40: private static Logger logger = Logger.getLogger(BaseResource.class); sascha@40: sascha@40: public BaseResource() { sascha@40: } sascha@40: sascha@40: protected Representation post(Representation requestRepr) sascha@40: throws ResourceException sascha@40: { sascha@40: try { sascha@40: return innerPost(requestRepr); sascha@40: } sascha@40: catch (ResourceException re) { sascha@40: throw re; sascha@40: } sascha@40: catch (RuntimeException re) { sascha@40: logger.error(re.getLocalizedMessage(), re); sascha@40: throw re; sascha@40: } sascha@40: } sascha@40: sascha@40: protected Representation innerPost(Representation requestRepr) sascha@40: throws ResourceException sascha@40: { sascha@40: return super.post(requestRepr); sascha@40: } sascha@40: sascha@47: protected Representation get() sascha@40: throws ResourceException sascha@40: { sascha@40: try { sascha@40: return innerGet(); sascha@40: } sascha@40: catch (ResourceException re) { sascha@40: throw re; sascha@40: } sascha@40: catch (RuntimeException re) { sascha@40: logger.error(re.getLocalizedMessage(), re); sascha@40: throw re; sascha@40: } sascha@40: } sascha@40: sascha@40: protected Representation innerGet() sascha@40: throws ResourceException sascha@40: { sascha@40: return super.get(); sascha@40: } sascha@48: sascha@48: protected CallMeta getCallMeta() { sascha@48: ClientInfo clientInfo = getClientInfo(); sascha@48: sascha@48: List> pl = clientInfo.getAcceptedLanguages(); sascha@48: sascha@48: PreferredLocale [] languages = new PreferredLocale[pl.size()]; sascha@48: sascha@48: int index = 0; sascha@48: sascha@48: for (Iterator> iter = pl.iterator(); iter.hasNext();) { sascha@48: Preference p = iter.next(); sascha@48: String lang = p.getMetadata().getName(); sascha@48: float quality = p.getQuality(); sascha@48: languages[index++] = new DefaultPreferredLocale(lang, quality); sascha@48: } sascha@48: sascha@48: return new DefaultCallMeta(languages); sascha@48: } sascha@40: } sascha@40: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: