KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > event > SimpleInstallerListener


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2004 Klaus Bartz
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.event;
23
24 import java.io.File JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import com.izforge.izpack.LocaleDatabase;
28 import com.izforge.izpack.Pack;
29 import com.izforge.izpack.PackFile;
30 import com.izforge.izpack.installer.AutomatedInstallData;
31 import com.izforge.izpack.installer.ResourceManager;
32 import com.izforge.izpack.util.AbstractUIProgressHandler;
33 import com.izforge.izpack.util.SpecHelper;
34
35 /**
36  * <p>
37  * This class implements all methods of interface InstallerListener, but do not do anything. It can
38  * be used as base class to save implementation of unneeded methods.
39  * </p>
40  * <p>
41  * Additional there are some common helper methods which are used from the base class SpecHelper.
42  * </p>
43  *
44  * @author Klaus Bartz
45  *
46  */

47 public class SimpleInstallerListener implements InstallerListener
48 {
49
50     private static ArrayList JavaDoc progressBarCaller = new ArrayList JavaDoc();
51
52     /** The name of the XML file that specifies the panel langpack */
53     protected static final String JavaDoc LANG_FILE_NAME = "CustomActionsLang.xml";
54
55     /** The packs locale database. */
56     protected static LocaleDatabase langpack = null;
57
58     protected static boolean doInformProgressBar = false;
59
60     private AutomatedInstallData installdata = null;
61
62     private SpecHelper specHelper = null;
63
64     /**
65      * The default constructor.
66      */

67     public SimpleInstallerListener()
68     {
69         this(false);
70     }
71
72     /**
73      * Constructs a simple installer listener. If useSpecHelper is true, a specification helper will
74      * be created.
75      *
76      * @param useSpecHelper
77      *
78      */

79     public SimpleInstallerListener(boolean useSpecHelper)
80     {
81         super();
82         if (useSpecHelper) setSpecHelper(new SpecHelper());
83     }
84
85     /*
86      * (non-Javadoc)
87      *
88      * @see com.izforge.izpack.compiler.InstallerListener#handleFile(java.io.File,
89      * com.izforge.izpack.PackFile)
90      */

91     public void afterFile(File JavaDoc file, PackFile pf) throws Exception JavaDoc
92     {
93         // Do nothing
94
}
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see com.izforge.izpack.compiler.InstallerListener#handleDir(java.io.File,
100      * com.izforge.izpack.PackFile)
101      */

102     public void afterDir(File JavaDoc dir, PackFile pf) throws Exception JavaDoc
103     {
104         // Do nothing
105
}
106
107     /*
108      * (non-Javadoc)
109      *
110      * @see com.izforge.izpack.compiler.InstallerListener#afterPacks(com.izforge.izpack.installer.AutomatedInstallData,
111      * com.izforge.izpack.util.AbstractUIProgressHandler)
112      */

113     public void afterPacks(AutomatedInstallData idata, AbstractUIProgressHandler handler)
114             throws Exception JavaDoc
115     {
116
117         // Do nothing
118
}
119
120     /*
121      * (non-Javadoc)
122      *
123      * @see com.izforge.izpack.compiler.InstallerListener#afterPack(com.izforge.izpack.Pack, int,
124      * com.izforge.izpack.util.AbstractUIProgressHandler)
125      */

126     public void afterPack(Pack pack, Integer JavaDoc i, AbstractUIProgressHandler handler) throws Exception JavaDoc
127     {
128         // TODO Auto-generated method stub
129

130     }
131
132     /*
133      * (non-Javadoc)
134      *
135      * @see com.izforge.izpack.compiler.InstallerListener#beforePacks(com.izforge.izpack.installer.AutomatedInstallData,
136      * int, com.izforge.izpack.util.AbstractUIProgressHandler)
137      */

