Search in sources :

Example 1 with NextcloudServer

use of com.owncloud.android.utils.NextcloudServer in project android by nextcloud.

the class ChooseRichDocumentsTemplateDialogFragment method newInstance.

// will be removed in favor of generic direct editing
@NextcloudServer(max = 18)
public static ChooseRichDocumentsTemplateDialogFragment newInstance(OCFile parentFolder, Type type) {
    ChooseRichDocumentsTemplateDialogFragment frag = new ChooseRichDocumentsTemplateDialogFragment();
    Bundle args = new Bundle();
    args.putParcelable(ARG_PARENT_FOLDER, parentFolder);
    args.putString(ARG_TYPE, type.name());
    frag.setArguments(args);
    return frag;
}
Also used : Bundle(android.os.Bundle) NextcloudServer(com.owncloud.android.utils.NextcloudServer)

Example 2 with NextcloudServer

use of com.owncloud.android.utils.NextcloudServer in project android by nextcloud.

the class RichDocumentsUrlOperation method run.

@NextcloudServer(max = 18)
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result;
    Utf8PostMethod postMethod = null;
    try {
        postMethod = new Utf8PostMethod(client.getBaseUri() + DOCUMENT_URL + JSON_FORMAT);
        postMethod.setParameter(FILE_ID, fileID);
        // remote request
        postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
        int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
        if (status == HttpStatus.SC_OK) {
            String response = postMethod.getResponseBodyAsString();
            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            String url = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString(NODE_URL);
            result = new RemoteOperationResult(true, postMethod);
            result.setSingleData(url);
        } else {
            result = new RemoteOperationResult(false, postMethod);
            client.exhaustResponse(postMethod.getResponseBodyAsStream());
        }
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Get rich document url for file with id " + fileID + " failed: " + result.getLogMessage(), result.getException());
    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
    }
    return result;
}
Also used : Utf8PostMethod(org.apache.commons.httpclient.methods.Utf8PostMethod) JSONObject(org.json.JSONObject) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) NextcloudServer(com.owncloud.android.utils.NextcloudServer)

Aggregations

NextcloudServer (com.owncloud.android.utils.NextcloudServer)2 Bundle (android.os.Bundle)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 Utf8PostMethod (org.apache.commons.httpclient.methods.Utf8PostMethod)1 JSONObject (org.json.JSONObject)1