/* * Copyright (c) 2004-2013 Stuart Boston * * This file is part of TheMovieDB API. * * TheMovieDB API is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * TheMovieDB API is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TheMovieDB API. If not, see . * */ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; /** * * @author stuart.boston */ public class TmdbConfiguration implements Serializable { private static final long serialVersionUID = 1L; /* * Logger */ private static final Logger logger = Logger.getLogger(TmdbConfiguration.class); /* * Properties */ @JsonProperty("base_url") private String baseUrl; @JsonProperty("secure_base_url") private String secureBaseUrl; @JsonProperty("poster_sizes") private List posterSizes; @JsonProperty("backdrop_sizes") private List backdropSizes; @JsonProperty("profile_sizes") private List profileSizes; @JsonProperty("logo_sizes") private List logoSizes; // //GEN-BEGIN:getterMethods public List getBackdropSizes() { return backdropSizes; } public String getBaseUrl() { return baseUrl; } public List getPosterSizes() { return posterSizes; } public List getProfileSizes() { return profileSizes; } public List getLogoSizes() { return logoSizes; } public String getSecureBaseUrl() { return secureBaseUrl; } // // //GEN-BEGIN:setterMethods public void setBackdropSizes(List backdropSizes) { this.backdropSizes = backdropSizes; } public void setBaseUrl(String baseUrl) { this.baseUrl = baseUrl; } public void setPosterSizes(List posterSizes) { this.posterSizes = posterSizes; } public void setProfileSizes(List profileSizes) { this.profileSizes = profileSizes; } public void setLogoSizes(List logoSizes) { this.logoSizes = logoSizes; } public void setSecureBaseUrl(String secureBaseUrl) { this.secureBaseUrl = secureBaseUrl; } // /** * Copy the data from the passed object to this one * * @param config */ public void clone(TmdbConfiguration config) { backdropSizes = config.getBackdropSizes(); baseUrl = config.getBaseUrl(); posterSizes = config.getPosterSizes(); profileSizes = config.getProfileSizes(); logoSizes = config.getLogoSizes(); } /** * Check that the poster size is valid * * @param posterSize * @return */ public boolean isValidPosterSize(String posterSize) { if (StringUtils.isBlank(posterSize) || posterSizes.isEmpty()) { return false; } return posterSizes.contains(posterSize); } /** * Check that the backdrop size is valid * * @param backdropSize * @return */ public boolean isValidBackdropSize(String backdropSize) { if (StringUtils.isBlank(backdropSize) || backdropSizes.isEmpty()) { return false; } return backdropSizes.contains(backdropSize); } /** * Check that the profile size is valid * * @param profileSize * @return */ public boolean isValidProfileSize(String profileSize) { if (StringUtils.isBlank(profileSize) || profileSizes.isEmpty()) { return false; } return profileSizes.contains(profileSize); } /** * Check that the logo size is valid * * @param logoSize * @return */ public boolean isValidLogoSize(String logoSize) { if (StringUtils.isBlank(logoSize) || logoSizes.isEmpty()) { return false; } return logoSizes.contains(logoSize); } /** * Check to see if the size is valid for any of the images types * * @param sizeToCheck * @return */ public boolean isValidSize(String sizeToCheck) { return (isValidPosterSize(sizeToCheck) || isValidBackdropSize(sizeToCheck) || isValidProfileSize(sizeToCheck) || isValidLogoSize(sizeToCheck)); } /** * Handle unknown properties and print a message * * @param key * @param value */ @JsonAnySetter public void handleUnknown(String key, Object value) { StringBuilder sb = new StringBuilder(); sb.append("Unknown property: '").append(key); sb.append("' value: '").append(value).append("'"); logger.trace(sb.toString()); } @Override public String toString() { StringBuilder sb = new StringBuilder("[ImageConfiguration="); sb.append("[baseUrl=").append(baseUrl); sb.append("],[posterSizes=").append(posterSizes.toString()); sb.append("],[backdropSizes=").append(backdropSizes.toString()); sb.append("],[profileSizes=").append(profileSizes.toString()); sb.append("],[logoSizes=").append(logoSizes.toString()); sb.append(("]]")); return sb.toString(); } }