18
18
import static java .nio .charset .StandardCharsets .UTF_8 ;
19
19
import static java .util .Collections .emptyList ;
20
20
import static java .util .stream .Collectors .toList ;
21
+ import static org .slf4j .LoggerFactory .getLogger ;
21
22
22
23
import com .github .mustachejava .DefaultMustacheFactory ;
23
24
import com .github .mustachejava .Mustache ;
24
25
import com .github .mustachejava .MustacheFactory ;
25
26
26
- import java .io .File ;
27
27
import java .io .IOException ;
28
- import java .io .InputStreamReader ;
29
28
import java .io .OutputStream ;
30
29
import java .io .OutputStreamWriter ;
31
- import java .io .Reader ;
32
30
import java .io .UncheckedIOException ;
33
31
import java .io .Writer ;
34
32
import java .util .Collections ;
42
40
43
41
import org .apache .commons .rdf .api .Triple ;
44
42
import org .eclipse .microprofile .config .inject .ConfigProperty ;
43
+ import org .slf4j .Logger ;
45
44
import org .trellisldp .api .NamespaceService ;
46
45
import org .trellisldp .api .RDFaWriterService ;
47
46
51
50
@ ApplicationScoped
52
51
public class DefaultRdfaWriterService implements RDFaWriterService {
53
52
54
- private static final MustacheFactory mf = new DefaultMustacheFactory ( );
53
+ private static final Logger LOGGER = getLogger ( DefaultRdfaWriterService . class );
55
54
56
55
/** The configuration key controlling the HTML template to use. */
57
56
public static final String CONFIG_RDFA_TEMPLATE = "trellis.rdfa.template" ;
@@ -65,6 +64,7 @@ public class DefaultRdfaWriterService implements RDFaWriterService {
65
64
/** The configuration key controlling the JS URLs to use. */
66
65
public static final String CONFIG_RDFA_JS = "trellis.rdfa.js" ;
67
66
67
+ private MustacheFactory mf ;
68
68
private Mustache template ;
69
69
70
70
@ Inject
@@ -90,9 +90,10 @@ public class DefaultRdfaWriterService implements RDFaWriterService {
90
90
91
91
@ PostConstruct
92
92
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 );
96
97
}
97
98
98
99
/**
@@ -116,9 +117,4 @@ public void write(final Stream<Triple> triples, final OutputStream out, final St
116
117
throw new UncheckedIOException (ex );
117
118
}
118
119
}
119
-
120
- static Reader getReader (final String template ) {
121
- return new InputStreamReader (Thread .currentThread ().getContextClassLoader ()
122
- .getResourceAsStream (template ), UTF_8 );
123
- }
124
120
}
0 commit comments