001/* 002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved. 003 * 004 * http://www.izforge.com/izpack/ 005 * http://developer.berlios.de/projects/izpack/ 006 * 007 * Copyright 2002 Elmar Grom 008 * 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 */ 021 022package com.izforge.izpack.util.os; 023 024import java.io.UnsupportedEncodingException; 025import java.util.Vector; 026 027/*---------------------------------------------------------------------------*/ 028/** 029 * This class represents a shortcut in a operating system independent way. OS specific subclasses 030 * are used to implement the necessary mapping from this generic API to the classes that reflect the 031 * system dependent AIP. 032 * 033 * @see com.izforge.izpack.util.TargetFactory 034 * 035 * @version 0.0.1 / 3/4/02 036 * @author Elmar Grom 037 */ 038public class Shortcut 039{ 040 041 // ------------------------------------------------------------------------ 042 // Constant Definitions 043 // ------------------------------------------------------------------------ 044 public static final int APPLICATIONS = 1; 045 046 public static final int START_MENU = 2; 047 048 public static final int DESKTOP = 3; 049 050 public static final int START_UP = 4; 051 052 /** Hide the window when starting. */ 053 public static final int HIDE = 0; 054 055 /** 056 * Show the window 'normal' when starting. Usually restores the window properties at the last 057 * shut-down. 058 */ 059 public static final int NORMAL = 1; 060 061 public static final int MINIMIZED = 2; 062 063 /** Show the window maximized when starting. */ 064 public static final int MAXIMIZED = 3; 065 066 /** identifies the user type as the current user */ 067 public static final int CURRENT_USER = 1; 068 069 /** identifies the user type as valid for all users */ 070 public static final int ALL_USERS = 2; 071 072 /** indicates that this shortcut should be created for all users or only me **/ 073 private Boolean createForAll; 074 075 /*--------------------------------------------------------------------------*/ 076 /** 077 * This method initializes the object. It is used as a replacement for the contructor because of 078 * the way it is instantiated through the <code>TargetFactory</code>. 079 * 080 * @param type the type or classification of the program group in which the link should exist. 081 * @param name the name of the shortcut. 082 */ 083 public void initialize(int type, String name) throws Exception 084 { 085 } 086 087 /*--------------------------------------------------------------------------*/ 088 /** 089 * Returns the base path of the shortcut depending on type. The base path is the directory that 090 * the short cut, (or its program group) will be created in. For instance, on Windows NT, a 091 * shortcut with user-type ALL_USERS, and link-type DESKTOP might have the base path 092 * "C:\Program Files\All Users\Desktop" 093 * 094 * @see #setLinkType(int) 095 * @see #setUserType(int) 096 */ 097 public String getBasePath() throws Exception 098 { 099 return (""); 100 } 101 102 /*--------------------------------------------------------------------------*/ 103 /** 104 * Returns a list of currently existing program groups, based on the requested type. For example 105 * if the type is <code>APPLICATIONS</code> then all the names of the program groups in the 106 * Start Menu\Programs menu would be returned. 107 * 108 * @param userType the type of user for the program group set. 109 * 110 * @return a <code>Vector</code> of <code>String</code> objects that represent the names of 111 * the existing program groups. It is theoretically possible that this list is empty. 112 * 113 * @see #APPLICATIONS 114 * @see #START_MENU 115 */ 116 public Vector getProgramGroups(int userType) 117 { 118 return (null); 119 } 120 121 /*--------------------------------------------------------------------------*/ 122 /** 123 * Subclass implementations return the fully qualified file name under which the link is saved 124 * on disk. <b>Note:</b> this method returns valid results only if the instance was created 125 * from a file on disk or after a successful save operation. An instance of this class returns 126 * an empty string. 127 * 128 * @return an empty <code>String</code> 129 */ 130 public String getFileName() 131 { 132 return (""); 133 } 134 135 /*--------------------------------------------------------------------------*/ 136 /** 137 * Subclass implementations return the path of the directory where the link file is stored, if 138 * it was necessary during the previous save operation to create the directory. This method 139 * returns <code>null</code> if no save operation was carried out or there was no need to 140 * create a directory during the previous save operation. 141 * 142 * @return this implementation returns always <code>null</code>. 143 */ 144 public String getDirectoryCreated() 145 { 146 return (null); 147 } 148 149 /*--------------------------------------------------------------------------*/ 150 /** 151 * Returns <code>true</code> if the target OS supports current user and all users. 152 * 153 * @return <code>true</code> if the target OS supports current and all users. 154 */ 155 public boolean multipleUsers() 156 { 157 return (false); 158 } 159 160 /*--------------------------------------------------------------------------*/ 161 /** 162 * Determines if a specific instance of this class supports the creation of shortcuts. The use 163 * of this method might seem odd, since one would not implement a flavor of this class that does 164 * not actually support the creation of shortcuts. In other words all flavors will in all 165 * probability return true. The only version that can be expected to return false is this class 166 * itself, since it has no actual implementation for shortcut creation. This is left to OS 167 * specific flavors. If the installer is launched on a unsupported OS there will be no 168 * appropriate flavor of this class, which will cause this class itself to be instantiated. The 169 * client code can now determine by calling this method if the active OS is supported and take 170 * appropriate action. 171 * 172 * @return <code>true</code> if the creation of shortcuts is supported, <code>false</code> 173 * if this is not supported. 174 */ 175 public boolean supported() 176 { 177 return (false); 178 } 179 180 /*--------------------------------------------------------------------------*/ 181 /** 182 * Sets the command line arguments that will be passed to the target when the link is activated. 183 * 184 * @param arguments the command line arguments 185 */ 186 public void setArguments(String arguments) 187 { 188 } 189 190 /*--------------------------------------------------------------------------*/ 191 /** 192 * Sets the description string that is used to identify the link in a menu or on the desktop. 193 * 194 * @param description the descriptiojn string 195 */ 196 public void setDescription(String description) 197 { 198 } 199 200 /*--------------------------------------------------------------------------*/ 201 /** 202 * Sets the location of the icon that is shown for the shortcut on the desktop. 203 * 204 * @param path a fully qualified file name of a file that contains the icon. 205 * @param index the index of the specific icon to use in the file. If there is only one icon in 206 * the file, use an index of 0. 207 */ 208 public void setIconLocation(String path, int index) 209 { 210 } 211 212 /*--------------------------------------------------------------------------*/ 213 /** 214 * returns icon Location 215 * 216 * @return iconLocation 217 */ 218 public String getIconLocation() 219 { 220 return ""; 221 } 222 223 /*--------------------------------------------------------------------------*/ 224 /** 225 * Sets the name of the program group this ShellLinbk should be placed in. 226 * 227 * @param groupName the name of the program group 228 */ 229 public void setProgramGroup(String groupName) 230 { 231 } 232 233 /*--------------------------------------------------------------------------*/ 234 /** 235 * Sets the show command that is passed to the target application when the link is activated. 236 * The show command determines if the the window will be restored to the previous size, 237 * minimized, maximized or visible at all. <br> 238 * <br> 239 * <b>Note:</b><br> 240 * Using <code>HIDE</code> will cause the target window not to show at all. There is not even 241 * a button on the taskbar. This is a very useful setting when batch files are used to launch a 242 * Java application as it will then appear to run just like any native Windows application.<br> 243 * 244 * @param show the show command. Valid settings are: <br> 245 * <ul> 246 * <li>{@link com.izforge.izpack.util.os.Shortcut#HIDE} 247 * <li>{@link com.izforge.izpack.util.os.Shortcut#NORMAL} 248 * <li>{@link com.izforge.izpack.util.os.Shortcut#MINIMIZED} 249 * <li>{@link com.izforge.izpack.util.os.Shortcut#MAXIMIZED} 250 * </ul> 251 * 252 * @see #getShowCommand 253 */ 254 public void setShowCommand(int show) 255 { 256 } 257 258 /* 259 * retrieves showCommand from the OS. Translates it into Shortcut.XXX terms. 260 */ 261 public int getShowCommand() 262 { 263 return Shortcut.NORMAL; 264 } 265 266 /*--------------------------------------------------------------------------*/ 267 /** 268 * Sets the absolute path to the shortcut target. 269 * 270 * @param path the fully qualified file name of the target 271 */ 272 public void setTargetPath(String path) 273 { 274 } 275 276 /*--------------------------------------------------------------------------*/ 277 /** 278 * Sets the working directory for the link target. 279 * 280 * @param dir the working directory 281 */ 282 public void setWorkingDirectory(String dir) 283 { 284 } 285 286 /*--------------------------------------------------------------------------*/ 287 /** 288 * Gets the working directory for the link target. 289 * 290 * @return the working directory. 291 */ 292 public String getWorkingDirectory() 293 { 294 return ""; 295 } 296 297 /*--------------------------------------------------------------------------*/ 298 /** 299 * Sets the name shown in a menu or on the desktop for the link. 300 * 301 * @param name The name that the link should display on a menu or on the desktop. Do not include 302 * a file extension. 303 */ 304 public void setLinkName(String name) 305 { 306 } 307 308 /*--------------------------------------------------------------------------*/ 309 /** 310 * Gets the type of link types are: <br> 311 * <ul> 312 * <li>{@link com.izforge.izpack.util.os.Shortcut#DESKTOP} 313 * <li>{@link com.izforge.izpack.util.os.Shortcut#APPLICATIONS} 314 * <li>{@link com.izforge.izpack.util.os.Shortcut#START_MENU} 315 * <li>{@link com.izforge.izpack.util.os.Shortcut#START_UP} 316 * </ul> 317 */ 318 public int getLinkType() 319 { 320 // fake default. 321 return Shortcut.DESKTOP; 322 } 323 324 /*--------------------------------------------------------------------------*/ 325 /** 326 * Sets the type of link 327 * 328 * @param type The type of link desired. The following values can be set:<br> 329 * <ul> 330 * <li>{@link com.izforge.izpack.util.os.Shortcut#DESKTOP} 331 * <li>{@link com.izforge.izpack.util.os.Shortcut#APPLICATIONS} 332 * <li>{@link com.izforge.izpack.util.os.Shortcut#START_MENU} 333 * <li>{@link com.izforge.izpack.util.os.Shortcut#START_UP} 334 * </ul> 335 * 336 * @exception IllegalArgumentException if an an invalid type is passed 337 * @throws UnsupportedEncodingException 338 */ 339 public void setLinkType(int type) throws IllegalArgumentException, UnsupportedEncodingException 340 { 341 } 342 343 /*--------------------------------------------------------------------------*/ 344 /** 345 * Sets the user type for the link 346 * 347 * @param type the type of user for the link. 348 * 349 * @see #CURRENT_USER 350 * @see #ALL_USERS 351 */ 352 public void setUserType(int type) 353 { 354 } 355 356 /*--------------------------------------------------------------------------*/ 357 /** 358 * Gets the user type for the link 359 * 360 * @return userType 361 * @see #CURRENT_USER 362 * @see #ALL_USERS 363 */ 364 public int getUserType() 365 { 366 return CURRENT_USER; 367 } 368 369 /*--------------------------------------------------------------------------*/ 370 /** 371 * Saves this link. 372 * 373 * @exception Exception if problems are encountered 374 */ 375 public void save() throws Exception 376 { 377 } 378 379 /*--------------------------------------------------------------------------*/ 380 /** 381 * Gets the link hotKey 382 * 383 * @return int hotKey 384 */ 385 public int getHotkey() 386 { 387 return 0; 388 } 389 390 /*--------------------------------------------------------------------------*/ 391 /** 392 * Sets the link hotKey 393 * 394 * @param hotkey 395 */ 396 public void setHotkey(int hotkey) 397 { 398 } 399 400 /** 401 * Sets the Encoding 402 * 403 * @param string 404 */ 405 public void setEncoding(String string) 406 { 407 } 408 409 /** 410 * This sets the Mimetype 411 * 412 * @param string 413 */ 414 public void setMimetype(String string) 415 { 416 } 417 418 /** 419 * Sets the terminal 420 * 421 * @param string 422 */ 423 public void setTerminal(String string) 424 { 425 } 426 427 /** 428 * This sets the terminals-options 429 * 430 * @param string 431 */ 432 public void setTerminalOptions(String string) 433 { 434 } 435 436 /** 437 * This sets the shortcut type 438 * 439 * @param string 440 */ 441 public void setType(String string) 442 { 443 } 444 445 /** 446 * This sets the KdeSubstUID 447 * 448 * @param string 449 */ 450 public void setKdeSubstUID(String string) 451 { 452 } 453 454 /** 455 * This sets the URL 456 * 457 * @param string 458 */ 459 public void setURL(String string) 460 { 461 } 462 463 /** 464 * Gets the Programs Folder for the given User. 465 * This is where to create subfolders or to place or create shortcuts. 466 * 467 * @param current_user one of current or all 468 * 469 * @return The Foldername or null on unsupported platforms. 470 */ 471 public String getProgramsFolder( int current_user ) 472 { 473 return null; 474 } 475 476 /** 477 * Sets the flag which indicates, that this should created for all. 478 * 479 * @param aCreateForAll A Flag - Set to true, if to create for All. 480 */ 481 public void setCreateForAll( Boolean aCreateForAll ) 482 { 483 this.createForAll = new Boolean( aCreateForAll.booleanValue( ) ); 484 } 485 486 /** 487 * Gets the create for All Flag 488 * 489 * @return Returns True if this should be for all. 490 */ 491 public Boolean getCreateForAll( ) 492 { 493 return createForAll; 494 } 495 496 497} 498/*---------------------------------------------------------------------------*/ 499