Coverage report

| %line | %branch
--- | --- | ---
tsukuba_bunko.peko.scenario.select.SelectHandler |
0% |
0% |

1 |  |
     /*
2 |  |
      * "Peko" Visual Novel System
3 |  |
      *
4 |  |
      * All Rights Reserved.
5 |  |
      * Copyright (c) 1999-2003 Tsukuba Bunko.
6 |  |
      *
7 |  |
      * $Id: SelectHandler.java,v 1.2 2005/07/12 10:00:36 ppoi Exp $
8 |  |
      */
9 |  |
     package tsukuba_bunko.peko.scenario.select;
10 |  |
11 |  |
     import	java.util.Map;
12 |  |
13 |  |
     import	org.xml.sax.Attributes;
14 |  |
     import	org.xml.sax.SAXException;
15 |  |
16 |  |
     import	tsukuba_bunko.peko.Logger;
17 |  |
18 |  |
     import	tsukuba_bunko.peko.scenario.ElementHandler;
19 |  |
     import	tsukuba_bunko.peko.scenario.FlagScope;
20 |  |
     import	tsukuba_bunko.peko.scenario.PSMLUtil;
21 |  |
22 |  |
23 |  |
     /**
24 |  |
      * <samp>select</samp> 要素を処理する <code>ElementHandler</code> です。
25 |  |
      * @author	$Author: ppoi $
26 |  |
      * @version	$Revision: 1.2 $
27 |  |
      */
