com.alibaba.citrus.util.FileUtil.normalizeAbsolutePath()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中com.alibaba.citrus.util.FileUtil.normalizeAbsolutePath()方法的一些代码示例,展示了FileUtil.normalizeAbsolutePath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.normalizeAbsolutePath()方法的具体详情如下:
包路径:com.alibaba.citrus.util.FileUtil
类名称:FileUtil
方法名:normalizeAbsolutePath

FileUtil.normalizeAbsolutePath介绍

[英]规格化绝对路径。

该方法返回以“/”开始的绝对路径。转换规则如下:

  1. 路径为空,则返回""
  2. 将所有backslash("\")转化成slash("/")。
  3. 去除重复的"/"或"\"。
  4. 去除".",如果发现"..",则向上朔一级目录。
  5. 保留路径末尾的"/"(如果有的话,除了空路径)。
  6. 对于绝对路径,如果".."上朔的路径超过了根目录,则看作非法路径,抛出异常。
    [中]规格化绝对路径。
    该方法返回以“/”开始的绝对路径。转换规则如下:
    1.路径为空,则返回""
    1.将所有反斜杠(\)转化成斜杠(“/”)
    1.去除重复的"/"或"\"。
    1.去除".",如果发现"..",则向上朔一级目录。
    1.保留路径末尾的"/"(如果有的话,除了空路径)。
    1.对于绝对路径,如果".."上朔的路径超过了根目录,则看作非法路径,抛出异常。

代码示例

代码示例来源:origin: webx/citrus

public InlineResourceHelper(String prefix) {
  this.prefix = FileUtil.normalizeAbsolutePath(prefix + "/");
}

代码示例来源:origin: webx/citrus

public void setHomepage(String homepage) {
  this.homepage = normalizeAbsolutePath(homepage);
}

代码示例来源:origin: webx/citrus

public void setHomepage(String homepage) {
  this.homepage = normalizeAbsolutePath(homepage);
}

代码示例来源:origin: webx/citrus

/**
 * 取得request所请求的资源路径。
 * <p>
 * 资源路径为<code>getServletPath() + getPathInfo()</code>。
 * </p>
 * <p>
 * 注意,<code>ResourcePath</code>以<code>"/"</code>开始,如果无内容,则返回空字符串
 * <code>""</code>。
 * </p>
 */
public static String getResourcePath(HttpServletRequest request) {
  String pathInfo = normalizeAbsolutePath(request.getPathInfo(), false);
  String servletPath = normalizeAbsolutePath(request.getServletPath(), pathInfo.length() != 0);
  return servletPath + pathInfo;
}

代码示例来源:origin: webx/citrus

private void resolveMacro(ResourcePatternResolver resolver, String macro) {
  String path = normalizeAbsolutePath(this.path + "/");
  String pattern = normalizeAbsolutePath(path + macro);
  Resource[] resources;
  try {
    resources = resolver.getResources(pattern);
  } catch (IOException e) {
    resources = null;
  }
  addMacroResources(path, resources);
}

代码示例来源:origin: webx/citrus

private void resolveMacro(ResourcePatternResolver resolver, String macro) {
  String path = normalizeAbsolutePath(this.path + "/");
  String pattern = normalizeAbsolutePath(path + macro);
  Resource[] resources;
  try {
    resources = resolver.getResources(pattern);
  } catch (IOException e) {
    resources = null;
  }
  addMacroResources(path, resources);
}

代码示例来源:origin: webx/citrus

private String getNewResourceName(ResourceMatchResult context) {
  String resourceName = EMPTY_STRING;
  if (newResourceName != null) {
    resourceName = newResourceName;
  }
  resourceName = normalizeAbsolutePath(context.substitute(resourceName));
  return resourceName;
}

代码示例来源:origin: webx/citrus

public void visitSubResource(Template subResourceTemplate) {
  for (String subResourceName : subResourceNames) {
    fullSubResourceName = normalizeAbsolutePath(resourceName + "/" + subResourceName);
    relativeSubResourceName = subResourceName;
    subResourceTemplate.accept(this);
  }
}

代码示例来源:origin: webx/citrus

private String getNewResourceName(ResourceMatchResult context) {
  String resourceName = EMPTY_STRING;
  if (newResourceName != null) {
    resourceName = newResourceName;
  }
  resourceName = normalizeAbsolutePath(context.substitute(resourceName));
  return resourceName;
}

代码示例来源:origin: webx/citrus

public void visitSubResource(Template subResourceTemplate) {
  for (String subResourceName : subResourceNames) {
    fullSubResourceName = normalizeAbsolutePath(resourceName + "/" + subResourceName);
    relativeSubResourceName = subResourceName;
    subResourceTemplate.accept(this);
  }
}

代码示例来源:origin: webx/citrus

public String getURI(String path) {
    String resourceName = FileUtil.normalizeAbsolutePath(prefix + path);
    InlineResource inlineResource = inlineResources.get(resourceName);
    if (inlineResource == null) {
      inlineResource = new InlineResource(resourceName);
      inlineResources.put(resourceName, inlineResource);
    }
    return "cid:" + inlineResource.getContentId();
  }
}

