1818import static java .nio .charset .StandardCharsets .UTF_8 ;
1919import static java .util .Collections .emptyList ;
2020import static java .util .stream .Collectors .toList ;
21+ import static org .slf4j .LoggerFactory .getLogger ;
2122
2223import com .github .mustachejava .DefaultMustacheFactory ;
2324import com .github .mustachejava .Mustache ;
2425import com .github .mustachejava .MustacheFactory ;
2526
26- import java .io .File ;
2727import java .io .IOException ;
28- import java .io .InputStreamReader ;
2928import java .io .OutputStream ;
3029import java .io .OutputStreamWriter ;
31- import java .io .Reader ;
3230import java .io .UncheckedIOException ;
3331import java .io .Writer ;
3432import java .util .Collections ;
4240
4341import org .apache .commons .rdf .api .Triple ;
4442import org .eclipse .microprofile .config .inject .ConfigProperty ;
43+ import org .slf4j .Logger ;
4544import org .trellisldp .api .NamespaceService ;
4645import org .trellisldp .api .RDFaWriterService ;
4746
5150@ ApplicationScoped
5251public class DefaultRdfaWriterService implements RDFaWriterService {
5352
54- private static final MustacheFactory mf = new DefaultMustacheFactory ( );
53+ private static final Logger LOGGER = getLogger ( DefaultRdfaWriterService . class );
5554
5655 /** The configuration key controlling the HTML template to use. */
5756 public static final String CONFIG_RDFA_TEMPLATE = "trellis.rdfa.template" ;
@@ -65,6 +64,7 @@ public class DefaultRdfaWriterService implements RDFaWriterService {
6564 /** The configuration key controlling the JS URLs to use. */
6665 public static final String CONFIG_RDFA_JS = "trellis.rdfa.js" ;
6766
67+ private MustacheFactory mf ;
6868 private Mustache template ;
6969
7070 @ Inject
@@ -90,9 +90,10 @@ public class DefaultRdfaWriterService implements RDFaWriterService {
9090
9191 @ PostConstruct
9292 void init () {
93- final String templatePath = templateLocation .orElse ("org/trellisldp/rdfa/resource.mustache" );
94- final File file = new File (templatePath );
95- template = file .exists () ? mf .compile (templatePath ) : mf .compile (getReader (templatePath ), templatePath );
93+ final String resource = templateLocation .orElse ("org/trellisldp/rdfa/resource.mustache" );
94+ LOGGER .info ("Using RDFa writer template: {}" , resource );
95+ mf = new DefaultMustacheFactory ();
96+ template = mf .compile (resource );
9697 }
9798
9899 /**
@@ -116,9 +117,4 @@ public void write(final Stream<Triple> triples, final OutputStream out, final St
116117 throw new UncheckedIOException (ex );
117118 }
118119 }
119-
120- static Reader getReader (final String template ) {
121- return new InputStreamReader (Thread .currentThread ().getContextClassLoader ()
122- .getResourceAsStream (template ), UTF_8 );
123- }
124120}
0 commit comments