@Test public void testFindByFilename() { ApplicationFinder f = new LaunchServicesApplicationFinder(); assertEquals(new Application("com.apple.Preview", "Preview"), f.find("file.png")); assertEquals(Application.notfound, f.find("file.txt_")); }
@Override public Application find(final String filename) { final String extension = Path.getExtension(filename); if(!defaultApplicationCache.contains(extension)) { if(StringUtils.isEmpty(extension)) { return Application.notfound; } final String path = this.findForType(extension); if(StringUtils.isEmpty(path)) { defaultApplicationCache.put(extension, Application.notfound); } else { final NSBundle bundle = NSBundle.bundleWithPath(path); if(null == bundle) { log.error(String.format("Loading bundle %s failed", path)); defaultApplicationCache.put(extension, Application.notfound); } else { defaultApplicationCache.put(extension, this.getDescription(bundle.bundleIdentifier())); } } } return defaultApplicationCache.get(extension); }
LaunchServicesApplicationFinder implements ApplicationFinder { @Override public Application find(final String filename) { final String extension = Path.getExtension(filename); if(!defaultApplicationCache.contains(extension)) { if(StringUtils.isEmpty(extension)) { return Application.notfound; } final String path = this.findForType(extension); if(StringUtils.isEmpty(path)) { defaultApplicationCache.put(extension, Application.notfound); } else { final NSBundle bundle = NSBundle.bundleWithPath(path); if(null == bundle) { log.error(String.format("Loading bundle %s failed", path)); defaultApplicationCache.put(extension, Application.notfound); } else { defaultApplicationCache.put(extension, this.getDescription(bundle.bundleIdentifier())); } } } return defaultApplicationCache.get(extension); } }
LaunchServicesApplicationFinder implements ApplicationFinder { @Override public Application find(final String filename) { final String extension = Path.getExtension(filename); if(!defaultApplicationCache.contains(extension)) { if(StringUtils.isEmpty(extension)) { return Application.notfound; } final String path = this.findForType(extension); if(StringUtils.isEmpty(path)) { defaultApplicationCache.put(extension, Application.notfound); } else { final NSBundle bundle = NSBundle.bundleWithPath(path); if(null == bundle) { log.error(String.format("Loading bundle %s failed", path)); defaultApplicationCache.put(extension, Application.notfound); } else { defaultApplicationCache.put(extension, this.getDescription(bundle.bundleIdentifier())); } } } return defaultApplicationCache.get(extension); } LaunchServicesApplicationFinder(); }
LaunchServicesApplicationFinder implements ApplicationFinder { @Override public Application find(final String filename) { final String extension = Path.getExtension(filename); if(!defaultApplicationCache.contains(extension)) { if(StringUtils.isEmpty(extension)) { return Application.notfound; } final String path = this.findForType(extension); if(StringUtils.isEmpty(path)) { defaultApplicationCache.put(extension, Application.notfound); } else { final NSBundle bundle = NSBundle.bundleWithPath(path); if(null == bundle) { log.error(String.format("Loading bundle %s failed", path)); defaultApplicationCache.put(extension, Application.notfound); } else { defaultApplicationCache.put(extension, this.getDescription(bundle.bundleIdentifier())); } } } return defaultApplicationCache.get(extension); } LaunchServicesApplicationFinder(); @Override List<Application> findAll(final String filename); @Override Application find(final String filename); @Override Application getDescription(final String search); @Override boolean isInstalled(final Application application); boolean register(final Local application); }
LaunchServicesApplicationFinder implements ApplicationFinder { @Override public Application find(final String filename) { final String extension = Path.getExtension(filename); if(!defaultApplicationCache.contains(extension)) { if(StringUtils.isEmpty(extension)) { return Application.notfound; } final String path = this.findForType(extension); if(StringUtils.isEmpty(path)) { defaultApplicationCache.put(extension, Application.notfound); } else { final NSBundle bundle = NSBundle.bundleWithPath(path); if(null == bundle) { log.error(String.format("Loading bundle %s failed", path)); defaultApplicationCache.put(extension, Application.notfound); } else { defaultApplicationCache.put(extension, this.getDescription(bundle.bundleIdentifier())); } } } return defaultApplicationCache.get(extension); } LaunchServicesApplicationFinder(); @Override List<Application> findAll(final String filename); @Override Application find(final String filename); @Override Application getDescription(final String search); @Override boolean isInstalled(final Application application); boolean register(final Local application);  }