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 <url> 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 * This class models a <url> element in an rss feed. 030 * </p> 031 * 032 * @author Bill Brown 033 * 034 */ 035public class URL implements Serializable { 036 037 /** 038 * 039 */ 040 private static final long serialVersionUID = -7336240801697282972L; 041 042 private final String url; 043 044 URL(String url) throws RSSpectException { 045 046 if (url == null || url.equals("")) { 047 throw new RSSpectException("url SHOULD NOT be blank."); 048 } 049 050 String urlLocal = url.trim(); 051 if (urlLocal.length() > 0 052 && new URIScheme().contains(urlLocal.substring(0, urlLocal 053 .indexOf(":")))) { 054 this.url = url; 055 } else { 056 throw new RSSpectException("link elements must start with a valid " 057 + "Uniform Resource Identifer (URI) Schemes. " 058 + "See http://www.iana.org. Yours started with: '" + url 059 + "'"); 060 } 061 062 } 063 064 URL(URL url) { 065 this.url = url.url; 066 } 067 068 /** 069 * @return the url. 070 */ 071 public String getUrl() { 072 return url; 073 } 074 075 /** 076 * Shows the contents of the <url> element. 077 */ 078 @Override 079 public String toString() { 080 return "<url>" + url + "</url>"; 081 } 082 083 @Override 084 public boolean equals(Object obj) { 085 if (obj == this) { 086 return true; 087 } 088 if (!(obj instanceof URL)) { 089 return false; 090 } 091 return this.toString().equals(obj.toString()); 092 } 093 094 @Override public int hashCode() { 095 return toString().hashCode(); 096 } 097}