Search in sources :

Example 11 with OutputException

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);
    }
}
Also used : OutputException(net.parostroj.timetable.output2.OutputException) TextTemplate(net.parostroj.timetable.model.TextTemplate) OutputException(net.parostroj.timetable.output2.OutputException)

Example 12 with OutputException

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);
        }
    }
}
Also used : TemplateOutputResources(net.parostroj.timetable.output2.template.TemplateOutputResources) TemplateOutputResources(net.parostroj.timetable.output2.template.TemplateOutputResources)

Example 13 with OutputException

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;
}
Also used : OutputUtil(net.parostroj.timetable.output2.util.OutputUtil)

Example 14 with OutputException

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);
    }
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) TrainTimetablesExtractor(net.parostroj.timetable.output2.impl.TrainTimetablesExtractor) TrainTimetables(net.parostroj.timetable.output2.impl.TrainTimetables) Train(net.parostroj.timetable.model.Train) Route(net.parostroj.timetable.model.Route) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 15 with OutputException

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);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) CustomCycles(net.parostroj.timetable.output2.impl.CustomCycles) OutputParam(net.parostroj.timetable.output2.OutputParam) OutputException(net.parostroj.timetable.output2.OutputException) CustomCyclesExtractor(net.parostroj.timetable.output2.impl.CustomCyclesExtractor) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) OutputException(net.parostroj.timetable.output2.OutputException) TrainsCycleType(net.parostroj.timetable.model.TrainsCycleType)

Aggregations

OutputException (net.parostroj.timetable.output2.OutputException)13 OutputStreamWriter (java.io.OutputStreamWriter)9 Writer (java.io.Writer)9 JAXBContext (javax.xml.bind.JAXBContext)8 Marshaller (javax.xml.bind.Marshaller)8 Dimension (java.awt.Dimension)4 IOException (java.io.IOException)4 Font (java.awt.Font)2 InputStream (java.io.InputStream)2 StreamSource (javax.xml.transform.stream.StreamSource)2 Position (net.parostroj.timetable.output2.impl.Position)2 PositionsExtractor (net.parostroj.timetable.output2.impl.PositionsExtractor)2 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)2 PDFDocumentGraphics2D (org.apache.fop.svg.PDFDocumentGraphics2D)2 Frame (java.awt.Frame)1 Graphics2D (java.awt.Graphics2D)1 RenderingHints (java.awt.RenderingHints)1 Key (java.awt.RenderingHints.Key)1 BufferedImage (java.awt.image.BufferedImage)1 URI (java.net.URI)1