5
5
import java .io .IOException ;
6
6
import java .io .InputStream ;
7
7
import java .net .URL ;
8
- import java .util .Properties ;
9
8
10
9
import ch .qos .logback .core .Context ;
11
10
import ch .qos .logback .core .joran .action .ActionUtil ;
12
11
import ch .qos .logback .core .joran .action .ActionUtil .Scope ;
13
12
import ch .qos .logback .core .model .Model ;
14
13
import ch .qos .logback .core .model .ModelConstants ;
15
14
import ch .qos .logback .core .model .PropertyModel ;
16
- import ch .qos .logback .core .model .util .PropertyModelUtil ;
15
+ import ch .qos .logback .core .model .util .PropertyModelHandlerHelper ;
17
16
import ch .qos .logback .core .util .Loader ;
18
17
19
18
public class PropertyModelHandler extends ModelHandlerBase {
@@ -32,55 +31,12 @@ protected Class<PropertyModel> getSupportedModelClass() {
32
31
}
33
32
34
33
@ Override
35
- public void handle (ModelInterpretationContext interpretationContext , Model model ) {
34
+ public void handle (ModelInterpretationContext mic , Model model ) {
36
35
37
36
PropertyModel propertyModel = (PropertyModel ) model ;
38
-
39
- Scope scope = ActionUtil .stringToScope (propertyModel .getScopeStr ());
40
-
41
- if (PropertyModelUtil .checkFileAttributeSanity (propertyModel )) {
42
- String file = propertyModel .getFile ();
43
- file = interpretationContext .subst (file );
44
- try (FileInputStream istream = new FileInputStream (file )) {
45
- loadAndSetProperties (interpretationContext , istream , scope );
46
- } catch (FileNotFoundException e ) {
47
- addError ("Could not find properties file [" + file + "]." );
48
- } catch (IOException |IllegalArgumentException e1 ) { // IllegalArgumentException is thrown in case the file
49
- // is badly malformed, i.e a binary.
50
- addError ("Could not read properties file [" + file + "]." , e1 );
51
- }
52
- } else if (PropertyModelUtil .checkResourceAttributeSanity (propertyModel )) {
53
- String resource = propertyModel .getResource ();
54
- resource = interpretationContext .subst (resource );
55
- URL resourceURL = Loader .getResourceBySelfClassLoader (resource );
56
- if (resourceURL == null ) {
57
- addError ("Could not find resource [" + resource + "]." );
58
- } else {
59
- try ( InputStream istream = resourceURL .openStream ();) {
60
- loadAndSetProperties (interpretationContext , istream , scope );
61
- } catch (IOException e ) {
62
- addError ("Could not read resource file [" + resource + "]." , e );
63
- }
64
- }
65
- } else if (PropertyModelUtil .checkValueNameAttributesSanity (propertyModel )) {
66
- // earlier versions performed Java '\' escapes for '\\' '\t' etc. Howevver, there is no
67
- // need to do this. See RegularEscapeUtil.__UNUSED__basicEscape
68
- String value = propertyModel .getValue ();
69
-
70
- // now remove both leading and trailing spaces
71
- value = value .trim ();
72
- value = interpretationContext .subst (value );
73
- ActionUtil .setProperty (interpretationContext , propertyModel .getName (), value , scope );
74
-
75
- } else {
76
- addError (ModelConstants .INVALID_ATTRIBUTES );
77
- }
78
- }
79
-
80
- void loadAndSetProperties (ModelInterpretationContext mic , InputStream istream , Scope scope ) throws IOException {
81
- Properties props = new Properties ();
82
- props .load (istream );
83
- PropertyModelUtil .setProperties (mic , props , scope );
37
+ PropertyModelHandlerHelper propertyModelHandlerHelper = new PropertyModelHandlerHelper (this );
38
+ propertyModelHandlerHelper .setContext (context );
39
+ propertyModelHandlerHelper .handlePropertyModel (mic , propertyModel );
84
40
}
85
41
86
42
}
0 commit comments