From: Bartek Przybylski Date: Sun, 29 Apr 2012 09:27:26 +0000 (+0200) Subject: cleanup after jackrabbit, releasing resources X-Git-Tag: oc-android-1.4.3~436 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/2d8300d8347267c1e4e12f8d7518fdc6205dd795?ds=inline cleanup after jackrabbit, releasing resources --- diff --git a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java index e68c54bf..423ce566 100644 --- a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java +++ b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java @@ -53,17 +53,23 @@ public class FileDataStorageManager implements DataStorageManager { @Override public OCFile getFileByPath(String path) { Cursor c = getCursorForValue(ProviderTableMeta.FILE_PATH, path); - if (c.moveToFirst()) - return createFileInstance(c); - return null; + OCFile file = null; + if (c.moveToFirst()) { + file = createFileInstance(c); + c.close(); + } + return file; } @Override public OCFile getFileById(long id) { Cursor c = getCursorForValue(ProviderTableMeta._ID, String.valueOf(id)); - if (c.moveToFirst()) - return createFileInstance(c); - return null; + OCFile file = null; + if (c.moveToFirst()) { + file = createFileInstance(c); + c.close(); + } + return file; } @Override diff --git a/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java index 5314e636..1d23ec82 100644 --- a/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java @@ -21,16 +21,12 @@ package eu.alefzero.owncloud.syncadapter; import java.io.IOException; import java.net.UnknownHostException; import java.util.Date; -import java.util.LinkedList; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.conn.ConnectionKeepAliveStrategy; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import android.accounts.Account; @@ -41,16 +37,10 @@ import android.content.AbstractThreadedSyncAdapter; import android.content.ContentProviderClient; import android.content.Context; import android.net.Uri; -import android.text.TextUtils; -import android.util.Log; import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.datamodel.DataStorageManager; -import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.webdav.HttpPropFind; -import eu.alefzero.webdav.TreeNode; -import eu.alefzero.webdav.TreeNode.NodeProperty; import eu.alefzero.webdav.WebdavClient; -import eu.alefzero.webdav.WebdavUtils; /** * Base SyncAdapter for OwnCloud Designed to be subclassed for the concrete @@ -161,18 +151,6 @@ public abstract class AbstractOwnCloudSyncAdapter extends return null; } - protected TreeNode fireRequest(HttpRequest query) - throws ClientProtocolException, OperationCanceledException, - AuthenticatorException, IOException { - HttpResponse response = fireRawRequest(query); - - TreeNode root = new TreeNode(); - root.setProperty(TreeNode.NodeProperty.NAME, ""); - //this.parseResponse(response, getUri(), getClient(), mHost, - // root.getChildList(), false, 0); - return root; - } - protected Uri getUri() { return Uri.parse(this.getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL)); @@ -198,63 +176,4 @@ public abstract class AbstractOwnCloudSyncAdapter extends return mClient; } - - private void parseResponse(HttpResponse resp, Uri uri, - DefaultHttpClient client, HttpHost targetHost, - LinkedList insertList, boolean sf, long parent_id) - throws IOException, OperationCanceledException, - AuthenticatorException { - boolean skipFirst = sf, override_parent = !sf; - for (TreeNode n : WebdavUtils.parseResponseToNodes(resp.getEntity() - .getContent())) { - if (skipFirst) { - skipFirst = false; - continue; - } - String path = n.stripPathFromFilename(uri.getPath()); - - long mod = n.getProperty(NodeProperty.LAST_MODIFIED_DATE) == null ? 0 - : Long.parseLong(n - .getProperty(NodeProperty.LAST_MODIFIED_DATE)); - - OCFile file = getStorageManager().getFileByPath(n.getProperty(NodeProperty.PATH)); - if (file != null && file.fileExists() && file.getModificationTimestamp() >= mod) { - Log.d(TAG, "No update for file/dir " + file.getFileName() - + " is needed"); - } else { - file = new OCFile(n.getProperty(NodeProperty.PATH)); - Log.d(TAG, "File " + n.getProperty(NodeProperty.PATH) - + " will be " - + (file.fileExists() ? "updated" : "created")); - long len = n.getProperty(NodeProperty.CONTENT_LENGTH) == null ? 0 - : Long.parseLong(n - .getProperty(NodeProperty.CONTENT_LENGTH)); - long create = n.getProperty(NodeProperty.CREATE_DATE) == null ? 0 - : Long.parseLong(n - .getProperty(NodeProperty.CREATE_DATE)); - - file.setFileLength(len); - file.setCreationTimestamp(create); - file.setModificationTimestamp(mod); - file.setMimetype(n.getProperty(NodeProperty.RESOURCE_TYPE)); - file.setParentId(parent_id); - getStorageManager().saveFile(file); - if (override_parent) { - parent_id = file.getFileId(); - override_parent = false; - } - } - - if (!TextUtils.isEmpty(n.getProperty(NodeProperty.NAME)) - && n.getProperty(NodeProperty.RESOURCE_TYPE).equals("DIR")) { - - HttpPropFind method = new HttpPropFind(uri.getPath() + path - + n.getProperty(NodeProperty.NAME).replace(" ", "%20") - + "/"); - HttpResponse response = fireRawRequest(method); - parseResponse(response, uri, client, targetHost, - n.getChildList(), true, file.getFileId()); - } - } - } } \ No newline at end of file diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java index 95c142dd..133e5fc1 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java @@ -31,7 +31,6 @@ import android.content.ContentProviderClient; import android.content.Context; import android.content.SyncResult; import android.os.Bundle; -import android.util.Log; import eu.alefzero.owncloud.datamodel.FileDataStorageManager; import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.webdav.WebdavEntry; @@ -43,7 +42,6 @@ import eu.alefzero.webdav.WebdavEntry; * @author Bartek Przybylski */ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { - private static final String TAG = "FileSyncAdapter"; public FileSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); @@ -72,7 +70,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { OCFile file = fillOCFile(we); file.setParentId(0); getStorageManager().saveFile(file); - Log.d(TAG, file.getPath() + " " + file.getFileId()); fetchData(getUri().toString(), syncResult, file.getFileId()); } } catch (OperationCanceledException e) { diff --git a/src/eu/alefzero/webdav/TreeNode.java b/src/eu/alefzero/webdav/TreeNode.java deleted file mode 100644 index 9e5ed8da..00000000 --- a/src/eu/alefzero/webdav/TreeNode.java +++ /dev/null @@ -1,109 +0,0 @@ -/* ownCloud Android client application - * - * Copyright (C) 2011 Bartek Przybylski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package eu.alefzero.webdav; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map.Entry; - -import org.w3c.dom.Document; - -import android.text.TextUtils; -import android.util.Log; - -public class TreeNode { - public enum NodeProperty { - NAME, - PARENT, - PATH, - RESOURCE_TYPE, - CREATE_DATE, - LAST_MODIFIED_DATE, - CONTENT_LENGTH - } - - private LinkedList mChildren; - - public TreeNode() { - propertyMap_ = new HashMap(); - mChildren = new LinkedList(); - } - - public void setProperty(NodeProperty propertyName, String propertyValue) { - propertyMap_.put(propertyName, propertyValue); - } - - public String getProperty(NodeProperty propertyName) { - return propertyMap_.get(propertyName); - } - - void refreshData(Document document) { - throw new RuntimeException("Unimplemented refreshData"); - } - - public String toString() { - String str = "TreeNode {"; - for (Entry e : propertyMap_.entrySet()) { - str += e.getKey() + ": " + e.getValue() + ","; - } - str += "}"; - return str; - } - - private HashMap propertyMap_; - - public String stripPathFromFilename(String oc_path) { - if (propertyMap_.containsKey(NodeProperty.NAME)) { - String name = propertyMap_.get(NodeProperty.NAME); - name = name.replace(oc_path, ""); - String path = ""; - String name2 = name; - if (name.endsWith("/")) { - name = name.substring(0, name.length()-1); - } - path = name.substring(0, name.lastIndexOf('/')+1); - name = name.substring(name.lastIndexOf('/')+1); - name = name.replace("%20", " "); - - propertyMap_.remove(NodeProperty.NAME); - propertyMap_.put(NodeProperty.NAME, name); - propertyMap_.remove(NodeProperty.PATH); - propertyMap_.put(NodeProperty.PATH, name2); - return path; - } - return null; - } - - public LinkedList getChildList() { - return mChildren; - } - - public String[] getChildrenNames() { - String[] names = new String[mChildren.size()]; - for (int i = 0; i < mChildren.size(); ++i) { - names[i] = mChildren.get(i).getProperty(NodeProperty.NAME); - } - return names; - } - - public boolean hasChildren() { - return !mChildren.isEmpty(); - } -} diff --git a/src/eu/alefzero/webdav/TreeNodeContainer.java b/src/eu/alefzero/webdav/TreeNodeContainer.java deleted file mode 100644 index 5dc8a14c..00000000 --- a/src/eu/alefzero/webdav/TreeNodeContainer.java +++ /dev/null @@ -1,36 +0,0 @@ -/* ownCloud Android client application - * Copyright (C) 2011 Bartek Przybylski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package eu.alefzero.webdav; - -import java.util.List; -import java.util.ListIterator; - -import org.w3c.dom.Document; - -public class TreeNodeContainer extends TreeNode { - - @Override - void refreshData(Document document) { - ListIterator iterator = children_.listIterator(); - while (iterator.hasNext()) { - iterator.next().refreshData(document); - } - } - - private List children_; -} diff --git a/src/eu/alefzero/webdav/TreeNodeFile.java b/src/eu/alefzero/webdav/TreeNodeFile.java deleted file mode 100644 index 8d57cbd3..00000000 --- a/src/eu/alefzero/webdav/TreeNodeFile.java +++ /dev/null @@ -1,42 +0,0 @@ -/* ownCloud Android client application - * Copyright (C) 2011 Bartek Przybylski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package eu.alefzero.webdav; - -import org.w3c.dom.Document; - -public class TreeNodeFile extends TreeNode { - - public TreeNodeFile() { - } - - @Override - void refreshData(Document document) { - /*if (is_pinned_) { - String fullPath = getProperty(NodeProperty.PATH); - if (document.hasChildNodes()) { - Node child = document.getFirstChild(); - do { - - } while ((child = child.getNextSibling()) != null); - } - - //TODO: update file - }*/ - } -} diff --git a/src/eu/alefzero/webdav/WebdavUtils.java b/src/eu/alefzero/webdav/WebdavUtils.java index 9c8bed3c..4fd9b74c 100644 --- a/src/eu/alefzero/webdav/WebdavUtils.java +++ b/src/eu/alefzero/webdav/WebdavUtils.java @@ -37,8 +37,6 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import eu.alefzero.webdav.TreeNode.NodeProperty; - import android.util.Log; public class WebdavUtils { @@ -98,74 +96,4 @@ public class WebdavUtils { } return null; } - - public static List parseResponseToNodes(InputStream response) { - LinkedList rList = new LinkedList(); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder; - try { - builder = factory.newDocumentBuilder(); - Document document = builder.parse(response); - String davPrefix = determineDAVPrefix(document.getDocumentElement()); - - NodeList nodes = document.getElementsByTagName(davPrefix + RESPONSE); - Log.i("WebdavUtils", "Parsing " + nodes.getLength() + " response nodes"); - - for (int i = 0; i < nodes.getLength(); ++i) { - Node currentNode = nodes.item(i); - TreeNode resultNode = new TreeNode(); - parseResourceType(currentNode, resultNode, davPrefix); - parseResourceDates(currentNode, resultNode, davPrefix); - parseDisplayName(currentNode, resultNode, davPrefix); - rList.add(resultNode); - } - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return rList; - } - - private static void parseDisplayName(Node currentNode, TreeNode resultNode, - String davPrefix) { - Element currentElement = (Element) currentNode; - if (currentElement.getElementsByTagName(davPrefix + HREF).getLength() != 0) { - String filepath = currentElement.getElementsByTagName(davPrefix + HREF).item(0).getFirstChild().getNodeValue(); - resultNode.setProperty(NodeProperty.NAME, filepath); - } - } - - private static void parseResourceDates(Node currentNode, TreeNode resultNode, String davPrefix) { - Element currentElement = (Element)currentNode; - if (currentElement.getElementsByTagName(davPrefix + LAST_MODIFIED).getLength() != 0) { - Date date = parseResponseDate( - currentElement.getElementsByTagName(davPrefix + LAST_MODIFIED).item(0).getFirstChild().getNodeValue()); - resultNode.setProperty(NodeProperty.LAST_MODIFIED_DATE, String.valueOf(date.getTime())); - } - if (currentElement.getElementsByTagName(davPrefix + CREATE_DATE).getLength() != 0) { - Date date = parseResponseDate( - currentElement.getElementsByTagName(davPrefix + CREATE_DATE).item(0).getFirstChild().getNodeValue()); - resultNode.setProperty(NodeProperty.CREATE_DATE, String.valueOf(date.getTime())); - } - } - - private static void parseResourceType(Node currentNode, TreeNode resultNode, String davPrefix) { - Element currentElement = (Element)currentNode; - if (currentElement.getElementsByTagName(davPrefix + RESOURCE_TYPE).getLength() != 0 && - currentElement.getElementsByTagName(davPrefix + RESOURCE_TYPE).item(0).hasChildNodes()) { - resultNode.setProperty(NodeProperty.RESOURCE_TYPE, "DIR"); - } else { - if (currentElement.getElementsByTagName(davPrefix + CONTENT_TYPE).getLength() != 0) { - resultNode.setProperty(NodeProperty.RESOURCE_TYPE, - currentElement.getElementsByTagName(davPrefix + CONTENT_TYPE).item(0).getFirstChild().getNodeValue()); - } - if (currentElement.getElementsByTagName(davPrefix + CONTENT_LENGTH).getLength() != 0) { - resultNode.setProperty(NodeProperty.CONTENT_LENGTH, - currentElement.getElementsByTagName(davPrefix + CONTENT_LENGTH).item(0).getFirstChild().getNodeValue()); - } - } - } }