cleanup after jackrabbit, releasing resources
authorBartek Przybylski <bart.p.pl@gmail.com>
Sun, 29 Apr 2012 09:27:26 +0000 (11:27 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Sun, 29 Apr 2012 09:27:26 +0000 (11:27 +0200)
src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java
src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java
src/eu/alefzero/webdav/TreeNode.java [deleted file]
src/eu/alefzero/webdav/TreeNodeContainer.java [deleted file]
src/eu/alefzero/webdav/TreeNodeFile.java [deleted file]
src/eu/alefzero/webdav/WebdavUtils.java

index e68c54b..423ce56 100644 (file)
@@ -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
index 5314e63..1d23ec8 100644 (file)
@@ -21,16 +21,12 @@ package eu.alefzero.owncloud.syncadapter;
 import java.io.IOException;\r
 import java.net.UnknownHostException;\r
 import java.util.Date;\r
-import java.util.LinkedList;\r
 \r
 import org.apache.http.HttpHost;\r
 import org.apache.http.HttpRequest;\r
 import org.apache.http.HttpResponse;\r
 import org.apache.http.client.ClientProtocolException;\r
 import org.apache.http.conn.ConnectionKeepAliveStrategy;\r
-import org.apache.http.impl.auth.BasicScheme;\r
-import org.apache.http.impl.client.DefaultHttpClient;\r
-import org.apache.http.protocol.BasicHttpContext;\r
 import org.apache.http.protocol.HttpContext;\r
 \r
 import android.accounts.Account;\r
@@ -41,16 +37,10 @@ import android.content.AbstractThreadedSyncAdapter;
 import android.content.ContentProviderClient;\r
 import android.content.Context;\r
 import android.net.Uri;\r
-import android.text.TextUtils;\r
-import android.util.Log;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
 import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
-import eu.alefzero.owncloud.datamodel.OCFile;\r
 import eu.alefzero.webdav.HttpPropFind;\r
-import eu.alefzero.webdav.TreeNode;\r
-import eu.alefzero.webdav.TreeNode.NodeProperty;\r
 import eu.alefzero.webdav.WebdavClient;\r
-import eu.alefzero.webdav.WebdavUtils;\r
 \r
 /**\r
  * Base SyncAdapter for OwnCloud Designed to be subclassed for the concrete\r
@@ -161,18 +151,6 @@ public abstract class AbstractOwnCloudSyncAdapter extends
                return null;\r
        }\r
 \r
-       protected TreeNode fireRequest(HttpRequest query)\r
-                       throws ClientProtocolException, OperationCanceledException,\r
-                       AuthenticatorException, IOException {\r
-               HttpResponse response = fireRawRequest(query);\r
-\r
-               TreeNode root = new TreeNode();\r
-               root.setProperty(TreeNode.NodeProperty.NAME, "");\r
-               //this.parseResponse(response, getUri(), getClient(), mHost,\r
-               //              root.getChildList(), false, 0);\r
-               return root;\r
-       }\r
-\r
        protected Uri getUri() {\r
                return Uri.parse(this.getAccountManager().getUserData(getAccount(),\r
                                AccountAuthenticator.KEY_OC_URL));\r
@@ -198,63 +176,4 @@ public abstract class AbstractOwnCloudSyncAdapter extends
 \r
                return mClient;\r
        }\r
-\r
-       private void parseResponse(HttpResponse resp, Uri uri,\r
-                       DefaultHttpClient client, HttpHost targetHost,\r
-                       LinkedList<TreeNode> insertList, boolean sf, long parent_id)\r
-                       throws IOException, OperationCanceledException,\r
-                       AuthenticatorException {\r
-               boolean skipFirst = sf, override_parent = !sf;\r
-               for (TreeNode n : WebdavUtils.parseResponseToNodes(resp.getEntity()\r
-                               .getContent())) {\r
-                       if (skipFirst) {\r
-                               skipFirst = false;\r
-                               continue;\r
-                       }\r
-                       String path = n.stripPathFromFilename(uri.getPath());\r
-\r
-                       long mod = n.getProperty(NodeProperty.LAST_MODIFIED_DATE) == null ? 0\r
-                                       : Long.parseLong(n\r
-                                                       .getProperty(NodeProperty.LAST_MODIFIED_DATE));\r
-                       \r
-                       OCFile file = getStorageManager().getFileByPath(n.getProperty(NodeProperty.PATH));\r
-                       if (file != null && file.fileExists() && file.getModificationTimestamp() >= mod) {\r
-                               Log.d(TAG, "No update for file/dir " + file.getFileName()\r
-                                               + " is needed");\r
-                       } else {\r
-                         file = new OCFile(n.getProperty(NodeProperty.PATH));\r
-                               Log.d(TAG, "File " + n.getProperty(NodeProperty.PATH)\r
-                                               + " will be "\r
-                                               + (file.fileExists() ? "updated" : "created"));\r
-                               long len = n.getProperty(NodeProperty.CONTENT_LENGTH) == null ? 0\r
-                                               : Long.parseLong(n\r
-                                                               .getProperty(NodeProperty.CONTENT_LENGTH));\r
-                               long create = n.getProperty(NodeProperty.CREATE_DATE) == null ? 0\r
-                                               : Long.parseLong(n\r
-                                                               .getProperty(NodeProperty.CREATE_DATE));\r
-\r
-                               file.setFileLength(len);\r
-                               file.setCreationTimestamp(create);\r
-                               file.setModificationTimestamp(mod);\r
-                               file.setMimetype(n.getProperty(NodeProperty.RESOURCE_TYPE));\r
-                               file.setParentId(parent_id);\r
-                               getStorageManager().saveFile(file);\r
-                               if (override_parent) {\r
-                                       parent_id = file.getFileId();\r
-                                       override_parent = false;\r
-                               }\r
-                       }\r
-\r
-                       if (!TextUtils.isEmpty(n.getProperty(NodeProperty.NAME))\r
-                                       && n.getProperty(NodeProperty.RESOURCE_TYPE).equals("DIR")) {\r
-\r
-                               HttpPropFind method = new HttpPropFind(uri.getPath() + path\r
-                                               + n.getProperty(NodeProperty.NAME).replace(" ", "%20")\r
-                                               + "/");\r
-                               HttpResponse response = fireRawRequest(method);\r
-                               parseResponse(response, uri, client, targetHost,\r
-                                               n.getChildList(), true, file.getFileId());\r
-                       }\r
-               }\r
-       }\r
 }
\ No newline at end of file
index 95c142d..133e5fc 100644 (file)
@@ -31,7 +31,6 @@ import android.content.ContentProviderClient;
 import android.content.Context;\r
 import android.content.SyncResult;\r
 import android.os.Bundle;\r
-import android.util.Log;\r
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
 import eu.alefzero.webdav.WebdavEntry;\r
@@ -43,7 +42,6 @@ import eu.alefzero.webdav.WebdavEntry;
  * @author Bartek Przybylski\r
  */\r
 public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {\r
-       private static final String TAG = "FileSyncAdapter";\r
 \r
        public FileSyncAdapter(Context context, boolean autoInitialize) {\r
                super(context, autoInitialize);\r
@@ -72,7 +70,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
           OCFile file = fillOCFile(we);\r
           file.setParentId(0);\r
           getStorageManager().saveFile(file);\r
-          Log.d(TAG, file.getPath() + " " + file.getFileId());\r
           fetchData(getUri().toString(), syncResult, file.getFileId());\r
         }\r
       } catch (OperationCanceledException e) {\r
diff --git a/src/eu/alefzero/webdav/TreeNode.java b/src/eu/alefzero/webdav/TreeNode.java
deleted file mode 100644 (file)
index 9e5ed8d..0000000
+++ /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 <http://www.gnu.org/licenses/>.
- *
- */
-
-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<TreeNode> mChildren;
-  
-  public TreeNode() {
-    propertyMap_ = new HashMap<NodeProperty, String>();
-    mChildren = new LinkedList<TreeNode>();
-  }
-  
-  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<NodeProperty, String> e : propertyMap_.entrySet()) {
-      str += e.getKey() + ": " + e.getValue() + ",";
-    }
-    str += "}";
-    return str;
-  }
-  
-  private HashMap<NodeProperty, String> 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<TreeNode> 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 (file)
index 5dc8a14..0000000
+++ /dev/null
@@ -1,36 +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
-package eu.alefzero.webdav;\r
-\r
-import java.util.List;\r
-import java.util.ListIterator;\r
-\r
-import org.w3c.dom.Document;\r
-\r
-public class TreeNodeContainer extends TreeNode {\r
-  \r
-  @Override\r
-  void refreshData(Document document) {\r
-    ListIterator<TreeNode> iterator = children_.listIterator();\r
-    while (iterator.hasNext()) {\r
-      iterator.next().refreshData(document);\r
-    }\r
-  }\r
-  \r
-  private List<TreeNode> children_;\r
-}\r
diff --git a/src/eu/alefzero/webdav/TreeNodeFile.java b/src/eu/alefzero/webdav/TreeNodeFile.java
deleted file mode 100644 (file)
index 8d57cbd..0000000
+++ /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 <http://www.gnu.org/licenses/>.
- *
- */
-
-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
-    }*/
-  }
-}
index 9c8bed3..4fd9b74 100644 (file)
@@ -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<TreeNode> parseResponseToNodes(InputStream response) {
-    LinkedList<TreeNode> rList = new LinkedList<TreeNode>();
-    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());
-      }
-    }
-  }
 }