Examples of TranscoderException


Examples of com.volantis.map.sti.transcoder.TranscoderException

        // ==================================================================
        // Prepare expectations.
        // ==================================================================
        transcoderMock
            .expects.transcode(resourceDescriptorMock, httpServletRequestMock, httpServletResponseMock)
            .fails(new TranscoderException(null));

        // ==================================================================
        // Do the test.
        // ==================================================================
        try {
View Full Code Here

Examples of com.volantis.map.sti.transcoder.TranscoderException

            SOAPEnvelope responseEnvelope = responseMessage.getSOAPPart().getEnvelope();
            SOAPBody responseBody = responseEnvelope.getBody();

            if (responseBody.hasFault()) {
                final SOAPFault fault = responseBody.getFault();
                throw new TranscoderException("soap-response-with-fault",
                        new Object[] { fault.getFaultCodeAsName(), fault.getFaultString() },
                        null);

            }
           
            document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

            Node node = responseBody.getFirstChild();
            node = document.importNode(node, true);
            document.appendChild(node);

            // Create TranscodingResponse
            TranscodingResponse transcodingResponse = dom2TransRespConverter.convert(document);

            if (!transcodingRequest.getOperationID().equals(
                    transcodingResponse.getOperationID())) {
                LOGGER.warn("invalid-operationID", new Object[] {
                        transcodingResponse.getOperationID(),
                        transcodingRequest.getOperationID()});
            }

            String contentID = transcodingResponse.getJobResult(0).getOutput().getLocation();

            Iterator iterator = responseMessage.getAttachments();

            // Copy the content of the first attachement to the HTTP response stream.
            boolean foundAttachement = false;

            while (!foundAttachement && iterator.hasNext()) {
                AttachmentPart part = (AttachmentPart) iterator.next();

//                    if (part.getContentId().equals(contentID)) {
                foundAttachement = true;

                InputStream inputStream = part.getDataHandler().getInputStream();

                if (inputStream == null) {
                    throw new TranscoderException(null);
                }

                OutputStream outputStream = response.getOutputStream();

                response.setContentType(part.getContentType());
                response.setContentLength(part.getSize());
                // Copy the content of input inputStream to the output inputStream.
                // The exception loggin is set to debug level
                // because of vbm 2008030721 the browser requests the map resource
                // two times in a row and aborts the firts request most of the times

                try {
                    byte buf[] = new byte[1024];
                    int len;
                    while ((len = inputStream.read(buf)) != -1) {
                        outputStream.write(buf, 0, len);
                    }
                    outputStream.flush();
                } finally {
                    // Ensure we close the input.
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug(e);
                        }
                    }
                    // Ensure we close the output.
                    try {
                        outputStream.close();
                    } catch (IOException e) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug(e);
                        }
                    }
                }
            }
        } catch (SOAPException e) {
            throw new TranscoderException(e);
        } catch (ConverterException e) {
            throw new TranscoderException(e);
        } catch (ParserConfigurationException e) {
            throw new TranscoderException(e);
        } catch (IOException e) {
            throw new TranscoderException(e);
        } catch (MimeTypeRetrieverException e) {
            throw new TranscoderException(e);
        }       
    }
View Full Code Here

Examples of org.apache.batik.transcoder.TranscoderException

      g2d.dispose();

      rend = null; // We're done with it...
      sendImage(dest);
    } catch (Exception ex) {
      throw new TranscoderException(ex);
    }
  }
View Full Code Here

