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.googlesitemap.app.subapp.sitemapdetail.contentconnector; |
35 |
|
|
36 |
|
import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.util.SiteMapEntryContainer; |
37 |
|
import info.magnolia.module.googlesitemap.bean.SiteMapEntry; |
38 |
|
import info.magnolia.module.googlesitemap.service.SiteMapService; |
39 |
|
import info.magnolia.ui.api.app.SubAppContext; |
40 |
|
import info.magnolia.ui.contentapp.detail.DetailLocation; |
41 |
|
import info.magnolia.ui.vaadin.integration.contentconnector.ContentConnector; |
42 |
|
|
43 |
|
import javax.inject.Inject; |
44 |
|
|
45 |
|
import org.apache.commons.lang.StringUtils; |
46 |
|
|
47 |
|
import com.vaadin.data.Item; |
48 |
|
import com.vaadin.data.util.BeanItem; |
49 |
|
|
50 |
|
|
51 |
|
@link@link |
52 |
|
|
|
|
| 63.5% |
Uncovered Elements: 19 (52) |
Complexity: 16 |
Complexity Density: 0.57 |
|
53 |
|
public class SitemapContentConnector implements ContentConnector { |
54 |
|
|
55 |
|
public static final String SEPARATOR = "@"; |
56 |
|
|
57 |
|
private final DetailLocation siteMapLocation; |
58 |
|
|
59 |
|
private SiteMapService siteMapService; |
60 |
|
|
61 |
|
private SiteMapEntryContainer container; |
62 |
|
|
63 |
|
private SitemapContentConnectorDefinition definition; |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
65 |
6 |
@Inject... |
66 |
|
public SitemapContentConnector(SitemapContentConnectorDefinition definition, SiteMapService siteMapService, SubAppContext subAppContext) { |
67 |
6 |
this.definition = definition; |
68 |
6 |
this.siteMapLocation = DetailLocation.wrap(subAppContext.getLocation()); |
69 |
6 |
this.siteMapService = siteMapService; |
70 |
6 |
this.container = new SiteMapEntryContainer(getSitemapPath(), this.definition.isVirtualUris(), this.siteMapService); |
71 |
|
} |
72 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
73 |
3 |
@Override... |
74 |
|
public String getItemUrlFragment(Object itemId) { |
75 |
3 |
if (itemId instanceof SiteMapEntry) { |
76 |
3 |
SiteMapEntry entry = (SiteMapEntry)itemId; |
77 |
3 |
return getSitemapPath() + SEPARATOR + entry.getPath(); |
78 |
|
} |
79 |
0 |
return getSitemapPath(); |
80 |
|
} |
81 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
82 |
4 |
@Override... |
83 |
|
public SiteMapEntry getItemIdByUrlFragment(String urlFragment) { |
84 |
4 |
if (urlFragment.startsWith(siteMapLocation.getNodePath())) { |
85 |
4 |
return findEntry(parsePageName(urlFragment)); |
86 |
|
} |
87 |
0 |
return null; |
88 |
|
} |
89 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
90 |
|
@Override... |
91 |
|
public Object getDefaultItemId() { |
92 |
|
return new Object(); |
93 |
|
} |
94 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
95 |
1 |
@Override... |
96 |
|
public Item getItem(Object itemId) { |
97 |
1 |
if (itemId instanceof SiteMapEntry) { |
98 |
1 |
return new BeanItem<SiteMapEntry>((SiteMapEntry) itemId); |
99 |
|
} |
100 |
0 |
return null; |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
103 |
0 |
@Override... |
104 |
|
public SiteMapEntry getItemId(Item item) { |
105 |
0 |
if (item instanceof BeanItem) { |
106 |
0 |
Object bean = ((BeanItem)item).getBean(); |
107 |
0 |
if (bean instanceof SiteMapEntry) { |
108 |
0 |
return (SiteMapEntry)bean; |
109 |
|
} |
110 |
|
} |
111 |
0 |
return null; |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
2 |
@Override... |
115 |
|
public boolean canHandleItem(Object itemId) { |
116 |
2 |
return itemId instanceof SiteMapEntry; |
117 |
|
} |
118 |
|
|
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
119 |
4 |
private SiteMapEntry findEntry(String pagePath) {... |
120 |
4 |
if (!StringUtils.isBlank(pagePath)) { |
121 |
4 |
SiteMapEntry id = container.firstItemId(); |
122 |
7 |
while (id != null) { |
123 |
7 |
if (id.getPath().equals(pagePath)) { |
124 |
4 |
return id; |
125 |
|
} |
126 |
3 |
id = container.nextItemId(id); |
127 |
|
} |
128 |
|
} |
129 |
0 |
return null; |
130 |
|
} |
131 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
132 |
|
public String getSitemapPath() {... |
133 |
|
return StringUtils.substringBefore(siteMapLocation.getNodePath(), SEPARATOR); |
134 |
|
} |
135 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
136 |
|
public SiteMapEntryContainer getContainer() {... |
137 |
|
return container; |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
4 |
private String parsePageName(String urlFragment) {... |
141 |
4 |
return StringUtils.substringAfterLast(urlFragment, SEPARATOR); |
142 |
|
} |
143 |
|
} |