Skip to content

Commit

Permalink
pcorlessGH-46 Fixes moving or copying nonexistent files; Adds message…
Browse files Browse the repository at this point in the history
… for dav file not found
  • Loading branch information
gtache committed Oct 13, 2020
1 parent eefa629 commit 5d093e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2865,10 +2865,21 @@ public void openDocument(final DavFileClient pdfDavClient) {
}

protected void openDavDocument() throws IOException, PDFException, PDFSecurityException {
InputStream stream = pdfClient.getStream();
document = new Document();
document.setInputStream(new BufferedInputStream(stream), pdfClient.getUrl());
commonNewDocumentHandling(pdfClient.getUrl());
if (pdfClient.exists()) {
final InputStream stream = pdfClient.getStream();
document = new Document();
document.setInputStream(new BufferedInputStream(stream), pdfClient.getUrl());
commonNewDocumentHandling(pdfClient.getUrl());
} else {
org.icepdf.ri.util.Resources.showMessageDialog(
viewer,
JOptionPane.INFORMATION_MESSAGE,
messageBundle,
"viewer.dialog.dav.notfound.title",
"viewer.dialog.dav.notfound.msg",
pdfClient.getUrl()
);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public InputStream getStream() throws IOException {
*/
public void resetStream() throws IOException {
close();
stream = sardine.get(url);
if (exists()) {
stream = sardine.get(url);
}
}

/**
Expand Down Expand Up @@ -213,7 +215,7 @@ public boolean exists() throws IOException {
}

/**
* Renames the remote resource to the given name
* Renames the remote resource to the given name. No-op if the file doesn't exist.
*
* @param newName The new name
* @return The client managing the resource under the new name
Expand All @@ -224,7 +226,7 @@ public DavFileClient rename(final String newName) throws IOException {
}

/**
* Moves the remote resource to the given url
* Moves the remote resource to the given url. No-op if the file doesn't exist.
*
* @param newUrl The new url
* @return The client managing the resource under the new url
Expand All @@ -235,15 +237,15 @@ public DavFileClient move(final String newUrl) throws IOException {
}

/**
* Moves the remote resource to the given url
* Moves the remote resource to the given url. No-op if the file doesn't exist.
*
* @param newUrl The new url
* @param overwrite Whether to overwrite the resource or not
* @return The client managing the resource under the new url
* @throws IOException
*/
public DavFileClient move(final String newUrl, final boolean overwrite) throws IOException {
if (!readOnly) {
if (!readOnly && exists()) {
final String[] split = newUrl.split("/");
createParentDirectory(Arrays.stream(split).limit(split.length - 1).collect(Collectors.joining("/")));
sardine.move(url, newUrl, overwrite);
Expand All @@ -254,7 +256,7 @@ public DavFileClient move(final String newUrl, final boolean overwrite) throws I
}

/**
* Copies the resource to the given url
* Copies the resource to the given url. No-op if the file doesn't exist.
*
* @param newUrl The new url
* @return The client managing the new resource
Expand All @@ -265,18 +267,22 @@ public DavFileClient copy(final String newUrl) throws IOException {
}

/**
* Copies the resource to the given url
* Copies the resource to the given url. No-op if the file doesn't exist.
*
* @param newUrl The new url
* @param overwrite Whether to overwrite or not
* @return The client managing the new resource
* @throws IOException
*/
public DavFileClient copy(final String newUrl, final boolean overwrite) throws IOException {
final String[] split = newUrl.split("/");
createParentDirectory(Arrays.stream(split).limit(split.length - 1).collect(Collectors.joining("/")));
sardine.copy(url, newUrl, overwrite);
return new DavFileClient(newUrl, username, password);
if (exists()) {
final String[] split = newUrl.split("/");
createParentDirectory(Arrays.stream(split).limit(split.length - 1).collect(Collectors.joining("/")));
sardine.copy(url, newUrl, overwrite);
return new DavFileClient(newUrl, username, password);
} else {
return this;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ viewer.dialog.sardine.exception.title=Communication error
viewer.dialog.sardine.exception.msg=Couldn't open document due to {0}
viewer.dialog.dav.exception.title=Webdav error
viewer.dialog.dav.exception.msg=Couldn't open document due to {0}
viewer.dialog.dav.notfound.title=File not found
viewer.dialog.dav.notfound.msg=Couldn't open file: File not found at\n{0}
### Save a Copy Dialog
viewer.dialog.saveAs.title=Save As
viewer.dialog.saveAs.extensionError.title=ICEpdf - Save Error
Expand Down

0 comments on commit 5d093e8

Please sign in to comment.