001 package com.khubla.pragmatach.framework.controller.impl.stat;
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.api.PragmatachException;
008 import com.khubla.pragmatach.framework.api.Response;
009 import com.khubla.pragmatach.framework.controller.impl.AbstractController;
010
011 /**
012 * @author tome
013 */
014 @Controller(name = "pragmatachStaticResourceController")
015 public class StaticResourceController extends AbstractController {
016 /**
017 * public resource dir
018 */
019 private static final String PUBLIC_RESOURCE_DIR = "/public";
020
021 /**
022 * ctor
023 */
024 public StaticResourceController() {
025 }
026
027 protected InputStream getStaticResourceInputStream(String[] imageResource) throws PragmatachException {
028 try {
029 final String resourceUri = buildWildcardResourceURI(imageResource);
030 return getResource(PUBLIC_RESOURCE_DIR + resourceUri);
031 } catch (final Exception e) {
032 throw new PragmatachException("Exception in getStaticResourceInputStream", e);
033 }
034 }
035
036 @Route(uri = "/public/*")
037 public Response render(String[] imageResource) throws PragmatachException {
038 try {
039 final InputStream is = getStaticResourceInputStream(imageResource);
040 return new StaticResourceResponse(getCacheHeaders(), is);
041 } catch (final Exception e) {
042 throw new PragmatachException("Exception in render", e);
043 }
044 }
045 }