View Javadoc

    1   /*
    2    * "Peko" Visual Novel System
    3    *
    4    * All Rights Reserved.
    5    * Copyright (c) 1999-2003 Tsukuba Bunko.
    6    *
    7    * $Id: LocaleDeserializer.java,v 1.1 2005/07/11 12:49:19 ppoi Exp $
    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   * {@link java.util.Locale} 型のリソースに対する {@link tsukuba_bunko.resource.ResourceDeserializer} 実装です。
    20   * @author	$Author: ppoi $
    21   * @version	$Revision: 1.1 $
    22   * @see <a href="http://softlab.tsukuba-bunko.org/peko/userguide/resource.html#type-peko:locale">peko:locale 型のリソース</a>
    23   */
    24  public class LocaleDeserializer extends BasicDeserializer {
    25
    26  	/***
    27  	 * テキスト
    28  	 */
    29  	private StringBuffer	_text = null;
    30
    31  	/***
    32  	 * 国コード
    33  	 */
    34  	private String	_country = null;
    35
    36  	/***
    37  	 * 言語コード
    38  	 */
    39  	private String	_language = null;
    40
    41
    42  	/***
    43  	 * <code>LocaleDeserializer</code> のインスタンスを生成します。
    44  	 */
    45  	public LocaleDeserializer()
    46  	{
    47  		super();
    48  	}
    49
    50
    51  //
    52  //	ContentHandler の実装
    53  //
    54  	public void startDocument()
    55  	{
    56  		_country = null;
    57  		_language = null;
    58  	}
    59
    60  	public void endDocument()
    61  	{
    62  		if( _language != null )	{
    63  			if( _country != null )	{
    64  				setValue( new Locale(_language, _country) );
    65  			}
    66  			else	{
    67  				setValue( new Locale(_language) );
    68  			}
    69  		}
    70  		else	{
    71  			setValue( Locale.getDefault() );
    72  		}
    73  	}
    74
    75  	public void startElement( String namespaceURI, String localName, String qName, Attributes attrs )
    76  	{
    77  		if( "language".equals(localName) || "country".equals(localName) )	{
    78  			_text = new StringBuffer();
    79  		}
    80  	}
    81
    82  	public void endElement( String namespaceURI, String localName, String qName )
    83  	{
    84  		if( "language".equals(localName) )	{
    85  			String	language = new String(_text).trim();
    86  			if( language.length() > 0 )	{
    87  				_language = language;
    88  			}
    89  		}
    90  		else if( "country".equals(localName) )	{
    91  			String	country = new String(_text).trim();
    92  			if( country.length() > 0 )	{
    93  				_country = country;
    94  			}
    95  		}
    96  		_text = null;
    97  	}
    98
    99  	public void characters( char[] ch, int begin, int length )
    100 	{
    101 		if( _text != null )	{
    102 			_text.append( ch, begin, length );
    103 		}
    104 	}
    105 }