errors.add("extract", new ActionMessage("error.template.prefix.empty"));
saveMessages(request, errors);
return actionMapping.findForward("error");
}
Template template = TemplateDAO.load(site.getSiteId(), templateName);
if (template != null) {
errors.add("extract", new ActionMessage("error.template.duplicate", templateName));
saveMessages(request, errors);
return actionMapping.findForward("error");
}
try {
if (!Format.isNullOrEmpty(form.getTemplateName())) {
File entry = new File(prefix);
entry.mkdir();
}
else {
InputStream stream = form.getFile().getInputStream();
JarInputStream jarStream = new JarInputStream(stream);
while (true) {
JarEntry entry = jarStream.getNextJarEntry();
if (entry == null) {
break;
}
String name = prefix + entry.getName();
if (entry.isDirectory()) {
File jarEntry = new File(name);
jarEntry.mkdirs();
continue;
}
FileOutputStream writer = new FileOutputStream(name);
byte[] buffer = new byte[1024];
while (true) {
int size = jarStream.read(buffer);
if (size <= 0) {
break;
}
writer.write(buffer, 0, size);
}
writer.close();
}
}
} catch (SecurityException e) {
errors.add("extract", new ActionMessage("error.file.create.invalid"));
saveMessages(request, errors);
return actionMapping.findForward("error");
} catch (FileNotFoundException e) {
errors.add("extract", new ActionMessage("error.file.create.invalid"));
saveMessages(request, errors);
return actionMapping.findForward("error");
} catch (Exception e) {
errors.add("extract", new ActionMessage("error.file.create.invalid"));
saveMessages(request, errors);
return actionMapping.findForward("error");
}
template = new Template();
template.setTemplateDesc(form.getTemplateDesc());
template.setRecCreateBy(adminBean.getUser().getUserId());
template.setRecCreateDatetime(new Date(System.currentTimeMillis()));
template.setTemplateName(templateName);
template.setSite(site);
template.setRecUpdateBy(adminBean.getUser().getUserId());
template.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
em.persist(template);
errors.add("info", new ActionMessage("message.template.created", templateName));
saveMessages(request, errors);
form.setTemplateName(template.getTemplateName());
form.setTemplateDesc(template.getTemplateDesc());
showDirectoryContent(request, form);
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);
ActionForward actionForward = actionMapping.findForward("success");
return actionForward;