@Test(expected = AccessDeniedException.class) public void testParseNotFound() throws Exception { new WinScpBookmarkCollection().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("[Sessions\\")) { current = new Host(protocols.forScheme(Scheme.sftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[Session\\\\(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else if(StringUtils.isBlank(line)) { this.add(current); current = null; } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } String value = scanner.next(); switch(name) { case "hostname": current.setHostname(value); break; case "username": current.getCredentials().setUsername(value); break; case "portnumber": try { current.setPort(Integer.parseInt(value)); } catch(NumberFormatException e) { log.warn("Invalid Port:" + e.getMessage()); } break; case "fsprotocol": try { switch(Integer.parseInt(value)) { case 0: case 1: case 2: current.setProtocol(protocols.forScheme(Scheme.sftp)); break; case 5: current.setProtocol(protocols.forScheme(Scheme.ftp)); break; } current.setPort(-1); } catch(NumberFormatException e) { log.warn("Unknown Protocol:" + e.getMessage()); } break; } } } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }
WinScpBookmarkCollection 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("[Sessions\\")) { current = new Host(protocols.forScheme(Scheme.sftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[Session\\\\(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else if(StringUtils.isBlank(line)) { this.add(current); current = null; } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } String value = scanner.next(); switch(name) { case "hostname": current.setHostname(value); break; case "username": current.getCredentials().setUsername(value); break; case "portnumber": try { current.setPort(Integer.parseInt(value)); } catch(NumberFormatException e) { log.warn("Invalid Port:" + e.getMessage()); } break; case "fsprotocol": try { switch(Integer.parseInt(value)) { case 0: case 1: case 2: current.setProtocol(protocols.forScheme(Scheme.sftp)); break; case 5: current.setProtocol(protocols.forScheme(Scheme.ftp)); break; } current.setPort(-1); } catch(NumberFormatException e) { log.warn("Unknown Protocol:" + e.getMessage()); } break; } } } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } } }
WinScpBookmarkCollection 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("[Sessions\\")) { current = new Host(protocols.forScheme(Scheme.sftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[Session\\\\(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else if(StringUtils.isBlank(line)) { this.add(current); current = null; } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } String value = scanner.next(); switch(name) { case "hostname": current.setHostname(value); break; case "username": current.getCredentials().setUsername(value); break; case "portnumber": try { current.setPort(Integer.parseInt(value)); } catch(NumberFormatException e) { log.warn("Invalid Port:" + e.getMessage()); } break; case "fsprotocol": try { switch(Integer.parseInt(value)) { case 0: case 1: case 2: current.setProtocol(protocols.forScheme(Scheme.sftp)); break; case 5: current.setProtocol(protocols.forScheme(Scheme.ftp)); break; } current.setPort(-1); } catch(NumberFormatException e) { log.warn("Unknown Protocol:" + e.getMessage()); } break; } } } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }  }
WinScpBookmarkCollection 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("[Sessions\\")) { current = new Host(protocols.forScheme(Scheme.sftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[Session\\\\(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else if(StringUtils.isBlank(line)) { this.add(current); current = null; } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } String value = scanner.next(); switch(name) { case "hostname": current.setHostname(value); break; case "username": current.getCredentials().setUsername(value); break; case "portnumber": try { current.setPort(Integer.parseInt(value)); } catch(NumberFormatException e) { log.warn("Invalid Port:" + e.getMessage()); } break; case "fsprotocol": try { switch(Integer.parseInt(value)) { case 0: case 1: case 2: current.setProtocol(protocols.forScheme(Scheme.sftp)); break; case 5: current.setProtocol(protocols.forScheme(Scheme.ftp)); break; } current.setPort(-1); } catch(NumberFormatException e) { log.warn("Unknown Protocol:" + e.getMessage()); } break; } } } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }  @Override String getBundleIdentifier(); @Override String getName(); @Override Local getFile(); }
WinScpBookmarkCollection 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("[Sessions\\")) { current = new Host(protocols.forScheme(Scheme.sftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[Session\\\\(.*)\\]"); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { current.setNickname(matcher.group(1)); } } else if(StringUtils.isBlank(line)) { this.add(current); current = null; } else { if(null == current) { log.warn("Failed to detect start of bookmark"); continue; } Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if(!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } String name = scanner.next().toLowerCase(Locale.ROOT); if(!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } String value = scanner.next(); switch(name) { case "hostname": current.setHostname(value); break; case "username": current.getCredentials().setUsername(value); break; case "portnumber": try { current.setPort(Integer.parseInt(value)); } catch(NumberFormatException e) { log.warn("Invalid Port:" + e.getMessage()); } break; case "fsprotocol": try { switch(Integer.parseInt(value)) { case 0: case 1: case 2: current.setProtocol(protocols.forScheme(Scheme.sftp)); break; case 5: current.setProtocol(protocols.forScheme(Scheme.ftp)); break; } current.setPort(-1); } catch(NumberFormatException e) { log.warn("Unknown Protocol:" + e.getMessage()); } break; } } } } catch(IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }  @Override String getBundleIdentifier(); @Override String getName(); @Override Local getFile();  }