From a21986aa471739a0e2a3f5b0c4decf02a3d9b60a Mon Sep 17 00:00:00 2001 From: sickboy Date: Mon, 11 Feb 2013 18:29:48 +0900 Subject: [PATCH] userName add --- src/jp/dogrun/ileaflet/controller/AppRouter.java | 13 +++++++------ .../dashboard/DashboardController.java | 16 ++++++++++++++-- .../controller/dashboard/IndexController.java | 13 +++---------- .../controller/dashboard/UploadController.java | 10 +++++----- war/mainFrame.jsp | 11 ++++++++++- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/jp/dogrun/ileaflet/controller/AppRouter.java b/src/jp/dogrun/ileaflet/controller/AppRouter.java index 87be359..b8870c5 100644 --- a/src/jp/dogrun/ileaflet/controller/AppRouter.java +++ b/src/jp/dogrun/ileaflet/controller/AppRouter.java @@ -6,6 +6,7 @@ import jp.dogrun.ileaflet.model.Actor; import org.slim3.controller.router.RouterImpl; +import org.slim3.util.ByteUtil; public class AppRouter extends RouterImpl { @@ -28,14 +29,14 @@ public boolean isStatic(String path) throws NullPointerException { @Override public String route(HttpServletRequest request, String path) { - System.out.println("きとるよー"); - HttpSession session = request.getSession(); if ( session != null ) { - //Actor actor = (Actor)session.getAttribute(Actor.class.getName()); - //if ( actor != null ) { - //request.setAttribute("userName", actor.getName()); - //} + Object actorObj = session.getAttribute(Actor.class.getName()); + if ( actorObj != null ) { + byte[] bytes = ByteUtil.toByteArray(actorObj); + Actor actor = ByteUtil.toObject(bytes, getClass().getClassLoader()); + request.setAttribute("userName", actor.getName()); + } } if ( isFilter(path,"/dashboard") ) return path; diff --git a/src/jp/dogrun/ileaflet/controller/dashboard/DashboardController.java b/src/jp/dogrun/ileaflet/controller/dashboard/DashboardController.java index e60d081..e72f426 100644 --- a/src/jp/dogrun/ileaflet/controller/dashboard/DashboardController.java +++ b/src/jp/dogrun/ileaflet/controller/dashboard/DashboardController.java @@ -1,5 +1,7 @@ package jp.dogrun.ileaflet.controller.dashboard; +import jp.dogrun.ileaflet.model.Actor; + import org.slim3.controller.Controller; import org.slim3.controller.Navigation; @@ -7,8 +9,18 @@ public abstract class DashboardController extends Controller { @Override protected Navigation run() throws Exception { - // TODO Auto-generated method stub - return null; + Actor actor = getActor(); + //ログイン状態を取得 + if ( actor == null ) { + return redirect("../login/"); + } + return process(); + } + + protected abstract Navigation process() throws Exception; + + protected Actor getActor() { + return sessionScope(Actor.class.getName()); } } diff --git a/src/jp/dogrun/ileaflet/controller/dashboard/IndexController.java b/src/jp/dogrun/ileaflet/controller/dashboard/IndexController.java index e2cdf7e..0aed362 100644 --- a/src/jp/dogrun/ileaflet/controller/dashboard/IndexController.java +++ b/src/jp/dogrun/ileaflet/controller/dashboard/IndexController.java @@ -6,25 +6,18 @@ import jp.dogrun.ileaflet.model.Actor; import jp.dogrun.ileaflet.model.Content; -import org.slim3.controller.Controller; import org.slim3.controller.Navigation; -public class IndexController extends Controller { +public class IndexController extends DashboardController { @Override - public Navigation run() throws Exception { + public Navigation process() throws Exception { - Actor actor = sessionScope(Actor.class.getName()); - //ログイン状態を取得 - if ( actor == null ) { - return redirect("../login/"); - } - + Actor actor = getActor(); ContentDao dao = new ContentDao(); List contentList =dao.findByIdentity(actor.getIdentity()); requestScope("contentList",contentList); - return forward("index.jsp"); } } diff --git a/src/jp/dogrun/ileaflet/controller/dashboard/UploadController.java b/src/jp/dogrun/ileaflet/controller/dashboard/UploadController.java index 21c050e..a810bcc 100644 --- a/src/jp/dogrun/ileaflet/controller/dashboard/UploadController.java +++ b/src/jp/dogrun/ileaflet/controller/dashboard/UploadController.java @@ -6,7 +6,6 @@ import jp.dogrun.ileaflet.model.Actor; import jp.dogrun.ileaflet.model.Content; -import org.slim3.controller.Controller; import org.slim3.controller.Navigation; import org.slim3.controller.upload.FileItem; import org.slim3.controller.validator.Validators; @@ -21,10 +20,10 @@ import com.google.appengine.api.files.FileWriteChannel; import com.google.appengine.api.files.GSFileOptions.GSFileOptionsBuilder; -public class UploadController extends Controller { +public class UploadController extends DashboardController { @Override - public Navigation run() throws Exception { + public Navigation process() throws Exception { if ( !validate() ) { return forward("index.jsp"); @@ -34,13 +33,13 @@ public Navigation run() throws Exception { EpubLogic logic = new EpubLogic(); byte[] epubData = fileItem.getData(); - if ( !logic.isCheck(epubData) ) { this.errors.put("errors", ApplicationMessage.get("message.epubCheck",ApplicationMessage.get("label.epubFile"))); //TODO メッセージ return forward("index.jsp"); } - Actor actor = sessionScope(Actor.class.getName()); + + Actor actor = getActor(); //コンテンツデータを設定 Content content = new Content(); @@ -75,6 +74,7 @@ public Navigation run() throws Exception { tx.rollback(); throw ex; } + //TODO アップロードしました。 return redirect("/dashboard/"); } diff --git a/war/mainFrame.jsp b/war/mainFrame.jsp index 021d031..65a7b44 100644 --- a/war/mainFrame.jsp +++ b/war/mainFrame.jsp @@ -28,8 +28,17 @@