代码示例来源:origin: webx/citrus

public String getURI(String path) {
    String resourceName = FileUtil.normalizeAbsolutePath(prefix + path);
    InlineResource inlineResource = inlineResources.get(resourceName);
    if (inlineResource == null) {
      inlineResource = new InlineResource(resourceName);
      inlineResources.put(resourceName, inlineResource);
    }
    return "cid:" + inlineResource.getContentId();
  }
}

代码示例来源:origin: webx/citrus

public ResourcesVisitor(RequestHandlerContext context, ExplorerVisitor v,
            ResourceLoadingService resourceLoadingService) {
  super(context, v);
  this.resourceLoadingService = assertNotNull(resourceLoadingService, "resourceLoadingService");
  String resourceName;
  try {
    resourceName = defaultIfEmpty(normalizeAbsolutePath(context.getRequest().getParameter("resource")), "/");
  } catch (IllegalPathException e) {
    resourceName = "/";
  }
  this.resourceName = resourceName;
}

代码示例来源:origin: webx/citrus

public ResourcesVisitor(RequestHandlerContext context, ExplorerVisitor v,
            ResourceLoadingService resourceLoadingService) {
  super(context, v);
  this.resourceLoadingService = assertNotNull(resourceLoadingService, "resourceLoadingService");
  String resourceName;
  try {
    resourceName = defaultIfEmpty(normalizeAbsolutePath(context.getRequest().getParameter("resource")), "/");
  } catch (IllegalPathException e) {
    resourceName = "/";
  }
  this.resourceName = resourceName;
}

代码示例来源:origin: webx/citrus

public SpringResourceLoaderAdapter(ResourceLoader springLoader, String path) {
  this.springLoader = assertNotNull(springLoader, "spring resource loader");
  path = normalizeAbsolutePath(path, true);
  assertTrue(!isEmpty(path), "path");
  this.path = path + '/';
}

代码示例来源:origin: webx/citrus

public SpringResourceLoaderAdapter(ResourceLoader springLoader, String path) {
  this.springLoader = assertNotNull(springLoader, "spring resource loader");
  path = normalizeAbsolutePath(path, true);
  assertTrue(!isEmpty(path), "path");
  this.path = path + '/';
}

代码示例来源:origin: webx/citrus

/** 创建一个context。 */
public AbstractResourceLoadingContext(String resourceName, Set<ResourceLoadingOption> options,
                   ResourceMapping[] mappings, ResourceLoadingService parent, Logger log) {
  // 不变量
  this.log = assertNotNull(log, "logger");
  this.parent = parent;
  this.originalResourceName = normalizeAbsolutePath(assertNotNull(trimToNull(resourceName), "resourceName"));
  this.originalOptions = defaultIfNull(options, EMPTY_OPTIONS);
  this.mappings = assertNotNull(mappings, "mappings");
  this.resourcesMatcher = new BestResourcesMatcher();
  // 变量
  this.resourceName = originalResourceName;
  this.options = originalOptions;
}

代码示例来源: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: webx/citrus

/** 初始化resource loader. */
@Override
public void init(ExtendedProperties configuration) {
  rsvc.getLog().info(getLogID() + " : initialization starting.");
  springLoader = assertNotNull((ResourceLoader) rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_KEY),
                 SPRING_RESOURCE_LOADER_KEY);
  path = normalizeAbsolutePath(configuration.getString("path"), true);
  assertTrue(!isEmpty(path), "path");
  path += "/";
  rsvc.getLog().info(getLogID() + " : set path '" + path + "'");
  rsvc.getLog().info(getLogID() + " : initialization complete.");
}

代码示例来源:origin: webx/citrus

/** 初始化resource loader. */
@Override
public void init(ExtendedProperties configuration) {
  rsvc.getLog().info(getLogID() + " : initialization starting.");
  springLoader = assertNotNull((ResourceLoader) rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_KEY),
                 SPRING_RESOURCE_LOADER_KEY);
  path = normalizeAbsolutePath(configuration.getString("path"), true);
  assertTrue(!isEmpty(path), "path");
  path += "/";
  rsvc.getLog().info(getLogID() + " : set path '" + path + "'");
  rsvc.getLog().info(getLogID() + " : initialization complete.");
}

相关文章