Coverage report

| %line | %branch
--- | --- | ---
tsukuba_bunko.peko.scenario.structure.HeadHandler |
0% |
0% |

1 |  |
     /*
2 |  |
      * "Peko" Visual Novel System
3 |  |
      *
4 |  |
      * All Rights Reserved.
5 |  |
      * Copyright (c) 1999-2003 Tsukuba Bunko.
6 |  |
      *
7 |  |
      * $Id: HeadHandler.java,v 1.1 2005/07/11 12:49:19 ppoi Exp $
8 |  |
      */
9 |  |
     package tsukuba_bunko.peko.scenario.structure;
10 |  |
11 |  |
     import	java.io.InputStream;
12 |  |
13 |  |
     import	java.net.URL;
14 |  |
15 |  |
     import	java.util.Iterator;
16 |  |
     import	java.util.Properties;
17 |  |
18 |  |
     import	org.xml.sax.Attributes;
19 |  |
20 |  |
     import	tsukuba_bunko.peko.Logger;
21 |  |
     import	tsukuba_bunko.peko.PekoSystem;
22 |  |
23 |  |
     import	tsukuba_bunko.peko.resource.ResourceManager;
24 |  |
25 |  |
26 |  |
     import tsukuba_bunko.peko.scenario.ElementHandler;
27 |  |
     import	tsukuba_bunko.peko.scenario.NextSceneMapping;
28 |  |
     import tsukuba_bunko.peko.scenario.PSMLUtil;
29 |  |
     import tsukuba_bunko.peko.scenario.SceneContext;
30 |  |
31 |  |
32 |  |
     /**
33 |  |
      * <samp>head</samp> 要素を処理する ElementHandler です。
34 |  |
      * @author	$Author: ppoi $
35 |  |
      * @version	$Revision: 1.1 $
36 |  |
      */
