OSDN Git Service

fa3182df05cc77b9882916d3d5b4852ae14ac28c
[coroid/jnicoapi.git] / src / nicobrowser / entity / NicoContent.java
1 /*$Id$*/
2 package nicobrowser.entity;
3
4 import javax.persistence.Column;
5 import javax.persistence.Entity;
6 import javax.persistence.GeneratedValue;
7 import javax.persistence.GenerationType;
8 import javax.persistence.Id;
9 import javax.persistence.Version;
10
11 /**
12  * ニコニコ動画コンテンツ情報.
13  */
14 @Entity
15 public class NicoContent implements java.io.Serializable {
16
17     public enum Status {
18
19         GET_INFO, GET_LOW, GET_FILE
20     }
21     private static final long serialVersionUID = 1L;
22     private Long id;
23     private Long version;
24     private String nicoId;
25     private String pageLink;
26     private String title;
27     private String fileName;
28     private Status status = Status.GET_INFO;
29     private int failTimes;
30     private boolean convertedMp3;
31     private boolean convertedMp4;
32     private String author;
33
34     @Id
35     @GeneratedValue(strategy = GenerationType.AUTO)
36     public Long getId() {
37         return id;
38     }
39
40     public void setId(Long id) {
41         this.id = id;
42     }
43
44     @Version
45     public Long getVersion() {
46         return version;
47     }
48
49     public void setVersion(Long version) {
50         this.version = version;
51     }
52
53     @Column(nullable = false)
54     public String getNicoId() {
55         return nicoId;
56     }
57
58     protected void setNicoId(String nicoId) {
59         this.nicoId = nicoId;
60     }
61
62     public String getPageLink() {
63         return pageLink;
64     }
65
66     public void setPageLink(String pageLink) {
67         this.pageLink = pageLink;
68         String[] elm = pageLink.split("/");
69         setNicoId(elm[elm.length - 1]);
70     }
71
72     public String getTitle() {
73         return title;
74     }
75
76     public void setTitle(String title) {
77         this.title = title;
78         setFileName(title);
79     }
80
81     public String getFileName() {
82         return fileName;
83     }
84
85     protected void setFileName(String fileName) {
86         if (fileName == null) {
87             this.fileName = null;
88             return;
89         }
90
91         StringBuilder str = new StringBuilder();
92         try {
93             for (int i = 0; i < fileName.length(); i++) {
94                 char c = fileName.charAt(i);
95                 if (c == '\\' || c == '/' || c == ':' || c == '*' || c == '?' ||
96                         c == '"' || c == '<' || c == '>' || c == '|' || c == '.') {
97                     c = '_';
98                 }
99                 str.append(c);
100             }
101         } catch (Exception e) {
102             e.printStackTrace();
103         }
104         this.fileName = str.toString();
105     }
106
107     @Column(nullable = false)
108     public Status getStatus() {
109         return status;
110     }
111
112     public void setStatus(Status status) {
113         this.status = status;
114     }
115
116     public int getFailTimes() {
117         return failTimes;
118     }
119
120     public void setFailTimes(int failTimes) {
121         this.failTimes = failTimes;
122     }
123
124     @Column(nullable = false)
125     public boolean isConvertedMp3() {
126         return convertedMp3;
127     }
128
129     public void setConvertedMp3(boolean convertedMp3) {
130         this.convertedMp3 = convertedMp3;
131     }
132
133     @Column(nullable = false)
134     public boolean isConvertedMp4() {
135         return convertedMp4;
136     }
137
138     public void setConvertedMp4(boolean convertedMp4) {
139         this.convertedMp4 = convertedMp4;
140     }
141
142     public String getAuthor() {
143         return author;
144     }
145
146     public void setAuthor(String author) {
147         this.author = author;
148     }
149
150     @Override
151     public int hashCode() {
152         int hash = 0;
153         hash += (id != null ? id.hashCode() : 0);
154         return hash;
155     }
156
157     @Override
158     public boolean equals(Object object) {
159         // TODO: Warning - this method won't work in the case the id fields are not set
160         if (!(object instanceof NicoContent)) {
161             return false;
162         }
163         NicoContent other = (NicoContent) object;
164         if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
165             return false;
166         }
167         return true;
168     }
169
170     @Override
171     public String toString() {
172         return new String(getTitle() + ": " + getPageLink());
173     }
174 }