2222import org .apache .commons .httpclient .methods .PutMethod ;
2323import org .apache .commons .httpclient .methods .StringRequestEntity ;
2424
25- import java .net .URLEncoder ;
2625import java .text .DateFormat ;
2726import java .text .SimpleDateFormat ;
2827import java .util .Calendar ;
@@ -140,11 +139,7 @@ public void setNote(String note) {
140139 this .note = note ;
141140 }
142141
143- @ Override
144- protected RemoteOperationResult <List <OCShare >> run (OwnCloudClient client ) {
145- RemoteOperationResult <List <OCShare >> result ;
146-
147- /// prepare array of parameters to update
142+ private String getRequestBody () {
148143 JsonObject params = new JsonObject ();
149144 if (password != null ) {
150145 params .addProperty (PARAM_PASSWORD , password );
@@ -161,7 +156,7 @@ protected RemoteOperationResult<List<OCShare>> run(OwnCloudClient client) {
161156 String formattedExpirationDate = dateFormat .format (expirationDate .getTime ());
162157 params .addProperty (PARAM_EXPIRATION_DATE , formattedExpirationDate );
163158 }
164-
159+
165160 if (permissions > 0 ) {
166161 params .addProperty (PARAM_PERMISSIONS , Integer .toString (permissions ));
167162 }
@@ -170,16 +165,24 @@ protected RemoteOperationResult<List<OCShare>> run(OwnCloudClient client) {
170165 params .addProperty (PARAM_HIDE_DOWNLOAD , Boolean .toString (hideFileDownload ));
171166 }
172167
173- PutMethod put = null ;
174- try {
175- if (note != null ) {
176- params .addProperty (PARAM_NOTE , URLEncoder .encode (note , ENTITY_CHARSET ));
177- }
168+ if (note != null ) {
169+ params .addProperty (PARAM_NOTE , note );
170+ }
178171
179- if (label != null ) {
180- params .addProperty (PARAM_LABEL , URLEncoder .encode (label , ENTITY_CHARSET ));
181- }
172+ if (label != null ) {
173+ params .addProperty (PARAM_LABEL , label );
174+ }
175+
176+ return params .toString ();
177+ }
182178
179+ @ Override
180+ protected RemoteOperationResult <List <OCShare >> run (OwnCloudClient client ) {
181+ RemoteOperationResult <List <OCShare >> result ;
182+ String requestBody = getRequestBody ();
183+
184+ PutMethod put = null ;
185+ try {
183186 Uri requestUri = client .getBaseUri ();
184187 Uri .Builder uriBuilder = requestUri .buildUpon ();
185188 uriBuilder .appendEncodedPath (ShareUtils .SHARING_API_PATH .substring (1 ));
@@ -188,11 +191,7 @@ protected RemoteOperationResult<List<OCShare>> run(OwnCloudClient client) {
188191
189192 put = new PutMethod (uriString );
190193 put .addRequestHeader (OCS_API_HEADER , OCS_API_HEADER_VALUE );
191- put .setRequestEntity (new StringRequestEntity (
192- params .toString (),
193- ENTITY_CONTENT_TYPE ,
194- ENTITY_CHARSET
195- ));
194+ put .setRequestEntity (new StringRequestEntity (requestBody , ENTITY_CONTENT_TYPE , ENTITY_CHARSET ));
196195
197196 int status = client .executeMethod (put );
198197 if (status == HttpStatus .SC_OK || status == HttpStatus .SC_BAD_REQUEST ) {
0 commit comments