001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * any nuclear facility.
035: */
036:
037: package com.sun.portal.community.notification;
038:
039: import java.util.Set;
040: import java.util.ResourceBundle;
041: import java.text.MessageFormat;
042:
043: import com.sun.portal.community.notification.NotificationType;
044:
045: public class Notification {
046:
047: //
048: // resource bundle lookup
049: //
050: public static final String SUBJECT_TEXT = ".subject";
051: public static final String SHORT_MESSAGE_TEXT = ".shortmsg";
052: public static final String MESSAGE_TEXT = ".msg";
053:
054: //
055: // private fields
056: //
057: private NotificationType _type;
058:
059: private String _sender;
060:
061: private Set _recipients;
062:
063: private ResourceBundle _rb;
064:
065: private String[] _args;
066:
067: public NotificationType getType() {
068:
069: return _type;
070: }
071:
072: public void setType(NotificationType type) {
073:
074: _type = type;
075: }
076:
077: public String getSender() {
078:
079: return _sender;
080: }
081:
082: public void setSender(String sender) {
083:
084: _sender = sender;
085: }
086:
087: public Set getRecipients() {
088:
089: return _recipients;
090: }
091:
092: public void setRecipients(Set recipients) {
093:
094: _recipients = recipients;
095: }
096:
097: public ResourceBundle getResourceBundle() {
098:
099: return _rb;
100: }
101:
102: public void setResourceBundle(ResourceBundle rb) {
103:
104: _rb = rb;
105: }
106:
107: public String[] getArguments() {
108:
109: return _args;
110: }
111:
112: public void setArguments(String[] args) {
113:
114: _args = args;
115: }
116:
117: public String getSubject() {
118:
119: return getLocalizedText(SUBJECT_TEXT);
120: }
121:
122: public String getMessage() {
123:
124: return getLocalizedText(MESSAGE_TEXT);
125: }
126:
127: public String getShortMessage() {
128:
129: return getLocalizedText(SHORT_MESSAGE_TEXT);
130: }
131:
132: public String toString() {
133:
134: StringBuffer sb = new StringBuffer();
135: sb.append("type=" + _type.toString());
136: sb.append(", sender=" + _sender);
137: sb.append(", recipients=" + _recipients);
138: sb.append(", subject=" + getSubject());
139: sb.append(", shortMessage=" + getShortMessage());
140: sb.append(", message=" + getMessage());
141:
142: return sb.toString();
143: }
144:
145: protected String getLocalizedText(String textType) {
146:
147: String text = _rb.getString(_type.toString() + textType);
148: if (text != null && text.length() > 0) {
149: text = MessageFormat.format(text, (Object[]) _args);
150: }
151: return text;
152: }
153: }
|