1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.exoplatform.ecm.webui.presentation.removecomment;
19
20 import java.util.Map;
21
22 import javax.jcr.Node;
23 import javax.jcr.version.VersionException;
24
25 import org.exoplatform.ecm.utils.text.Text;
26 import org.exoplatform.ecm.webui.presentation.AbstractActionComponent;
27 import org.exoplatform.ecm.webui.presentation.action.UIPresentationEventListener;
28 import org.exoplatform.ecm.webui.utils.JCRExceptionManager;
29 import org.exoplatform.ecm.webui.utils.Utils;
30 import org.exoplatform.services.cms.comments.CommentsService;
31 import org.exoplatform.services.cms.link.NodeFinder;
32 import org.exoplatform.services.log.ExoLogger;
33 import org.exoplatform.services.log.Log;
34 import org.exoplatform.web.application.ApplicationMessage;
35 import org.exoplatform.webui.application.WebuiRequestContext;
36 import org.exoplatform.webui.config.annotation.ComponentConfig;
37 import org.exoplatform.webui.config.annotation.EventConfig;
38 import org.exoplatform.webui.core.UIApplication;
39
40
41
42
43
44
45
46
47 @ComponentConfig(events = {
48 @EventConfig(listeners = RemoveCommentComponent.RemoveCommentActionListener.class,
49 confirm = "RemoveCommentComponent.msg.confirm-deletecomment") })
50 public class RemoveCommentComponent extends AbstractActionComponent {
51
52 private static final Log LOG = ExoLogger.getLogger(RemoveCommentComponent.class.getName());
53
54
55
56
57 protected String loadConfirmMesssage(org.exoplatform.webui.config.Event event,
58 WebuiRequestContext context,
59 String beanId) {
60 String confirmKey = event.getConfirm();
61 if(confirmKey.length() < 1) return confirmKey;
62 String confirm = Utils.getResourceBundle(Utils.LOCALE_WEBUI_DMS, confirmKey, getClass().getClassLoader());
63 return confirm.replaceAll("\\{0\\}", beanId);
64 }
65
66 public static void doDelete(Map<String, Object> variables) throws Exception {
67 AbstractActionComponent uicomponent = (AbstractActionComponent)variables.get(UICOMPONENT);
68 UIApplication uiApp = uicomponent.getAncestorOfType(UIApplication.class);
69 NodeFinder nodefinder = uicomponent.getApplicationComponent(NodeFinder.class);
70 String wsname = String.valueOf(variables.get(Utils.WORKSPACE_PARAM));
71 String nodepath = String.valueOf(variables.get(OBJECTID));
72 WebuiRequestContext requestcontext = (WebuiRequestContext)variables.get(Utils.REQUESTCONTEXT);
73 try {
74 Node commentNode = (Node) nodefinder.getItem(wsname,
75 Text.escapeIllegalJcrChars(nodepath));
76 CommentsService commentService = uicomponent.getApplicationComponent(CommentsService.class);
77 commentService.deleteComment(commentNode);
78 uicomponent.updateAjax(requestcontext);
79 } catch(VersionException e) {
80 if (LOG.isErrorEnabled()) {
81 LOG.error("Version exception");
82 }
83 Object[] args = { nodepath } ;
84 uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.can-not-delete-version", args,
85 ApplicationMessage.WARNING));
86 } catch (Exception e) {
87 if (LOG.isErrorEnabled()) {
88 LOG.error("an unexpected error occurs while removing the node", e);
89 }
90 JCRExceptionManager.process(uiApp, e);
91 }
92 }
93
94 public static class RemoveCommentActionListener extends UIPresentationEventListener<RemoveCommentComponent> {
95 protected void executeAction(Map<String, Object> variables) throws Exception {
96 RemoveCommentComponent.doDelete(variables);
97 }
98 }
99 }