1
2
3
4
5
6
7
8 package jp.sourceforge.jindolf.corelib;
9
10 import java.io.IOException;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.List;
14 import javax.xml.parsers.DocumentBuilder;
15 import org.w3c.dom.Element;
16 import org.xml.sax.SAXException;
17
18
19
20
21
22 public final class PreDefAvatar{
23
24 private final String avatarId;
25 private final String fullName;
26 private final String jobTitle;
27 private final String shortName;
28 private final int serialNo;
29
30
31
32
33
34
35
36
37
38
39
40 private PreDefAvatar(String avatarId,
41 String fullName,
42 String jobTitle,
43 String shortName,
44 int serialNo ){
45 super();
46
47 if( avatarId == null
48 || fullName == null
49 || jobTitle == null
50 || shortName == null ){
51 throw new NullPointerException();
52 }
53
54 if( avatarId.length() <= 0
55 || fullName.length() <= 0
56 || serialNo < 0 ){
57 throw new IllegalArgumentException();
58 }
59
60 this.avatarId = avatarId.intern();
61 this.fullName = fullName.intern();
62 this.jobTitle = jobTitle.intern();
63 this.shortName = shortName.intern();
64 this.serialNo = serialNo;
65
66 return;
67 }
68
69
70
71
72
73
74
75
76
77
78 public static List<PreDefAvatar> buildPreDefAvatarList(
79 DocumentBuilder builder)
80 throws IOException,
81 SAXException {
82 List<Element> elemList = DomUtils.loadElemList(
83 builder, XmlResource.I_URL_AVATARDEF, "preDefinedAvatar");
84
85 List<PreDefAvatar> result = new ArrayList<>(elemList.size());
86
87 for(Element elem : elemList){
88 PreDefAvatar avatar = buildAvatar(elem);
89 result.add(avatar);
90 }
91
92 result = Collections.unmodifiableList(result);
93
94 return result;
95 }
96
97
98
99
100
101
102
103
104 private static PreDefAvatar buildAvatar(Element avatarDef)
105 throws SAXException {
106 String avatarId = avatarDef.getAttribute("avatarId");
107 String jobTitle = avatarDef.getAttribute("jobTitle");
108 String shortName = avatarDef.getAttribute("shortName");
109 String serialNum = avatarDef.getAttribute("serialNum");
110
111 String fullName = jobTitle + "\u0020" + shortName;
112
113 int serialNo;
114 try{
115 serialNo = Integer.parseInt(serialNum);
116 }catch(NumberFormatException e){
117 throw new SAXException("illegal number form", e);
118 }
119
120 PreDefAvatar avatar = new PreDefAvatar(avatarId,
121 fullName,
122 jobTitle,
123 shortName,
124 serialNo );
125
126 return avatar;
127 }
128
129
130
131
132
133
134
135 public String getAvatarId(){
136 return this.avatarId;
137 }
138
139
140
141
142
143
144 public String getFullName(){
145 return this.fullName;
146 }
147
148
149
150
151
152
153 public String getJobTitle(){
154 return this.jobTitle;
155 }
156
157
158
159
160
161
162 public String getShortName(){
163 return this.shortName;
164 }
165
166
167
168
169
170
171 public int getSerialNo(){
172 return this.serialNo;
173 }
174
175 }