001/**
002 * Copyright 2011 Bill Brown
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package com.colorfulsoftware.rss;
017
018import java.io.Serializable;
019
020/**
021 * <p>
022 * The &lt;author> element.
023 * </p>
024 * <p>
025 * From the <a href="http://cyber.law.harvard.edu/rss/rss.html">RSS 2.0
026 * specification</a>...
027 * </p>
028 * <p>
029 * Email address of the author of the item. <a href=
030 * "http://cyber.law.harvard.edu/rss/rss.html#ltauthorgtSubelementOfLtitemgt"
031 * >More</a>.
032 * </p>
033 * 
034 * <p>
035 * &lt;author> is an optional sub-element of &lt;item>.
036 * </p>
037 * 
038 * <p>
039 * It's the email address of the author of the item. For newspapers and
040 * magazines syndicating via RSS, the author is the person who wrote the article
041 * that the &lt;item> describes. For collaborative weblogs, the author of the
042 * item might be different from the managing editor or webmaster. For a weblog
043 * authored by a single individual it would make sense to omit the &lt;author>
044 * element.
045 * </p>
046 * 
047 * <p>
048 * &lt;author>lawyer@boyer.net (Lawyer Boyer)&lt;/author>
049 * </p>
050 * 
051 * @author Bill Brown
052 * 
053 */
054public class Author implements Serializable {
055
056        private static final long serialVersionUID = -547859529015538572L;
057
058        private final String author;
059
060        Author(String author) throws RSSpectException {
061                if (author == null || author.equals("")) {
062                        throw new RSSpectException("Author names SHOULD NOT be blank.");
063                }
064                this.author = author;
065        }
066
067        Author(Author author) {
068                this.author = author.author;
069        }
070
071        /**
072         * @return the author's email address and maybe more text.
073         */
074        public String getAuthor() {
075                return author;
076        }
077
078        /**
079         * Shows the contents of the &lt;author> element.
080         */
081        @Override
082        public String toString() {
083                return "<author>" + author + "</author>";
084        }
085        
086        @Override
087        public boolean equals(Object obj) {
088                if (obj == this) {
089                        return true;
090                }
091                if (!(obj instanceof Author)) {
092                        return false;
093                }
094                return this.toString().equals(obj.toString());
095        }
096        
097        @Override public int hashCode() {
098                return toString().hashCode();
099        }
100
101}