WikiDocumentDefaults defaults;
try {
Class<?> tplClass = Class.forName(templateType);
if (!TemplateRegistry.instance().getTemplateTypes().contains(tplClass)) {
throw new InvalidWikiRequestException("Invalid templateType: " + templateType);
}
if (tplClass.getAnnotation(WikiDocumentTemplate.class).requiresTemplateInstance()) {
getLog().debug("instantiating template " + tplClass.getName() + " with current document instance");
defaults = (WikiDocumentDefaults)tplClass.getConstructor(WikiDocument.class).newInstance(doc);
} else {
getLog().debug("instantiating template " + tplClass.getName() + " with no-arg constructor");
defaults = (WikiDocumentDefaults)tplClass.newInstance();
}
if (WikiDocumentEditorDefaults.class.isAssignableFrom(tplClass)) {
getLog().debug("letting template set editor defaults");
((WikiDocumentEditorDefaults)defaults).setEditorDefaults(this);
}
} catch (Exception ex) {
throw new InvalidWikiRequestException("Invalid templateType: " + templateType);
}
doc.setDefaults(defaults);
}
return doc;