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 private PreDefAvatar(String avatarId,
40 String fullName,
41 String jobTitle,
42 String shortName,
43 int serialNo ){
44 super();
45
46 if( avatarId == null
47 || fullName == null
48 || jobTitle == null
49 || shortName == null ){
50 throw new NullPointerException();
51 }
52
53 if( avatarId.length() <= 0
54 || fullName.length() <= 0
55 || serialNo < 0 ){
56 throw new IllegalArgumentException();
57 }
58
59 this.avatarId = avatarId.intern();
60 this.fullName = fullName.intern();
61 this.jobTitle = jobTitle.intern();
62 this.shortName = shortName.intern();
63 this.serialNo = serialNo;
64
65 return;
66 }
67
68
69
70
71
72
73
74
75
76 public static List<PreDefAvatar> buildPreDefAvatarList(
77 DocumentBuilder builder)
78 throws IOException,
79 SAXException {
80 List<Element> elemList = DomUtils.loadElemList(
81 builder, XmlResource.I_URL_AVATARDEF, "preDefinedAvatar");
82
83 List<PreDefAvatar> result = new ArrayList<>(elemList.size());
84
85 for(Element elem : elemList){
86 PreDefAvatar avatar = buildAvatar(elem);
87 result.add(avatar);
88 }
89
90 result = Collections.unmodifiableList(result);
91
92 return result;
93 }
94
95
96
97
98
99
100
101 private static PreDefAvatar buildAvatar(Element avatarDef)
102 throws SAXException {
103 String avatarId = avatarDef.getAttribute("avatarId");
104 String jobTitle = avatarDef.getAttribute("jobTitle");
105 String shortName = avatarDef.getAttribute("shortName");
106 String serialNum = avatarDef.getAttribute("serialNum");
107
108 String fullName = jobTitle + "\u0020" + shortName;
109
110 int serialNo;
111 try{
112 serialNo = Integer.parseInt(serialNum);
113 }catch(NumberFormatException e){
114 throw new SAXException("illegal number form", e);
115 }
116
117 PreDefAvatar avatar = new PreDefAvatar(avatarId,
118 fullName,
119 jobTitle,
120 shortName,
121 serialNo );
122
123 return avatar;
124 }
125
126
127
128
129
130
131 public String getAvatarId(){
132 return this.avatarId;
133 }
134
135
136
137
138
139 public String getFullName(){
140 return this.fullName;
141 }
142
143
144
145
146
147 public String getJobTitle(){
148 return this.jobTitle;
149 }
150
151
152
153
154
155 public String getShortName(){
156 return this.shortName;
157 }
158
159
160
161
162
163 public int getSerialNo(){
164 return this.serialNo;
165 }
166
167 }