hudson.Util.getFileName()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(132)

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

Util.getFileName介绍

[英]Cuts all the leading path portion and get just the file name.
[中]剪切所有前导路径部分,只获取文件名。

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Cuts all the leading path portion and get just the file name.
 */
@Nonnull
public static String getFileName(@Nonnull String filePath) {
  int idx = filePath.lastIndexOf('\\');
  if(idx>=0)
    return getFileName(filePath.substring(idx+1));
  idx = filePath.lastIndexOf('/');
  if(idx>=0)
    return getFileName(filePath.substring(idx+1));
  return filePath;
}

代码示例来源:origin: jenkinsci/jenkins

String fileName = Util.getFileName(fileItem.getName());
if("".equals(fileName)){
  return new HttpRedirect("advanced");

代码示例来源:origin: jenkinsci/jenkins

String target = readSymlink(f);
if (target!=null) {
  int n = Integer.parseInt(Util.getFileName(target));
  if (n==RESOLVES_TO_NONE)  return null;

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Cuts all the leading path portion and get just the file name.
 */
public static String getFileName(String filePath) {
  int idx = filePath.lastIndexOf('\\');
  if(idx>=0)
    return getFileName(filePath.substring(idx+1));
  idx = filePath.lastIndexOf('/');
  if(idx>=0)
    return getFileName(filePath.substring(idx+1));
  return filePath;
}

代码示例来源:origin: hudson/hudson-2.x

/**
 * Cuts all the leading path portion and get just the file name.
 */
public static String getFileName(String filePath) {
  int idx = filePath.lastIndexOf('\\');
  if(idx>=0)
    return getFileName(filePath.substring(idx+1));
  idx = filePath.lastIndexOf('/');
  if(idx>=0)
    return getFileName(filePath.substring(idx+1));
  return filePath;
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

/**
 * Cuts all the leading path portion and get just the file name.
 */
public static String getFileName(String filePath) {
  int idx = filePath.lastIndexOf('\\');
  if (idx >= 0) {
    return getFileName(filePath.substring(idx + 1));
  }
  idx = filePath.lastIndexOf('/');
  if (idx >= 0) {
    return getFileName(filePath.substring(idx + 1));
  }
  return filePath;
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Cuts all the leading path portion and get just the file name.
 */
public static String getFileName(String filePath) {
  int idx = filePath.lastIndexOf('\\');
  if (idx >= 0) {
    return getFileName(filePath.substring(idx + 1));
  }
  idx = filePath.lastIndexOf('/');
  if (idx >= 0) {
    return getFileName(filePath.substring(idx + 1));
  }
  return filePath;
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Cuts all the leading path portion and get just the file name.
 */
@Nonnull
public static String getFileName(@Nonnull String filePath) {
  int idx = filePath.lastIndexOf('\\');
  if(idx>=0)
    return getFileName(filePath.substring(idx+1));
  idx = filePath.lastIndexOf('/');
  if(idx>=0)
    return getFileName(filePath.substring(idx+1));
  return filePath;
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

/**
 * Uploads a plugin.
 */
public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
  try {
    Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
    ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
    // Parse the request
    FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
    String fileName = Util.getFileName(fileItem.getName());
    if("".equals(fileName))
      return new HttpRedirect("advanced");
    if(!fileName.endsWith(".hpi"))
      throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
    fileItem.write(new File(rootDir, fileName));
    fileItem.delete();
    pluginUploaded = true;
    return new HttpRedirect(".");
  } catch (IOException e) {
    throw e;
  } catch (Exception e) {// grrr. fileItem.write throws this
    throw new ServletException(e);
  }
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Uploads a plugin.
 */
public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
  try {
    Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
    ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
    // Parse the request
    FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
    String fileName = Util.getFileName(fileItem.getName());
    if("".equals(fileName))
      return new HttpRedirect("advanced");
    if(!fileName.endsWith(".hpi"))
      throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
    fileItem.write(new File(rootDir, fileName));
    fileItem.delete();
    pluginUploaded = true;
    return new HttpRedirect(".");
  } catch (IOException e) {
    throw e;
  } catch (Exception e) {// grrr. fileItem.write throws this
    throw new ServletException(e);
  }
}

代码示例来源:origin: hudson/hudson-2.x

/**
 * Uploads a plugin.
 */
public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
  try {
    Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
    ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
    // Parse the request
    FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
    String fileName = Util.getFileName(fileItem.getName());
    if("".equals(fileName))
      return new HttpRedirect("advanced");
    if(!fileName.endsWith(".hpi"))
      throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
    fileItem.write(new File(rootDir, fileName));
    fileItem.delete();
    pluginUploaded = true;
    return new HttpRedirect(".");
  } catch (IOException e) {
    throw e;
  } catch (Exception e) {// grrr. fileItem.write throws this
    throw new ServletException(e);
  }
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Uploads a plugin.
 */
public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
  try {
    Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
    ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
    // Parse the request
    FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
    String fileName = Util.getFileName(fileItem.getName());
    if ("".equals(fileName)) {
      return new HttpRedirect("advanced");
    }
    if (!fileName.endsWith(".hpi")) {
      throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
    }
    fileItem.write(new File(rootDir, fileName));
    fileItem.delete();
    pluginUploaded = true;
    return new HttpRedirect(".");
  } catch (IOException e) {
    throw e;
  } catch (Exception e) {// grrr. fileItem.write throws this
    throw new ServletException(e);
  }
}

代码示例来源:origin: org.jenkins-ci.plugins/scriptler

/**
 * Uploads a script and stores it with the given filename to the configuration. It will be stored on the filessytem.
 * 
 * @param req
 *            request
 * @return forward to index page.
 * @throws IOException
 * @throws ServletException
 */
public HttpResponse doUploadScript(StaplerRequest req) throws IOException, ServletException {
  checkPermission(Hudson.ADMINISTER);
  try {
    
    FileItem fileItem = req.getFileItem("file");
    boolean nonAdministerUsing = req.getSubmittedForm().getBoolean("nonAdministerUsing");
    String fileName = Util.getFileName(fileItem.getName());
    if (StringUtils.isEmpty(fileName)) {
      return new HttpRedirect(".");
    }
    saveScript(fileItem, nonAdministerUsing, fileName);
    return new HttpRedirect("index");
  } catch (IOException e) {
    throw e;
  } catch (Exception e) {
    throw new ServletException(e);
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

String fileName = Util.getFileName(fileItem.getName());
if("".equals(fileName)){
  return new HttpRedirect("advanced");

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

String target = readSymlink(f);
if (target!=null) {
  int n = Integer.parseInt(Util.getFileName(target));
  if (n==RESOLVES_TO_NONE)  return null;

相关文章

微信公众号

最新文章

更多