01: package org.objectweb.celtix.common.util;
02:
03: import java.io.*;
04: import java.net.*;
05:
06: public final class StringUtils {
07:
08: private StringUtils() {
09: }
10:
11: public static String extract(String string, String startToken,
12: String endToken) {
13: int start = string.indexOf(startToken) + startToken.length();
14: int end = string.lastIndexOf(endToken);
15:
16: if (start == -1 || end == -1) {
17: return null;
18: }
19:
20: return string.substring(start, end);
21: }
22:
23: public static String wrapper(String string, String startToken,
24: String endToken) {
25: StringBuffer sb = new StringBuffer();
26: sb.append(startToken);
27: sb.append(string);
28: sb.append(endToken);
29: return sb.toString();
30: }
31:
32: public static boolean isFileExist(String file) {
33: return new File(file).exists() && new File(file).isFile();
34: }
35:
36: public static boolean isFileAbsolute(String file) {
37: return isFileExist(file) && new File(file).isAbsolute();
38: }
39:
40: public static URL getURL(String spec) throws MalformedURLException {
41: try {
42: return new URL(spec);
43: } catch (MalformedURLException e) {
44: return new File(spec).toURL();
45: }
46: }
47:
48: public static boolean isEmpty(String str) {
49: if (str != null && str.trim().length() > 0) {
50: return false;
51: }
52: return true;
53: }
54: }
|