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

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

本文整理了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

  1. /**
  2. * Cuts all the leading path portion and get just the file name.
  3. */
  4. @Nonnull
  5. public static String getFileName(@Nonnull String filePath) {
  6. int idx = filePath.lastIndexOf('\\');
  7. if(idx>=0)
  8. return getFileName(filePath.substring(idx+1));
  9. idx = filePath.lastIndexOf('/');
  10. if(idx>=0)
  11. return getFileName(filePath.substring(idx+1));
  12. return filePath;
  13. }

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

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

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

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

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

  1. /**
  2. * Cuts all the leading path portion and get just the file name.
  3. */
  4. public static String getFileName(String filePath) {
  5. int idx = filePath.lastIndexOf('\\');
  6. if(idx>=0)
  7. return getFileName(filePath.substring(idx+1));
  8. idx = filePath.lastIndexOf('/');
  9. if(idx>=0)
  10. return getFileName(filePath.substring(idx+1));
  11. return filePath;
  12. }

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

  1. /**
  2. * Cuts all the leading path portion and get just the file name.
  3. */
  4. public static String getFileName(String filePath) {
  5. int idx = filePath.lastIndexOf('\\');
  6. if(idx>=0)
  7. return getFileName(filePath.substring(idx+1));
  8. idx = filePath.lastIndexOf('/');
  9. if(idx>=0)
  10. return getFileName(filePath.substring(idx+1));
  11. return filePath;
  12. }

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

  1. /**
  2. * Cuts all the leading path portion and get just the file name.
  3. */
  4. public static String getFileName(String filePath) {
  5. int idx = filePath.lastIndexOf('\\');
  6. if (idx >= 0) {
  7. return getFileName(filePath.substring(idx + 1));
  8. }
  9. idx = filePath.lastIndexOf('/');
  10. if (idx >= 0) {
  11. return getFileName(filePath.substring(idx + 1));
  12. }
  13. return filePath;
  14. }

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

  1. /**
  2. * Cuts all the leading path portion and get just the file name.
  3. */
  4. public static String getFileName(String filePath) {
  5. int idx = filePath.lastIndexOf('\\');
  6. if (idx >= 0) {
  7. return getFileName(filePath.substring(idx + 1));
  8. }
  9. idx = filePath.lastIndexOf('/');
  10. if (idx >= 0) {
  11. return getFileName(filePath.substring(idx + 1));
  12. }
  13. return filePath;
  14. }

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

  1. /**
  2. * Cuts all the leading path portion and get just the file name.
  3. */
  4. @Nonnull
  5. public static String getFileName(@Nonnull String filePath) {
  6. int idx = filePath.lastIndexOf('\\');
  7. if(idx>=0)
  8. return getFileName(filePath.substring(idx+1));
  9. idx = filePath.lastIndexOf('/');
  10. if(idx>=0)
  11. return getFileName(filePath.substring(idx+1));
  12. return filePath;
  13. }

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

  1. /**
  2. * Uploads a plugin.
  3. */
  4. public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
  5. try {
  6. Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
  7. ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
  8. // Parse the request
  9. FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
  10. String fileName = Util.getFileName(fileItem.getName());
  11. if("".equals(fileName))
  12. return new HttpRedirect("advanced");
  13. if(!fileName.endsWith(".hpi"))
  14. throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
  15. fileItem.write(new File(rootDir, fileName));
  16. fileItem.delete();
  17. pluginUploaded = true;
  18. return new HttpRedirect(".");
  19. } catch (IOException e) {
  20. throw e;
  21. } catch (Exception e) {// grrr. fileItem.write throws this
  22. throw new ServletException(e);
  23. }
  24. }

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

  1. /**
  2. * Uploads a plugin.
  3. */
  4. public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
  5. try {
  6. Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
  7. ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
  8. // Parse the request
  9. FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
  10. String fileName = Util.getFileName(fileItem.getName());
  11. if("".equals(fileName))
  12. return new HttpRedirect("advanced");
  13. if(!fileName.endsWith(".hpi"))
  14. throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
  15. fileItem.write(new File(rootDir, fileName));
  16. fileItem.delete();
  17. pluginUploaded = true;
  18. return new HttpRedirect(".");
  19. } catch (IOException e) {
  20. throw e;
  21. } catch (Exception e) {// grrr. fileItem.write throws this
  22. throw new ServletException(e);
  23. }
  24. }

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

  1. /**
  2. * Uploads a plugin.
  3. */
  4. public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
  5. try {
  6. Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
  7. ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
  8. // Parse the request
  9. FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
  10. String fileName = Util.getFileName(fileItem.getName());
  11. if("".equals(fileName))
  12. return new HttpRedirect("advanced");
  13. if(!fileName.endsWith(".hpi"))
  14. throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
  15. fileItem.write(new File(rootDir, fileName));
  16. fileItem.delete();
  17. pluginUploaded = true;
  18. return new HttpRedirect(".");
  19. } catch (IOException e) {
  20. throw e;
  21. } catch (Exception e) {// grrr. fileItem.write throws this
  22. throw new ServletException(e);
  23. }
  24. }

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

  1. /**
  2. * Uploads a plugin.
  3. */
  4. public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
  5. try {
  6. Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
  7. ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
  8. // Parse the request
  9. FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
  10. String fileName = Util.getFileName(fileItem.getName());
  11. if ("".equals(fileName)) {
  12. return new HttpRedirect("advanced");
  13. }
  14. if (!fileName.endsWith(".hpi")) {
  15. throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
  16. }
  17. fileItem.write(new File(rootDir, fileName));
  18. fileItem.delete();
  19. pluginUploaded = true;
  20. return new HttpRedirect(".");
  21. } catch (IOException e) {
  22. throw e;
  23. } catch (Exception e) {// grrr. fileItem.write throws this
  24. throw new ServletException(e);
  25. }
  26. }

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

  1. /**
  2. * Uploads a script and stores it with the given filename to the configuration. It will be stored on the filessytem.
  3. *
  4. * @param req
  5. * request
  6. * @return forward to index page.
  7. * @throws IOException
  8. * @throws ServletException
  9. */
  10. public HttpResponse doUploadScript(StaplerRequest req) throws IOException, ServletException {
  11. checkPermission(Hudson.ADMINISTER);
  12. try {
  13. FileItem fileItem = req.getFileItem("file");
  14. boolean nonAdministerUsing = req.getSubmittedForm().getBoolean("nonAdministerUsing");
  15. String fileName = Util.getFileName(fileItem.getName());
  16. if (StringUtils.isEmpty(fileName)) {
  17. return new HttpRedirect(".");
  18. }
  19. saveScript(fileItem, nonAdministerUsing, fileName);
  20. return new HttpRedirect("index");
  21. } catch (IOException e) {
  22. throw e;
  23. } catch (Exception e) {
  24. throw new ServletException(e);
  25. }
  26. }

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

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

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

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

相关文章