ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.vci.server.workflow.server;
 
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
 
import com.vci.server.workflow.common.resouce.EventProperties;
/**
 * 
 * add by caill 遍历获取所有eventConf_模块名称.properties格式的文件
 * 
 * */
public class EventUtil {
    public static void main(String[] args){
        EventUtil eu = new EventUtil();
        eu.getAlleventConfName();
        System.out.println(EventProperties.getStringProperty("workflow.event.type.trainsition"));
    }
    private static String SPLIT_CHAR = "##";
    public List<String> getAlleventConfName() {
        List<String> nameList = new ArrayList<String>();
        try {
            URLClassLoader loader = (URLClassLoader)this.getClass().getClassLoader();        
            URL[] urls = loader.getURLs();
            for(URL url : urls){
                URI uri = url.toURI();
                String uriToString = uri.toString();
                if(uriToString.endsWith(".jar")){
                    JarFile jar = new JarFile(new File(uri));
                    
                    Enumeration<JarEntry> entrys = jar.entries();
                    while(entrys.hasMoreElements()){
                        JarEntry entry = entrys.nextElement();
                        ZipEntry zip = (ZipEntry)entry;
                        String zipName = zip.getName();
                        if(zipName.contains("properties/eventConf") && zipName.endsWith(".properties")){
                            nameList.add(zipName + SPLIT_CHAR + uriToString);
                        }
                    }
                }
            }
            Collections.sort(nameList, new Comparator<String>() {
                public int compare(String o1, String o2) {
                    int index1= o1.indexOf(SPLIT_CHAR);
                    int index2= o2.indexOf(SPLIT_CHAR);
                    String str1 = o1.substring(0, index1);
                    String str2 = o2.substring(0, index2);
                    return str1.compareTo(str2);
                }
            });
            int splitCharLen = SPLIT_CHAR.length();
            List<String> list = new ArrayList<String>();
            for (String name: nameList){
                int index = name.indexOf(SPLIT_CHAR);
                String zipName = name.substring(0, index);
                String uriToString = name.substring(index + splitCharLen);
                //System.out.println("#####properties的路径======" + uriToString + "!" + zipName);
                list.add(zipName);
            }
            nameList = list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        
        return nameList;
    }
}