public List<String> getCategoriesByURI(String URI, IWContext iwc) {
   List<String> categories = new ArrayList<String>();
   BuilderService bservice = null;
   String property = null;
   try {
     bservice = BuilderServiceFactory.getBuilderService(iwc);
   } catch (RemoteException e) {
     e.printStackTrace();
   }
   String pageKey = bservice.getExistingPageKeyByURI(CoreConstants.SLASH + URI);
   List<String> moduleId = bservice.getModuleId(pageKey, ArticleListViewer.class.getName());
   if (moduleId != null) {
     for (int i = 0; i < moduleId.size(); i++) {
       property = bservice.getProperty(pageKey, moduleId.get(i), "categories");
       if (property != null) {
         if (property.indexOf(",") != -1) {
           Collection<String> strings = ListUtil.convertCommaSeparatedStringToList(property);
           for (String string : strings) {
             categories.add(string);
           }
         } else {
           categories.add(property);
         }
       } else {
         // Article list viewer without property - displaying all pages
         categories = null;
       }
     }
   }
   return categories;
 }
  public List<String> getArticlesByURI(String URI, IWContext iwc) {
    List<String> articles = new ArrayList<String>();
    BuilderService bservice = null;
    try {
      bservice = BuilderServiceFactory.getBuilderService(iwc);
    } catch (RemoteException e) {
      e.printStackTrace();
    }
    String pageKey = bservice.getExistingPageKeyByURI(CoreConstants.SLASH + URI);

    List<String> moduleId = bservice.getModuleId(pageKey, ArticleItemViewer.class.getName());

    if (moduleId != null) {
      for (int i = 0; i < moduleId.size(); i++) {
        String articleURI = bservice.getProperty(pageKey, moduleId.get(i), "resourcePath");
        articleURI = articleURI.substring(0, articleURI.length());
        articles.add(CoreConstants.WEBDAV_SERVLET_URI + articleURI);
      }
    }
    return articles;
  }
  @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);
      }
    }
  }