1 package org.unitedfront2.web.controller.profile; 2 3 import java.util.Date; 4 import java.util.List; 5 6 import org.apache.tiles.Attribute; 7 import org.apache.tiles.AttributeContext; 8 import org.apache.tiles.context.TilesRequestContext; 9 import org.apache.tiles.preparer.PreparerException; 10 import org.apache.tiles.preparer.ViewPreparer; 11 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.stereotype.Repository; 13 import org.unitedfront2.domain.SimpleUser; 14 import org.unitedfront2.domain.communication.ProfileTable; 15 16 /** 17 * プロフィールウィジェット用のビュープリペアラークラスです。 18 * 19 * @author kurokkie 20 * 21 */ 22 @Repository(value = "profile.publicProfileWidgetPreparer") 23 public class PublicProfileWidgetPreparer implements ViewPreparer { 24 25 /** ユーザリストが更新される間隔 (15分) */ 26 public static final int REFLESH_TERM = 60 * 15 * 1000; 27 28 /** 最大表示件数 (15) */ 29 public static final int MAX = 10; 30 31 /** 前回更新した日時 */ 32 private Date lastRefleshDate; 33 34 /** ユーザリストのキャッシュ */ 35 private List<SimpleUser> cache; 36 37 /** プロフィールテーブル */ 38 @Autowired private ProfileTable profileTable; 39 40 @Override 41 public void execute(TilesRequestContext tilesContext, 42 AttributeContext attributeContext) throws PreparerException { 43 attributeContext.putAttribute("users", new Attribute(getUsers())); 44 } 45 46 private List<SimpleUser> getUsers() { 47 if (cache == null 48 || new Date().after(new Date(lastRefleshDate.getTime() 49 + REFLESH_TERM))) { 50 cache = profileTable.getPublicProfileOwnersRandomly(MAX); 51 lastRefleshDate = new Date(); 52 } 53 return cache; 54 } 55 }