Java Code Examples for org.springframework.util.AntPathMatcher#extractPathWithinPattern()

The following examples show how to use org.springframework.util.AntPathMatcher#extractPathWithinPattern() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirectLinkController.java    From zfile with MIT License 5 votes vote down vote up
/**
 * 获取指定驱动器, 某个文件的直链, 然后重定向过去.
 * @param   driveId
 *          驱动器 ID
 *
 * @return  重定向至文件直链
 */
@GetMapping("/directlink/{driveId}/**")
public String directlink(@PathVariable("driveId") Integer driveId, final HttpServletRequest request) {
    String path = (String) request.getAttribute(
            HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    AntPathMatcher apm = new AntPathMatcher();
    String filePath = apm.extractPathWithinPattern(bestMatchPattern, path);

    if (filePath.length() > 0 && filePath.charAt(0) != ZFileConstant.PATH_SEPARATOR_CHAR) {
        filePath = "/" + filePath;
    }

    AbstractBaseFileService fileService = driveContext.get(driveId);
    FileItemDTO fileItem = fileService.getFileItem(filePath);

    String url = fileItem.getUrl();

    int queryIndex = url.indexOf('?');

    if (queryIndex != -1) {
        String origin = url.substring(0, queryIndex);
        String queryString = url.substring(queryIndex + 1);

        url = URLUtil.encode(origin) + "?" + URLUtil.encode(queryString);
    } else {
        url = URLUtil.encode(url);
    }


    if (Objects.equals(fileItem.getType(), FileTypeEnum.FOLDER)) {
        return "redirect:" + fileItem.getUrl();
    } else {
        return "redirect:" + url;
    }
}
 
Example 2
Source File: LocalController.java    From zfile with MIT License 5 votes vote down vote up
/**
 * 本地存储下载指定文件
 *
 * @param   driveId
 *          驱动器 ID
 *
 * @return  文件
 */
@GetMapping("/file/{driveId}/**")
@ResponseBody
public ResponseEntity<Object> downAttachment(@PathVariable("driveId") Integer driveId, final HttpServletRequest request) {
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    AntPathMatcher apm = new AntPathMatcher();
    String filePath = apm.extractPathWithinPattern(bestMatchPattern, path);
    LocalServiceImpl localService = (LocalServiceImpl) driveContext.get(driveId);
    return FileUtil.export(new File(StringUtils.removeDuplicateSeparator(localService.getFilePath() + ZFileConstant.PATH_SEPARATOR + filePath)));
}
 
Example 3
Source File: ModuleTemplatesController.java    From hesperides with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Permet d'extraire la PathVariable "templateName", qui peut contenir des slashes.
 */
private static String extractFilePath(HttpServletRequest request) {
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    AntPathMatcher apm = new AntPathMatcher();
    path = apm.extractPathWithinPattern(bestMatchPattern, path);
    return URLDecoder.decode(path, StandardCharsets.UTF_8);
}
 
Example 4
Source File: CategoryController.java    From wallride with Apache License 2.0 5 votes vote down vote up
private String extractPathFromPattern(final HttpServletRequest request){
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String bestMatchPattern = (String ) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);

    AntPathMatcher apm = new AntPathMatcher();
    String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path);

    return finalPath;
}
 
Example 5
Source File: ControllerUtils.java    From airsonic-advanced with GNU General Public License v3.0 3 votes vote down vote up
public static String extractMatched(final HttpServletRequest request) {

        String path = (String) request.getAttribute(
                HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);

        AntPathMatcher apm = new AntPathMatcher();

        return apm.extractPathWithinPattern(bestMatchPattern, path);

    }
 
Example 6
Source File: ControllerUtils.java    From airsonic with GNU General Public License v3.0 3 votes vote down vote up
public static String extractMatched(final HttpServletRequest request) {

        String path = (String) request.getAttribute(
                HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);

        AntPathMatcher apm = new AntPathMatcher();

        return apm.extractPathWithinPattern(bestMatchPattern, path);

    }
 
Example 7
Source File: WebUtils.java    From onboard with Apache License 2.0 3 votes vote down vote up
public static String extractPathFromPattern(final HttpServletRequest request) {

        String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);

        AntPathMatcher apm = new AntPathMatcher();
        String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path);

        return finalPath;

    }