Skip to content

Commit

Permalink
Fx bug in file chooser msg + updates sonar analysis action + README
Browse files Browse the repository at this point in the history
  • Loading branch information
fathzer committed Sep 28, 2023
1 parent 9063e98 commit 3205d33
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ name: Build
on:
push:
branches:
- "**"
- "*"
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'zulu' # Alternative distribution options are available.
- name: Cache SonarCloud packages
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand All @@ -33,4 +34,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent test org.jacoco:jacoco-maven-plugin:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dorg.slf4j.simpleLogger.log.org.mockserver.log=warn -Dsonar.projectKey=jclop2_dropbox
run: >
mvn -Dmaven.test.failure.ignore=true -B org.jacoco:jacoco-maven-plugin:prepare-agent test org.jacoco:jacoco-maven-plugin:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dorg.slf4j.simpleLogger.log.org.mockserver.log=warn
-Dsonar.organization=jclop -Dsonar.host.url=https://sonarcloud.io -Dsonar.projectKey=jclop2_dropbox
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,53 @@
A [JClop](https://github.com/jclop2/JClop) implementation that uses Dropbox as underlying storage provider.

It requires java 6+.

Limitations : sub-folders are not supported in Swing file chooser.

## Usage example

### Pre-requisite
In order to connect your application with Dropbox, you should [register it](https://www.dropbox.com/developers/apps/create) in the [Developer section](https://www.dropbox.com/developers/) of the Dropbox web site.
Once the application has been created, you will get an application key and an application secret. Both are required to use this library.

### How to create the JClop service

Let's suppose you have registered an application named "Test application" and *appKey* and *appSecret* are its key and secret.

```java
// Dropbox requires connection data to be initialized
final DbxAppInfo appInfo = new DbxAppInfo(appKey, appSecret);
final DbxConnectionData ctData = new DbxConnectionData("Test application", DbxRequestConfig.newBuilder("Test client").build(), appInfo);
// Create the service
final DropboxService service = new DropboxService(new File("cacheTest"), ctData);
```

### How to select a file

First you should have a Dropboxservice in the *service* variable (see above).

```java
// Create a chooser to choose a file in Dropbox
final URIChooser chooser = new DropboxURIChooser(service);
// Create a dialog that allows the selection of a file in Dropbox
final URIChooserDialog dialog = new URIChooserDialog(null, "", new URIChooser[] {chooser});
// Get the URI of a file
// The first time, you'll have to connect to your Dropbox account using a browser (this is the Dropbox way to connect to an account).
// The next time, you will not be asked again to connect (the connection data is saved in the local cache folder).
final URI uri = dialog.showDialog();
if (uri != null) {
// If a file was selected
System.out.println("Full (with credentials) URI is "+uri);
System.out.println("Displayable URI is "+service.getDisplayable(uri));
}
```

If you select a file in the dialog, this code will ouput something like
```
Full (with credentials) URI is dropbox://12345678:OAuth2-refresh-3nVCk_EhwVcAAAAAB8fAe1wcuiZ3YrBj7o4KJI482s8AKeZ9UpJO7GhZJoAB_kw@cloud.jclop.fathzer.com/userName/file
Displayable URI is dropbox://userName/file
```
**Be cautious with the full URI, it contains sensitive information**: the credentials it contains would allow anybody to obtain the same privileges your application has on the user dropbox account.

### How to read/write a file
Jclop provides a generic way for accessing files, please see [its documentation](https://github.com/jclop2/JClop).
6 changes: 2 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>jclop-dropbox2</artifactId>
<version>0.1.6</version>
<version>0.1.7</version>
<parent>
<groupId>com.fathzer</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.4</version>
<version>1.0.8</version>
</parent>
<name>JClop-Dropbox</name>
<url>http://jclop.soft.fathzer.com</url>
Expand All @@ -16,8 +16,6 @@
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.organization>jclop</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ protected void confirm() {
pair = webAuth.finishFromCode(code);
} catch (BadRequestException e) {
// The user didn't grant the access to Dropbox
AbstractURIChooserPanel.showError(this, MessagePack.getString("com.fathzer.soft.jclop.dropbox.ConnectionDialog.accessNotGranted", getLocale()), getLocale()); //$NON-NLS-1$
final String message = MessagePack.getString("com.fathzer.soft.jclop.dropbox.ConnectionDialog.accessNotGranted", getLocale()); //$NON-NLS-1$
AbstractURIChooserPanel.showError(this, Formatter.format(message, data.getAppName()), getLocale());
getConnectionButtonsPanel().getConnectButton().setEnabled(true);
updateOkButtonEnabled();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

#Wordings related to the dropbox tab of the file selection dialog
com.fathzer.soft.jclop.dropbox.ConnectionDialog.title=Connect to Dropbox
com.fathzer.soft.jclop.dropbox.ConnectionDialog.message.content=<html><b>{2}</b> will only have access to a specific folder (/Applications/{2}), not your whole account.<br><br>Click the \"<b>{0}</b>\" button when you are ready to link Yapbam to your account (requires an Internet connection)<br>Then, you will be redirected to a browser window where Dropbox will ask you to grant access to Yapbam.<br><br><b>After</b> you've granted access to Dropbox, copy the code displayed in your browser in the field below and click the "<b>{1}</b>" button</html>
com.fathzer.soft.jclop.dropbox.ConnectionDialog.message.content=<html><b>{2}</b> will only have access to a specific folder (/Applications/{2}), not your whole account.<br><br>Click the \"<b>{0}</b>\" button when you are ready to link this application to your account (requires an Internet connection)<br>Then, you will be redirected to a browser window where Dropbox will ask you to grant access to {2}.<br><br><b>After</b> you've granted access to Dropbox, copy the code displayed in your browser in the field below and click the "<b>{1}</b>" button</html>
com.fathzer.soft.jclop.dropbox.ConnectionDialog.message.header=<html>Storing data to <b>Dropbox</b> requires that you authorize {0} to access your Dropbox account.</html>
com.fathzer.soft.jclop.dropbox.ConnectionDialog.startButton=Start Connection
com.fathzer.soft.jclop.dropbox.ConnectionDialog.startButton.tooltip=Click this button to start the connection process.
com.fathzer.soft.jclop.dropbox.ConnectionDialog.accessNotGranted=It seems you didn't grant access to Yapbam, please retry.
com.fathzer.soft.jclop.dropbox.ConnectionDialog.accessNotGranted=It seems you didn't grant access to {0}, please retry.
com.fathzer.soft.jclop.dropbox.ConnectionDialog.unexpectedError=An unexpected error occurred while connecting to Dropbox.
com.fathzer.soft.jclop.dropbox.ConnectionDialog.error.processNotStarted=<html>You may click the <b>{0}</b> button first.</html>
com.fathzer.soft.jclop.dropbox.ConnectionDialog.error.unableToLaunchBrowser.message=Sorry, an unexpected error occurred while launching the browser.
Expand Down

0 comments on commit 3205d33

Please sign in to comment.