Skip to content

Commit

Permalink
make compatible the vfs on https and github, pulicating the repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
frett27 committed Oct 15, 2023
1 parent 32aa48c commit 4c6eeed
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static StandardFileSystemManager getManager() throws Exception {
fsManager.init();

fsManager.addProvider("bod", new BodProvider());
fsManager.addProvider("bods", new BodProvider());

FSMANAGER = fsManager;
VFS.setManager(FSMANAGER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ ResponseInformations toResponseInformation(HttpResponse response) {
return responseInformations;
}

@Override
public boolean exists() throws FileSystemException {
boolean exists = (getType() != FileType.IMAGINARY);
return exists;
}

@Override
public FileType getType() throws FileSystemException {
FileType type = super.getType();
return type;
}

/**
* Construct {@code Http4FileObject}.
*
Expand Down Expand Up @@ -153,7 +165,13 @@ protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mo
}

URI getHttpUri() {
return URI.create(getInternalURI().toString().replaceAll("bod://", "http://"));
String uri = getInternalURI().toString();

uri = uri.replaceAll("bod://", "http://");
if (uri.contains(":443")) {
uri = uri.replaceAll("http://", "https://");
}
return URI.create(uri);
}

FileType fileType = null;
Expand All @@ -174,12 +192,33 @@ protected FileType doGetType() throws Exception {
lastHeadResponse = toResponseInformation(httpResponse);
final int status = httpResponse.getStatusLine().getStatusCode();

// try get content

if (status == HttpStatus.SC_OK
|| status == HttpStatus.SC_METHOD_NOT_ALLOWED /* method is not allowed, but resource exist */) {
fileType = FileType.FILE;
return fileType;
}

if (status == HttpStatus.SC_NOT_FOUND) {
// try /content
URI contentListUri = URI.create(getHttpUri() + "/CONTENT");

final HttpGet getRequest = new HttpGet(contentListUri);
try (final CloseableHttpResponse httpResponseContent = executeHttpUriRequest(getRequest)) {
try {
final int content_status = httpResponseContent.getStatusLine().getStatusCode();
if (content_status == HttpStatus.SC_OK) {
getChildren();
fileType = FileType.FOLDER;
return fileType;
}
} catch (Exception ex) {
// continue
}
}
}

if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_GONE) {
fileType = FileType.IMAGINARY;
return fileType;
Expand Down Expand Up @@ -255,7 +294,7 @@ protected CloseableHttpResponse executeHttpUriRequest(final HttpUriRequest httpR
// System.out.println("execute : " + httpRequest);
final HttpClientContext httpClientContext = getAbstractFileSystem().getHttpClientContext();
CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(httpRequest, httpClientContext);
// System.out.println(" response :" + response.getStatusLine());
// System.out.println(" response :" + response.getStatusLine());
return response;

}
Expand Down
8 changes: 4 additions & 4 deletions aprint-core/src/main/resources/aprintversion.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#APrint Version
#Fri Aug 18 17:30:52 CEST 2023
date=2023/08/18 05\:30
githash=e6865a76e605c2f15ff44241da8c932c55173093
version=2022.12.955
#Fri Aug 18 17:53:17 CEST 2023
date=2023/08/18 05\:53
githash=03f833ac65e05257e0c5ac51333a92ffb873ae2b
version=2022.12.956
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.VFS;
import org.barrelorgandiscovery.tools.VFSTools;
import org.jdesktop.swingx.HorizontalLayout;

import com.googlecode.vfsjfilechooser2.VFSJFileChooser;
Expand Down Expand Up @@ -195,22 +196,12 @@ public void run() {

FileObject fo = null;
String failureMessage = null;
try {
// if(aTitledURLEntry.getURL().startsWith("ftp")) {
// FileSystemOptions opts = new FileSystemOptions();
//
// FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
// FileSystemManager manager = VFS.getManager();
//fo = manager.resolveFile(aTitledURLEntry.getURL(), opts);
// } else {
//

fo = VFS.getManager().resolveFile(aTitledURLEntry.getURL());
//}

if ((fo != null) && !fo.exists()) {
try {
fo = VFSTools.getManager().resolveFile(aTitledURLEntry.getURL());
//FileObject[] childrens = fo.getChildren();
/* if ((fo != null) && !fo.exists()) {
fo = null;
}
}*/
} catch (Throwable exc) {
fo = null;
failureMessage = exc.getMessage();
Expand Down

0 comments on commit 4c6eeed

Please sign in to comment.