1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  package ch.qos.logback.core.joran.spi;
15  
16  import java.util.Map;
17  import java.util.Stack;
18  
19  import ch.qos.logback.core.Context;
20  import ch.qos.logback.core.joran.action.Action;
21  import ch.qos.logback.core.model.Model;
22  import ch.qos.logback.core.spi.ContextAwareBase;
23  import ch.qos.logback.core.spi.PropertyContainer;
24  import ch.qos.logback.core.spi.ScanException;
25  import ch.qos.logback.core.util.OptionHelper;
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  public class SaxEventInterpretationContext extends ContextAwareBase implements PropertyContainer {
36      Stack<Model> modelStack;
37  
38      SaxEventInterpreter saxEventInterpreter;
39  
40      public SaxEventInterpretationContext(Context context, SaxEventInterpreter saxEventInterpreter) {
41          this.context = context;
42          this.saxEventInterpreter = saxEventInterpreter;
43          this.modelStack = new Stack<>();
44      }
45  
46      public SaxEventInterpreter getSaxEventInterpreter() {
47          return saxEventInterpreter;
48      }
49  
50      
51  
52  
53  
54  
55      public Model peekModel() {
56          if(modelStack.isEmpty()) {
57              return null;
58          }
59          return modelStack.peek();
60      }
61  
62      public void pushModel(Model m) {
63          modelStack.push(m);
64      }
65  
66      public boolean isModelStackEmpty() {
67          return modelStack.isEmpty();
68      }
69  
70      public Model popModel() {
71          return modelStack.pop();
72      }
73  
74      public Stack<Model> getCopyOfModelStack() {
75          Stack<Model> copy = new Stack<>();
76          copy.addAll(modelStack);
77          return copy;
78      }
79  
80      public void addSubstitutionProperty(String key, String value) {
81          throw new UnsupportedOperationException();
82      }
83  
84      
85  
86  
87  
88      public String getProperty(String key) {
89          return context.getProperty(key);
90      }
91  
92      public Map<String, String> getCopyOfPropertyMap() {
93          return null;
94      }
95  
96      public String subst(String value) {
97          if (value == null) {
98              return null;
99          }
100 
101         try {
102             return OptionHelper.substVars(value, this, context);
103         } catch (ScanException | IllegalArgumentException e) {
104             addError("Problem while parsing [" + value + "]", e);
105             return value;
106         }
107     }
108 
109 }