Java Path Extract nio extractLanguageRelativePath(final Path absolutePath)

Here you can find the source of extractLanguageRelativePath(final Path absolutePath)

Description

extract Language Relative Path

License

Apache License

Declaration

private static String extractLanguageRelativePath(final Path absolutePath) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.nio.file.Path;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final String CONFIG_NAMES_FILE_TOC = "toc.html";

    private static String extractLanguageRelativePath(final Path absolutePath) {
        final String fileName;
        if (absolutePath != null && absolutePath.getFileName() != null) {
            fileName = absolutePath.getFileName().toString();
        } else {/*  www .j  av  a 2s .c o  m*/
            fileName = "";
        }
        final String pathRegexSeparator;
        if ("\\".equals(File.separator)) {
            pathRegexSeparator = "\\\\";
        } else {
            pathRegexSeparator = File.separator;
        }
        final String languagePathPattern = "(it|en|fr)" + pathRegexSeparator + "(faq|imgs|pages|pdf|toc\\.html)";
        Pattern pattern = Pattern.compile(languagePathPattern);
        final String pathString;
        if (absolutePath != null) {
            pathString = absolutePath.toString();
        } else {
            pathString = "";
        }
        Matcher matcher = pattern.matcher(pathString);
        String lang = "";
        String folderType = "";
        while (matcher.find()) {
            lang = matcher.group(1);
            folderType = matcher.group(2);
        }
        String result = lang + File.separator + folderType;
        if (result.endsWith(File.separator)) {
            result = fileName;
        } else if (!fileName.equals(CONFIG_NAMES_FILE_TOC)) {
            result += File.separator + fileName;
        }
        return result;
    }
}

Related

  1. extract(Path archive, Path targetDirectory)
  2. extractClassName(Path path)
  3. extractCurrentPath()
  4. extractFile(ZipInputStream zipIn, Path filePath)
  5. extractLuaStacktrace(Path path, StackTraceElement[] stackTrace)
  6. extractVersion(Path pathToBinaries)
  7. extractZipArchive(final File zipFile, Path destDir)
  8. unzipFileInArchive(FileChannel channel, String relpathInZip, File extractTo)