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 <textInput> 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 * Specifies a text input box that can be displayed with the channel. More info 030 * <a href= 031 * "http://cyber.law.harvard.edu/rss/rss.html#lttextinputgtSubelementOfLtchannelgt" 032 * >here</a>. 033 * </p> 034 * 035 * <p> 036 * A channel may optionally contain a <textInput> sub-element, which contains 037 * four required sub-elements. 038 * </p> 039 * 040 * <p> 041 * <title> -- The label of the Submit button in the text input area. 042 * </p> 043 * 044 * <p> 045 * <description> -- Explains the text input area. 046 * </p> 047 * 048 * <p> 049 * <name> -- The name of the text object in the text input area. 050 * </p> 051 * 052 * <p> 053 * <<link> -- The URL of the CGI script that processes text input requests. 054 * </p> 055 * 056 * <p> 057 * The purpose of the <textInput> element is something of a mystery. You can 058 * use it to specify a search engine box. Or to allow a reader to provide 059 * feedback. Most aggregators ignore it. 060 * </p> 061 * 062 * @author Bill Brown 063 * 064 */ 065public class TextInput implements Serializable { 066 067 /** 068 * 069 */ 070 private static final long serialVersionUID = -1063471668352135813L; 071 072 private final Title title; 073 private final Description description; 074 private final Name name; 075 private final Link link; 076 077 TextInput(Title title, Description description, Name name, Link link) 078 throws RSSpectException { 079 // make sure title is present 080 if (title == null) { 081 throw new RSSpectException( 082 "textInput elements MUST contain a title element."); 083 } 084 this.title = new Title(title.getTitle()); 085 086 // make sure description is present 087 if (description == null) { 088 throw new RSSpectException( 089 "textInput elements MUST contain a description element."); 090 } 091 this.description = new Description(description.getDescription()); 092 093 // make sure name is present 094 if (name == null) { 095 throw new RSSpectException( 096 "textInput elements MUST contain a name element."); 097 } 098 this.name = new Name(name.getName()); 099 100 // make sure link is present 101 if (link == null) { 102 throw new RSSpectException( 103 "textInput elements MUST contain a link element."); 104 } 105 this.link = new Link(link.getLink()); 106 ; 107 } 108 109 TextInput(TextInput textInput) { 110 this.title = textInput.getTitle(); 111 this.description = textInput.getDescription(); 112 this.name = textInput.getName(); 113 this.link = textInput.getLink(); 114 } 115 116 /** 117 * @return the title object. 118 */ 119 public Title getTitle() { 120 return new Title(title); 121 } 122 123 /** 124 * @return the description object. 125 */ 126 public Description getDescription() { 127 return new Description(description.getDescription()); 128 } 129 130 /** 131 * @return the name object. 132 */ 133 public Name getName() { 134 return new Name(name); 135 } 136 137 /** 138 * @return the link object. 139 */ 140 public Link getLink() { 141 return new Link(link); 142 143 } 144 145 /** 146 * Shows the contents of the <textInput> element. 147 */ 148 @Override 149 public String toString() { 150 return "<textInput>" + title + description + name + link 151 + "</textInput>"; 152 } 153 154 @Override 155 public boolean equals(Object obj) { 156 if (obj == this) { 157 return true; 158 } 159 if (!(obj instanceof TextInput)) { 160 return false; 161 } 162 return this.toString().equals(obj.toString()); 163 } 164 165 @Override public int hashCode() { 166 return toString().hashCode(); 167 } 168}