18
18
19
19
package org .audit4j .core ;
20
20
21
- import java .io .BufferedWriter ;
22
- import java .io .File ;
23
21
import java .io .FileNotFoundException ;
24
22
import java .io .FileReader ;
25
23
import java .io .FileWriter ;
26
24
import java .io .IOException ;
27
25
import java .util .ArrayList ;
28
- import java .util .HashMap ;
29
26
import java .util .List ;
30
- import java .util .Map ;
31
27
32
28
import org .audit4j .core .exception .ConfigurationException ;
33
- import org .audit4j .core .exception .TroubleshootException ;
34
- import org .audit4j .core .handler .ConsoleAuditHandler ;
35
29
import org .audit4j .core .handler .Handler ;
36
- import org .audit4j .core .handler .file .FileAuditHandler ;
37
- import org .audit4j .core .layout .SimpleLayout ;
38
30
39
31
import com .esotericsoftware .yamlbeans .YamlException ;
40
32
import com .esotericsoftware .yamlbeans .YamlReader ;
47
39
*
48
40
* @since 1.0.1
49
41
*/
50
- public final class ConfigUtil {
42
+ final class ConfigUtil {
51
43
52
44
/**
53
45
* Instantiates a new config util.
54
46
*/
55
47
private ConfigUtil () {
56
48
}
57
49
58
- /**
59
- * Creates the dummy config.
60
- *
61
- * @return the configuration
62
- */
63
- static Configuration createDummyConfig () {
64
- Configuration conf = new Configuration ();
65
- List <Handler > handlers = new ArrayList <>();
66
- FileAuditHandler handler = new FileAuditHandler ();
67
- handler .setArchive ("true" );
68
- handler .setCronPattern ("1d1M" );
69
- handlers .add (handler );
70
- //FileAuditHandler handler = new FileAuditHandler();
71
- //handlers.add(handler);
72
- ConsoleAuditHandler handler2 = new ConsoleAuditHandler ();
73
- handlers .add (handler2 );
74
- conf .setHandlers (handlers );
75
- conf .setLayout (new SimpleLayout ());
76
- conf .setOptions ("sd" );
77
- Map <String ,String > properties = new HashMap <String ,String >();
78
- properties .put ("log.file.location" , "$user.dir" );
79
- conf .setProperties (properties );
80
- //conf.setMetaData(new DummyMetaData());
81
- return conf ;
82
- }
83
-
84
50
/**
85
51
* Generate config from object.
86
52
*/
@@ -89,43 +55,18 @@ static void generateConfigFromObject() {
89
55
try {
90
56
writer = new YamlWriter (new FileWriter ("audit4j.conf.yml" ));
91
57
writer .getConfig ().setClassTag ("Configuration" , Configuration .class );
92
- writer .write (createDummyConfig () );
58
+ writer .write (Configuration . DEFAULT );
93
59
writer .close ();
94
60
} catch (IOException e ) {
95
61
// TODO Auto-generated catch block
96
62
e .printStackTrace ();
97
63
}
98
64
}
99
65
100
- /**
101
- * Generate config from text.
102
- */
103
- public static void generateConfigFromText () {
104
- StringBuffer yml = new StringBuffer ("!Configuration\n " );
105
- yml .append ("released: " ).append (CoreConstants .RELEASE_DATE ).append ("\n " );
106
- yml .append ("version: " ).append (CoreConstants .RELEASE_VERSION ).append ("\n " );
107
- yml .append ("handlers:" ).append ("\n " );
108
- yml .append ("- !org.audit4j.core.handler.ConsoleAuditHandler {}" ).append ("\n " );
109
- yml .append ("- !org.audit4j.core.handler.file.FileAuditHandler {}" ).append ("\n " );
110
- yml .append ("layout: !org.audit4j.core.layout.SimpleLayout {}" ).append ("\n " );
111
- yml .append ("metaData: !org.audit4j.core.DummyMetaData {}" ).append ("\n " );
112
- yml .append ("properties:" ).append ("\n " );
113
- yml .append (" log.file.location: user.dir" ).append ("\n " );
114
-
115
- File file = new File (CoreConstants .CONFIG_FILE_NAME );
116
- try {
117
- FileWriter fw = new FileWriter (file .getAbsoluteFile ());
118
- BufferedWriter bw = new BufferedWriter (fw );
119
- bw .write (yml .toString ());
120
- bw .close ();
121
- } catch (IOException e ) {
122
- throw new TroubleshootException ("Unable to create configuration file. " , e );
123
- }
124
- }
125
-
126
66
/**
127
67
* Read config.
128
68
*
69
+ * @param filePath the file path
129
70
* @return the configuration
130
71
* @throws ConfigurationException the configuration exception
131
72
*/
@@ -143,15 +84,17 @@ static Configuration readConfig(final String filePath) throws ConfigurationExcep
143
84
}
144
85
}
145
86
87
+ /**
88
+ * Gets the handler class names.
89
+ *
90
+ * @param handlers the handlers
91
+ * @return the handler class names
92
+ */
146
93
static List <String > getHandlerClassNames (List <Handler > handlers ){
147
94
List <String > handlerClassNameList = new ArrayList <>();
148
95
for (Handler handler : handlers ) {
149
96
handlerClassNameList .add (handler .getClass ().getName ());
150
97
}
151
98
return handlerClassNameList ;
152
99
}
153
-
154
- public static void main (String [] args ) {
155
- generateConfigFromObject ();
156
- }
157
100
}
0 commit comments