@Test(expected = AccessDeniedException.class) public void testParseNotFound() throws Exception { new NetDrive2BookmarkCollection().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 JsonReader reader = new JsonReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8)); reader.beginArray(); String url; String user; boolean ssl; Protocol protocol; while(reader.hasNext()) { reader.beginObject(); boolean skip = false; url = null; ssl = false; protocol = null; user = null; while(reader.hasNext()) { final String name = reader.nextName(); switch(name) { case "url": url = this.readNext(name, reader); if(StringUtils.isBlank(url)) { skip = true; } break; case "ssl": ssl = reader.nextBoolean(); break; case "user": user = this.readNext(name, reader); break; case "type": final String type = this.readNext(name, reader); switch(type) { case "google_cloud_storage": protocol = protocols.forType(Protocol.Type.googlestorage); break; case "gdrive": protocol = protocols.forType(Protocol.Type.googledrive); break; default: protocol = protocols.forName(type); } break; default: log.warn(String.format("Ignore property %s", name)); reader.skipValue(); break; } } reader.endObject(); if(!skip && protocol != null && StringUtils.isNotBlank(user)) { if(ssl) { switch(protocol.getType()) { case ftp: protocol = protocols.forScheme(Scheme.ftps); break; case dav: protocol = protocols.forScheme(Scheme.davs); break; } } try { this.add(new HostParser(protocols, protocol).get(url)); } catch(HostParserException e) { log.warn(e); } } } reader.endArray(); } catch(IllegalStateException | IOException e) { throw new LocalAccessDeniedException(e.getMessage(), e); } }
NetDrive2BookmarkCollection extends JsonBookmarkCollection { @Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try { final JsonReader reader = new JsonReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8)); reader.beginArray(); String url; String user; boolean ssl; Protocol protocol; while(reader.hasNext()) { reader.beginObject(); boolean skip = false; url = null; ssl = false; protocol = null; user = null; while(reader.hasNext()) { final String name = reader.nextName(); switch(name) { case "url": url = this.readNext(name, reader); if(StringUtils.isBlank(url)) { skip = true; } break; case "ssl": ssl = reader.nextBoolean(); break; case "user": user = this.readNext(name, reader); break; case "type": final String type = this.readNext(name, reader); switch(type) { case "google_cloud_storage": protocol = protocols.forType(Protocol.Type.googlestorage); break; case "gdrive": protocol = protocols.forType(Protocol.Type.googledrive); break; default: protocol = protocols.forName(type); } break; default: log.warn(String.format("Ignore property %s", name)); reader.skipValue(); break; } } reader.endObject(); if(!skip && protocol != null && StringUtils.isNotBlank(user)) { if(ssl) { switch(protocol.getType()) { case ftp: protocol = protocols.forScheme(Scheme.ftps); break; case dav: protocol = protocols.forScheme(Scheme.davs); break; } } try { this.add(new HostParser(protocols, protocol).get(url)); } catch(HostParserException e) { log.warn(e); } } } reader.endArray(); } catch(IllegalStateException | IOException e) { throw new LocalAccessDeniedException(e.getMessage(), e); } } }
NetDrive2BookmarkCollection extends JsonBookmarkCollection { @Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try { final JsonReader reader = new JsonReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8)); reader.beginArray(); String url; String user; boolean ssl; Protocol protocol; while(reader.hasNext()) { reader.beginObject(); boolean skip = false; url = null; ssl = false; protocol = null; user = null; while(reader.hasNext()) { final String name = reader.nextName(); switch(name) { case "url": url = this.readNext(name, reader); if(StringUtils.isBlank(url)) { skip = true; } break; case "ssl": ssl = reader.nextBoolean(); break; case "user": user = this.readNext(name, reader); break; case "type": final String type = this.readNext(name, reader); switch(type) { case "google_cloud_storage": protocol = protocols.forType(Protocol.Type.googlestorage); break; case "gdrive": protocol = protocols.forType(Protocol.Type.googledrive); break; default: protocol = protocols.forName(type); } break; default: log.warn(String.format("Ignore property %s", name)); reader.skipValue(); break; } } reader.endObject(); if(!skip && protocol != null && StringUtils.isNotBlank(user)) { if(ssl) { switch(protocol.getType()) { case ftp: protocol = protocols.forScheme(Scheme.ftps); break; case dav: protocol = protocols.forScheme(Scheme.davs); break; } } try { this.add(new HostParser(protocols, protocol).get(url)); } catch(HostParserException e) { log.warn(e); } } } reader.endArray(); } catch(IllegalStateException | IOException e) { throw new LocalAccessDeniedException(e.getMessage(), e); } }  }
NetDrive2BookmarkCollection extends JsonBookmarkCollection { @Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try { final JsonReader reader = new JsonReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8)); reader.beginArray(); String url; String user; boolean ssl; Protocol protocol; while(reader.hasNext()) { reader.beginObject(); boolean skip = false; url = null; ssl = false; protocol = null; user = null; while(reader.hasNext()) { final String name = reader.nextName(); switch(name) { case "url": url = this.readNext(name, reader); if(StringUtils.isBlank(url)) { skip = true; } break; case "ssl": ssl = reader.nextBoolean(); break; case "user": user = this.readNext(name, reader); break; case "type": final String type = this.readNext(name, reader); switch(type) { case "google_cloud_storage": protocol = protocols.forType(Protocol.Type.googlestorage); break; case "gdrive": protocol = protocols.forType(Protocol.Type.googledrive); break; default: protocol = protocols.forName(type); } break; default: log.warn(String.format("Ignore property %s", name)); reader.skipValue(); break; } } reader.endObject(); if(!skip && protocol != null && StringUtils.isNotBlank(user)) { if(ssl) { switch(protocol.getType()) { case ftp: protocol = protocols.forScheme(Scheme.ftps); break; case dav: protocol = protocols.forScheme(Scheme.davs); break; } } try { this.add(new HostParser(protocols, protocol).get(url)); } catch(HostParserException e) { log.warn(e); } } } reader.endArray(); } catch(IllegalStateException | IOException e) { throw new LocalAccessDeniedException(e.getMessage(), e); } }  @Override String getName(); @Override String getBundleIdentifier(); @Override Local getFile(); }
NetDrive2BookmarkCollection extends JsonBookmarkCollection { @Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try { final JsonReader reader = new JsonReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8)); reader.beginArray(); String url; String user; boolean ssl; Protocol protocol; while(reader.hasNext()) { reader.beginObject(); boolean skip = false; url = null; ssl = false; protocol = null; user = null; while(reader.hasNext()) { final String name = reader.nextName(); switch(name) { case "url": url = this.readNext(name, reader); if(StringUtils.isBlank(url)) { skip = true; } break; case "ssl": ssl = reader.nextBoolean(); break; case "user": user = this.readNext(name, reader); break; case "type": final String type = this.readNext(name, reader); switch(type) { case "google_cloud_storage": protocol = protocols.forType(Protocol.Type.googlestorage); break; case "gdrive": protocol = protocols.forType(Protocol.Type.googledrive); break; default: protocol = protocols.forName(type); } break; default: log.warn(String.format("Ignore property %s", name)); reader.skipValue(); break; } } reader.endObject(); if(!skip && protocol != null && StringUtils.isNotBlank(user)) { if(ssl) { switch(protocol.getType()) { case ftp: protocol = protocols.forScheme(Scheme.ftps); break; case dav: protocol = protocols.forScheme(Scheme.davs); break; } } try { this.add(new HostParser(protocols, protocol).get(url)); } catch(HostParserException e) { log.warn(e); } } } reader.endArray(); } catch(IllegalStateException | IOException e) { throw new LocalAccessDeniedException(e.getMessage(), e); } }  @Override String getName(); @Override String getBundleIdentifier(); @Override Local getFile();  }