コード例 #1
0
  private String getFeedByEvents(String extraURI, RSSRequest rssRequest) {
    IWContext iwc = getIWContext(rssRequest);
    String uri = extraURI.substring("group/".length(), extraURI.length());
    String feedFile =
        "events_" + getTypesString(uri) + getPeriod(uri) + iwc.getLocale().getLanguage() + ".xml";

    if (rssFileURIsCacheList.contains(feedFile)) return feedFile;
    String events = extraURI.substring("events/".length());
    String eventsPeriod = null;
    List eventsList = new ArrayList();
    int index = -1;
    String title = "";
    if (events.indexOf("+") == -1) {
      eventsList.add(events.substring(0, events.indexOf("/")));
      events = events.substring(events.indexOf("/") + 1, events.length());
    } else {
      while (true) {
        index = events.indexOf("+");
        if (index == -1) {
          index = events.indexOf("/");
          eventsList.add(events.substring(0, index));
          events = events.substring(index + 1, events.length());
          title = title + events.substring(0, index);
          break;
        } else {
          title = title + events.substring(0, index) + ", ";
          eventsList.add(events.substring(0, index));
          events = events.substring(index + 1, events.length());
        }
      }
    }

    eventsPeriod = events;
    Timestamp from = null;
    Timestamp to = null;
    CalBusiness calendar = new CalBusinessBean();
    List entries = null;
    if (eventsPeriod.length() != 0) {
      String fromStr = eventsPeriod.substring(0, DATE_LENGTH);
      String toStr = eventsPeriod.substring(DATE_LENGTH + 1, eventsPeriod.length() - 1);
      from = getTimeStampFromString(fromStr);
      to = getTimeStampFromString(toStr);
      Collection coll = calendar.getEntriesBetweenTimestamps(from, to);
      entries = new ArrayList();
      title = title + fromStr + "-" + toStr;
      for (Iterator iter = coll.iterator(); iter.hasNext(); ) {
        CalendarEntry element = (CalendarEntry) iter.next();
        if (eventsList.contains(element.getEntryTypeName())) {
          entries.add(element);
        }
      }
    } else entries = new ArrayList(calendar.getEntriesByEvents(eventsList));

    if (entries.isEmpty())
      return getFeed(NO_ENTRIES_FOUND_TITLE, NO_ENTRIES_FOUND_FILE, null, rssRequest, iwc);
    else {
      return getFeed(title, feedFile, entries, rssRequest, iwc);
    }
  }
コード例 #2
0
  @Override
  public void handleRSSRequest(RSSRequest rssRequest) throws IOException {
    String feedParentFolder = null;
    String feedFile = null;
    String category = getCategory(rssRequest.getExtraUri());
    String extraURI = rssRequest.getExtraUri();
    if (extraURI == null) {
      extraURI = CoreConstants.EMPTY;
    }
    if ((!extraURI.endsWith(CoreConstants.SLASH)) && (extraURI.length() != 0)) {
      extraURI = extraURI.concat(CoreConstants.SLASH);
    }

    List<String> categories = new ArrayList<String>();
    List<String> articles = new ArrayList<String>();
    if (category != null) categories.add(category);

    IWContext iwc = getIWContext(rssRequest);
    String language = iwc.getLocale().getLanguage();

    if (StringUtil.isEmpty(extraURI)) {
      feedParentFolder = ARTICLE_RSS;
      feedFile = "all_".concat(language).concat(".xml");
    } else if (category != null) {
      feedParentFolder =
          ARTICLE_RSS.concat("category/").concat(category).concat(CoreConstants.SLASH);
      feedFile = "feed_.".concat(language).concat(".xml");
    } else {
      //	Have page URI
      feedParentFolder = ARTICLE_RSS.concat("page/").concat(extraURI);
      feedFile = "feed_".concat(language).concat(".xml");
      categories = getCategoriesByURI(extraURI, iwc);
      if (ListUtil.isEmpty(categories)) {
        articles = getArticlesByURI(extraURI, iwc);
      }
    }

    String realURI = CoreConstants.WEBDAV_SERVLET_URI + feedParentFolder + feedFile;
    if (rssFileURIsCacheList.contains(feedFile)) {
      try {
        this.dispatch(realURI, rssRequest);
      } catch (ServletException e) {
        LOGGER.log(Level.WARNING, "Error dispatching: " + realURI, e);
      }
    } else {
      //	Generate RSS and store and the dispatch to it and add a listener to that directory
      try {
        // todo code the 3 different cases (see description)
        searchForArticles(rssRequest, feedParentFolder, feedFile, categories, articles, extraURI);
        rssFileURIsCacheList.add(feedFile);

        this.dispatch(realURI, rssRequest);
      } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error while searching or dispatching: " + realURI, e);
        throw new IOException(e.getMessage());
      }
    }
  }
