3939import org .aarboard .nextcloud .api .webdav .pathresolver .WebDavPathResolver ;
4040import org .aarboard .nextcloud .api .webdav .pathresolver .WebDavPathResolverBuilder ;
4141
42- public class NextcloudConnector {
42+ public class NextcloudConnector implements AutoCloseable {
4343
44- private final ServerConfig _serverConfig ;
44+ private final ServerConfig serverConfig ;
4545 private final ProvisionConnector pc ;
4646 private final FilesharingConnector fc ;
4747 private final ConfigConnector cc ;
@@ -73,7 +73,7 @@ public NextcloudConnector(String serverName, boolean useHTTPS, int port, String
7373
7474 /**
7575 * @param serviceUrl url of the nextcloud instance, e.g.
76- * https://nextcloud.instance.com:8443/cloud
76+ * <a href=" https://nextcloud.instance.com:8443/cloud">...</a>
7777 * @param loginName User for login
7878 * @param password Password for login
7979 */
@@ -83,32 +83,32 @@ public NextcloudConnector(String serviceUrl, String loginName, String password)
8383
8484 /**
8585 * @param serviceUrl url of the nextcloud instance, e.g.
86- * https://nextcloud.instance.com:8443/cloud
86+ * <a href=" https://nextcloud.instance.com:8443/cloud">...</a>
8787 * @param bearerToken Bearer token for login
8888 */
8989 public NextcloudConnector (String serviceUrl , String bearerToken ) {
9090 this (serviceUrl , new AuthenticationConfig (bearerToken ));
9191 }
9292
9393 /**
94- * @param serviceUrl url of the nextcloud instance, e.g.
95- * https://nextcloud.instance.com:8443/cloud
94+ * @param originalServiceUrl url of the nextcloud instance, e.g.
95+ * <a href=" https://nextcloud.instance.com:8443/cloud">...</a>
9696 * @param authenticationConfig Authentication config
9797 */
98- public NextcloudConnector (String serviceUrl , AuthenticationConfig authenticationConfig ) {
98+ public NextcloudConnector (String originalServiceUrl , AuthenticationConfig authenticationConfig ) {
9999 try {
100- URL _serviceUrl = new URL (serviceUrl );
101- boolean useHTTPS = serviceUrl .startsWith ("https" );
102- _serverConfig = new ServerConfig (_serviceUrl .getHost (), useHTTPS , _serviceUrl .getPort (),
100+ URL serviceUrl = new URL (originalServiceUrl );
101+ boolean useHTTPS = originalServiceUrl .startsWith ("https" );
102+ this . serverConfig = new ServerConfig (serviceUrl .getHost (), useHTTPS , serviceUrl .getPort (),
103103 authenticationConfig );
104- if (!_serviceUrl .getPath ().isEmpty ()) {
105- _serverConfig . setSubPathPrefix (_serviceUrl .getPath ());
104+ if (!serviceUrl .getPath ().isEmpty ()) {
105+ this . serverConfig . setSubPathPrefix (serviceUrl .getPath ());
106106 }
107- pc = new ProvisionConnector (_serverConfig );
108- fc = new FilesharingConnector (_serverConfig );
109- cc = new ConfigConnector (_serverConfig );
110- fd = new Folders (_serverConfig );
111- fl = new Files (_serverConfig );
107+ pc = new ProvisionConnector (this . serverConfig );
108+ fc = new FilesharingConnector (this . serverConfig );
109+ cc = new ConfigConnector (this . serverConfig );
110+ fd = new Folders (this . serverConfig );
111+ fl = new Files (this . serverConfig );
112112
113113 } catch (MalformedURLException e ) {
114114 throw new IllegalArgumentException (e );
@@ -124,12 +124,12 @@ public NextcloudConnector(String serviceUrl, AuthenticationConfig authentication
124124 */
125125 public NextcloudConnector (String serverName , boolean useHTTPS , int port ,
126126 AuthenticationConfig authenticationConfig ) {
127- _serverConfig = new ServerConfig (serverName , useHTTPS , port , authenticationConfig );
128- pc = new ProvisionConnector (_serverConfig );
129- fc = new FilesharingConnector (_serverConfig );
130- cc = new ConfigConnector (_serverConfig );
131- fd = new Folders (_serverConfig );
132- fl = new Files (_serverConfig );
127+ this . serverConfig = new ServerConfig (serverName , useHTTPS , port , authenticationConfig );
128+ pc = new ProvisionConnector (this . serverConfig );
129+ fc = new FilesharingConnector (this . serverConfig );
130+ cc = new ConfigConnector (this . serverConfig );
131+ fd = new Folders (this . serverConfig );
132+ fl = new Files (this . serverConfig );
133133 }
134134
135135 /**
@@ -171,8 +171,8 @@ public void setWebDavPathResolverAsType(final WebDavPathResolverBuilder.TYPE typ
171171 WebDavPathResolver resolver = WebDavPathResolverBuilder .get (type )
172172 .ofVersion (NextcloudVersion .get (getServerVersion ()))
173173 .withUserName (getCurrentUser ().getId ())
174- // .withUserName(_serverConfig .getUserName())
175- .withBasePathPrefix (_serverConfig .getSubPathPrefix ()).build ();
174+ // .withUserName(this.serverConfig .getUserName())
175+ .withBasePathPrefix (this . serverConfig .getSubPathPrefix ()).build ();
176176
177177 this .fd .setWebDavPathResolver (resolver );
178178 this .fl .setWebDavPathResolver (resolver );
@@ -188,14 +188,24 @@ public void shutdown() throws IOException {
188188 ConnectorCommon .shutdown ();
189189 }
190190
191+ /**
192+ * Close the HTTP client. Perform this to cleanly shut down this
193+ * application.
194+ *
195+ * @throws Exception In case of errors
196+ */
197+ public void close () throws Exception {
198+ shutdown ();
199+ }
200+
191201 /**
192202 * Trust all HTTPS certificates presented by the server. This is e.g. used
193203 * to work against a Nextcloud instance with a self-signed certificate.
194204 *
195- * @param trustAllCertificates Do we accep self signed certificates or not
205+ * @param trustAllCertificates Do we accept self- signed certificates or not
196206 */
197207 public void trustAllCertificates (boolean trustAllCertificates ) {
198- _serverConfig .setTrustAllCertificates (trustAllCertificates );
208+ this . serverConfig .setTrustAllCertificates (trustAllCertificates );
199209 }
200210
201211 /**
@@ -206,7 +216,7 @@ public void trustAllCertificates(boolean trustAllCertificates) {
206216 * installed in root
207217 */
208218 public void setSubpathPrefix (String subpathPrefix ) {
209- _serverConfig .setSubPathPrefix (subpathPrefix );
219+ this . serverConfig .setSubPathPrefix (subpathPrefix );
210220 }
211221
212222 /**
@@ -662,7 +672,7 @@ public CompletableFuture<UserDetailsAnswer> getUserAsync(String userId) {
662672 }
663673
664674 /**
665- * Gets user details of currently logged in user
675+ * Gets user details of currently logged- in user
666676 *
667677 * @return all user details
668678 */
@@ -968,7 +978,7 @@ public void uploadFile(File srcFile, String remotePath) {
968978 * @deprecated Since some nextcloud installations use fpm or fastcgi to
969979 * connect to php, here the uploads might get zero empty on the server Use a
970980 * (temp) file to upload the data, so the content length is known in advance
971- * https://github.com/a-schild/nextcloud-java-api/issues/20
981+ * <a href=" https://github.com/a-schild/nextcloud-java-api/issues/20">...</a>
972982 */
973983 public void uploadFile (InputStream inputStream , String remotePath ) {
974984 fl .uploadFile (inputStream , remotePath );
@@ -987,7 +997,7 @@ public void uploadFile(InputStream inputStream, String remotePath) {
987997 * @deprecated Since some nextcloud installations use fpm or fastcgi to
988998 * connect to php, here the uploads might get zero empty on the server Use a
989999 * (temp) file to upload the data, so the content length is known in advance
990- * https://github.com/a-schild/nextcloud-java-api/issues/20
1000+ * <a href=" https://github.com/a-schild/nextcloud-java-api/issues/20">...</a>
9911001 */
9921002 public void uploadFile (InputStream inputStream , String remotePath , boolean continueHeader ) {
9931003 fl .uploadFile (inputStream , remotePath , continueHeader );
@@ -1136,7 +1146,7 @@ public CompletableFuture<XMLAnswer> editShareAsync(int shareId, Map<ShareData, S
11361146 * nextcloud server
11371147 * @param downloadpath Local path where the file has to be downloaded in the
11381148 * local machine
1139- * @return boolean true if sucessfull
1149+ * @return boolean true if successful
11401150 * @throws java.io.IOException In case of IO errors
11411151 */
11421152 public boolean downloadFile (String remotepath , String downloadpath ) throws IOException {
@@ -1219,7 +1229,7 @@ public String getAppConfigAppKeyValue(String appConfigAppKeyPath) {
12191229 * @param appConfigAppKey a key name as returned by
12201230 * {@link #getAppConfigAppKeys(String)}
12211231 * @param value the value to set
1222- * @return true if sucessfully set
1232+ * @return true if successfully set
12231233 */
12241234 public boolean setAppConfigAppKeyValue (String appConfigApp , String appConfigAppKey , Object value ) {
12251235 return cc .setAppConfigAppKeyValue (appConfigApp , appConfigAppKey , value );
@@ -1230,7 +1240,7 @@ public boolean setAppConfigAppKeyValue(String appConfigApp, String appConfigAppK
12301240 * @param appConfigAppKeyPath the full appConfigAppKeyPath combining
12311241 * appConfigApp and appConfigAppKey with "/"
12321242 * @param value the value to set
1233- * @return Operation sucessfull
1243+ * @return Operation successful
12341244 */
12351245 public boolean setAppConfigAppKeyValue (String appConfigAppKeyPath , Object value ) {
12361246 return cc .setAppConfigAppKeyValue (appConfigAppKeyPath , value );
@@ -1243,7 +1253,7 @@ public boolean setAppConfigAppKeyValue(String appConfigAppKeyPath, Object value)
12431253 * {@link #getAppConfigApps()}
12441254 * @param appConfigAppkey a key name as returned by
12451255 * {@link #getAppConfigAppKeys(String)}
1246- * @return Operation sucessfull
1256+ * @return Operation successful
12471257 */
12481258 public boolean deleteAppConfigAppKeyEntry (String appConfigApp , String appConfigAppkey ) {
12491259 return cc .deleteAppConfigAppKeyEntry (appConfigApp , appConfigAppkey );
0 commit comments