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.user.profile.impl.TerminalXmlFileProfilDataFactory;
00038 import org.openmobileis.common.util.PropertiesManager;
00039 import org.openmobileis.common.util.exception.ServiceException;
00040 import org.openmobileis.common.util.log.LogManager;
00041 import org.xmlpull.v1.XmlPullParserException;
00042
00053 public class TerminalProfileManager {
00054
00055 private static TerminalProfileManager manager;
00056
00057 private String profilFile;
00058
00059 private Profile profil = null;
00060
00061 private TerminalProfileManager() {
00062 profilFile = PropertiesManager.getManager().getProperty("org.openmobileis.profil.file");
00063 if (profilFile == null) {
00064 profilFile = System.getProperty("user.dir") + File.separator + "WEB-INF" + File.separator + "conf" + File.separator + "properties" + File.separator
00065 + "profildata.xml";
00066 }
00067 }
00068
00069 public static TerminalProfileManager getManager() {
00070 if (manager == null) {
00071 synchronized (org.openmobileis.modules.profiles.old.ProfileManager.class) {
00072 if (manager == null) {
00073 manager = new TerminalProfileManager();
00074 try {
00075 manager.parseFile();
00076 } catch (Throwable ex) {
00077 LogManager.traceError(0, ex);
00078 }
00079 }
00080 }
00081 }
00082 return manager;
00083 }
00084
00085 public void saveProfilFile(String fileData) throws ServiceException {
00086 try {
00087 FileWriter out = new FileWriter(this.profilFile);
00088 try {
00089 out.write(fileData.toCharArray());
00090 out.flush();
00091 } finally {
00092 out.close();
00093 }
00094 this.parseFile();
00095 } catch (Throwable ex) {
00096 throw new ServiceException(ex);
00097 }
00098 }
00099
00100 public Profile getProfil() {
00101 return profil;
00102 }
00103
00104 private void parseFile() throws IOException, XmlPullParserException {
00105 try {
00106 FileReader reader = new FileReader(this.profilFile);
00107 try {
00108 TerminalXmlFileProfilDataFactory parser = new TerminalXmlFileProfilDataFactory(reader);
00109 this.profil = parser.getParsedProfil();
00110 } finally {
00111 reader.close();
00112 }
00113 } catch (FileNotFoundException ex) {
00114 LogManager.traceWarning(0, "Warning Profil file not found.");
00115 }
00116
00117 }
00118 }