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 <element> 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 * Maximum value for height is 400, default value is 31. 030 * </p> 031 * 032 * @author Bill Brown 033 * 034 */ 035public class Height implements Serializable { 036 037 /** 038 * 039 */ 040 private static final long serialVersionUID = 828264834229377611L; 041 042 private final String height; 043 044 Height(String height) throws RSSpectException { 045 046 if (height == null || height.equals("")) { 047 throw new RSSpectException("height SHOULD NOT be blank."); 048 } 049 050 try { 051 int localHeight = Integer.parseInt(height); 052 if (localHeight > 400) { 053 throw new RSSpectException( 054 "height cannot be greater than 400px."); 055 } 056 } catch (NumberFormatException n) { 057 throw new RSSpectException("invalid number format for height."); 058 } 059 060 this.height = height; 061 } 062 063 Height(Height height) { 064 this.height = height.height; 065 } 066 067 /** 068 * @return the height. 069 */ 070 public String getHeight() { 071 return height; 072 } 073 074 /** 075 * Shows the contents of the <height> element. 076 */ 077 @Override 078 public String toString() { 079 return "<height>" + height + "</height>"; 080 } 081 082 @Override 083 public boolean equals(Object obj) { 084 if (obj == this) { 085 return true; 086 } 087 if (!(obj instanceof Height)) { 088 return false; 089 } 090 return this.toString().equals(obj.toString()); 091 } 092 093 @Override public int hashCode() { 094 return toString().hashCode(); 095 } 096}