54 * |
59 * |
55 * </ul> |
60 * </ul> |
56 * |
61 * |
57 * @return the CommandMap |
62 * @return the CommandMap |
58 */ |
63 */ |
59 public static CommandMap getDefaultCommandMap() { |
64 public static synchronized CommandMap getDefaultCommandMap() { |
60 if (defaultCommandMap == null) |
65 if (defaultCommandMap != null) |
61 defaultCommandMap = new MailcapCommandMap(); |
66 return defaultCommandMap; |
62 |
67 |
63 return defaultCommandMap; |
68 // fetch per-thread-context-class-loader default |
|
69 ClassLoader tccl = SecuritySupport.getContextClassLoader(); |
|
70 CommandMap def = map.get(tccl); |
|
71 if (def == null) { |
|
72 def = new MailcapCommandMap(); |
|
73 map.put(tccl, def); |
|
74 } |
|
75 return def; |
64 } |
76 } |
65 |
77 |
66 /** |
78 /** |
67 * Set the default CommandMap. Reset the CommandMap to the default by |
79 * Set the default CommandMap. Reset the CommandMap to the default by |
68 * calling this method with <code>null</code>. |
80 * calling this method with <code>null</code>. |
69 * |
81 * |
70 * @param commandMap The new default CommandMap. |
82 * @param commandMap The new default CommandMap. |
71 * @exception SecurityException if the caller doesn't have permission |
83 * @exception SecurityException if the caller doesn't have permission |
72 * to change the default |
84 * to change the default |
73 */ |
85 */ |
74 public static void setDefaultCommandMap(CommandMap commandMap) { |
86 public static synchronized void setDefaultCommandMap(CommandMap commandMap) { |
75 SecurityManager security = System.getSecurityManager(); |
87 SecurityManager security = System.getSecurityManager(); |
76 if (security != null) { |
88 if (security != null) { |
77 try { |
89 try { |
78 // if it's ok with the SecurityManager, it's ok with me... |
90 // if it's ok with the SecurityManager, it's ok with me... |
79 security.checkSetFactory(); |
91 security.checkSetFactory(); |
80 } catch (SecurityException ex) { |
92 } catch (SecurityException ex) { |
81 // otherwise, we also allow it if this code and the |
93 // otherwise, we also allow it if this code and the |
82 // factory come from the same class loader (e.g., |
94 // factory come from the same (non-system) class loader (e.g., |
83 // the JAF classes were loaded with the applet classes). |
95 // the JAF classes were loaded with the applet classes). |
84 if (CommandMap.class.getClassLoader() != |
96 if (CommandMap.class.getClassLoader() == null || |
|
97 CommandMap.class.getClassLoader() != |
85 commandMap.getClass().getClassLoader()) |
98 commandMap.getClass().getClassLoader()) |
86 throw ex; |
99 throw ex; |
87 } |
100 } |
88 } |
101 } |
|
102 // remove any per-thread-context-class-loader CommandMap |
|
103 map.remove(SecuritySupport.getContextClassLoader()); |
89 defaultCommandMap = commandMap; |
104 defaultCommandMap = commandMap; |
90 } |
105 } |
91 |
106 |
92 /** |
107 /** |
93 * Get the preferred command list from a MIME Type. The actual semantics |
108 * Get the preferred command list from a MIME Type. The actual semantics |