1 23 package org.enhydra.kelp; 24 25 import org.enhydra.tool.ToolBoxInfo; 27 import org.enhydra.tool.common.FilenameFilter; 28 import org.enhydra.tool.common.FileUtil; 29 import org.enhydra.tool.common.PathHandle; 30 import org.enhydra.tool.common.ToolException; 31 32 import org.enhydra.kelp.common.Constants; 34 import org.enhydra.kelp.common.ResUtil; 35 36 import java.io.File ; 38 import java.net.MalformedURLException ; 39 import java.util.ArrayList ; 40 import java.util.Arrays ; 41 import java.util.ResourceBundle ; 42 import java.util.Properties ; 43 44 47 public class KelpInfo { 48 public static final String ADDIN_ROOT = "addin.root"; 49 public static final String ADDIN_HELP = "using_kelp.html"; 50 51 static ResourceBundle res = 53 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); private static final String VERSION = "5.2"; private static final String TOOLBOX_CLASS = 56 "org.enhydra.tool.ToolBoxInfo"; 58 public static String getKelpVersion() { 60 return KelpInfo.VERSION; 61 } 62 63 public static void verifyIDEClassPath() throws Exception { 64 boolean valid = true; 65 66 valid = KelpInfo.isClassPathComplete(); 67 StringBuffer message = new StringBuffer (); 68 69 if (!valid) { 70 message.append(res.getString("MissingJars1")); 71 message.append(res.getString("MissingJars2")); 72 if (KelpInfo.isToolBoxInClassPath()) { 73 if (!KelpInfo.isToolBoxVersionInSynch()) { 74 message.setLength(0); 75 message.append(res.getString("OutOfSync")); 76 message.append(ResUtil.format(res.getString("Kelp_version_0"), 77 KelpInfo.getKelpVersion())); 78 message.append('\n'); 79 message.append(ResUtil.format(res.getString("ToolBox_version_0"), 80 ToolBoxInfo.getToolBoxVersion())); 81 } else if (!ToolBoxInfo.isEnhydraInClassPath()) { 82 message.append(Constants.FILE_ENHYDRA_JAR); 83 message.append('\n'); 84 } else if (!ToolBoxInfo.isXMLCInClassPath()) { 85 message.append(Constants.FILE_XMLC_JAR); 86 message.append('\n'); 87 } 88 } else { 89 message.append(Constants.FILE_TOOLBOX_JAR); 90 message.append('\n'); 91 } 92 throw new Exception (message.toString()); 93 } 94 } 95 96 public static String getMessageBoxTitle() { 97 StringBuffer buf = new StringBuffer (); 98 99 buf.append(Constants.KELP); 100 buf.append(Constants.TAB1); 101 buf.append(KelpInfo.VERSION); 102 return buf.toString(); 103 } 104 105 public static boolean isToolBoxInClassPath() { 106 boolean inPath = true; 107 108 try { 109 Class testClass = Class.forName(TOOLBOX_CLASS); 110 } catch (java.lang.ClassNotFoundException e) { 111 inPath = false; 112 } 113 return inPath; 114 } 115 116 public static boolean isToolBoxVersionInSynch() { 117 boolean inSynch = false; 118 119 if (KelpInfo.isToolBoxInClassPath()) { 120 if (ToolBoxInfo.getToolBoxVersion().equalsIgnoreCase(KelpInfo.getKelpVersion())) { 121 inSynch = true; 122 } 123 } 124 return inSynch; 125 } 126 127 public static boolean isClassPathComplete() { 128 boolean complete = false; 129 130 if (KelpInfo.isToolBoxInClassPath()) { 131 if (ToolBoxInfo.isXMLCInClassPath() 132 && KelpInfo.isToolBoxVersionInSynch()) { 133 complete = true; 134 } 135 } 136 return complete; 137 } 138 139 public static String getAddinHelpURL() { 140 String [] search = new String [0]; 141 142 return KelpInfo.getAddinHelpURL(search); 143 } 144 145 public static String getAddinHelpURL(String s) { 146 String [] search = new String [1]; 147 148 if (s == null) { 149 search = new String [0]; 150 } else { 151 search[0] = s; 152 } 153 return KelpInfo.getAddinHelpURL(search); 154 } 155 156 public static String getAddinHelpURL(String [] search) { 157 StringBuffer buf = new StringBuffer (); 158 File file = null; 159 160 buf.append(KelpInfo.getAddinRoot(search)); 161 buf.append("/doc/"); 162 buf.append(KelpInfo.ADDIN_HELP); 163 file = new File (buf.toString()); 164 buf.setLength(0); 165 try { 166 buf.append(file.toURL().toExternalForm()); 167 } catch (MalformedURLException e) { 168 e.printStackTrace(System.err); 169 } 170 return buf.toString(); 171 } 172 173 private static String getAddinRoot(String [] search) { 174 final String FILE_ADDIN_JAR = "KelpAddinJBuilder7.jar"; 175 ArrayList list = null; 176 Properties props = null; 177 String root = null; 178 String [] paths = new String [0]; 179 ClassLoader loader = null; 180 FilenameFilter filter = null; 181 PathHandle ph = null; 182 KelpInfo info = null; 183 184 info = new KelpInfo(); 186 loader = info.getClass().getClassLoader(); 187 paths = FileUtil.findJarPaths(FILE_ADDIN_JAR, loader); 188 for (int i = 0; i < paths.length; i++) { 189 ph = PathHandle.createPathHandle(paths[i]); 190 ph = ph.getParent(); 191 if (ph.getParent() == null) { 192 root = ph.getPath(); 193 } else { 194 root = ph.getParent().getPath(); 195 } 196 break; 197 } 198 199 if (root == null) { 201 ph = PathHandle.createPathHandle(ToolBoxInfo.getEnhydraRoot()); 202 if (ph.getParent() != null) { 203 list = new ArrayList (Arrays.asList(search)); 204 list.add(ph.getParent().getPath() + "/kelp5"); 205 list.trimToSize(); 206 search = new String [list.size()]; 207 search = (String []) list.toArray(search); 208 list.clear(); 209 } 210 filter = new FilenameFilter(); 211 filter.setIncludeName(KelpInfo.ADDIN_HELP); 212 filter.setDirectoryValid(false); 213 for (int i = 0; i < search.length; i++) { 214 ph = PathHandle.createPathHandle(FileUtil.findFirst(filter, 215 search[i])); 216 if (ph.isFile()) { 217 ph = ph.getParent(); 218 if (ph.getParent() != null) { 219 ph = ph.getParent(); 220 } 221 root = ph.getPath(); 222 break; 223 } 224 } 225 } 226 try { 227 228 props = ToolBoxInfo.loadProperties(); 230 if (root == null) { 231 root = props.getProperty(ADDIN_ROOT); 232 } else { 233 props.setProperty(KelpInfo.ADDIN_ROOT, root); 234 ToolBoxInfo.storeProperties(props); 235 } 236 } catch (ToolException e) { 237 e.printStackTrace(System.err); 238 root = null; 239 } 240 if (root == null) { 241 root = "../kelp5"; 242 } 243 return root; 244 } 245 246 249 private KelpInfo() {} 250 251 } 252
| Popular Tags
|