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.workflow.setup.for3_5;
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 import info.magnolia.module.delta.AbstractRepositoryTask;
41 import info.magnolia.module.delta.TaskExecutionException;
42
43 import javax.jcr.RepositoryException;
44
45
46
47
48
49
50
51 public class RemoveMetadataFromExpressionsWorkspace extends AbstractRepositoryTask {
52 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(RemoveMetadataFromExpressionsWorkspace.class);
53
54 public RemoveMetadataFromExpressionsWorkspace() {
55 super("Nodetypes changed", "Removes the metadata nodes from the Expressions workspace");
56 }
57
58 protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException {
59 final HierarchyManager hm = ctx.getHierarchyManager("Expressions");
60 final Content root = hm.getRoot();
61 final MetadataRemover metadataRemover = new MetadataRemover(ctx);
62 try {
63 ContentUtil.visit(root, metadataRemover, ContentUtil.EXCLUDE_META_DATA_CONTENT_FILTER);
64 } catch (Exception e) {
65
66 throw new TaskExecutionException("Cant' removed MetaData from the Expression workspace: " + e.getMessage(), e);
67 }
68 }
69
70 private final static class MetadataRemover implements ContentUtil.Visitor {
71 public MetadataRemover(InstallContext ctx) {
72 this.ctx = ctx;
73 }
74
75 private final InstallContext ctx;
76
77 public void visit(Content node) throws Exception {
78 final Content metadata = node.getChildByName("MetaData");
79 if (metadata != null) {
80 log.debug("Will remove MetaData at " + metadata.getHandle());
81 metadata.delete();
82 }
83 }
84 }
85 }