root / src / gr / ebs / gss / client / rest / resource / SearchResource.java @ b98ec534
History | View | Annotate | Download (3.4 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* GSS is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.client.rest.resource; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
import java.util.Date; |
23 |
import java.util.LinkedList; |
24 |
import java.util.List; |
25 |
|
26 |
import com.google.gwt.http.client.URL; |
27 |
import com.google.gwt.json.client.JSONArray; |
28 |
import com.google.gwt.json.client.JSONObject; |
29 |
import com.google.gwt.json.client.JSONParser; |
30 |
|
31 |
/**
|
32 |
* @author kman
|
33 |
*/
|
34 |
public class SearchResource extends RestResource { |
35 |
|
36 |
public SearchResource(String aUri) { |
37 |
super(aUri);
|
38 |
} |
39 |
|
40 |
List<FileResource> files = new ArrayList<FileResource>(); |
41 |
List<String> filePaths = new LinkedList<String>(); |
42 |
|
43 |
/**
|
44 |
* Retrieve the files.
|
45 |
*
|
46 |
* @return the files
|
47 |
*/
|
48 |
public List<String> getFilePaths() { |
49 |
return filePaths;
|
50 |
} |
51 |
|
52 |
/**
|
53 |
* Modify the files.
|
54 |
*
|
55 |
* @param newFilePaths the files to set
|
56 |
*/
|
57 |
public void setFilePaths(List<String> newFilePaths) { |
58 |
filePaths = newFilePaths; |
59 |
} |
60 |
|
61 |
/**
|
62 |
* Retrieve the files.
|
63 |
*
|
64 |
* @return the files
|
65 |
*/
|
66 |
public List<FileResource> getFiles() { |
67 |
return files;
|
68 |
} |
69 |
|
70 |
/**
|
71 |
* Modify the files.
|
72 |
*
|
73 |
* @param newFiles the files to set
|
74 |
*/
|
75 |
public void setFiles(List<FileResource> newFiles) { |
76 |
files = newFiles; |
77 |
} |
78 |
|
79 |
@Override
|
80 |
public void createFromJSON(String text) { |
81 |
JSONArray subs = JSONParser.parse(text).isArray(); |
82 |
if (subs != null) |
83 |
for (int i = 0; i < subs.size(); i++) { |
84 |
JSONObject fo = subs.get(i).isObject(); |
85 |
if (fo != null) { |
86 |
String fname = unmarshallString(fo, "name"); |
87 |
String fowner = unmarshallString(fo, "owner"); |
88 |
String fcontent = unmarshallString(fo, "content"); |
89 |
String fpath = unmarshallString(fo, "path"); |
90 |
fpath = URL.decodeComponent(fpath);
|
91 |
Integer fversion = null; |
92 |
if (fo.get("version") != null) |
93 |
fversion = new Integer(fo.get("version").toString()); |
94 |
boolean fdeleted = unmarshallBoolean(fo, "deleted"); |
95 |
Date fcreationDate = null; |
96 |
if (fo.get("creationDate") != null) |
97 |
fcreationDate = new Date(new Long(fo.get("creationDate").toString())); |
98 |
Date fmodificationDate = null; |
99 |
if (fo.get("modificationDate") != null) |
100 |
fmodificationDate = new Date(new Long(fo.get("modificationDate").toString())); |
101 |
String furi = unmarshallString(fo,"uri"); |
102 |
Long fsize = 0L; |
103 |
if(fo.get("size") != null) |
104 |
fsize = new Long(fo.get("size").toString()); |
105 |
filePaths.add(furi); |
106 |
FileResource fs = new FileResource(furi);
|
107 |
fs.setName(fname); |
108 |
fs.setOwner(fowner); |
109 |
fs.setVersion(fversion); |
110 |
fs.setContentLength(fsize); |
111 |
fs.setDeleted(fdeleted); |
112 |
fs.setCreationDate(fcreationDate); |
113 |
fs.setModificationDate(fmodificationDate); |
114 |
fs.setContentType(fcontent); |
115 |
fs.setPath(fpath); |
116 |
files.add(fs); |
117 |
} |
118 |
} |
119 |
} |
120 |
|
121 |
@Override
|
122 |
public String getLastModifiedSince() { |
123 |
return null; |
124 |
} |
125 |
} |