37 |  |
     public class HeadHandler extends ElementHandler {
38 |  |
39 |  |
     	/**
40 |  |
     	 * 文字列キャッシュ
41 |  |
     	 */
42 | 0 |
     	protected StringBuffer	_text = null;
43 |  |
44 |  |
     	/**
45 |  |
     	 * 遷移先表
46 |  |
     	 */
47 | 0 |
     	protected NextSceneMapping	_nextSceneMapping = null;
48 |  |
49 |  |
     	/**
50 |  |
     	 */
51 | 0 |
     	protected String	_condition = null;
52 |  |
53 |  |
54 |  |
     	/**
55 |  |
     	 * <code>HeadHandler</code> のインスタンスを生成します。
56 |  |
     	 */
57 |  |
     	public HeadHandler()
58 |  |
     	{
59 | 0 |
     		super();
60 | 0 |
     	}
61 |  |
62 |  |
63 |  |
     //
64 |  |
     //	ElementHandler の実装
65 |  |
     //
66 |  |
     	public void endDocument()
67 |  |
     	{
68 | 0 |
     		SceneContext	context = getSceneContext();
69 | 0 |
     		if( context.getSceneTitle() == null )	{
70 | 0 |
     			Logger.warn( MessageIDs.SCN5001W );
71 | 0 |
     			context.setSceneTitle( context.getSceneName() );
72 |  |
     		}
73 | 0 |
     		ResourceManager	resources = ResourceManager.getInstance();
74 | 0 |
     		PekoSystem.getInstance().getMainWindow().setTitle( context.getSceneTitle() + " - " + resources.getResource("game-info.title") );
75 | 0 |
     	}
76 |  |
77 |  |
     	public void startElement( String namespaceURI, String localName, String qName, Attributes attrs )
78 |  |
     	{
79 | 0 |
     		if( localName.equals("property") )	{
80 | 0 |
     			String	name = PSMLUtil.getAttributeValue( attrs, "name" );
81 | 0 |
     			String	file = PSMLUtil.getAttributeValue( attrs, "file" );
82 | 0 |
     			if( (name != null) && (name.length() > 0) )	{
83 | 0 |
     				getSceneContext().setProperty( name, PSMLUtil.getAttributeValue(attrs, "value") );
84 | 0 |
     			}
85 | 0 |
     			else if( (file != null) && (file.length() > 0) )	{
86 | 0 |
     				ResourceManager	resources = ResourceManager.getInstance();
87 | 0 |
     				URL	sceneDir = resources.getLocationResources().getScenesDirecotryURL();
88 | 0 |
     				URL	fileURL = null;
89 |  |
     				try	{
90 | 0 |
     					fileURL = new URL( sceneDir, file );
91 |  |
     				}
92 | 0 |
     				catch( Exception e )	{
93 | 0 |
     					Logger.warn( MessageIDs.SCN5002W, new Object[]{getSceneContext().getCurrentPath()}, e );
94 | 0 |
     					return;
95 | 0 |
     				}
96 |  |
97 | 0 |
     				Properties	properties = new Properties();
98 | 0 |
     				InputStream	is = null;
99 |  |
     				try	{
100 | 0 |
     					is = fileURL.openStream();
101 | 0 |
     					properties.load( is );
102 |  |
     				}
103 | 0 |
     				catch( Exception e )	{
104 | 0 |
     					Logger.warn( MessageIDs.SCN5002W, new Object[]{getSceneContext().getCurrentPath()}, e );
105 |  |
     					return;
106 |  |
     				}
107 |  |
     				finally	{
108 | 0 |
     					if( is != null )	{
109 |  |
     						try	{
110 | 0 |
     							is.close();
111 |  |
     						}
112 | 0 |
     						catch( Exception e )	{
113 | 0 |
     						}
114 | 0 |
     					}
115 | 0 |
     				}
116 |  |
117 | 0 |
     				SceneContext	context = getSceneContext();
118 | 0 |
     				Iterator	itr = properties.keySet().iterator();
119 | 0 |
     				String	key = null;
120 | 0 |
     				while( itr.hasNext() )	{
121 | 0 |
     					key = (String)itr.next();
122 | 0 |
     					context.setProperty( key, properties.getProperty(key) );
123 | 0 |
     				}
124 |  |
     			}
125 | 0 |
     		}
126 | 0 |
     		else if( "next-scene".equals(localName) )	{
127 | 0 |
     			_nextSceneMapping = getSceneContext().getNextSceneMapping();
128 | 0 |
     		}
129 | 0 |
     		else if( localName.equals("title") )	{
130 | 0 |
     			_text = new StringBuffer();
131 | 0 |
     		}
132 | 0 |
     		else if( localName.equals("scene-ref") )	{
133 | 0 |
     			_text = new StringBuffer();
134 | 0 |
     			_condition = PSMLUtil.getAttributeValue( attrs, "if" );
135 | 0 |
     			if( _condition != null )	{
136 | 0 |
     				_condition = _condition.trim();
137 |  |
     			}
138 |  |
     		}
139 | 0 |
     	}
140 |  |
141 |  |
     	public void endElement( String namespaceURI, String localName, String qName )
142 |  |
     	{
143 | 0 |
     		if( localName.equals("title") )	{
144 | 0 |
     			if( _text.length() == 0 )	{
145 | 0 |
     				Logger.warn( MessageIDs.SCN5001W );
146 | 0 |
     				getSceneContext().setSceneTitle( getSceneContext().getSceneName() );
147 | 0 |
     			}
148 |  |
     			else	{
149 | 0 |
     				getSceneContext().setSceneTitle( new String(_text) );
150 |  |
     			}
151 | 0 |
     		}
152 | 0 |
     		else if( localName.equals("scene-ref") )	{
153 | 0 |
     			if( _text.length() > 0 )	{
154 | 0 |
     				NextSceneMapping	mapping = getSceneContext().getNextSceneMapping();
155 | 0 |
     				String	sceneName = new String(_text).trim();
156 | 0 |
     				if( (_condition == null) || (_condition.length() == 0) )	{
157 | 0 |
     					mapping.setDefaultSceneMapping( sceneName );
158 | 0 |
     				}
159 |  |
     				else	{
160 | 0 |
     					mapping.addNextSceneMapping( _condition, sceneName );
161 |  |
     				}
162 | 0 |
     				_condition = null;
163 | 0 |
     			}
164 |  |
     		}
165 | 0 |
     		else if( localName.equals("next-scene") )	{
166 | 0 |
     			_nextSceneMapping = null;
167 |  |
     		}
168 | 0 |
     		_text = null;
169 | 0 |
     	}
170 |  |
171 |  |
     	public void characters( char[] ch, int begin, class="keyword">int length )
172 |  |
     	{
173 | 0 |
     		if( _text != null )	{
174 | 0 |
     			_text.append( ch, begin, length );
175 |  |
     		}
176 | 0 |
     	}
177 |  |
     }

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