1 package com.explosion.expf.menusandtools;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.awt.Component;
23 import java.util.Map;
24
25 /***
26 * This class is a little util for checking cookies.
27 * @author Stephen Cowx
28 */
29 public class CookieChecker
30 {
31
32 private String cookieName;
33 private int enabledThreshold = 1;
34
35 public CookieChecker(String cookieName, int enabledThreshold)
36 {
37 this.cookieName = cookieName;
38 this.enabledThreshold = enabledThreshold;
39 }
40
41 /***
42 * This method checks for an object of type Integer
43 */
44 private boolean checkEnabled(Map cookieDatabase) throws Exception
45 {
46 if (cookieDatabase == null)
47 return false;
48
49 try
50 {
51 Object cookie = cookieDatabase.get(cookieName);
52 if (cookie != null && ((Integer) cookie).intValue() >= enabledThreshold)
53 return true;
54 else
55 return false;
56 }
57 catch (ClassCastException e)
58 {
59 throw new CookieException("Expected object of type Integer in cookie database but found object of another type.", e);
60 }
61 }
62
63 /***
64 * This method checks for an object of type Integer
65 */
66 public void checkEnabled(Map componentCookies, Map localCookies,Map globalCookies, Component component) throws Exception
67 {
68 boolean componenttrue = checkEnabled(componentCookies);
69 boolean localtrue = checkEnabled(localCookies);
70 boolean globaltrue = checkEnabled(globalCookies);
71
72 if(componenttrue || localtrue || globaltrue )
73 component.setEnabled(true);
74 else
75 component.setEnabled(false);
76 }
77 }