예제 #1
0
    public void run() {
      WebdavClient wc =
          OwnCloudClientUtils.createOwnCloudClient(
              mAccount, getSherlockActivity().getApplicationContext());
      AccountManager am = AccountManager.get(getSherlockActivity());
      String baseUrl = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL);
      OwnCloudVersion ocv =
          new OwnCloudVersion(am.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));
      String webdav_path = AccountUtils.getWebdavPath(ocv);
      Log.d("ASD", "" + baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath()));

      Log.e(
          "ASD",
          Uri.parse(baseUrl).getPath() == null
              ? ""
              : Uri.parse(baseUrl).getPath()
                  + webdav_path
                  + WebdavUtils.encodePath(mNew.getRemotePath()));
      LocalMoveMethod move =
          new LocalMoveMethod(
              baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath()),
              Uri.parse(baseUrl).getPath() == null
                  ? ""
                  : Uri.parse(baseUrl).getPath()
                      + webdav_path
                      + WebdavUtils.encodePath(mNew.getRemotePath()));

      boolean success = false;
      try {
        int status = wc.executeMethod(move);
        success = move.succeeded();
        move.getResponseBodyAsString(); // exhaust response, although not interesting
        Log.d(TAG, "Move returned status: " + status);

      } catch (HttpException e) {
        Log.e(
            TAG,
            "HTTP Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(),
            e);

      } catch (IOException e) {
        Log.e(
            TAG,
            "I/O Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(),
            e);

      } catch (Exception e) {
        Log.e(
            TAG,
            "Unexpected exception renaming file "
                + mOld.getRemotePath()
                + " to "
                + mNew.getRemotePath(),
            e);

      } finally {
        move.releaseConnection();
      }

      if (success) {
        FileDataStorageManager fdsm =
            new FileDataStorageManager(mAccount, getActivity().getContentResolver());
        fdsm.removeFile(mOld, false);
        fdsm.saveFile(mNew);
        mFile = mNew;
        mHandler.post(
            new Runnable() {
              @Override
              public void run() {
                boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
                getActivity()
                    .dismissDialog(
                        (inDisplayActivity)
                            ? FileDisplayActivity.DIALOG_SHORT_WAIT
                            : FileDetailActivity.DIALOG_SHORT_WAIT);
                updateFileDetails(mFile, mAccount);
                mContainerActivity.onFileStateChanged();
              }
            });

      } else {
        mHandler.post(
            new Runnable() {
              @Override
              public void run() {
                // undo the local rename
                if (mNew.isDown()) {
                  File f = new File(mNew.getStoragePath());
                  if (!f.renameTo(new File(mOld.getStoragePath()))) {
                    // the local rename undoing failed; last chance: save the new local storage path
                    // in the old file
                    mFile.setStoragePath(mNew.getStoragePath());
                    FileDataStorageManager fdsm =
                        new FileDataStorageManager(mAccount, getActivity().getContentResolver());
                    fdsm.saveFile(mFile);
                  }
                }
                boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
                getActivity()
                    .dismissDialog(
                        (inDisplayActivity)
                            ? FileDisplayActivity.DIALOG_SHORT_WAIT
                            : FileDetailActivity.DIALOG_SHORT_WAIT);
                try {
                  Toast msg =
                      Toast.makeText(
                          getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
                  msg.show();

                } catch (NotFoundException e) {
                  e.printStackTrace();
                }
              }
            });
      }
    }
