source: trunk/gli/src/org/greenstone/gatherer/Message.java@ 4436

Last change on this file since 4436 was 4363, checked in by kjdon, 21 years ago

re-tabbed the code for java

  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37
38
39
40
41
42
43package org.greenstone.gatherer;
44/**************************************************************************************
45 * Title: Gatherer
46 * Description: The Gatherer: a tool for gathering and enriching a digital collection.
47 * Copyright: Copyright (c) 2001
48 * Company: The University of Waikato
49 * Written: / /01
50 * Revised: 28/05/01
51 **************************************************************************************/
52import java.util.Date;
53import java.util.Random;
54/** Provides an event-type wrapper around a message for displaying to the user.
55 * @author John Thompson, Greenstone Digital Library, University of Waikato
56 * @version 2.1
57 */
58public class Message {
59 /** The level of this message. See above. */
60 public int level;
61 /** The source of this message. See above. */
62 public int source;
63 /** The age of this message. Used for ordering. */
64 public long time;
65 /** The actual message content of this message. */
66 public String message;
67 /** Used to indicate the source of the message is anywhere in general. */
68 static final public int GENERAL = 0;
69 /** Used to indicate the source of the message is the browsing methods. */
70 static final public int BROWSER = 1;
71 /** Used to indicate the source of the message is the mirroring methods. */
72 static final public int MIRRORING = 2;
73 /** Used to indicate the source of the message is the file collection methods. */
74 static final public int COLLECT = 3;
75 /** Used to indicate the source of the message is the metadata and set methods. */
76 static final public int METAEDIT = 4;
77 /** Used to indicate the source of the message is the building methods. */
78 static final public int BUILDING = 5;
79 /** Used to indicate the source of the message is the preview methods. */
80 static final public int FINAL = 6;
81 /** Used to indicate the source of the message is the log itself. */
82 static final public int LOG = 7;
83 /** Used to indicate the level of the message is Main. */
84 static final public int MAIN = 0;
85 /** Used to indicate the level of the message is Event. */
86 static final public int EVENT = 1;
87 /** Used to indicate the level of the message is Information. */
88 static final public int INFO = 2;
89 /** Used to indicate the level of the message is Error. */
90 static final public int ERROR = 3;
91
92 /**
93 * Creates a new message.
94 * @param source the source of this message as an <i>int</i>. See above.
95 * @param level the level of this message as an <i>int</i>. See above.
96 * @param message the message content of this message as a <strong>String</strong>.
97 */
98 public Message(int source, int level, String message) {
99 this.level = level;
100 this.source = source;
101 time = (new Date()).getTime();
102 this.message = message;
103 }
104 /**
105 * Used to display a message, stating level and source.
106 * @param gatherer the main <strong>Gatherer</strong> class, used to get at the Dictionary.
107 * @see org.greenstone.gatherer.Dictionary
108 */
109 public String toString(Gatherer gatherer) {
110 String source_str = "";
111 switch(source) {
112 case GENERAL:
113 source_str = gatherer.dictionary.get("Source.General");
114 break;
115 case BROWSER:
116 source_str = gatherer.dictionary.get("Source.Browser");
117 break;
118 case MIRRORING:
119 source_str = gatherer.dictionary.get("Source.Mirroring");
120 break;
121 case COLLECT:
122 source_str = gatherer.dictionary.get("Source.Collect");
123 break;
124 case METAEDIT:
125 source_str = gatherer.dictionary.get("Source.MetaEdit");
126 break;
127 case BUILDING:
128 source_str = gatherer.dictionary.get("Source.Building");
129 break;
130 default:
131 source_str = gatherer.dictionary.get("Source.Unknown");
132 }
133
134 String level_str = "";
135 switch(level) {
136 case MAIN:
137 level_str = gatherer.dictionary.get("Level.Main");
138 break;
139 case EVENT:
140 level_str = gatherer.dictionary.get("Level.Event");
141 break;
142 case INFO:
143 level_str = gatherer.dictionary.get("Level.Information");
144 break;
145 case ERROR:
146 level_str = gatherer.dictionary.get("Level.Error");
147 break;
148 default:
149 level_str = gatherer.dictionary.get("Level.Unknown");
150 }
151 return source_str + " " + level_str + " > " + message;
152 }
153 /** Used during testing testing to generate a random message.
154 * @return A new <strong>Message</strong> object which has a random source, level and a message body of the current system time.
155 */
156 static public Message random() {
157 Random generator = new Random();
158 int s = generator.nextInt(6);
159 int l = generator.nextInt(4);
160 String m = new Long(System.currentTimeMillis()).toString();
161 return new Message(s,l,m);
162 }
163}
Note: See TracBrowser for help on using the repository browser.