Revision 1ac430a1 web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java

b/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java
11 11
import com.google.gwt.json.client.JSONObject;
12 12
import com.google.gwt.json.client.JSONParser;
13 13
import com.google.gwt.json.client.JSONValue;
14
import java.util.ArrayList;
15 14
import java.util.Date;
16 15
import java.util.LinkedHashSet;
17
import java.util.List;
18 16
import java.util.Set;
19
import org.w3c.css.sac.ElementSelector;
20 17

  
21 18
public class Folder extends Resource {
19
    /*
20
     * The name of the folder. If the folder is a container this is its name. If it is a virtual folder this is the
21
     * last part of its path
22
     */
22 23
    private String name = null;
23 24

  
24 25
    private Date lastModified = null;
......
26 27
    private long bytesUsed = 0;
27 28

  
28 29
    private Set<Folder> subfolders = new LinkedHashSet<Folder>();
30
    /*
31
     * The name of the container that this folder belongs to. If this folder is container, this field equals name
32
     */
29 33
    private String container = null;
30 34

  
35
    /*
36
     * This is the full path of the folder (prefix is a misnomer but it was named so because this is used as a prefix=
37
     * parameter in the request that fetches its children). If the folder is a cointainer this is empty string
38
     */
31 39
    private String prefix = "";
32 40

  
33 41
    public Folder() {};
......
64 72
        return container;
65 73
    }
66 74

  
67
    public void setContainer(String container) {
68
        this.container = container;
69
    }
70

  
71 75
    public String getPrefix() {
72 76
        return prefix;
73 77
    }
......
91 95
            for (int i=0; i<array.size(); i++) {
92 96
                JSONObject o = array.get(i).isObject();
93 97
                if (o != null) {
94
                    if (o.containsKey("subdir")) {
98
                    String contentType = unmarshallString(o, "content_type");
99
                    if (o.containsKey("subdir") || (contentType != null && contentType.startsWith("application/directory"))) {
95 100
                        Folder f = new Folder();
96
                        f.populate(o);
97
                        f.setContainer(container == null ? name : container);
98
                        f.setPrefix(container == null ? f.getName() : prefix + "/" + f.getName());
101
                        f.populate(o, container);
99 102
                        subfolders.add(f);
100 103
                    }
101 104
                    else {
102
                        String contentType = unmarshallString(o, "content_type");
103
                        if (contentType != null && contentType.startsWith("application/directory")) {
104
                            Folder f = new Folder();
105
                            f.populate(o);
106
                            f.setContainer(container == null ? name : container);
107
                            f.setPrefix(container == null ? f.getName() : prefix + "/" + f.getName());
108
                            subfolders.add(f);
109
                        }
110
                        else {
111
                            // add file
112
                        }
105
                        // add file
113 106
                    }
114 107
                }
115 108
            }
116 109
        }
117 110
    }
118 111

  
119
    public void populate(JSONObject o) {
112
    public void populate(JSONObject o, String aContainer) {
113
        String path = null;
120 114
        if (o.containsKey("subdir")) {
121
            name = unmarshallString(o, "subdir");
122
            if (name.endsWith("/"))
123
                name = name.substring(0, name.length() - 1);
115
            path = unmarshallString(o, "subdir");
124 116
        }
125 117
        else {
126
            name = unmarshallString(o, "name");
118
            path = unmarshallString(o, "name");
127 119
            lastModified = unmarshallDate(o, "last_modified");
128 120
        }
121
        if (path.endsWith("/"))
122
            path = path.substring(0, path.length() - 1);
123
        if (path.contains("/"))
124
            name = path.substring(path.lastIndexOf("/") + 1, path.length()); //strip the prefix
125
        else
126
            name = path;
127
        if (aContainer != null) {
128
            container = aContainer;
129
            prefix = path;
130
        }
131
        else {
132
            container = name;
133
            prefix = "";
134
        }
129 135
    }
130 136

  
131 137
    @Override
......
148 154
    public boolean equals(Object other) {
149 155
        if (other instanceof Folder) {
150 156
            Folder o = (Folder) other;
151
            return name.equals(o.getName()) && prefix.equals(o.getPrefix());
157
            if (container != null)
158
                return prefix.equals(o.getPrefix()) && container.equals(o.getContainer());
159
            else
160
                return o.getContainer() == null && name.equals(o.getName());
152 161
        }
153 162
        return false;
154 163
    }

Also available in: Unified diff