View Javadoc

1   package org.opensync.engine.server;
2   
3   import java.io.*;
4   import java.util.*;
5   
6   import org.opensync.tools.Utils;
7   import org.opensync.engine.server.OpenSyncException;
8   
9   /***
10   * This object gives all the properties needed by the OpenSync application
11   */
12  
13  public class OpenSyncProps {
14    /***
15     * The log roll window in Ko (clean screen when reach)
16     *
17     *
18     */
19    protected int guiLogRollWindow;
20    /***
21     * The Task window will close when fihish
22     *
23     */
24    protected boolean guiTaskCloseWhenFinished;
25    /***
26     * The http port of the scheduler used to start a taks by a http request
27     *
28     */
29    protected int schedulerHttpPort;
30    /***
31     * The log level
32     *
33     *
34     */
35    protected String logLevel;
36  
37    /***
38     * The incremental mode for synchronisation
39     */
40    protected boolean incrementalMode;
41  
42    public boolean getIncrementalMode() {
43      return this.incrementalMode;
44    }
45  
46    protected String xsltProcessorProp;
47    protected String xmlParserProp;
48  
49    public String getXsltProcessorProp() {
50      return this.xsltProcessorProp;
51    }
52  
53    public String getXmlParserProp() {
54      return this.xmlParserProp;
55    }
56  
57    /***
58     * Construct a OpenSyncProps
59     *
60     */
61    public OpenSyncProps(){
62    }
63    /***
64     * Get the log roll window in Ko
65     *
66     */
67    public int getGuiLogRollWindow() {
68      return guiLogRollWindow;
69    }
70    /***
71     * Set the log roll window
72     *
73     * @param	guiLogRollWindow the roll window in Ko
74     */
75    public void setGuiLogRollWindow(int guiLogRollWindow) {
76      this.guiLogRollWindow = guiLogRollWindow;
77    }
78    /***
79     * Set it, if you want the Task window closed when fihish
80     *
81     * @param	guiTaskCloseWhenFinished
82     */
83    public void setGuiTaskCloseWhenFinished(boolean guiTaskCloseWhenFinished) {
84      this.guiTaskCloseWhenFinished = guiTaskCloseWhenFinished;
85    }
86    /***
87     * The Task window must be closed closed when fihish
88     *
89     */
90    public boolean isGuiTaskCloseWhenFinished() {
91      return guiTaskCloseWhenFinished;
92    }
93    /***
94     * Load the properties file
95     *
96     * @param	path the path of the properties file
97     * @exception	OpenSyncException
98     * @exception	IOException
99     */
100   public void loadProperties(String path)throws IOException,OpenSyncException{
101     Properties properties = new Properties();
102     properties.load(new FileInputStream(path));
103     String tmp;
104     tmp = properties.getProperty("gui.log.roll-window");
105     if(tmp == null){
106       throw new OpenSyncException("property.not-found",new Object[]{"gui.log.roll-window"});
107     }
108     logLevel = properties.getProperty("log.level");
109     if(logLevel == null){
110       throw new OpenSyncException("property.not-found",new Object[]{"log.level"});
111     }
112     try {
113       guiLogRollWindow = Integer.parseInt(tmp);
114     }
115     catch (NumberFormatException ex) {
116       throw new OpenSyncException("property.not-a-number",new Object[]{"gui.log.roll-window"});
117     }
118     tmp = properties.getProperty("scheduler.http-port");
119     if(tmp == null){
120       throw new OpenSyncException("property.not-found",new Object[]{"scheduler.http-port"});
121     }
122     try {
123       schedulerHttpPort = Integer.parseInt(tmp);
124     }
125     catch (NumberFormatException ex) {
126       throw new OpenSyncException("property.not-a-number",new Object[]{"scheduler.http-port"});
127     }
128     tmp = properties.getProperty("gui.task.close-when-finish");
129     if(tmp == null){
130       throw new OpenSyncException("property.not-found",new Object[]{"gui.task.close-when-finish"});
131     }
132     if(!(tmp.equalsIgnoreCase("true") || tmp.equalsIgnoreCase("false"))){
133       throw new OpenSyncException("property.not-a-boolean",new Object[]{"gui.task.close-when-finish"});
134     }
135     guiTaskCloseWhenFinished = tmp.equalsIgnoreCase("true");
136 
137     tmp = properties.getProperty("synchronizer.incremental");
138     if (tmp == null) {
139       throw new OpenSyncException("property.not-found",new Object[]{"synchronizer.incremental"});
140     }
141     if(!(tmp.equalsIgnoreCase("true") || tmp.equalsIgnoreCase("false"))){
142       throw new OpenSyncException("property.not-a-boolean",new Object[]{"synchronizer.incremental"});
143     }
144     incrementalMode= tmp.equalsIgnoreCase("true");
145 
146     tmp = properties.getProperty("javax.xml.transform.TransformerFactory");
147     if (tmp == null) {
148       // By default, use a JAXP compliant XSLT processor
149       this.xsltProcessorProp = "net.sf.saxon.TransformerFactoryImpl";
150     } else
151       this.xsltProcessorProp = tmp;
152 
153     tmp = properties.getProperty("javax.xml.parsers.SAXParserFactory");
154     if (tmp == null) {
155       // By default, use a JAXP compliant Xerces parser
156       this.xmlParserProp = "org.apache.xerces.jaxp.SAXParserFactoryImpl";
157     } else
158       this.xmlParserProp = tmp;
159 
160     tmp = properties.getProperty("utils.debug");
161     if (tmp == null) {
162       throw new OpenSyncException("property.not-found",new Object[]{"utils.debug"});
163     }
164     if(!(tmp.equalsIgnoreCase("true") || tmp.equalsIgnoreCase("false"))){
165       throw new OpenSyncException("property.not-a-boolean",new Object[]{"utils.debug"});
166     }
167     Utils.debug = tmp.equalsIgnoreCase("true");
168   }
169   /***
170    * Set the http scheduler port
171    *
172    * @param	schedulerHttpPort the http port
173    */
174   public void setSchedulerHttpPort(int schedulerHttpPort) {
175     this.schedulerHttpPort = schedulerHttpPort;
176   }
177   /***
178    * Get the http scheduler port
179    *
180    */
181   public int getSchedulerHttpPort() {
182     return schedulerHttpPort;
183   }
184   /***
185    * Set the level
186    *
187    * @param	logLevel the level
188    */
189   public void setLogLevel(String logLevel) {
190     this.logLevel = logLevel;
191   }
192   /***
193    * Get the level
194    *
195    */
196   public String getLogLevel() {
197     return logLevel;
198   }
199 /***
200  * @param incrementalMode The incrementalMode to set.
201  */
202 public void setIncrementalMode(boolean incrementalMode) {
203 	this.incrementalMode = incrementalMode;
204 }
205 /***
206  * @param xmlParserProp The xmlParserProp to set.
207  */
208 public void setXmlParserProp(String xmlParserProp) {
209 	this.xmlParserProp = xmlParserProp;
210 }
211 /***
212  * @param xsltProcessorProp The xsltProcessorProp to set.
213  */
214 public void setXsltProcessorProp(String xsltProcessorProp) {
215 	this.xsltProcessorProp = xsltProcessorProp;
216 }
217 }
218 
219 
220 
221