List of usage examples for org.apache.commons.io FilenameUtils isExtension
public static boolean isExtension(String filename, Collection<String> extensions)
From source file:org.nickelproject.util.testUtil.ClasspathUtil.java
private static Predicate<String> getHasExtension(final String pExtension) { return new Predicate<String>() { @Override/* w ww .j a va 2s .c o m*/ public boolean apply(final String pName) { return FilenameUtils.isExtension(pName, pExtension); } }; }
From source file:org.o3project.odenos.core.util.ComponentLoader.java
private static boolean isClassFile(final File file) { String filename = file.getName(); return FilenameUtils.isExtension(filename, "class"); }
From source file:org.openflexo.technologyadapter.jdbc.rm.JDBCResourceFactory.java
@Override public <I> boolean isValidArtefact(I serializationArtefact, FlexoResourceCenter<I> resourceCenter) { String name = resourceCenter.retrieveName(serializationArtefact); return FilenameUtils.isExtension(name, JDBC_EXTENSION); }
From source file:org.openmicroscopy.shoola.env.Container.java
/** * Initializes the member fields. /*from w w w .j av a2 s . co m*/ * <p>The absolute path to the installation directory is obtained from * <code>home</code>. If this parameter doesn't specify an absolute path, * then it'll be translated into an absolute path. Translation is system * dependent -- in many cases, the path is resolved against the user * directory (typically the directory in which the JVM was invoked).</p> * * @param home Path to the installation directory. If <code>null</code> or * empty, then the user directory is assumed. * @param configFile The configuration file. * @throws StartupException If <code>home</code> can't be resolved to a * valid and existing directory. */ private Container(String home, String configFile) throws StartupException { if (CommonsLangUtils.isBlank(configFile) || !FilenameUtils.isExtension(configFile, "xml")) configFile = CONFIG_FILE; this.configFile = configFile; if (CommonsLangUtils.isBlank(FilenameUtils.getPath(home))) home = System.getProperty("user.dir"); File f = new File(home); //Now make it absolute. If the original path wasn't absolute, then //translation is system dependent. f = f.getAbsoluteFile(); homeDir = f.getAbsolutePath(); //Make sure that what we've got is a directory. if (!f.exists() || !f.isDirectory()) throw new StartupException("Can't locate home dir: " + homeDir); agentsPool = new HashSet<Agent>(); registry = RegistryFactory.makeNew(); }
From source file:org.opoo.press.converter.AbstractWikiTextConverter.java
@Override public boolean matches(Source src) { String name = src.getSourceEntry().getName().toLowerCase(); String[] extensions = getInputFileExtensions(); if (extensions.length == 1) { return FilenameUtils.isExtension(name, extensions[0]); }//from ww w . j a v a 2 s. com return FilenameUtils.isExtension(name, extensions); }
From source file:org.opoo.press.converter.TextilejConverter.java
@Override public boolean matches(Source src) { String name = src.getSourceEntry().getName().toLowerCase(); if (FilenameUtils.isExtension(name, "textile")) { return true; }/*ww w . j a va2s .c om*/ return false; }
From source file:org.opoo.press.converter.TxtmarkMarkdownConverter.java
@Override public boolean matches(Source src) { String name = src.getSourceEntry().getName().toLowerCase(); if (FilenameUtils.isExtension(name, new String[] { "markdown", "md" })) { return true; }// w ww .j a va 2 s . co m if ("post".equals(src.getMeta().get("layout")) && FilenameUtils.isExtension(name, "txt")) { return true; } return false; }
From source file:org.opoo.press.impl.ConfigImpl.java
/** * @param file/*from w ww.ja v a 2 s . c om*/ */ @SuppressWarnings("unchecked") private void loadConfigFromFile(File file) { String name = file.getName(); InputStream inputStream = null; Map<String, Object> map = null; try { inputStream = FileUtils.openInputStream(file); if (FilenameUtils.isExtension(name, "json")) { if (objectMapper == null) { objectMapper = new ObjectMapper(); } map = objectMapper.readValue(inputStream, Map.class); } else { //yaml is not thread safe, so create new instance map = new Yaml().loadAs(inputStream, Map.class); } } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(inputStream); } if (map != null) { log.debug("Config loaded: {}", map); putAll(map); } }
From source file:org.orbisgis.core.plugin.BundleTools.java
/** * Register in the host bundle the provided list of bundle reference * @param hostBundle Host BundleContext//from w w w . j av a 2 s.c o m * @param nonDefaultBundleDeploying Bundle Reference array to deploy bundles in a non default way (install&start) */ public static void installBundles(BundleContext hostBundle, BundleReference[] nonDefaultBundleDeploying) { //Create a Map of nonDefaultBundleDeploying by their artifactId Map<String, BundleReference> customDeployBundles = new HashMap<String, BundleReference>( nonDefaultBundleDeploying.length); for (BundleReference ref : nonDefaultBundleDeploying) { customDeployBundles.put(ref.getArtifactId(), ref); } // List bundles in the /bundle subdirectory File bundleFolder = new File(BUNDLE_DIRECTORY); if (!bundleFolder.exists()) { return; } File[] files = bundleFolder.listFiles(); List<File> jarList = new ArrayList<File>(); if (files != null) { for (File file : files) { if (FilenameUtils.isExtension(file.getName(), "jar")) { jarList.add(file); } } } if (!jarList.isEmpty()) { Map<String, Bundle> installedBundleMap = new HashMap<String, Bundle>(); // Keep a reference to bundles in the framework cache for (Bundle bundle : hostBundle.getBundles()) { String key = bundle.getSymbolicName() + "_" + bundle.getVersion(); installedBundleMap.put(key, bundle); } // final List<Bundle> installedBundleList = new LinkedList<Bundle>(); for (File jarFile : jarList) { // Extract version and symbolic name of the bundle String key = ""; try { List<PackageDeclaration> packageDeclarations = new ArrayList<PackageDeclaration>(); BundleReference jarRef = parseJarManifest(jarFile, packageDeclarations); key = jarRef.getArtifactId() + "_" + jarRef.getVersion(); } catch (IOException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); } // Retrieve from the framework cache the bundle at this location Bundle b = installedBundleMap.remove(key); // Read Jar manifest without installing it BundleReference reference = new BundleReference(""); // Default deploy try { JarFile jar = new JarFile(jarFile); Manifest manifest = jar.getManifest(); if (manifest != null && manifest.getMainAttributes() != null) { String artifact = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); BundleReference customRef = customDeployBundles.get(artifact); if (customRef != null) { reference = customRef; } } } catch (Exception ex) { LOGGER.error(I18N.tr("Could not read bundle manifest"), ex); } try { if (b != null) { String installedBundleLocation = b.getLocation(); if (!installedBundleLocation.equals(jarFile.toURI().toString())) { //if the location is not the same reinstall it b.uninstall(); b = null; } } // If the bundle is not in the framework cache install it if ((b == null) && reference.isAutoInstall()) { b = hostBundle.installBundle(jarFile.toURI().toString()); if (!isFragment(b) && reference.isAutoStart()) { installedBundleList.add(b); } } else if ((b != null)) { b.update(); } } catch (BundleException ex) { LOGGER.error("Error while installing bundle in bundle directory", ex); } } // Start new bundles for (Bundle bundle : installedBundleList) { try { bundle.start(); } catch (BundleException ex) { LOGGER.error("Error while starting bundle in bundle directory", ex); } } } }
From source file:org.orbisgis.framework.BundleTools.java
/** * Delete OSGi fragment bundles that are both in OSGi cache and in bundle sub-dir * @param bundleCache OSGi bundle cache ex: ~/.Orbisgis/4.X/cache/ *//*w w w . java2 s . co m*/ public void deleteFragmentInCache(File bundleCache) { if (bundleCache.exists()) { // List bundles in the /bundle subdirectory File bundleFolder = new File(BUNDLE_DIRECTORY); if (!bundleFolder.exists()) { return; } File[] files = bundleFolder.listFiles(); if (files != null) { List<String> fragmentBundlesArtifacts = new ArrayList<>(files.length); // Search for Fragment in /bundle/ subdir for (File file : files) { if (FilenameUtils.isExtension(file.getName(), "jar")) { // Read Manifest try (JarFile jar = new JarFile(file)) { Manifest manifest = jar.getManifest(); if (manifest != null && manifest.getMainAttributes() != null) { String artifact = manifest.getMainAttributes().getValue(Constants.FRAGMENT_HOST); if (artifact != null) { fragmentBundlesArtifacts.add(parseManifest(manifest, null).getArtifactId()); } } } catch (IOException ex) { LOGGER.log(Logger.LOG_ERROR, "Error while reading Jar manifest:\n" + file.getPath()); } } } // Remove folders in bundle cache that contain a fragment cache File[] cacheFolders = bundleCache.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); if (cacheFolders != null) { for (File folder : cacheFolders) { try { // Get the first folder, may contain only one ex:"version0.0" File[] cacheBundleFolder = folder.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); if (cacheBundleFolder != null && cacheBundleFolder.length > 0) { // Read Jar manifest File jarBundle = new File(cacheBundleFolder[0], "bundle.jar"); if (jarBundle.exists()) { // Read artifact String artifact = parseJarManifest(jarBundle, null).getArtifactId(); if (fragmentBundlesArtifacts.contains(artifact)) { // Delete the cache folder int tryCount = 0; while (tryCount < DELETE_TRY_COUNT) { try { if (jarBundle.delete()) { FileUtils.deleteDirectory(folder); } else { throw new IOException("Could not delete jar file"); } break; } catch (IOException ex) { tryCount++; try { Thread.sleep(WAIT_RETRY_DELETE); } catch (InterruptedException iex) { break; } } } if (folder.exists()) { LOGGER.log(Logger.LOG_ERROR, "Cannot delete a bundle cache folder, library may not be up to" + " date, please delete the following folder and restart OrbisGIS:" + "\n" + folder.getPath()); } else { LOGGER.log(Logger.LOG_INFO, I18N.tr("Delete fragment bundle {0} in " + "cache directory", artifact)); } } } } } catch (IOException ex) { LOGGER.log(Logger.LOG_ERROR, "Error while reading Jar manifest:\n" + folder.getPath(), ex); } } } } } }