use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class GroovyTemplate method write.
private void write(OutputStream output, OutputParams params, TrainDiagram diagram, Locale locale, Charset outputEncoding) throws OutputException {
try {
Map<String, Object> map = binding.get(diagram, params, locale);
TextTemplate textTemplate = getTextTemplate(params);
if (textTemplate != null) {
textTemplate.evaluate(output, map, outputEncoding.name());
} else {
throw new OutputException("Template missing");
}
binding.postProcess(diagram, params, map);
} catch (OutputException e) {
throw e;
} catch (Exception e) {
throw new OutputException("Error evaluating template", e);
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class OutputWriter method generateOutput.
private void generateOutput(net.parostroj.timetable.model.Output modelOutput) throws OutputException {
OutputTemplate template = modelOutput.getTemplate();
String type = template.getAttribute(OutputTemplate.ATTR_OUTPUT_TYPE, String.class);
OutputFactory factory = OutputFactory.newInstance(template.getOutput());
factory.setParameter("locale", modelOutput.getLocale() != null ? modelOutput.getLocale() : settings.getLocale());
Output output = factory.createOutput(type);
TextTemplate textTemplate = template.getTemplate();
OutputResources resources = new TemplateOutputResources(template);
List<OutputSettings> outputNames = this.createOutputs(modelOutput);
if (outputNames == null) {
this.generateOutput(output, this.getFile(null, getOutputKey(modelOutput), template.getAttributes().get(OutputTemplate.ATTR_OUTPUT_EXTENSION, String.class), factory.getType()), textTemplate, type, null, this.updateContext(modelOutput, template, null), resources, null);
} else {
for (OutputSettings outputName : outputNames) {
this.generateOutput(output, this.getFile(outputName.directory, outputName.name), textTemplate, type, outputName.params, this.updateContext(modelOutput, template, outputName.context), resources, outputName.encoding);
}
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class OutputWriter method createOutputs.
private List<OutputSettings> createOutputs(net.parostroj.timetable.model.Output modelOutput) throws OutputException {
OutputTemplate template = modelOutput.getTemplate();
List<OutputSettings> result = null;
if (template.getScript() != null) {
final List<OutputSettings> out = new ArrayList<>();
Map<String, Object> binding = new HashMap<>();
binding.put("diagram", diagram);
binding.put("output", modelOutput);
binding.put("log", scriptLog);
binding.put("settings", new WrapperLogMap<>(modelOutput.getSettings().getAttributesMap(net.parostroj.timetable.model.Output.CATEGORY_SETTINGS), scriptLog, "settings"));
binding.put("localization", new WrapperLogMap<>(template.getAttributes().getAttributesMap(OutputTemplate.CATEGORY_I18N), scriptLog, "localization"));
binding.put("locale", modelOutput.getLocale() != null ? modelOutput.getLocale() : settings.getLocale());
binding.put("key", getOutputKey(modelOutput));
binding.put("selection", modelOutput.getSelection());
binding.put("util", new OutputUtil());
binding.put("outputs", new OutputCollector() {
@Override
public void add(String name, Map<String, Object> context) {
out.add(new OutputSettings().setName(name).setContext(context));
}
@Override
public void add(String name, Map<String, Object> context, String encoding) {
out.add(new OutputSettings().setName(name).setContext(context).setEncoding(encoding));
}
@Override
public OutputSettings create() {
OutputSettings lSettings = new OutputSettings();
out.add(lSettings);
return lSettings;
}
});
try {
template.getScript().evaluateWithException(binding);
} catch (GrafikonException e) {
throw new OutputException("Error in script: " + e.getMessage(), e);
}
result = out;
}
return result;
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class XmlTrainTimetablesOutput method writeTo.
@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
try {
// extract tts
List<Train> trains = SelectionHelper.selectTrains(params, diagram);
List<Route> routes = SelectionHelper.getRoutes(params, diagram, trains);
TrainsCycle cycle = SelectionHelper.getDriverCycle(params);
TrainTimetablesExtractor te = new TrainTimetablesExtractor(diagram, trains, routes, cycle, this.getLocale());
TrainTimetables tt = te.getTrainTimetables();
JAXBContext context = JAXBContext.newInstance(TrainTimetables.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, this.getCharset().name());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Writer writer = new OutputStreamWriter(stream, this.getCharset());
m.marshal(tt, writer);
} catch (Exception e) {
throw new OutputException(e);
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class XmlCustomCyclesOutput method writeTo.
@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
try {
// check for type
OutputParam param = params.get("cycle_type");
TrainsCycleType type = param != null ? param.getValue(TrainsCycleType.class) : null;
// extract
CustomCyclesExtractor tuce = new CustomCyclesExtractor(SelectionHelper.selectCycles(params, diagram, type));
CustomCycles cycles = new CustomCycles(tuce.getCycles());
JAXBContext context = JAXBContext.newInstance(CustomCycles.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, this.getCharset().name());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Writer writer = new OutputStreamWriter(stream, this.getCharset());
m.marshal(cycles, writer);
} catch (Exception e) {
throw new OutputException(e);
}
}
Aggregations