1 /** 2 * This file Copyright (c) 2008-2016 Magnolia International 3 * Ltd. (http://www.magnolia-cms.com). All rights reserved. 4 * 5 * 6 * This file is dual-licensed under both the Magnolia 7 * Network Agreement and the GNU General Public License. 8 * You may elect to use one or the other of these licenses. 9 * 10 * This file is distributed in the hope that it will be 11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the 12 * implied warranty of MERCHANTABILITY or FITNESS FOR A 13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. 14 * Redistribution, except as permitted by whichever of the GPL 15 * or MNA you select, is prohibited. 16 * 17 * 1. For the GPL license (GPL), you can redistribute and/or 18 * modify this file under the terms of the GNU General 19 * Public License, Version 3, as published by the Free Software 20 * Foundation. You should have received a copy of the GNU 21 * General Public License, Version 3 along with this program; 22 * if not, write to the Free Software Foundation, Inc., 51 23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 * 25 * 2. For the Magnolia Network Agreement (MNA), this file 26 * and the accompanying materials are made available under the 27 * terms of the MNA which accompanies this distribution, and 28 * is available at http://www.magnolia-cms.com/mna.html 29 * 30 * Any modifications to this file must keep this entire header 31 * intact. 32 * 33 */ 34 package info.magnolia.module.rssaggregator.importhandler; 35 36 import info.magnolia.module.rssaggregator.util.Assert; 37 38 import org.apache.commons.lang3.builder.ToStringBuilder; 39 40 import com.rometools.rome.feed.synd.SyndFeed; 41 42 /** 43 * A {@link #name named} feed channel that typically belongs to an {@link AggregateFeed}. Knows the {@link #url url} on 44 * which a given RSS or ATOM feed resides and {@link #feed holds} the {@link SyndFeed feed} that was fetched after 45 * successful retrieval by a {@link RSSFeedFetcher}. 46 * 47 * @see AggregateFeed 48 * @see RSSFeedFetcher 49 * @see SyndFeed 50 */ 51 public class FeedChannel { 52 53 private final String name; 54 private final String url; 55 private final String title; 56 private SyndFeed feed; 57 58 /** 59 * Create a new feed channel from the given <code>name</code>, <code>url</code> and <code>title</code>. 60 * 61 * @param name the name of the feed channel (e.g.: 'channel-0') 62 * @param url the url of the feed channel (e.g.: 'http://robl.jteam.nl/?feed=rss2' 63 * @param title the title of the feed channel (e.g.: 'I'll take the red pill ...') 64 * @throws IllegalArgumentException if the given <code>name</code> or <code>url</code> provided is blank, or 65 * <code>title</code> is <code>null</code> 66 */ 67 public FeedChannel(String name, String url, String title) { 68 Assert.notBlank(name, "'name' must not be blank"); 69 Assert.notBlank(url, "'url' must not be blank"); 70 Assert.notNull(title, "'title' must not be null"); 71 this.name = name; 72 this.url = url; 73 this.title = title; 74 } 75 76 @Override 77 public boolean equals(Object o) { 78 if (this == o) return true; 79 if (o == null || getClass() != o.getClass()) return false; 80 81 FeedChannel that = (FeedChannel) o; 82 83 if (feed != null ? !feed.equals(that.feed) : that.feed != null) return false; 84 if (!name.equals(that.name)) return false; 85 if (!title.equals(that.title)) return false; 86 if (!url.equals(that.url)) return false; 87 88 return true; 89 } 90 91 @Override 92 public int hashCode() { 93 int result = name.hashCode(); 94 result = 31 * result + url.hashCode(); 95 result = 31 * result + title.hashCode(); 96 result = 31 * result + (feed != null ? feed.hashCode() : 0); 97 return result; 98 } 99 100 @Override 101 public String toString() { 102 return new ToStringBuilder(this) 103 .append("name", name) 104 .append("url", url) 105 .append("title", title) 106 .append("feed", feed) 107 .toString(); 108 } 109 110 // Helper methods 111 112 /** 113 * Return <code>true</code> when this feed channel contains a {@link #feed}, <code>false</code> otherwise. 114 * 115 * @return true when this feed channel contains a feed, false otherwise 116 */ 117 public boolean hasFeed() { 118 return feed != null; 119 } 120 121 // Getters & setters 122 123 /** 124 * Return the name of the feed channel. 125 * 126 * @return the name of the feed channel 127 */ 128 public String getName() { 129 return name; 130 } 131 132 /** 133 * Return the url which points to the RSS or ATOM feed for this feed channel. 134 * 135 * @return the url which points to the RSS or ATOM feed for this feed channel 136 */ 137 public String getUrl() { 138 return url; 139 } 140 141 /** 142 * Return the title of the feed channel. 143 * 144 * @return the title of the feed channel 145 */ 146 public String getTitle() { 147 return title; 148 } 149 150 /** 151 * Set the feed (fetch result) for this feed channel. 152 * 153 * @param feed the feed (fetch result) for this feed channel (must not be null) 154 * @throws IllegalArgumentException if the given feed is <code>null</code> 155 */ 156 public void setFeed(SyndFeed feed) { 157 Assert.notNull(feed, "'feed' must not be null"); 158 this.feed = feed; 159 } 160 161 /** 162 * Return the feed (fetch result) for this feed channel. 163 * 164 * @return the feed (fetch result) for this feed channel or <code>null</code> if no result was set 165 */ 166 public SyndFeed getFeed() { 167 return feed; 168 } 169 170 }