Пример #1
0
  /*
   * (non-Javadoc) {@inheritDoc}
   */
  @Override
  public Navigation run() throws Exception {
    Validators v = new Validators(request);
    v.add("startWeek", v.required(), v.integerType(), v.longRange(START_WEEK_MIN, START_WEEK_MAX));
    v.add("keyword", v.maxlength(KEYWORD_MAX_LENGTH));
    if (!v.validate()) {
      response.setStatus(UNAUTHORIZED);
      Errors errors = v.getErrors();
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < errors.size(); i++) {
        sb.append(errors.get(i) + "\n");
      }
      response.setContentType("text/plain;charset=UTF-8");
      response.getWriter().write(new String(sb));
    } else {
      response.setContentType("text/calendar;charset=UTF-8");
      response.setHeader("Content-Disposition", "filename=\"" + ICALENDAR_FILE_NAME + "\"");

      Integer startWeekNum = Integer.parseInt(request.getParameter("startWeek"));
      StartWeek startWeek = StartWeek.parse(startWeekNum);
      String keyword = request.getParameter("keyword");
      String memcacheKey = "startWeek=" + startWeekNum;
      if (keyword != null) {
        memcacheKey += "&keyword=" + URLEncoder.encode(keyword, "UTF-8");
      }
      Object cache = Memcache.get(memcacheKey);
      if (cache == null) {
        CalendarCondition condition = new CalendarCondition();
        if (keyword != null) {
          // 半角スペースで区切られているキーワードは分割して配列にする。
          condition.setKeywords(Arrays.asList(keyword.split(" ")));
        }
        condition.setStartDate(startWeek.toDate());

        Calendar calendar = calendarService.getCalendar(condition);
        response.getWriter().write(calendar.toString());

        // MemcacheにiCalendarの内容をキャッシュする。
        Memcache.put(memcacheKey, calendar.toString());
      } else {
        // キャッシュがある場合はキャッシュの内容を返す。
        response.getWriter().write((String) cache);
      }
    }
    response.flushBuffer();

    return null;
  }
Пример #2
0
  @Override
  public Navigation run() throws Exception {
    Validators validators = new Validators(request);
    EventMeta meta = EventMeta.get();

    validators.add("project", validators.required());
    validators.add(meta.presentation, validators.required());

    if (!validators.validate()) {
      return reportValidationErrors(validators.getErrors());
    }

    Map<String, Object> map = new RequestMap(request);
    map.put("project", asKey("project"));

    eventManager.create(map);
    return forward("../admin.jsp");
  }