Java tutorial
/* Copyright 2013 Mael Le Guvel This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the COPYING file for more details. */ package fr.mael.microrss.web; import java.util.Locale; import java.util.ResourceBundle; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import fr.mael.microrss.service.UserService; import fr.mael.microrss.util.Tools; @PreAuthorize("isAuthenticated()") @Controller @RequestMapping("/config") public class ConfigController { @Autowired private Config config; @Autowired private UserService userService; @RequestMapping(value = "/", method = RequestMethod.GET) @ResponseBody public Config get(Locale locale) throws Exception { ResourceBundle bundle = ResourceBundle.getBundle("fr.mael.microrss.i18n.messages", locale); Config config = new Config(userService.getUserConfig()); config.setI18n(Tools.convertResourceBundleToMap(bundle)); return config; } @RequestMapping(value = "/{name}/{value}", method = RequestMethod.POST) @ResponseBody public void update(@PathVariable String name, @PathVariable String value) { userService.updateOption(name, value); } }