| 1 | package fr.sii.ogham.template.freemarker; | |
| 2 | ||
| 3 | import java.io.IOException; | |
| 4 | import java.io.Reader; | |
| 5 | ||
| 6 | import fr.sii.ogham.core.resource.path.ResolvedResourcePath; | |
| 7 | import fr.sii.ogham.core.resource.path.UnresolvedPath; | |
| 8 | import fr.sii.ogham.core.resource.resolver.FirstSupportingResourceResolver; | |
| 9 | import fr.sii.ogham.core.resource.resolver.ResourceResolver; | |
| 10 | import fr.sii.ogham.template.exception.NoResolverAdapterException; | |
| 11 | import fr.sii.ogham.template.exception.ResolverAdapterConfigurationException; | |
| 12 | import fr.sii.ogham.template.exception.ResolverAdapterException; | |
| 13 | import fr.sii.ogham.template.exception.ResolverAdapterNotFoundException; | |
| 14 | import fr.sii.ogham.template.freemarker.adapter.FirstSupportingResolverAdapter; | |
| 15 | import freemarker.cache.TemplateLoader; | |
| 16 | ||
| 17 | /** | |
| 18 | * <p> | |
| 19 | * Decorator resolver that is able to manage {@link ResolvedResourcePath}. | |
| 20 | * </p> | |
| 21 | * <p> | |
| 22 | * It delegates to a {@link FirstSupportingResourceResolver} the link between path, {@link ResolvedResourcePath} and {@link ResourceResolver}. each lookup to a | |
| 23 | * dedicated {@link ResourceResolver}. | |
| 24 | * </p> | |
| 25 | * <p> | |
| 26 | * It delegates to a {@link FirstSupportingResolverAdapter} the link between {@link ResourceResolver} and the {@link TemplateLoader} implementation to use with | |
| 27 | * the given path. | |
| 28 | * </p> | |
| 29 | * | |
| 30 | * @author Cyril Dejonghe | |
| 31 | * @see FirstSupportingResourceResolver | |
| 32 | * @see FirstSupportingResolverAdapter | |
| 33 | * | |
| 34 | */ | |
| 35 | public class FreeMarkerFirstSupportingTemplateLoader implements TemplateLoader { | |
| 36 | ||
| 37 | private FirstSupportingResourceResolver resolver; | |
| 38 | private FirstSupportingResolverAdapter resolverAdapter; | |
| 39 | ||
| 40 | public FreeMarkerFirstSupportingTemplateLoader(FirstSupportingResourceResolver resolver, FirstSupportingResolverAdapter resolverAdapter) { | |
| 41 | super(); | |
| 42 | this.resolver = resolver; | |
| 43 | this.resolverAdapter = resolverAdapter; | |
| 44 | } | |
| 45 | ||
| 46 | @Override | |
| 47 | public Object findTemplateSource(String unresolvedTemplateName) throws IOException { | |
| 48 | ResourceResolver supportingResolver = resolver.getSupportingResolver(new UnresolvedPath(unresolvedTemplateName)); | |
| 49 | TemplateLoader templateLoader; | |
| 50 | try { | |
| 51 | templateLoader = resolverAdapter.adapt(supportingResolver); | |
| 52 | String resolvedPath = supportingResolver.resolve(new UnresolvedPath(unresolvedTemplateName)).getResolvedPath(); | |
| 53 | Object source = templateLoader.findTemplateSource(resolvedPath); | |
| 54 |
8
1. findTemplateSource : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader::findTemplateSource → TIMED_OUT 2. findTemplateSource : negated conditional → KILLED 3. findTemplateSource : negated conditional → KILLED 4. findTemplateSource : negated conditional → KILLED 5. findTemplateSource : negated conditional → KILLED 6. findTemplateSource : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader::findTemplateSource → KILLED 7. findTemplateSource : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader::findTemplateSource → KILLED 8. findTemplateSource : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader::findTemplateSource → KILLED |
return source == null ? null : new AdaptedSource(source, templateLoader); |
| 55 | ||
| 56 | } catch (NoResolverAdapterException e) { | |
| 57 | throw new ResolverAdapterNotFoundException("Unable to find template source cause no adapter supporting template name '" + unresolvedTemplateName + "' was found. ", e); | |
| 58 | } catch (ResolverAdapterConfigurationException e) { | |
| 59 | throw new ResolverAdapterNotFoundException("Unable to find template source because of invalid adapter configuration for template name '" + unresolvedTemplateName + "'. ", e); | |
| 60 | } catch (ResolverAdapterException e) { | |
| 61 | throw new IOException("Unable to find template source because of adapter failure for template name '" + unresolvedTemplateName + "'. ", e); | |
| 62 | } | |
| 63 | } | |
| 64 | ||
| 65 | @Override | |
| 66 | public long getLastModified(Object templateSource) { | |
| 67 |
1
1. getLastModified : replaced long return with 0 for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader::getLastModified → SURVIVED |
return ((AdaptedSource) templateSource).getLastModified(); |
| 68 | } | |
| 69 | ||
| 70 | @Override | |
| 71 | public Reader getReader(Object templateSource, String encoding) throws IOException { | |
| 72 |
4
1. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader::getReader → TIMED_OUT 2. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader::getReader → KILLED 3. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader::getReader → KILLED 4. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader::getReader → KILLED |
return ((AdaptedSource) templateSource).getReader(encoding); |
| 73 | } | |
| 74 | ||
| 75 | @Override | |
| 76 | public void closeTemplateSource(Object templateSource) throws IOException { | |
| 77 |
1
1. closeTemplateSource : removed call to fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::close → SURVIVED |
((AdaptedSource) templateSource).close(); |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * see freemarker.cache.MultiTemplateLoader.MultiSource | |
| 82 | */ | |
| 83 | static final class AdaptedSource { | |
| 84 | ||
| 85 | private final Object source; | |
| 86 | private final TemplateLoader loader; | |
| 87 | ||
| 88 | AdaptedSource(Object source, TemplateLoader loader) { | |
| 89 | this.source = source; | |
| 90 | this.loader = loader; | |
| 91 | } | |
| 92 | ||
| 93 | long getLastModified() { | |
| 94 |
2
1. getLastModified : replaced long return with 0 for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::getLastModified → SURVIVED 2. getLastModified : replaced long return with 0 for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::getLastModified → TIMED_OUT |
return loader.getLastModified(source); |
| 95 | } | |
| 96 | ||
| 97 | Reader getReader(String encoding) throws IOException { | |
| 98 |
4
1. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::getReader → TIMED_OUT 2. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::getReader → KILLED 3. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::getReader → KILLED 4. getReader : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::getReader → KILLED |
return loader.getReader(source, encoding); |
| 99 | } | |
| 100 | ||
| 101 | void close() throws IOException { | |
| 102 |
2
1. close : removed call to freemarker/cache/TemplateLoader::closeTemplateSource → SURVIVED 2. close : removed call to freemarker/cache/TemplateLoader::closeTemplateSource → TIMED_OUT |
loader.closeTemplateSource(source); |
| 103 | } | |
| 104 | ||
| 105 | Object getWrappedSource() { | |
| 106 |
1
1. getWrappedSource : replaced return value with null for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::getWrappedSource → NO_COVERAGE |
return source; |
| 107 | } | |
| 108 | ||
| 109 | @Override | |
| 110 | public boolean equals(Object o) { | |
| 111 |
1
1. equals : negated conditional → NO_COVERAGE |
if (o instanceof AdaptedSource) { |
| 112 | AdaptedSource m = (AdaptedSource) o; | |
| 113 |
3
1. equals : replaced boolean return with true for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::equals → NO_COVERAGE 2. equals : negated conditional → NO_COVERAGE 3. equals : negated conditional → NO_COVERAGE |
return m.loader.equals(loader) && m.source.equals(source); |
| 114 | } | |
| 115 |
1
1. equals : replaced boolean return with true for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::equals → NO_COVERAGE |
return false; |
| 116 | } | |
| 117 | ||
| 118 | @Override | |
| 119 | public int hashCode() { | |
| 120 |
3
1. hashCode : Replaced integer multiplication with division → NO_COVERAGE 2. hashCode : Replaced integer addition with subtraction → NO_COVERAGE 3. hashCode : replaced int return with 0 for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::hashCode → NO_COVERAGE |
return loader.hashCode() + 31 * source.hashCode(); |
| 121 | } | |
| 122 | ||
| 123 | @Override | |
| 124 | public String toString() { | |
| 125 |
2
1. toString : replaced return value with "" for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::toString → NO_COVERAGE 2. toString : replaced return value with "" for fr/sii/ogham/template/freemarker/FreeMarkerFirstSupportingTemplateLoader$AdaptedSource::toString → TIMED_OUT |
return source.toString(); |
| 126 | } | |
| 127 | } | |
| 128 | } | |
Mutations | ||
| 54 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 67 |
1.1 |
|
| 72 |
1.1 2.2 3.3 4.4 |
|
| 77 |
1.1 |
|
| 94 |
1.1 2.2 |
|
| 98 |
1.1 2.2 3.3 4.4 |
|
| 102 |
1.1 2.2 |
|
| 106 |
1.1 |
|
| 111 |
1.1 |
|
| 113 |
1.1 2.2 3.3 |
|
| 115 |
1.1 |
|
| 120 |
1.1 2.2 3.3 |
|
| 125 |
1.1 2.2 |