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
, "");
78 if (name
.endsWith("/")) {
79 name
= name
.substring(0, name
.length()-1);
81 path
= name
.substring(0, name
.lastIndexOf('/')+1);
82 name
= name
.substring(name
.lastIndexOf('/')+1);
83 name
= name
.replace("%20", " ");
85 propertyMap_
.remove(NodeProperty
.NAME
);
86 propertyMap_
.put(NodeProperty
.NAME
, name
);
87 propertyMap_
.remove(NodeProperty
.PATH
);
88 propertyMap_
.put(NodeProperty
.PATH
, name2
);
94 public LinkedList
<TreeNode
> getChildList() {
98 public String
[] getChildrenNames() {
99 String
[] names
= new String
[mChildren
.size()];
100 for (int i
= 0; i
< mChildren
.size(); ++i
) {
101 names
[i
] = mChildren
.get(i
).getProperty(NodeProperty
.NAME
);
106 public boolean hasChildren() {
107 return !mChildren
.isEmpty();