/** * Replace the Extension of the file * @param name * @param newExtension * @return the new file name */ public static String replaceExtension(String name, String newExtension) { if (name == null || newExtension == null) return name; return MString.beforeLastIndex(name, '.') + "." + newExtension; }
public static String getFileDirectory(String path) { if (path == null) return null; if (MString.isIndex(path, "/")) { String ret = MString.beforeLastIndex(path, "/"); while (ret.endsWith("/")) ret = ret.substring(0, ret.length()-1); if (ret.length() == 0) return null; return ret; } return null; }
/** * Returns the directory without file name or current directory. * /dir/subdir/file will return /dir/subdir * @param path * @return The previous directory name or null */ public static String getFileDirectory(String path) { if (path == null) return null; if (MString.isIndex(path, File.separatorChar)) { String ret = MString.beforeLastIndex(path, File.separatorChar); while (ret.endsWith(""+File.separatorChar)) ret = ret.substring(0, ret.length()-1); if (ret.length() == 0) return null; return ret; } return null; }
/** * Returns the name without path and extension. * * @param key * @return file name */ public static String getFileNameOnly(String key) { if (key == null) return null; if (key.indexOf('/') >= 0) key = MString.afterLastIndex(key, '/'); if (key.indexOf('\\') >= 0) key = MString.afterLastIndex(key, '\\'); if (key.length() > 1 && key.indexOf('.',1) >= 0) key = MString.beforeLastIndex(key, '.'); return key; }
@SuppressWarnings("unchecked") protected void init() { Bundle bundle = FrameworkUtil.getBundle(process.getClass()); LinkedList<String> classNames = new LinkedList<>(); // TODO iterate and parse .... like DefaultProcesLoader String start = process.getClass().getPackage().getName().replace('.', '/'); Enumeration<URL> enu = bundle.findEntries(start, "*.class", true); while (enu.hasMoreElements()) { URL url = enu.nextElement(); String name = url.getPath(); if (name.endsWith(".class") && name.indexOf('$') < 0) { if (name.startsWith("/")) name = name.substring(1); classNames.add(MString.beforeLastIndex(name,'.').replace('/', '.')); } } // load class and test if it's Element for (String name : classNames) { try { Class<?> clazz = bundle.loadClass(name); if (AElement.class.isAssignableFrom(clazz)) elementClasses.add((Class<? extends AElement<?>>) clazz); } catch (Throwable t) { log().w(name,t); } } }
time = MString.beforeLastIndex(time, '.');