KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > util > os > Shortcut


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 2002 Elmar Grom
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.util.os;
23
24 import java.io.UnsupportedEncodingException JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import com.izforge.izpack.installer.UninstallData;
28 import com.izforge.izpack.util.Debug;
29
30 /*---------------------------------------------------------------------------*/
31 /**
32  * This class represents a shortcut in a operating system independent way. OS specific subclasses
33  * are used to implement the necessary mapping from this generic API to the classes that reflect the
34  * system dependent AIP.
35  *
36  * @see com.izforge.izpack.util.TargetFactory
37  *
38  * @version 0.0.1 / 3/4/02
39  * @author Elmar Grom
40  */

41 public class Shortcut
42 {
43
44     // ------------------------------------------------------------------------
45
// Constant Definitions
46
// ------------------------------------------------------------------------
47
/** APPLICATIONS = 1 */
48     public static final int APPLICATIONS = 1;
49
50     /** START_MENU = 2 */
51     public static final int START_MENU = 2;
52
53     /** DESKTOP = 3 */
54     public static final int DESKTOP = 3;
55
56     /** START_UP = 4 */
57     public static final int START_UP = 4;
58
59     /** HIDE = 0 (Hide the window when starting.) */
60     public static final int HIDE = 0;
61
62     /**
63      * NORMAL = 1 Show the window 'normal' when starting. Usually restores the window properties at
64      * the last shut-down.
65      */

66     public static final int NORMAL = 1;
67
68     /** MINIMIZED = 2 */
69     public static final int MINIMIZED = 2;
70
71     /** MAXIMIZED = 3 (Show the window maximized when starting.) */
72     public static final int MAXIMIZED = 3;
73
74     /** CURRENT_USER = 1 (identifies the user type as the current user) */
75     public static final int CURRENT_USER = 1;
76
77     /** ALL_USERS = 2 (identifies the user type as valid for all users) */
78     public static final int ALL_USERS = 2;
79
80     /** indicates that this shortcut should be created for all users or only me * */
81     private Boolean JavaDoc createForAll;
82
83     /** internal field UninstallData uninstaller */
84     protected UninstallData uninstaller;
85
86     /*--------------------------------------------------------------------------*/
87     /**
88      * This method initializes the object. It is used as a replacement for the contructor because of
89      * the way it is instantiated through the <code>TargetFactory</code>.
90      *
91      * @param type the type or classification of the program group in which the link should exist.
92      * @param name the name of the shortcut.
93      */

94     public void initialize(int type, String JavaDoc name) throws Exception JavaDoc
95     {
96     }
97
98     /*--------------------------------------------------------------------------*/
99     /**
100      * Returns the base path of the shortcut depending on type. The base path is the directory that
101      * the short cut, (or its program group) will be created in. For instance, on Windows NT, a
102      * shortcut with user-type ALL_USERS, and link-type DESKTOP might have the base path
103      * "C:\Program&nbsp;Files\All&nbsp;Users\Desktop"
104      *
105      * @see #setLinkType(int)
106      * @see #setUserType(int)
107      */

108     public String JavaDoc getBasePath() throws Exception JavaDoc
109     {
110         return ("");
111     }
112
113     /*--------------------------------------------------------------------------*/
114     /**
115      * Returns a list of currently existing program groups, based on the requested type. For example
116      * if the type is <code>APPLICATIONS</code> then all the names of the program groups in the
117      * Start Menu\Programs menu would be returned.
118      *
119      * @param userType the type of user for the program group set.
120      *
121      * @return a <code>Vector</code> of <code>String</code> objects that represent the names of
122      * the existing program groups. It is theoretically possible that this list is empty.
123      *
124      * @see #APPLICATIONS
125      * @see #START_MENU
126      */

127     public Vector JavaDoc getProgramGroups(int userType)
128     {
129         return (null);
130     }
131
132     /*--------------------------------------------------------------------------*/
133     /**
134      * Subclass implementations return the fully qualified file name under which the link is saved
135      * on disk. <b>Note:</b> this method returns valid results only if the instance was created
136      * from a file on disk or after a successful save operation. An instance of this class returns
137      * an empty string.
138      *
139      * @return an empty <code>String</code>
140      */

141     public String JavaDoc getFileName()
142     {
143         return ("");
144     }
145
146     /*--------------------------------------------------------------------------*/
147     /**
148      * Subclass implementations return the path of the directory where the link file is stored, if
149      * it was necessary during the previous save operation to create the directory. This method
150      * returns <code>null</code> if no save operation was carried out or there was no need to
151      * create a directory during the previous save operation.
152      *
153      * @return this implementation returns always <code>null</code>.
154      */

155     public String JavaDoc getDirectoryCreated()
156     {
157         return (null);
158     }
159
160     /*--------------------------------------------------------------------------*/
161     /**
162      * Returns <code>true</code> if the target OS supports current user and all users.
163      *
164      * @return <code>true</code> if the target OS supports current and all users.
165      */

166     public boolean multipleUsers()
167     {
168         return (false);
169     }
170
171     /*--------------------------------------------------------------------------*/
172     /**
173      * Determines if a specific instance of this class supports the creation of shortcuts. The use
174      * of this method might seem odd, since one would not implement a flavor of this class that does
175      * not actually support the creation of shortcuts. In other words all flavors will in all
176      * probability return true. The only version that can be expected to return false is this class
177      * itself, since it has no actual implementation for shortcut creation. This is left to OS
178      * specific flavors. If the installer is launched on a unsupported OS there will be no
179      * appropriate flavor of this class, which will cause this class itself to be instantiated. The
180      * client code can now determine by calling this method if the active OS is supported and take
181      * appropriate action.
182      *
183      * @return <code>true</code> if the creation of shortcuts is supported, <code>false</code>
184      * if this is not supported.
185      */

186     public boolean supported()
187     {
188         return (false);
189     }
190
191     /*--------------------------------------------------------------------------*/
192     /**
193      * Sets the command line arguments that will be passed to the target when the link is activated.
194      *
195      * @param arguments the command line arguments
196      */

197     public void setArguments(String JavaDoc arguments)
198     {
199     }
200
201     /*--------------------------------------------------------------------------*/
202     /**
203      * Sets the description string that is used to identify the link in a menu or on the desktop.
204      *
205      * @param description the descriptiojn string
206      */

207     public void setDescription(String JavaDoc description)
208     {
209     }
210
211     /*--------------------------------------------------------------------------*/
212     /**
213      * Sets the location of the icon that is shown for the shortcut on the desktop.
214      *
215      * @param path a fully qualified file name of a file that contains the icon.
216      * @param index the index of the specific icon to use in the file. If there is only one icon in
217      * the file, use an index of 0.
218      */

219     public void setIconLocation(String JavaDoc path, int index)
220     {
221     }
222
223     /*--------------------------------------------------------------------------*/
224     /**
225      * returns icon Location
226      *
227      * @return iconLocation
228      */

229     public String JavaDoc getIconLocation()
230     {
231         return "";
232     }
233
234     /*--------------------------------------------------------------------------*/
235     /**
236      * Sets the name of the program group this ShellLinbk should be placed in.
237      *
238      * @param groupName the name of the program group
239      */

240     public void setProgramGroup(String JavaDoc groupName)
241     {
242     }
243
244     /*--------------------------------------------------------------------------*/
245     /**
246      * Sets the show command that is passed to the target application when the link is activated.
247      * The show command determines if the the window will be restored to the previous size,
248      * minimized, maximized or visible at all. <br>
249      * <br>
250      * <b>Note:</b><br>
251      * Using <code>HIDE</code> will cause the target window not to show at all. There is not even
252      * a button on the taskbar. This is a very useful setting when batch files are used to launch a
253      * Java application as it will then appear to run just like any native Windows application.<br>
254      *
255      * @param show the show command. Valid settings are: <br>
256      * <ul>
257      * <li>{@link com.izforge.izpack.util.os.Shortcut#HIDE}
258      * <li>{@link com.izforge.izpack.util.os.Shortcut#NORMAL}
259      * <li>{@link com.izforge.izpack.util.os.Shortcut#MINIMIZED}
260      * <li>{@link com.izforge.izpack.util.os.Shortcut#MAXIMIZED}
261      * </ul>
262      *
263      * @see #getShowCommand
264      */

265     public void setShowCommand(int show)
266     {
267     }
268
269     /*
270      * retrieves showCommand from the OS. Translates it into Shortcut.XXX terms.
271      */

272     public int getShowCommand()
273     {
274         return Shortcut.NORMAL;
275     }
276
277     /*--------------------------------------------------------------------------*/
278     /**
279      * Sets the absolute path to the shortcut target.
280      *
281      * @param path the fully qualified file name of the target
282      */

283     public void setTargetPath(String JavaDoc path)
284     {
285     }
286
287     /*--------------------------------------------------------------------------*/
288     /**
289      * Sets the working directory for the link target.
290      *
291      * @param dir the working directory
292      */

293     public void setWorkingDirectory(String JavaDoc dir)
294     {
295     }
296
297     /*--------------------------------------------------------------------------*/
298     /**
299      * Gets the working directory for the link target.
300      *
301      * @return the working directory.
302      */

303     public String JavaDoc getWorkingDirectory()
304     {
305         return "";
306     }
307
308     /*--------------------------------------------------------------------------*/
309     /**
310      * Sets the name shown in a menu or on the desktop for the link.
311      *
312      * @param name The name that the link should display on a menu or on the desktop. Do not include
313      * a file extension.
314      */

315     public void setLinkName(String JavaDoc name)
316     {
317     }
318
319     /*--------------------------------------------------------------------------*/
320     /**
321      * Gets the type of link types are: <br>
322      * <ul>
323      * <li>{@link com.izforge.izpack.util.os.Shortcut#DESKTOP}
324      * <li>{@link com.izforge.izpack.util.os.Shortcut#APPLICATIONS}
325      * <li>{@link com.izforge.izpack.util.os.Shortcut#START_MENU}
326      * <li>{@link com.izforge.izpack.util.os.Shortcut#START_UP}
327      * </ul>
328      */

329     public int getLinkType()
330     {
331         // fake default.
332
return Shortcut.DESKTOP;
333     }
334
335     /*--------------------------------------------------------------------------*/
336     /**
337      * Sets the type of link
338      *
339      * @param type The type of link desired. The following values can be set:<br>
340      * <ul>
341      * <li>{@link com.izforge.izpack.util.os.Shortcut#DESKTOP}
342      * <li>{@link com.izforge.izpack.util.os.Shortcut#APPLICATIONS}
343      * <li>{@link com.izforge.izpack.util.os.Shortcut#START_MENU}
344      * <li>{@link com.izforge.izpack.util.os.Shortcut#START_UP}
345      * </ul>
346      *
347      * @exception IllegalArgumentException if an an invalid type is passed
348      * @throws UnsupportedEncodingException
349      */

350     public void setLinkType(int type) throws IllegalArgumentException JavaDoc, UnsupportedEncodingException JavaDoc
351     {
352     }
353
354     /*--------------------------------------------------------------------------*/
355     /**
356      * Sets the user type for the link
357      *
358      * @param type the type of user for the link.
359      *
360      * @see #CURRENT_USER
361      * @see #ALL_USERS
362      */

363     public void setUserType(int type)
364     {
365     }
366
367     /*--------------------------------------------------------------------------*/
368     /**
369      * Gets the user type for the link
370      *
371      * @return userType
372      * @see #CURRENT_USER
373      * @see #ALL_USERS
374      */

375     public int getUserType()
376     {
377         return CURRENT_USER;
378     }
379
380     /*--------------------------------------------------------------------------*/
381     /**
382      * Saves this link.
383      *
384      * @exception Exception if problems are encountered
385      */

386     public void save() throws Exception JavaDoc
387     {
388     }
389
390     /*--------------------------------------------------------------------------*/
391     /**
392      * Gets the link hotKey
393      *
394      * @return int hotKey
395      */

396     public int getHotkey()
397     {
398         return 0;
399     }
400
401     /*--------------------------------------------------------------------------*/
402     /**
403      * Sets the link hotKey
404      *
405      * @param hotkey
406      */

407     public void setHotkey(int hotkey)
408     {
409     }
410
411     /**
412      * Sets the Encoding
413      *
414      * @param string
415      */

416     public void setEncoding(String JavaDoc string)
417     {
418     }
419
420     /**
421      * This sets the Mimetype
422      *
423      * @param string
424      */

425     public void setMimetype(String JavaDoc string)
426     {
427     }
428
429     /**
430      * Sets the terminal
431      *
432      * @param string
433      */

434     public void setTerminal(String JavaDoc string)
435     {
436     }
437
438     /**
439      * This sets the terminals-options
440      *
441      * @param string
442      */

443     public void setTerminalOptions(String JavaDoc string)
444     {
445     }
446
447     /**
448      * This sets the shortcut type
449      *
450      * @param string
451      */

452     public void setType(String JavaDoc string)
453     {
454     }
455
456     /**
457      * This sets the KdeUserName
458      *
459      * @param string The UserName
460      */

461     public void setKdeUserName(String JavaDoc string)
462     {
463     }
464
465     /**
466      * This sets the setKdeSubstUID
467      *
468      * @param string exactly &quot;true&quot; or &quot;false&quot; or nothing
469      */

470     public void setKdeSubstUID(String JavaDoc string)
471     {
472     }
473
474     /**
475      * This sets the URL
476      *
477      * @param string
478      */

479     public void setURL(String JavaDoc string)
480     {
481     }
482
483     /**
484      * Gets the Programs Folder for the given User. This is where to create subfolders or to place
485      * or create shortcuts.
486      *
487      * @param current_user one of current or all
488      *
489      * @return The Foldername or null on unsupported platforms.
490      */

491     public String JavaDoc getProgramsFolder(int current_user)
492     {
493         return null;
494     }
495
496     /**
497      * Sets the flag which indicates, that this should created for all.
498      *
499      * @param aCreateForAll A Flag - Set to true, if to create for All.
500      */

501     public void setCreateForAll(Boolean JavaDoc aCreateForAll)
502     {
503         this.createForAll = Boolean.valueOf(aCreateForAll.booleanValue());
504     }
505
506     /**
507      * Gets the create for All Flag
508      *
509      * @return Returns True if this should be for all.
510      */

511     public Boolean JavaDoc getCreateForAll()
512     {
513         return createForAll;
514     }
515
516     /**
517      * Sets the Categories Field On Unixes
518      *
519      * @param theCategories the categories
520      */

521     public void setCategories(String JavaDoc theCategories)
522     {
523     }
524
525     /**
526      * Sets the TryExecField on Unixes.
527      *
528      * @param aTryExec the try exec command
529      */

530     public void setTryExec(String JavaDoc aTryExec)
531     {
532     }
533
534     /**
535      * Sets the Uninstaller field with the unique Uninstaller Instance.
536      *
537      * @param theUninstaller the unique instance
538      */

539     public void setUninstaller(UninstallData theUninstaller)
540     {
541         uninstaller = theUninstaller;
542     }
543
544     /**
545      * Dummy Method especially for the Unix Root User.
546      *
547      */

548     public void execPostAction()
549     {
550         //Debug.log("Call of unused execPostAction Method in " + this.getClass().getName() );
551
}
552
553     /**
554      * Clean Up Method to do some cleanups after Shortcut Creation.
555      * <br>
556      * currently unused.
557      */

558     public void cleanUp()
559     {
560         //Debug.log("Call of unused cleanUp Method in " + this.getClass().getName() );
561
}
562
563 }
564 /*---------------------------------------------------------------------------*/
565
566
Popular Tags