From: Bartek Przybylski Date: Sat, 28 Apr 2012 22:14:01 +0000 (+0200) Subject: initial move to jackrabbit (syncing) X-Git-Tag: oc-android-1.4.3~440 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/87814cec4292fee1303c85dfce68b2d122ffb6b2 initial move to jackrabbit (syncing) --- diff --git a/libs/commons-codec-1.4.jar b/libs/commons-codec-1.4.jar deleted file mode 100644 index 458d432d..00000000 Binary files a/libs/commons-codec-1.4.jar and /dev/null differ diff --git a/libs/commons-httpclient-3.0.1.jar b/libs/commons-httpclient-3.0.1.jar deleted file mode 100644 index cfc777c7..00000000 Binary files a/libs/commons-httpclient-3.0.1.jar and /dev/null differ diff --git a/libs/commons-io-2.0.1.jar b/libs/commons-io-2.0.1.jar deleted file mode 100644 index 5b64b7d6..00000000 Binary files a/libs/commons-io-2.0.1.jar and /dev/null differ diff --git a/libs/commons-logging-1.1.1.jar b/libs/commons-logging-1.1.1.jar deleted file mode 100644 index 1deef144..00000000 Binary files a/libs/commons-logging-1.1.1.jar and /dev/null differ diff --git a/libs/httpclient-4.1.2.jar b/libs/httpclient-4.1.2.jar deleted file mode 100644 index b3cdb4cd..00000000 Binary files a/libs/httpclient-4.1.2.jar and /dev/null differ diff --git a/libs/httpclient-cache-4.1.2.jar b/libs/httpclient-cache-4.1.2.jar deleted file mode 100644 index 6b7bcce5..00000000 Binary files a/libs/httpclient-cache-4.1.2.jar and /dev/null differ diff --git a/libs/httpcore-4.1.2.jar b/libs/httpcore-4.1.2.jar deleted file mode 100644 index 66ae90b0..00000000 Binary files a/libs/httpcore-4.1.2.jar and /dev/null differ diff --git a/libs/httpmime-4.1.2.jar b/libs/httpmime-4.1.2.jar deleted file mode 100644 index eea3b3ff..00000000 Binary files a/libs/httpmime-4.1.2.jar and /dev/null differ diff --git a/libs/not-yet-commons-ssl-0.3.11.jar b/libs/not-yet-commons-ssl-0.3.11.jar deleted file mode 100644 index 7b564277..00000000 Binary files a/libs/not-yet-commons-ssl-0.3.11.jar and /dev/null differ diff --git a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java index 38212785..e862a5a3 100644 --- a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java +++ b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java @@ -124,7 +124,7 @@ public class FileDataStorageManager implements DataStorageManager { file.setFileId(new_id); } } - + if (file.isDirectory() && file.needsUpdatingWhileSaving()) for (OCFile f : getDirectoryContent(file)) saveFile(f); diff --git a/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java index 698fda8b..5314e636 100644 --- a/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java @@ -153,12 +153,12 @@ public abstract class AbstractOwnCloudSyncAdapter extends protected HttpResponse fireRawRequest(HttpRequest query) throws ClientProtocolException, OperationCanceledException, AuthenticatorException, IOException { - BasicHttpContext httpContext = new BasicHttpContext(); + /*BasicHttpContext httpContext = new BasicHttpContext(); BasicScheme basicAuth = new BasicScheme(); httpContext.setAttribute("preemptive-auth", basicAuth); - HttpResponse response = getClient().execute(mHost, query, httpContext); - return response; + HttpResponse response = getClient().execute(mHost, query, httpContext);*/ + return null; } protected TreeNode fireRequest(HttpRequest query) @@ -168,8 +168,8 @@ public abstract class AbstractOwnCloudSyncAdapter extends TreeNode root = new TreeNode(); root.setProperty(TreeNode.NodeProperty.NAME, ""); - this.parseResponse(response, getUri(), getClient(), mHost, - root.getChildList(), false, 0); + //this.parseResponse(response, getUri(), getClient(), mHost, + // root.getChildList(), false, 0); return root; } @@ -178,7 +178,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends AccountAuthenticator.KEY_OC_URL)); } - private DefaultHttpClient getClient() throws OperationCanceledException, + protected WebdavClient getClient() throws OperationCanceledException, AuthenticatorException, IOException { if (mClient == null) { String username = getAccount().name.split("@")[0]; @@ -196,7 +196,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends mHost = mClient.getTargetHost(); } - return mClient.getHttpClient(); + return mClient; } private void parseResponse(HttpResponse resp, Uri uri, diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java index 02920a14..bf480127 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java @@ -21,6 +21,11 @@ package eu.alefzero.owncloud.syncadapter; import java.io.IOException; import org.apache.http.entity.StringEntity; +import org.apache.jackrabbit.webdav.DavException; +import org.apache.jackrabbit.webdav.MultiStatus; +import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; +import org.apache.jackrabbit.webdav.property.DavProperty; +import org.apache.jackrabbit.webdav.property.DavPropertyName; import android.accounts.Account; import android.accounts.AuthenticatorException; @@ -35,10 +40,12 @@ import android.os.Bundle; import android.os.RemoteException; import android.util.Log; import eu.alefzero.owncloud.datamodel.FileDataStorageManager; +import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta; import eu.alefzero.webdav.HttpPropFind; import eu.alefzero.webdav.TreeNode; import eu.alefzero.webdav.TreeNode.NodeProperty; +import eu.alefzero.webdav.WebdavEntry; import eu.alefzero.webdav.WebdavUtils; /** @@ -53,7 +60,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { public FileSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); } - + @Override public synchronized void onPerformSync( Account account, @@ -62,83 +69,43 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { ContentProviderClient provider, SyncResult syncResult) { - try { this.setAccount(account); this.setContentProvider(provider); this.setStorageManager(new FileDataStorageManager(account, getContentProvider())); - HttpPropFind query = this.getPropFindQuery(); - query.setEntity(new StringEntity(WebdavUtils.prepareXmlForPropFind())); - TreeNode root = this.fireRequest(query); - - // commitToDatabase(root, null); - } catch (OperationCanceledException e) { - e.printStackTrace(); - } catch (AuthenticatorException e) { - syncResult.stats.numAuthExceptions++; - e.printStackTrace(); - } catch (IOException e) { - syncResult.stats.numIoExceptions++; - e.printStackTrace(); - }// catch (RemoteException e) { - // e.printStackTrace(); - // q} + fetchData(getUri().toString(), syncResult, 0); } - private void commitToDatabase(TreeNode root, String parentId) throws RemoteException { - for (TreeNode n : root.getChildList()) { - Log.d(TAG, n.toString()); - ContentValues cv = new ContentValues(); - cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, n.getProperty(NodeProperty.CONTENT_LENGTH)); - cv.put(ProviderTableMeta.FILE_MODIFIED, n.getProperty(NodeProperty.LAST_MODIFIED_DATE)); - cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, n.getProperty(NodeProperty.RESOURCE_TYPE)); - cv.put(ProviderTableMeta.FILE_PARENT, parentId); + private void fetchData(String uri, SyncResult syncResult, long parentId) { + try { + PropFindMethod query = new PropFindMethod(uri); + getClient().executeMethod(query); + MultiStatus resp = null; + resp = query.getResponseBodyAsMultiStatus(); + for (int i = (parentId==0?0:1); i < resp.getResponses().length; ++i) { + WebdavEntry we = new WebdavEntry(resp.getResponses()[i]); + OCFile file = new OCFile(we.path()); + file.setCreationTimestamp(we.createTimestamp()); + file.setFileLength(we.contentLength()); + file.setMimetype(we.contentType()); + file.setModificationTimestamp(we.modifiedTimesamp()); + file.setParentId(parentId); + if (we.contentType().equals("DIR")) + fetchData(getUri().toString() + we.path(), syncResult, file.getFileId()); + } - String name = n.getProperty(NodeProperty.NAME), - path = n.getProperty(NodeProperty.PATH); - Cursor c = this.getContentProvider().query(ProviderTableMeta.CONTENT_URI_FILE, - null, - ProviderTableMeta.FILE_NAME+"=? AND " + ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?", - new String[]{name, path, this.getAccount().name}, - null); - if (c.moveToFirst()) { - this.getContentProvider().update(ProviderTableMeta.CONTENT_URI, - cv, - ProviderTableMeta._ID+"=?", - new String[]{c.getString(c.getColumnIndex(ProviderTableMeta._ID))}); - Log.d(TAG, "ID of: "+name+":"+c.getString(c.getColumnIndex(ProviderTableMeta._ID))); - } else { - cv.put(ProviderTableMeta.FILE_NAME, n.getProperty(NodeProperty.NAME)); - cv.put(ProviderTableMeta.FILE_PATH, n.getProperty(NodeProperty.PATH)); - cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, this.getAccount().name); - Uri entry = this.getContentProvider().insert(ProviderTableMeta.CONTENT_URI_FILE, cv); - Log.d(TAG, "Inserting new entry " + path); - c = this.getContentProvider().query(entry, null, null, null, null); - c.moveToFirst(); - } - if (n.getProperty(NodeProperty.RESOURCE_TYPE).equals("DIR")) { - commitToDatabase(n, c.getString(c.getColumnIndex(ProviderTableMeta._ID))); - } - } - // clean removed files - String[] selection = new String[root.getChildList().size()+2]; - selection[0] = this.getAccount().name; - selection[1] = parentId; - String qm = ""; - for (int i = 2; i < selection.length-1; ++i) { - qm += "?,"; - selection[i] = root.getChildList().get(i-2).getProperty(NodeProperty.NAME); - } - if (selection.length >= 3) { - selection[selection.length-1] = root.getChildrenNames()[selection.length-3]; - qm += "?"; - } - for (int i = 0; i < selection.length; ++i) { - Log.d(TAG,selection[i]+""); - } - Log.d(TAG,"Removing files "+ parentId); - this.getContentProvider().delete(ProviderTableMeta.CONTENT_URI, - ProviderTableMeta.FILE_ACCOUNT_OWNER+"=? AND " + ProviderTableMeta.FILE_PARENT + (parentId==null?" IS ":"=")+"? AND " + ProviderTableMeta.FILE_NAME + " NOT IN ("+qm+")", - selection); - } + } catch (OperationCanceledException e) { + e.printStackTrace(); + } catch (AuthenticatorException e) { + syncResult.stats.numAuthExceptions++; + e.printStackTrace(); + } catch (IOException e) { + syncResult.stats.numIoExceptions++; + e.printStackTrace(); + } catch (DavException e) { + syncResult.stats.numIoExceptions++; + e.printStackTrace(); + } + } + } diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java index fa3e9046..452eca01 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java @@ -104,6 +104,7 @@ public class FileListFragment extends FragmentListView { String s = "/"; for (String a : mDirNames) s+= a + "/"; + Log.e("ASD", s); mStorageManager = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); OCFile file = mStorageManager.getFileByPath(s); diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 0a5295b1..f03b7a97 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -22,12 +22,14 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.HttpVersion; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPut; import org.apache.http.conn.ClientConnectionManager; @@ -38,7 +40,6 @@ import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.FileEntity; -import org.apache.http.entity.mime.content.FileBody; import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; @@ -53,12 +54,13 @@ import eu.alefzero.webdav.HttpMkCol; import android.net.Uri; import android.util.Log; -public class WebdavClient { +public class WebdavClient extends HttpClient { private DefaultHttpClient mHttpClient; private BasicHttpContext mHttpContext; private HttpHost mTargetHost; private SchemeRegistry mSchemeRegistry; - private Uri mUri; + private Uri mUri; + private Credentials mCredentials; final private static String TAG = "WebdavClient"; public DefaultHttpClient getHttpClient() { @@ -78,15 +80,17 @@ public class WebdavClient { // determine default port for http or https int targetPort = mTargetHost.getPort() == -1 ? ( mUri.getScheme().equals("https") ? 443 : 80) - : mUri.getPort(); - - mHttpClient.getCredentialsProvider().setCredentials( - new AuthScope(mUri.getHost(), targetPort), - new UsernamePasswordCredentials(username, password)); - BasicScheme basicAuth = new BasicScheme(); - mHttpContext.setAttribute("preemptive-auth", basicAuth); + : mUri.getPort(); + + getParams().setAuthenticationPreemptive(true); + getState().setCredentials(AuthScope.ANY, getCredentials(username, password)); } + private Credentials getCredentials(String username, String password) { + if (mCredentials == null) + mCredentials = new UsernamePasswordCredentials(username, password); + return mCredentials; + } public void allowUnsignedCertificates() { // https mSchemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); diff --git a/src/eu/alefzero/webdav/WebdavEntry.java b/src/eu/alefzero/webdav/WebdavEntry.java new file mode 100644 index 00000000..2c7f378b --- /dev/null +++ b/src/eu/alefzero/webdav/WebdavEntry.java @@ -0,0 +1,101 @@ +package eu.alefzero.webdav; + +import java.util.Date; + +import org.apache.jackrabbit.webdav.MultiStatusResponse; +import org.apache.jackrabbit.webdav.property.DavProperty; +import org.apache.jackrabbit.webdav.property.DavPropertyName; +import org.apache.jackrabbit.webdav.property.DavPropertySet; + +import android.util.Log; + +public class WebdavEntry { + private String mName, mPath, mUri, mContentType; + private long mContentLength, mCreateTimestamp, mModifiedTimestamp; + + public WebdavEntry(MultiStatusResponse ms) { + resetData(); + if (ms.getStatus().length != 0) { + mUri = ms.getHref(); + + mPath = mUri.split("webdav.php", 2)[1]; + + int status = ms.getStatus()[0].getStatusCode(); + DavPropertySet propSet = ms.getProperties(status); + @SuppressWarnings("rawtypes") + DavProperty prop = propSet.get(DavPropertyName.DISPLAYNAME); + if (prop != null) mName = (String) prop.getName().toString(); + else { + String[] tmp = mPath.split("/"); + if (tmp.length > 0) + mName = tmp[tmp.length-1]; + } + + prop = propSet.get(DavPropertyName.GETCONTENTTYPE); + if (prop != null) { + mContentType = (String) prop.getValue(); + } else { + mContentType = "DIR"; + /*prop = propSet.get(DavPropertyName.ISCOLLECTION); + if (prop != null && Boolean.parseBoolean((String) prop.getValue())) + mContentType = "DIR";*/ + } + + prop = propSet.get(DavPropertyName.GETCONTENTLENGTH); + if (prop != null) + mContentLength = Long.parseLong((String) prop.getValue()); + + prop = propSet.get(DavPropertyName.GETLASTMODIFIED); + if (prop != null) { + Date d = WebdavUtils.parseResponseDate((String)prop.getValue()); + mModifiedTimestamp = (d != null) ? d.getTime() : 0; + } + + prop = propSet.get(DavPropertyName.CREATIONDATE); + if (prop != null) { + Date d = WebdavUtils.parseResponseDate((String)prop.getValue()); + mCreateTimestamp = (d != null) ? d.getTime() : 0; + } + + } else { + Log.e("WebdavEntry", "General fuckup, no status for webdav response"); + } + } + + public String path() { + return mPath; + } + + public String name() { + return mName; + } + + public boolean isDirectory() { + return mContentType.equals("DIR"); + } + + public String contentType() { + return mContentType; + } + + public String uri() { + return mUri; + } + + public long contentLength() { + return mContentLength; + } + + public long createTimestamp() { + return mCreateTimestamp; + } + + public long modifiedTimesamp() { + return mModifiedTimestamp; + } + + private void resetData() { + mName = mUri = mContentType = null; + mContentLength = mCreateTimestamp = mModifiedTimestamp = 0; + } +} diff --git a/src/eu/alefzero/webdav/WebdavUtils.java b/src/eu/alefzero/webdav/WebdavUtils.java index 5c75e669..9c8bed3c 100644 --- a/src/eu/alefzero/webdav/WebdavUtils.java +++ b/src/eu/alefzero/webdav/WebdavUtils.java @@ -78,7 +78,7 @@ public class WebdavUtils { return ""; } - private static Date parseResponseDate(String date) { + public static Date parseResponseDate(String date) { Date returnDate = null; for (int i = 0; i < DATETIME_FORMATS.length; ++i) { try {