Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / rest / resource / RestResource.java @ 44d84dc0

History | View | Annotate | Download (2.1 kB)

1 a52ea5e4 pastith
/*
2 b98ec534 Natasa Kapravelou
 * Copyright 2009, 2010 Electronic Business Systems Ltd.
3 a52ea5e4 pastith
 *
4 a52ea5e4 pastith
 * This file is part of GSS.
5 a52ea5e4 pastith
 *
6 a52ea5e4 pastith
 * GSS is free software: you can redistribute it and/or modify
7 a52ea5e4 pastith
 * it under the terms of the GNU General Public License as published by
8 a52ea5e4 pastith
 * the Free Software Foundation, either version 3 of the License, or
9 a52ea5e4 pastith
 * (at your option) any later version.
10 a52ea5e4 pastith
 *
11 a52ea5e4 pastith
 * GSS is distributed in the hope that it will be useful,
12 a52ea5e4 pastith
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 a52ea5e4 pastith
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 a52ea5e4 pastith
 * GNU General Public License for more details.
15 a52ea5e4 pastith
 *
16 a52ea5e4 pastith
 * You should have received a copy of the GNU General Public License
17 a52ea5e4 pastith
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 a52ea5e4 pastith
 */
19 a52ea5e4 pastith
package gr.ebs.gss.client.rest.resource;
20 a52ea5e4 pastith
21 a52ea5e4 pastith
import java.io.Serializable;
22 a52ea5e4 pastith
23 a52ea5e4 pastith
import com.google.gwt.json.client.JSONObject;
24 c5070ebe Natasa Kapravelou
import com.google.gwt.user.client.ui.TreeItem;
25 a52ea5e4 pastith
26 a52ea5e4 pastith
27 a52ea5e4 pastith
/**
28 a52ea5e4 pastith
 * @author kman
29 a52ea5e4 pastith
 *
30 a52ea5e4 pastith
 */
31 a52ea5e4 pastith
public abstract class RestResource implements Serializable{
32 555e8e59 pastith
        String uri;
33 a52ea5e4 pastith
34 555e8e59 pastith
        public RestResource(String aUri) {
35 a52ea5e4 pastith
                super();
36 fdff1ea9 Dimitris Routsis
                setUri(aUri);
37 a52ea5e4 pastith
        }
38 a52ea5e4 pastith
39 a52ea5e4 pastith
        /**
40 555e8e59 pastith
         * Retrieve the uri.
41 a52ea5e4 pastith
         *
42 555e8e59 pastith
         * @return the uri
43 a52ea5e4 pastith
         */
44 555e8e59 pastith
        public String getUri() {
45 555e8e59 pastith
                return uri;
46 a52ea5e4 pastith
        }
47 a52ea5e4 pastith
48 a52ea5e4 pastith
        /**
49 555e8e59 pastith
         * Modify the uri.
50 a52ea5e4 pastith
         *
51 555e8e59 pastith
         * @param aUri the path to set
52 a52ea5e4 pastith
         */
53 555e8e59 pastith
        public void setUri(String aUri) {
54 555e8e59 pastith
                uri = aUri;
55 014f6b56 Dimitris Routsis
                if (uri!=null) {
56 014f6b56 Dimitris Routsis
                        // Remove any parameter part
57 014f6b56 Dimitris Routsis
                        int qm = uri.indexOf('?');
58 014f6b56 Dimitris Routsis
                        if (qm>=0) uri = uri.substring(0, qm);
59 014f6b56 Dimitris Routsis
                }
60 a52ea5e4 pastith
        }
61 a52ea5e4 pastith
62 a52ea5e4 pastith
        public abstract void createFromJSON(String text);
63 a52ea5e4 pastith
64 555e8e59 pastith
        protected String unmarshallString(JSONObject obj, String key){
65 555e8e59 pastith
                if(obj.get(key) != null)
66 555e8e59 pastith
                        if(obj.get(key).isString() != null)
67 555e8e59 pastith
                                return obj.get(key).isString().stringValue();
68 a52ea5e4 pastith
                return null;
69 a52ea5e4 pastith
        }
70 a52ea5e4 pastith
71 555e8e59 pastith
        protected boolean unmarshallBoolean(JSONObject obj, String key){
72 555e8e59 pastith
                if(obj.get(key) != null)
73 555e8e59 pastith
                        if(obj.get(key).isBoolean() != null)
74 555e8e59 pastith
                                return obj.get(key).isBoolean().booleanValue();
75 a52ea5e4 pastith
                return false;
76 a52ea5e4 pastith
        }
77 62f168b2 Giannis Koutsoubos
78 62f168b2 Giannis Koutsoubos
        public static native String getDate(Long ms)/*-{
79 62f168b2 Giannis Koutsoubos
                return (new Date(ms)).toUTCString();
80 62f168b2 Giannis Koutsoubos
        }-*/;
81 62f168b2 Giannis Koutsoubos
82 62f168b2 Giannis Koutsoubos
        public abstract String getLastModifiedSince();
83 c5070ebe Natasa Kapravelou
84 c18fb50e Panagiotis Astithas
        public void updateHistory(@SuppressWarnings("unused") TreeItem item, @SuppressWarnings("unused") String path) {
85 c18fb50e Panagiotis Astithas
                // Most resources won't have to do anything here.
86 b98ec534 Natasa Kapravelou
        }
87 a52ea5e4 pastith
}