You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
212 lines
5.9 KiB
Java
212 lines
5.9 KiB
Java
/*
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
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<String> posterSizes;
|
|
@JsonProperty("backdrop_sizes")
|
|
private List<String> backdropSizes;
|
|
@JsonProperty("profile_sizes")
|
|
private List<String> profileSizes;
|
|
@JsonProperty("logo_sizes")
|
|
private List<String> logoSizes;
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Getter methods">//GEN-BEGIN:getterMethods
|
|
public List<String> getBackdropSizes() {
|
|
return backdropSizes;
|
|
}
|
|
|
|
public String getBaseUrl() {
|
|
return baseUrl;
|
|
}
|
|
|
|
public List<String> getPosterSizes() {
|
|
return posterSizes;
|
|
}
|
|
|
|
public List<String> getProfileSizes() {
|
|
return profileSizes;
|
|
}
|
|
|
|
public List<String> getLogoSizes() {
|
|
return logoSizes;
|
|
}
|
|
|
|
public String getSecureBaseUrl() {
|
|
return secureBaseUrl;
|
|
}
|
|
|
|
// </editor-fold>
|
|
// <editor-fold defaultstate="collapsed" desc="Setter methods">//GEN-BEGIN:setterMethods
|
|
public void setBackdropSizes(List<String> backdropSizes) {
|
|
this.backdropSizes = backdropSizes;
|
|
}
|
|
|
|
public void setBaseUrl(String baseUrl) {
|
|
this.baseUrl = baseUrl;
|
|
}
|
|
|
|
public void setPosterSizes(List<String> posterSizes) {
|
|
this.posterSizes = posterSizes;
|
|
}
|
|
|
|
public void setProfileSizes(List<String> profileSizes) {
|
|
this.profileSizes = profileSizes;
|
|
}
|
|
|
|
public void setLogoSizes(List<String> logoSizes) {
|
|
this.logoSizes = logoSizes;
|
|
}
|
|
|
|
public void setSecureBaseUrl(String secureBaseUrl) {
|
|
this.secureBaseUrl = secureBaseUrl;
|
|
}
|
|
// </editor-fold>
|
|
|
|
/**
|
|
* 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();
|
|
}
|
|
}
|