KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > cache > PageNotFoundCache


1 /*
2  * Created on May 31, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package com.dotmarketing.cache;
8
9 import java.io.FileInputStream JavaDoc;
10 import java.io.FileNotFoundException JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.util.Properties JavaDoc;
13
14 import com.dotmarketing.portlets.htmlpages.model.HTMLPage;
15 import com.dotmarketing.util.Config;
16 import com.dotmarketing.util.Logger;
17 import com.dotmarketing.util.UtilMethods;
18
19 /**
20  * @author David
21  *
22  * TODO To change the template for this generated type comment go to Window -
23  * Preferences - Java - Code Style - Code Templates
24  */

25 public class PageNotFoundCache {
26
27     // Cache to store the data
28
private static DotCache cache;
29
30     // Name of the variable with the provider name
31
private static String JavaDoc providerEntry = "CACHE_PROVIDER";
32
33     // Name of the variable with the properties path
34
private static String JavaDoc propertiesEntry = "CACHE_PROPERTIES_FILE";
35
36     // region's name for the cache
37
private static String JavaDoc regionName = "PageNotFoundCache";
38
39     static {
40         init();
41     }
42
43     // Methods implemented in the interface
44
public static void clearCache() {
45         cache.clear();
46     }
47
48     public static void destroy() {
49         cache.destroy();
50     }
51
52     public static Object JavaDoc getPageFromCache(String JavaDoc URI) {
53         return cache.get(URI);
54     }
55
56     public static void addPageToCache(String JavaDoc URI) {
57         //cache.put(URI, URI);
58
}
59
60     // Protected methods
61
public static void removePageFromCache(String JavaDoc URI) {
62
63         cache.remove(URI);
64     }
65
66     public static void removePageFromCache(HTMLPage page) {
67         try {
68             long _x = page.getIdentifier();
69             if (_x == 0) {
70                 String JavaDoc pagePath = "/live/" + _x + "." + Config.getStringProperty("VELOCITY_HTMLPAGE_EXTENSION");
71                 removePageFromCache(pagePath);
72             }
73         } catch (Exception JavaDoc ex) {
74             Logger.error(PageNotFoundCache.class, ex.toString());
75         }
76     }
77
78     protected static void unlock(Object JavaDoc key) {
79         cache.unlock(key);
80     }
81
82     protected static int getTimeout() {
83         return cache.getTimeout();
84     }
85
86     protected static void lock(Object JavaDoc key) {
87         cache.lock(key);
88     }
89
90     protected static long nextTimestamp() {
91         return cache.nextTimestamp();
92     }
93
94     // END Protected methods
95

96     private static void init() {
97         try {
98             Properties JavaDoc PageNotFountProperties = new Properties JavaDoc();
99             String JavaDoc cacheProviderClassName = com.dotmarketing.util.Config.getStringProperty(providerEntry);
100             try {
101                 String JavaDoc propertyFilePath = com.dotmarketing.util.Config.getStringProperty(propertiesEntry);
102                 if (UtilMethods.isSet(propertyFilePath)) {
103                     FileInputStream JavaDoc fileInputStream = new FileInputStream JavaDoc(propertyFilePath);
104                     PageNotFountProperties.load(fileInputStream);
105                 }
106             } catch (FileNotFoundException JavaDoc ex) {
107
108                 String JavaDoc propertyFileNotFound = "The property file has been no found \n";
109                 Logger.debug(PageNotFoundCache.class, propertyFileNotFound + ex.getMessage());
110             } catch (IOException JavaDoc ex) {
111                 Logger.debug(PageNotFoundCache.class, ex.getMessage());
112             } finally {
113                 cache = new DotCache(cacheProviderClassName, regionName, PageNotFountProperties);
114             }
115         } catch (Exception JavaDoc ex) {
116             Logger.error(PageNotFoundCache.class, ex.toString());
117         }
118     }
119 }
120
Popular Tags