import java.nio.file.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.*;
import com.fasterxml.jackson.databind.*;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.templateresolver.StringTemplateResolver;
import org.thymeleaf.templatemode.TemplateMode;
public class JsonLdRegression {
public static final class GlobalData {
private final String jsonLd;
GlobalData(String value) { this.jsonLd = value; }
public String getJsonLd() { return jsonLd; }
}
public static void main(String[] args) throws Exception {
String header = new String(Files.readAllBytes(Paths.get(args[0])), StandardCharsets.UTF_8);
Matcher matcher = Pattern.compile("").matcher(header);
if (!matcher.find()) throw new IllegalStateException("Actual JSON-LD template fragment missing");
String fragment = matcher.group();
if (matcher.find()) throw new IllegalStateException("Ambiguous JSON-LD template fragment");
StringTemplateResolver resolver = new StringTemplateResolver();
resolver.setTemplateMode(TemplateMode.HTML);
resolver.setCacheable(false);
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.setTemplateResolver(resolver);
ObjectMapper mapper = new ObjectMapper();
String[] names = {"ordinary", "quote-and-slash", "unicode", "ampersand",
"less-than-text", "sample-tag", "comparison", "two-markers", "unicode-marker",
"newline-marker", "mixed-markers", "unicode-separators"};
String[] values = {"ordinary profile", "quotes \" and slash \\", "Unicode café 雪", "ampersand & plain",
"plain < marker", "", "left < right", "two ", "",
"line\n", "mixed \"\" &", "separator \u2028\u2029"};
int passed=0, failed=0;
for (int i=0; i data = new LinkedHashMap();
data.put("@context","https://schema.org");
data.put("@type","Person");
data.put("description",values[i]);
String original = mapper.writeValueAsString(data);
Context context = new Context(Locale.ROOT);
context.setVariable("global", new GlobalData(original));
String rendered = engine.process(fragment,context);
int begin = rendered.indexOf('>')+1, end = rendered.lastIndexOf("");
if (begin<=0 || end