TreeNode.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* ownCloud Android client application
  2. *
  3. * Copyright (C) 2011 Bartek Przybylski
  4. *
  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.
  9. *
  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.
  14. *
  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/>.
  17. *
  18. */
  19. package eu.alefzero.webdav;
  20. import java.util.HashMap;
  21. import java.util.LinkedList;
  22. import java.util.Map.Entry;
  23. import org.w3c.dom.Document;
  24. import android.text.TextUtils;
  25. import android.util.Log;
  26. public class TreeNode {
  27. public enum NodeProperty {
  28. NAME,
  29. PARENT,
  30. PATH,
  31. RESOURCE_TYPE,
  32. CREATE_DATE,
  33. LAST_MODIFIED_DATE,
  34. CONTENT_LENGTH
  35. }
  36. private LinkedList<TreeNode> mChildren;
  37. public TreeNode() {
  38. propertyMap_ = new HashMap<NodeProperty, String>();
  39. mChildren = new LinkedList<TreeNode>();
  40. }
  41. public void setProperty(NodeProperty propertyName, String propertyValue) {
  42. propertyMap_.put(propertyName, propertyValue);
  43. }
  44. public String getProperty(NodeProperty propertyName) {
  45. return propertyMap_.get(propertyName);
  46. }
  47. void refreshData(Document document) {
  48. throw new RuntimeException("Unimplemented refreshData");
  49. }
  50. public String toString() {
  51. String str = "TreeNode {";
  52. for (Entry<NodeProperty, String> e : propertyMap_.entrySet()) {
  53. str += e.getKey() + ": " + e.getValue() + ",";
  54. }
  55. str += "}";
  56. return str;
  57. }
  58. private HashMap<NodeProperty, String> propertyMap_;
  59. public String stripPathFromFilename(String oc_path) {
  60. if (propertyMap_.containsKey(NodeProperty.NAME)) {
  61. String name = propertyMap_.get(NodeProperty.NAME);
  62. name = name.replace(oc_path, "");
  63. String path = "";
  64. String name2 = name;
  65. if (name.endsWith("/")) {
  66. name = name.substring(0, name.length()-1);
  67. }
  68. path = name.substring(0, name.lastIndexOf('/')+1);
  69. name = name.substring(name.lastIndexOf('/')+1);
  70. name = name.replace("%20", " ");
  71. propertyMap_.remove(NodeProperty.NAME);
  72. propertyMap_.put(NodeProperty.NAME, name);
  73. propertyMap_.remove(NodeProperty.PATH);
  74. propertyMap_.put(NodeProperty.PATH, name2);
  75. Log.i("TreeNode", toString());
  76. return path;
  77. }
  78. return null;
  79. }
  80. public LinkedList<TreeNode> getChildList() {
  81. return mChildren;
  82. }
  83. public String[] getChildrenNames() {
  84. String[] names = new String[mChildren.size()];
  85. for (int i = 0; i < mChildren.size(); ++i) {
  86. names[i] = mChildren.get(i).getProperty(NodeProperty.NAME);
  87. }
  88. return names;
  89. }
  90. public boolean hasChildren() {
  91. return !mChildren.isEmpty();
  92. }
  93. }