01: /*
02: * Created on 26 mars 2005
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package httpserver;
08:
09: import java.io.File;
10: import java.io.FileInputStream;
11: import java.io.FileNotFoundException;
12: import java.io.FileOutputStream;
13: import java.io.IOException;
14: import java.io.InputStream;
15: import java.io.OutputStream;
16: import java.util.Properties;
17:
18: /**
19: * @author Antoine
20: *
21: * TODO To change the template for this generated type comment go to
22: * Window - Preferences - Java - Code Style - Code Templates
23: */
24: public class Config extends Properties {
25:
26: private String commentaire = Serveur.NOM_SERVEUR
27: + "-Configuration File";
28:
29: public void setWWWDirectory(String directory) {
30: super .setProperty("WWWDirectory", directory);
31: }
32:
33: public String getWWWDirectory() {
34: return super .getProperty("WWWDirectory");
35: }
36:
37: public void setTypesMimeFile(String fileName) {
38: super .setProperty("TypesMime", fileName);
39: }
40:
41: public String getTypesMimeFile() {
42: return super .getProperty("TypesMime");
43: }
44:
45: public void setPort(int port) {
46: super .setProperty("Port", "" + port);
47: }
48:
49: public int getPort() {
50: return new Integer(super .getProperty("Port")).intValue();
51: }
52:
53: public void setDefaultPageName(String defaultPage) {
54: super .setProperty("DefaultPageName", defaultPage);
55: }
56:
57: public String getDefaultPageName() {
58: return super .getProperty("DefaultPageName");
59: }
60:
61: public void set404Page(String pageName) {
62: super .setProperty("404Page", pageName);
63: }
64:
65: public String get404Page() {
66: return super .getProperty("404Page");
67: }
68:
69: public boolean isCorrect() {
70: return ((this .getDefaultPageName() != null) && (this
71: .getWWWDirectory() != null));
72: }
73:
74: public void saveToFile(String xmlOutputFile) throws IOException,
75: Exception {
76: if (!this .isCorrect())
77: throw new Exception(
78: "La configuration n'est pas correcte : impossible de l'enregistree");
79:
80: OutputStream output = new FileOutputStream(new File(
81: xmlOutputFile));
82: super .storeToXML(output, this .commentaire);
83: output.close();
84: }
85:
86: public void getFromFile(String xmlInputFile)
87: throws FileNotFoundException, IOException, Exception {
88: InputStream input = new FileInputStream(new File(xmlInputFile));
89: super .loadFromXML(input);
90: if (!this .isCorrect())
91: throw new Exception("La configuration dans le fichier "
92: + xmlInputFile + " n'est pas correcte");
93: input.close();
94: }
95:
96: }
|