All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fastchar.extjs.interceptor.FastExtFileInterceptor Maven / Gradle / Ivy

Go to download

FastChar-ExtJs is a Java Web framework that uses extjs libraries.Quickly build a background management system

There is a newer version: 2.2.2
Show newest version
package com.fastchar.extjs.interceptor;

import com.fastchar.core.FastAction;
import com.fastchar.core.FastFile;
import com.fastchar.interfaces.IFastInterceptor;
import com.fastchar.utils.FastFileUtils;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.name.Rename;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;

public class FastExtFileInterceptor implements IFastInterceptor {

    @Override
    public void onInterceptor(FastAction fastAction) throws Exception {
        try {
            List> paramListFile = fastAction.getParamListFile();
            for (FastFile fastFile : paramListFile) {
                if (fastFile.isImageFile()) {
                    int resizeToWidth = fastAction.getParamToInt(fastFile.getParamName() + ".width", -1);
                    int resizeToHeight = fastAction.getParamToInt(fastFile.getParamName() + ".height", -1);
                    if (resizeToWidth > 0 && resizeToHeight > 0) {
                        List files = Thumbnails.of(fastFile.getFile())
                                .size(resizeToWidth, resizeToHeight)
                                .allowOverwrite(true)
                                .asFiles( Rename.NO_CHANGE);
                        for (File thumbFile : files) {
                            BufferedImage bufferedImage = ImageIO.read(thumbFile);
                            fastFile.setAttr("width", bufferedImage.getWidth());
                            fastFile.setAttr("height", bufferedImage.getHeight());
                            FastFileUtils.moveFile(thumbFile, fastFile.getFile(), true);
                        }
                    }else{
                        BufferedImage bufferedImage = ImageIO.read(fastFile.getFile());
                        if (bufferedImage != null) {
                            fastFile.setAttr("width", bufferedImage.getWidth());
                            fastFile.setAttr("height", bufferedImage.getHeight());
                        }
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        fastAction.invoke();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy