Subversion Repositories bacoAlunos

Rev

Rev 1670 | Rev 1692 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1670 Rev 1675
Line 1... Line 1...
1
package pt.estgp.estgweb.domain;
1
package pt.estgp.estgweb.domain;
2
 
2
 
3
import com.owlike.genson.Genson;
3
import com.owlike.genson.Genson;
4
import com.owlike.genson.TransformationException;
4
import com.owlike.genson.TransformationException;
-
 
5
import org.json.JSONArray;
5
import org.json.JSONException;
6
import org.json.JSONException;
6
import org.json.JSONObject;
7
import org.json.JSONObject;
7
 
8
 
8
import java.io.IOException;
9
import java.io.IOException;
9
import java.io.Serializable;
10
import java.io.Serializable;
-
 
11
import java.util.ArrayList;
10
import java.util.List;
12
import java.util.List;
-
 
13
import java.util.Set;
11
 
14
 
12
/**
15
/**
13
 * Created by jorgemachado on 23/02/17.
16
 * Created by jorgemachado on 23/02/17.
14
 */
17
 */
15
public class RepositoryDocumentCollectionImpl extends RepositoryDocumentCollection {
18
public class RepositoryDocumentCollectionImpl extends RepositoryDocumentCollection {
Line 17... Line 20...
17
    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() {
20
    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() {
18
        return getId();
21
        return getId();
19
    }
22
    }
20
 
23
 
21
 
24
 
-
 
25
    static Genson genson;
-
 
26
 
-
 
27
    static {
22
    static Genson genson = new Genson.Builder()
28
        Genson.Builder gensonBuilder =  new Genson.Builder()
23
            .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
29
            .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
24
            .include(RepositoryDocumentCollectionImpl.class)
30
            .include(RepositoryDocumentCollectionImpl.class)
25
            .include(1.5.0/docs/api/java/lang/String.html">String.class)
31
            .include(1.5.0/docs/api/java/lang/String.html">String.class)
-
 
32
            .exclude("parent", RepositoryDocumentCollection.class);
26
            .create();
33
        genson = gensonBuilder.create();
27
 
34
 
-
 
35
    }
28
    public 1.5.0/docs/api/java/lang/String.html">String toJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
36
    public 1.5.0/docs/api/java/lang/String.html">String toJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
29
    {
37
    {
30
        return genson.serialize(this);
38
        return genson.serialize(this);
31
    }
39
    }
32
 
40
 
33
    public static 1.5.0/docs/api/java/lang/String.html">String toJson(List<RepositoryDocumentCollection> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
41
    public static 1.5.0/docs/api/java/lang/String.html">String toJson(List<RepositoryDocumentCollection> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
34
    {
42
    {
35
        return genson.serialize(collections);
43
        return genson.serialize(collections);
36
    }
44
    }
-
 
45
    public static JSONArray toJsonArray(Set<RepositoryDocumentCollectionImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException {
-
 
46
        ArrayList<RepositoryDocumentCollectionImpl> collectionsList  = new ArrayList<RepositoryDocumentCollectionImpl>(collections);
-
 
47
        return toJsonArray(collectionsList);
-
 
48
    }
-
 
49
 
-
 
50
    public static JSONArray toJsonArray(List<RepositoryDocumentCollectionImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException {
-
 
51
        return new JSONArray(genson.serialize(collections));
-
 
52
    }
37
 
53
 
38
    public static RepositoryDocumentCollectionImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException {
54
    public static RepositoryDocumentCollectionImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException {
39
        return genson.deserialize(json, RepositoryDocumentCollectionImpl.class);
55
        return genson.deserialize(json, RepositoryDocumentCollectionImpl.class);
40
    }
56
    }
41
 
57
 
42
    public JSONObject toJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException {
58
    public JSONObject toJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException {
43
        return new JSONObject(toJson());
59
        return new JSONObject(toJson());
44
    }
60
    }
-
 
61
 
-
 
62
    public 1.5.0/docs/api/java/lang/String.html">String getPathName()
-
 
63
    {
-
 
64
        if(getParent()==null)
-
 
65
            return getName();
-
 
66
        else
-
 
67
            return getParent().getPathName() + " - " + getName();
-
 
68
    }
45
}
69
}
46
 
70