1 /*
2  * Copyright (C) Azureus Software, Inc, All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  *
16  */
17 package org.gudy.azureus2.core3.logging;
18 
19 import com.aelitis.azureus.core.util.GeneralUtils;
20 import org.gudy.azureus2.core3.config.COConfigurationManager;
21 import org.gudy.azureus2.pluginsimpl.local.PluginCoreUtils;
22 import java.util.ArrayList;
23 
24 /**
25  * @author TuxPaper
26  */
27 public class LogAlert implements org.gudy.azureus2.plugins.logging.LogAlert {
28 	// log types
29 	public static final int AT_INFORMATION = LogEvent.LT_INFORMATION;
30 
31 	public static final int AT_WARNING = LogEvent.LT_WARNING;
32 
33 	public static final int AT_ERROR = LogEvent.LT_ERROR;
34 
35 	public static final boolean REPEATABLE = true;
36 
37 	public static final boolean UNREPEATABLE = false;
38 
39 	public int entryType;
40 
41 	public Throwable err = null;
42 
43 	public boolean repeatable;
44 
45 	public String text;
46 
47 	/** A list of events that this entry is related to */
48 	public Object[] relatedTo;
49 
50 		// -1 -> default
51 	public int	timeoutSecs	= -1;
52 
53 	public String details;
54 
55 	public boolean forceNotify;
56 
57 	/**
58 	 * @param type
59 	 * @param text
60 	 * @param repeatable
61 	 */
LogAlert(boolean repeatable, int type, String text)62 	public LogAlert(boolean repeatable, int type, String text) {
63 		entryType = type;
64 		this.text = text;
65 		this.repeatable = repeatable;
66 	}
67 
68 	/**
69 	 * @param type
70 	 * @param text
71 	 * @param repeatable
72 	 * @param timeoutSecs  -1 -> use defaults 0 -> no timeout
73 	 */
LogAlert(boolean repeatable, int type, String text, int timeoutSecs)74 	public LogAlert(boolean repeatable, int type, String text, int timeoutSecs) {
75 		entryType = type;
76 		this.text = text;
77 		this.repeatable = repeatable;
78 		this.timeoutSecs = timeoutSecs;
79 	}
80 
LogAlert(Object[] relatedTo, boolean repeatable, int type, String text)81 	public LogAlert(Object[] relatedTo, boolean repeatable, int type, String text) {
82 		this(repeatable, type, text);
83 		this.relatedTo = relatedTo;
84 	}
85 
LogAlert(Object relatedTo, boolean repeatable, int type, String text)86 	public LogAlert(Object relatedTo, boolean repeatable, int type, String text) {
87 		this(repeatable, type, text);
88 		this.relatedTo = new Object[] { relatedTo };
89 	}
90 
LogAlert(boolean repeatable, String text, Throwable err)91 	public LogAlert(boolean repeatable, String text, Throwable err) {
92 		this(repeatable, AT_ERROR, text);
93 		this.err = err;
94 	}
95 
LogAlert(boolean repeatable, int type, String text, Throwable err)96 	public LogAlert(boolean repeatable, int type, String text, Throwable err) {
97 		this(repeatable, type, text);
98 		this.err = err;
99 	}
100 
101 	/**
102 	 * @param downloadManagerImpl
103 	 * @param b
104 	 * @param string
105 	 * @param e
106 	 */
LogAlert(Object relatedTo, boolean repeatable, String text, Throwable err)107 	public LogAlert(Object relatedTo, boolean repeatable,
108 			String text, Throwable err) {
109 		this(repeatable, text, err);
110 		this.relatedTo = new Object[] { relatedTo };
111 	}
112 
113 	// Plugin methods.
getGivenTimeoutSecs()114 	public int getGivenTimeoutSecs() {return timeoutSecs;}
getText()115 	public String getText() {return text;}
getError()116 	public Throwable getError() {return err;}
getType()117 	public int getType() {
118 		switch (entryType) {
119 			case AT_INFORMATION:
120 				return LT_INFORMATION;
121 			case AT_ERROR:
122 				return LT_ERROR;
123 			case AT_WARNING:
124 				return LT_WARNING;
125 			default:
126 				return LT_INFORMATION;
127 		}
128 	}
129 
getContext()130 	public Object[] getContext() {
131 		if (this.relatedTo == null) {return null;}
132 		ArrayList l = new ArrayList();
133 		for (int i=0; i<this.relatedTo.length; i++) {
134 			l.add(PluginCoreUtils.convert(this.relatedTo[i], false));
135 		}
136 		return l.toArray();
137 	}
138 
getTimeoutSecs()139 	public int getTimeoutSecs() {
140 		if (this.timeoutSecs != -1) {return this.timeoutSecs;}
141 		return COConfigurationManager.getIntParameter("Message Popup Autoclose in Seconds");
142 	}
143 
getPlainText()144 	public String getPlainText() {
145 		return GeneralUtils.stripOutHyperlinks(text);
146 	}
147 
148 }
149