001    package com.khubla.pragmatach.plugin.responsive;
002    
003    import java.io.InputStream;
004    
005    import com.khubla.pragmatach.framework.annotation.Controller;
006    import com.khubla.pragmatach.framework.annotation.Route;
007    import com.khubla.pragmatach.framework.annotation.RouteParameter;
008    import com.khubla.pragmatach.framework.api.PragmatachException;
009    import com.khubla.pragmatach.framework.api.Response;
010    import com.khubla.pragmatach.framework.controller.impl.stat.StaticResourceController;
011    
012    /**
013     * @author tome
014     */
015    @Controller(name = "ResponsiveImageController")
016    public class ResponsiveImageController extends StaticResourceController {
017       /**
018        * ctor
019        */
020       public ResponsiveImageController() {
021       }
022    
023       /**
024        * render
025        */
026       @Route(uri = "/pragmatach/plugin/getscaledimage/@img/@xscale/@yscale")
027       public Response getscaledimage(@RouteParameter(name = "img") String imageResource, @RouteParameter(name = "xscale") double xscale, @RouteParameter(name = "yscale") double yscale)
028             throws PragmatachException {
029          try {
030             final InputStream imageStream = getResource(imageResource);
031             return new ResponsiveImageResponse(getCacheHeaders(), imageStream, xscale, yscale);
032          } catch (final Exception e) {
033             throw new PragmatachException("Exception in render", e);
034          }
035       }
036    
037       /**
038        * render
039        */
040       @Route(uri = "/pragmatach/plugin/getsizedimage/@img/@width/@height")
041       public Response getsizedimage(@RouteParameter(name = "img") String imageResource, @RouteParameter(name = "width") int width, @RouteParameter(name = "height") int height) throws PragmatachException {
042          try {
043             final InputStream imageStream = getResource(imageResource);
044             return new ResponsiveImageResponse(getCacheHeaders(), imageStream, width, height);
045          } catch (final Exception e) {
046             throw new PragmatachException("Exception in render", e);
047          }
048       }
049    }