Project

General

Profile

1
package eu.dnetlib.pid.resolver.model;
2

    
3
import com.google.gson.Gson;
4
import com.google.gson.GsonBuilder;
5
import org.apache.commons.lang3.StringEscapeUtils;
6

    
7
/**
8
 * The Class PID.
9
 */
10
public class PID {
11

    
12
    private static Gson g = new GsonBuilder().setPrettyPrinting().create();
13

    
14
    /**
15
     * The id.
16
     */
17
    private String id;
18

    
19
    /**
20
     * The type.
21
     */
22
    private String type;
23

    
24
    /**
25
     * Instantiates a new pid.
26
     */
27
    public PID() {
28

    
29
    }
30

    
31
    /**
32
     * Instantiates a new pid.
33
     *
34
     * @param id   the id
35
     * @param type the type
36
     */
37
    public PID(final String id, final String type) {
38
        if (id != null) {
39
            this.id = id.replace("http://dx.doi.org/", "").toLowerCase();
40
        }
41
        this.type = type;
42
    }
43

    
44
    /**
45
     * Gets the id.
46
     *
47
     * @return the id
48
     */
49
    public String getId() {
50
        return id;
51
    }
52

    
53
    /**
54
     * Sets the id.
55
     *
56
     * @param id the id to set
57
     */
58
    public void setId(final String id) {
59
        if (id != null) {
60
            this.id = id.replace("http://dx.doi.org/", "").toLowerCase();
61
        }
62
        ;
63
    }
64

    
65
    public String getEscapeXMLId() {
66
        return StringEscapeUtils.escapeXml11(id);
67
    }
68

    
69
    /**
70
     * Gets the type.
71
     *
72
     * @return the type
73
     */
74
    public String getType() {
75
        return type;
76
    }
77

    
78
    /**
79
     * Sets the type.
80
     *
81
     * @param type the type to set
82
     */
83
    public void setType(final String type) {
84
        if (type != null) {
85
            this.type = type.toUpperCase();
86
        } else {
87
            this.type = type;
88
        }
89
    }
90

    
91
    @Override
92
    public String toString() {
93
        return g.toJson(this);
94
    }
95
}
(5-5/7)