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

com.fastchar.extjs.interceptor.FastExtRootAttachInterceptor 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.FastChar;
import com.fastchar.core.FastDispatcher;
import com.fastchar.interfaces.IFastRootInterceptor;
import com.fastchar.servlet.http.FastHttpServletRequest;
import com.fastchar.servlet.http.FastHttpServletResponse;
import com.fastchar.utils.FastBooleanUtils;

import java.io.File;

public class FastExtRootAttachInterceptor implements IFastRootInterceptor {

    @Override
    public void onInterceptor(FastHttpServletRequest request, FastHttpServletResponse response, FastDispatcher dispatcher) throws Exception {
        try {
            String contentUrl = dispatcher.getContentUrl();
            if (contentUrl.startsWith("/attach/")) {//统一拦截附件目录
                String[] split = contentUrl.split("attach/");
                String child = split[1];
                String path = child;
                if (child.startsWith("http://") || child.startsWith("https://")) {
                    path = child;
                } else {
                    File file = new File(FastChar.getConstant().getAttachDirectory(), child);
                    if (file.exists()) {
                        path = file.getAbsolutePath();
                    } else {
                        file = new File(FastChar.getPath().getWebRootPath(), child);
                    }

                    if (file.exists()) {
                        path = file.getAbsolutePath();
                    }
                }
                boolean disposition = FastBooleanUtils.formatToBoolean(request.getParameter("disposition"), false);
                dispatcher.setContentUrl("/attach?disposition=" + disposition + "&path=" + path);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        dispatcher.invoke();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy