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.model.components;
35
36 import info.magnolia.cms.core.MgnlNodeType;
37 import info.magnolia.jcr.util.SessionUtil;
38 import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration;
39 import info.magnolia.module.googlesitemap.bean.SiteMapEntry;
40 import info.magnolia.module.googlesitemap.model.SiteMapModel;
41 import info.magnolia.module.googlesitemap.service.SiteMapService;
42 import info.magnolia.rendering.model.RenderingModel;
43 import info.magnolia.rendering.template.RenderableDefinition;
44
45 import java.util.ArrayList;
46 import java.util.Iterator;
47 import java.util.List;
48
49 import javax.inject.Inject;
50 import javax.jcr.Node;
51 import javax.jcr.Property;
52 import javax.jcr.PropertyIterator;
53 import javax.jcr.RepositoryException;
54
55
56
57
58
59
60
61 public class SiteComponent extends SiteMapModel<RenderableDefinition>{
62
63
64
65
66
67 @Inject
68 public SiteComponent(Node content, RenderableDefinition definition, RenderingModel< ? > parent, SiteMapService siteMapService) {
69 super(content, definition, parent, siteMapService);
70 }
71
72
73
74
75
76 public Iterator<SiteMapEntry> getSiteMapEntry(String type) throws RepositoryException {
77 List<SiteMapEntry> res = new ArrayList<SiteMapEntry>();
78
79 if(!content.hasNode(GoogleSiteMapConfiguration.SITE_DIALOG_CONFIGURATION_NAME)) {
80 return res.iterator();
81 }
82
83
84 PropertyIterator properties = content.getNode(GoogleSiteMapConfiguration.SITE_DIALOG_CONFIGURATION_NAME).getProperties();
85
86 while(properties.hasNext()) {
87 Property property = properties.nextProperty();
88 if(!property.getName().startsWith(MgnlNodeType.JCR_PREFIX)) {
89 Node node = SessionUtil.getNode(this.content.getSession().getWorkspace().getName(), property.getString());
90
91 res.addAll(siteMapService.getSiteMapBeanForSite(node, true));
92 }
93 }
94
95
96 return res.iterator();
97 }
98 }