src/main/java/org/efaps/ui/servlet/ImageServlet.java
@Override
    protected void doGet(final HttpServletRequest _req,
                         final HttpServletResponse _res)
        throws ServletException
    {
        String imgName = _req.getRequestURI();

        imgName = imgName.substring(imgName.lastIndexOf('/') + 1);

        try {
            final Cache<String, ImageMapper> cache = InfinispanCache.get().<String, ImageMapper>getCache(
                            ImageServlet.CACHENAME);
            if (!cache.containsKey(imgName)) {
                final QueryBuilder queryBldr = new QueryBuilder(CIAdminUserInterface.Image);
                queryBldr.addWhereAttrEqValue(CIAdminUserInterface.Image.Name, imgName);
                final MultiPrintQuery multi = queryBldr.getPrint();
                final SelectBuilder selLabel = new SelectBuilder().file().label();
                final SelectBuilder selLength = new SelectBuilder().file().length();
                multi.addSelect(selLabel, selLength);
                multi.addAttribute(CIAdminUserInterface.Image.Name,
                                CIAdminUserInterface.Image.Modified);
                multi.executeWithoutAccessCheck();
                if (multi.next()) {
                    final String name = multi.<String>getAttribute(CIAdminUserInterface.Image.Name);
                    final String file = multi.<String>getSelect(selLabel);
                    final Long filelength = multi.<Long>getSelect(selLength);
                    final DateTime time = multi.<DateTime>getAttribute(CIAdminUserInterface.Image.Modified);
                    final ImageMapper imageMapper = new ImageMapper(multi.getCurrentInstance(),
                                    name, file, filelength, time.getMillis());
                    cache.put(imgName, imageMapper);
                } else {
                    cache.put(imgName, ImageServlet.NULL);
                }
            }

            final ImageMapper imageMapper = cache.get(imgName);
            if (imageMapper != null && !imageMapper.equals(ImageServlet.NULL)) {
                final Checkout checkout = new Checkout(imageMapper.instance);

                _res.setContentType(getServletContext().getMimeType(imageMapper.file));
                _res.setContentLength((int) imageMapper.filelength);
                _res.setDateHeader("Last-Modified", imageMapper.time);

                _res.setDateHeader("Expires", System.currentTimeMillis()
                                + (3600 * 1000));
                _res.setHeader("Cache-Control", "max-age=3600");

                checkout.execute(_res.getOutputStream());
                checkout.close();
            }
        } catch (final IOException e) {
            ImageServlet.LOG.error("while reading history data", e);
            throw new ServletException(e);
        } catch (final CacheReloadException e) {
            ImageServlet.LOG.error("while reading history data", e);
            throw new ServletException(e);
        } catch (final EFapsException e) {
            ImageServlet.LOG.error("while reading history data", e);
            throw new ServletException(e);
        }
    }
@Override
    protected void doGet(final HttpServletRequest _req,
                         final HttpServletResponse _res)
        throws ServletException
    {
        String imgName = _req.getRequestURI();

        imgName = imgName.substring(imgName.lastIndexOf('/') + 1);

        try {
            final Cache<String, ImageMapper> cache = InfinispanCache.get().<String, ImageMapper>getCache(
                            ImageServlet.CACHENAME);
            if (!cache.containsKey(imgName)) {
                final QueryBuilder queryBldr = new QueryBuilder(CIAdminUserInterface.Image);
                queryBldr.addWhereAttrEqValue(CIAdminUserInterface.Image.Name, imgName);
                final MultiPrintQuery multi = queryBldr.getPrint();
                final SelectBuilder selLabel = new SelectBuilder().file().label();
                final SelectBuilder selLength = new SelectBuilder().file().length();
                multi.addSelect(selLabel, selLength);
                multi.addAttribute(CIAdminUserInterface.Image.Name,
                                CIAdminUserInterface.Image.Modified);
                multi.executeWithoutAccessCheck();
                if (multi.next()) {
                    final String name = multi.<String>getAttribute(CIAdminUserInterface.Image.Name);
                    final String file = multi.<String>getSelect(selLabel);
                    final Long filelength = multi.<Long>getSelect(selLength);
                    final DateTime time = multi.<DateTime>getAttribute(CIAdminUserInterface.Image.Modified);
                    final ImageMapper imageMapper = new ImageMapper(multi.getCurrentInstance(),
                                    name, file, filelength, time.getMillis());
                    cache.put(imgName, imageMapper);
                } else {
                    cache.put(imgName, ImageServlet.NULL);
                }
            }

            final ImageMapper imageMapper = cache.get(imgName);
            if (imageMapper != null && !imageMapper.equals(ImageServlet.NULL)) {
                final Checkout checkout = new Checkout(imageMapper.instance);

                _res.setContentType(getServletContext().getMimeType(imageMapper.file));
                _res.setContentLength((int) imageMapper.filelength);
                _res.setDateHeader("Last-Modified", imageMapper.time);

                _res.setDateHeader("Expires", System.currentTimeMillis()
                                + (3600 * 1000));
                _res.setHeader("Cache-Control", "max-age=3600");

                checkout.execute(_res.getOutputStream());
                checkout.close();
            }
        } catch (final IOException e) {
            ImageServlet.LOG.error("while reading history data", e);
            throw new ServletException(e);
        } catch (final CacheReloadException e) {
            ImageServlet.LOG.error("while reading history data", e);
            throw new ServletException(e);
        } catch (final EFapsException e) {
            ImageServlet.LOG.error("while reading history data", e);
            throw new ServletException(e);
        }
    }
