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

Last change on this file since 8720 was 8720, checked in by schweer, 19 years ago

worked on web interface

  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 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.io.UnsupportedEncodingException;
12import java.net.URLEncoder;
13import java.util.*;
14import java.util.Map;
15import java.util.Set;
16
17import 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 */
25public 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("<", "&lt;");
62 encodedValue = encodedValue.replace(">", "&gt;");
63 encodedValue = encodedValue.replace("'", "&apos;");
64 encodedValue = encodedValue.replace("\"", "&quot;");
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}
Note: See TracBrowser for help on using the repository browser.