コード例 #1
0
  private String getFeed(
      String title, String feedFileName, Collection entries, RSSRequest rssRequest, IWContext iwc) {
    if (rssFileURIsCacheList.contains(feedFileName))
      return PATH_TO_FEED_PARENT_FOLDER + feedFileName;
    Date now = new Date();
    RSSBusiness rss = null;
    try {
      rss = IBOLookup.getServiceInstance(iwc, RSSBusiness.class);
    } catch (IBOLookupException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    String serverName = iwc.getServerURL();
    serverName = serverName.substring(0, serverName.length() - 1);
    SyndFeed feed = null;

    feed =
        rss.createNewFeed(
            title,
            serverName,
            FEED_DESCRIPTION,
            "atom_1.0",
            iwc.getCurrentLocale().toString(),
            new Timestamp(now.getTime()));

    if (entries != null) feed.setEntries(getFeedEntries(entries));

    try {
      String feedContent = rss.convertFeedToAtomXMLString(feed);
      IWSlideService service = this.getIWSlideService(rssRequest);
      service.uploadFileAndCreateFoldersFromStringAsRoot(
          PATH_TO_FEED_PARENT_FOLDER,
          feedFileName,
          feedContent,
          RSSAbstractProducer.RSS_CONTENT_TYPE,
          true);
      rssFileURIsCacheList.add(feedFileName);
    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return PATH_TO_FEED_PARENT_FOLDER + feedFileName;
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  public void searchForArticles(
      RSSRequest rssRequest,
      String feedParentPath,
      String feedFileName,
      List<String> categories,
      List<String> articles,
      String extraURI) {

    IWContext iwc = getIWContext(rssRequest);
    boolean getAllArticles = false;

    if (StringUtil.isEmpty(extraURI)) {
      getAllArticles = true;
    }

    String serverName = iwc.getServerURL();
    serverName = serverName.substring(0, serverName.length() - 1);

    Collection<SearchResult> results = getArticleSearchResults(PATH, categories, iwc);
    if (ListUtil.isEmpty(results)) {
      LOGGER.warning("No results found in: " + PATH + " by the categories: " + categories);
      return;
    }

    List<String> urisToArticles = new ArrayList<String>();
    for (SearchResult result : results) {
      urisToArticles.add(result.getSearchResultURI());
    }

    if (!ListUtil.isEmpty(articles)) {
      if (ListUtil.isEmpty(categories)) {
        urisToArticles = articles;
      } else {
        urisToArticles.addAll(articles);
      }
    }

    if (!ListUtil.isEmpty(articles) && ListUtil.isEmpty(categories)) urisToArticles = articles;

    RSSBusiness rss = null;
    SyndFeed articleFeed = null;
    long time = System.currentTimeMillis();
    try {
      rss = IBOLookup.getServiceInstance(iwc, RSSBusiness.class);
    } catch (IBOLookupException e) {
      LOGGER.log(Level.WARNING, "Error getting " + RSSBusiness.class, e);
    }

    String description = CoreConstants.EMPTY;
    String title = CoreConstants.EMPTY;
    if (ListUtil.isEmpty(results) && !getAllArticles) {
      description = "No articles found. Empty feed";
    } else {
      description =
          "Article feed generated by IdegaWeb ePlatform, Idega Software, http://www.idega.com";

      BuilderService bservice = null;
      String pageKey = null;
      try {
        if (!StringUtil.isEmpty(extraURI)) {
          bservice = BuilderServiceFactory.getBuilderService(iwc);
          pageKey = bservice.getExistingPageKeyByURI(CoreConstants.SLASH + extraURI);
          ICPage icpage = bservice.getICPage(pageKey);
          title = icpage.getName();
        }
      } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error getting page name from: " + extraURI, e);
      }

      String lang = iwc.getCurrentLocale().getLanguage();
      SyndFeed allArticles =
          rss.createNewFeed(title, serverName, description, "atom_1.0", lang, new Timestamp(time));

      List<SyndEntry> allEntries = new ArrayList<SyndEntry>();
      for (int i = 0; i < urisToArticles.size(); i++) {
        String articleURL =
            serverName
                .concat(urisToArticles.get(i))
                .concat(CoreConstants.SLASH)
                .concat(lang)
                .concat(".xml");
        articleFeed = rss.getFeed(articleURL);
        if (articleFeed != null) allEntries.addAll(articleFeed.getEntries());
      }

      allArticles.setEntries(allEntries);
      String allArticlesContent = null;
      try {
        allArticlesContent = rss.convertFeedToAtomXMLString(allArticles);
      } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error converting to Atom from: " + allArticles, e);
      }

      try {
        IWSlideService service = this.getIWSlideService(rssRequest);
        service.uploadFileAndCreateFoldersFromStringAsRoot(
            feedParentPath,
            feedFileName,
            allArticlesContent,
            RSSAbstractProducer.RSS_CONTENT_TYPE,
            true);
      } catch (RemoteException e) {
        LOGGER.log(
            Level.WARNING,
            "Error uploading to: " + feedParentPath + feedFileName + " file: " + allArticlesContent,
            e);
      }
    }
  }