source: trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/NotificationStore.java@ 9874

Last change on this file since 9874 was 9874, checked in by kjdon, 19 years ago

merged from branch ant-install-branch: merge 1

  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
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 */
9package org.greenstone.gsdlas;
10
11import java.util.*;
12
13import org.greenstone.gsdlas.profiles.Subscription;
14
15/**
16 * @author schweer
17 *
18 * TODO To change the template for this generated type comment go to
19 * Window - Preferences - Java - Code Style - Code Templates
20 */
21public class NotificationStore {
22
23 private static NotificationStore instance;
24 private Map eventsForSubscriptionID = new TreeMap();
25
26 private NotificationStore() {
27 }
28
29 /**
30 * @return
31 */
32 public static NotificationStore getInstance() {
33 if (instance == null) instance = new NotificationStore();
34 return instance;
35 }
36
37 public void add(Map event, Set subscriptions) {
38 encodeValues(event);
39 for (Iterator iter = subscriptions.iterator(); iter.hasNext();) {
40 Subscription sub = (Subscription) iter.next();
41 Integer subscriptionID = new Integer(sub.getId());
42 if (!eventsForSubscriptionID.containsKey(subscriptionID)) {
43 eventsForSubscriptionID.put(subscriptionID, new HashSet());
44 }
45 ((Set) eventsForSubscriptionID.get(subscriptionID)).add(event);
46 }
47 }
48
49 /**
50 * @param event
51 */
52 private void encodeValues(Map event) {
53 for (Iterator iter = event.keySet().iterator(); iter.hasNext();) {
54 String key = (String) iter.next();
55 String value = (String) event.get(key);
56 String encodedValue = value.replaceAll("&", "&");
57 encodedValue = encodedValue.replaceAll("<", "&lt;");
58 encodedValue = encodedValue.replaceAll(">", "&gt;");
59 encodedValue = encodedValue.replaceAll("\'", "&apos;");
60 encodedValue = encodedValue.replaceAll("\"", "&quot;");
61
62 event.put(key, encodedValue);
63 }
64 }
65
66 /**
67 * @param subscriptionID
68 * @return
69 */
70 public Set getEvents(Integer subscriptionID) {
71 if (eventsForSubscriptionID.containsKey(subscriptionID)) {
72 return Collections.unmodifiableSet((Set) eventsForSubscriptionID.get(subscriptionID));
73 }
74 return new TreeSet();
75 }
76
77}
Note: See TracBrowser for help on using the repository browser.