1 /* ownCloud Android client application 
   3  * Copyright (C) 2011  Bartek Przybylski 
   5  * This program is free software: you can redistribute it and/or modify 
   6  * it under the terms of the GNU General Public License as published by 
   7  * the Free Software Foundation, either version 3 of the License, or 
   8  * (at your option) any later version. 
  10  * This program is distributed in the hope that it will be useful, 
  11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  13  * GNU General Public License for more details. 
  15  * You should have received a copy of the GNU General Public License 
  16  * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  20 package eu
.alefzero
.webdav
; 
  22 import java
.util
.HashMap
; 
  23 import java
.util
.LinkedList
; 
  24 import java
.util
.Map
.Entry
; 
  26 import org
.w3c
.dom
.Document
; 
  28 import android
.text
.TextUtils
; 
  29 import android
.util
.Log
; 
  31 public class TreeNode 
{ 
  32   public enum NodeProperty 
{ 
  42   private LinkedList
<TreeNode
> mChildren
; 
  45     propertyMap_ 
= new HashMap
<NodeProperty
, String
>(); 
  46     mChildren 
= new LinkedList
<TreeNode
>(); 
  49   public void setProperty(NodeProperty propertyName
, String propertyValue
) { 
  50     propertyMap_
.put(propertyName
, propertyValue
); 
  53   public String 
getProperty(NodeProperty propertyName
) { 
  54     return propertyMap_
.get(propertyName
); 
  57   void refreshData(Document document
) { 
  58     throw new RuntimeException("Unimplemented refreshData"); 
  61   public String 
toString() { 
  62     String str 
= "TreeNode {"; 
  63     for (Entry
<NodeProperty
, String
> e 
: propertyMap_
.entrySet()) { 
  64       str 
+= e
.getKey() + ": " + e
.getValue() + ","; 
  70   private HashMap
<NodeProperty
, String
> propertyMap_
; 
  72   public String 
stripPathFromFilename(String oc_path
) { 
  73     if (propertyMap_
.containsKey(NodeProperty
.NAME
)) { 
  74       String name 
= propertyMap_
.get(NodeProperty
.NAME
); 
  75       name 
= name
.replace(oc_path
, ""); 
  77       if (name
.endsWith("/")) { 
  78         name 
= name
.substring(0, name
.length()-1); 
  80       path 
= name
.substring(0, name
.lastIndexOf('/')+1); 
  81       name 
= name
.substring(name
.lastIndexOf('/')+1); 
  82       name 
= name
.replace("%20", " "); 
  83       if (TextUtils
.isEmpty(name
)) { 
  87       propertyMap_
.remove(NodeProperty
.NAME
); 
  88       propertyMap_
.put(NodeProperty
.NAME
, name
); 
  89       propertyMap_
.remove(NodeProperty
.PATH
); 
  90       propertyMap_
.put(NodeProperty
.PATH
, path
); 
  91       Log
.i("TreeNode", toString()); 
  97   public LinkedList
<TreeNode
> getChildList() { 
 101   public String
[] getChildrenNames() { 
 102     String
[] names 
= new String
[mChildren
.size()]; 
 103     for (int i 
= 0; i 
< mChildren
.size(); ++i
) { 
 104       names
[i
] = mChildren
.get(i
).getProperty(NodeProperty
.NAME
); 
 109   public boolean hasChildren() { 
 110     return !mChildren
.isEmpty();