/Users/lyon/j4p/src/security/WebStartBean.java

1    package security; 
2     
3    import classUtils.reflection.Command; 
4    import gui.In; 
5    import gui.dialogs.BeanDialog; 
6    import xml.Utils; 
7     
8    import java.io.File; 
9    import java.io.Serializable; 
10   import java.security.KeyStore; 
11   import java.util.prefs.Preferences; 
12    
13   /** 
14    * Copyright DocJava, inc. 
15    * User: lyon 
16    * Date: Sep 3, 2004 
17    * Time: 9:12:18 AM 
18    */ 
19   public class WebStartBean implements Serializable { 
20       private String password = ""; 
21       private String vendor = ""; 
22       private String codeBase = ""; 
23       private String iconUrl = ""; 
24       private String hostUrl = ""; 
25       private String rootDirectory = ""; 
26       private String className = ""; 
27       private String keyStoreFile = ""; 
28       private String jarFileName = ""; 
29       private String alias = ""; 
30       private String webServer = ""; 
31       private String webServerUid = ""; 
32    
33       public WebStartBean() { 
34       } 
35    
36    
37    
38       public static WebStartBean fromXml(String xmlString) { 
39           return (WebStartBean) Utils.decodeXml(xmlString); 
40       } 
41    
42       public String toXml() { 
43           return Utils.toXml(this)+"</java>"; 
44       } 
45    
46       public String toString() { 
47           return "\npassword=" + password + 
48                   "\nvendor=" + vendor + 
49                   "\ncodeBase=" + codeBase + 
50                   "\niconUrl=" + iconUrl + 
51                   "\nhostUrl=" + hostUrl + 
52                   "\nrootDirectory=" + rootDirectory + 
53                   "\nclassName=" + className + 
54                   "\nkeyStoreFile=" + keyStoreFile + 
55                   "\njarFileName=" + jarFileName + 
56                   "\nalias=" + alias + 
57                   "\nwebServer=" + webServer + 
58                   "\nwebServerUid=" + webServerUid; 
59       } 
60    
61       public String getVendor() { 
62           return vendor; 
63       } 
64    
65       public void setVendor(String vendor) { 
66           this.vendor = vendor; 
67       } 
68    
69       public String getCodeBase() { 
70           return codeBase; 
71       } 
72    
73       public void setCodeBase(String codeBase) { 
74           this.codeBase = codeBase; 
75       } 
76    
77       public String getIconUrl() { 
78           return iconUrl; 
79       } 
80    
81       public void setIconUrl(String iconUrl) { 
82           this.iconUrl = iconUrl; 
83       } 
84    
85       public String getHostUrl() { 
86           return hostUrl; 
87       } 
88    
89       public void setHostUrl(String hostUrl) { 
90           this.hostUrl = hostUrl; 
91       } 
92    
93       public String getRootDirectory() { 
94           return rootDirectory; 
95       } 
96    
97       public void setRootDirectory(String rootDirectory) { 
98           this.rootDirectory = rootDirectory; 
99       } 
100   
101      public String getClassName() { 
102          return className; 
103      } 
104   
105      public void setClassName(String className) { 
106          this.className = className; 
107      } 
108   
109      public String getJarFileName() { 
110          return jarFileName; 
111      } 
112   
113      public void setJarFileName(String jarFileName) { 
114          this.jarFileName = jarFileName; 
115      } 
116   
117      public String getAlias() { 
118          return alias; 
119      } 
120   
121      public void setAlias(String alias) { 
122          this.alias = alias; 
123      } 
124   
125      public String getWebServer() { 
126          return webServer; 
127      } 
128   
129      public void setWebServer(String webServer) { 
130          this.webServer = webServer; 
131      } 
132   
133      public String getWebServerUid() { 
134          return webServerUid; 
135      } 
136   
137      public void setWebServerUid(String webServerUid) { 
138          this.webServerUid = webServerUid; 
139      } 
140   
141      public String getKeyStoreFile() { 
142          return keyStoreFile; 
143      } 
144   
145      public void setKeyStoreFile(String keyStoreFile) { 
146          this.keyStoreFile = keyStoreFile; 
147      } 
148   
149      private final static String key = "WebStartBean"; 
150   
151      public void saveInPreferences() { 
152          String s = toXml(); 
153          Preferences p = Preferences.userRoot(); 
154          p.put(key, s); 
155      } 
156   
157      public static WebStartBean getFromPreferences() { 
158          Preferences p = Preferences.userRoot(); 
159          String s = p.get(key, null); 
160          if (s==null) return WebStartBean.getDefaultWebStartBean(); 
161          return fromXml(s); 
162      } 
163   
164      public static void main(String[] args) { 
165          //testWebStartBean(); 
166          WebStartBean w2 = WebStartBean.getFromPreferences(); 
167          System.out.println("read from preferences"+w2.toXml()); 
168      } 
169   
170      private static void testWebStartBean() { 
171          WebStartBean wsb = new WebStartBean(); 
172          wsb.setAlias("docjava"); 
173          wsb.setClassName("security.WebStartBean"); 
174          wsb.setVendor("DocJava, Inc"); 
175          final String x = wsb.toXml(); 
176          System.out.println(x); 
177          wsb.saveInPreferences(); 
178      } 
179   
180      /** 
181       * Get WebStartBean and use a GUI 
182       * to prompt the USER. 
183       * 
184       * @return 
185       */ 
186      public static WebStartBean getDefaultWebStartBeanGUI() { 
187          BeanDialog dialog = new BeanDialog(WebStartBean.getFromPreferences()); 
188          dialog.pack(); 
189          dialog.show(); 
190          Object o = dialog.getData(); 
191          return (WebStartBean) o; 
192      } 
193   
194      public static WebStartBean getDefaultWebStartBean() { 
195          WebStartBean wsb = new WebStartBean(); 
196          String password = In.getPassword("enter keystore password"); 
197          wsb.setPassword(password); 
198          KeyStore ks = KeyUtils.getKeyStore(password); 
199          File ksf = KeyUtils.getKeystoreFile(); 
200          wsb.setKeyStoreFile(ksf.toString()); 
201          ks = KeyUtils.getKeyStore(ksf, password); 
202          wsb.setClassName(Command.getClassFromFile().getName()); 
203          wsb.setRootDirectory("/var/www/html/book/cgij/code/jnlp/"); 
204          wsb.setWebServer("192.168.1.95"); 
205          wsb.setWebServerUid("lyon"); 
206          wsb.setIconUrl("http://show.docjava.com:8086/" + 
207                  "consulti/docjava.jpe\""); 
208          wsb.setCodeBase("http://show.docjava.com:8086/" + 
209                  "book/cgij/code/jnlp/"); 
210          wsb.setAlias(KeyUtils.getAlias(ks)); 
211          wsb.setVendor("DocJava, Inc."); 
212          wsb.setJarFileName(wsb.getClassName() + ".jar"); 
213          wsb.setHostUrl("http://www.docjava.com"); 
214          return wsb; 
215      } 
216   
217      public String getPassword() { 
218          return password; 
219      } 
220   
221      public void setPassword(String password) { 
222          this.password = password; 
223      } 
224  } 
225