@Test(expected = AccessDeniedException.class) public void testParseNotFound() throws Exception { new TotalCommanderBookmarkCollection().parse(new ProtocolFactory(Collections.emptySet()), new Local(System.getProperty("java.io.tmpdir"), "f")); }
@Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try (final BufferedReader in = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { Host current = null; String line; while((line = in.readLine()) != null) { if(line.startsWith("[")) { if(current != null) { this.add(current); } current = new Host(protocols.forScheme(Scheme.ftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } final Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } final String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } final String value = scanner.next(); switch(name) { case "host": current.setHostname(value); break; case "directory": current.setDefaultPath(value); break; case "username": current.getCredentials().setUsername(value); break; default: log.warn(String.format("Ignore property %s", name)); break; } } } if(current != null) { this.add(current); } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }
TotalCommanderBookmarkCollection extends ThirdpartyBookmarkCollection { @Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try (final BufferedReader in = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { Host current = null; String line; while((line = in.readLine()) != null) { if(line.startsWith("[")) { if(current != null) { this.add(current); } current = new Host(protocols.forScheme(Scheme.ftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } final Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } final String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } final String value = scanner.next(); switch(name) { case "host": current.setHostname(value); break; case "directory": current.setDefaultPath(value); break; case "username": current.getCredentials().setUsername(value); break; default: log.warn(String.format("Ignore property %s", name)); break; } } } if(current != null) { this.add(current); } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } } }
TotalCommanderBookmarkCollection extends ThirdpartyBookmarkCollection { @Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try (final BufferedReader in = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { Host current = null; String line; while((line = in.readLine()) != null) { if(line.startsWith("[")) { if(current != null) { this.add(current); } current = new Host(protocols.forScheme(Scheme.ftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } final Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } final String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } final String value = scanner.next(); switch(name) { case "host": current.setHostname(value); break; case "directory": current.setDefaultPath(value); break; case "username": current.getCredentials().setUsername(value); break; default: log.warn(String.format("Ignore property %s", name)); break; } } } if(current != null) { this.add(current); } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }  }
TotalCommanderBookmarkCollection extends ThirdpartyBookmarkCollection { @Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try (final BufferedReader in = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { Host current = null; String line; while((line = in.readLine()) != null) { if(line.startsWith("[")) { if(current != null) { this.add(current); } current = new Host(protocols.forScheme(Scheme.ftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } final Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } final String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } final String value = scanner.next(); switch(name) { case "host": current.setHostname(value); break; case "directory": current.setDefaultPath(value); break; case "username": current.getCredentials().setUsername(value); break; default: log.warn(String.format("Ignore property %s", name)); break; } } } if(current != null) { this.add(current); } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }  @Override String getBundleIdentifier(); @Override String getName(); @Override Local getFile(); @Override boolean add(final Host bookmark); }
TotalCommanderBookmarkCollection extends ThirdpartyBookmarkCollection { @Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try (final BufferedReader in = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { Host current = null; String line; while((line = in.readLine()) != null) { if(line.startsWith("[")) { if(current != null) { this.add(current); } current = new Host(protocols.forScheme(Scheme.ftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } final Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } final String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } final String value = scanner.next(); switch(name) { case "host": current.setHostname(value); break; case "directory": current.setDefaultPath(value); break; case "username": current.getCredentials().setUsername(value); break; default: log.warn(String.format("Ignore property %s", name)); break; } } } if(current != null) { this.add(current); } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }  @Override String getBundleIdentifier(); @Override String getName(); @Override Local getFile(); @Override boolean add(final Host bookmark);  }