1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.services.wcm.core.impl;
18
19 import javax.jcr.Node;
20 import javax.jcr.Property;
21
22 import org.apache.commons.chain.Context;
23 import org.exoplatform.services.command.action.Action;
24 import org.exoplatform.services.jcr.ext.common.SessionProvider;
25 import org.exoplatform.services.log.ExoLogger;
26 import org.exoplatform.services.log.Log;
27 import org.exoplatform.services.wcm.core.NodetypeConstant;
28 import org.exoplatform.services.wcm.core.WebSchemaConfigService;
29 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
30
31
32
33
34
35
36 public class WebSchemaModificationAction implements Action{
37 private static final Log LOG = ExoLogger.getLogger(WebSchemaModificationAction.class.getName());
38 public boolean execute(Context context) throws Exception {
39 Property property = (Property)context.get("currentItem");
40 String propertyName = property.getName();
41
42 if (!propertyName.equals("jcr:data")
43 && !propertyName.equals(NodetypeConstant.EXO_PRIORITY)
44 && !propertyName.equals(NodetypeConstant.EXO_ACTIVE)
45 && !propertyName.equals("exo:restorePath")) {
46
47
48 return propertyName.equalsIgnoreCase("exo:active");
49 }
50 Node grandParent = property.getParent().getParent();
51 if(propertyName.equals("jcr:data") && !grandParent.getPrimaryNodeType().getName().equals("nt:file"))
52 return false;
53
54 WebSchemaConfigService schemaConfigService = WCMCoreUtils.getService(WebSchemaConfigService.class);
55 SessionProvider sessionProvider = WCMCoreUtils.getSystemSessionProvider();
56
57 Node node = null;
58 if (propertyName.equals("jcr:data")) {
59 node = grandParent;
60 } else {
61 node = property.getParent();
62 }
63
64 try {
65 if (propertyName.equals("exo:restorePath")) {
66 schemaConfigService.updateSchemaOnRemove(sessionProvider, node);
67 } else {
68 schemaConfigService.updateSchemaOnModify(sessionProvider, node);
69 }
70 } catch (Exception e) {
71 if (LOG.isErrorEnabled()) {
72 LOG.error("Error when update schema when modify node: "+node.getPath(), e);
73 }
74 }
75 return true;
76 }
77
78 }