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.module.delta;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.cms.core.HierarchyManager;
38 import info.magnolia.cms.util.ContentUtil;
39 import info.magnolia.module.InstallContext;
40
41 import javax.jcr.RepositoryException;
42 import javax.jcr.Value;
43
44
45
46
47
48
49
50 @Deprecated
51 public class RenamePropertyAllModulesNodeTask extends AllModulesNodeOperation {
52 private final String srcPropertyName;
53 private final String destPropertyName;
54 private final String baseNodeName;
55
56 public RenamePropertyAllModulesNodeTask(String name, String description, String baseNodeName, String srcPropertyName, String destPropertyName) {
57 super(name, description);
58 this.baseNodeName = baseNodeName;
59 this.srcPropertyName = srcPropertyName;
60 this.destPropertyName = destPropertyName;
61 }
62
63 @Override
64 protected void operateOnModuleNode(Content node, HierarchyManager hm, InstallContext ctx) throws RepositoryException, TaskExecutionException {
65 try {
66 if (node.hasContent(baseNodeName)) {
67 ContentUtil.visit(node.getContent(baseNodeName), new ContentUtil.Visitor() {
68 @Override
69 public void visit(Content subNode) throws Exception {
70 if (subNode.hasNodeData(srcPropertyName)) {
71 final Value value = subNode.getNodeData(srcPropertyName).getValue();
72 subNode.deleteNodeData(srcPropertyName);
73 subNode.setNodeData(destPropertyName, value);
74 }
75 }
76 });
77 }
78 } catch (RepositoryException e) {
79 throw e;
80 } catch (Exception e) {
81
82 throw new TaskExecutionException(e.getMessage(), e);
83 }
84 }
85 }
86