@Test public void testLoad() throws Exception { final Local source = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); LocalTouchFactory.get().touch(source); IOUtils.write(new RandomStringGenerator.Builder().build().generate(1000), source.getOutputStream(false), Charset.defaultCharset()); final AtomicBoolean r = new AtomicBoolean(); final ThirdpartyBookmarkCollection c = new ThirdpartyBookmarkCollection() { @Override public String getName() { return StringUtils.EMPTY; } @Override public Local getFile() { return source; } @Override protected void parse(final ProtocolFactory protocols, final Local file) { this.add(new Host(new TestProtocol())); r.set(true); } @Override public String getBundleIdentifier() { return "t"; } }; c.load(); assertTrue(r.get()); assertEquals(0, c.iterator().next().compareTo(new Host(new TestProtocol()))); r.set(false); PreferencesFactory.get().setProperty(c.getConfiguration(), true); c.load(); assertFalse(r.get()); AbstractHostCollection bookmarks = new AbstractHostCollection() { }; bookmarks.add(new Host(new TestProtocol())); c.filter(bookmarks); assertTrue(c.isEmpty()); }
@Override public void load() throws AccessDeniedException { final Local file = this.getFile(); if(file.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Found bookmarks file at %s", file)); } Checksum current = Checksum.NONE; if(file.isFile()) { try { current = ChecksumComputeFactory.get(HashAlgorithm.md5).compute(file.getInputStream(), new TransferStatus()); if(log.isDebugEnabled()) { log.debug(String.format("Current checksum for %s is %s", file, current)); } } catch(BackgroundException e) { log.warn(String.format("Failure obtaining checksum for %s", file)); } } if(preferences.getBoolean(this.getConfiguration())) { final Checksum previous = new Checksum(HashAlgorithm.md5, preferences.getProperty(String.format("%s.checksum", this.getConfiguration()))); if(log.isDebugEnabled()) { log.debug(String.format("Saved previous checksum %s for bookmark %s", previous, file)); } if(StringUtils.isNotBlank(previous.hash)) { if(previous.equals(current)) { if(log.isInfoEnabled()) { log.info(String.format("Skip importing bookmarks from %s with previously saved checksum %s", file, previous)); } } else { if(log.isInfoEnabled()) { log.info(String.format("Checksum changed for bookmarks file at %s", file)); } } } else { if(log.isDebugEnabled()) { log.debug(String.format("Skip importing bookmarks from %s", file)); } } } else { this.parse(ProtocolFactory.get(), file); } if(current != null) { preferences.setProperty(String.format("%s.checksum", this.getConfiguration()), current.hash); } } else { if(log.isInfoEnabled()) { log.info(String.format("No bookmarks file at %s", file)); } } super.load(); }
ThirdpartyBookmarkCollection extends Collection<Host> { @Override public void load() throws AccessDeniedException { final Local file = this.getFile(); if(file.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Found bookmarks file at %s", file)); } Checksum current = Checksum.NONE; if(file.isFile()) { try { current = ChecksumComputeFactory.get(HashAlgorithm.md5).compute(file.getInputStream(), new TransferStatus()); if(log.isDebugEnabled()) { log.debug(String.format("Current checksum for %s is %s", file, current)); } } catch(BackgroundException e) { log.warn(String.format("Failure obtaining checksum for %s", file)); } } if(preferences.getBoolean(this.getConfiguration())) { final Checksum previous = new Checksum(HashAlgorithm.md5, preferences.getProperty(String.format("%s.checksum", this.getConfiguration()))); if(log.isDebugEnabled()) { log.debug(String.format("Saved previous checksum %s for bookmark %s", previous, file)); } if(StringUtils.isNotBlank(previous.hash)) { if(previous.equals(current)) { if(log.isInfoEnabled()) { log.info(String.format("Skip importing bookmarks from %s with previously saved checksum %s", file, previous)); } } else { if(log.isInfoEnabled()) { log.info(String.format("Checksum changed for bookmarks file at %s", file)); } } } else { if(log.isDebugEnabled()) { log.debug(String.format("Skip importing bookmarks from %s", file)); } } } else { this.parse(ProtocolFactory.get(), file); } if(current != null) { preferences.setProperty(String.format("%s.checksum", this.getConfiguration()), current.hash); } } else { if(log.isInfoEnabled()) { log.info(String.format("No bookmarks file at %s", file)); } } super.load(); } }
ThirdpartyBookmarkCollection extends Collection<Host> { @Override public void load() throws AccessDeniedException { final Local file = this.getFile(); if(file.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Found bookmarks file at %s", file)); } Checksum current = Checksum.NONE; if(file.isFile()) { try { current = ChecksumComputeFactory.get(HashAlgorithm.md5).compute(file.getInputStream(), new TransferStatus()); if(log.isDebugEnabled()) { log.debug(String.format("Current checksum for %s is %s", file, current)); } } catch(BackgroundException e) { log.warn(String.format("Failure obtaining checksum for %s", file)); } } if(preferences.getBoolean(this.getConfiguration())) { final Checksum previous = new Checksum(HashAlgorithm.md5, preferences.getProperty(String.format("%s.checksum", this.getConfiguration()))); if(log.isDebugEnabled()) { log.debug(String.format("Saved previous checksum %s for bookmark %s", previous, file)); } if(StringUtils.isNotBlank(previous.hash)) { if(previous.equals(current)) { if(log.isInfoEnabled()) { log.info(String.format("Skip importing bookmarks from %s with previously saved checksum %s", file, previous)); } } else { if(log.isInfoEnabled()) { log.info(String.format("Checksum changed for bookmarks file at %s", file)); } } } else { if(log.isDebugEnabled()) { log.debug(String.format("Skip importing bookmarks from %s", file)); } } } else { this.parse(ProtocolFactory.get(), file); } if(current != null) { preferences.setProperty(String.format("%s.checksum", this.getConfiguration()), current.hash); } } else { if(log.isInfoEnabled()) { log.info(String.format("No bookmarks file at %s", file)); } } super.load(); } ThirdpartyBookmarkCollection();  ThirdpartyBookmarkCollection(final PasswordStore keychain); }
ThirdpartyBookmarkCollection extends Collection<Host> { @Override public void load() throws AccessDeniedException { final Local file = this.getFile(); if(file.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Found bookmarks file at %s", file)); } Checksum current = Checksum.NONE; if(file.isFile()) { try { current = ChecksumComputeFactory.get(HashAlgorithm.md5).compute(file.getInputStream(), new TransferStatus()); if(log.isDebugEnabled()) { log.debug(String.format("Current checksum for %s is %s", file, current)); } } catch(BackgroundException e) { log.warn(String.format("Failure obtaining checksum for %s", file)); } } if(preferences.getBoolean(this.getConfiguration())) { final Checksum previous = new Checksum(HashAlgorithm.md5, preferences.getProperty(String.format("%s.checksum", this.getConfiguration()))); if(log.isDebugEnabled()) { log.debug(String.format("Saved previous checksum %s for bookmark %s", previous, file)); } if(StringUtils.isNotBlank(previous.hash)) { if(previous.equals(current)) { if(log.isInfoEnabled()) { log.info(String.format("Skip importing bookmarks from %s with previously saved checksum %s", file, previous)); } } else { if(log.isInfoEnabled()) { log.info(String.format("Checksum changed for bookmarks file at %s", file)); } } } else { if(log.isDebugEnabled()) { log.debug(String.format("Skip importing bookmarks from %s", file)); } } } else { this.parse(ProtocolFactory.get(), file); } if(current != null) { preferences.setProperty(String.format("%s.checksum", this.getConfiguration()), current.hash); } } else { if(log.isInfoEnabled()) { log.info(String.format("No bookmarks file at %s", file)); } } super.load(); } ThirdpartyBookmarkCollection();  ThirdpartyBookmarkCollection(final PasswordStore keychain); @Override void load(); abstract String getName(); abstract Local getFile(); boolean isInstalled(); abstract String getBundleIdentifier(); String getConfiguration(); @Override boolean add(final Host bookmark); void filter(final AbstractHostCollection bookmarks); @Override String toString(); }
ThirdpartyBookmarkCollection extends Collection<Host> { @Override public void load() throws AccessDeniedException { final Local file = this.getFile(); if(file.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Found bookmarks file at %s", file)); } Checksum current = Checksum.NONE; if(file.isFile()) { try { current = ChecksumComputeFactory.get(HashAlgorithm.md5).compute(file.getInputStream(), new TransferStatus()); if(log.isDebugEnabled()) { log.debug(String.format("Current checksum for %s is %s", file, current)); } } catch(BackgroundException e) { log.warn(String.format("Failure obtaining checksum for %s", file)); } } if(preferences.getBoolean(this.getConfiguration())) { final Checksum previous = new Checksum(HashAlgorithm.md5, preferences.getProperty(String.format("%s.checksum", this.getConfiguration()))); if(log.isDebugEnabled()) { log.debug(String.format("Saved previous checksum %s for bookmark %s", previous, file)); } if(StringUtils.isNotBlank(previous.hash)) { if(previous.equals(current)) { if(log.isInfoEnabled()) { log.info(String.format("Skip importing bookmarks from %s with previously saved checksum %s", file, previous)); } } else { if(log.isInfoEnabled()) { log.info(String.format("Checksum changed for bookmarks file at %s", file)); } } } else { if(log.isDebugEnabled()) { log.debug(String.format("Skip importing bookmarks from %s", file)); } } } else { this.parse(ProtocolFactory.get(), file); } if(current != null) { preferences.setProperty(String.format("%s.checksum", this.getConfiguration()), current.hash); } } else { if(log.isInfoEnabled()) { log.info(String.format("No bookmarks file at %s", file)); } } super.load(); } ThirdpartyBookmarkCollection();  ThirdpartyBookmarkCollection(final PasswordStore keychain); @Override void load(); abstract String getName(); abstract Local getFile(); boolean isInstalled(); abstract String getBundleIdentifier(); String getConfiguration(); @Override boolean add(final Host bookmark); void filter(final AbstractHostCollection bookmarks); @Override String toString();  }