View Javadoc

1   /*
2    * This file is part of NetPisteur.
3    * 
4    * Copyright 2001-2002 : Olivier CORNEC, David BOUANCHEAU, Loic LOPEZ,
5    *                       Gatan BOUDARD, Mael LE LANNOU, Julien ROBINEAU
6    * 
7    * Copyright 2002-2003 : Olivier BRIENS, Simon DEZE, Florence FRIGOULT,
8    *                       Olivier JOURNEAULT, Francois MARTINIER, Damien RAUDE-MORVAN
9    * 
10   * Copyright 2004-2007 : Damien RAUDE-MORVAN
11   * 
12   * NetPisteur is free software; you can redistribute it and/or modify
13   * it under the terms of the GNU General Public License as published by
14   * the Free Software Foundation; either version 2 of the License, or
15   * (at your option) any later version.
16   *
17   * NetPisteur is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   * GNU General Public License for more details.
21   *
22   * You should have received a copy of the GNU General Public License
23   * along with NetPisteur; if not, write to the Free Software
24   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25   *
26   */
27  package com.drazzib.netpisteur.configuration;
28  
29  import java.io.BufferedInputStream;
30  import java.io.BufferedOutputStream;
31  import java.io.File;
32  import java.io.FileInputStream;
33  import java.io.FileOutputStream;
34  import java.io.IOException;
35  import java.io.InputStream;
36  import java.util.Properties;
37  
38  import org.apache.commons.logging.Log;
39  import org.apache.commons.logging.LogFactory;
40  
41  /**
42   * <P>
43   * <STRONG>Description </STRONG>
44   * <P>
45   * Represents an User
46   * 
47   * 
48   * @version 1.0
49   * @since 2002/03/19
50   * @author NetPisteurTeam
51   */
52  
53  public class Configuration {
54  	
55  	private static Log log = LogFactory.getLog(Configuration.class);
56  
57  	/**
58  	 * Represents the Cobaye studied
59  	 */
60  	private Cobaye cobaye;
61  
62  	/**
63  	 * Represents the proxy configuration
64  	 */
65  	private String proxyHost;
66  
67  	private String proxyPort;
68  
69  	private boolean proxyActif;
70  
71  	/**
72  	 * 
73  	 * CONFIG
74  	 * 
75  	 * 
76  	 */
77  
78  	private boolean timerActif = false;
79  
80  	private int timerHeure;
81  
82  	private int timerMinute;
83  
84  	private int timerSeconde;
85  
86  	private String rootNom;
87  
88  	private String rootPrenom;
89  
90  	private String rootPassword;
91  
92  	private String rootSeparator;
93  
94  	private String rootPage;
95  
96  	private String cobayeName;
97  
98  	private boolean mesureClick = true;
99  
100 	private boolean mesurePlacement = true;
101 
102 	private boolean mesureUrl = true;
103 
104 	private boolean mesureHL = true;
105 
106 	/**
107 	 * Represents the only one Configuration
108 	 */
109 	private static Configuration handle;
110 
111 	// /////////////////////////////////////
112 	// constructors of the class
113 
114 	/**
115 	 * Configuration() : 1st constructor
116 	 * 
117 	 */
118 
119 	private Configuration() {
120 
121 		this.cobaye = new Cobaye();
122 		this.proxyHost = "";
123 		this.proxyPort = "";
124 		this.proxyActif = false;
125 
126 	} // ---------------------------------------------Configuration()
127 
128 	/**
129 	 * method avoiding the doubled blooms We have to use it as a constructor
130 	 * 
131 	 * @return the current configuration
132 	 * 
133 	 */
134 
135 	public static Configuration getHandle() {
136 		if (handle == null) {
137 			handle = new Configuration();
138 		}
139 		return (handle);
140 	}
141 
142 	// /////////////////////////////////////
143 	// access methods for attributes
144 
145 	/**
146 	 * getProxyActif() : says if the proxy is used
147 	 * 
148 	 * @return boolean : true : use a proxy
149 	 */
150 	public boolean isProxyActif() {
151 		return this.proxyActif;
152 	}
153 
154 	/**
155 	 * getProxyHost() : says if the proxy is used
156 	 */
157 	public String getProxyHost() {
158 		return this.proxyHost;
159 	}
160 
161 	/**
162 	 * getProxyPort() : says if the proxy is used
163 	 */
164 	public String getProxyPort() {
165 		return this.proxyPort;
166 	}
167 
168 	/**
169 	 * getCobaye() : returns the studied Cobaye
170 	 * 
171 	 * @return Cobaye : Cobaye studied
172 	 */
173 
174 	public Cobaye getCobaye() {
175 		return this.cobaye;
176 	} // ------------------------------------------------------getCobaye()
177 
178 	// /////////////////////////////////////
179 	// modification methods for attributes
180 
181 	/**
182 	 * setProxyActif() : set true if the proxy is used
183 	 */
184 	public void setProxyActif(boolean p) {
185 		this.proxyActif = p;
186 	}
187 
188 	/**
189 	 * setProxyHost() : set true if the proxy is used
190 	 */
191 	public void setProxyHost(String p) {
192 		this.proxyHost = p;
193 	}
194 
195 	/**
196 	 * setProxyPort() : set true if the proxy is used
197 	 */
198 	public void setProxyPort(String p) {
199 		this.proxyPort = p;
200 	}
201 
202 	/**
203 	 * setCobaye(Cobaye unCobaye) : set the Cobaye to study
204 	 * 
205 	 * @param unCobaye :
206 	 *            Cobaye to study
207 	 */
208 
209 	public void setCobaye(Cobaye unCobaye) {
210 		this.cobaye = unCobaye;
211 	} // ------------------------------------------------------setCobaye()
212 
213 	// /////////////////////////////////////
214 	// operation
215 
216 	/**
217 	 * writeProxyConfToDisk() Method to write the proxy configuration in the
218 	 * proxyConf.dat file
219 	 * 
220 	 * @return boolean : success or failure
221 	 */
222 	public boolean writeProxyConfToDisk() {
223 
224 		boolean retour = false;
225 		Properties config = new Properties();
226 		BufferedOutputStream conffile;
227 
228 		try {
229 			config.setProperty("proxyActif", "" + this.proxyActif);
230 			config.setProperty("proxyHost", this.proxyHost);
231 			config.setProperty("proxyPort", this.proxyPort);
232 
233 			// Lecture de la config
234 			conffile = new BufferedOutputStream(new FileOutputStream(
235 					"conf/proxyConf.properties"));
236 			config.store(conffile, "Fichier de config du proxy");
237 
238 			retour = true;
239 		} catch (IOException e) {
240 			log.debug(e);
241 		}
242 
243 		return (retour);
244 
245 	} // ----------------------------------------------------writeProxyConfToDisk()
246 
247 	/**
248 	 * readProxyConfFromDisk() Method to read the proxy configuration in the
249 	 * proxyConf.dat file
250 	 * 
251 	 * @return boolean : success or failure
252 	 */
253 	public boolean readProxyConfFromDisk() {
254 
255 		boolean retour = false;
256 		Properties config = new Properties();
257 		BufferedInputStream conffile = null;
258 
259 		try {
260 			// Lecture de la config
261 			File conf = new File("conf/proxyConf.properties");
262 			if (conf.isFile()) {
263 				conffile = new BufferedInputStream(new FileInputStream(
264 						conf));
265 			} else {
266 				InputStream aResource = getClass()
267 				.getResourceAsStream(
268 				"/com/drazzib/netpisteur/conf/proxyConf.properties");
269 				if (aResource != null)
270 				conffile = new BufferedInputStream(aResource);
271 			}
272 			
273 			if (conffile != null)
274 			{
275 				config.load(conffile);
276 			}
277 
278 			if (config.getProperty("proxyActif") != null
279 					&& config.getProperty("proxyActif").equals("true")) {
280 				this.proxyActif = true;
281 			} else {
282 				this.proxyActif = false;
283 			}
284 			this.proxyHost = config.getProperty("proxyHost");
285 			this.proxyPort = config.getProperty("proxyPort");
286 			retour = true;
287 		} catch (java.io.IOException e) {
288 			log.error(e);
289 		}
290 
291 		return (retour);
292 
293 	} // ---------------------------------------- readProxyConfFromDisk()
294 
295 	public String getCobayeName() {
296 		return this.cobayeName;
297 	}
298 
299 	public void setCobayeName(String pcobayeName) {
300 		this.cobayeName = pcobayeName;
301 	}
302 
303 	public boolean isMesureClick() {
304 		return this.mesureClick;
305 	}
306 
307 	public void setMesureClick(boolean bMesureClick) {
308 		this.mesureClick = bMesureClick;
309 	}
310 
311 	public boolean isMesureHL() {
312 		return this.mesureHL;
313 	}
314 
315 	public void setMesureHL(boolean pmesureHL) {
316 		this.mesureHL = pmesureHL;
317 	}
318 
319 	public boolean isMesurePlacement() {
320 		return this.mesurePlacement;
321 	}
322 
323 	public void setMesurePlacement(boolean mesureMove) {
324 		this.mesurePlacement = mesureMove;
325 	}
326 
327 	public boolean isMesureURL() {
328 		return this.mesureUrl;
329 	}
330 
331 	public void setMesureURL(boolean pmesureUrl) {
332 		this.mesureUrl = pmesureUrl;
333 	}
334 
335 	public String getRootNom() {
336 		return this.rootNom;
337 	}
338 
339 	public void setRootNom(String prootNom) {
340 		this.rootNom = prootNom;
341 	}
342 
343 	public String getRootPage() {
344 		return this.rootPage;
345 	}
346 
347 	public void setRootPage(String prootPage) {
348 		this.rootPage = prootPage;
349 	}
350 
351 	public String getRootPassword() {
352 		return this.rootPassword;
353 	}
354 
355 	public void setRootPassword(String prootPassword) {
356 		this.rootPassword = prootPassword;
357 	}
358 
359 	public String getRootPrenom() {
360 		return this.rootPrenom;
361 	}
362 
363 	public void setRootPrenom(String prootPrenom) {
364 		this.rootPrenom = prootPrenom;
365 	}
366 
367 	public String getRootSeparator() {
368 		return this.rootSeparator;
369 	}
370 
371 	public void setRootSeparator(String prootSeparator) {
372 		this.rootSeparator = prootSeparator;
373 	}
374 
375 	public boolean isTimerActif() {
376 		return this.timerActif;
377 	}
378 
379 	public void setTimerActif(boolean ptimerActif) {
380 		this.timerActif = ptimerActif;
381 	}
382 
383 	public int getTimerHeure() {
384 		return this.timerHeure;
385 	}
386 
387 	public void setTimerHeure(int ptimerHeure) {
388 		this.timerHeure = ptimerHeure;
389 	}
390 
391 	public int getTimerMinute() {
392 		return this.timerMinute;
393 	}
394 
395 	public void setTimerMinute(int ptimerMinute) {
396 		this.timerMinute = ptimerMinute;
397 	}
398 
399 	public int getTimerSeconde() {
400 		return this.timerSeconde;
401 	}
402 
403 	public void setTimerSeconde(int ptimerSeconde) {
404 		this.timerSeconde = ptimerSeconde;
405 	}
406 
407 } // ----------------------------------------------------fin
408 // Configuration.java
409