KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > utils > CacheSettings


1 //
2
//Informa -- RSS Library for Java
3
//Copyright (c) 2002 by Niko Schmuck
4
//
5
//Niko Schmuck
6
//http://sourceforge.net/projects/informa
7
//mailto:niko_schmuck@users.sourceforge.net
8
//
9
//This library is free software.
10
//
11
//You may redistribute it and/or modify it under the terms of the GNU
12
//Lesser General Public License as published by the Free Software Foundation.
13
//
14
//Version 2.1 of the license should be included with this distribution in
15
//the file LICENSE. If the license is not included with this distribution,
16
//you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
//or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
//MA 02139 USA.
19
//
20
//This library is distributed in the hope that it will be useful,
21
//but WITHOUT ANY WARRANTY; without even the implied waranty of
22
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
//Lesser General Public License for more details.
24
//
25
// $Id: CacheSettings.java,v 1.4 2004/06/22 18:52:30 jga Exp $
26

27 package de.nava.informa.utils;
28
29 import de.nava.informa.core.ChannelIF;
30 import de.nava.informa.core.ChannelFormat;
31
32 /**
33  * delegation class for the various CacheSettingsIF implementation.
34  *
35  *
36  * default behavior : ttl (or update period) in feed is always respected.
37  * without such indication, the ttl specified by the informa user is used.
38  * @author Jean-Guy Avelin
39  */

40 public class CacheSettings implements CacheSettingsIF {
41
42   static private CacheSettingsIF v_091;
43   static private CacheSettingsIF v_100;
44   static private CacheSettingsIF v_200;
45   static private CacheSettingsIF v_A030;
46   /* default settings */
47   /* can read properties file to instantiate alternative implementations*/
48   /* TODO : property file handling */
49   static {
50     v_091 = new RSS091Settings();
51     v_100 = new RSS100Settings();
52     v_200 = new RSS200Settings();
53     v_A030 = new Atom030Settings();
54   }
55
56   /**
57    * determine ttl for the feed, depending on ttl specified by the
58    * feed producer and the ttl wanted by the informa user.
59    */

60   public long getTtl(ChannelIF channel, long ttl) {
61
62     if (channel.getFormat().equals(ChannelFormat.RSS_0_91)
63         || channel.getFormat().equals(ChannelFormat.RSS_0_92)
64         || channel.getFormat().equals(ChannelFormat.RSS_0_93)
65         || channel.getFormat().equals(ChannelFormat.RSS_0_94) ) {
66       return v_091.getTtl(channel, ttl);
67     } else if (channel.getFormat().equals(ChannelFormat.RSS_1_0)) {
68       return v_100.getTtl(channel, ttl);
69     } else if (channel.getFormat().equals(ChannelFormat.RSS_2_0)) {
70       return v_200.getTtl(channel, ttl);
71     }
72     else if (channel.getFormat().equals(ChannelFormat.ATOM_0_3)) {
73       return v_A030.getTtl(channel, ttl);
74     }
75     
76     return CacheSettingsIF.DEFAULT_TTL;
77   }
78
79   /**
80    * TODO : remove ?
81    */

82   public void setDefaultTtl(long defTtl) {
83     v_091.setDefaultTtl(defTtl);
84     v_100.setDefaultTtl(defTtl);
85     v_200.setDefaultTtl(defTtl);
86     v_A030.setDefaultTtl(defTtl);
87   }
88
89   public void setDefaultTtl(String JavaDoc type, long defTtl) {
90     if (ChannelFormat.RSS_0_91.equals(type)
91         || ChannelFormat.RSS_0_92.equals(type)
92         || ChannelFormat.RSS_0_93.equals(type)
93         || ChannelFormat.RSS_0_94.equals(type)) {
94       v_091.setDefaultTtl(defTtl);
95       return;
96     }
97
98     if (ChannelFormat.RSS_1_0.equals(type)) {
99       v_100.setDefaultTtl(defTtl);
100       return;
101     }
102
103     if (ChannelFormat.RSS_2_0.equals(type)) {
104       v_200.setDefaultTtl(defTtl);
105       return;
106     }
107
108     if (ChannelFormat.ATOM_0_3.equals(type)) {
109       v_A030.setDefaultTtl(defTtl);
110       return;
111     }
112     
113   }
114 }
115
Popular Tags