Example usage for org.springframework.web.context.support ServletContextResource getFile

List of usage examples for org.springframework.web.context.support ServletContextResource getFile

Introduction

In this page you can find the example usage for org.springframework.web.context.support ServletContextResource getFile.

Prototype

@Override
public File getFile() throws IOException 

Source Link

Document

This implementation resolves "file:" URLs or alternatively delegates to ServletContext.getRealPath , throwing a FileNotFoundException if not found or not resolvable.

Usage

From source file:org.cloudfoundry.practical.demo.web.ZippedServletResourceHandler.java

@Override
public void afterPropertiesSet() throws Exception {
    ServletContextResource zipResource = new ServletContextResource(this.servletContext, this.zipFile);
    UrlResource urlResource = new UrlResource(
            "jar:" + zipResource.getFile().toURI().toString() + "!/" + this.rootPath + "/");
    this.handler = new ResourceHttpRequestHandler();
    this.handler.setLocations(Collections.<Resource>singletonList(urlResource));
    ((AutowireCapableBeanFactory) this.beanFactory).initializeBean(this.handler,
            this.beanName + "ResourceHandler");
}

From source file:com.sishuok.es.maintain.icon.web.controller.IconController.java

/**
 * ?  ? ??//from www  . j a  v a  2  s . c  o m
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/genCssFile")
@ResponseBody
public String genIconCssFile(HttpServletRequest request) {

    this.permissionList.assertHasEditPermission();

    String uploadFileTemplate = ".%1$s{background:url(%2$s/%3$s);width:%4$spx;height:%5$spx;display:inline-block;vertical-align: middle;%6$s}";
    String cssSpriteTemplate = ".%1$s{background:url(%2$s/%3$s) no-repeat -%4$spx -%5$spx;width:%6$spx;height:%7$spx;display:inline-block;vertical-align: middle;%8$s}";

    ServletContext sc = request.getServletContext();
    String ctx = sc.getContextPath();

    List<String> cssList = Lists.newArrayList();

    Searchable searchable = Searchable.newSearchable().addSearchParam("type_in",
            new IconType[] { IconType.upload_file, IconType.css_sprite });

    List<Icon> iconList = baseService.findAllWithNoPageNoSort(searchable);

    for (Icon icon : iconList) {

        if (icon.getType() == IconType.upload_file) {
            cssList.add(String.format(uploadFileTemplate, icon.getIdentity(), ctx, icon.getImgSrc(),
                    icon.getWidth(), icon.getHeight(), icon.getStyle()));
            continue;
        }

        if (icon.getType() == IconType.css_sprite) {
            cssList.add(String.format(cssSpriteTemplate, icon.getIdentity(), ctx, icon.getSpriteSrc(),
                    icon.getLeft(), icon.getTop(), icon.getWidth(), icon.getHeight(), icon.getStyle()));
            continue;
        }

    }

    try {
        ServletContextResource resource = new ServletContextResource(sc, iconClassFile);
        FileUtils.writeLines(resource.getFile(), cssList);
    } catch (Exception e) {
        LogUtils.logError("gen icon error", e);
        return "?" + e.getMessage();
    }

    return "??";
}

From source file:com.daphne.es.maintain.icon.web.controller.IconController.java

/**
 * ?  ? ??//from ww w  . j a  v  a2  s.  c  o m
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/genCssFile")
@ResponseBody
public String genIconCssFile(HttpServletRequest request) {

    this.permissionList.assertHasEditPermission();

    String uploadFileTemplate = ".%1$s{background:url(%2$s/%3$s);width:%4$spx;height:%5$spx;display:inline-block;vertical-align: middle;%6$s}";
    String cssSpriteTemplate = ".%1$s{background:url(%2$s/%3$s) no-repeat -%4$spx -%5$spx;width:%6$spx;height:%7$spx;display:inline-block;vertical-align: middle;%8$s}";

    ServletContext sc = request.getServletContext();
    String ctx = sc.getContextPath();

    List<String> cssList = Lists.newArrayList();

    Searchable searchable = Searchable.newSearchable().addSearchParam("type_in",
            new IconType[] { IconType.upload_file, IconType.css_sprite });

    List<Icon> iconList = baseService.findAllWithNoPageNoSort(searchable);

    for (Icon icon : iconList) {

        if (icon.getType() == IconType.upload_file) {
            cssList.add(String.format(uploadFileTemplate, icon.getIdentity(), ctx, icon.getImgSrc(),
                    icon.getWidth(), icon.getHeight(), icon.getStyle()));
            continue;
        }

        if (icon.getType() == IconType.css_sprite) {
            cssList.add(String.format(cssSpriteTemplate, icon.getIdentity(), ctx, icon.getSpriteSrc(),
                    icon.getLeft(), icon.getTop(), icon.getWidth(), icon.getHeight(), icon.getStyle()));
            continue;
        }

    }

    try {

        ServletContextResource resource = new ServletContextResource(sc, iconClassFile);
        FileUtils.writeLines(resource.getFile(), cssList);
    } catch (Exception e) {
        LogUtils.logError("gen icon error", e);
        return "?" + e.getMessage();
    }

    return "??";
}

From source file:com.luna.maintain.icon.web.controller.IconController.java

/**
 * ?  ? ??/*from w  ww  .  ja v  a2s  .  com*/
 *
 * @param request
 * @return
 */
@RequestMapping(value = "/genCssFile")
@ResponseBody
public String genIconCssFile(HttpServletRequest request) {

    this.permissionList.assertHasEditPermission();

    String uploadFileTemplate = ".%1$s{background:url(%2$s/%3$s);width:%4$spx;height:%5$spx;display:inline-block;vertical-align: middle;%6$s}";
    String cssSpriteTemplate = ".%1$s{background:url(%2$s/%3$s) no-repeat -%4$spx -%5$spx;width:%6$spx;height:%7$spx;display:inline-block;vertical-align: middle;%8$s}";

    ServletContext sc = request.getServletContext();
    String ctx = sc.getContextPath();

    List<String> cssList = Lists.newArrayList();

    Searchable searchable = Searchable.newSearchable().addSearchParam("type_in",
            new IconType[] { IconType.upload_file, IconType.css_sprite });

    List<Icon> iconList = baseService.findAllWithNoPageNoSort(searchable);

    for (Icon icon : iconList) {

        if (icon.getType() == IconType.upload_file) {
            cssList.add(String.format(uploadFileTemplate, icon.getIdentity(), ctx, icon.getImgSrc(),
                    icon.getWidth(), icon.getHeight(), icon.getStyle()));
            continue;
        }

        if (icon.getType() == IconType.css_sprite) {
            cssList.add(String.format(cssSpriteTemplate, icon.getIdentity(), ctx, icon.getSpriteSrc(),
                    icon.getLeft(), icon.getTop(), icon.getWidth(), icon.getHeight(), icon.getStyle()));
            continue;
        }

    }

    try {
        ServletContextResource resource = new ServletContextResource(sc, iconClassFile);
        FileUtils.writeLines(resource.getFile(), cssList);
    } catch (Exception e) {
        log.error("gen icon error", e);
        return "?" + e.getMessage();
    }

    return "??";
}