Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ext {
jenaVersion = "4.0.0"
jsonldVersion = "0.13.0"
liquibaseVersion = "4.3.4"
mustacheVersion = "0.9.6"
mustacheVersion = "0.9.7"
quarkusVersion = "1.13.2.Final"
rxjavaVersion = "2.2.21"
snakeyamlVersion = "1.28"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
import static org.slf4j.LoggerFactory.getLogger;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.util.Collections;
Expand All @@ -42,6 +40,7 @@

import org.apache.commons.rdf.api.Triple;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.slf4j.Logger;
import org.trellisldp.api.NamespaceService;
import org.trellisldp.api.RDFaWriterService;

Expand All @@ -51,7 +50,7 @@
@ApplicationScoped
public class DefaultRdfaWriterService implements RDFaWriterService {

private static final MustacheFactory mf = new DefaultMustacheFactory();
private static final Logger LOGGER = getLogger(DefaultRdfaWriterService.class);

/** The configuration key controlling the HTML template to use. */
public static final String CONFIG_RDFA_TEMPLATE = "trellis.rdfa.template";
Expand All @@ -65,6 +64,7 @@ public class DefaultRdfaWriterService implements RDFaWriterService {
/** The configuration key controlling the JS URLs to use. */
public static final String CONFIG_RDFA_JS = "trellis.rdfa.js";

private MustacheFactory mf;
private Mustache template;

@Inject
Expand All @@ -90,9 +90,10 @@ public class DefaultRdfaWriterService implements RDFaWriterService {

@PostConstruct
void init() {
final String templatePath = templateLocation.orElse("org/trellisldp/rdfa/resource.mustache");
final File file = new File(templatePath);
template = file.exists() ? mf.compile(templatePath) : mf.compile(getReader(templatePath), templatePath);
final String resource = templateLocation.orElse("org/trellisldp/rdfa/resource.mustache");
LOGGER.info("Using RDFa writer template: {}", resource);
mf = new DefaultMustacheFactory();
template = mf.compile(resource);
}

/**
Expand All @@ -116,9 +117,4 @@ public void write(final Stream<Triple> triples, final OutputStream out, final St
throw new UncheckedIOException(ex);
}
}

static Reader getReader(final String template) {
return new InputStreamReader(Thread.currentThread().getContextClassLoader()
.getResourceAsStream(template), UTF_8);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import javax.ws.rs.ProcessingException;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.commons.rdf.api.Graph;
Expand Down Expand Up @@ -109,6 +110,7 @@ default Stream<Executable> runTests() throws Exception {
return Stream.of(this::testGetJsonLdDefault,
this::testGetJsonLdCompacted,
this::testGetNTriples,
this::testGetRDFa,
this::testGetRDF,
this::testRdfContainment,
this::testPostJsonLd,
Expand Down Expand Up @@ -219,6 +221,12 @@ default void testGetNTriples() {
}
}

default void testGetRDFa() {
try (final Response res = target(getResourceLocation()).request().accept(MediaType.TEXT_HTML).get()) {
assertAll("Check for RDFa", checkRdfResponse(res, LDP.RDFSource, MediaType.TEXT_HTML_TYPE));
}
}

/**
* Test POSTing an RDF resource.
*/
Expand Down