Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Changelog for nextcloud api
## Version 13.0.2
- 2024-03-16
- Typo fixes
- Javadoc url's
- Modifiers should be declared in the correct order
- Try-with resources
- Use constants where possible
- Removed redundant Exception throwing
- Simplified assertions in tests

## Version 13.0.1
- 2023-09-29
- Release 13.0.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Java api library to access nextcloud features from java applications
<dependency>
<groupId>com.github.a-schild</groupId>
<artifactId>nextcloud-java-api</artifactId>
<version>13.0.1</version>
<version>13.1.0</version>
</dependency>
```

Expand Down
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.aarboard.nextcloud</groupId>
<artifactId>nextcloud-api</artifactId>
<version>13.0.1</version>
<version>13.1.0</version>
<packaging>jar</packaging>
<properties>
<!-- compile time dependencies -->
<httpcore.version>4.4.16</httpcore.version>
<httpasyncclient.version>4.1.5</httpasyncclient.version>
<httpclient.version>4.5.14</httpclient.version>
<slf4j-api.version>2.0.9</slf4j-api.version>
<slf4j-api.version>2.0.13</slf4j-api.version>
<sardine.version>5.12</sardine.version>
<commons-io.version>2.13.0</commons-io.version>
<commons-lang3.version>3.13.0</commons-lang3.version>
<commons-codec.version>1.16.0</commons-codec.version>
<jackson.version>2.15.2</jackson.version>
<commons-io.version>2.16.1</commons-io.version>
<commons-lang3.version>3.18.0</commons-lang3.version>
<commons-codec.version>1.17.0</commons-codec.version>
<jackson.version>2.17.1</jackson.version>
<jakarta.xml.bind-api.version>4.0.1</jakarta.xml.bind-api.version>
<jakarta-annotation-api.version>2.1.1</jakarta-annotation-api.version>
<jaxb-impl.version>3.0.0</jaxb-impl.version>
Expand All @@ -42,8 +42,8 @@
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<cyclonedx-maven-plugin.version>2.7.9</cyclonedx-maven-plugin.version>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<netbeans.hint.license>gpl30</netbeans.hint.license>
</properties>
<name>NextCloud Java API library</name>
Expand Down Expand Up @@ -274,7 +274,7 @@
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>true</doUpdate>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
<plugin>
Expand Down
80 changes: 45 additions & 35 deletions src/main/java/org/aarboard/nextcloud/api/NextcloudConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
import org.aarboard.nextcloud.api.webdav.pathresolver.WebDavPathResolver;
import org.aarboard.nextcloud.api.webdav.pathresolver.WebDavPathResolverBuilder;

public class NextcloudConnector {
public class NextcloudConnector implements AutoCloseable {

private final ServerConfig _serverConfig;
private final ServerConfig serverConfig;
private final ProvisionConnector pc;
private final FilesharingConnector fc;
private final ConfigConnector cc;
Expand Down Expand Up @@ -73,7 +73,7 @@ public NextcloudConnector(String serverName, boolean useHTTPS, int port, String

/**
* @param serviceUrl url of the nextcloud instance, e.g.
* https://nextcloud.instance.com:8443/cloud
* <a href="https://nextcloud.instance.com:8443/cloud">...</a>
* @param loginName User for login
* @param password Password for login
*/
Expand All @@ -83,32 +83,32 @@ public NextcloudConnector(String serviceUrl, String loginName, String password)

/**
* @param serviceUrl url of the nextcloud instance, e.g.
* https://nextcloud.instance.com:8443/cloud
* <a href="https://nextcloud.instance.com:8443/cloud">...</a>
* @param bearerToken Bearer token for login
*/
public NextcloudConnector(String serviceUrl, String bearerToken) {
this(serviceUrl, new AuthenticationConfig(bearerToken));
}

/**
* @param serviceUrl url of the nextcloud instance, e.g.
* https://nextcloud.instance.com:8443/cloud
* @param originalServiceUrl url of the nextcloud instance, e.g.
* <a href="https://nextcloud.instance.com:8443/cloud">...</a>
* @param authenticationConfig Authentication config
*/
public NextcloudConnector(String serviceUrl, AuthenticationConfig authenticationConfig) {
public NextcloudConnector(String originalServiceUrl, AuthenticationConfig authenticationConfig) {
try {
URL _serviceUrl = new URL(serviceUrl);
boolean useHTTPS = serviceUrl.startsWith("https");
_serverConfig = new ServerConfig(_serviceUrl.getHost(), useHTTPS, _serviceUrl.getPort(),
URL serviceUrl = new URL(originalServiceUrl);
boolean useHTTPS = originalServiceUrl.startsWith("https");
this.serverConfig = new ServerConfig(serviceUrl.getHost(), useHTTPS, serviceUrl.getPort(),
authenticationConfig);
if (!_serviceUrl.getPath().isEmpty()) {
_serverConfig.setSubPathPrefix(_serviceUrl.getPath());
if (!serviceUrl.getPath().isEmpty()) {
this.serverConfig.setSubPathPrefix(serviceUrl.getPath());
}
pc = new ProvisionConnector(_serverConfig);
fc = new FilesharingConnector(_serverConfig);
cc = new ConfigConnector(_serverConfig);
fd = new Folders(_serverConfig);
fl = new Files(_serverConfig);
pc = new ProvisionConnector(this.serverConfig);
fc = new FilesharingConnector(this.serverConfig);
cc = new ConfigConnector(this.serverConfig);
fd = new Folders(this.serverConfig);
fl = new Files(this.serverConfig);

} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
Expand All @@ -124,12 +124,12 @@ public NextcloudConnector(String serviceUrl, AuthenticationConfig authentication
*/
public NextcloudConnector(String serverName, boolean useHTTPS, int port,
AuthenticationConfig authenticationConfig) {
_serverConfig = new ServerConfig(serverName, useHTTPS, port, authenticationConfig);
pc = new ProvisionConnector(_serverConfig);
fc = new FilesharingConnector(_serverConfig);
cc = new ConfigConnector(_serverConfig);
fd = new Folders(_serverConfig);
fl = new Files(_serverConfig);
this.serverConfig = new ServerConfig(serverName, useHTTPS, port, authenticationConfig);
pc = new ProvisionConnector(this.serverConfig);
fc = new FilesharingConnector(this.serverConfig);
cc = new ConfigConnector(this.serverConfig);
fd = new Folders(this.serverConfig);
fl = new Files(this.serverConfig);
}

/**
Expand Down Expand Up @@ -171,8 +171,8 @@ public void setWebDavPathResolverAsType(final WebDavPathResolverBuilder.TYPE typ
WebDavPathResolver resolver = WebDavPathResolverBuilder.get(type)
.ofVersion(NextcloudVersion.get(getServerVersion()))
.withUserName(getCurrentUser().getId())
// .withUserName(_serverConfig.getUserName())
.withBasePathPrefix(_serverConfig.getSubPathPrefix()).build();
// .withUserName(this.serverConfig.getUserName())
.withBasePathPrefix(this.serverConfig.getSubPathPrefix()).build();

this.fd.setWebDavPathResolver(resolver);
this.fl.setWebDavPathResolver(resolver);
Expand All @@ -188,14 +188,24 @@ public void shutdown() throws IOException {
ConnectorCommon.shutdown();
}

/**
* Close the HTTP client. Perform this to cleanly shut down this
* application.
*
* @throws Exception In case of errors
*/
public void close() throws Exception {
shutdown();
}

/**
* Trust all HTTPS certificates presented by the server. This is e.g. used
* to work against a Nextcloud instance with a self-signed certificate.
*
* @param trustAllCertificates Do we accep self signed certificates or not
* @param trustAllCertificates Do we accept self-signed certificates or not
*/
public void trustAllCertificates(boolean trustAllCertificates) {
_serverConfig.setTrustAllCertificates(trustAllCertificates);
this.serverConfig.setTrustAllCertificates(trustAllCertificates);
}

/**
Expand All @@ -206,7 +216,7 @@ public void trustAllCertificates(boolean trustAllCertificates) {
* installed in root
*/
public void setSubpathPrefix(String subpathPrefix) {
_serverConfig.setSubPathPrefix(subpathPrefix);
this.serverConfig.setSubPathPrefix(subpathPrefix);
}

/**
Expand Down Expand Up @@ -662,7 +672,7 @@ public CompletableFuture<UserDetailsAnswer> getUserAsync(String userId) {
}

/**
* Gets user details of currently logged in user
* Gets user details of currently logged-in user
*
* @return all user details
*/
Expand Down Expand Up @@ -968,7 +978,7 @@ public void uploadFile(File srcFile, String remotePath) {
* @deprecated Since some nextcloud installations use fpm or fastcgi to
* connect to php, here the uploads might get zero empty on the server Use a
* (temp) file to upload the data, so the content length is known in advance
* https://github.com/a-schild/nextcloud-java-api/issues/20
* <a href="https://github.com/a-schild/nextcloud-java-api/issues/20">...</a>
*/
public void uploadFile(InputStream inputStream, String remotePath) {
fl.uploadFile(inputStream, remotePath);
Expand All @@ -987,7 +997,7 @@ public void uploadFile(InputStream inputStream, String remotePath) {
* @deprecated Since some nextcloud installations use fpm or fastcgi to
* connect to php, here the uploads might get zero empty on the server Use a
* (temp) file to upload the data, so the content length is known in advance
* https://github.com/a-schild/nextcloud-java-api/issues/20
* <a href="https://github.com/a-schild/nextcloud-java-api/issues/20">...</a>
*/
public void uploadFile(InputStream inputStream, String remotePath, boolean continueHeader) {
fl.uploadFile(inputStream, remotePath, continueHeader);
Expand Down Expand Up @@ -1136,7 +1146,7 @@ public CompletableFuture<XMLAnswer> editShareAsync(int shareId, Map<ShareData, S
* nextcloud server
* @param downloadpath Local path where the file has to be downloaded in the
* local machine
* @return boolean true if sucessfull
* @return boolean true if successful
* @throws java.io.IOException In case of IO errors
*/
public boolean downloadFile(String remotepath, String downloadpath) throws IOException {
Expand Down Expand Up @@ -1219,7 +1229,7 @@ public String getAppConfigAppKeyValue(String appConfigAppKeyPath) {
* @param appConfigAppKey a key name as returned by
* {@link #getAppConfigAppKeys(String)}
* @param value the value to set
* @return true if sucessfully set
* @return true if successfully set
*/
public boolean setAppConfigAppKeyValue(String appConfigApp, String appConfigAppKey, Object value) {
return cc.setAppConfigAppKeyValue(appConfigApp, appConfigAppKey, value);
Expand All @@ -1230,7 +1240,7 @@ public boolean setAppConfigAppKeyValue(String appConfigApp, String appConfigAppK
* @param appConfigAppKeyPath the full appConfigAppKeyPath combining
* appConfigApp and appConfigAppKey with "/"
* @param value the value to set
* @return Operation sucessfull
* @return Operation successful
*/
public boolean setAppConfigAppKeyValue(String appConfigAppKeyPath, Object value) {
return cc.setAppConfigAppKeyValue(appConfigAppKeyPath, value);
Expand All @@ -1243,7 +1253,7 @@ public boolean setAppConfigAppKeyValue(String appConfigAppKeyPath, Object value)
* {@link #getAppConfigApps()}
* @param appConfigAppkey a key name as returned by
* {@link #getAppConfigAppKeys(String)}
* @return Operation sucessfull
* @return Operation successful
*/
public boolean deleteAppConfigAppKeyEntry(String appConfigApp, String appConfigAppkey) {
return cc.deleteAppConfigAppKeyEntry(appConfigApp, appConfigAppkey);
Expand Down
Loading
Loading