<commit_before>package org.gridsphere.portlets.core.rss;

import org.gridsphere.provider.portlet.jsr.ActionPortlet;
import org.gridsphere.provider.event.jsr.RenderFormEvent;
import org.gridsphere.provider.event.jsr.ActionFormEvent;
import org.gridsphere.provider.portletui.beans.ListBoxBean;
import org.gridsphere.provider.portletui.beans.ListBoxItemBean;
import org.gridsphere.services.core.rss.RssService;

import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;

import com.sun.syndication.io.FeedException;
import com.sun.syndication.feed.synd.SyndFeed;

import java.net.MalformedURLException;
import java.io.IOException;

public class RSSPortlet extends ActionPortlet {

    public final static String VIEW_RSS_JSP = "rss/viewRSS.jsp";
    private RssService rssService = null;

    public void init(PortletConfig config) throws PortletException {
        super.init(config);
        rssService = (RssService)createPortletService(RssService.class);
        DEFAULT_VIEW_PAGE = "doView";
    }


    public void doView(RenderFormEvent event) throws PortletException {
        SyndFeed feed = null;
        PortletPreferences prefs = event.getRenderRequest().getPreferences();
        String[] feedURL = prefs.getValues("feedurl", new String[]{null});
        //  todo localize the errormessages
        if (feedURL.equals("")) return;

        ListBoxBean feedsLB = event.getListBoxBean("feedsLB");
        feedsLB.clear();
        feedsLB.setSize(1);

        SyndFeed selectedFeed = null;
        String feedurl = (String)event.getRenderRequest().getPortletSession(true).getAttribute("selectedfeed");
        if (feedurl == null) feedurl = feedURL[0];
        for (int i = 0; i < feedURL.length; i++) {
            try {
                feed = rssService.getFeed(feedURL[i]);
            } catch (FeedException e) {
                log.error("Could not create Feed.", e);
                createErrorMessage(event, "Could not create Feed.");
            } catch (MalformedURLException e) {
                log.error("RSS URL " + feedURL + " is not valid.", e);
                createErrorMessage(event, "RSS URL " + feedURL[i] + " is not valid.");
            } catch (IOException e) {
                log.error("Could not read RSS feed from " + feedURL[i], e);
                createErrorMessage(event, "Could not read RSS feed from " + feedURL);
            }
            ListBoxItemBean item = new ListBoxItemBean();
            item.setName(feedURL[i]);
            item.setValue((feed.getTitle() != null) ? feed.getTitle() : feedURL[i]);<commit_msg>minor<commit_after>package org.gridsphere.portlets.core.rss;

import org.gridsphere.provider.portlet.jsr.ActionPortlet;
import org.gridsphere.provider.event.jsr.RenderFormEvent;
import org.gridsphere.provider.event.jsr.ActionFormEvent;
import org.gridsphere.provider.portletui.beans.ListBoxBean;
import org.gridsphere.provider.portletui.beans.ListBoxItemBean;
import org.gridsphere.services.core.rss.RssService;

import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;

import com.sun.syndication.io.FeedException;
import com.sun.syndication.feed.synd.SyndFeed;

import java.net.MalformedURLException;
import java.io.IOException;

public class RSSPortlet extends ActionPortlet {

    public final static String VIEW_RSS_JSP = "rss/viewRSS.jsp";
    private RssService rssService = null;

    public void init(PortletConfig config) throws PortletException {
        super.init(config);
        rssService = (RssService)createPortletService(RssService.class);
        DEFAULT_VIEW_PAGE = "doView";
    }


    public void doView(RenderFormEvent event) throws PortletException {
        SyndFeed feed = null;
        PortletPreferences prefs = event.getRenderRequest().getPreferences();
        String[] feedURL = prefs.getValues("feedurl", new String[]{null});
        //  todo localize the errormessages
        if (feedURL.equals("")) return;

        ListBoxBean feedsLB = event.getListBoxBean("feedsLB");
        feedsLB.clear();
        feedsLB.setSize(1);

        SyndFeed selectedFeed = null;
        String feedurl = (String)event.getRenderRequest().getPortletSession(true).getAttribute("selectedfeed");
        if (feedurl == null) feedurl = feedURL[0];
        for (int i = 0; i < feedURL.length; i++) {
            try {
                feed = rssService.getFeed(feedURL[i]);
            } catch (FeedException e) {
                log.error("Could not create Feed.", e);
                createErrorMessage(event, "Could not create Feed.");
            } catch (MalformedURLException e) {
                log.error("RSS URL " + feedURL + " is not valid.", e);
                createErrorMessage(event, "RSS URL " + feedURL[i] + " is not valid.");
            } catch (IOException e) {
                log.error("Could not read RSS feed from " + feedURL[i], e);
                createErrorMessage(event, "Could not read RSS feed from " + feedURL[i]);
            }
            ListBoxItemBean item = new ListBoxItemBean();
            item.setName(feedURL[i]);
            item.setValue((feed.getTitle() != null) ? feed.getTitle() : feedURL[i]);
{'fraction_non_alphanumeric': 0.11159946493407223, 'fraction_numerical': 0.0011465698452130708, 'mean_word_length': 3.0354664610639936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3221872', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1504, 'n_words': 323}