KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > generator > DODSEjenProperties


1 package org.enhydra.dods.generator;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.FileOutputStream JavaDoc;
6 import java.util.Properties JavaDoc;
7 import org.enhydra.dods.Common;
8 import org.enhydra.dods.xml.XmlUtil;
9 import org.enhydra.dods.xml.XmlUtilException;
10
11 /**
12  * Generate DODS-Ejen.properties file
13  *
14  * @author Nenad Vico
15  * @version 1.0
16  */

17 public class DODSEjenProperties {
18     public static void main(String JavaDoc[] args) {
19         
20         String JavaDoc customTemplateDirStr = null;
21
22         try {
23             Properties JavaDoc dodswizard = new Properties JavaDoc();
24
25             dodswizard.setProperty("project.root", args[1]);
26             dodswizard.setProperty("doml.file", args[0]);
27             dodswizard.setProperty("doml.template", args[2]);
28             dodswizard.setProperty("database.vendor", args[3]);
29             dodswizard.setProperty("generate.force", args[4]);
30             dodswizard.setProperty("dods.config", Common.getConfigDir());
31             customTemplateDirStr = Common.getCustomTemplateDir();
32             int l = 0;
33             int k = 0;
34             int last = 0;
35
36             if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
37                 l = args[0].lastIndexOf("/");
38                 k = args[0].lastIndexOf("\\");
39                 if (l >= k) {
40                     last = l;
41                 } else {
42                     last = k;
43                 }
44             } else {
45                 last = args[0].lastIndexOf("/");
46             }
47             dodswizard.setProperty("doml.filename", args[0].substring(last + 1));
48         
49             File JavaDoc dodsEjenProperty = new File JavaDoc(Common.getDodsEjenPropertyFilename());
50
51             dodsEjenProperty.getParentFile().mkdirs();
52             dodswizard.store(new FileOutputStream JavaDoc(Common.getDodsEjenPropertyFilename()),
53                     "DODS Generator Wizard");
54             Properties JavaDoc dodsProperties = new Properties JavaDoc();
55             FileInputStream JavaDoc fisInstall = new FileInputStream JavaDoc(Common.getInstallProperties());
56
57             dodsProperties.load(fisInstall);
58             fisInstall.close();
59             dodsProperties.setProperty("current.user.dir",
60                     System.getProperties().getProperty("user.home"));
61             
62             String JavaDoc templateDir = null;
63
64             if (customTemplateDirStr != null) {
65                 templateDir = customTemplateDirStr;
66             } else {
67                 try {
68                     templateDir = XmlUtil.getSingleTextNode(Common.getConfigDir()
69                             + File.separator + "dodsConf.xml",
70                             "/dodsConf/TemplateDir", null);
71                 } catch (XmlUtilException ex) {}
72                    
73                 if (templateDir == null) {
74                     templateDir = Common.getDODSRoot() + File.separator
75                             + "template";
76                 }
77                    
78             }
79             dodsProperties.setProperty("template.dir", templateDir);
80             dodsProperties.store(new FileOutputStream JavaDoc(Common.getInstallProperties()),
81                     "DODS-EJEN INSTALL PROPERTIES");
82         } catch (Exception JavaDoc e) {
83             e.printStackTrace();
84         }
85     }
86 }
87
Popular Tags