SyslogConfig.java
5.25 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package com.sitech.ismp.ice.syslogd;
import java.io.*;
import java.lang.*;
import java.text.*;
import java.util.*;
public class
SyslogConfig
{
public static final String RCS_ID = "$Id: SyslogConfig.java,v 1.1.1.1 1998/02/22 05:47:55 time Exp $";
public static final String RCS_REV = "$Revision: 1.1.1.1 $";
public static final String RCS_NAME = "$Name: $";
public static final String DEFAULT_CONFIG_PATH = "syslog.conf";
private String pathName;
private ConfigEntryVector entries;
private Hashtable displays;
private boolean debugDisplays;
public
SyslogConfig()
{
this( SyslogConfig.DEFAULT_CONFIG_PATH );
}
public
SyslogConfig( String pathName )
{
this.pathName = pathName;
this.displays = new Hashtable();
this.entries = new ConfigEntryVector();
this.debugDisplays = false;
}
public void
setConfigPathname( String pathName )
{
this.pathName = pathName;
}
public ConfigEntryVector
getConfigEntries()
{
return this.entries;
}
public void
addConfigEntry( ConfigEntry entry )
{
this.entries.addConfigEntry( entry );
}
public void
addDisplayEntry( DisplayEntry entry )
{
this.displays.put( entry.getName(), entry );
}
public DisplayEntry
getDisplayEntry( String name )
{
DisplayEntry entry = null;
try { entry = (DisplayEntry) this.displays.get( name ); }
catch ( NoSuchElementException ex )
{ entry = null; }
return entry;
}
public Enumeration
getDisplayEnumeration()
{
return this.displays.elements();
}
public boolean
loadConfiguration()
{
return this.loadConfiguration( this.pathName );
}
private boolean
loadConfiguration( String pathName )
{
ConfigEntry entry;
BufferedReader reader;
boolean result = true;
try {
reader = new BufferedReader(
new FileReader( pathName ) );
}
catch ( Exception ex )
{
System.err.println
( "ERROR opening configuration file '"
+ pathName + "'\n\t" + ex.getMessage() );
return false;
}
ConfigFormat parser = ConfigFormat.getInstance();
for ( int lineNumber = 1 ; ; )
{
String configLine = null;
StringBuffer configLineBuf = null;
for ( ; ; )
{
boolean lineContinued = false;
try {
configLine = reader.readLine();
}
catch ( IOException ex )
{
result = false;
configLineBuf = null;
System.err.println
( "ERROR reading configuration line #"
+ lineNumber + ":\n\t" + ex.getMessage() );
break;
}
if ( configLine == null )
break;
++lineNumber;
if ( configLine.endsWith( "\\" ) )
{
lineContinued = true;
configLine =
configLine.substring
( 0, configLine.length()-1 );
}
if ( configLineBuf != null )
configLineBuf.append( configLine );
else
configLineBuf = new StringBuffer( configLine );
if ( ! lineContinued )
break;
}
// Check for end of file (EOF),
if ( configLineBuf == null )
break;
configLine = configLineBuf.toString();
// Skip blank lines.
configLine = configLine.trim();
if ( configLine.length() < 1 )
continue;
// Check for comment.
if ( configLine.startsWith( "#" ) )
{
continue;
}
else if ( configLine.startsWith( "@" ) )
{
// REVIEW We are treating disply entries a little
// different, without its own Format class.
// If we add the ability to re-write the
// config file, we may re-think this!
String[] args =
com.sitech.ismp.ice.util.StringUtilities.parseArgumentString
( configLine.substring(1) );
if ( args.length < 8 )
{
System.err.println
( "ERROR bad display definition line #"
+ lineNumber + ": wrong number of arguments." );
}
else
{
String name = args[0];
String className = args[1];
String title = args[2];
int x = 20;
int y = 30;
int width = 500;
int height = 300;
int bufLength = 250;
try {
bufLength = Integer.parseInt( args[3] );
x = Integer.parseInt( args[4] );
y = Integer.parseInt( args[5] );
width = Integer.parseInt( args[6] );
height = Integer.parseInt( args[7] );
}
catch ( NumberFormatException ex )
{
System.err.println
( "ERROR bad display geometry line #"
+ lineNumber + ":\n\t" + ex.getMessage() );
}
String[] parameters = null;
if ( args.length > 8 )
{
parameters = new String[ args.length - 8 ];
for ( int i = 8 ; i < args.length ; ++i )
{
parameters[i-8] = args[i];
}
}
DisplayEntry display =
new DisplayEntry
( name, className, title,
bufLength, x, y, width, height,
parameters );
if ( display != null )
{
this.displays.put( name, display );
if ( this.debugDisplays )
System.err.println( "ADDED DISPLAY '" + name + "'" );
}
}
}
else
{
try {
entry = parser.parseEntry( configLine );
}
catch ( ParseException ex )
{
result = false;
System.err.println
( "ERROR bad configuration line #"
+ lineNumber + ":\n\t" + ex.getMessage() );
continue;
}
this.addConfigEntry( entry );
}
}
try { reader.close(); }
catch ( IOException ex ) { }
return result;
}
}