| 1 | package com.reallifedeveloper.common.infrastructure; | |
| 2 | ||
| 3 | import static com.reallifedeveloper.common.domain.LogUtil.removeCRLF; | |
| 4 | ||
| 5 | import java.io.FileNotFoundException; | |
| 6 | import java.io.IOException; | |
| 7 | import java.io.InputStream; | |
| 8 | ||
| 9 | import org.markdown4j.Markdown4jProcessor; | |
| 10 | import org.slf4j.Logger; | |
| 11 | import org.slf4j.LoggerFactory; | |
| 12 | ||
| 13 | import com.reallifedeveloper.common.resource.documentation.HtmlProducer; | |
| 14 | ||
| 15 | /** | |
| 16 | * An implementation of {@link HtmlProducer} that converts | |
| 17 | * <a href="http://daringfireball.net/projects/markdown/">Markdown</a> | |
| 18 | * documents to HTML using <a href="https://code.google.com/p/markdown4j/">Markdown4j</a>. | |
| 19 | * | |
| 20 | * @author RealLifeDeveloper | |
| 21 | */ | |
| 22 | public final class Markdown4jHtmlProducer implements HtmlProducer { | |
| 23 | ||
| 24 | private static final Logger LOG = LoggerFactory.getLogger(Markdown4jHtmlProducer.class); | |
| 25 | ||
| 26 | private final Markdown4jProcessor markdownProcessor = new Markdown4jProcessor(); | |
| 27 | ||
| 28 | @Override | |
| 29 | public String produce(String resourceName) throws IOException { | |
| 30 | LOG.trace("produce: resourceName={}", removeCRLF(resourceName)); | |
| 31 |
1
1. produce : negated conditional → KILLED |
if (resourceName == null) { |
| 32 | throw new IllegalArgumentException("resourceName must not be null"); | |
| 33 | } | |
| 34 | try (InputStream in = getClass().getResourceAsStream(resourceName)) { | |
| 35 |
1
1. produce : negated conditional → KILLED |
if (in == null) { |
| 36 | throw new FileNotFoundException("Resource not found: " + resourceName); | |
| 37 | } | |
| 38 | String html = "<html>" + markdownProcessor.process(in) + "</html>"; | |
| 39 | LOG.trace("produce: {}", removeCRLF(html)); | |
| 40 |
1
1. produce : replaced return value with "" for com/reallifedeveloper/common/infrastructure/Markdown4jHtmlProducer::produce → KILLED |
return html; |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | @Override | |
| 45 | public boolean canHandle(String resourceName) { | |
| 46 |
2
1. canHandle : replaced boolean return with true for com/reallifedeveloper/common/infrastructure/Markdown4jHtmlProducer::canHandle → KILLED 2. canHandle : replaced boolean return with false for com/reallifedeveloper/common/infrastructure/Markdown4jHtmlProducer::canHandle → KILLED |
return resourceName.endsWith(".md"); |
| 47 | } | |
| 48 | ||
| 49 | } | |
Mutations | ||
| 31 |
1.1 |
|
| 35 |
1.1 |
|
| 40 |
1.1 |
|
| 46 |
1.1 2.2 |