1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package org.devacfr.maven.skins.reflow.model; |
20 |
|
|
21 |
|
import javax.annotation.Nonnull; |
22 |
|
import javax.annotation.Nullable; |
23 |
|
|
24 |
|
import java.util.List; |
25 |
|
import java.util.Set; |
26 |
|
|
27 |
|
import com.google.common.collect.Sets; |
28 |
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
29 |
|
import org.devacfr.maven.skins.reflow.HtmlTool; |
30 |
|
import org.devacfr.maven.skins.reflow.HtmlTool.IdElement; |
31 |
|
import org.devacfr.maven.skins.reflow.ISkinConfig; |
32 |
|
import org.devacfr.maven.skins.reflow.Xpp3Utils; |
33 |
|
import org.slf4j.Logger; |
34 |
|
import org.slf4j.LoggerFactory; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@author |
40 |
|
@since |
41 |
|
@param |
42 |
|
@link |
43 |
|
|
|
|
| 66,7% |
Uncovered Elements: 19 (57) |
Complexity: 17 |
Complexity Density: 0,45 |
|
44 |
|
public abstract class Toc<T extends Toc<?>> extends BsComponent { |
45 |
|
|
46 |
|
private static final Set<String> TOC_TYPES = Sets.newHashSet("sidebar", "top", "false"); |
47 |
|
|
48 |
|
|
49 |
|
public static final String COMPONENT = "toc"; |
50 |
|
|
51 |
|
|
52 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(Toc.class); |
53 |
|
|
54 |
|
|
55 |
|
private boolean enabled = true; |
56 |
|
|
57 |
|
|
58 |
|
private final String type; |
59 |
|
|
60 |
|
|
61 |
|
@param |
62 |
|
|
63 |
|
@param |
64 |
|
|
65 |
|
@return@link |
66 |
|
|
|
|
| 80,8% |
Uncovered Elements: 5 (26) |
Complexity: 6 |
Complexity Density: 0,3 |
|
67 |
13 |
public static Toc<?> createToc(@Nonnull final ISkinConfig config, @Nullable final String preferredType) {... |
68 |
13 |
Toc<?> toc = null; |
69 |
13 |
String type = config.getPropertyValue(COMPONENT, String.class, preferredType); |
70 |
13 |
if (LOGGER.isTraceEnabled()) { |
71 |
0 |
LOGGER.trace("Page '{}' Find Toc: {}", config.getFileId(), type); |
72 |
|
} |
73 |
13 |
if (!TOC_TYPES.contains(type)) { |
74 |
6 |
type = preferredType; |
75 |
|
} |
76 |
13 |
if (type == null) { |
77 |
6 |
type = ""; |
78 |
|
} |
79 |
13 |
switch (type) { |
80 |
0 |
case "sidebar": |
81 |
0 |
toc = createSidebar(config); |
82 |
0 |
break; |
83 |
1 |
case "top": |
84 |
1 |
toc = createTopBar(config); |
85 |
1 |
break; |
86 |
12 |
default: |
87 |
|
|
88 |
12 |
toc = new Toc<Toc<?>>("", "") {}; |
89 |
|
|
90 |
12 |
toc.withEnabled(false); |
91 |
12 |
break; |
92 |
|
} |
93 |
|
|
94 |
13 |
return toc; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
@param |
99 |
|
|
100 |
|
@return |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
0 |
public static Toc<?> createSidebar(@Nonnull final ISkinConfig config) {... |
103 |
0 |
return new TocSidebar(config); |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
@param |
108 |
|
|
109 |
|
@return |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
1 |
public static Toc<?> createTopBar(@Nonnull final ISkinConfig config) {... |
112 |
1 |
return new TocTopBar(config); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
@param |
117 |
|
@link |
118 |
|
@param |
119 |
|
|
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
121 |
14 |
protected Toc(final String type, final String component) {... |
122 |
14 |
super(component); |
123 |
14 |
this.type = type; |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
@return |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
129 |
20 |
@SuppressWarnings("unchecked")... |
130 |
|
protected T self() { |
131 |
20 |
return (T) this; |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
@return@link@link |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0 |
public String getType() {... |
138 |
0 |
return type; |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
@return |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
4 |
public boolean isEnabled() {... |
147 |
4 |
return enabled; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
@param |
152 |
|
|
153 |
|
@return@link |
154 |
|
@since |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
156 |
0 |
public List<? extends IdElement> getTocItems(final ISkinConfig skinConfig) {... |
157 |
0 |
final HtmlTool htmlTool = getHtmlTool(skinConfig); |
158 |
0 |
final String bodyContent = getBodyContent(skinConfig); |
159 |
|
|
160 |
0 |
final List<? extends IdElement> tocItems = htmlTool.headingTree(bodyContent, |
161 |
|
Xpp3Utils.getChildren(skinConfig.get("sections"))); |
162 |
0 |
return tocItems; |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
@param |
169 |
|
|
170 |
|
@return |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
172 |
14 |
protected T withEnabled(final boolean enabled) {... |
173 |
14 |
this.enabled = enabled; |
174 |
14 |
return self(); |
175 |
|
} |
176 |
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
177 |
5 |
@Override... |
178 |
|
protected String onPreRender(final @Nonnull ISkinConfig skinConfig, final @Nonnull String bodyContent) { |
179 |
5 |
if (this.enabled) { |
180 |
0 |
final HtmlTool htmlTool = getHtmlTool(skinConfig); |
181 |
0 |
return htmlTool.ensureHeadingIds(skinConfig.getContext().getType(), |
182 |
|
skinConfig.getFileId(), |
183 |
|
bodyContent, |
184 |
|
HtmlTool.DEFAULT_SLUG_SEPARATOR); |
185 |
|
} |
186 |
5 |
return bodyContent; |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
@inheritDoc |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
192 |
0 |
@Override... |
193 |
|
public String toString() { |
194 |
0 |
return ToStringBuilder.reflectionToString(this); |
195 |
|
} |
196 |
|
} |