|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| package com.unitesk.atp.tree.generation; |
|
33 |
| |
|
34 |
| import java.io.InputStream; |
|
35 |
| import java.io.IOException; |
|
36 |
| import java.io.File; |
|
37 |
| |
|
38 |
| import java.util.Enumeration; |
|
39 |
| import java.util.HashMap; |
|
40 |
| import java.util.Iterator; |
|
41 |
| import java.util.Map; |
|
42 |
| import java.util.Properties; |
|
43 |
| |
|
44 |
| import com.unitesk.atp.tree.tool.Tool; |
|
45 |
| import com.unitesk.atp.messages.*; |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| public class TokenStyleManager |
|
55 |
| { |
|
56 |
| protected String[] styles = null; |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
0
| public TokenStyleManager( Class token_types_interface
|
|
67 |
| , String tokenstyle_file |
|
68 |
| , MessageBox mbox |
|
69 |
| ) |
|
70 |
| { |
|
71 |
0
| InputStream in = Tool.findFile( tokenstyle_file );
|
|
72 |
| |
|
73 |
0
| Properties name_to_style = new Properties();
|
|
74 |
| |
|
75 |
0
| Map type_to_style = new HashMap();
|
|
76 |
| |
|
77 |
0
| if( in != null )
|
|
78 |
| { |
|
79 |
0
| try
|
|
80 |
| { |
|
81 |
0
| name_to_style.load( in );
|
|
82 |
0
| mbox.info( new FileStatusMessage( FoundFileStatus.status
|
|
83 |
| , tokenstyle_file |
|
84 |
| ) |
|
85 |
| ); |
|
86 |
| } |
|
87 |
| catch( IOException e ) |
|
88 |
| { |
|
89 |
0
| mbox.error( new IOErrorMessage( new File( tokenstyle_file ) ) );
|
|
90 |
| } |
|
91 |
| |
|
92 |
0
| Enumeration name_enum = name_to_style.propertyNames();
|
|
93 |
0
| int max = 0;
|
|
94 |
| |
|
95 |
0
| while( name_enum.hasMoreElements() )
|
|
96 |
| { |
|
97 |
0
| String name = (String)name_enum.nextElement();
|
|
98 |
0
| String style = name_to_style.getProperty( name );
|
|
99 |
| |
|
100 |
0
| if( style != null && style.length() > 0 )
|
|
101 |
| { |
|
102 |
0
| try
|
|
103 |
| { |
|
104 |
0
| Integer type = (Integer) token_types_interface
|
|
105 |
| .getField( name ) |
|
106 |
| .get( null ); |
|
107 |
0
| type_to_style.put( type, style );
|
|
108 |
0
| max = Math.max( max, type.intValue() );
|
|
109 |
| } |
|
110 |
| catch( NoSuchFieldException fe ) |
|
111 |
| { |
|
112 |
0
| mbox.error( new NameNotFoundMessage
|
|
113 |
| ( new File( tokenstyle_file ) |
|
114 |
| , null |
|
115 |
| , mbox |
|
116 |
| .getStringManager() |
|
117 |
| .getString( TokenStyleManager.class |
|
118 |
| , "message.token" |
|
119 |
| ) |
|
120 |
| , name |
|
121 |
| ) |
|
122 |
| ); |
|
123 |
| } |
|
124 |
| catch( IllegalAccessException fe ) |
|
125 |
| { |
|
126 |
0
| mbox.error( new NameNotFoundMessage
|
|
127 |
| ( new File( tokenstyle_file ) |
|
128 |
| , null |
|
129 |
| , mbox |
|
130 |
| .getStringManager() |
|
131 |
| .getString( TokenStyleManager.class |
|
132 |
| , "message.token" |
|
133 |
| ) |
|
134 |
| , name |
|
135 |
| ) |
|
136 |
| ); |
|
137 |
| } |
|
138 |
| } |
|
139 |
| } |
|
140 |
| |
|
141 |
0
| styles = new String[max+1];
|
|
142 |
| |
|
143 |
0
| Iterator type_enum = type_to_style.entrySet().iterator();
|
|
144 |
| |
|
145 |
0
| while( type_enum.hasNext() )
|
|
146 |
| { |
|
147 |
0
| Map.Entry entry = (Map.Entry)type_enum.next();
|
|
148 |
0
| Integer type = (Integer)entry.getKey();
|
|
149 |
0
| String style = (String)entry.getValue();
|
|
150 |
0
| styles[type.intValue()] = style;
|
|
151 |
| } |
|
152 |
| } |
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
0
| public String getStyle( int type )
|
|
163 |
| { |
|
164 |
0
| if( styles != null && 0 <= type && type < styles.length )
|
|
165 |
| { |
|
166 |
0
| return styles[type];
|
|
167 |
| } else { |
|
168 |
0
| return null;
|
|
169 |
| } |
|
170 |
| } |
|
171 |
| } |