View Javadoc

1   /*
2   
3    * Copyright 2001-2004 The Apache Software Foundation.
4   
5    * 
6   
7    * Licensed under the Apache License, Version 2.0 (the "License");
8   
9    * you may not use this file except in compliance with the License.
10  
11   * You may obtain a copy of the License at
12  
13   * 
14  
15   *      http://www.apache.org/licenses/LICENSE-2.0
16  
17   * 
18  
19   * Unless required by applicable law or agreed to in writing, software
20  
21   * distributed under the License is distributed on an "AS IS" BASIS,
22  
23   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  
25   * See the License for the specific language governing permissions and
26  
27   * limitations under the License.
28  
29   */
30  
31  package org.apache.geronimo.ews.ws4j2ee.utils;
32  
33  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationConstants;
34  
35  import java.io.File;
36  import java.io.FileInputStream;
37  import java.io.FileNotFoundException;
38  import java.io.FileOutputStream;
39  import java.io.IOException;
40  import java.util.Properties;
41  
42  /***
43   * @author hemapani@opensource.lk
44   */
45  
46  public class PropertyStore {
47  
48      private Properties properties;
49  
50      private File file;
51  
52      public PropertyStore() throws Exception {
53          File baseDir = new File(".");
54          String path = baseDir.getCanonicalPath();
55          if (path.indexOf("geronimo")!=-1) {
56              File file2 = new File("./modules/axis/");
57              if(file2.exists()) {
58                  path = new File("./modules/axis/").getAbsolutePath();
59              }
60          }
61          file = new File(path, "target/" + GenerationConstants.WS4J2EE_PROPERTY_FILE);
62          file.getParentFile().mkdirs();
63          FileInputStream in = null;
64          System.out.println(file.getAbsolutePath() + " created .. ");
65          try {
66              properties = new Properties();
67              if (file.exists()) {
68                  in = new FileInputStream(file);
69                  properties.load(in);
70              }
71          } catch (FileNotFoundException e) {
72          } catch (IOException e) {
73          } finally {
74              try {
75                  if (in != null) {
76                      in.close();
77                  }
78              } catch (Exception e) {
79              }
80          }
81      }
82  
83      public void store(String repository) {
84          properties.setProperty(GenerationConstants.MAVEN_LOCAL_REPOSITARY, repository);
85          FileOutputStream out = null;
86          try {
87              out = new FileOutputStream(file);
88              properties.store(out, "repository Location");
89          } catch (FileNotFoundException e) {
90          } catch (IOException e) {
91          } finally {
92              try {
93                  if (out != null) {
94                      out.close();
95                  }
96              } catch (Exception e) {
97              }
98          }
99      }
100 
101     public static void main(String[] args) {
102         try {
103             PropertyStore store = new PropertyStore();
104             store.store(args[0]);
105         } catch (Exception e) {
106         }
107     }
108 
109 }
110