HibernateUtil.startTransaction();
User user = _getUser(req);
// Old template used to compare against edited version
Template oldTemplate = new Template();
try {
Logger.debug(this, "Calling Retrieve method");
_retrieveWebAsset(req, res, config, form, user, Template.class,
WebKeys.TEMPLATE_EDIT);
} catch (Exception ae) {
_handleException(ae, req);
return;
}
/*
* We are editing the Template
*/
if ((cmd != null) && cmd.equals(Constants.EDIT)) {
try {
Logger.debug(this, "Calling Edit method");
_editWebAsset(req, res, config, form, user);
} catch (Exception ae) {
if ((referer != null) && (referer.length() != 0)) {
if (ae.getMessage()!=null && ae.getMessage().equals(WebKeys.EDIT_ASSET_EXCEPTION)) {
//The web asset edit threw an exception because it's
// locked so it should redirect back with message
java.util.Map<String,String[]> params = new java.util.HashMap<String,String[]>();
params.put("struts_action",new String[] { "/ext/director/direct" });
params.put("cmd", new String[] { "editTemplate" });
params.put("template", new String[] { req.getParameter("inode") });
params.put("referer", new String[] { URLEncoder.encode(referer, "UTF-8") });
String directorURL = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq, WindowState.MAXIMIZED.toString(), params);
_sendToReferral(req, res, directorURL);
return;
}
}
_handleException(ae, req);
}
}
// *********************** BEGIN GRAZIANO issue-12-dnd-template
/*
* We are drawing the Template. In this case we call the _editWebAsset method but in the Template model creation we add the drawed property.
*/
if ((cmd != null) && cmd.equals(Constants.DESIGN)) {
try {
Logger.debug(this, "Calling Design method");
_editWebAsset(req, res, config, form, user);
} catch (Exception ae) {
if ((referer != null) && (referer.length() != 0)) {
if (ae.getMessage().equals(WebKeys.EDIT_ASSET_EXCEPTION)) {
//The web asset edit threw an exception because it's
// locked so it should redirect back with message
java.util.Map<String,String[]> params = new java.util.HashMap<String,String[]>();
params.put("struts_action",new String[] { "/ext/director/direct" });
params.put("cmd", new String[] { "editTemplate" });
params.put("template", new String[] { req.getParameter("inode") });
params.put("referer", new String[] { URLEncoder.encode(referer, "UTF-8") });
String directorURL = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq, WindowState.MAXIMIZED.toString(), params);
_sendToReferral(req, res, directorURL);
return;
}
}
_handleException(ae, req);
}
}
if ((cmd != null) && cmd.equals(Constants.ADD_DESIGN)) {
try {
if (Validator.validate(req, form, mapping)) {
Logger.debug(this, "Calling Save method for design template");
Logger.debug(this, "Calling Save method");
// the old template before editing using the inode from el request
oldTemplate = APILocator.getTemplateAPI().find(req.getParameter("inode"), user, false);
_saveWebAsset(req, res, config, form, user);
String subcmd = req.getParameter("subcmd");
if ((subcmd != null) && subcmd.equals(com.dotmarketing.util.Constants.PUBLISH)) {
Logger.debug(this, "Calling Publish method");
_publishWebAsset(req, res, config, form, user, WebKeys.TEMPLATE_FORM_EDIT);
if(!UtilMethods.isSet(referer)) {
java.util.Map<String, String[]> params = new java.util.HashMap<String, String[]>();
params.put("struts_action",new String[] {"/ext/templates/view_templates"});
referer = PortletURLUtil.getActionURL(req,WindowState.MAXIMIZED.toString(),params);
}
// edited template from the form
Template template = (Template) req.getAttribute(WebKeys.TEMPLATE_FORM_EDIT);
// call for invalidation on the live cache if the theme changed
if(template.isDrawed() && !template.getTheme().equals(oldTemplate.getTheme())){
APILocator.getTemplateAPI().invalidateTemplatePages(template.getInode(), user, false, false);
}
}
try{
_sendToReferral(req, res, referer);
return;
}
catch(Exception e){
java.util.Map<String,String[]> params = new java.util.HashMap<String,String[]>();
params.put("struts_action",new String[] { "/ext/templates/view_templates" });
String directorURL = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq, WindowState.MAXIMIZED.toString(), params);
_sendToReferral(req, res, directorURL);
return;
}
}
} catch (Exception ae) {
_handleException(ae, req);
}
}
// *********************** END GRAZIANO issue-12-dnd-template
/*
* If we are updating the Template, copy the information
* from the struts bean to the hbm inode and run the
* update action and return to the list
*/
if ((cmd != null) && cmd.equals(Constants.ADD)) {
try {
if (Validator.validate(req, form, mapping)) {
Logger.debug(this, "Calling Save method");
// the old template before editing using the inode from el request
oldTemplate = APILocator.getTemplateAPI().find(req.getParameter("inode"), user, false);
_saveWebAsset(req, res, config, form, user);
String subcmd = req.getParameter("subcmd");
if ((subcmd != null) && subcmd.equals(com.dotmarketing.util.Constants.PUBLISH)) {
Logger.debug(this, "Calling Publish method");
_publishWebAsset(req, res, config, form, user,
WebKeys.TEMPLATE_FORM_EDIT);
if(!UtilMethods.isSet(referer)) {
java.util.Map<String, String[]> params = new java.util.HashMap<String, String[]>();
params.put("struts_action",new String[] {"/ext/templates/view_templates"});
referer = PortletURLUtil.getActionURL(req,WindowState.MAXIMIZED.toString(),params);
}
// edited template from the form
Template template = (Template) req.getAttribute(WebKeys.TEMPLATE_FORM_EDIT);
// call for invalidation on the live cache if the theme changed
if(template.isDrawed() && !template.getTheme().equals(oldTemplate.getTheme())){
APILocator.getTemplateAPI().invalidateTemplatePages(template.getInode(), user, false, false);
}
}
try{
_sendToReferral(req, res, referer);
return;
}
catch(Exception e){
java.util.Map<String,String[]> params = new java.util.HashMap<String,String[]>();
params.put("struts_action",new String[] { "/ext/templates/view_templates" });
String directorURL = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq, WindowState.MAXIMIZED.toString(), params);
_sendToReferral(req, res, directorURL);
return;
}
}
} catch (Exception ae) {
_handleException(ae, req);
}
}
/*
* If we are deleteing the Template,
* run the delete action and return to the list
*
*/
else if ((cmd != null) && cmd.equals(Constants.DELETE)) {
try {
Logger.debug(this, "Calling Delete method");
_deleteWebAsset(req, res, config, form, user,
WebKeys.TEMPLATE_EDIT);
} catch (Exception ae) {
_handleException(ae, req);
return;
}
_sendToReferral(req, res, referer);
}
else if ((cmd != null) && cmd.equals(com.dotmarketing.util.Constants.FULL_DELETE))
{
try
{
Logger.debug(this,"Calling Full Delete Method");
WebAsset webAsset = (WebAsset) req.getAttribute(WebKeys.TEMPLATE_EDIT);
if(WebAssetFactory.deleteAsset(webAsset,user)) {
SessionMessages.add(httpReq, "message", "message." + webAsset.getType() + ".full_delete");
} else {
SessionMessages.add(httpReq, "error", "message." + webAsset.getType() + ".full_delete.error");
}
}
catch(Exception ae)
{
_handleException(ae, req);
return;
}
_sendToReferral(req, res, referer);
}
else if ((cmd != null) && cmd.equals(com.dotmarketing.util.Constants.FULL_DELETE_LIST))
{
try
{
Logger.debug(this,"Calling Full Delete Method");
String [] inodes = req.getParameterValues("publishInode");
StringBuilder dependencies = new StringBuilder();
boolean returnValue = false;
for(String inode : inodes) {
String result = APILocator.getTemplateAPI().checkDependencies(inode, user, false);
WebAsset webAsset = (WebAsset) InodeFactory.getInode(inode,Template.class);
if(UtilMethods.isSet(result)) {
dependencies.append(LanguageUtil.get(user, "template-name")).append(": ").append(webAsset.getFriendlyName()).append("\n");
dependencies.append(LanguageUtil.get(user, "Pages-URLs")).append(": ").append(result);
} else {
returnValue = WebAssetFactory.deleteAsset(webAsset,user);
}
dependencies.append("\n");
}
if(returnValue)
{
SessionMessages.add(httpReq,"message","message.template.full_delete");
}
else
{
SessionMessages.add(httpReq,"error","message.template.full_delete.error");
Logger.debug(this," Template cannot be deleted if it has existing relationships");
}
}
catch(Exception ae)
{
SessionMessages.add(httpReq,"error","message.template.full_delete.error");
_handleException(ae, req);
return;
}
_sendToReferral(req, res, referer);
}
/*
* If we are undeleting the Template,
* run the undelete action and return to the list
*
*/
else if ((cmd != null)
&& cmd.equals(com.dotmarketing.util.Constants.UNDELETE)) {
try {
Logger.debug(this, "Calling UnDelete method");
_undeleteWebAsset(req, res, config, form, user,
WebKeys.TEMPLATE_EDIT);
} catch (Exception ae) {
_handleException(ae, req);
return;
}
_sendToReferral(req, res, referer);
}
/*
* If we are deleting the Template version,
* run the deeleteversion action and return to the list
*/
else if ((cmd != null)
&& cmd.equals(com.dotmarketing.util.Constants.DELETEVERSION)) {
try {
Logger.debug(this, "Calling Delete Version Method");
_deleteVersionWebAsset(req, res, config, form, user,
WebKeys.TEMPLATE_EDIT);
} catch (Exception ae) {
_handleException(ae, req);
return;
}
_sendToReferral(req, res, referer);
}
/*
* If we are unpublishing the Template,
* run the unpublish action and return to the list
*/
else if ((cmd != null)
&& cmd.equals(com.dotmarketing.util.Constants.UNPUBLISH)) {
try {
Logger.debug(this, "Calling Unpublish Method");
_unPublishWebAsset(req, res, config, form, user,
WebKeys.TEMPLATE_EDIT);
} catch (Exception ae) {
_handleException(ae, req);
return;
}
_sendToReferral(req, res, referer);
}
/*
* If we are getting the Template version back,
* run the getversionback action and return to the list
*/
else if ((cmd != null)
&& cmd.equals(com.dotmarketing.util.Constants.GETVERSIONBACK)) {
try {
Logger.debug(this, "Calling Get Version Back Method");
_getVersionBackWebAsset(req, res, config, form, user);
} catch (Exception ae) {
_handleException(ae, req);
}
_sendToReferral(req, res, referer);
}
/*
* If we are getting the Template versions,
* run the assetversions action and return to the list
*/
else if ((cmd != null)
&& cmd.equals(com.dotmarketing.util.Constants.ASSETVERSIONS)) {
try {
Logger.debug(this, "Calling Get Versions Method");
_getVersionsWebAsset(req, res, config, form, user,
WebKeys.TEMPLATE_EDIT, WebKeys.TEMPLATE_VERSIONS);
} catch (Exception ae) {
_handleException(ae, req);
return;
}
}
/*
* If we are unlocking the Template,
* run the unlock action and return to the list
*/
else if ((cmd != null)
&& cmd.equals(com.dotmarketing.util.Constants.UNLOCK)) {
try {
Logger.debug(this, "Calling Unlock Method");
_unLockWebAsset(req, res, config, form, user,
WebKeys.TEMPLATE_EDIT);
} catch (Exception ae) {
_handleException(ae, req);
return;
}
_sendToReferral(req, res, referer);
}
/*
* If we are copying the Template,
* run the copy action and return to the list
*/
else if ((cmd != null)
&& cmd.equals(com.dotmarketing.util.Constants.COPY)) {
try {
Logger.debug(this, "Calling Copy Method");
_copyWebAsset(req, res, config, form, user);
} catch (Exception ae) {
_handleException(ae, req);
}
_sendToReferral(req, res, referer);
} else
Logger.debug(this, "Unspecified Action");
HibernateUtil.commitTransaction();
_setupEditTemplatePage(reqImpl, res, config, form, user);
// *********************** BEGIN GRAZIANO issue-12-dnd-template
boolean isDrawed = req.getAttribute(WebKeys.TEMPLATE_IS_DRAWED)!=null?(Boolean)req.getAttribute(WebKeys.TEMPLATE_IS_DRAWED):false;
// If we are into the design mode we are redirected at the new portlet action
if(((null!=cmd) && cmd.equals(Constants.DESIGN))){
req.setAttribute(WebKeys.OVERRIDE_DRAWED_TEMPLATE_BODY, false);
setForward(req, "portlet.ext.templates.design_template");
}else if(isDrawed){
req.setAttribute(WebKeys.OVERRIDE_DRAWED_TEMPLATE_BODY, true);
// create the javascript parameters for left side (Page Width, Layout ecc..) of design template
Template template = (Template) req.getAttribute(WebKeys.TEMPLATE_EDIT);
TemplateLayout parameters = DesignTemplateUtil.getDesignParameters(template.getDrawedBody());
req.setAttribute(WebKeys.TEMPLATE_JAVASCRIPT_PARAMETERS, parameters);
setForward(req, "portlet.ext.templates.design_template");
}else
setForward(req, "portlet.ext.templates.edit_template");
// *********************** END GRAZIANO issue-12-dnd-template