Examples of org.apache.batik.transcoder.TranscoderException

     */
    protected void transcode(Document document, String uri,
                             TranscoderOutput output) throws TranscoderException {

        if (!(document instanceof SVGOMDocument)) {
            throw new TranscoderException(Messages.formatMessage("notsvg",
                    null));
        }
        SVGDocument svgDoc = (SVGDocument)document;
        SVGSVGElement root = svgDoc.getRootElement();
        // initialize the SVG document with the appropriate context
        String parserClassname = (String)hints.get(KEY_XML_PARSER_CLASSNAME);
        DefaultSVGContext svgCtx = new DefaultSVGContext();
        svgCtx.setPixelToMM(userAgent.getPixelToMM());
        ((SVGOMDocument)document).setSVGContext(svgCtx);

        boolean stroke = true;
        if (hints.containsKey(KEY_STROKE_TEXT)) {
            stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue();
        }

        // build the GVT tree
        GVTBuilder builder = new GVTBuilder();
        ImageRendererFactory rendFactory = new StaticRendererFactory();
        GraphicsNodeRenderContext rc = getRenderContext(stroke);
        BridgeContext ctx = new BridgeContext(userAgent, rc);
        PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
        ctx.putBridge(pdfAElementBridge);
        GraphicsNode gvtRoot;
        try {
            gvtRoot = builder.build(ctx, svgDoc);
        } catch (BridgeException ex) {
            throw new TranscoderException(ex);
        }
        // get the 'width' and 'height' attributes of the SVG document
        float docWidth = (float)ctx.getDocumentSize().getWidth();
        float docHeight = (float)ctx.getDocumentSize().getHeight();
        ctx = null;
        builder = null;

        // compute the image's width and height according the hints
        float imgWidth = -1;
        if (hints.containsKey(ImageTranscoder.KEY_WIDTH)) {
            imgWidth =
                ((Float)hints.get(ImageTranscoder.KEY_WIDTH)).floatValue();
        }
        float imgHeight = -1;
        if (hints.containsKey(ImageTranscoder.KEY_HEIGHT)) {
            imgHeight =
                ((Float)hints.get(ImageTranscoder.KEY_HEIGHT)).floatValue();
        }
        float width, height;
        if (imgWidth > 0 && imgHeight > 0) {
            width = imgWidth;
            height = imgHeight;
        } else if (imgHeight > 0) {
            width = (docWidth * imgHeight) / docHeight;
            height = imgHeight;
        } else if (imgWidth > 0) {
            width = imgWidth;
            height = (docHeight * imgWidth) / docWidth;
        } else {
            width = docWidth;
            height = docHeight;
        }
        // compute the preserveAspectRatio matrix
        AffineTransform Px;
        String ref = null;
        try {
            ref = new URL(uri).getRef();
        } catch (MalformedURLException ex) {
            // nothing to do, catched previously
        }

        try {
            Px = ViewBox.getViewTransform(ref, root, width, height);
        } catch (BridgeException ex) {
            throw new TranscoderException(ex);
        }

        if (Px.isIdentity() && (width != docWidth || height != docHeight)) {
            // The document has no viewBox, we need to resize it by hand.
            // we want to keep the document size ratio
            float d = Math.max(docWidth, docHeight);
            float dd = Math.max(width, height);
            float scale = dd / d;
            Px = AffineTransform.getScaleInstance(scale, scale);
        }
        // take the AOI into account if any
        if (hints.containsKey(ImageTranscoder.KEY_AOI)) {
            Rectangle2D aoi = (Rectangle2D)hints.get(ImageTranscoder.KEY_AOI);
            // transform the AOI into the image's coordinate system
            aoi = Px.createTransformedShape(aoi).getBounds2D();
            AffineTransform Mx = new AffineTransform();
            double sx = width / aoi.getWidth();
            double sy = height / aoi.getHeight();
            Mx.scale(sx, sy);
            double tx = -aoi.getX();
            double ty = -aoi.getY();
            Mx.translate(tx, ty);
            // take the AOI transformation matrix into account
            // we apply first the preserveAspectRatio matrix
            Px.preConcatenate(Mx);
        }
        // prepare the image to be painted
        int w = (int)width;
        int h = (int)height;

        PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D(stroke,
                output.getOutputStream(), w, h);
        graphics.setSVGDimension(docWidth, docHeight);

        if (!stroke) {
            TextPainter textPainter = null;
            textPainter = new PDFTextPainter(graphics.getFontState());
            rc.setTextPainter(textPainter);
        }

        pdfAElementBridge.setPDFGraphics2D(graphics);
        if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
            graphics.setBackgroundColor((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
        }
        graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
        graphics.setRenderingHints(rc.getRenderingHints());

        gvtRoot.paint(graphics, rc);

        try {
            graphics.finish();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new TranscoderException(ex);
        }
    }
View Full Code Here

Examples of org.apache.batik.transcoder.TranscoderException

        /**
         * Displays the specified error message using the <tt>ErrorHandler</tt>.
         */
        public void displayError(String message) {
            try {
                getErrorHandler().error(new TranscoderException(message));
            } catch (TranscoderException ex) {
                throw new RuntimeException();
            }
        }
View Full Code Here

Examples of org.apache.batik.transcoder.TranscoderException

        /**
         * Displays the specified error using the <tt>ErrorHandler</tt>.
         */
        public void displayError(Exception e) {
            try {
                getErrorHandler().error(new TranscoderException(e));
            } catch (TranscoderException ex) {
                throw new RuntimeException();
            }
        }
View Full Code Here

Examples of org.apache.batik.transcoder.TranscoderException

        /**
         * Displays the specified message using the <tt>ErrorHandler</tt>.
         */
        public void displayMessage(String message) {
            try {
                getErrorHandler().warning(new TranscoderException(message));
            } catch (TranscoderException ex) {
                throw new RuntimeException();
            }
        }
View Full Code Here

Examples of org.apache.batik.transcoder.TranscoderException

            }

            pp.print(in, out);
            out.flush();
        } catch (IOException e) {
            getErrorHandler().fatalError(new TranscoderException(e.getMessage()));
        }
    }
View Full Code Here

Examples of org.apache.batik.transcoder.TranscoderException

                default:
                    break misc3;
                }
            }
        } catch (XMLException e) {
            errorHandler.fatalError(new TranscoderException(e.getMessage()));
        }
    }
View Full Code Here

Examples of org.apache.batik.transcoder.TranscoderException

    /**
     * Creates a transcoder exception.
     */
    protected TranscoderException fatalError(String key, Object[] params)
        throws TranscoderException {
        TranscoderException result = new TranscoderException(key);
        errorHandler.fatalError(result);
        return result;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.