Eclipseplugins
UserExitTools.java
1 package com.proalpha.pds.ui;
2 
3 import java.nio.file.Paths;
4 import java.util.ArrayList;
5 import java.util.List;
6 
7 import org.eclipse.core.resources.IFile;
8 import org.eclipse.core.runtime.IPath;
9 
10 public class UserExitTools {
14  static final String USEREXITFILEEXTENTIONS = "cdf,fld,if,i,lib,p,pds,tdf,w,cls";
15  static final String USEREXITCUSTOMLEVELS = "c,q,u,x,y,z";
16  List<String> userexitfiletypes = new ArrayList<>();
17 
18 
19  public static boolean userexitpossible(IFile filename) {
23  // without a file we can't check
24  if (filename ==null){
25  return false;
26  }
27 
28  // Return yes if the file Extension allows USER EXITS
29 
30  String[] results = USEREXITFILEEXTENTIONS.split(",");
31 
32  for (String result : results) {
33  if (result.equalsIgnoreCase(filename.getFileExtension() )) {
34  return true;
35  }
36  }
37 
38  return false;
39  }
40 
41  public static boolean userExitFileExists(IFile file, String customlevel) {
46  if (file == null){
47  return false;
48  }
49 
50  if(file.getFileExtension().equalsIgnoreCase("cls")) {
51  return claasUserExitExists(file,customlevel);
52  }
53  IPath newFilePath;
54  //only getRawLocation returns the FULL Path from OS
55  newFilePath = file.getRawLocation();
56  newFilePath = newFilePath.removeFileExtension();
57  newFilePath = newFilePath.addFileExtension(getUserExitFileExt(file,customlevel));
58  return newFilePath.toFile().exists();
59 
60  }
61 
62  private static String getUserExitFileExt(IFile pAprocedure,String customLevel) {
63 
64  return customLevel.toLowerCase() + "x" + pAprocedure.getFileExtension().substring(0, 1);
65 
66  }
67 
68  private static boolean claasUserExitExists(IFile file, String customlevel) {
72  IPath newFilePath = file.getRawLocation();
73  String newFileName = newFilePath.removeFileExtension().toString();
74 
75  // if File ends with the current Custom Level it may be an User Exit.
76  if(newFileName.toUpperCase().endsWith(customlevel.toUpperCase())) {
77  newFileName = newFileName.substring(0,newFileName.length() - 1);
78  if (Paths.get(newFileName + ".cls").toFile().exists()){
79  return true;
80  }
81  }
82 
83  if (newFileName.endsWith("Std"))
84  //remove the Std
85  newFileName = newFileName.substring(0, newFileName.length() - 3);
86 
87  return Paths.get(newFileName + customlevel.toUpperCase() + ".cls").toFile().exists();
88 
89  }
90 }
static boolean userExitFileExists(IFile file, String customlevel)
static boolean userexitpossible(IFile filename)