| 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.snippet; |
| 20 |
|
|
| 21 |
|
import javax.annotation.Nonnull; |
| 22 |
|
import javax.annotation.Nullable; |
| 23 |
|
|
| 24 |
|
import org.devacfr.maven.skins.reflow.snippet.ComponentToken.Type; |
| 25 |
|
import org.jsoup.Jsoup; |
| 26 |
|
import org.jsoup.nodes.Document; |
| 27 |
|
import org.jsoup.nodes.Element; |
| 28 |
|
|
| 29 |
|
import static java.util.Objects.requireNonNull; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
@author |
| 33 |
|
@version |
| 34 |
|
@param |
| 35 |
|
|
| 36 |
|
|
| |
|
| 67,6% |
Uncovered Elements: 11 (34) |
Complexity: 9 |
Complexity Density: 0,39 |
|
| 37 |
|
public class SnippetComponent<T extends SnippetComponent<T>> extends Component<T> { |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
private final Type type; |
| 41 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 42 |
31 |
@Nonnull... |
| 43 |
|
public static SnippetComponent<?> createSnippet(@Nonnull final Element element, |
| 44 |
|
final Component<?> parent, |
| 45 |
|
final Type type) { |
| 46 |
31 |
requireNonNull(element); |
| 47 |
31 |
return new SnippetComponent<>(element, type).addAttributes(element.attributes()).withParent(parent); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@param |
| 52 |
|
@param |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 54 |
31 |
public SnippetComponent(@Nonnull final Element element, @Nonnull final Type type) {... |
| 55 |
31 |
super(element); |
| 56 |
31 |
this.type = requireNonNull(type); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
@return |
| 61 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 62 |
0 |
@Nonnull... |
| 63 |
|
public Type getType() { |
| 64 |
0 |
return type; |
| 65 |
|
} |
| 66 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 67 |
0 |
@Override... |
| 68 |
|
protected SnippetComponent<?> getRootParent() { |
| 69 |
0 |
return this; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
@link |
| 74 |
|
|
| 75 |
|
@param |
| 76 |
|
|
| 77 |
|
|
| |
|
| 69,6% |
Uncovered Elements: 7 (23) |
Complexity: 5 |
Complexity Density: 0,29 |
|
| 78 |
31 |
public void render(final SnippetContext context) {... |
| 79 |
31 |
try { |
| 80 |
31 |
final Element element = getElement(); |
| 81 |
31 |
final String html = context.renderComponent(this); |
| 82 |
31 |
final Document doc = Jsoup.parse(html); |
| 83 |
31 |
if (doc.body().children().isEmpty()) { |
| 84 |
0 |
return; |
| 85 |
|
} |
| 86 |
|
|
| 87 |
31 |
if (doc.body().children().size() > 1) { |
| 88 |
0 |
final Element div = new Element("div"); |
| 89 |
0 |
doc.body().children().forEach((e) -> div.appendChild(e)); |
| 90 |
0 |
element.replaceWith(div); |
| 91 |
|
} else { |
| 92 |
31 |
final Element el = doc.body().children().first(); |
| 93 |
|
|
| 94 |
31 |
if (ComponentResolver.hasIncludedSnippetComponent(el)) { |
| 95 |
1 |
final SnippetParser parser = context.createChildParser(); |
| 96 |
1 |
final Document childDoc = parser.parse(context.getConfig(), el.outerHtml()).document(); |
| 97 |
1 |
element.replaceWith(childDoc.body().children().first()); |
| 98 |
|
} else { |
| 99 |
30 |
element.replaceWith(el); |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
} catch (final Exception e) { |
| 103 |
0 |
throw new RuntimeException(e.getMessage(), e); |
| 104 |
|
} |
| 105 |
|
} |
| 106 |
|
} |