1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
package tsukuba_bunko.peko.resource; |
10 |
|
|
11 |
|
import java.util.Locale; |
12 |
|
|
13 |
|
import org.xml.sax.Attributes; |
14 |
|
|
15 |
|
import tsukuba_bunko.resource.BasicDeserializer; |
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
public class LocaleDeserializer extends BasicDeserializer { |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
0 |
private StringBuffer _text = null; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
0 |
private String _country = null; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
0 |
private String _language = null; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
public LocaleDeserializer() |
46 |
|
{ |
47 |
0 |
super(); |
48 |
0 |
} |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
public void startDocument() |
55 |
|
{ |
56 |
0 |
_country = null; |
57 |
0 |
_language = null; |
58 |
0 |
} |
59 |
|
|
60 |
|
public void endDocument() |
61 |
|
{ |
62 |
0 |
if( _language != null ) { |
63 |
0 |
if( _country != null ) { |
64 |
0 |
setValue( new Locale(_language, _country) ); |
65 |
0 |
} |
66 |
|
else { |
67 |
0 |
setValue( new Locale(_language) ); |
68 |
|
} |
69 |
0 |
} |
70 |
|
else { |
71 |
0 |
setValue( Locale.getDefault() ); |
72 |
|
} |
73 |
0 |
} |
74 |
|
|
75 |
|
public void startElement( String namespaceURI, String localName, String qName, Attributes attrs ) |
76 |
|
{ |
77 |
0 |
if( "language".equals(localName) || "country".equals(localName) ) { |
78 |
0 |
_text = new StringBuffer(); |
79 |
|
} |
80 |
0 |
} |
81 |
|
|
82 |
|
public void endElement( String namespaceURI, String localName, String qName ) |
83 |
|
{ |
84 |
0 |
if( "language".equals(localName) ) { |
85 |
0 |
String language = new String(_text).trim(); |
86 |
0 |
if( language.length() > 0 ) { |
87 |
0 |
_language = language; |
88 |
|
} |
89 |
0 |
} |
90 |
0 |
else if( "country".equals(localName) ) { |
91 |
0 |
String country = new String(_text).trim(); |
92 |
0 |
if( country.length() > 0 ) { |
93 |
0 |
_country = country; |
94 |
|
} |
95 |
|
} |
96 |
0 |
_text = null; |
97 |
0 |
} |
98 |
|
|
99 |
|
public void characters( char[] ch, int begin, class="keyword">int length ) |
100 |
|
{ |
101 |
0 |
if( _text != null ) { |
102 |
0 |
_text.append( ch, begin, length ); |
103 |
|
} |
104 |
0 |
} |
105 |
|
} |