1 | /*
|
---|
2 | * Created on Nov 23, 2004
|
---|
3 | * Copyright (C) Andrea Schweer, 2004
|
---|
4 | *
|
---|
5 | * This file is part of the Greenstone Alerting Service.
|
---|
6 | * Refer to the COPYING file in the base directory of this package
|
---|
7 | * for licensing information.
|
---|
8 | */
|
---|
9 | package org.greenstone.gsdlas;
|
---|
10 |
|
---|
11 | import java.io.UnsupportedEncodingException;
|
---|
12 | import java.net.URLEncoder;
|
---|
13 | import java.util.*;
|
---|
14 | import java.util.Map;
|
---|
15 | import java.util.Set;
|
---|
16 |
|
---|
17 | import org.greenstone.gsdlas.profiles.Subscription;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * @author schweer
|
---|
21 | *
|
---|
22 | * TODO To change the template for this generated type comment go to
|
---|
23 | * Window - Preferences - Java - Code Style - Code Templates
|
---|
24 | */
|
---|
25 | public class NotificationStore {
|
---|
26 |
|
---|
27 | private static NotificationStore instance;
|
---|
28 | private Map eventsForSubscriptionID = new TreeMap();
|
---|
29 |
|
---|
30 | private NotificationStore() {
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @return
|
---|
35 | */
|
---|
36 | public static NotificationStore getInstance() {
|
---|
37 | if (instance == null) instance = new NotificationStore();
|
---|
38 | return instance;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void add(Map event, Set subscriptions) {
|
---|
42 | encodeValues(event);
|
---|
43 | for (Iterator iter = subscriptions.iterator(); iter.hasNext();) {
|
---|
44 | Subscription sub = (Subscription) iter.next();
|
---|
45 | Integer subscriptionID = new Integer(sub.getId());
|
---|
46 | if (!eventsForSubscriptionID.containsKey(subscriptionID)) {
|
---|
47 | eventsForSubscriptionID.put(subscriptionID, new HashSet());
|
---|
48 | }
|
---|
49 | ((Set) eventsForSubscriptionID.get(subscriptionID)).add(event);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * @param event
|
---|
55 | */
|
---|
56 | private void encodeValues(Map event) {
|
---|
57 | for (Iterator iter = event.keySet().iterator(); iter.hasNext();) {
|
---|
58 | String key = (String) iter.next();
|
---|
59 | String value = (String) event.get(key);
|
---|
60 | String encodedValue = value.replace("&", "&");
|
---|
61 | encodedValue = encodedValue.replace("<", "<");
|
---|
62 | encodedValue = encodedValue.replace(">", ">");
|
---|
63 | encodedValue = encodedValue.replace("'", "'");
|
---|
64 | encodedValue = encodedValue.replace("\"", """);
|
---|
65 |
|
---|
66 | event.put(key, encodedValue);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * @param subscriptionID
|
---|
72 | * @return
|
---|
73 | */
|
---|
74 | public Set getEvents(Integer subscriptionID) {
|
---|
75 | if (eventsForSubscriptionID.containsKey(subscriptionID)) {
|
---|
76 | return Collections.unmodifiableSet((Set) eventsForSubscriptionID.get(subscriptionID));
|
---|
77 | }
|
---|
78 | return new TreeSet();
|
---|
79 | }
|
---|
80 |
|
---|
81 | }
|
---|