aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/service/notification/NotificationData.java
blob: dd2bc8fa0313875807b9bbc47ed66846b652c6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.sip.communicator.service.notification;

import java.util.*;

/**
 * Object to cache fired notifications before all handler implementations are
 * ready registered.
 *
 * @author Ingo Bauersachs
 */
public class NotificationData
{
    /**
     * The name/key of the <tt>NotificationData</tt> extra which is provided to
     * {@link CommandNotificationHandler#execute(CommandNotificationAction,
     * Map)} i.e. a <tt>Map&lt;String,String&gt;</tt> which is known by the
     * (argument) name <tt>cmdargs</tt>.
     */
    public static final String COMMAND_NOTIFICATION_HANDLER_CMDARGS_EXTRA
        = "CommandNotificationHandler.cmdargs";

    /**
     * The name/key of the <tt>NotificationData</tt> extra which is provided to
     * {@link PopupMessageNotificationHandler#popupMessage(
     * PopupMessageNotificationAction, String, String, byte[], Object)} i.e. an
     * <tt>Object</tt> which is known by the (argument) name <tt>tag</tt>.
     */
    public static final String POPUP_MESSAGE_HANDLER_TAG_EXTRA
        = "PopupMessageNotificationHandler.tag";

    /**
     * The name/key of the <tt>NotificationData</tt> extra which is provided to
     * {@link SoundNotificationHandler} i.e. a <tt>Callable&lt;Boolean&gt;</tt>
     * which is known as the condition which determines whether looping sounds
     * are to continue playing.
     */
    public static final String SOUND_NOTIFICATION_HANDLER_LOOP_CONDITION_EXTRA
        = "SoundNotificationHandler.loopCondition";

    private final String eventType;

    /**
     * The {@link NotificationHandler}-specific extras provided to this
     * instance. The keys are among the <tt>XXX_EXTRA</tt> constants defined by
     * the <tt>NotificationData</tt> class.
     */
    private final Map<String, Object> extras;

    private final byte[] icon;
    private final String message;
    private final String title;

    /**
     * Creates a new instance of this class.
     *
     * @param eventType the type of the event that we'd like to fire a
     * notification for.
     * @param title the title of the given message
     * @param message the message to use if and where appropriate (e.g. with
     * systray or log notification.)
     * @param icon the icon to show in the notification if and where appropriate
     * @param extras additional/extra {@link NotificationHandler}-specific data
     * to be provided by the new instance to the various
     * <tt>NotificationHandler</tt>s
     */
    NotificationData(
            String eventType,
            String title,
            String message,
            byte[] icon,
            Map<String, Object> extras)
    {
        this.eventType = eventType;
        this.title = title;
        this.message = message;
        this.icon = icon;
        this.extras = extras;
    }

    /**
     * Gets the type of the event that we'd like to fire a notification for
     *
     * @return the eventType
     */
    public String getEventType()
    {
        return eventType;
    }

    /**
     * Gets the {@link NotificationHandler}-specific extras provided to this
     * instance.
     *
     * @return the <tt>NotificationHandler</tt>-specific extras provided to this
     * instance. The keys are among the <tt>XXX_EXTRA</tt> constants defined by
     * the <tt>NotificationData</tt> class
     */
    Map<String, Object> getExtras()
    {
        return Collections.unmodifiableMap(extras);
    }

    /**
     * Gets the {@link NotificationHandler}-specific extra provided to this
     * instance associated with a specific key.
     *
     * @param key the key whose associated <tt>NotificationHandler</tt>-specific
     * extra is to be returned. Well known keys are defined by the
     * <tt>NotificationData</tt> class as the <tt>XXX_EXTRA</tt> constants.
     * @return the <tt>NotificationHandler</tt>-specific extra provided to this
     * instance associated with the specified <tt>key</tt>
     */
    public Object getExtra(String key)
    {
        return (extras == null) ? null : extras.get(key);
    }

    /**
     * Gets the icon to show in the notification if and where appropriate.
     *
     * @return the icon
     */
    byte[] getIcon()
    {
        return icon;
    }

    /**
     * Gets the message to use if and where appropriate (e.g. with systray or
     * log notification).
     *
     * @return the message
     */
    String getMessage()
    {
        return message;
    }

    /**
     * Gets the title of the given message.
     *
     * @return the title
     */
    String getTitle()
    {
        return title;
    }
}