View Javadoc

1   /***
2    * Created on July 24, 2006, Copyright UC Regents
3    */
4   package org.telscenter.pas.properties;
5   
6   import java.util.HashMap;
7   import java.util.Map;
8   
9   /***
10   * lookup table of common os values -> application; along with helper
11   * methods to start running well known native applications
12   * 
13   * @author jerrycheung
14   *
15   */
16  public class CommandMap {
17  	
18  	// common os.name
19  	private static final String MAC_OS_X = "Mac OS X";
20  	private static final String MAC_OS = "Mac OS";
21  	private static final String LINUX = "Linux";
22  	private static final String WINDOWS_XP = "Windows XP";
23  	private static final String WINDOWS_NT = "Windows NT";
24  	private static final String WINDOWS_2000 = "Windows 2000";
25  	
26  	public Map<String, String> osToCommands;
27  	
28  	private String osId;
29  	
30  	public CommandMap() {
31  		this.osId = System.getProperty("os.name"); // os.name for now
32  		initCommandMap();
33  	}
34  	
35  	/***
36  	 * populates map from application-type -> command
37  	 */
38  	// TODO: add in more common applications
39  	private void initCommandMap() {
40  		osToCommands = new HashMap<String, String>();
41  		osToCommands.put("DEFAULT", "open");
42  		
43  		if(osId.equals(WINDOWS_2000)) {
44  			
45  		} else if(osId.equals(WINDOWS_NT)) {
46  			
47  		} else if(osId.equals(WINDOWS_XP)) {
48  			
49  		} else if(osId.equals(LINUX)) {
50  			
51  		} else if(osId.equals(MAC_OS)) {
52  			
53  		} else if(osId.equals(MAC_OS_X)) {
54  			
55  		}
56  	}
57  
58  	/***
59  	 * @param type filetype associated with native application
60  	 * @return String of arguments to be used for Runtime.exec
61  	 */
62  	public String getCommand(String type) {
63  		if(osToCommands.containsKey(type)) {
64  			return osToCommands.get(type).toString();
65  		} else {
66  			System.err.println("Unknown application type, defaulting to 'open' command");
67  			return osToCommands.get("DEFAULT").toString();
68  		}
69  	}
70  	
71  	public void setCommand(String type, String command) {
72  		osToCommands.put(type, command);
73  	}
74  }
75