コード例 #1
0
  private Map<String, String> getLocaleLabels(Locale locale) {
    Map<String, String> labelMap = new HashMap<String, String>();
    ResourceBundle labels = ResourceBundle.getBundle("Messages", locale);

    labelMap.put(SyndicationFeed.MSG_UNTITLED, labels.getString(msgKey + ".notitle"));
    labelMap.put(SyndicationFeed.MSG_LOGO_TITLE, labels.getString(msgKey + ".logo.title"));
    labelMap.put(
        SyndicationFeed.MSG_FEED_DESCRIPTION,
        labels.getString(msgKey + ".general-feed.description"));
    labelMap.put(SyndicationFeed.MSG_UITYPE, SyndicationFeed.UITYPE_JSPUI);
    for (String selector : SyndicationFeed.getDescriptionSelectors()) {
      labelMap.put(
          "metadata." + selector, labels.getString(SyndicationFeed.MSG_METADATA + selector));
    }
    return labelMap;
  }
コード例 #2
0
ファイル: FeedServlet.java プロジェクト: ekate/fda5
  protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, SQLException, AuthorizeException {
    includeAll = ConfigurationManager.getBooleanProperty("harvest.includerestricted.rss", true);
    String path = request.getPathInfo();
    String feedType = null;
    String handle = null;

    // build label map from localized Messages resource bundle
    Locale locale = request.getLocale();
    ResourceBundle msgs = ResourceBundle.getBundle("Messages", locale);
    Map<String, String> labelMap = new HashMap<String, String>();
    labelMap.put(SyndicationFeed.MSG_UNTITLED, msgs.getString(clazz + ".notitle"));
    labelMap.put(SyndicationFeed.MSG_LOGO_TITLE, msgs.getString(clazz + ".logo.title"));
    labelMap.put(
        SyndicationFeed.MSG_FEED_DESCRIPTION, msgs.getString(clazz + ".general-feed.description"));
    labelMap.put(SyndicationFeed.MSG_UITYPE, SyndicationFeed.UITYPE_JSPUI);
    for (String selector : SyndicationFeed.getDescriptionSelectors()) {
      labelMap.put("metadata." + selector, msgs.getString(SyndicationFeed.MSG_METADATA + selector));
    }

    if (path != null) {
      // substring(1) is to remove initial '/'
      path = path.substring(1);
      int split = path.indexOf('/');
      if (split != -1) {
        feedType = path.substring(0, split);
        handle = path.substring(split + 1);
      }
    }

    DSpaceObject dso = null;

    // as long as this is not a site wide feed,
    // attempt to retrieve the Collection or Community object
    if (handle != null && !handle.equals(SITE_FEED_KEY)) {
      // Determine if handle is a valid reference
      dso = HandleManager.resolveToObject(context, handle);
      if (dso == null) {
        log.info(LogManager.getHeader(context, "invalid_handle", "path=" + path));
        JSPManager.showInvalidIDError(request, response, handle, -1);
        return;
      }
    }

    if (!enabled
        || (dso != null
            && (dso.getType() != Constants.COLLECTION && dso.getType() != Constants.COMMUNITY))) {
      log.info(LogManager.getHeader(context, "invalid_id", "path=" + path));
      JSPManager.showInvalidIDError(request, response, path, -1);
      return;
    }

    // Determine if requested format is supported
    if (feedType == null || !formats.contains(feedType)) {
      log.info(LogManager.getHeader(context, "invalid_syndformat", "path=" + path));
      JSPManager.showInvalidIDError(request, response, path, -1);
      return;
    }

    if (dso != null && dso.getType() == Constants.COLLECTION) {
      labelMap.put(
          SyndicationFeed.MSG_FEED_TITLE,
          MessageFormat.format(
              msgs.getString(clazz + ".feed.title"),
              msgs.getString(clazz + ".feed-type.collection"),
              dso.getMetadata("short_description")));
    } else if (dso != null && dso.getType() == Constants.COMMUNITY) {
      labelMap.put(
          SyndicationFeed.MSG_FEED_TITLE,
          MessageFormat.format(
              msgs.getString(clazz + ".feed.title"),
              msgs.getString(clazz + ".feed-type.community"),
              dso.getMetadata("short_description")));
    }

    // Lookup or generate the feed
    // Cache key is handle + locale
    String cacheKey = (handle == null ? "site" : handle) + "." + locale.toString();
    SyndicationFeed feed = null;
    if (feedCache != null) {
      CacheFeed cFeed = feedCache.get(cacheKey);
      if (cFeed != null) // cache hit, but...
      {
        // Is the feed current?
        boolean cacheFeedCurrent = false;
        if (cFeed.timeStamp + (cacheAge * HOUR_MSECS) < System.currentTimeMillis()) {
          cacheFeedCurrent = true;
        }
        // Not current, but have any items changed since feed was created/last checked?
        else if (!itemsChanged(context, dso, cFeed.timeStamp)) {
          // no items have changed, re-stamp feed and use it
          cFeed.timeStamp = System.currentTimeMillis();
          cacheFeedCurrent = true;
        }
        if (cacheFeedCurrent) {
          feed = cFeed.access();
        }
      }
    }

    // either not caching, not found in cache, or feed in cache not current
    if (feed == null) {
      feed = new SyndicationFeed(SyndicationFeed.UITYPE_JSPUI);
      feed.populate(request, dso, getItems(context, dso), labelMap);
      if (feedCache != null) {
        cache(cacheKey, new CacheFeed(feed));
      }
    }

    // set the feed to the requested type & return it
    try {
      feed.setType(feedType);
      response.setContentType("text/xml; charset=UTF-8");
      feed.output(response.getWriter());
    } catch (FeedException fex) {
      throw new IOException(fex.getMessage(), fex);
    }
  }