138     public void beforePacks(AutomatedInstallData idata, Integer JavaDoc npacks,
139             AbstractUIProgressHandler handler) throws Exception JavaDoc
140     {
141         if (installdata == null) installdata = idata;
142         if (installdata != null && SimpleInstallerListener.langpack == null)
143         {
144             // Load langpack.
145
try
146             {
147                 String JavaDoc resource = LANG_FILE_NAME + "_" + installdata.localeISO3;
148                 SimpleInstallerListener.langpack = new LocaleDatabase(ResourceManager.getInstance()
149                         .getInputStream(resource));
150             }
151             catch (Throwable JavaDoc exception)
152             {}
153
154         }
155     }
156
157     /*
158      * (non-Javadoc)
159      *
160      * @see com.izforge.izpack.compiler.InstallerListener#beforePack(com.izforge.izpack.Pack, int,
161      * com.izforge.izpack.util.AbstractUIProgressHandler)
162      */

163     public void beforePack(Pack pack, Integer JavaDoc i, AbstractUIProgressHandler handler)
164             throws Exception JavaDoc
165     {
166         // Do nothing
167
}
168
169     /*
170      * (non-Javadoc)
171      *
172      * @see com.izforge.izpack.installer.InstallerListener#isFileListener()
173      */

174     public boolean isFileListener()
175     {
176         // For default no.
177
return false;
178     }
179
180     /*
181      * (non-Javadoc)
182      *
183      * @see com.izforge.izpack.installer.InstallerListener#beforeFile(java.io.File,
184      * com.izforge.izpack.PackFile)
185      */

186     public void beforeFile(File JavaDoc file, PackFile pf) throws Exception JavaDoc
187     {
188         // Do nothing
189
}
190
191     /*
192      * (non-Javadoc)
193      *
194      * @see com.izforge.izpack.installer.InstallerListener#beforeDir(java.io.File,
195      * com.izforge.izpack.PackFile)
196      */

197     public void beforeDir(File JavaDoc dir, PackFile pf) throws Exception JavaDoc
198     {
199         // Do nothing
200
}
201
202     /**
203      * Returns current specification helper.
204      *
205      * @return current specification helper
206      */

207     public SpecHelper getSpecHelper()
208     {
209         return specHelper;
210     }
211
212     /**
213      * Sets the given specification helper to the current used helper.
214      *
215      * @param helper specification helper which should be used
216      */

217     public void setSpecHelper(SpecHelper helper)
218     {
219         specHelper = helper;
220     }
221
222     /**
223      * Returns the current installdata object.
224      *
225      * @return current installdata object
226      */

227     public AutomatedInstallData getInstalldata()
228     {
229         return installdata;
230     }
231
232     /**
233      * Sets the installdata object.
234      *
235      * @param data installdata object which should be set to current
236      */

237     public void setInstalldata(AutomatedInstallData data)
238     {
239         installdata = data;
240     }
241
242     /**
243      * Returns the count of listeners which are registered as progress bar caller.
244      *
245      * @return the count of listeners which are registered as progress bar caller
246      */

247     public static int getProgressBarCallerCount()
248     {
249         return (progressBarCaller.size());
250     }
251
252     /**
253      * Returns the progress bar caller id of this object.
254      *
255      * @return the progress bar caller id of this object
256      */

257     protected int getProgressBarCallerId()
258     {
259         for (int i = 0; i < progressBarCaller.size(); ++i)
260         {
261             if (progressBarCaller.get(i) == this) return (i + 1);
262         }
263         return (0);
264     }
265
266     /**
267      * Sets this object as progress bar caller.
268      */

269     protected void setProgressBarCaller()
270     {
271         progressBarCaller.add(this);
272
273     }
274
275     /**
276      * Returns whether this object should inform the progress bar or not.
277      *
278      * @return whether this object should inform the progress bar or not
279      */

280     protected boolean informProgressBar()
281     {
282         return (doInformProgressBar);
283     }
284
285     /**
286      * Returns the language dependant message from the resource CustomActionsLang.xml or the common
287      * language pack for the given id. If no string will be found, the id returns.
288      *
289      * @param id string id for which the message should be resolved
290      * @return the related language dependant message
291      */

292     protected String JavaDoc getMsg(String JavaDoc id)
293     {
294         String JavaDoc retval = id;
295         if (SimpleInstallerListener.langpack != null)
296         {
297             retval = SimpleInstallerListener.langpack.getString(id);
298         }
299         if (retval.equals(id) && getInstalldata() != null)
300         {
301             retval = getInstalldata().langpack.getString(id);
302         }
303         return (retval);
304     }
305 }
306
Popular Tags