01: package com.bostechcorp.cbesb.runtime.ccsl.lib;
02:
03: import java.io.File;
04:
05: import org.w3c.dom.Document;
06: import org.w3c.dom.Node;
07:
08: import com.bostechcorp.cbesb.common.util.Dom;
09: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
10:
11: public class CcslUtil {
12:
13: public static String getAssemblyNameFromWorkspaceDir(
14: String workspaceDir) {
15: String assemblyName = null;
16: String ws = EsbPathHelper.getCbesbUiWorkSpace();
17: int start = workspaceDir.toLowerCase()
18: .indexOf(ws.toLowerCase());
19: if (start >= 0) {
20: start += ws.length() + 1;
21: int end = workspaceDir.indexOf("/", start);
22: if (end < 0)
23: end = workspaceDir.indexOf("\\", start);
24: if (end >= 0)
25: assemblyName = workspaceDir.substring(start, end);
26: else
27: assemblyName = workspaceDir.substring(start);
28: }
29:
30: return assemblyName;
31: }
32:
33: public static String getAssemblyName(String suRootPath)
34: throws Exception {
35: // System.out.println("rootPath:"+suRootPath);
36: Document doc = Dom.getDomTree(new File(suRootPath
37: + "/../../../install/META-INF/jbi.xml"), null);
38:
39: Node sa = Dom.findChild(doc.getDocumentElement(),
40: "service-assembly", true);
41: Node saId = Dom.findChild(sa, "identification", false);
42: Node saName = Dom.findChild(saId, "name", false);
43: String name = saName.getTextContent();
44: return name;
45: }
46:
47: public static String getSaProjectPath(String suRootPath)
48: throws Exception {
49: String ws = EsbPathHelper.getCbesbUiWorkSpace();
50: ws.replace("\\", "/");
51: return ws + "/" + getAssemblyName(suRootPath);
52: }
53:
54: /**
55: *
56: * @param suRootPath
57: * @param scriptClass
58: * @return result[0]=rootPath, result[1]=scriptClass
59: * @throws Exception
60: */
61: public static String[] getRootScriptPath(String suRootPath,
62: String scriptClass) throws Exception {
63: String[] result = new String[2];
64: if (scriptClass.indexOf("::") == -1) {
65: result[0] = getSaProjectPath(suRootPath) + "/src/script";
66: result[1] = scriptClass;
67: return result;
68: } else {
69: String[] array = scriptClass.split("::");
70: String ws = EsbPathHelper.getCbesbUiWorkSpace();
71: String temp;
72: if (array.length == 2) {
73: result[0] = ws + "/" + array[0] + "/src/script";
74: temp = array[1];
75: } else {
76: result[0] = ws + "/" + array[1] + "/src/script";
77: temp = array[2];
78: }
79: int pos = temp.lastIndexOf('/');
80: result[1] = temp.substring(pos + 1);
81:
82: }
83: return result;
84: }
85:
86: /**
87: *
88: * @param suRootPath
89: * @return rootPath
90: * @throws Exception
91: */
92: public static String getRootScriptPath(String suRootPath)
93: throws Exception {
94:
95: return getSaProjectPath(suRootPath) + "/src/script";
96: }
97: }
|