コード例 #3
0
  private String getFeedByLedger(String extraURI, RSSRequest rssRequest) {
    IWContext iwc = getIWContext(rssRequest);
    //		String feedFile = "ledger_"+extraURI.substring("ledger/".length(),
    // extraURI.length()-1)+"_"+iwc.getLocale().getLanguage()+".xml";
    String uri = extraURI.substring("ledger/".length(), extraURI.length());
    String feedFile =
        "ledger_" + getName(uri) + getPeriod(uri) + "_" + iwc.getLocale().getLanguage() + ".xml";
    if (rssFileURIsCacheList.contains(feedFile)) return PATH_TO_FEED_PARENT_FOLDER + feedFile;
    String ledger = extraURI.substring("ledger/".length());
    String ledgerID = ledger.substring(0, ledger.indexOf("/"));
    String ledgerPeriod = ledger.substring(ledgerID.length() + 1, ledger.length());
    Timestamp from = null;
    Timestamp to = null;
    CalBusiness calendar = new CalBusinessBean();
    int ledgerIdInt;
    List entries = null;
    try {
      ledgerIdInt = Integer.parseInt(ledgerID);
    } catch (NumberFormatException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return getFeed(
          INCORRECT_URI_TITLE, INCORRECT_URI_FILE, null, rssRequest, getIWContext(rssRequest));
    }

    LedgerVariationsHandler ledgerVariationsHandler = new DefaultLedgerVariationsHandler();
    String title =
        ((DefaultLedgerVariationsHandler) ledgerVariationsHandler)
            .getCalBusiness(iwc)
            .getLedger(Integer.parseInt(ledgerID))
            .getName();

    if (ledgerPeriod.length() != 0) {
      String fromStr = ledgerPeriod.substring(0, DATE_LENGTH);
      String toStr = ledgerPeriod.substring(DATE_LENGTH + 1, ledgerPeriod.length() - 1);
      from = getTimeStampFromString(fromStr);
      to = getTimeStampFromString(toStr);
      if (to.before(from))
        return getFeed(INCORRECT_PERIOD_TITLE, INCORRECT_PERIOD_FILE, null, rssRequest, iwc);
      title = title + " " + fromStr + "-" + toStr;
      Collection coll = calendar.getEntriesBetweenTimestamps(from, to);
      entries = new ArrayList();
      for (Iterator iter = coll.iterator(); iter.hasNext(); ) {
        CalendarEntry element = (CalendarEntry) iter.next();
        if (element.getLedgerID() == ledgerIdInt) {
          entries.add(element);
        }
      }
    } else entries = new ArrayList(calendar.getEntriesByLedgerID(ledgerIdInt));
    if (entries.isEmpty())
      return getFeed(NO_ENTRIES_FOUND_TITLE, NO_ENTRIES_FOUND_FILE, null, rssRequest, iwc);
    else {

      return getFeed(title, feedFile, entries, rssRequest, iwc);
    }
  }
コード例 #4
0
  private String getFeedByPeriod(String extraURI, RSSRequest rssRequest) {
    IWContext iwc = getIWContext(rssRequest);
    String uri = extraURI.substring("period/".length(), extraURI.length());
    String feedFile = "period_" + getName(uri) + iwc.getLocale().getLanguage() + ".xml";

    if (rssFileURIsCacheList.contains(feedFile)) return PATH_TO_FEED_PARENT_FOLDER + feedFile;

    String period = extraURI.substring("period/".length());
    String fromStr = period.substring(0, DATE_LENGTH);
    String toStr = period.substring(DATE_LENGTH + 1, period.length() - 1);
    Timestamp fromTmst = getTimeStampFromString(fromStr);
    Timestamp toTmst = getTimeStampFromString(toStr);

    if (toTmst.before(fromTmst))
      return getFeed(INCORRECT_PERIOD_TITLE, INCORRECT_PERIOD_FILE, null, rssRequest, iwc);
    CalBusiness calendar = new CalBusinessBean();

    Collection entries = calendar.getEntriesBetweenTimestamps(fromTmst, toTmst);
    if (entries.isEmpty())
      return getFeed(NO_ENTRIES_FOUND_TITLE, NO_ENTRIES_FOUND_FILE, null, rssRequest, iwc);
    String title = fromStr + "-" + toStr;

    return getFeed(title, feedFile, entries, rssRequest, iwc);
  }