View Javadoc

    1   /*
    2    * "Peko" Visual Novel System
    3    *
    4    * All Rights Reserved.
    5    * Copyright (c) 1999-2003 Tsukuba Bunko.
    6    *
    7    * $Id: FlagHandler.java,v 1.1 2005/07/11 12:49:19 ppoi Exp $
    8    */
    9   package tsukuba_bunko.peko.scenario.util;
    10
    11  import	org.xml.sax.Attributes;
    12
    13  import	tsukuba_bunko.peko.Logger;
    14
    15  import	tsukuba_bunko.peko.scenario.ElementHandler;
    16  import	tsukuba_bunko.peko.scenario.FlagScope;
    17  import	tsukuba_bunko.peko.scenario.PSMLUtil;
    18
    19
    20  /***
    21   * <samp>flag</samp> 要素を処理する ElementHandler 実装です。
    22   * @author	$Author: ppoi $
    23   * @version	$Revision: 1.1 $
    24   */
    25  public class FlagHandler	extends ElementHandler	{
    26
    27  	/***
    28  	 * フラグ ID
    29  	 */
    30  	private String	_flagID = null;
    31
    32  	/***
    33  	 * フラグスコープ
    34  	 */
    35  	private FlagScope	_scope = null;
    36
    37  	/***
    38  	 * フラグを立てるか降ろすか
    39  	 */
    40  	private boolean	_declare = true;
    41
    42
    43  	/***
    44  	 * <code>FlagHandler</code> のインスタンスを生成します。
    45  	 */
    46  	public FlagHandler()
    47  	{
    48  		super();
    49  	}
    50
    51
    52  //
    53  //	ContentHandler の実装
    54  //
    55  	public void startDocument()
    56  	{
    57  		_flagID = null;
    58  		_declare = true;
    59  		_scope = null;
    60  	}
    61
    62  	public void endDocument()
    63  	{
    64  		if( _flagID != null )	{
    65  			if( _declare )	{
    66  				getSceneContext().declareFlag( _flagID, _scope );
    67  			}
    68  			else	{
    69  				getSceneContext().undeclareFlag( _flagID, _scope );
    70  			}
    71  		}
    72  	}
    73
    74  	public void startElement( String namespaceURI, String localname, String qName, Attributes attrs )
    75  	{
    76  		String	flagID = PSMLUtil.getAttributeValue( attrs, "id" );
    77  		if( flagID == null )	{
    78  			Logger.error( MessageIDs.SCN6002W, new Object[]{getSceneContext().getCurrentPath()} );
    79  		}
    80  		else	{
    81  			_flagID = flagID;
    82  		}
    83
    84  		String	scope = PSMLUtil.getAttributeValue( attrs, "scope" );
    85  		if( "scene".equals(scope) )	{
    86  			_scope = FlagScope.SCENE;
    87  		}
    88  		else if( "session".equals(scope) )	{
    89  			_scope = FlagScope.SESSION;
    90  		}
    91  		else if( "system".equals(scope) )	{
    92  			_scope = FlagScope.SYSTEM;
    93  		}
    94  		else	{
    95  			Logger.error( MessageIDs.SCN6003W, new Object[]{((scope == null)?"null":scope), getSceneContext().getCurrentPath()} );
    96  			_flagID = null;
    97  		}
    98
    99  		String	action = PSMLUtil.getAttributeValue( attrs, "action" );
    100 		if( action != null )	{
    101 			if( "undeclare".equals(action) )	{
    102 				_declare = false;
    103 			}
    104 			else if( "declare".equals(action) )	{
    105 				_declare = true;
    106 			}
    107 			else	{
    108 				Logger.warn( MessageIDs.SCN6004W, new Object[]{getSceneContext().getCurrentPath()} );
    109 				_flagID = null;
    110 			}
    111 		}
    112 		else	{
    113 			_declare = true;
    114 		}
    115 	}
    116 }