本文整理了Java中com.alibaba.citrus.util.FileUtil.getFileNameAndExtension()
方法的一些代码示例,展示了FileUtil.getFileNameAndExtension()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.getFileNameAndExtension()
方法的具体详情如下:
包路径:com.alibaba.citrus.util.FileUtil
类名称:FileUtil
方法名:getFileNameAndExtension
[英]取得指定路径的名称和后缀。
[中]取得指定路径的名称和后缀。
代码示例来源:origin: webx/citrus
/**
* 取得指定路径的名称和后缀。
*
* @param path 路径
* @return 路径和后缀
*/
public static FileNameAndExtension getFileNameAndExtension(String path) {
return getFileNameAndExtension(path, false);
}
代码示例来源:origin: webx/citrus
/**
* 取得指定路径的名称和后缀。
*
* @param path 路径
* @return 路径和后缀
*/
public static FileNameAndExtension getFileNameAndExtension(String path) {
return getFileNameAndExtension(path, false);
}
代码示例来源:origin: webx/citrus
/**
* 取得指定路径的名称和后缀。
*
* @param path 路径
* @return 路径和后缀
*/
public static FileNameAndExtension getFileNameAndExtension(String path) {
return getFileNameAndExtension(path, false);
}
代码示例来源:origin: webx/citrus
@Override
public String doMapping(String name) {
FileNameAndExtension names = getFileNameAndExtension(name, true);
String extension = names.getExtension(); // 可能为null
if (extension == null) {
extension = EMPTY_STRING;
} else {
extension = extension.toLowerCase();
}
// 如果映射规则存在,则替换后缀
if (extensionMappings.containsKey(extension)) {
String mapToExtension = extensionMappings.get(extension);
name = names.getFileName(); // 总不为null
// 如果以/结尾,就不加后缀。
if (name.length() == 0 || !StringUtil.contains(NAME_SEPARATOR, name.charAt(name.length() - 1))) {
// 如果获取的映射后缀不为空,则加上后缀
if (!StringUtil.isEmpty(mapToExtension)) {
name = name + EXTENSION_SEPARATOR + mapToExtension;
}
}
} else {
// 当后缀不在映射规则中,且后缀为空,则至返回名称的前部
if (StringUtil.isEmpty(extension)) {
name = names.getFileName();
}
}
return name;
}
代码示例来源:origin: webx/citrus
@Override
public String doMapping(String name) {
FileNameAndExtension names = getFileNameAndExtension(name, true);
String extension = names.getExtension(); // 可能为null
if (extension == null) {
extension = EMPTY_STRING;
} else {
extension = extension.toLowerCase();
}
// 如果映射规则存在,则替换后缀
if (extensionMappings.containsKey(extension)) {
String mapToExtension = extensionMappings.get(extension);
name = names.getFileName(); // 总不为null
// 如果以/结尾,就不加后缀。
if (name.length() == 0 || !StringUtil.contains(NAME_SEPARATOR, name.charAt(name.length() - 1))) {
// 如果获取的映射后缀不为空,则加上后缀
if (!StringUtil.isEmpty(mapToExtension)) {
name = name + EXTENSION_SEPARATOR + mapToExtension;
}
}
} else {
// 当后缀不在映射规则中,且后缀为空,则至返回名称的前部
if (StringUtil.isEmpty(extension)) {
name = names.getFileName();
}
}
return name;
}
代码示例来源:origin: webx/citrus
public TemplateKey(String templateName, TemplateSearchingStrategy[] strategies) {
templateName = assertNotNull(trimToNull(normalizeAbsolutePath(templateName)), "illegal templateName: %s",
templateName);
FileNameAndExtension names = getFileNameAndExtension(templateName, true);
this.templateNameWithoutExtension = names.getFileName();
this.extension = names.getExtension();
if (isEmptyArray(strategies)) {
this.strategyKeys = EMPTY_OBJECT_ARRAY;
} else {
this.strategyKeys = new Object[strategies.length];
for (int i = 0; i < strategies.length; i++) {
strategyKeys[i] = strategies[i].getKey(getTemplateName());
}
}
}
代码示例来源:origin: com.alibaba.citrus/citrus-webx-all
/**
* 取得指定路径的名称和后缀。
*
* @param path 路径
* @return 路径和后缀
*/
public static FileNameAndExtension getFileNameAndExtension(String path) {
return getFileNameAndExtension(path, false);
}
代码示例来源:origin: webx/citrus
public TemplateKey(String templateName, TemplateSearchingStrategy[] strategies) {
templateName = assertNotNull(trimToNull(normalizeAbsolutePath(templateName)), "illegal templateName: %s",
templateName);
FileNameAndExtension names = getFileNameAndExtension(templateName, true);
this.templateNameWithoutExtension = names.getFileName();
this.extension = names.getExtension();
if (isEmptyArray(strategies)) {
this.strategyKeys = EMPTY_OBJECT_ARRAY;
} else {
this.strategyKeys = new Object[strategies.length];
for (int i = 0; i < strategies.length; i++) {
strategyKeys[i] = strategies[i].getKey(getTemplateName());
}
}
}
代码示例来源:origin: com.alibaba.citrus/citrus-webx-all
@Override
public String doMapping(String name) {
FileNameAndExtension names = getFileNameAndExtension(name, true);
String extension = names.getExtension(); // 可能为null
if (extension == null) {
extension = EMPTY_STRING;
} else {
extension = extension.toLowerCase();
}
// 如果映射规则存在,则替换后缀
if (extensionMappings.containsKey(extension)) {
String mapToExtension = extensionMappings.get(extension);
name = names.getFileName(); // 总不为null
// 如果以/结尾,就不加后缀。
if (name.length() == 0 || !StringUtil.contains(NAME_SEPARATOR, name.charAt(name.length() - 1))) {
// 如果获取的映射后缀不为空,则加上后缀
if (!StringUtil.isEmpty(mapToExtension)) {
name = name + EXTENSION_SEPARATOR + mapToExtension;
}
}
} else {
// 当后缀不在映射规则中,且后缀为空,则至返回名称的前部
if (StringUtil.isEmpty(extension)) {
name = names.getFileName();
}
}
return name;
}
代码示例来源:origin: com.alibaba.citrus/citrus-webx-all
public TemplateKey(String templateName, TemplateSearchingStrategy[] strategies) {
templateName = assertNotNull(trimToNull(normalizeAbsolutePath(templateName)), "illegal templateName: %s",
templateName);
FileNameAndExtension names = getFileNameAndExtension(templateName, true);
this.templateNameWithoutExtension = names.getFileName();
this.extension = names.getExtension();
if (isEmptyArray(strategies)) {
this.strategyKeys = EMPTY_OBJECT_ARRAY;
} else {
this.strategyKeys = new Object[strategies.length];
for (int i = 0; i < strategies.length; i++) {
strategyKeys[i] = strategies[i].getKey(getTemplateName());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!