1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.setup.for3_5;
35
36 import javax.jcr.RepositoryException;
37
38 import info.magnolia.cms.core.Content;
39 import info.magnolia.cms.core.HierarchyManager;
40 import info.magnolia.cms.core.NodeData;
41 import info.magnolia.cms.util.ContentUtil;
42 import info.magnolia.cms.util.NodeDataUtil;
43 import info.magnolia.commands.DelegateCommand;
44 import info.magnolia.module.InstallContext;
45 import info.magnolia.module.delta.AllModulesNodeOperation;
46 import info.magnolia.module.delta.TaskExecutionException;
47
48 import org.apache.commons.lang.StringUtils;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51
52
53
54
55
56
57
58 public class ReconfigureCommands extends AllModulesNodeOperation {
59
60
61
62
63 private static Logger log = LoggerFactory.getLogger(ReconfigureCommands.class);
64
65 public ReconfigureCommands() {
66 super("reconfigure commands", "rename impl to class or commandName");
67 }
68
69 protected void operateOnModuleNode(Content node, HierarchyManager hm, InstallContext ctx) throws RepositoryException, TaskExecutionException {
70 try {
71 if(node.hasContent("commands")){
72 ContentUtil.visit(node.getContent("commands"), new ContentUtil.Visitor(){
73 public void visit(Content node) throws Exception {
74 if(node.hasNodeData("impl")){
75 String value = node.getNodeData("impl").getString();
76 node.deleteNodeData("impl");
77 NodeData classNodeData = NodeDataUtil.getOrCreate(node, "class");
78 if(StringUtils.contains(value, ".")){
79 classNodeData.setValue(value);
80 }
81 else if(StringUtils.isNotEmpty(value)){
82 classNodeData.setValue(DelegateCommand.class.getName());
83 NodeDataUtil.getOrCreateAndSet(node, "commandName", value);
84 }
85 else{
86
87 }
88 }
89 }
90 });
91 }
92 }
93 catch(RepositoryException e){
94 throw e;
95 }
96 catch (Exception e) {
97 throw new TaskExecutionException("can't reconfigure tasks", e);
98 }
99 }
100 }