use of edu.princeton.cs.algs4.ST in project bookish by parrt.
the class Tool method legacy_translate.
// legacy single-doc translation
public Pair<Document, String> legacy_translate(Translator trans, String inputDir, String inputFilename) throws IOException {
Pair<BookishParser.DocumentContext, BookishParser> results = parseChapter(inputDir, inputFilename, 0);
trans.entities = results.b.entities;
// get single chapter
Document doc = (Document) trans.visit(results.a);
doc.chapter.connectContainerTree();
ModelConverter converter = new ModelConverter(trans.templates);
ST outputST = converter.walk(doc);
return new Pair<>(doc, outputST.render());
}
use of edu.princeton.cs.algs4.ST in project inmemantlr by julianthome.
the class StringCodeGenPipeline method getTokenVocabOutput.
ST getTokenVocabOutput() {
ST vocabFileST = new ST(CodeGenerator.vocabFilePattern);
Map<String, Integer> tokens = new LinkedHashMap<>();
// make constants for the token names
for (String t : g.tokenNameToTypeMap.keySet()) {
int tokenType = g.tokenNameToTypeMap.get(t);
if (tokenType >= Token.MIN_USER_TOKEN_TYPE) {
tokens.put(t, tokenType);
}
}
vocabFileST.add("tokenvocab", tokens);
// now dump the strings
Map<String, Integer> literals = new LinkedHashMap<>();
for (String literal : g.stringLiteralToTypeMap.keySet()) {
int tokenType = g.stringLiteralToTypeMap.get(literal);
if (tokenType >= Token.MIN_USER_TOKEN_TYPE) {
literals.put(literal, tokenType);
}
}
vocabFileST.add("literals", literals);
return vocabFileST;
}
use of edu.princeton.cs.algs4.ST in project jdbi by jdbi.
the class UseStringTemplateSqlLocatorImpl method configureForType.
@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
SqlLocator locator = (type, method, config) -> {
String templateName = SqlAnnotations.getAnnotationValue(method, sql -> sql).orElseGet(method::getName);
STGroup group = findStringTemplateGroup(type);
if (!group.isDefined(templateName)) {
throw new IllegalStateException("No StringTemplate group " + templateName + " for class " + sqlObjectType);
}
return templateName;
};
TemplateEngine templateEngine = (templateName, ctx) -> {
STGroup group = findStringTemplateGroup(sqlObjectType);
ST template = group.getInstanceOf(templateName);
ctx.getAttributes().forEach(template::add);
return template.render();
};
registry.get(SqlObjects.class).setSqlLocator(locator);
registry.get(SqlStatements.class).setTemplateEngine(templateEngine);
}
use of edu.princeton.cs.algs4.ST in project webcert by sklintyg.
the class ReceiveMedicalCertificateAnswerIT method testCreateAnswerWithInvalidXMLFailsWithApplicationError.
/**
* Trigger a soapfault by sending a totally nonsense request - Soap faults should get transformed to a valid
* (application) error response
*/
@Test
public void testCreateAnswerWithInvalidXMLFailsWithApplicationError() {
ST brokenTemplate = templateGroup.getInstanceOf("brokenrequest");
given().body(brokenTemplate.render()).when().post(RECEIVE_QUESTION_V1_0).then().statusCode(200).rootPath(BASE).body("result.resultCode", is(ResultCodeType.ERROR.value())).body("result.errorId", is(ErrorIdType.APPLICATION_ERROR.value()));
}
use of edu.princeton.cs.algs4.ST in project jbpm by kiegroup.
the class WidProcessor method getTemplateData.
public byte[] getTemplateData(String templateResource, Map<String, WidInfo> widInfoMap) throws IOException {
ST stTemplate = new ST(getTemplateResourceFileAsString(templateResource), '$', '$');
stTemplate.add("widInfo", widInfoMap);
stTemplate.add("openbracket", "{");
stTemplate.add("closebracket", "}");
return stTemplate.render().getBytes();
}
Aggregations