KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > nodes > CreateDefaultPropertyFile


1 /* $Id$
2  *
3  * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  */

15
16 //
17
// DESCRIPTION
18
//
19
// Peter Pilgrim
20
// Tue Jan 26 19:55:32 GMT 1999
21
//
22
// RCS HEADER ``CreateDefaultPropertyFile.java''
23
//
24
// $Author$
25
// $Date$
26
// $Source$
27
// $Revision$ $State$ $Locker$
28
//
29

30 package ixenon.free.nodes;
31
32 import java.io.*;
33 import java.util.*;
34 import java.awt.*;
35 import java.awt.event.*;
36
37 import javax.swing.*; // for JTree
38
import javax.swing.event.*; // for events
39
import javax.swing.tree.*; // MutableTreeNode
40

41 import ixenon.free.install.*; // for FreeInstallerApplication
42
import ixenon.free.swing.*; // for `ResetProgressBar' & `UpdateProgressBar'
43

44 /**
45  * An <code>Installable</code> node that creates a default
46  * property file for an Application.
47  */

48 public class CreateDefaultPropertyFile extends AbstractInstallable
49 implements Installable
50 {
51     public final static int SLEEP_TIME=125; // Sleep time
52

53     /** the target directory */
54     protected File targetDirectory;
55     /** the property filename */
56     protected String JavaDoc propFilename;
57     /** the prefix directory */
58     protected String JavaDoc prefixDir;
59     /** the executable prefix directory */
60     protected String JavaDoc execPrefixDir;
61     /** the image directory */
62     protected String JavaDoc imagesDir;
63     /** the audio directory */
64     protected String JavaDoc audioDir;
65     /** the URL */
66     protected String JavaDoc url;
67     
68     /**
69      * Construct a installable
70      *
71      * @param nodeName the name of the installable node
72      * @param destDir the destination directory
73      * @param propFilename the property filename
74      * @param execPrefixDir the execution prefix directory
75      * @param imagesDir the images directory
76      * @param audioDir the audio directory
77      * @param url the URL
78      */

79     public CreateDefaultPropertyFile ( String JavaDoc nodeName,
80                        String JavaDoc propFilename,
81                        String JavaDoc prefixDir,
82                        String JavaDoc execPrefixDir,
83                        String JavaDoc imagesDir,
84                        String JavaDoc audioDir,
85                        String JavaDoc url )
86     {
87     super( nodeName, null, true /*allowsChildren*/ );
88     if ( propFilename == null || prefixDir == null)
89         throw new IllegalArgumentException JavaDoc(
90         "illegal number arguments supplied." );
91
92     this.propFilename = propFilename;
93     this.prefixDir = prefixDir;
94     this.execPrefixDir = execPrefixDir != null ? execPrefixDir : prefixDir;
95     this.imagesDir = imagesDir != null ? imagesDir : "";
96     this.audioDir = audioDir != null? audioDir : "";
97     this.url = url != null ? url : "";
98     }
99     
100     /**
101      * create or retrieve the visual component of the installable
102      * if one exists. Otherwise return null.
103      */

104     public Component getVisualComponent()
105     {
106     return (null);
107     }
108     
109     /**
110      * create or retrieve the configurable component of the installable
111      * if one exists. Otherwise return null object.
112      */

113     public Component getConfigurableComponent()
114     {
115     return (null);
116     }
117
118     /**
119      * method to install by copying files from the source
120      * directory to target directory
121      *
122      * @exception <code>InstallException</code> if there is an
123      * problem trying to install the entity.
124      */

125     public void install() throws InstallException
126     {
127     FreeInstallerApplication theApp =
128         FreeInstallerApplication.getInstance();
129
130     targetDirectory = new File( new File(propFilename).getParent() );
131     if ( !targetDirectory.exists() )
132         targetDirectory.mkdirs();
133
134     if ( !targetDirectory.isDirectory() )
135         throw new InstallException(
136         "no such target directory:`"+targetDirectory.getAbsolutePath()+"'" );
137
138     // Get the selected files to copy
139
theApp.getProgressFrame().setStatusText( getNodeName() );
140
141     JProgressBar pbar = theApp.getProgressFrame().getProgressBarNode();
142     int index = 0;
143     SwingUtilities.invokeLater( new ResetProgressBar( pbar, 0, 1, 0 ) );
144     
145     // OLD CODE: pbar.setValue(j+1);
146
try { Thread.sleep(SLEEP_TIME); } catch (InterruptedException JavaDoc ie) { ; }
147
148     File dstFile = new File( propFilename );
149
150     // Check if file exists, if true then delete it.
151
if (dstFile.exists() )
152         dstFile.delete();
153     
154     PrintWriter pwriter=null;
155     FileWriter fwriter=null;
156     
157     String JavaDoc fileSep = System.getProperty("file.separator");
158     String JavaDoc pathSep = System.getProperty("path.separator");
159     
160     theApp.printInfo( "Creating default property file: `" + dstFile.getPath()+"'" );
161     // Add another one to the uninstallable
162
uninstallable.addFile( dstFile );
163
164     try {
165         fwriter = new FileWriter( dstFile );
166         pwriter = new PrintWriter( fwriter );
167
168         pwriter.println( "# Filename:`"+dstFile.getPath()+"'" );
169         pwriter.println( "#\n# DESCRIPTION:\n#\tA default application Java property file for:" );
170         pwriter.println( "#\t");
171         pwriter.println( "#\t " +theApp.getProductName() + " by " + theApp.getCompanyName() +" [c]" );
172         pwriter.println( "#\t");
173         pwriter.println( "#\tAutomagically generated by FreeInstaller V"+ApplicationVersion.getVersionString() );
174         pwriter.println( "#");
175         pwriter.println( "# WARNING: On Windows and OS/2 pathnames must be backslashified to protect");
176         pwriter.println( "# the file separator character (\\).");
177         pwriter.println( "#");
178         pwriter.println();
179         pwriter.println( "env.PREFIX="+InstallUtilities.getBackslashifiedPath(prefixDir) );
180         pwriter.println( "env.EXEC_PREFIX="+InstallUtilities.getBackslashifiedPath(execPrefixDir) );
181         pwriter.println( "env.AUDIO_DIR="+InstallUtilities.getBackslashifiedPath(audioDir) );
182         pwriter.println( "env.IMAGES_DIR="+InstallUtilities.getBackslashifiedPath(imagesDir) );
183         pwriter.println( "env.WEB_ROOT_URL="+InstallUtilities.getBackslashifiedPath(url) );
184         pwriter.println( "# UNCOMMENT the next line to get debug on application resources");
185         pwriter.println( "## env.DEBUG_RESOURCES=doit ");
186         pwriter.println();
187
188         pwriter.println( "# Modify the next line to alter the java file Search Path" );
189         pwriter.println( "# For example on a UNIX type operating system:" );
190         pwriter.println( "## env.JAVAFILESEARCHPATH=%N%S ; %T/%N%S ; %H/%T/%N%S ; %H/%N%S ; %P/%T/%N%S ; /usr/local/%T/%N%S ; /usr/local/%N%S ; %Z/%T/%N" );
191         pwriter.println();
192
193         // This part is more readable now. Basically we give
194
// precedence to internationalised resources. Those with
195
// %L/%T come before %T and before the default.
196
// Where %L is the locale language e.g `en_uk'
197
// and %T is the resource type e.g. `images'
198
// and %N%S represent a filename and suffix e.g `duke.gif'.
199
// and %H is the shorthand token for HOME.
200
// and %P is the shorthand token for the prefix.
201
//
202
String JavaDoc javaFileSearchPath =
203         "%T/%L/%N%S;" + "%T/%N%S;" + "%N%S;" +
204         "%H/%T/%L/%N%S;" + "%H/%T/%N%S;" + "%H/%N%S;" +
205         "%P/%L/%T/%N%S;" + "%P/%T/%N%S;" + "%P/%N%S;" +
206         prefixDir+"/%L/%T/%N%S;" +
207         prefixDir+"/%T/%N%S;" +
208         prefixDir+"/%N%S" ;
209         
210         pwriter.println( "env.JAVAFILESEARCHPATH="+InstallUtilities.getBackslashifiedPath(javaFileSearchPath) );
211         
212         pwriter.println();
213         pwriter.println( "# END");
214         pwriter.flush();
215         InstallUtilities.setFilePermissions( dstFile, InstallConstants.INST_RDWR_PERMS );
216     }
217     catch (IOException ioe) {
218         throw new InstallException(
219         "I/O exception occurred writing file:"+ targetDirectory.getPath()+
220         "\ndetails:"+ioe.getMessage() );
221     }
222     finally {
223         if (fwriter != null) try { fwriter.close(); } catch (Exception JavaDoc e) { ; }
224         if (pwriter != null) try { pwriter.close(); } catch (Exception JavaDoc e) { ; }
225     }
226
227     SwingUtilities.invokeLater( new UpdateProgressBar( pbar, ++index ) );
228     }
229
230     /** Create a Unix shell script launcher */
231     protected void createUnixShellScript() throws InstallException
232     {
233     }
234
235     /**
236      * method to perform the cleanup of content if cancelled, or aborted
237      */

238     public void cleanup() throws InstallException
239     {
240     // empty
241
}
242
243 }
244
245 // fini
246
Popular Tags