Package org.apache.fop.util

Examples of org.apache.fop.util.UnclosableInputStream


        private FopImage.ImageInfo getImage(String uri, InputStream fis,
                float pixelUnitToMM) {
            // parse document and get the size attributes of the svg element

            try {
                fis = new UnclosableInputStream(fis);

                FopImage.ImageInfo info = new FopImage.ImageInfo();

                //Set the resolution to that of the FOUserAgent
                info.dpiHorizontal = 25.4f / pixelUnitToMM;
View Full Code Here


        Document doc = null;
        FopImage.ImageInfo info = new FopImage.ImageInfo();
        info.mimeType = getMimeType();

        try {
            final InputStream is = new UnclosableInputStream(input);
            int length = is.available();
            is.mark(length);

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            doc = dbf.newDocumentBuilder().parse(is);
            info.data = doc;
View Full Code Here

                SVGDocument doc;
                if (src instanceof DOMSource) {
                    DOMSource domSrc = (DOMSource)src;
                    doc = (SVGDocument)domSrc.getNode();
                } else {
                    in = new UnclosableInputStream(ImageUtil.needInputStream(src));
                    int length = in.available();
                    in.mark(length + 1);
                    SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
                            getParserName());
                    doc = factory.createSVGDocument(src.getSystemId(), in);
View Full Code Here

        return info;
    }

    private ImageInfo getImage(String uri, Source src, ImageContext context) throws IOException {

        InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src));
        try {
            Document planDoc = getDocument(in);
            Element rootEl = planDoc.getDocumentElement();
            if (!PlanElementMapping.NAMESPACE.equals(
                    rootEl.getNamespaceURI())) {
                in.reset();
                return null;
            }

            //Have to render the plan to know its size
            PlanRenderer pr = new PlanRenderer();
            Document svgDoc = pr.createSVGDocument(planDoc);
            float width = pr.getWidth();
            float height = pr.getHeight();

            //Return converted SVG image
            ImageInfo info = new ImageInfo(uri, "image/svg+xml");
            final ImageSize size = new ImageSize();
            size.setSizeInMillipoints(
                    Math.round(width * 1000),
                    Math.round(height * 1000));
            //Set the resolution to that of the FOUserAgent
            size.setResolution(context.getSourceResolution());
            size.calcPixelsFromSize();
            info.setSize(size);

            //The whole image had to be loaded for this, so keep it
            Image image = new ImageXMLDOM(info, svgDoc,
                    svgDoc.getDocumentElement().getNamespaceURI());
            info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image);

            return info;
        } catch (TransformerException e) {
            try {
                in.reset();
            } catch (IOException ioe) {
                // we're more interested in the original exception
            }
            log.debug("Error while trying to parsing a Plan file: "
                    + e.getMessage());
View Full Code Here

        return info;
    }

    private ImageInfo getImage(String uri, Source src, ImageContext context) {

        InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src));
        try {
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            Source source = new StreamSource(in);
            DOMResult res = new DOMResult();
            transformer.transform(source, res);
           
            //Have to render the plan to know its size
            PlanRenderer pr = new PlanRenderer();
            Document svgDoc = pr.createSVGDocument((Document)res.getNode());
            float width = pr.getWidth();
            float height = pr.getHeight();
           
            //Return converted SVG image
            ImageInfo info = new ImageInfo(uri, "image/svg+xml");
            final ImageSize size = new ImageSize();
            size.setSizeInMillipoints(
                    Math.round(width * 1000),
                    Math.round(height * 1000));
            //Set the resolution to that of the FOUserAgent
            size.setResolution(context.getSourceResolution());
            size.calcPixelsFromSize();
            info.setSize(size);

            //The whole image had to be loaded for this, so keep it
            Image image = new ImageXMLDOM(info, svgDoc,
                    svgDoc.getDocumentElement().getNamespaceURI());
            info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image);
           
            return info;
        } catch (TransformerException e) {
            try {
                in.reset();
            } catch (IOException ioe) {
                // we're more interested in the original exception
            }
            log.debug("Error while trying to parsing a Plan file: "
                    + e.getMessage());
View Full Code Here

     */
    class Loader {
       
        private ImageInfo getImage(String uri, Source src, ImageContext context) {

            InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src));
            try {
                int length = in.available();
                in.mark(length + 1);
               
                TransformerFactory tFactory = TransformerFactory.newInstance();
                Transformer transformer = tFactory.newTransformer();
                Source source = new StreamSource(in);
                SAXMathBuilder mathBuilder = new SAXMathBuilder();
                SAXResult res = new SAXResult(mathBuilder);
                transformer.transform(source, res);
               
                String fontname = "Helvetica";
                int fontstyle = 0;
                int displayfontsize = 12;
                int inlinefontsize = 12;

                if (mathBuilder.getMathRootElement() == null) {
                    //not a MathML document
                    try {
                        in.reset();
                    } catch (IOException ioe) {
                        log.error("Error while resetting ImageInputStream", ioe);
                    }
                    return null;
                }
                final MathBase base = new MathBase(
                                  mathBuilder.getMathRootElement(),
                                  fontname, fontstyle, inlinefontsize,
                                  displayfontsize);
               
                ImageInfo info = new ImageInfo(uri, "text/mathml");
                final ImageSize size = new ImageSize();
                size.setSizeInMillipoints(
                        Math.round(base.getWidth() * 1000),
                        Math.round(base.getHeight() * 1000));
                //Set the resolution to that of the FOUserAgent
                size.setResolution(context.getSourceResolution());
                size.calcPixelsFromSize();
                info.setSize(size);

                Graphics2DImagePainter painter = new Graphics2DImagePainter() {

                    public Dimension getImageSize() {
                        return size.getDimensionMpt();
                    }

                    public void paint(Graphics2D g2d, Rectangle2D area) {
                        base.paint(g2d);
                    }
                   
                };
               
                //The whole image had to be loaded for this, so keep it
                Image image = new ImageGraphics2D(info, painter);
                info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image);
               
                return info;
            } catch (NoClassDefFoundError ncdfe) {
                try {
                    in.reset();
                } catch (IOException ioe) {
                    // we're more interested in the original exception
                }
                jeuclidAvailable = false;
                log.warn("JEuclid not in class path", ncdfe);
                return null;
            } catch (IOException e) {
                // If the MathML is invalid then it throws an IOException
                // so there is no way of knowing if it is an svg document

                log.debug("Error while trying to load stream as an MathML file: "
                                       + e.getMessage());
                // assuming any exception means this document is not svg
                // or could not be loaded for some reason
                try {
                    in.reset();
                } catch (IOException ioe) {
                    // we're more interested in the original exception
                }
                return null;
            } catch (TransformerException e) {
                try {
                    in.reset();
                } catch (IOException ioe) {
                    // we're more interested in the original exception
                }
                log.debug("Error while trying to parsing a MathML file: "
                        + e.getMessage());
View Full Code Here

    class Loader {
        private ImageInfo getImage(String uri, Source src,
                ImageContext context) {
            // parse document and get the size attributes of the svg element

            InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src));
            try {
                in.mark(4 + 1);
               
                DataInputStream din = new DataInputStream(in);
                int magic = EndianUtils.swapInteger(din.readInt());
                din.reset();
                if (magic != WMFConstants.META_ALDUS_APM) {
                    return null; //Not a WMF file
                }

                WMFRecordStore wmfStore = new WMFRecordStore();
                wmfStore.read(din);
                IOUtils.closeQuietly(din);
               
                int width = wmfStore.getWidthUnits();
                int height = wmfStore.getHeightUnits();
                int dpi = wmfStore.getMetaFileUnitsPerInch();
               
                ImageInfo info = new ImageInfo(uri, "image/x-wmf");
                ImageSize size = new ImageSize();
                size.setSizeInPixels(width, height);
                size.setResolution(dpi);
                size.calcSizeFromPixels();
                info.setSize(size);
                ImageWMF img = new ImageWMF(info, wmfStore);
                info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, img);
               
                return info;
            } catch (NoClassDefFoundError ncdfe) {
                try {
                    in.reset();
                } catch (IOException ioe) {
                    // we're more interested in the original exception
                }
                batikAvailable = false;
                log.warn("Batik not in class path", ncdfe);
                return null;
            } catch (IOException e) {
                // If the svg is invalid then it throws an IOException
                // so there is no way of knowing if it is an svg document

                log.debug("Error while trying to load stream as an WMF file: "
                                       + e.getMessage());
                // assuming any exception means this document is not svg
                // or could not be loaded for some reason
                try {
                    in.reset();
                } catch (IOException ioe) {
                    // we're more interested in the original exception
                }
                return null;
            }
