public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws IOException, ServletException {
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSSSSS");
fmt.setTimeZone(new SimpleTimeZone(0, ""));
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String loginUrl = userService.createLoginURL("/");
String logoutUrl = userService.createLogoutURL("/");
Entity userPrefs = null;
if (user != null) {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
String cacheKey = "UserPrefs:" + user.getUserId();
userPrefs = (Entity) memcache.get(cacheKey);
if (userPrefs == null) {
log.warning("CACHE MISS");
Key userKey = KeyFactory.createKey("UserPrefs", user.getUserId());
try {
userPrefs = ds.get(userKey);
memcache.put(cacheKey, userPrefs);
} catch (EntityNotFoundException e) {
// No user preferences stored.
}
} else {
log.warning("CACHE HIT");
}
}
if (userPrefs != null) {
int tzOffset = ((Long) userPrefs.getProperty("tz_offset")).intValue();
fmt.setTimeZone(new SimpleTimeZone(tzOffset * 60 * 60 * 1000, ""));
req.setAttribute("tzOffset", tzOffset);
} else {
req.setAttribute("tzOffset", 0);
}