@Test public void testCopyFile() throws Exception { final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DefaultTouchFeature<String>(new DAVUploadFeature(new DAVWriteFeature(session)), new DAVAttributesFinderFeature(session)).touch(test, new TransferStatus()); final Path copy = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DAVCopyFeature(session).copy(test, copy, new TransferStatus(), new DisabledConnectionCallback()); assertTrue(new DAVFindFeature(session).find(test)); assertTrue(new DAVFindFeature(session).find(copy)); new DAVDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); new DAVDeleteFeature(session).delete(Collections.<Path>singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final String target = new DefaultUrlProvider(session.getHost()).toUrl(copy).find(DescriptiveUrl.Type.provider).getUrl(); if(session.getFeature(Lock.class) != null && status.getLockId() != null) { session.getClient().copy(new DAVPathEncoder().encode(source), target, true, Collections.singletonMap(HttpHeaders.IF, String.format("(<%s>)", status.getLockId()))); } else { session.getClient().copy(new DAVPathEncoder().encode(source), target, true); } return copy; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Cannot copy {0}", e, source); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, source); } }
DAVCopyFeature implements Copy { @Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final String target = new DefaultUrlProvider(session.getHost()).toUrl(copy).find(DescriptiveUrl.Type.provider).getUrl(); if(session.getFeature(Lock.class) != null && status.getLockId() != null) { session.getClient().copy(new DAVPathEncoder().encode(source), target, true, Collections.singletonMap(HttpHeaders.IF, String.format("(<%s>)", status.getLockId()))); } else { session.getClient().copy(new DAVPathEncoder().encode(source), target, true); } return copy; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Cannot copy {0}", e, source); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, source); } } }
DAVCopyFeature implements Copy { @Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final String target = new DefaultUrlProvider(session.getHost()).toUrl(copy).find(DescriptiveUrl.Type.provider).getUrl(); if(session.getFeature(Lock.class) != null && status.getLockId() != null) { session.getClient().copy(new DAVPathEncoder().encode(source), target, true, Collections.singletonMap(HttpHeaders.IF, String.format("(<%s>)", status.getLockId()))); } else { session.getClient().copy(new DAVPathEncoder().encode(source), target, true); } return copy; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Cannot copy {0}", e, source); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, source); } } DAVCopyFeature(final DAVSession session); }
DAVCopyFeature implements Copy { @Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final String target = new DefaultUrlProvider(session.getHost()).toUrl(copy).find(DescriptiveUrl.Type.provider).getUrl(); if(session.getFeature(Lock.class) != null && status.getLockId() != null) { session.getClient().copy(new DAVPathEncoder().encode(source), target, true, Collections.singletonMap(HttpHeaders.IF, String.format("(<%s>)", status.getLockId()))); } else { session.getClient().copy(new DAVPathEncoder().encode(source), target, true); } return copy; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Cannot copy {0}", e, source); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, source); } } DAVCopyFeature(final DAVSession session); @Override Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback); @Override boolean isRecursive(final Path source, final Path target); }
DAVCopyFeature implements Copy { @Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final String target = new DefaultUrlProvider(session.getHost()).toUrl(copy).find(DescriptiveUrl.Type.provider).getUrl(); if(session.getFeature(Lock.class) != null && status.getLockId() != null) { session.getClient().copy(new DAVPathEncoder().encode(source), target, true, Collections.singletonMap(HttpHeaders.IF, String.format("(<%s>)", status.getLockId()))); } else { session.getClient().copy(new DAVPathEncoder().encode(source), target, true); } return copy; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Cannot copy {0}", e, source); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, source); } } DAVCopyFeature(final DAVSession session); @Override Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback); @Override boolean isRecursive(final Path source, final Path target);  }