| 1 | package fr.sii.ogham.template.freemarker.adapter; | |
| 2 | ||
| 3 | import java.io.IOException; | |
| 4 | import java.io.Reader; | |
| 5 | import java.io.StringReader; | |
| 6 | import java.util.Locale; | |
| 7 | ||
| 8 | import fr.sii.ogham.core.util.EqualsBuilder; | |
| 9 | import fr.sii.ogham.core.util.HashCodeBuilder; | |
| 10 | import fr.sii.ogham.template.freemarker.SkipLocaleForStringContentTemplateLookupStrategy; | |
| 11 | import freemarker.cache.StringTemplateLoader; | |
| 12 | import freemarker.cache.TemplateLoader; | |
| 13 | ||
| 14 | /** | |
| 15 | * Ogham special implementation to handle template that is directly provided as | |
| 16 | * string. This is different from {@link StringTemplateLoader} provided by | |
| 17 | * Freemarker. The Freemarker implementations expects that template content is | |
| 18 | * previously registered and referenced by a name. Then when requesting the | |
| 19 | * template, only the name is used. This is an alias. | |
| 20 | * | |
| 21 | * <p> | |
| 22 | * This implementation directly handles the template content as string. | |
| 23 | * | |
| 24 | * <p> | |
| 25 | * To work as expected, the {@link Locale} resolution must be skipped. Take a | |
| 26 | * look at {@link SkipLocaleForStringContentTemplateLookupStrategy}. | |
| 27 | * | |
| 28 | * @author Aurélien Baudet | |
| 29 | * | |
| 30 | */ | |
| 31 | public class StringContentTemplateLoader implements TemplateLoader { | |
| 32 | ||
| 33 | @Override | |
| 34 | public Object findTemplateSource(String name) throws IOException { | |
| 35 |
2
1. findTemplateSource : replaced return value with null for fr/sii/ogham/template/freemarker/adapter/StringContentTemplateLoader::findTemplateSource → NO_COVERAGE 2. findTemplateSource : replaced return value with null for fr/sii/ogham/template/freemarker/adapter/StringContentTemplateLoader::findTemplateSource → KILLED |
return new StringTemplateSource(name); |
| 36 | } | |
| 37 | ||
| 38 | @Override | |
| 39 | public long getLastModified(Object templateSource) { | |
| 40 |
2
1. getLastModified : replaced long return with 0 for fr/sii/ogham/template/freemarker/adapter/StringContentTemplateLoader::getLastModified → SURVIVED 2. getLastModified : replaced long return with 0 for fr/sii/ogham/template/freemarker/adapter/StringContentTemplateLoader::getLastModified → NO_COVERAGE |
return System.currentTimeMillis(); |
| 41 | } | |
| 42 | ||
| 43 | @Override | |
| 44 | public Reader getReader(Object templateSource, String encoding) throws IOException { | |
| 45 |
2
1. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/adapter/StringContentTemplateLoader::getReader → NO_COVERAGE 2. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/adapter/StringContentTemplateLoader::getReader → KILLED |
return new StringReader(((StringTemplateSource) templateSource).source); |
| 46 | } | |
| 47 | ||
| 48 | @Override | |
| 49 | public void closeTemplateSource(Object templateSource) throws IOException { | |
| 50 | // nothing to do | |
| 51 | } | |
| 52 | ||
| 53 | private static class StringTemplateSource { | |
| 54 | private final String source; | |
| 55 | ||
| 56 | public StringTemplateSource(String source) { | |
| 57 | super(); | |
| 58 | this.source = source; | |
| 59 | } | |
| 60 | ||
| 61 | @Override | |
| 62 | public int hashCode() { | |
| 63 |
1
1. hashCode : replaced int return with 0 for fr/sii/ogham/template/freemarker/adapter/StringContentTemplateLoader$StringTemplateSource::hashCode → NO_COVERAGE |
return new HashCodeBuilder().append(source).hashCode(); |
| 64 | } | |
| 65 | ||
| 66 | @Override | |
| 67 | public boolean equals(Object obj) { | |
| 68 |
2
1. equals : replaced boolean return with false for fr/sii/ogham/template/freemarker/adapter/StringContentTemplateLoader$StringTemplateSource::equals → NO_COVERAGE 2. equals : replaced boolean return with true for fr/sii/ogham/template/freemarker/adapter/StringContentTemplateLoader$StringTemplateSource::equals → NO_COVERAGE |
return new EqualsBuilder(this, obj).appendFields("source").isEqual(); |
| 69 | } | |
| 70 | | |
| 71 | | |
| 72 | } | |
| 73 | } | |
Mutations | ||
| 35 |
1.1 2.2 |
|
| 40 |
1.1 2.2 |
|
| 45 |
1.1 2.2 |
|
| 63 |
1.1 |
|
| 68 |
1.1 2.2 |