1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.core.joran.action;
16
17 import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
18 import ch.qos.logback.core.model.Model;
19 import ch.qos.logback.core.model.ResourceModel;
20 import org.xml.sax.Attributes;
21
22
23
24
25
26
27 abstract public class ResourceAction extends BaseModelAction {
28
29 private static final String FILE_ATTR = "file";
30 private static final String URL_ATTR = "url";
31 private static final String RESOURCE_ATTR = "resource";
32 private static final String OPTIONAL_ATTR = "optional";
33
34
35 abstract protected ResourceModel makeNewResourceModel();
36
37 @Override
38 protected boolean validPreconditions(SaxEventInterpretationContext intercon, String name, Attributes attributes) {
39 PreconditionValidator pv = new PreconditionValidator(this, intercon, name, attributes);
40 pv.validateOneAndOnlyOneAttributeProvided(FILE_ATTR, URL_ATTR, RESOURCE_ATTR);
41 return pv.isValid();
42 }
43
44 @Override
45 protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String localName,
46 Attributes attributes) {
47 ResourceModel resourceModel = makeNewResourceModel();
48 fillInIncludeModelAttributes(resourceModel, localName, attributes);
49 return resourceModel;
50 }
51
52
53 private void fillInIncludeModelAttributes(ResourceModel resourceModel, String tagName, Attributes attributes) {
54 resourceModel.setTag(tagName);
55 String fileAttribute = attributes.getValue(FILE_ATTR);
56 String urlAttribute = attributes.getValue(URL_ATTR);
57 String resourceAttribute = attributes.getValue(RESOURCE_ATTR);
58 String optionalAttribute = attributes.getValue(OPTIONAL_ATTR);
59 resourceModel.setFile(fileAttribute);
60 resourceModel.setUrl(urlAttribute);
61 resourceModel.setResource(resourceAttribute);
62 resourceModel.setOptional(optionalAttribute);
63 }
64
65 }