00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 package org.openmobileis.module.profiles.terminal;
00029
00030 import java.io.File;
00031 import java.io.FileNotFoundException;
00032 import java.io.FileReader;
00033 import java.io.FileWriter;
00034 import java.io.IOException;
00035
00036 import org.openmobileis.common.user.profile.Profile;
00037 import org.openmobileis.common.util.PropertiesManager;
00038 import org.openmobileis.common.util.exception.ServiceException;
00039 import org.openmobileis.common.util.log.LogManager;
00040 import org.xmlpull.v1.XmlPullParserException;
00041
00052 public class TerminalProfileManager {
00053
00054 private static TerminalProfileManager manager;
00055
00056 private String profilFile;
00057
00058 private TerminalProfile profil = null;
00059
00060 private TerminalProfileManager() {
00061 profilFile = PropertiesManager.getManager().getProperty("org.openmobileis.profil.file");
00062 if (profilFile == null) {
00063 profilFile = System.getProperty("user.dir") + File.separator + "WEB-INF" + File.separator + "conf" + File.separator
00064 + "profildata.xml";
00065 }
00066 }
00067
00068 public String getProfileFilename() {
00069 return this.profilFile;
00070 }
00071
00072 public static TerminalProfileManager getManager() {
00073 if (manager == null) {
00074 synchronized (TerminalProfileManager.class) {
00075 if (manager == null) {
00076 manager = new TerminalProfileManager();
00077 try {
00078 manager.parseFile();
00079 } catch (Throwable ex) {
00080 LogManager.traceError(0, ex);
00081 }
00082 }
00083 }
00084 }
00085 return manager;
00086 }
00087
00088 public void saveProfilFile(String fileData) throws ServiceException {
00089 try {
00090 FileWriter out = new FileWriter(this.profilFile);
00091 try {
00092 out.write(fileData.toCharArray());
00093 out.flush();
00094 } finally {
00095 out.close();
00096 }
00097 this.parseFile();
00098 } catch (Throwable ex) {
00099 throw new ServiceException(ex);
00100 }
00101 }
00102
00103 public TerminalProfile getProfil() {
00104 return profil;
00105 }
00106
00107 private void parseFile() throws IOException, XmlPullParserException {
00108 try {
00109 FileReader reader = new FileReader(this.profilFile);
00110 try {
00111 TerminalXmlProfilParser parser = new TerminalXmlProfilParser(reader);
00112 this.profil = parser.parse();
00113 } finally {
00114 reader.close();
00115 }
00116 } catch (FileNotFoundException ex) {
00117 LogManager.traceWarning(0, "Warning Profil file not found.");
00118 }
00119
00120 }
00121 }