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; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.MgnlNodeType; |
37 |
|
import info.magnolia.context.MgnlContext; |
38 |
|
import info.magnolia.jcr.predicate.AbstractPredicate; |
39 |
|
import info.magnolia.jcr.util.MetaDataUtil; |
40 |
|
import info.magnolia.jcr.util.NodeUtil; |
41 |
|
import info.magnolia.jcr.util.SessionUtil; |
42 |
|
import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration; |
43 |
|
import info.magnolia.module.googlesitemap.bean.SiteMapEntry; |
44 |
|
import info.magnolia.module.googlesitemap.service.SiteMapService; |
45 |
|
import info.magnolia.rendering.model.RenderingModel; |
46 |
|
import info.magnolia.rendering.model.RenderingModelImpl; |
47 |
|
import info.magnolia.rendering.template.RenderableDefinition; |
48 |
|
|
49 |
|
import java.util.HashSet; |
50 |
|
import java.util.Iterator; |
51 |
|
import java.util.Set; |
52 |
|
|
53 |
|
import javax.inject.Inject; |
54 |
|
import javax.jcr.Node; |
55 |
|
import javax.jcr.NodeIterator; |
56 |
|
import javax.jcr.Property; |
57 |
|
import javax.jcr.PropertyIterator; |
58 |
|
import javax.jcr.RepositoryException; |
59 |
|
|
60 |
|
import org.apache.commons.lang.StringUtils; |
61 |
|
import org.apache.jackrabbit.commons.predicate.Predicate; |
62 |
|
import org.slf4j.Logger; |
63 |
|
import org.slf4j.LoggerFactory; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@version |
70 |
|
@param |
71 |
|
|
|
|
| 81.6% |
Uncovered Elements: 9 (49) |
Complexity: 15 |
Complexity Density: 0.48 |
|
72 |
|
public class SiteMapModel <RD extends RenderableDefinition> extends RenderingModelImpl<RD> { |
73 |
|
|
74 |
|
|
75 |
|
private static final Logger log = LoggerFactory.getLogger(SiteMapModel.class); |
76 |
|
|
77 |
|
|
78 |
|
private static Predicate All_Site_Nodes = new AbstractPredicate<Node>() { |
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
79 |
34
|
@Override... |
80 |
|
public boolean evaluateTyped(Node node) { |
81 |
34
|
try { |
82 |
34
|
return node.getName().startsWith(GoogleSiteMapConfiguration.SITE_DIALOG_CONFIGURATION_NAME); |
83 |
|
} catch (RepositoryException e) { |
84 |
0
|
return false; |
85 |
|
} |
86 |
|
} |
87 |
|
}; |
88 |
|
|
89 |
|
|
90 |
|
protected SiteMapService siteMapService; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
96 |
11
|
@Inject... |
97 |
|
public SiteMapModel(Node content, RD definition, RenderingModel< ? > parent, SiteMapService siteMapService) { |
98 |
11
|
super(content, definition, parent); |
99 |
11
|
this.siteMapService = siteMapService; |
100 |
|
} |
101 |
|
|
102 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
103 |
0
|
@Override... |
104 |
|
public String execute() { |
105 |
|
|
106 |
|
|
107 |
0
|
if(this.definition.getParameters()!=null && this.definition.getParameters().containsKey("xmlDisplay")) { |
108 |
0
|
MgnlContext.getWebContext().getResponse().setContentType("text/xml"); |
109 |
|
} |
110 |
|
|
111 |
0
|
return null; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
|
|
| 94.3% |
Uncovered Elements: 2 (35) |
Complexity: 9 |
Complexity Density: 0.39 |
|
119 |
7
|
public Iterator<SiteMapEntry> getSiteMapBeans() {... |
120 |
7
|
Set<SiteMapEntry> res = new HashSet<SiteMapEntry>(); |
121 |
7
|
try { |
122 |
|
|
123 |
7
|
if(!content.hasNode("content")) { |
124 |
1
|
return res.iterator(); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
6
|
Node node = null; |
129 |
6
|
Iterator<Node> iterator = NodeUtil.collectAllChildren(content,All_Site_Nodes).iterator(); |
130 |
12
|
while (iterator.hasNext()) { |
131 |
|
|
132 |
6
|
node = iterator.next(); |
133 |
6
|
PropertyIterator properties = node.getProperties(); |
134 |
|
|
135 |
19
|
while(properties.hasNext()) { |
136 |
13
|
Property property = properties.nextProperty(); |
137 |
13
|
if(!property.getName().startsWith(MgnlNodeType.JCR_PREFIX)) { |
138 |
13
|
Node root = SessionUtil.getNode(this.content.getSession().getWorkspace().getName(), property.getString()); |
139 |
|
|
140 |
13
|
res.addAll(siteMapService.getSiteMapBeanForSite(root, false)); |
141 |
|
} |
142 |
|
} |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
6
|
NodeIterator nodeIterator = content.getNode("content").getNodes(); |
148 |
12
|
while (nodeIterator.hasNext()) { |
149 |
8
|
node = nodeIterator.nextNode(); |
150 |
8
|
String templateName = MetaDataUtil.getTemplate(node); |
151 |
8
|
if(StringUtils.isNotEmpty(templateName) && templateName.endsWith(GoogleSiteMapConfiguration.VIRTUAL_URI_TEMPLATE_NAME)) { |
152 |
|
|
153 |
2
|
res.addAll(siteMapService.getSiteMapBeanForVirtualUri(false)); |
154 |
2
|
break; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
} catch (RepositoryException re) { |
160 |
0
|
log.error("Could not initialize SiteMapBeans", re); |
161 |
|
} |
162 |
6
|
return res.iterator(); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
} |