//wraps request to get session object
ActionRequestImpl reqImpl = (ActionRequestImpl) req;
HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
//gets TemplateForm struts bean
TemplateForm cf = (TemplateForm) form;
Template newTemplate = new Template();
//gets the new information for the container from the request object
BeanUtils.copyProperties(newTemplate,form);
req.setAttribute(WebKeys.TEMPLATE_FORM_EDIT, newTemplate);
//gets the current template being edited from the request object
Template currentTemplate = (Template) req.getAttribute(WebKeys.TEMPLATE_EDIT);
//Retrieves the host were the template will be assigned to
Host host = hostAPI.find(cf.getHostId(), user, false);
boolean isNew = !InodeUtils.isSet(currentTemplate.getInode());
//Checking permissions
if (!isNew) {
_checkWritePermissions(currentTemplate, user, httpReq);
newTemplate.setIdentifier(currentTemplate.getIdentifier());
} else {
//If the asset is new checking that the user has permission to add children to the parent host
if(!permissionAPI.doesUserHavePermission(host, PermissionAPI.PERMISSION_CAN_ADD_CHILDREN, user, false)) {
SessionMessages.add(httpReq, "message", "message.insufficient.permissions.to.save");
throw new ActionException(WebKeys.USER_PERMISSIONS_EXCEPTION);
}
}
//gets user id from request for mod user
//gets file object for the thumbnail
if (InodeUtils.isSet(cf.getImage())) {
newTemplate.setImage(cf.getImage());
}
// *********************** BEGIN GRAZIANO issue-12-dnd-template
if(cmd.equals(Constants.ADD_DESIGN)){
newTemplate.setDrawed(true);
// create the body with all the main HTML tags
// Folder themeFolder = APILocator.getFolderAPI().find(newTemplate.getTheme(), user, false);
String themeHostId = APILocator.getFolderAPI().find(newTemplate.getTheme(), user, false).getHostId();
String themePath = null;
if(themeHostId.equals(host.getInode())) {
themePath = Template.THEMES_PATH + newTemplate.getThemeName() + "/";
} else {
Host themeHost = APILocator.getHostAPI().find(themeHostId, user, false);
themePath = "//" + themeHost.getHostname() + Template.THEMES_PATH + newTemplate.getThemeName() + "/";
}
StringBuffer endBody = DesignTemplateUtil.getBody(newTemplate.getBody(), newTemplate.getHeadCode(), themePath, cf.isHeaderCheck(), cf.isFooterCheck());
// set the drawedBody for future edit
newTemplate.setDrawedBody(newTemplate.getBody());
// set the real body
newTemplate.setBody(endBody.toString());
newTemplate.setHeadCode(cf.getHeadCode());
}
// *********************** END GRAZIANO issue-12-dnd-template
APILocator.getTemplateAPI().saveTemplate(newTemplate,host , user, false);