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.templating; |
35 |
|
|
36 |
|
import freemarker.core.Environment; |
37 |
|
import info.magnolia.cms.beans.config.ContentRepository; |
38 |
|
import info.magnolia.cms.beans.config.ServerConfiguration; |
39 |
|
import info.magnolia.cms.core.Content; |
40 |
|
import info.magnolia.cms.core.NodeData; |
41 |
|
import info.magnolia.cms.i18n.I18nContentWrapper; |
42 |
|
import info.magnolia.cms.util.ContentUtil; |
43 |
|
import info.magnolia.cms.util.InheritanceContentWrapper; |
44 |
|
import info.magnolia.cms.util.SiblingsHelper; |
45 |
|
import info.magnolia.context.MgnlContext; |
46 |
|
import info.magnolia.link.LinkUtil; |
47 |
|
import info.magnolia.link.LinkException; |
48 |
|
import info.magnolia.module.templating.engine.RenderingEngine; |
49 |
|
import info.magnolia.objectfactory.Components; |
50 |
|
|
51 |
|
import javax.jcr.RepositoryException; |
52 |
|
|
53 |
|
import org.apache.commons.lang.StringUtils; |
54 |
|
import org.apache.commons.lang.exception.ExceptionUtils; |
55 |
|
import org.slf4j.Logger; |
56 |
|
import org.slf4j.LoggerFactory; |
57 |
|
|
58 |
|
import java.io.IOException; |
59 |
|
import java.io.Writer; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@author |
66 |
|
@version |
67 |
|
|
|
|
| 2.9% |
Uncovered Elements: 68 (70) |
Complexity: 30 |
Complexity Density: 0.77 |
|
68 |
|
public class MagnoliaTemplatingUtilities { |
69 |
|
|
70 |
|
private static final Logger log = LoggerFactory.getLogger(MagnoliaTemplatingUtilities.class); |
71 |
|
|
72 |
|
protected RenderingEngine renderingEngine = Components.getSingleton(RenderingEngine.class); |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
5
|
public static MagnoliaTemplatingUtilities getInstance(){... |
75 |
5
|
return Components.getSingleton(MagnoliaTemplatingUtilities.class); |
76 |
|
} |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0
|
public SiblingsHelper siblings(Content node) throws RepositoryException {... |
82 |
0
|
return SiblingsHelper.of(node); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0
|
public void renderTemplate(Content content) throws RenderException, IOException {... |
86 |
0
|
renderTemplate(content, getWriter()); |
87 |
|
} |
88 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
0
|
public void renderTemplate(Content content, Writer out) throws RenderException, IOException {... |
90 |
0
|
renderingEngine.render(content, out); |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
0
|
public void renderTemplate(Content content, Writer out, String templateName) throws RenderException, IOException {... |
94 |
0
|
renderingEngine.render(content, templateName, out); |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
0
|
public void renderParagraph(Content paragraphNode) throws RenderException, IOException {... |
98 |
0
|
renderParagraph(paragraphNode, getWriter()); |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
0
|
public void renderParagraph(Content paragraphNode, Writer out) throws RenderException, IOException {... |
102 |
0
|
renderingEngine.render(paragraphNode, out); |
103 |
|
} |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
0
|
public void renderParagraph(Content paragraphNode, Writer out, String paragraphName) throws RenderException, IOException {... |
106 |
0
|
renderingEngine.render(paragraphNode, paragraphName, out); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
112 |
0
|
protected Writer getWriter() {... |
113 |
0
|
final Environment env = Environment.getCurrentEnvironment(); |
114 |
0
|
return env.getOut(); |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0
|
public Content inherit(Content node) {... |
118 |
0
|
return new InheritanceContentWrapper(node); |
119 |
|
} |
120 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
121 |
0
|
public Content i18n(Content node) {... |
122 |
0
|
return new I18nContentWrapper(node); |
123 |
|
} |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
0
|
public boolean isEditMode(){... |
126 |
|
|
127 |
0
|
return isAuthorInstance() && !isPreviewMode(); |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0
|
public boolean isPreviewMode(){... |
131 |
0
|
return MgnlContext.getAggregationState().isPreviewMode(); |
132 |
|
} |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
0
|
public boolean isAuthorInstance(){... |
135 |
0
|
return ServerConfiguration.getInstance().isAdmin(); |
136 |
|
} |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
0
|
public boolean isPublicInstance(){... |
139 |
0
|
return !isAuthorInstance(); |
140 |
|
} |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
0
|
public String createLink(Content node) {... |
143 |
0
|
return LinkUtil.createLink(node); |
144 |
|
} |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
146 |
0
|
public String createLink(NodeData nd) {... |
147 |
0
|
try { |
148 |
0
|
return LinkUtil.createLink(nd); |
149 |
|
} catch (LinkException e) { |
150 |
0
|
log.error("Can't resolve link defined in node {} because of {}.", nd.getHandle(), ExceptionUtils.getRootCauseMessage(e)); |
151 |
0
|
return null; |
152 |
|
} |
153 |
|
} |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
155 |
0
|
public String createLink(String repositoryId, String uuid) {... |
156 |
0
|
try { |
157 |
0
|
return LinkUtil.createLink(repositoryId, uuid); |
158 |
|
} catch (RepositoryException e) { |
159 |
0
|
log.error("Can't resolve link with UUID {} because of {}.", uuid , ExceptionUtils.getRootCauseMessage(e)); |
160 |
0
|
return null; |
161 |
|
} |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
168 |
0
|
public String createAttribute(String name, String value){... |
169 |
0
|
value = StringUtils.trim(value); |
170 |
0
|
if(StringUtils.isNotEmpty(value)){ |
171 |
0
|
return new StringBuffer().append(name).append("=\"").append(value).append("\"").toString(); |
172 |
|
} |
173 |
0
|
return StringUtils.EMPTY; |
174 |
|
} |
175 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
0
|
public Content getContent(String path){... |
177 |
0
|
return getContent(ContentRepository.WEBSITE, path); |
178 |
|
} |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
180 |
0
|
public Content getContent(String repository, String path){... |
181 |
0
|
return ContentUtil.getContent(repository, path); |
182 |
|
} |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
0
|
public Content getContentByUUID(String uuid){... |
185 |
0
|
return getContentByUUID(ContentRepository.WEBSITE, uuid); |
186 |
|
} |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
0
|
public Content getContentByUUID(String repository, String uuid){... |
189 |
0
|
return ContentUtil.getContentByUUID(repository, uuid); |
190 |
|
} |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
192 |
0
|
public static Content encode(Content content){... |
193 |
0
|
if(content != null){ |
194 |
0
|
return new HTMLEncodingContentWrapper(content, true); |
195 |
|
} |
196 |
0
|
return null; |
197 |
|
} |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
199 |
0
|
public static Content decode(Content content){... |
200 |
0
|
if(content instanceof HTMLEncodingContentWrapper){ |
201 |
0
|
return ((HTMLEncodingContentWrapper)content).getWrappedContent(); |
202 |
|
} |
203 |
0
|
throw new IllegalStateException("The content to decode is not wrapped by a " + HTMLEncodingContentWrapper.class.getName()); |
204 |
|
} |
205 |
|
|
206 |
|
} |