001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.amazonrankings.util;
016    
017    import com.liferay.portal.kernel.util.PropsKeys;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.kernel.webcache.WebCacheItem;
021    import com.liferay.portal.kernel.webcache.WebCachePoolUtil;
022    import com.liferay.portal.util.PropsUtil;
023    import com.liferay.portlet.amazonrankings.model.AmazonRankings;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class AmazonRankingsUtil {
029    
030            public static String getAmazonAccessKeyId() {
031                    return PropsUtil.get(PropsKeys.AMAZON_ACCESS_KEY_ID);
032            }
033    
034            public static String getAmazonAssociateTag() {
035                    return PropsUtil.get(PropsKeys.AMAZON_ASSOCIATE_TAG);
036            }
037    
038            public static AmazonRankings getAmazonRankings(String isbn) {
039                    if (!Validator.isDigit(isbn)) {
040                            return null;
041                    }
042    
043                    WebCacheItem wci = new AmazonRankingsWebCacheItem(isbn);
044    
045                    return (AmazonRankings)WebCachePoolUtil.get(
046                            AmazonRankingsUtil.class.getName() + StringPool.PERIOD + isbn, wci);
047            }
048    
049    }