001
014
015 package com.liferay.portlet.amazonrankings.util;
016
017 import com.liferay.portal.kernel.util.DateFormatFactoryUtil;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.kernel.util.TimeZoneUtil;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.portal.kernel.webcache.WebCacheItem;
022 import com.liferay.portal.kernel.webcache.WebCachePoolUtil;
023 import com.liferay.portal.util.PropsValues;
024 import com.liferay.portlet.amazonrankings.model.AmazonRankings;
025
026 import java.text.DateFormat;
027
028 import java.util.Calendar;
029
030
033 public class AmazonRankingsUtil {
034
035 public static String getAmazonAccessKeyId() {
036 return PropsValues.AMAZON_ACCESS_KEY_ID;
037 }
038
039 public static String getAmazonAssociateTag() {
040 return PropsValues.AMAZON_ASSOCIATE_TAG;
041 }
042
043 public static AmazonRankings getAmazonRankings(String isbn) {
044 if (!Validator.isDigit(isbn)) {
045 return null;
046 }
047
048 WebCacheItem wci = new AmazonRankingsWebCacheItem(isbn);
049
050 return (AmazonRankings)WebCachePoolUtil.get(
051 AmazonRankingsUtil.class.getName() + StringPool.PERIOD + isbn, wci);
052 }
053
054 public static String getAmazonSecretAccessKey() {
055 return PropsValues.AMAZON_SECRET_ACCESS_KEY;
056 }
057
058 public static String getTimestamp() {
059 DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat(
060 _TIMESTAMP);
061
062 dateFormat.setTimeZone(TimeZoneUtil.getDefault());
063
064 Calendar calendar = Calendar.getInstance();
065
066 return dateFormat.format(calendar.getTime());
067 }
068
069 public static boolean isEnabled() {
070 if (Validator.isNull(PropsValues.AMAZON_ACCESS_KEY_ID) ||
071 Validator.isNull(PropsValues.AMAZON_ASSOCIATE_TAG) ||
072 Validator.isNull(PropsValues.AMAZON_SECRET_ACCESS_KEY)) {
073
074 return false;
075 }
076 else {
077 return true;
078 }
079 }
080
081 private static final String _TIMESTAMP = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
082
083 }