*
* @param type the content type
* @return the editor kit, or null if one cannot be created
*/
public EditorKit createEditorKitForContentType(String type) {
EditorKit k = null;
if (kitRegistry == null) {
// nothing has been loaded yet.
kitRegistry = new Hashtable();
} else {
k = (EditorKit) kitRegistry.get(type);
}
if (k == null) {
// try to dynamically load the support
HelpSet hs = model.getHelpSet();
String classname =
(String) hs.getKeyData(HelpSet.kitTypeRegistry,
type);
// I don't know of a class for this type
if (classname == null) {
return null;
}
ClassLoader loader =
(ClassLoader) hs.getKeyData(HelpSet.kitLoaderRegistry,
type);
if (loader == null) {
loader = hs.getLoader();
}
try {
Class c;
if (loader != null) {
c = loader.loadClass(classname);
} else {
c = Class.forName(classname);
}
k = (EditorKit) c.newInstance();
kitRegistry.put(type, k);
} catch (Throwable e) {
e.printStackTrace();
k = null;
}
}
// create a copy of the prototype or null if there
// is no prototype.
if (k != null) {
return (EditorKit) k.clone();
} else {
// null, check the JEditorPane registry
k = JEditorPane.createEditorKitForContentType(type);
}
return k;