root / web_client / src / gr / grnet / pithos / web / client / tagtree / Tag.java @ 860e552b
History | View | Annotate | Download (6.3 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2011 GRNET S.A. All rights reserved.
|
3 |
*
|
4 |
* Redistribution and use in source and binary forms, with or
|
5 |
* without modification, are permitted provided that the following
|
6 |
* conditions are met:
|
7 |
*
|
8 |
* 1. Redistributions of source code must retain the above
|
9 |
* copyright notice, this list of conditions and the following
|
10 |
* disclaimer.
|
11 |
*
|
12 |
* 2. Redistributions in binary form must reproduce the above
|
13 |
* copyright notice, this list of conditions and the following
|
14 |
* disclaimer in the documentation and/or other materials
|
15 |
* provided with the distribution.
|
16 |
*
|
17 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
* POSSIBILITY OF SUCH DAMAGE.
|
29 |
*
|
30 |
* The views and conclusions contained in the software and
|
31 |
* documentation are those of the authors and should not be
|
32 |
* interpreted as representing official policies, either expressed
|
33 |
* or implied, of GRNET S.A.
|
34 |
*/
|
35 |
|
36 |
package gr.grnet.pithos.web.client.tagtree; |
37 |
|
38 |
import com.google.gwt.http.client.Response; |
39 |
import com.google.gwt.i18n.client.DateTimeFormat; |
40 |
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; |
41 |
import com.google.gwt.json.client.JSONArray; |
42 |
import com.google.gwt.json.client.JSONObject; |
43 |
import com.google.gwt.json.client.JSONParser; |
44 |
import com.google.gwt.json.client.JSONValue; |
45 |
import gr.grnet.pithos.web.client.foldertree.File; |
46 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
47 |
import java.util.Date; |
48 |
import java.util.Iterator; |
49 |
import java.util.LinkedHashSet; |
50 |
import java.util.Set; |
51 |
|
52 |
public class Tag extends Resource { |
53 |
/*
|
54 |
* The name of the tag.
|
55 |
*/
|
56 |
private String name = null; |
57 |
|
58 |
private Set<File> files = new LinkedHashSet<File>(); |
59 |
|
60 |
public Tag() {};
|
61 |
|
62 |
public Tag(String name) { |
63 |
this.name = name;
|
64 |
} |
65 |
|
66 |
public String getName() { |
67 |
return name;
|
68 |
} |
69 |
|
70 |
// public void populate(Response response) {
|
71 |
// String header = response.getHeader("Last-Modified");
|
72 |
// if (header != null)
|
73 |
// lastModified = DateTimeFormat.getFormat(PredefinedFormat.RFC_2822).parse(header);
|
74 |
//
|
75 |
// header = response.getHeader("X-Container-Bytes-Used");
|
76 |
// if (header != null)
|
77 |
// bytesUsed = Long.valueOf(header);
|
78 |
//
|
79 |
// header = response.getHeader("X-Object-Meta-Trash");
|
80 |
// if (header != null && header.equals("true"))
|
81 |
// inTrash = true;
|
82 |
//
|
83 |
// subfolders.clear(); //This is necessary in case we update a pre-existing Tag so that stale subfolders won't show up
|
84 |
// files.clear();
|
85 |
// JSONValue json = JSONParser.parseStrict(response.getText());
|
86 |
// JSONArray array = json.isArray();
|
87 |
// if (array != null) {
|
88 |
// for (int i=0; i<array.size(); i++) {
|
89 |
// JSONObject o = array.get(i).isObject();
|
90 |
// if (o != null) {
|
91 |
// String contentType = unmarshallString(o, "content_type");
|
92 |
// if (o.containsKey("subdir") || (contentType != null && (contentType.startsWith("application/directory") || contentType.startsWith("application/folder")))) {
|
93 |
// Tag f = new Tag();
|
94 |
// f.populate(this, o, container);
|
95 |
// subfolders.add(f);
|
96 |
// }
|
97 |
// else if (!(o.containsKey("x_object_meta_trash") && o.get("x_object_meta_trash").isString().stringValue().equals("true"))) {
|
98 |
// File file = new File();
|
99 |
// file.populate(this, o, container);
|
100 |
// files.add(file);
|
101 |
// }
|
102 |
// }
|
103 |
// }
|
104 |
// //This step is necessary to remove the trashed folders. Trashed folders are added initially because we need to
|
105 |
// //avoid having in the list the virtual folders of the form {"subdir":"folder1"} which have no indication of thrash
|
106 |
// Iterator<Tag> iter = subfolders.iterator();
|
107 |
// while (iter.hasNext()) {
|
108 |
// Tag f = iter.next();
|
109 |
// if (f.isInTrash())
|
110 |
// iter.remove();
|
111 |
// }
|
112 |
// }
|
113 |
// }
|
114 |
//
|
115 |
// public void populate(Tag parent, JSONObject o, String aContainer) {
|
116 |
// this.parent = parent;
|
117 |
// String path = null;
|
118 |
// if (o.containsKey("subdir")) {
|
119 |
// path = unmarshallString(o, "subdir");
|
120 |
// }
|
121 |
// else {
|
122 |
// path = unmarshallString(o, "name");
|
123 |
// lastModified = unmarshallDate(o, "last_modified");
|
124 |
// }
|
125 |
// if (path.endsWith("/"))
|
126 |
// path = path.substring(0, path.length() - 1);
|
127 |
// if (path.contains("/"))
|
128 |
// name = path.substring(path.lastIndexOf("/") + 1, path.length()); //strip the prefix
|
129 |
// else
|
130 |
// name = path;
|
131 |
// if (aContainer != null) {
|
132 |
// container = aContainer;
|
133 |
// prefix = path;
|
134 |
// }
|
135 |
// else {
|
136 |
// container = name;
|
137 |
// prefix = "";
|
138 |
// }
|
139 |
// if (o.containsKey("x_object_meta_trash") && o.get("x_object_meta_trash").isString().stringValue().equals("true"))
|
140 |
// inTrash = true;
|
141 |
// }
|
142 |
//
|
143 |
// public static Tag createFromResponse(Response response, Tag result) {
|
144 |
// Tag f = null;
|
145 |
// if (result == null)
|
146 |
// f = new Tag();
|
147 |
// else
|
148 |
// f = result;
|
149 |
//
|
150 |
// f.populate(response);
|
151 |
// return f;
|
152 |
// }
|
153 |
|
154 |
@Override
|
155 |
public boolean equals(Object other) { |
156 |
if (other instanceof Tag) { |
157 |
Tag o = (Tag) other; |
158 |
return name.equals(o.getName());
|
159 |
} |
160 |
return false; |
161 |
} |
162 |
|
163 |
@Override
|
164 |
public int hashCode() { |
165 |
return name.hashCode();
|
166 |
} |
167 |
|
168 |
public Set<File> getFiles() { |
169 |
return files;
|
170 |
} |
171 |
} |