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 package com.mindtree.techworks.insight.preferences.util;
26
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.Iterator;
30 import java.util.List;
31
32 import com.mindtree.techworks.insight.InsightConstants;
33 import com.mindtree.techworks.insight.download.FTPFileset;
34 import com.mindtree.techworks.insight.download.Fileset;
35 import com.mindtree.techworks.insight.download.HTTPFileset;
36 import com.mindtree.techworks.insight.download.ProxyInfo;
37 import com.mindtree.techworks.insight.download.SFTPFileset;
38 import com.mindtree.techworks.insight.preferences.PreferenceManager;
39 import com.mindtree.techworks.insight.preferences.model.Preference;
40 import com.mindtree.techworks.insight.preferences.model.PreferenceAttribute;
41
42
43
44
45
46
47
48
49
50 public class PreferenceInterpreter {
51
52
53
54
55 private static final String TRUE = "true";
56
57
58
59
60
61
62
63
64 private static final String DISPLAY_COLUMN = "eventcolumnpreference";
65
66
67
68
69 private static final String FILESET = "fileset";
70
71
72
73
74 private static final String LOCAL_FILESETS = "local";
75
76
77
78
79 private static final String FTP_FILESETS = "ftpfiles";
80
81
82
83
84 private static final String SFTP_FILESETS = "sftpfiles";
85
86
87
88
89 private static final String HTTP_FILESETS = "remote";
90
91
92
93
94 private static final String PROXY = "proxy";
95
96
97
98
99
100
101
102
103 private static final String SHOW_FILESETS = "showFilesetsOnLoad";
104
105
106
107
108 private static final String PREFERRED_FILSET_TYPE = "filesetType";
109
110
111
112
113
114
115 private static final String FTP_FILESET_HOSTNAME = "hostname";
116
117
118
119
120 private static final String FTP_FILESET_PORTNO = "portno";
121
122
123
124
125 private static final String FTP_FILESET_HOMEDIR = "homedir";
126
127
128
129
130 private static final String FTP_FILESET_AUTHENTICATION = "authentication";
131
132
133
134
135 private static final String FTP_FILESET_USERNAME = "username";
136
137
138
139
140 private static final String FTP_FILESET_PASSWORD = "password";
141
142
143
144
145 private static final String FTP_FILESET_FILE_PREFIX = "urlId";
146
147
148
149
150
151
152 private static final String SFTP_FILESET_HOSTNAME = "hostname";
153
154
155
156
157 private static final String SFTP_FILESET_PORTNO = "portno";
158
159
160
161
162 private static final String SFTP_FILESET_HOMEDIR = "homedir";
163
164
165
166
167 private static final String SFTP_FILESET_AUTHENTICATION = "authentication";
168
169
170
171
172 private static final String SFTP_FILESET_USERNAME = "username";
173
174
175
176
177 private static final String SFTP_FILESET_PASSWORD = "password";
178
179
180
181
182 private static final String TAILING_OPTION = "tailOption";
183
184
185
186 private static final String SFTP_FILESET_FILE_PREFIX = "urlId";
187
188
189
190
191
192
193 private static final String HTTP_AUTHENTICATION_REQUIRED = "authentication";
194
195
196
197
198 private static final String HTTP_AUTHENTICATION_USERNAME = "username";
199
200
201
202
203 private static final String HTTP_AUTHENTICATION_PASSWORD = "password";
204
205
206
207
208 private static final String HTTP_IGNORE_PROXY = "ignoreProxy";
209
210
211
212
213 private static final String HTTP_FILESET_URL_PREFIX = "urlId";
214
215
216
217
218
219
220 private static final String HTTP_PROXY_HOST = "http.proxy.host";
221
222
223
224
225 private static final String HTTP_PROXY_PORT = "http.proxy.port";
226
227
228
229
230 private static final String FTP_PROXY_HOST = "ftp.proxy.host";
231
232
233
234
235 private static final String FTP_PROXY_PORT = "ftp.proxy.port";
236
237
238
239
240 private static final String SOCKS_PROXY_HOST = "socks.proxy.host";
241
242
243
244
245 private static final String SOCKS_PROXY_PORT = "socks.proxy.port";
246
247
248
249
250 private static final String PROXY_REQUIRES_AUTHENTICATION = "authentication";
251
252
253
254
255 private static final String PROXY_AUTH_USER = "user";
256
257
258
259
260 private static final String PROXY_AUTH_PASSWORD = "password";
261
262
263
264
265 private static final String REMOTE_PREFERENCE = "remoteProtocol";
266
267
268
269
270 private static final String REMOTE_PORT = "port";
271
272
273
274
275 private static final String CACHE_CONFIG = "cacheConfig";
276 private static final String PAGE_SIZE = "pageSize";
277
278
279
280
281
282
283
284
285
286
287
288
289
290 public static int [] getConfiguredColumnsForDisplay () {
291
292 ArrayList configuredColumns = new ArrayList();
293 Preference preference = PreferenceManager.getInstance().getPreference(
294 DISPLAY_COLUMN);
295 Iterator iterator = preference.iteratePreferenceAttributeIds();
296 while (iterator.hasNext()) {
297 String id = (String) iterator.next();
298 configuredColumns.add(id);
299 }
300
301 Collections.sort(configuredColumns);
302 int [] columns = new int [configuredColumns.size()];
303 for (int i = 0; i < configuredColumns.size(); i++ ) {
304 columns[i] = Integer.parseInt(preference
305 .getPreferenceAttributeById(
306 (String) configuredColumns.get(i)).getValue());
307 }
308 return columns;
309 }
310
311
312
313
314
315
316 public static boolean getShowFilesetOnLoad () {
317
318 Preference preference = PreferenceManager.getInstance().getPreference(
319 FILESET);
320 return preference.getPreferenceAttributeById(SHOW_FILESETS).getValue()
321 .equals(TRUE);
322 }
323
324
325
326
327
328
329
330
331
332
333
334 public static int getPreferredFilesetType () {
335
336 Preference preference = PreferenceManager.getInstance().getPreference(
337 FILESET);
338 return Integer.parseInt(preference.getPreferenceAttributeById(
339 PREFERRED_FILSET_TYPE).getValue());
340 }
341
342
343
344
345
346
347
348
349
350
351
352 public static List getLocalFilesets () {
353
354 Preference preference = PreferenceManager.getInstance().getPreference(
355 FILESET).getPreferenceById(LOCAL_FILESETS);
356 List localFilesets = new ArrayList();
357 for (Iterator filesetPrefItr = preference.iterateChildPreferences(); filesetPrefItr
358 .hasNext();) {
359 Preference localFilesetPref = (Preference) filesetPrefItr.next();
360 Fileset localFileSet = new Fileset(localFilesetPref.getName(),
361 Fileset.LOCAL_FILESET);
362 for (Iterator fileItr = localFilesetPref
363 .iteratePreferenceAttributes(); fileItr.hasNext();) {
364 localFileSet.addFile(((PreferenceAttribute) fileItr.next())
365 .getValue());
366 }
367 localFilesets.add(localFileSet);
368 }
369 return localFilesets;
370 }
371
372
373
374
375
376
377
378
379
380
381
382
383 public static List getFTPFilesets () {
384
385 Preference preference = PreferenceManager.getInstance().getPreference(
386 FILESET).getPreferenceById(FTP_FILESETS);
387 List ftpFilesets = new ArrayList();
388 for (Iterator ftpFilesetPrefItr = preference.iterateChildPreferences(); ftpFilesetPrefItr
389 .hasNext();) {
390 Preference ftpFilesetPref = (Preference) ftpFilesetPrefItr.next();
391 FTPFileset ftpFileSet = new FTPFileset(ftpFilesetPref.getName());
392
393
394 ftpFileSet.setHost(ftpFilesetPref.getPreferenceAttributeById(
395 FTP_FILESET_HOSTNAME).getValue());
396 String portNo = ftpFilesetPref.getPreferenceAttributeById(
397 FTP_FILESET_PORTNO).getValue();
398 if (null != portNo && portNo.length() > 0) {
399 ftpFileSet.setPort(Integer.parseInt(portNo));
400 }
401 ftpFileSet
402 .setDefaultDirectory(ftpFilesetPref
403 .getPreferenceAttributeById(FTP_FILESET_HOMEDIR)
404 .getValue());
405
406
407 boolean requiresAuthentication = ftpFilesetPref
408 .getPreferenceAttributeById(FTP_FILESET_AUTHENTICATION)
409 .getValue().equals(TRUE);
410 ftpFileSet.setAuthenticationRequired(requiresAuthentication);
411 if (requiresAuthentication) {
412 ftpFileSet.setUserName(ftpFilesetPref
413 .getPreferenceAttributeById(FTP_FILESET_USERNAME)
414 .getValue());
415 ftpFileSet.setPassword(ftpFilesetPref
416 .getPreferenceAttributeById(FTP_FILESET_PASSWORD)
417 .getValue());
418 }
419
420
421
422
423 for (Iterator fileItr = ftpFilesetPref
424 .iteratePreferenceAttributes(); fileItr.hasNext();) {
425 PreferenceAttribute fileAttribute = (PreferenceAttribute) fileItr
426 .next();
427 if (fileAttribute.getId().startsWith(FTP_FILESET_FILE_PREFIX)) {
428 ftpFileSet.addFile(fileAttribute.getValue());
429 }
430 }
431
432
433 ftpFilesets.add(ftpFileSet);
434 }
435 return ftpFilesets;
436 }
437
438
439
440
441
442
443
444
445
446
447
448
449 public static List getSFTPFilesets () {
450
451 Preference preference = PreferenceManager.getInstance().getPreference(
452 FILESET).getPreferenceById(SFTP_FILESETS);
453 List sftpFilesets = new ArrayList();
454 for (Iterator sftpFilesetPrefItr = preference.iterateChildPreferences(); sftpFilesetPrefItr
455 .hasNext();) {
456 Preference sftpFilesetPref = (Preference) sftpFilesetPrefItr.next();
457 SFTPFileset sftpFileSet = new SFTPFileset(sftpFilesetPref.getName());
458
459
460 sftpFileSet.setHost(sftpFilesetPref.getPreferenceAttributeById(
461 SFTP_FILESET_HOSTNAME).getValue());
462 String portNo = sftpFilesetPref.getPreferenceAttributeById(
463 SFTP_FILESET_PORTNO).getValue();
464 if (null != portNo && portNo.length() > 0) {
465 sftpFileSet.setPort(Integer.parseInt(portNo));
466 }
467 sftpFileSet
468 .setDefaultDirectory(sftpFilesetPref
469 .getPreferenceAttributeById(SFTP_FILESET_HOMEDIR)
470 .getValue());
471
472
473 boolean requiresAuthentication = sftpFilesetPref
474 .getPreferenceAttributeById(SFTP_FILESET_AUTHENTICATION)
475 .getValue().equals(TRUE);
476 sftpFileSet.setAuthenticationRequired(requiresAuthentication);
477 if (requiresAuthentication) {
478 sftpFileSet.setUserName(sftpFilesetPref
479 .getPreferenceAttributeById(SFTP_FILESET_USERNAME)
480 .getValue());
481 sftpFileSet.setPassword(sftpFilesetPref
482 .getPreferenceAttributeById(SFTP_FILESET_PASSWORD)
483 .getValue());
484 }
485
486
487
488
489 for (Iterator fileItr = sftpFilesetPref
490 .iteratePreferenceAttributes(); fileItr.hasNext();) {
491 PreferenceAttribute fileAttribute = (PreferenceAttribute) fileItr
492 .next();
493 if (fileAttribute.getId().startsWith(SFTP_FILESET_FILE_PREFIX)) {
494 sftpFileSet.addFile(fileAttribute.getValue());
495 }
496 }
497
498
499 sftpFilesets.add(sftpFileSet);
500 }
501 return sftpFilesets;
502 }
503
504
505
506
507
508
509
510
511
512
513
514
515
516 public static List getHttpFilesets () {
517
518 Preference preference = PreferenceManager.getInstance().getPreference(
519 FILESET).getPreferenceById(HTTP_FILESETS);
520 List httpFilesets = new ArrayList();
521
522
523 for (Iterator httpFilesetPrefItr = preference.iterateChildPreferences(); httpFilesetPrefItr
524 .hasNext();) {
525 Preference httpFilesetPref = (Preference) httpFilesetPrefItr.next();
526 HTTPFileset httpFileSet = new HTTPFileset(httpFilesetPref.getName());
527
528
529 boolean requiresAuthentication = httpFilesetPref
530 .getPreferenceAttributeById(HTTP_AUTHENTICATION_REQUIRED)
531 .getValue().equals(TRUE);
532 httpFileSet.setAuthenticationRequired(requiresAuthentication);
533 if (requiresAuthentication) {
534 httpFileSet.setUserName(httpFilesetPref
535 .getPreferenceAttributeById(
536 HTTP_AUTHENTICATION_USERNAME).getValue());
537 httpFileSet.setPassword(httpFilesetPref
538 .getPreferenceAttributeById(
539 HTTP_AUTHENTICATION_PASSWORD).getValue());
540 }
541
542 httpFileSet.setIgnoreProxy(httpFilesetPref
543 .getPreferenceAttributeById(HTTP_IGNORE_PROXY).getValue()
544 .equals(TRUE));
545
546
547 for (Iterator urlItr = httpFilesetPref
548 .iteratePreferenceAttributes(); urlItr.hasNext();) {
549 PreferenceAttribute fileAttribute = (PreferenceAttribute) urlItr
550 .next();
551 if (fileAttribute.getId().startsWith(HTTP_FILESET_URL_PREFIX)) {
552 httpFileSet.addFile(fileAttribute.getValue());
553 }
554 }
555
556
557 httpFilesets.add(httpFileSet);
558 }
559
560 return httpFilesets;
561 }
562
563
564
565
566
567
568
569 public static ProxyInfo getProxyInfo () {
570
571 Preference preference = PreferenceManager.getInstance().getPreference(
572 PROXY);
573 ProxyInfo proxyInfo = new ProxyInfo();
574 String host = null;
575 String port = null;
576
577
578 host = preference.getPreferenceAttributeById(HTTP_PROXY_HOST)
579 .getValue();
580 port = preference.getPreferenceAttributeById(HTTP_PROXY_PORT)
581 .getValue();
582 if (host != null && port != null && host.length() > 0
583 && port.length() > 0) {
584 proxyInfo.setHttpProxyInfo(host, Integer.parseInt(port));
585 }
586
587
588 host = preference.getPreferenceAttributeById(FTP_PROXY_HOST).getValue();
589 port = preference.getPreferenceAttributeById(FTP_PROXY_PORT).getValue();
590 if (host != null && port != null && host.length() > 0
591 && port.length() > 0) {
592 proxyInfo.setFtpProxyInfo(host, Integer.parseInt(port));
593 }
594
595
596 host = preference.getPreferenceAttributeById(SOCKS_PROXY_HOST)
597 .getValue();
598 port = preference.getPreferenceAttributeById(SOCKS_PROXY_PORT)
599 .getValue();
600 if (host != null && port != null && host.length() > 0
601 && port.length() > 0) {
602 proxyInfo.setSocksProxyInfo(host, Integer.parseInt(port));
603 }
604
605 proxyInfo.setAuthenticationRequired(preference
606 .getPreferenceAttributeById(PROXY_REQUIRES_AUTHENTICATION)
607 .getValue().equals(TRUE));
608 if (proxyInfo.isAuthenticationRequired()) {
609 proxyInfo.setPasswordInformation(preference
610 .getPreferenceAttributeById(PROXY_AUTH_USER).getValue(),
611 preference.getPreferenceAttributeById(PROXY_AUTH_PASSWORD)
612 .getValue());
613 }
614
615 return proxyInfo;
616 }
617
618
619
620
621
622
623
624
625
626 public static boolean getTailingStatus(){
627 Preference pref = PreferenceManager.getInstance().getPreference(FILESET);
628 if(pref!=null){
629 PreferenceAttribute prefAttribute = pref.getPreferenceAttributeById(TAILING_OPTION);
630 if(prefAttribute!=null){
631 return prefAttribute.getValue().equalsIgnoreCase(TRUE);
632 }
633 }
634 return false;
635 }
636
637
638
639
640
641
642
643
644 public static int getRemoteProtocolListenerPort () {
645
646 Preference pref = PreferenceManager.getInstance ()
647 .getPreference (REMOTE_PREFERENCE);
648 if (null != pref) {
649 PreferenceAttribute preferenceAttribute = pref
650 .getPreferenceAttributeById (REMOTE_PORT);
651 if (null != preferenceAttribute) {
652 try {
653 return Integer.valueOf (preferenceAttribute.getValue ())
654 .intValue ();
655 } catch (NumberFormatException nfe) {
656
657
658 preferenceAttribute.setValue (String
659 .valueOf (InsightConstants.REMOTE_PORT_DEFAULT_VALUE));
660 return InsightConstants.REMOTE_PORT_DEFAULT_VALUE;
661 }
662 }
663 }
664 return InsightConstants.REMOTE_PORT_DEFAULT_VALUE;
665 }
666
667
668
669
670
671
672 public static int getCachePageSize() {
673 Preference pref = PreferenceManager.getInstance ()
674 .getPreference (CACHE_CONFIG);
675 if (null != pref) {
676 PreferenceAttribute preferenceAttribute = pref
677 .getPreferenceAttributeById (PAGE_SIZE);
678 if (null != preferenceAttribute) {
679 try {
680 return Integer.valueOf (preferenceAttribute.getValue ())
681 .intValue ();
682 } catch (NumberFormatException nfe) {
683
684
685 preferenceAttribute.setValue (String
686 .valueOf (InsightConstants.DEFAULT_PAGE_SIZE));
687 return InsightConstants.DEFAULT_PAGE_SIZE;
688 }
689 }
690 }
691 return InsightConstants.DEFAULT_PAGE_SIZE;
692 }
693 }