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

com.smartling.maven.plugins.smartlingapi.SmartlingApiMavenPluginUtils Maven / Gradle / Ivy

The newest version!
package com.smartling.maven.plugins.smartlingapi;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FilenameUtils;

import com.smartling.api.sdk.file.FileType;

public final class SmartlingApiMavenPluginUtils
{

    public static final String SMARTLING_API_PLUGIN_NAME = "Smartling API Maven Plugin";
    public static final String SMARTLING_WORK_DIRECTORY = "${project.build.directory}/smartling";

    public static final String SMARTLING_API_SUCCESS_CODE = "SUCCESS"; // TODO: move from Maven plugin to API SDK

    private SmartlingApiMavenPluginUtils()
    {
        // Utility class
    }

    public static void createParentDirIfNotExists(final File destFile)
    {
        final File parentFile = destFile.getParentFile();
        if (null != parentFile)
            parentFile.mkdirs();
    }

    public static String unixStyleFileName(final File file)
    {
        return FilenameUtils.normalize(file.getPath(), true);
    }

    public static FileType detectFileType(final File file) throws FileTypeDetectionException
    {
        // TODO: implement magic number-based filetype detection (e.g. IDML) and file sniffing (e.g. XML vs. ANDROID) if extension mapping is ambiguous or extension is unknown

        final String fileExtension = FilenameUtils.getExtension(file.getName());
        final FileType fileType = extensionToFileTypeMap.get(fileExtension.toLowerCase());

        if (null == fileType)
            throw new FileTypeDetectionException(String.format("Unknown file extension: %s; fileName=%s", fileExtension, unixStyleFileName(file)));

        return fileType;
    }
    private static Map extensionToFileTypeMap =  new HashMap();
    static
    {
        // TODO: extend/generalize this mapping
        extensionToFileTypeMap.put("properties", FileType.JAVA_PROPERTIES);
        extensionToFileTypeMap.put("strings", FileType.IOS);
//      extensionToFileTypeMap.put("", FileType.ANDROID);
        extensionToFileTypeMap.put("po", FileType.GETTEXT);
        extensionToFileTypeMap.put("pot", FileType.GETTEXT);
        extensionToFileTypeMap.put("xlf", FileType.XLIFF);
        extensionToFileTypeMap.put("yml", FileType.YAML);
        extensionToFileTypeMap.put("json", FileType.JSON);
        extensionToFileTypeMap.put("js", FileType.JSON);
        extensionToFileTypeMap.put("xml", FileType.XML);
        extensionToFileTypeMap.put("html", FileType.HTML);
        extensionToFileTypeMap.put("htm", FileType.HTML);
        extensionToFileTypeMap.put("xhtml", FileType.HTML);
//      extensionToFileTypeMap.put("", FileType.FREEMARKER);
        extensionToFileTypeMap.put("docx", FileType.DOCX);
        extensionToFileTypeMap.put("pptx", FileType.PPTX);
        extensionToFileTypeMap.put("xlsx", FileType.XLSX);
        extensionToFileTypeMap.put("idml", FileType.IDML);
        extensionToFileTypeMap.put("xls", FileType.XLS);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy