1 /* vim:set ts=4 sts=4 sw=4 noet fenc=utf-8:
3 Copyright 2009 senju@users.sourceforge.jp
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
18 package jp.sourceforge.rabbitBTS.controllers;
20 import javax.servlet.http.HttpServletRequest;
22 import jp.sourceforge.rabbitBTS.Sht;
23 import jp.sourceforge.rabbitBTS.models.Account;
24 import jp.sourceforge.rabbitBTS.models.BbsPost;
25 import jp.sourceforge.rabbitBTS.services.AccountService;
26 import jp.sourceforge.rabbitBTS.services.BbsService;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Controller;
30 import org.springframework.ui.ModelMap;
31 import org.springframework.validation.BindingResult;
32 import org.springframework.validation.Validator;
33 import org.springframework.web.bind.annotation.RequestMapping;
34 import org.springframework.web.bind.annotation.RequestMethod;
37 public final class BbsController extends BaseController {
39 private Validator validator;
42 private AccountService accountService;
45 private BbsService bbsService;
47 @RequestMapping(method = RequestMethod.GET)
48 public void index(ModelMap model, HttpServletRequest req) {
49 final BbsPost g = new BbsPost();
50 model.addAttribute(g);
51 model.addAttribute("posts", this.bbsService.fetchPosts());
54 @RequestMapping(method = RequestMethod.POST)
55 public String postEdit(BbsPost post, BindingResult result,
56 HttpServletRequest req, ModelMap map) {
57 if (!this.isCsrfSafe(result)) {
61 this.validator.validate(post, result);
62 if (result.hasErrors()) {
63 Sht.log(this).trace("BBS Post Validate fail.");
67 final Account acc = this.accountService.getCurrentAccount();
68 this.bbsService.addNewPost(post, acc);
71 return "redirect:index.html";