@ Override protected void doGet ( final HttpServletRequest _req , final HttpServletResponse _res ) throws ServletException { String imgName = _req . getRequestURI ( ) ; imgName = imgName . substring ( imgName . lastIndexOf ( ' ' ) + 1 ) ; try { final Cache < String , ImageMapper > cache = InfinispanCache . get ( ) . < String , ImageMapper > getCache ( ImageServlet . CACHENAME ) ; if ( ! cache . containsKey ( imgName ) ) { final QueryBuilder queryBldr = new QueryBuilder ( CIAdminUserInterface . Image ) ; queryBldr . addWhereAttrEqValue ( CIAdminUserInterface . Image . Name , imgName ) ; final MultiPrintQuery multi = queryBldr . getPrint ( ) ; final SelectBuilder selLabel = new SelectBuilder ( ) . file ( ) . label ( ) ; final SelectBuilder selLength = new SelectBuilder ( ) . file ( ) . length ( ) ; multi . addSelect ( selLabel , selLength ) ; multi . addAttribute ( CIAdminUserInterface . Image . Name , CIAdminUserInterface . Image . Modified ) ; multi . executeWithoutAccessCheck ( ) ; if ( multi . next ( ) ) { final String name = multi . < String > getAttribute ( CIAdminUserInterface . Image . Name ) ; final String file = multi . < String > getSelect ( selLabel ) ; final Long filelength = multi . < Long > getSelect ( selLength ) ; final DateTime time = multi . < DateTime > getAttribute ( CIAdminUserInterface . Image . Modified ) ; final ImageMapper imageMapper = new ImageMapper ( multi . getCurrentInstance ( ) , name , file , filelength , time . getMillis ( ) ) ; cache . put ( imgName , imageMapper ) ; } else { cache . put ( imgName , ImageServlet . NULL ) ; } } final ImageMapper imageMapper = cache . get ( imgName ) ; if ( imageMapper != null && ! imageMapper . equals ( ImageServlet . NULL ) ) { final Checkout checkout = new Checkout ( imageMapper . instance ) ; _res . setContentType ( getServletContext ( ) . getMimeType ( imageMapper . file ) ) ; _res . setContentLength ( ( int ) imageMapper . filelength ) ; _res . setDateHeader ( "Last-Modified" , imageMapper . time ) ; _res . setDateHeader ( "Expires" , System . currentTimeMillis ( ) + ( 3600 * 1000 ) ) ; _res . setHeader ( "Cache-Control" , "max-age=3600" ) ; checkout . execute ( _res . getOutputStream ( ) ) ; checkout . close ( ) ; } } catch ( final IOException e ) { ImageServlet . LOG . error ( "while reading history data" , e ) ; throw new ServletException ( e ) ; } catch ( final CacheReloadException e ) { ImageServlet . LOG . error ( "while reading history data" , e ) ; throw new ServletException ( e ) ; } catch ( final EFapsException e ) { ImageServlet . LOG . error ( "while reading history data" , e ) ; throw new ServletException ( e ) ; } }
The method checks the image from the user interface image object out and
returns them in a output stream to the web client. The name of the user
interface image object must given as name at the end of the path.

@param _req request variable
@param _res response variable
@throws ServletException on error
The method checks the image from the user interface image object out and returns them in a output stream to the web client . The name of the user interface image object must given as name at the end of the path .