@Override public void run() { mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend); } });
public RemoteOperationResult execute(OwnCloudClient client) { return execute(client, false); }
/** * Run operation for asynchronous or synchronous 'onExecute' method. * * Considers and performs silent refresh of account credentials if possible, and if * {@link RemoteOperation#setSilentRefreshOfAccountCredentials(boolean)} was called with * parameter 'true' before the execution. * * @return Remote operation result */ private RemoteOperationResult<T> runOperation() { RemoteOperationResult<T> result; try { grantOwnCloudClient(); result = run(mClient); } catch (AccountsException | IOException e) { Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e); result = new RemoteOperationResult<>(e); } return result; }
@Test public void testString() throws IOException, XmlPullParserException { String emptyString = ""; InputStream is = new ByteArrayInputStream(emptyString.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); Assert.assertFalse(xmlParser.isVirusException()); Assert.assertFalse(xmlParser.isInvalidCharacterException()); } }
@Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { if (!result.isSuccess()) { Toast.makeText(this, R.string.todo_operation_finished_in_fail, Toast.LENGTH_SHORT).show(); Log.e(LOG_TAG, result.getLogMessage(), result.getException()); } else if (operation instanceof ReadRemoteFolderOperation) { onSuccessfulRefresh((ReadRemoteFolderOperation)operation, result); } else if (operation instanceof com.owncloud.android.lib.resources.files.UploadRemoteFileOperation) { onSuccessfulUpload((com.owncloud.android.lib.resources.files.UploadRemoteFileOperation)operation, result); } else if (operation instanceof RemoveRemoteFileOperation ) { onSuccessfulRemoteDeletion((RemoveRemoteFileOperation)operation, result); } else if (operation instanceof DownloadRemoteFileOperation ) { onSuccessfulDownload(); } else { Toast.makeText(this, R.string.todo_operation_finished_in_success, Toast.LENGTH_SHORT).show(); } }
/** * Performs the operation * * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; result = createFolder(client); if (!result.isSuccess() && mCreateFullPath && RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); if (result.isSuccess()) { result = createFolder(client); // second (and last) try } } return result; }
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; /// download will be performed to a temporal file, then moved to the final location File tmpFile = new File(getTmpPath()); /// perform the download try { tmpFile.getParentFile().mkdirs(); result = downloadFile(client, tmpFile); Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + result.getLogMessage()); } catch (Exception e) { result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + result.getLogMessage(), e); } return result; }
/** * Checks if a file with the new name already exists. * * @return 'True' if the target path is already used by an existing file. */ private boolean targetPathIsUsed(OwnCloudClient client) { ExistenceCheckRemoteOperation existenceCheckRemoteOperation = new ExistenceCheckRemoteOperation(mNewRemotePath, false, false); RemoteOperationResult exists = existenceCheckRemoteOperation.run(client); return exists.isSuccess(); } }
/** * Asynchronous execution of the operation * started by {@link RemoteOperation#execute(OwnCloudClient, * OnRemoteOperationListener, Handler)}, * and result posting. */ @Override public final void run() { final RemoteOperationResult resultToSend = runOperation(); if (mAccount != null && mContext != null) { // Save Client Cookies AccountUtils.saveClient(mClient, mAccount, mContext); } if (mListenerHandler != null && mListener != null) { mListenerHandler.post(() -> mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend)); } else if (mListener != null) { mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend); } } }
/** * Parse OCS node * @param parser * @return reason for exception * @throws XmlPullParserException * @throws IOException */ private String readError (XmlPullParser parser) throws XmlPullParserException, IOException { String errorMessage = ""; parser.require(XmlPullParser.START_TAG, ns , NODE_ERROR); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); // read NODE_MESSAGE if (name.equalsIgnoreCase(NODE_MESSAGE)) { errorMessage = readText(parser); } else { skip(parser); } } return errorMessage; }
/** * Synchronously executes the remote operation * * Do not call this method from the main thread. * * @param client Client object to reach an ownCloud server during the execution of * the operation. * @return Result of the operation. */ public RemoteOperationResult execute(OwnCloudClient client, boolean useNextcloudUserAgent) { if (client == null) throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + "OwnCloudClient"); mClient = client; mClient.setUseNextcloudUserAgent(useNextcloudUserAgent); return run(client); }
public RemoteOperationResult(boolean success, int httpCode, Header[] headers) { this(success, httpCode); if (headers != null) { for (Header header : headers) { if ("location".equals(header.getName().toLowerCase(Locale.US))) { mRedirectedLocation = header.getValue(); continue; } if ("www-authenticate".equals(header.getName().toLowerCase(Locale.US))) { mAuthenticateHeaders.add(header.getValue()); } } } if (isIdPRedirection()) { mCode = ResultCode.UNAUTHORIZED; // overrides default ResultCode.UNKNOWN } }
/** * Synchronously executes the remote operation * * Do not call this method from the main thread. * * @param client Client object to reach an ownCloud server during the execution of * the operation. * @return Result of the operation. */ public RemoteOperationResult<T> execute(OkHttpClient client, Context context) { if (client == null) throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + "OwnCloudClient"); mHttpClient = client; mContext = context; return runOperation(); }
@Test public void testEmptyString() throws IOException, XmlPullParserException { String emptyString = ""; InputStream is = new ByteArrayInputStream(emptyString.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); Assert.assertFalse(xmlParser.isVirusException()); Assert.assertFalse(xmlParser.isInvalidCharacterException()); }
public RemoteOperationResult execute(Account account, Context context) { return execute(account, context, false); }
/** * Synchronously executes the remote operation on the received ownCloud account. * * Do not call this method from the main thread. * * This method should be used whenever an ownCloud account is available, instead of * {@link #execute(OwnCloudClient)}. * * @param account ownCloud account in remote ownCloud server to reach during the * execution of the operation. * @param context Android context for the component calling the method. * @return Result of the operation. */ public RemoteOperationResult<T> execute(Account account, Context context) { if (account == null) throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + "Account"); if (context == null) throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + "Context"); mAccount = account; mContext = context.getApplicationContext(); return runOperation(); }
@Test public void testInvalidCharacterUploadException() throws IOException, XmlPullParserException { String virusException = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n" + " <s:exception>OCP\\Files\\InvalidPathException</s:exception>\n" + " <s:message>Wrong Path</s:message>\n" + "</d:error>"; InputStream is = new ByteArrayInputStream(virusException.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); Assert.assertTrue(xmlParser.isInvalidCharacterException()); Assert.assertFalse(xmlParser.isVirusException()); }
private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, mCreateFullPath); return operation.execute(client); } }
@Test public void testInvalidCharacterException() throws IOException, XmlPullParserException { String virusException = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n" + " <s:exception>OC\\Connector\\Sabre\\Exception\\InvalidPath</s:exception>\n" + " <s:message>Wrong Path</s:message>\n" + "</d:error>"; InputStream is = new ByteArrayInputStream(virusException.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); Assert.assertTrue(xmlParser.isInvalidCharacterException()); Assert.assertFalse(xmlParser.isVirusException()); }
private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { RemoteOperation operation = new CreateFolderRemoteOperation(parentPath, mCreateFullPath); return operation.execute(client); }