root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / event / SimpleInstallerListener.java @ 15280
History | View | Annotate | Download (8.14 KB)
1 |
/*
|
---|---|
2 |
* $Id: SimpleInstallerListener.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
3 |
* IzPack
|
4 |
* Copyright (C) 2004 Klaus Bartz
|
5 |
*
|
6 |
* File : SimpleInstallerListener.java
|
7 |
* Description : Simple custom action listener implementation for install time.
|
8 |
* Author's email : klaus.bartz@coi.de
|
9 |
* Author's Website : http://www.coi.de/
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
24 |
*/
|
25 |
|
26 |
package com.izforge.izpack.event; |
27 |
|
28 |
import java.io.File; |
29 |
import java.util.ArrayList; |
30 |
|
31 |
import com.izforge.izpack.LocaleDatabase; |
32 |
import com.izforge.izpack.Pack; |
33 |
import com.izforge.izpack.PackFile; |
34 |
import com.izforge.izpack.installer.AutomatedInstallData; |
35 |
import com.izforge.izpack.installer.ResourceManager; |
36 |
import com.izforge.izpack.util.AbstractUIProgressHandler; |
37 |
import com.izforge.izpack.util.SpecHelper; |
38 |
|
39 |
|
40 |
|
41 |
/**
|
42 |
* <p>This class implements all methods of interface
|
43 |
* InstallerListener, but do not do anything.
|
44 |
* It can be used as base class to save implementation
|
45 |
* of unneeded methods.</p>
|
46 |
* <p>Additional there are some common helper methods
|
47 |
* which are used from the base class SpecHelper.</p>
|
48 |
*
|
49 |
* @author Klaus Bartz
|
50 |
*
|
51 |
*/
|
52 |
public class SimpleInstallerListener implements InstallerListener |
53 |
{ |
54 |
|
55 |
private static ArrayList progressBarCaller = new ArrayList(); |
56 |
|
57 |
/** The name of the XML file that specifies the panel langpack */
|
58 |
protected static final String LANG_FILE_NAME = "CustomActionsLang.xml"; |
59 |
|
60 |
/** The packs locale database. */
|
61 |
protected static LocaleDatabase langpack = null; |
62 |
|
63 |
protected static boolean doInformProgressBar = false; |
64 |
|
65 |
private AutomatedInstallData installdata = null; |
66 |
private SpecHelper specHelper = null; |
67 |
|
68 |
/**
|
69 |
* The default constructor.
|
70 |
*/
|
71 |
public SimpleInstallerListener()
|
72 |
{ |
73 |
this(false); |
74 |
} |
75 |
|
76 |
/**
|
77 |
* Constructs a simple installer listener.
|
78 |
* If useSpecHelper is true, a specification helper will be
|
79 |
* created.
|
80 |
* @param useSpecHelper
|
81 |
*
|
82 |
*/
|
83 |
public SimpleInstallerListener(boolean useSpecHelper) |
84 |
{ |
85 |
super();
|
86 |
if( useSpecHelper )
|
87 |
setSpecHelper( new SpecHelper() );
|
88 |
} |
89 |
|
90 |
/* (non-Javadoc)
|
91 |
* @see com.izforge.izpack.compiler.InstallerListener#handleFile(java.io.File, com.izforge.izpack.PackFile)
|
92 |
*/
|
93 |
public void afterFile(File file, PackFile pf) |
94 |
throws Exception |
95 |
{ |
96 |
// Do nothing
|
97 |
; |
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see com.izforge.izpack.compiler.InstallerListener#handleDir(java.io.File, com.izforge.izpack.PackFile)
|
102 |
*/
|
103 |
public void afterDir(File dir, PackFile pf) |
104 |
throws Exception |
105 |
{ |
106 |
// Do nothing
|
107 |
; |
108 |
} |
109 |
|
110 |
/* (non-Javadoc)
|
111 |
* @see com.izforge.izpack.compiler.InstallerListener#afterPacks(com.izforge.izpack.installer.AutomatedInstallData, com.izforge.izpack.util.AbstractUIProgressHandler)
|
112 |
*/
|
113 |
public void afterPacks( |
114 |
AutomatedInstallData idata, |
115 |
AbstractUIProgressHandler handler) |
116 |
throws Exception |
117 |
{ |
118 |
|
119 |
// Do nothing
|
120 |
; |
121 |
} |
122 |
|
123 |
/* (non-Javadoc)
|
124 |
* @see com.izforge.izpack.compiler.InstallerListener#afterPack(com.izforge.izpack.Pack, int, com.izforge.izpack.util.AbstractUIProgressHandler)
|
125 |
*/
|
126 |
public void afterPack(Pack pack, Integer i, AbstractUIProgressHandler handler) |
127 |
throws Exception |
128 |
{ |
129 |
// TODO Auto-generated method stub
|
130 |
|
131 |
} |
132 |
|
133 |
/* (non-Javadoc)
|
134 |
* @see com.izforge.izpack.compiler.InstallerListener#beforePacks(com.izforge.izpack.installer.AutomatedInstallData, int, com.izforge.izpack.util.AbstractUIProgressHandler)
|
135 |
*/
|
136 |
public void beforePacks( |
137 |
AutomatedInstallData idata, |
138 |
Integer npacks,
|
139 |
AbstractUIProgressHandler handler) |
140 |
throws Exception |
141 |
{ |
142 |
if( installdata == null ) |
143 |
installdata = idata; |
144 |
if( installdata != null && SimpleInstallerListener.langpack == null) |
145 |
{ |
146 |
// Load langpack.
|
147 |
try
|
148 |
{ |
149 |
String resource = LANG_FILE_NAME + "_" + installdata.localeISO3; |
150 |
SimpleInstallerListener.langpack = |
151 |
new LocaleDatabase(ResourceManager.getInstance().getInputStream(resource));
|
152 |
} |
153 |
catch (Throwable exception) |
154 |
{} |
155 |
|
156 |
} |
157 |
} |
158 |
|
159 |
/* (non-Javadoc)
|
160 |
* @see com.izforge.izpack.compiler.InstallerListener#beforePack(com.izforge.izpack.Pack, int, com.izforge.izpack.util.AbstractUIProgressHandler)
|
161 |
*/
|
162 |
public void beforePack(Pack pack, Integer i, AbstractUIProgressHandler handler) |
163 |
throws Exception |
164 |
{ |
165 |
// Do nothing
|
166 |
; |
167 |
} |
168 |
|
169 |
/* (non-Javadoc)
|
170 |
* @see com.izforge.izpack.installer.InstallerListener#isFileListener()
|
171 |
*/
|
172 |
public boolean isFileListener() |
173 |
{ |
174 |
// For default no.
|
175 |
return false; |
176 |
} |
177 |
|
178 |
/* (non-Javadoc)
|
179 |
* @see com.izforge.izpack.installer.InstallerListener#beforeFile(java.io.File, com.izforge.izpack.PackFile)
|
180 |
*/
|
181 |
public void beforeFile(File file, PackFile pf) throws Exception |
182 |
{ |
183 |
// Do nothing
|
184 |
; |
185 |
} |
186 |
|
187 |
/* (non-Javadoc)
|
188 |
* @see com.izforge.izpack.installer.InstallerListener#beforeDir(java.io.File, com.izforge.izpack.PackFile)
|
189 |
*/
|
190 |
public void beforeDir(File dir, PackFile pf) throws Exception |
191 |
{ |
192 |
// Do nothing
|
193 |
; |
194 |
} |
195 |
|
196 |
/**
|
197 |
* Returns current specification helper.
|
198 |
* @return current specification helper
|
199 |
*/
|
200 |
public SpecHelper getSpecHelper()
|
201 |
{ |
202 |
return specHelper;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* Sets the given specification helper to the current used helper.
|
207 |
* @param helper specification helper which should be used
|
208 |
*/
|
209 |
public void setSpecHelper(SpecHelper helper) |
210 |
{ |
211 |
specHelper = helper; |
212 |
} |
213 |
|
214 |
/**
|
215 |
* Returns the current installdata object.
|
216 |
* @return current installdata object
|
217 |
*/
|
218 |
public AutomatedInstallData getInstalldata()
|
219 |
{ |
220 |
return installdata;
|
221 |
} |
222 |
|
223 |
/**
|
224 |
* Sets the installdata object.
|
225 |
* @param data installdata object which should be set to current
|
226 |
*/
|
227 |
public void setInstalldata(AutomatedInstallData data) |
228 |
{ |
229 |
installdata = data; |
230 |
} |
231 |
|
232 |
/**
|
233 |
* Returns the count of listeners which are registered as progress bar caller.
|
234 |
* @return the count of listeners which are registered as progress bar caller
|
235 |
*/
|
236 |
public static int getProgressBarCallerCount() |
237 |
{ |
238 |
return( progressBarCaller.size());
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* Returns the progress bar caller id of this object.
|
243 |
* @return the progress bar caller id of this object
|
244 |
*/
|
245 |
protected int getProgressBarCallerId() |
246 |
{ |
247 |
for( int i = 0; i < progressBarCaller.size(); ++i) |
248 |
{ |
249 |
if( progressBarCaller.get(i) == this ) |
250 |
return(i + 1); |
251 |
} |
252 |
return(0); |
253 |
} |
254 |
|
255 |
/**
|
256 |
* Sets this object as progress bar caller.
|
257 |
*/
|
258 |
protected void setProgressBarCaller() |
259 |
{ |
260 |
progressBarCaller.add(this);
|
261 |
|
262 |
} |
263 |
|
264 |
/**
|
265 |
* Returns whether this object should inform the progress bar or not.
|
266 |
* @return whether this object should inform the progress bar or not
|
267 |
*/
|
268 |
protected boolean informProgressBar() |
269 |
{ |
270 |
return( doInformProgressBar );
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* Returns the language dependant message from the resource
|
275 |
* CustomActionsLang.xml or the common language pack for the given id.
|
276 |
* If no string will be found, the id returns.
|
277 |
* @param id string id for which the message should be resolved
|
278 |
* @return the related language dependant message
|
279 |
*/
|
280 |
protected String getMsg(String id) |
281 |
{ |
282 |
String retval = id;
|
283 |
if( SimpleInstallerListener.langpack != null ) |
284 |
{ |
285 |
retval = SimpleInstallerListener.langpack.getString(id); |
286 |
} |
287 |
if( retval.equals(id) && getInstalldata() != null) |
288 |
{ |
289 |
retval = getInstalldata().langpack.getString(id); |
290 |
} |
291 |
return( retval);
|
292 |
} |
293 |
} |