Skip to content
FileController.java 726 B
Newer Older
package it.inaf.ia2.transfer.controller;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class FileController {

    @Autowired
    protected HttpServletRequest request;

    public String getPath() {

        String uri = request.getRequestURI().substring(request.getContextPath().length());

        String[] parts = uri.split("/");
        return String.join("/", Arrays.stream(parts)
                .map(p -> URLDecoder.decode(p, StandardCharsets.UTF_8))
                .collect(Collectors.toList()));
    }
}