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.admininterface.templates;
35
36 import java.util.Collection;
37 import java.util.Iterator;
38 import javax.jcr.RepositoryException;
39 import javax.jcr.UnsupportedRepositoryOperationException;
40 import javax.jcr.version.Version;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 import info.magnolia.cms.core.Content;
45 import info.magnolia.cms.core.ItemType;
46 import info.magnolia.cms.core.version.ContentVersion;
47 import info.magnolia.cms.security.AccessDeniedException;
48 import info.magnolia.cms.util.ContentWrapper;
49 import info.magnolia.module.admininterface.VersionUtil;
50 import info.magnolia.module.templating.RenderableDefinition;
51 import info.magnolia.module.templating.RenderingModel;
52 import info.magnolia.module.templating.RenderingModelImpl;
53
54 public class MgnlDeletedTemplateModel extends RenderingModelImpl<RenderableDefinition> {
55
56 private static final Logger log = LoggerFactory.getLogger(MgnlDeletedTemplateModel.class);
57
58 public MgnlDeletedTemplateModel(Content content, RenderableDefinition definition, RenderingModel parent) {
59 super(content, definition, parent);
60 }
61
62 public String getLastVersion() {
63 Collection<Version> allVersions = null;
64
65 Iterator<Version> iterator = null;
66 Content maybeVersion = getContent();
67 Content content = getContent();
68 try {
69 try {
70 allVersions = VersionUtil.getSortedNotDeletedVersions(content);
71 } catch (AccessDeniedException e) {
72
73 while (maybeVersion != null && maybeVersion instanceof ContentWrapper) {
74 maybeVersion = ((ContentWrapper) maybeVersion).getWrappedContent();
75 }
76 if (maybeVersion instanceof ContentVersion) {
77 String versionName = ((ContentVersion) maybeVersion).getVersionLabel();
78 content = maybeVersion.getHierarchyManager().getContent(maybeVersion.getHandle());
79 allVersions = VersionUtil.getSortedNotDeletedVersionsBefore(content, versionName);
80 }
81 }
82
83 if (allVersions == null || allVersions.isEmpty()) {
84 return null;
85 }
86 return allVersions.iterator().next().getName();
87 } catch (UnsupportedRepositoryOperationException e) {
88
89 log.error("Failed to retrieve version history for " + getContent().getHandle() + ". This node doesn't support versioning", e);
90 } catch (RepositoryException e) {
91 log.error("Failed to retrieve version history for " + getContent().getHandle() + "", e);
92 }
93 return null;
94 }
95
96 public boolean hasChildren() {
97 return getContent().hasChildren(ItemType.CONTENT.getSystemName());
98 }
99
100 public String getDeletionAuthor() {
101 return getContent().getNodeData("mgnl:deletedBy").getString();
102 }
103
104 public String getDeletionDate() {
105 return getContent().getNodeData("mgnl:deletedOn").getString();
106 }
107 }