@Test public void testFindDirectory() throws Exception { final Path test = new DAVDirectoryFeature(session).mkdir(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null, new TransferStatus()); final DAVAttributesFinderFeature f = new DAVAttributesFinderFeature(session); final PathAttributes attributes = f.find(test); assertEquals(-1, attributes.getSize()); assertNotEquals(-1L, attributes.getModificationDate()); assertNotNull(attributes.getETag()); try { f.find(new Path("/trunk", EnumSet.of(Path.Type.file))); fail(); } catch(NotfoundException e) { } session.close(); }
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { try { for(final DavResource resource : this.list(file)) { if(resource.isDirectory()) { if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } else { if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } return this.toAttributes(resource); } throw new NotfoundException(file.getAbsolute()); } catch(SardineException e) { try { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(InteroperabilityException i) { log.warn(String.format("Failure with PROPFIND request for %s. %s", file, i.getMessage())); final Map<String, String> headers = session.getClient().execute( new HttpHead(new DAVPathEncoder().encode(file)), new HeadersResponseHandler()); final PathAttributes attributes = new PathAttributes(); try { attributes.setModificationDate(rfc1123.parse(headers.get(HttpHeaders.LAST_MODIFIED)).getTime()); } catch(InvalidDateException p) { log.warn(String.format("%s is not RFC 1123 format %s", headers.get(HttpHeaders.LAST_MODIFIED), p.getMessage())); } if(!headers.containsKey(HttpHeaders.CONTENT_ENCODING)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(headers.get(HttpHeaders.ETAG)); } if(headers.containsKey(HttpHeaders.CONTENT_MD5)) { attributes.setChecksum(Checksum.parse(headers.get(HttpHeaders.CONTENT_MD5))); } return attributes; } } } catch(SardineException e) { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, file); } }
DAVAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { try { for(final DavResource resource : this.list(file)) { if(resource.isDirectory()) { if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } else { if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } return this.toAttributes(resource); } throw new NotfoundException(file.getAbsolute()); } catch(SardineException e) { try { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(InteroperabilityException i) { log.warn(String.format("Failure with PROPFIND request for %s. %s", file, i.getMessage())); final Map<String, String> headers = session.getClient().execute( new HttpHead(new DAVPathEncoder().encode(file)), new HeadersResponseHandler()); final PathAttributes attributes = new PathAttributes(); try { attributes.setModificationDate(rfc1123.parse(headers.get(HttpHeaders.LAST_MODIFIED)).getTime()); } catch(InvalidDateException p) { log.warn(String.format("%s is not RFC 1123 format %s", headers.get(HttpHeaders.LAST_MODIFIED), p.getMessage())); } if(!headers.containsKey(HttpHeaders.CONTENT_ENCODING)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(headers.get(HttpHeaders.ETAG)); } if(headers.containsKey(HttpHeaders.CONTENT_MD5)) { attributes.setChecksum(Checksum.parse(headers.get(HttpHeaders.CONTENT_MD5))); } return attributes; } } } catch(SardineException e) { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, file); } } }
DAVAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { try { for(final DavResource resource : this.list(file)) { if(resource.isDirectory()) { if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } else { if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } return this.toAttributes(resource); } throw new NotfoundException(file.getAbsolute()); } catch(SardineException e) { try { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(InteroperabilityException i) { log.warn(String.format("Failure with PROPFIND request for %s. %s", file, i.getMessage())); final Map<String, String> headers = session.getClient().execute( new HttpHead(new DAVPathEncoder().encode(file)), new HeadersResponseHandler()); final PathAttributes attributes = new PathAttributes(); try { attributes.setModificationDate(rfc1123.parse(headers.get(HttpHeaders.LAST_MODIFIED)).getTime()); } catch(InvalidDateException p) { log.warn(String.format("%s is not RFC 1123 format %s", headers.get(HttpHeaders.LAST_MODIFIED), p.getMessage())); } if(!headers.containsKey(HttpHeaders.CONTENT_ENCODING)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(headers.get(HttpHeaders.ETAG)); } if(headers.containsKey(HttpHeaders.CONTENT_MD5)) { attributes.setChecksum(Checksum.parse(headers.get(HttpHeaders.CONTENT_MD5))); } return attributes; } } } catch(SardineException e) { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, file); } } DAVAttributesFinderFeature(DAVSession session); }
DAVAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { try { for(final DavResource resource : this.list(file)) { if(resource.isDirectory()) { if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } else { if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } return this.toAttributes(resource); } throw new NotfoundException(file.getAbsolute()); } catch(SardineException e) { try { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(InteroperabilityException i) { log.warn(String.format("Failure with PROPFIND request for %s. %s", file, i.getMessage())); final Map<String, String> headers = session.getClient().execute( new HttpHead(new DAVPathEncoder().encode(file)), new HeadersResponseHandler()); final PathAttributes attributes = new PathAttributes(); try { attributes.setModificationDate(rfc1123.parse(headers.get(HttpHeaders.LAST_MODIFIED)).getTime()); } catch(InvalidDateException p) { log.warn(String.format("%s is not RFC 1123 format %s", headers.get(HttpHeaders.LAST_MODIFIED), p.getMessage())); } if(!headers.containsKey(HttpHeaders.CONTENT_ENCODING)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(headers.get(HttpHeaders.ETAG)); } if(headers.containsKey(HttpHeaders.CONTENT_MD5)) { attributes.setChecksum(Checksum.parse(headers.get(HttpHeaders.CONTENT_MD5))); } return attributes; } } } catch(SardineException e) { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, file); } } DAVAttributesFinderFeature(DAVSession session); @Override PathAttributes find(final Path file); }
DAVAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { try { for(final DavResource resource : this.list(file)) { if(resource.isDirectory()) { if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } else { if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } return this.toAttributes(resource); } throw new NotfoundException(file.getAbsolute()); } catch(SardineException e) { try { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(InteroperabilityException i) { log.warn(String.format("Failure with PROPFIND request for %s. %s", file, i.getMessage())); final Map<String, String> headers = session.getClient().execute( new HttpHead(new DAVPathEncoder().encode(file)), new HeadersResponseHandler()); final PathAttributes attributes = new PathAttributes(); try { attributes.setModificationDate(rfc1123.parse(headers.get(HttpHeaders.LAST_MODIFIED)).getTime()); } catch(InvalidDateException p) { log.warn(String.format("%s is not RFC 1123 format %s", headers.get(HttpHeaders.LAST_MODIFIED), p.getMessage())); } if(!headers.containsKey(HttpHeaders.CONTENT_ENCODING)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(headers.get(HttpHeaders.ETAG)); } if(headers.containsKey(HttpHeaders.CONTENT_MD5)) { attributes.setChecksum(Checksum.parse(headers.get(HttpHeaders.CONTENT_MD5))); } return attributes; } } } catch(SardineException e) { throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, file); } } DAVAttributesFinderFeature(DAVSession session); @Override PathAttributes find(final Path file);  }