package com.platform.modules.video.service.impl;

import com.platform.modules.video.service.RealPathResolver;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;

@Component
@Service("realPathResolver")
public class ServletContextRealPathResolver  implements ServletContextAware, RealPathResolver {

    private ServletContext context;

    @Override
    public void setServletContext(ServletContext servletContext) {
        this.context = servletContext;
    }

    @Override
    public String get(String path) {
//        String realPath = context.getRealPath(path);
//        if (realPath == null) {
//            realPath = context.getRealPath("/") + path;
//        }
        if (StringUtils.isBlank(path)) {
            return "/";
        }
        if (path.trim().startsWith("/")) {
            return path.trim();
        }
        return path;
    }
}