예제 #2
0
    public void run() {
      AccountManager am = AccountManager.get(getActivity());
      Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
      OwnCloudVersion ocv =
          new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
      String url =
          am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL)
              + AccountUtils.getWebdavPath(ocv);

      Log.d("share", "sharing for version " + ocv.toString());

      if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {
        String APPS_PATH = "/apps/files_sharing/";
        String SHARE_PATH = "ajax/share.php";

        String SHARED_PATH = "/apps/files_sharing/get.php?token=";

        final String WEBDAV_SCRIPT = "webdav.php";
        final String WEBDAV_FILES_LOCATION = "/files/";

        WebdavClient wc =
            OwnCloudClientUtils.createOwnCloudClient(
                account, getActivity().getApplicationContext());
        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
        params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);

        // wc.getParams().setParameter("http.protocol.single-cookie-header", true);
        // wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

        PostMethod post =
            new PostMethod(
                am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL)
                    + APPS_PATH
                    + SHARE_PATH);

        post.addRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
        post.addRequestHeader(
            "Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Log.d("share", mPath + "");
        formparams.add(new BasicNameValuePair("sources", mPath));
        formparams.add(new BasicNameValuePair("uid_shared_with", "public"));
        formparams.add(new BasicNameValuePair("permissions", "0"));
        post.setRequestEntity(
            new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));

        int status;
        try {
          PropFindMethod find = new PropFindMethod(url + "/");
          find.addRequestHeader(
              "Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
          Log.d("sharer", "" + url + "/");

          for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {
            Log.d("sharer-h", a.getName() + ":" + a.getValue());
          }

          int status2 = wc.executeMethod(find);

          Log.d("sharer", "propstatus " + status2);

          GetMethod get =
              new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");
          get.addRequestHeader(
              "Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));

          status2 = wc.executeMethod(get);

          Log.d("sharer", "getstatus " + status2);
          Log.d("sharer", "" + get.getResponseBodyAsString());

          for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {
            Log.d("sharer", a.getName() + ":" + a.getValue());
          }

          status = wc.executeMethod(post);
          for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {
            Log.d("sharer-h", a.getName() + ":" + a.getValue());
          }
          for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {
            Log.d("sharer", a.getName() + ":" + a.getValue());
          }
          String resp = post.getResponseBodyAsString();
          Log.d("share", "" + post.getURI().toString());
          Log.d("share", "returned status " + status);
          Log.d("share", " " + resp);

          if (status != HttpStatus.SC_OK
              || resp == null
              || resp.equals("")
              || resp.startsWith("false")) {
            return;
          }

          JSONObject jsonObject = new JSONObject(resp);
          String jsonStatus = jsonObject.getString("status");
          if (!jsonStatus.equals("success"))
            throw new Exception("Error while sharing file status != success");

          String token = jsonObject.getString("data");
          String uri =
              am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token;
          Log.d("Actions:shareFile ok", "url: " + uri);

        } catch (Exception e) {
          e.printStackTrace();
        }

      } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {

      }
    }
예제 #3
0
    public void run() {
      WebdavClient wc =
          OwnCloudClientUtils.createOwnCloudClient(
              mAccount, getSherlockActivity().getApplicationContext());
      AccountManager am = AccountManager.get(getSherlockActivity());
      String baseUrl = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL);
      OwnCloudVersion ocv =
          new OwnCloudVersion(am.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));
      String webdav_path = AccountUtils.getWebdavPath(ocv);
      Log.d(
          "ASD",
          "" + baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath()));

      DeleteMethod delete =
          new DeleteMethod(
              baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath()));

      boolean success = false;
      int status = -1;
      try {
        status = wc.executeMethod(delete);
        success = (delete.succeeded());
        delete.getResponseBodyAsString(); // exhaust the response, although not interesting
        Log.d(TAG, "Delete: returned status " + status);

      } catch (HttpException e) {
        Log.e(TAG, "HTTP Exception removing file " + mFileToRemove.getRemotePath(), e);

      } catch (IOException e) {
        Log.e(TAG, "I/O Exception removing file " + mFileToRemove.getRemotePath(), e);

      } catch (Exception e) {
        Log.e(TAG, "Unexpected exception removing file " + mFileToRemove.getRemotePath(), e);

      } finally {
        delete.releaseConnection();
      }

      if (success) {
        FileDataStorageManager fdsm =
            new FileDataStorageManager(mAccount, getActivity().getContentResolver());
        fdsm.removeFile(mFileToRemove, true);
        mHandler.post(
            new Runnable() {
              @Override
              public void run() {
                boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
                getActivity()
                    .dismissDialog(
                        (inDisplayActivity)
                            ? FileDisplayActivity.DIALOG_SHORT_WAIT
                            : FileDetailActivity.DIALOG_SHORT_WAIT);
                try {
                  Toast msg =
                      Toast.makeText(
                          getActivity().getApplicationContext(),
                          R.string.remove_success_msg,
                          Toast.LENGTH_LONG);
                  msg.show();
                  if (inDisplayActivity) {
                    // double pane
                    FragmentTransaction transaction =
                        getActivity().getSupportFragmentManager().beginTransaction();
                    transaction.replace(
                        R.id.file_details_container,
                        new FileDetailFragment(null, null)); // empty FileDetailFragment
                    transaction.commit();
                    mContainerActivity.onFileStateChanged();

                  } else {
                    getActivity().finish();
                  }

                } catch (NotFoundException e) {
                  e.printStackTrace();
                }
              }
            });

      } else {
        mHandler.post(
            new Runnable() {
              @Override
              public void run() {
                boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
                getActivity()
                    .dismissDialog(
                        (inDisplayActivity)
                            ? FileDisplayActivity.DIALOG_SHORT_WAIT
                            : FileDetailActivity.DIALOG_SHORT_WAIT);
                try {
                  Toast msg =
                      Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG);
                  msg.show();

                } catch (NotFoundException e) {
                  e.printStackTrace();
                }
              }
            });
      }
    }