/** * Create an HTML Serializer object. * * @param namespaceService a namespace service * @param template the template location * @param css the css to use (comma-delimited for multiple css documents) * @param js the js to use (comma-delimited for multiple js documents) * @param icon an icon, may be {@code null} */ public HtmlSerializer(final NamespaceService namespaceService, final String template, final List<String> css, final List<String> js, final String icon) { this.namespaceService = requireNonNull(namespaceService, "NamespaceService may not be null!"); final String templatePath = ofNullable(template).orElse("org/trellisldp/rdfa/resource.mustache"); final File tpl = new File(templatePath); this.template = tpl.exists() ? mf.compile(templatePath) : mf.compile(getReader(templatePath), templatePath); this.css = ofNullable(css).orElseGet(Collections::emptyList); this.js = ofNullable(js).orElseGet(Collections::emptyList); this.icon = icon; }
/** * Create an HTML Serializer object. * * @param namespaceService a namespace service * @param template the template location * @param css the css to use (comma-delimited for multiple css documents) * @param js the js to use (comma-delimited for multiple js documents) * @param icon an icon, may be {@code null} */ public HtmlSerializer(final NamespaceService namespaceService, final String template, final String css, final String js, final String icon) { this(namespaceService, template, intoList(css), intoList(js), icon); }
@BeforeEach @SuppressWarnings("unchecked") public void setUp() { initMocks(this); final Map<String, String> namespaces = new HashMap<>(); namespaces.put("dc", DCTerms.NS); namespaces.put("rdf", RDF.uri); namespaces.put("dcmitype", "http://purl.org/dc/dcmitype/"); when(mockNamespaceService.getNamespaces()).thenReturn(namespaces); service = new HtmlSerializer(mockNamespaceService); }
@Test public void testHtmlSerializer4() throws Exception { final String path = getClass().getResource("/resource-test.mustache").toURI().getPath(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final RDFaWriterService service4 = new HtmlSerializer(mockNamespaceService, path, "//www.trellisldp.org/assets/css/trellis.css", "", null); service4.write(getTriples(), out, "http://example.com/"); assertAll("HTML check", checkHtmlFromTriples(new String(out.toByteArray(), UTF_8))); }
@Test public void testHtmlSerializer5() throws Exception { final String path = getClass().getResource("/resource-test.mustache").toURI().getPath(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final RDFaWriterService service4 = new HtmlSerializer(new NoopNamespaceService(), path, "//www.trellisldp.org/assets/css/trellis.css", "", null); service4.write(getTriples2(), out, "http://example.com/"); assertAll("HTML check", checkHtmlWithoutNamespaces(new String(out.toByteArray(), UTF_8))); }
/** * Create an HTML Serializer object. * * @param namespaceService a namespace service * @param template the template location * @param css the css to use (comma-delimited for multiple css documents) * @param js the js to use (comma-delimited for multiple js documents) * @param icon an icon, may be {@code null} */ public HtmlSerializer(final NamespaceService namespaceService, final String template, final String css, final String js, final String icon) { this(namespaceService, template, intoList(css), intoList(js), icon); }
/** * Create an HTML Serializer object. * * @param namespaceService a namespace service * @param template the template location * @param css the css to use (comma-delimited for multiple css documents) * @param js the js to use (comma-delimited for multiple js documents) * @param icon an icon, may be {@code null} */ public HtmlSerializer(final NamespaceService namespaceService, final String template, final List<String> css, final List<String> js, final String icon) { this.namespaceService = requireNonNull(namespaceService, "NamespaceService may not be null!"); final String templatePath = ofNullable(template).orElse("org/trellisldp/rdfa/resource.mustache"); final File tpl = new File(templatePath); this.template = tpl.exists() ? mf.compile(templatePath) : mf.compile(getReader(templatePath), templatePath); this.css = ofNullable(css).orElseGet(Collections::emptyList); this.js = ofNullable(js).orElseGet(Collections::emptyList); this.icon = icon; }
@Test public void testDefaultSerializer() { final RDFaWriterService svc = new HtmlSerializer(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); svc.write(getTriples2(), out, "http://example.com/"); assertAll("HTML check", checkHtmlWithoutNamespaces(new String(out.toByteArray(), UTF_8))); }
@Test public void testHtmlSerializer3() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final RDFaWriterService service4 = new HtmlSerializer(mockNamespaceService, "/resource-test.mustache", "//www.trellisldp.org/assets/css/trellis.css", "", "//www.trellisldp.org/assets/img/trellis.png"); service4.write(getTriples(), out, "http://example.com/"); assertAll("HTML check", checkHtmlFromTriples(new String(out.toByteArray(), UTF_8))); }
private static IOService buildIoService(final AppConfiguration config) { final long cacheSize = config.getJsonld().getCacheSize(); final long hours = config.getJsonld().getCacheExpireHours(); final Cache<String, String> cache = newBuilder().maximumSize(cacheSize).expireAfterAccess(hours, HOURS).build(); final TrellisCache<String, String> profileCache = new TrellisCache<>(cache); final NamespaceService namespaceService = new NamespacesJsonContext(config.getNamespaces()); final RDFaWriterService htmlSerializer = new HtmlSerializer(namespaceService, config.getAssets().getTemplate(), config.getAssets().getCss(), config.getAssets().getJs(), config.getAssets().getIcon()); return new JenaIOService(namespaceService, htmlSerializer, profileCache, config.getJsonld().getContextWhitelist(), config.getJsonld().getContextDomainWhitelist()); }