Java Code Examples for org.springframework.web.context.support.ServletContextResource.getFile()

The following are Jave code examples for showing how to use getFile() of the org.springframework.web.context.support.ServletContextResource class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: onecmdb   File: IconGenerator.java   Source Code and License Vote up 4 votes
private Map<String, List<Image>> getImageMap() throws IOException {
    
    ServletContextResource imagesRes 
    = new ServletContextResource(getServletContext(), this.imageDirectory);
    
    File imagesFile = imagesRes.getFile();
    
    final Map<String, List<Image>> images = new TreeMap<String, List<Image>>();
    File[] imageFiles = imagesFile.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {

            FileSystemResource file = new FileSystemResource(new File(dir, name));
            
            for (String ext : exts) {
                if (name.toLowerCase().endsWith(ext)) { 
                    try {
                        BufferedImage img = ImageIO.read(file.getFile());
                        
                        String key = name.substring(0, name.length() - ext.length());
                        key = name.substring(0, key.length() - 2);
                        
                        List<Image> imageList = images.get(key);
                        if (imageList == null) {
                            imageList = new ArrayList<Image>(1);
                            images.put(key, imageList);
                        }
                        imageList.add(img);
                        return true;
                    } catch (IOException e) { 
                        return false;
                    }
                }
            }
            return false;
            
        }});


    return images;
    
}
 
Example 2
Project: OneCMDBwithMaven   File: IconGenerator.java   Source Code and License Vote up 4 votes
private Map<String, List<Image>> getImageMap() throws IOException {
    
    ServletContextResource imagesRes 
    = new ServletContextResource(getServletContext(), this.imageDirectory);
    
    File imagesFile = imagesRes.getFile();
    
    final Map<String, List<Image>> images = new TreeMap<String, List<Image>>();
    File[] imageFiles = imagesFile.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {

            FileSystemResource file = new FileSystemResource(new File(dir, name));
            
            for (String ext : exts) {
                if (name.toLowerCase().endsWith(ext)) { 
                    try {
                        BufferedImage img = ImageIO.read(file.getFile());
                        
                        String key = name.substring(0, name.length() - ext.length());
                        key = name.substring(0, key.length() - 2);
                        
                        List<Image> imageList = images.get(key);
                        if (imageList == null) {
                            imageList = new ArrayList<Image>(1);
                            images.put(key, imageList);
                        }
                        imageList.add(img);
                        return true;
                    } catch (IOException e) { 
                        return false;
                    }
                }
            }
            return false;
            
        }});


    return images;
    
}
 
Example 3
Project: onecmdb   File: IconGenerator.java   Source Code and License Vote up 2 votes
public ModelAndView addHandler(HttpServletRequest request,
        HttpServletResponse respone, IconOptionsCommand optionsCommand) throws IOException {

    HashMap<String, Object> data = new HashMap<String, Object>();

    
    
    ServletContextResource depot
    = new ServletContextResource(getServletContext(), this.imageDirectory);

    
    
    
    String imageid = optionsCommand.getIconid();
    if (imageid != null) {
    
        
        final ByteArrayInputStream in = new ByteArrayInputStream(optionsCommand.getIconData());
        final BufferedImage image = ImageIO.read(in);
        
        for (double f = 16.0; f <= 48.0; f += 16)
        {
            
            Image scaled = image.getScaledInstance((int) f, (int) f, java.awt.Image.SCALE_AREA_AVERAGING);
            
            
            BufferedImage scaledImage = toBufferedImage(scaled);
            
            final File file = new File(depot.getFile(), imageid  + ((int) f) + ".png");
            ImageIO.write(scaledImage, "png", file);
            
        }

        data.put("successful", true);
    
    }
    
    
    
    return new ModelAndView("imageAdd", "imageAdd", data);

    
}
 
Example 4
Project: OneCMDBwithMaven   File: IconGenerator.java   Source Code and License Vote up 2 votes
public ModelAndView addHandler(HttpServletRequest request,
        HttpServletResponse respone, IconOptionsCommand optionsCommand) throws IOException {

    HashMap<String, Object> data = new HashMap<String, Object>();

    
    
    ServletContextResource depot
    = new ServletContextResource(getServletContext(), this.imageDirectory);

    
    
    
    String imageid = optionsCommand.getIconid();
    if (imageid != null) {
    
        
        final ByteArrayInputStream in = new ByteArrayInputStream(optionsCommand.getIconData());
        final BufferedImage image = ImageIO.read(in);
        
        for (double f = 16.0; f <= 48.0; f += 16)
        {
            
            Image scaled = image.getScaledInstance((int) f, (int) f, java.awt.Image.SCALE_AREA_AVERAGING);
            
            
            BufferedImage scaledImage = toBufferedImage(scaled);
            
            final File file = new File(depot.getFile(), imageid  + ((int) f) + ".png");
            ImageIO.write(scaledImage, "png", file);
            
        }

        data.put("successful", true);
    
    }
    
    
    
    return new ModelAndView("imageAdd", "imageAdd", data);

    
}