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.resources.app;
35
36 import info.magnolia.resourceloader.ResourceOrigin;
37 import info.magnolia.resourceloader.layered.LayeredResource;
38 import info.magnolia.resources.app.workbench.ResourcesContainer;
39 import info.magnolia.ui.vaadin.integration.contentconnector.ContentConnector;
40
41 import javax.inject.Inject;
42
43 import com.vaadin.data.Item;
44 import com.vaadin.data.Property;
45
46
47
48
49
50
51
52 public class ResourcesContentConnector implements ContentConnector {
53
54 private final ResourceOrigin<LayeredResource> origin;
55
56 @Inject
57 @SuppressWarnings("unchecked")
58 public ResourcesContentConnector(ResourceOrigin resourceOrigin) {
59 this.origin = (ResourceOrigin<LayeredResource>) resourceOrigin;
60 }
61
62 @Override
63 public String getItemUrlFragment(Object itemId) {
64 return origin.getByPath((String) itemId).getPath();
65 }
66
67 @Override
68 public String getItemIdByUrlFragment(String urlFragment) {
69 return urlFragment;
70 }
71
72 @Override
73 public String getDefaultItemId() {
74
75 return "/";
76 }
77
78 @Override
79 public Item getItem(Object itemId) {
80 return ResourcesContainer.newItem(origin.getByPath((String) itemId));
81 }
82
83 @Override
84 public String getItemId(Item item) {
85 Property<?> resourcePathProperty = item.getItemProperty(ResourcesContainer.RESOURCE_PATH);
86 if (resourcePathProperty != null) {
87 return (String) resourcePathProperty.getValue();
88 }
89 return null;
90 }
91
92 @Override
93 public boolean canHandleItem(Object itemId) {
94 return itemId instanceof String && origin.hasPath((String) itemId);
95 }
96
97 public ResourceOrigin getOrigin() {
98 return origin;
99 }
100 }