Search in sources :

Example 16 with OutputException

use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.

the class XmlDriverCyclesOutput method writeTo.

@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
    try {
        DriverCyclesExtractor dce = new DriverCyclesExtractor(diagram, SelectionHelper.selectCycles(params, diagram, diagram.getDriverCycleType()), true);
        DriverCycles cycles = dce.getDriverCycles();
        JAXBContext context = JAXBContext.newInstance(DriverCycles.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) OutputException(net.parostroj.timetable.output2.OutputException) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) DriverCyclesExtractor(net.parostroj.timetable.output2.impl.DriverCyclesExtractor) DriverCycles(net.parostroj.timetable.output2.impl.DriverCycles) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) OutputException(net.parostroj.timetable.output2.OutputException)

Example 17 with OutputException

use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.

the class XmlEngineCyclesOutput method writeTo.

@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
    try {
        EngineCyclesExtractor tuce = new EngineCyclesExtractor(SelectionHelper.selectCycles(params, diagram, diagram.getEngineCycleType()));
        EngineCycles cycles = new EngineCycles(tuce.getEngineCycles());
        JAXBContext context = JAXBContext.newInstance(EngineCycles.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 : EngineCyclesExtractor(net.parostroj.timetable.output2.impl.EngineCyclesExtractor) Marshaller(javax.xml.bind.Marshaller) OutputException(net.parostroj.timetable.output2.OutputException) EngineCycles(net.parostroj.timetable.output2.impl.EngineCycles) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) OutputException(net.parostroj.timetable.output2.OutputException)

Example 18 with OutputException

use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.

the class PdfTransformer method getFopFactory.

private static FopFactory getFopFactory(URIResolver resolver) throws OutputException {
    try (InputStream fopCfgStream = ResourceHelper.getStream("fop/fop-cfg.xml", PdfTransformer.class.getClassLoader())) {
        // base uri is empty
        URI baseURI = new URI("");
        FopConfParser parser = new FopConfParser(fopCfgStream, EnvironmentalProfileFactory.createRestrictedIO(baseURI, convertResolver(resolver)));
        FopFactory fopFactory = parser.getFopFactoryBuilder().build();
        fopFactory.getFontManager().disableFontCache();
        return fopFactory;
    } catch (IOException | SAXException | URISyntaxException e) {
        throw new OutputException("Error creating FOP factory", e);
    }
}
Also used : InputStream(java.io.InputStream) OutputException(net.parostroj.timetable.output2.OutputException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) SAXException(org.xml.sax.SAXException)

Example 19 with OutputException

use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.

the class DrawOutput method processSvg.

private void processSvg(Collection<Image> images, OutputStream stream, DrawLayout layout) throws OutputException {
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    // Create an instance of org.w3c.dom.Document.
    String svgNS = "http://www.w3.org/2000/svg";
    Document document = domImpl.createDocument(svgNS, "svg", null);
    SVGGeneratorContext context = SVGGeneratorContext.createDefault(document);
    context.setGraphicContextDefaults(new SVGGeneratorContext.GraphicContextDefaults());
    // set default font
    context.getGraphicContextDefaults().setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
    // set antialiasing
    Map<Key, Object> map = new HashMap<>();
    map.put(RenderingHints.KEY_ANTIALIASING, Boolean.TRUE);
    map.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    context.getGraphicContextDefaults().setRenderingHints(new RenderingHints(map));
    SVGGraphics2D g2d = new SVGGraphics2D(context, false);
    List<Dimension> sizes = this.getSizes(images, g2d);
    Dimension size = this.getTotalSize(sizes, layout);
    g2d.setSVGCanvasSize(size);
    this.drawImages(sizes, images, g2d, layout);
    // write to ouput - do not use css style
    boolean useCSS = false;
    try {
        Writer out = new OutputStreamWriter(stream, "UTF-8");
        g2d.stream(out, useCSS);
    } catch (IOException e) {
        throw new OutputException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) DOMImplementation(org.w3c.dom.DOMImplementation) GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Dimension(java.awt.Dimension) IOException(java.io.IOException) Document(org.w3c.dom.Document) SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext) Font(java.awt.Font) RenderingHints(java.awt.RenderingHints) OutputException(net.parostroj.timetable.output2.OutputException) OutputStreamWriter(java.io.OutputStreamWriter) Key(java.awt.RenderingHints.Key) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

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