28 |  |
     public class SelectHandler	extends ElementHandler	{
29 |  |
30 |  |
     	/**
31 |  |
     	 * id - 属性値リスト
32 |  |
     	 */
33 | 0 |
     	private Map	_attributes = new java.util.HashMap( 89 );
34 |  |
35 |  |
     	/**
36 |  |
     	 * 現在パース中の選択肢 ID
37 |  |
     	 */
38 | 0 |
     	private String	_id = null;
39 |  |
40 |  |
     	/**
41 |  |
     	 * テキストバッファ
42 |  |
     	 */
43 | 0 |
     	private StringBuffer	_text = null;
44 |  |
45 |  |
     	/**
46 |  |
     	 * 選択肢名
47 |  |
     	 */
48 | 0 |
     	private String	_name = null;
49 |  |
50 |  |
     	/**
51 |  |
     	 * スコープ
52 |  |
     	 */
53 | 0 |
     	private FlagScope	_scope = null;
54 |  |
55 |  |
56 |  |
     	/**
57 |  |
     	 * <code>SelectHandler</code> のインスタンスを作成します。
58 |  |
     	 */
59 |  |
     	public SelectHandler()
60 |  |
     	{
61 | 0 |
     		super();
62 | 0 |
     	}
63 |  |
64 |  |
65 |  |
     	/**
66 |  |
     	 * SelectCanvas コーディネータを取得します。
67 |  |
     	 * @return	SelectCanvas コーディネータ
68 |  |
     	 */
69 |  |
     	protected SelectCoordinator getSelectCoordinator()
70 |  |
     	{
71 | 0 |
     		return getSceneContext().getSceneProcessor().getSelectCoordinator();
72 |  |
     	}
73 |  |
74 |  |
75 |  |
     //
76 |  |
     //	ContentHandler の実装
77 |  |
     //
78 |  |
     	public void startDocument()
79 |  |
     	{
80 | 0 |
     		_attributes.clear();
81 | 0 |
     		setEndOfScene( false );
82 | 0 |
     	}
83 |  |
84 |  |
     	public void endDocument()
85 |  |
     	{
86 | 0 |
     		SelectCoordinator	coordinator = getSelectCoordinator();
87 |  |
88 | 0 |
     		String	id = coordinator.select();
89 | 0 |
     		if( id == null )	{
90 |  |
     			//	キャンセルされた
91 | 0 |
     			return;
92 |  |
     		}
93 |  |
     		else	{
94 | 0 |
     			getSceneContext().declareFlag( _name + ":" + id, _scope );
95 |  |
     		}
96 |  |
97 | 0 |
     		coordinator.end();
98 | 0 |
     	}
99 |  |
100 |  |
     	public void startElement( String namespaceURI, String localName, String qName, Attributes attrs )
101 |  |
     		throws SAXException
102 |  |
     	{
103 | 0 |
     		if( localName.equals("item") )	{
104 | 0 |
     			if( _id != null )	{
105 | 0 |
     				Logger.error( "[scenario.select] BUG! Invalid PSML Structure. location: " + getSceneContext().getCurrentPath() );
106 | 0 |
     				throw new SAXException( "Invalid PSML Structure." );
107 |  |
     			}
108 |  |
109 | 0 |
     			String	id = PSMLUtil.getAttributeValue( attrs, "id" );
110 | 0 |
     			if( (id == null) || (id.length() == 0) )	{
111 | 0 |
     				Logger.warn( MessageIDs.SCN4002W, new Object[]{getSceneContext().getCurrentPath()} );
112 | 0 |
     				_id = null;
113 | 0 |
     			}
114 |  |
     			else	{
115 | 0 |
     				_id = id;
116 | 0 |
     				_text = new StringBuffer();
117 |  |
     			}
118 | 0 |
     		}
119 | 0 |
     		else if( "select".equals(localName) )	{
120 | 0 |
     			String	name = PSMLUtil.getAttributeValue( attrs, "name" );
121 | 0 |
     			if( (name == null) || (name.length() == 0) )	{
122 | 0 |
     				Logger.error( MessageIDs.SCN4001E, new Object[]{getSceneContext().getCurrentPath()} );
123 | 0 |
     				throw new SAXException( "invalid select element appeared." );
124 |  |
     			}
125 | 0 |
     			_name = PSMLUtil.getAttributeValue( attrs, "name" );
126 |  |
127 | 0 |
     			String	flagScope = PSMLUtil.getAttributeValue( attrs, "scope" );
128 | 0 |
     			if( (flagScope == null) || flagScope.equals("session") )	{
129 | 0 |
     				_scope = FlagScope.SESSION;
130 | 0 |
     			}
131 | 0 |
     			else if( flagScope.equals("scene") )	{
132 | 0 |
     				_scope = FlagScope.SCENE;
133 | 0 |
     			}
134 | 0 |
     			else if( flagScope.equals("system") )	{
135 | 0 |
     				_scope = FlagScope.SYSTEM;
136 | 0 |
     			}
137 |  |
     			else	{
138 | 0 |
     				Logger.warn( MessageIDs.SCN4004W, new Object[]{"session", getSceneContext().getCurrentPath()} );
139 | 0 |
     				_scope = FlagScope.SESSION;
140 |  |
     			}
141 |  |
142 | 0 |
     			getSelectCoordinator().begin();
143 |  |
     		}
144 | 0 |
     	}
145 |  |
146 |  |
     	public void endElement( String namespaceURI, String localName, String qName )
147 |  |
     	{
148 | 0 |
     		if( (_id != null) && localName.equals("item") )	{
149 | 0 |
     			if( _text.length() == 0 )	{
150 | 0 |
     				Logger.warn( MessageIDs.SCN4003W, new Object[]{getSceneContext().getCurrentPath()} );
151 | 0 |
     			}
152 |  |
     			else	{
153 | 0 |
     				SelectCoordinator	coordinator = getSceneContext().getSceneProcessor().getSelectCoordinator();
154 | 0 |
     				coordinator.addSelectItem( _id, new String(_text) );
155 |  |
     			}
156 | 0 |
     			_id = null;
157 | 0 |
     			_text = null;
158 |  |
     		}
159 | 0 |
     	}
160 |  |
161 |  |
     	public void characters( char[] ch, int begin, class="keyword">int length )
162 |  |
     	{
163 | 0 |
     		if( _text != null )	{
164 | 0 |
     			_text.append( ch, begin, length );
165 |  |
     		}
166 | 0 |
     	}
167 |  |
     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.