Просмотр исходного кода

cleanup after jackrabbit, releasing resources

Bartek Przybylski 13 лет назад
Родитель
Сommit
2d8300d834

+ 12 - 6
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

+ 0 - 81
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<TreeNode> 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());
-			}
-		}
-	}
 }

+ 0 - 3
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) {

+ 0 - 109
src/eu/alefzero/webdav/TreeNode.java

@@ -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();
-  }
-}

+ 0 - 36
src/eu/alefzero/webdav/TreeNodeContainer.java

@@ -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 <http://www.gnu.org/licenses/>.
- *
- */
-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<TreeNode> iterator = children_.listIterator();
-    while (iterator.hasNext()) {
-      iterator.next().refreshData(document);
-    }
-  }
-  
-  private List<TreeNode> children_;
-}

+ 0 - 42
src/eu/alefzero/webdav/TreeNodeFile.java

@@ -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
-    }*/
-  }
-}

+ 0 - 72
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<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());
-      }
-    }
-  }
 }