Newer
Older
package org.josast.property;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;
/**
* <b>Description : This class allows to save data in a configuration file.</b>
* <br>
* for the JOSAST project the org.josast.config.databinding is prefered to this
* package for storing data.
*
* <p>
* Projet : JOSAST <BR>
*
* <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox <br>
* The aim of the project is to create a set of tools for amateur satellite
* purpose. All this tools could be used together to create specific software.
* <b>JOSAST</b> project is managed by AVMDTI
* (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) <br>
* This software is an open source software. Please read the <b><i>JOSAST
* licence</b></i><BR>
* (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
* for more information contact
* <a href="mailto:josast@avmdti.org">josast@avmdti.org</a>
* </p>
*
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
* @version 1.0
* <p>
* <b><i> Source Update </b></i>
* </p>
* <br>
* Version : date : name : comments <br>
* V1 : 3 mars 2004 : C. Mercier : create file <br>
* V2 : 01 mai 2019 : C. Mercier : Change log system
* <p>
private static Logger log = Logger.getLogger("AmsatLogger");
private Properties P = null;
private String fileName = "configuration.ini";
/** Constructeur priv� */
private CONFIG() {
}
private String getName() {
String path = System.getProperty("user.dir") + "/config";
File apath = new File(path);
if (!apath.exists()) {
boolean res = apath.mkdir();
if (!res) {
log.severe("fail to create " + path);
}
}
return path + "/" + fileName;
}
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
public String GetProperty(final String Item) {
if (P == null) {
try {
P = new Properties();
FileInputStream in = new FileInputStream(getName());
P.load(in);
in.close();
} catch (Exception e) {
log.severe("erreur ouverture fichier de configuration"); //$NON-NLS-1$
return null;
}
}
String S = P.getProperty(Item);
if (S == null) {
return null;
} else {
return S.trim(); // $NON-NLS-1$
}
}
/**
* Set a property into the file
*
*
* @param Item Item to store
* @param Valeur value to store
*
*/
public void SetProperty(final String Item, final String Valeur) {
if (P == null) {
P = new Properties();
try {
FileInputStream in = new FileInputStream(getName());
P.load(in);
in.close();
} catch (Exception e2) {
log.severe("Erreur de ouverture du fichier de configuration"); //$NON-NLS-1$
e2.printStackTrace();
}
}
P.put(Item, Valeur); // $NON-NLS-1$
FileOutputStream out = null;
try {
out = new FileOutputStream(getName());
} catch (FileNotFoundException e) {
log.severe("erreur cr�ation de fichier");
e.printStackTrace();
}
try {
P.store(out, null);
} catch (IOException e1) {
log.severe("erreur sauvegarde");
e1.printStackTrace();
}
try {
out.close();
} catch (IOException e3) {
log.severe("erreur de fermeture");
e3.printStackTrace();
}
}
/**
* Returns the nomFichier.
*
* @return String
*/
public String getFileName() {
return fileName;
}
/**
* Sets the nomFichier.
*
* @param nomfichier The nomFichier to set
*/
public void setFileName(final String nomfichier) {
fileName = nomfichier;
}