moving from eu.alefzero.eu to com.owncloud.android
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / syncadapter / FileSyncAdapter.java
diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java
deleted file mode 100644 (file)
index 39a8831..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/* ownCloud Android client application\r
- *   Copyright (C) 2011  Bartek Przybylski\r
- *\r
- *   This program is free software: you can redistribute it and/or modify\r
- *   it under the terms of the GNU General Public License as published by\r
- *   the Free Software Foundation, either version 3 of the License, or\r
- *   (at your option) any later version.\r
- *\r
- *   This program is distributed in the hope that it will be useful,\r
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- *   GNU General Public License for more details.\r
- *\r
- *   You should have received a copy of the GNU General Public License\r
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
- *\r
- */\r
-\r
-package eu.alefzero.owncloud.syncadapter;\r
-\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Vector;\r
-\r
-import org.apache.jackrabbit.webdav.DavException;\r
-import org.apache.jackrabbit.webdav.MultiStatus;\r
-import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;\r
-\r
-import android.accounts.Account;\r
-import android.accounts.AuthenticatorException;\r
-import android.accounts.OperationCanceledException;\r
-import android.content.ContentProviderClient;\r
-import android.content.Context;\r
-import android.content.Intent;\r
-import android.content.SyncResult;\r
-import android.os.Bundle;\r
-import android.util.Log;\r
-import android.webkit.MimeTypeMap;\r
-import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
-import eu.alefzero.owncloud.datamodel.OCFile;\r
-import eu.alefzero.webdav.WebdavEntry;\r
-\r
-/**\r
- * SyncAdapter implementation for syncing sample SyncAdapter contacts to the\r
- * platform ContactOperations provider.\r
- * \r
- * @author Bartek Przybylski\r
- */\r
-public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {\r
-\r
-    private final static String TAG = "FileSyncAdapter"; \r
-    \r
-    private long mCurrentSyncTime;\r
-    \r
-    public FileSyncAdapter(Context context, boolean autoInitialize) {\r
-        super(context, autoInitialize);\r
-    }\r
-\r
-    @Override\r
-    public synchronized void onPerformSync(Account account, Bundle extras,\r
-            String authority, ContentProviderClient provider,\r
-            SyncResult syncResult) {\r
-\r
-        this.setAccount(account);\r
-        this.setContentProvider(provider);\r
-        this.setStorageManager(new FileDataStorageManager(account,\r
-                getContentProvider()));\r
-        \r
-        Log.d(TAG, "syncing owncloud account " + account.name);\r
-\r
-        sendStickyBroadcast(true, -1);  // starting message to the main IU\r
-\r
-        PropFindMethod query;\r
-        try {\r
-            mCurrentSyncTime = System.currentTimeMillis();\r
-            query = new PropFindMethod(getUri().toString() + "/");\r
-            getClient().executeMethod(query);\r
-            MultiStatus resp = null;\r
-            resp = query.getResponseBodyAsMultiStatus();\r
-\r
-            if (resp.getResponses().length > 0) {\r
-                WebdavEntry we = new WebdavEntry(resp.getResponses()[0], getUri().getPath());\r
-                OCFile file = fillOCFile(we);\r
-                file.setParentId(0);\r
-                getStorageManager().saveFile(file);\r
-                fetchData(getUri().toString(), syncResult, file.getFileId());\r
-            }\r
-        } catch (OperationCanceledException e) {\r
-            e.printStackTrace();\r
-        } catch (AuthenticatorException e) {\r
-            syncResult.stats.numAuthExceptions++;\r
-            e.printStackTrace();\r
-        } catch (IOException e) {\r
-            syncResult.stats.numIoExceptions++;\r
-            e.printStackTrace();\r
-        } catch (DavException e) {\r
-            syncResult.stats.numIoExceptions++;\r
-            e.printStackTrace();\r
-        }\r
-        sendStickyBroadcast(false, -1);        \r
-    }\r
-\r
-    private void fetchData(String uri, SyncResult syncResult, long parentId) {\r
-        try {\r
-            PropFindMethod query = new PropFindMethod(uri);\r
-            getClient().executeMethod(query);\r
-            MultiStatus resp = null;\r
-            resp = query.getResponseBodyAsMultiStatus();\r
-            List<String> paths = new ArrayList<String>();\r
-            List<Long> fileIds = new ArrayList<Long>(); \r
-            for (int i = 1; i < resp.getResponses().length; ++i) {\r
-                WebdavEntry we = new WebdavEntry(resp.getResponses()[i], getUri().getPath());\r
-                OCFile file = fillOCFile(we);\r
-                file.setParentId(parentId);\r
-                getStorageManager().saveFile(file);\r
-                if (parentId == 0)\r
-                    parentId = file.getFileId();\r
-                if (we.contentType().equals("DIR")) {\r
-                    // for recursive fetch later\r
-                    paths.add(we.path());\r
-                    fileIds.add(file.getFileId());\r
-                }\r
-            }\r
-            \r
-            Vector<OCFile> files = getStorageManager().getDirectoryContent(\r
-                    getStorageManager().getFileById(parentId));\r
-            for (OCFile file : files) {\r
-                if (file.getLastSyncDate() != mCurrentSyncTime && file.getLastSyncDate() != 0)\r
-                    getStorageManager().removeFile(file);\r
-            }\r
-            \r
-            // synched folder -> notice to main thread\r
-            sendStickyBroadcast(true, parentId);\r
-\r
-            // recursive fetch\r
-            Iterator<String> pathsIt = paths.iterator();\r
-            Iterator<Long> fileIdsIt = fileIds.iterator();\r
-            while (pathsIt.hasNext()) {\r
-                fetchData(getUri().toString() + pathsIt.next(), syncResult, fileIdsIt.next());\r
-            }\r
-\r
-\r
-        } catch (OperationCanceledException e) {\r
-            e.printStackTrace();\r
-        } catch (AuthenticatorException e) {\r
-            syncResult.stats.numAuthExceptions++;\r
-            e.printStackTrace();\r
-        } catch (IOException e) {\r
-            syncResult.stats.numIoExceptions++;\r
-            e.printStackTrace();\r
-        } catch (DavException e) {\r
-            syncResult.stats.numIoExceptions++;\r
-            e.printStackTrace();\r
-        }\r
-    }\r
-\r
-    private OCFile fillOCFile(WebdavEntry we) {\r
-        OCFile file = new OCFile(we.path());\r
-        file.setCreationTimestamp(we.createTimestamp());\r
-        file.setFileLength(we.contentLength());\r
-        file.setMimetype(we.contentType());\r
-        file.setModificationTimestamp(we.modifiedTimesamp());\r
-        file.setLastSyncDate(mCurrentSyncTime);\r
-        return file;\r
-    }\r
-    \r
-    \r
-    private void sendStickyBroadcast(boolean inProgress, long OCDirId) {\r
-        Intent i = new Intent(FileSyncService.SYNC_MESSAGE);\r
-        i.putExtra(FileSyncService.IN_PROGRESS, inProgress);\r
-        i.putExtra(FileSyncService.ACCOUNT_NAME, getAccount().name);\r
-        if (OCDirId > 0) {\r
-            i.putExtra(FileSyncService.SYNC_FOLDER, OCDirId);\r
-        }\r
-        getContext().sendStickyBroadcast(i);\r
-    }\r
-\r
-}\r