View Full Code Here

                SVGDocument doc;
                if (src instanceof DOMSource) {
                    DOMSource domSrc = (DOMSource)src;
                    doc = (SVGDocument)domSrc.getNode();
                } else {
                    in = new UnclosableInputStream(ImageUtil.needInputStream(src));
                    int length = in.available();
                    in.mark(length + 1);
                    SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
                            getParserName());
                    doc = (SVGDocument) factory.createSVGDocument(src.getSystemId(), in);
View Full Code Here

        private ImageInfo getImage(String uri, Source src,
                ImageContext context) {
            // parse document and get the size attributes of the svg element

            InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src));
            try {
                in.mark(4 + 1);

                DataInputStream din = new DataInputStream(in);
                int magic = EndianUtils.swapInteger(din.readInt());
                din.reset();
                if (magic != WMFConstants.META_ALDUS_APM) {
                    return null; //Not a WMF file
                }

                WMFRecordStore wmfStore = new WMFRecordStore();
                wmfStore.read(din);
                IOUtils.closeQuietly(din);

                int width = wmfStore.getWidthUnits();
                int height = wmfStore.getHeightUnits();
                int dpi = wmfStore.getMetaFileUnitsPerInch();

                ImageInfo info = new ImageInfo(uri, "image/x-wmf");
                ImageSize size = new ImageSize();
                size.setSizeInPixels(width, height);
                size.setResolution(dpi);
                size.calcSizeFromPixels();
                info.setSize(size);
                ImageWMF img = new ImageWMF(info, wmfStore);
                info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, img);

                return info;
            } catch (NoClassDefFoundError ncdfe) {
                try {
                    in.reset();
                } catch (IOException ioe) {
                    // we're more interested in the original exception
                }
                batikAvailable = false;
                log.warn("Batik not in class path", ncdfe);
                return null;
            } catch (IOException e) {
                // If the svg is invalid then it throws an IOException
                // so there is no way of knowing if it is an svg document

                log.debug("Error while trying to load stream as an WMF file: "
                                       + e.getMessage());
                // assuming any exception means this document is not svg
                // or could not be loaded for some reason
                try {
                    in.reset();
                } catch (IOException ioe) {
                    // we're more interested in the original exception
                }
                return null;
            }
View Full Code Here

                SVGDocument doc;
                if (src instanceof DOMSource) {
                    DOMSource domSrc = (DOMSource)src;
                    doc = (SVGDocument)domSrc.getNode();
                } else {
                    in = new UnclosableInputStream(ImageUtil.needInputStream(src));
                    int length = in.available();
                    in.mark(length + 1);
                    SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
                            getParserName());
                    doc = factory.createSVGDocument(src.getSystemId(), in);
View Full Code Here

TOP

Related Classes of org.apache.fop.util.UnclosableInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.