private File getFromIndex(final List<String> categories, final String key) throws IOException { final File index = getIndex(categories); synchronized (index.getAbsolutePath()) { final Properties properties = loadIndex(index); final String file = (String) properties.get(key); if (file == null) { return null; } return new File(getPath(categories, false) + File.separator + file); } }
private void addEntryToIndex(final List<String> categories, final String key, final String value) throws FileNotFoundException, IOException { final File index = getIndex(categories); synchronized (index.getAbsolutePath()) { final Properties properties = loadIndex(index); properties.setProperty(key, value); storeIndex(index, properties); } }
private void analysePath(final File dir, final Set<String> keys) throws FileNotFoundException, IOException { final File[] files = dir.listFiles(); if (files != null) { for (final File file : files) { if (file.isFile() && !file.getName().equals(INDEX_NAME)) { final File index = new File(dir.getAbsolutePath() + File.separator + INDEX_NAME); synchronized (index.getAbsolutePath()) { final Properties properties = loadIndex(index); for (final Entry<Object, Object> entry : properties.entrySet()) { if (entry.getValue().equals(file.getName())) { keys.add((String) entry.getKey()); } } } } else if (file.isDirectory()) { analysePath(file, keys); } } } }
private File removeFromIndex(final List<String> categories, final String key) throws IOException { final File index = getIndex(categories); synchronized (index.getAbsolutePath()) { final Properties properties = loadIndex(index); final String file = (String) properties.remove(key); storeIndex(index, properties); return new File(getPath(categories, false) + File.separator + file); } }
@Override public Set<String> getKeys(final List<String> categories, final String regex) { final File dir = getPath(categories, false); if (dir == null || !dir.exists()) { return Collections.emptySet(); } try { final File index = getIndex(categories); synchronized (index.getAbsolutePath()) { final Properties properties = loadIndex(index); final Enumeration<Object> keys = properties.keys(); final Set<String> result = new HashSet<String>(); while (keys.hasMoreElements()) { final String key = (String) keys.nextElement(); if (regex == null || key.matches(regex)) { result.add(key); } } return result; } } catch (final IOException e) { throw new BonitaRuntimeException(e); } }
@Override public <T> Map<String, T> getDataFromRegex(final Class<T> clazz, final List<String> categories, final String regex) { final File dir = getPath(categories, false); if (dir == null || !dir.exists()) { return Collections.emptyMap(); } try { final File index = getIndex(categories); synchronized (index.getAbsolutePath()) { final Properties properties = loadIndex(index); final Map<String, T> result = new HashMap<String, T>(); for (final Entry<Object, Object> entry : properties.entrySet()) { final String key = (String) entry.getKey(); final File f = new File(dir + File.separator + entry.getValue()); if (f.isFile() && (regex == null || key.matches(regex))) { result.put(key, getData(clazz, f)); } } return result; } } catch (final IOException e) { throw new BonitaRuntimeException(e); } }
@Override public <T> Map<String, T> getData(final Class<T> clazz, final List<String> categories, final Collection<String> keys) { if (keys == null) { return Collections.emptyMap(); } final File dir = getPath(categories, false); if (dir == null || !dir.exists()) { return Collections.emptyMap(); } try { final File index = getIndex(categories); synchronized (index.getAbsolutePath()) { final Properties properties = loadIndex(index); final Map<String, T> result = new HashMap<String, T>(); for (final Entry<Object, Object> entry : properties.entrySet()) { final String key = (String) entry.getKey(); if (keys.contains(key)) { final File f = new File(dir + File.separator + entry.getValue()); if (f.isFile()) { result.put(key, getData(clazz, f)); } } } return result; } } catch (final IOException e) { throw new BonitaRuntimeException(e); } }