use of fr.opensagres.xdocreport.template.FieldExtractor in project SORMAS-Project by hzi-braunschweig.
the class TemplateEngine method extractTemplateVariablesDocx.
public DocumentVariables extractTemplateVariablesDocx(File templateFile) throws DocumentTemplateException {
try {
FileInputStream templateInputStream = new FileInputStream(templateFile);
IXDocReport report = readXDocReport(templateInputStream);
FieldsExtractor<FieldExtractor> extractor = FieldsExtractor.create();
report.extractFields(extractor);
return filterExtractedVariables(extractor);
} catch (XDocReportException | IOException e) {
throw new DocumentTemplateException(String.format(I18nProperties.getString(Strings.errorReadingTemplate), templateFile.getName()));
}
}
use of fr.opensagres.xdocreport.template.FieldExtractor in project SORMAS-Project by hzi-braunschweig.
the class TemplateEngine method getFieldExtractorTxt.
private FieldsExtractor<FieldExtractor> getFieldExtractorTxt(Reader templateFileReader, String templateName) throws DocumentTemplateException {
FieldsExtractor<FieldExtractor> extractor = FieldsExtractor.create();
ExtractVariablesVelocityVisitor visitor = new ExtractVariablesVelocityVisitor(extractor);
try {
Template template = new Template();
template.setName(templateName);
SimpleNode document = RuntimeSingleton.parse(templateFileReader, template);
document.jjtAccept(visitor, null);
return extractor;
} catch (ParseException e) {
throw new DocumentTemplateException(I18nProperties.getString(Strings.errorProcessingTemplate));
}
}
use of fr.opensagres.xdocreport.template.FieldExtractor in project SORMAS-Project by hzi-braunschweig.
the class TemplateEngine method extractTemplateVariablesTxt.
public DocumentVariables extractTemplateVariablesTxt(File templateFile) throws DocumentTemplateException {
try {
FileReader templateFileReader = new FileReader(templateFile);
String templateName = templateFile.getName();
FieldsExtractor<FieldExtractor> extractor = getFieldExtractorTxt(templateFileReader, templateName);
return filterExtractedVariables(extractor);
} catch (IOException e) {
throw new DocumentTemplateException(String.format(I18nProperties.getString(Strings.errorReadingTemplate), templateFile.getName()));
}
}
use of fr.opensagres.xdocreport.template.FieldExtractor in project SORMAS-Project by hzi-braunschweig.
the class TemplateEngine method filterExtractedVariables.
private DocumentVariables filterExtractedVariables(FieldsExtractor<FieldExtractor> extractor) {
Set<String> variables = new HashSet<>();
Set<String> nullableVariables = new HashSet<>();
for (FieldExtractor field : extractor.getFields()) {
String fieldName = field.getName();
Matcher matcher = VARIABLE_PATTERN.matcher(fieldName);
if (matcher.matches()) {
String withBrackets = matcher.group(3);
String withoutBrackets = matcher.group(5);
String variable = withBrackets != null ? withBrackets : withoutBrackets;
if (variable != null) {
variables.add(variable);
}
if (matcher.group(2) != null || matcher.group(4) != null) {
nullableVariables.add(variable);
} else {
nullableVariables.remove(variable);
}
}
}
return new DocumentVariables(variables, nullableVariables);
}
use of fr.opensagres.xdocreport.template.FieldExtractor in project SORMAS-Project by hzi-braunschweig.
the class TemplateEngine method validateTemplateDocx.
public void validateTemplateDocx(InputStream templateInputStream) throws DocumentTemplateException {
try {
IXDocReport report = readXDocReport(templateInputStream);
FieldsExtractor<FieldExtractor> extractor = FieldsExtractor.create();
report.extractFields(extractor);
} catch (XDocReportException | IOException e) {
throw new DocumentTemplateException(I18nProperties.getString(Strings.errorProcessingTemplate));
}
}
Aggregations