1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.tika.sax.xpath;
18
19
20
21
22
23 public class CompositeMatcher extends Matcher {
24
25 private final Matcher a;
26
27 private final Matcher b;
28
29 public CompositeMatcher(Matcher a, Matcher b) {
30 this.a = a;
31 this.b = b;
32 }
33
34 public Matcher descend(String namespace, String name) {
35 Matcher a = this.a.descend(namespace, name);
36 Matcher b = this.b.descend(namespace, name);
37 if (a == FAIL) {
38 return b;
39 } else if (b == FAIL) {
40 return a;
41 } else if (this.a == a && this.b == b) {
42 return this;
43 } else {
44 return new CompositeMatcher(a, b);
45 }
46 }
47
48 public boolean matchesElement() {
49 return a.matchesElement() || b.matchesElement();
50 }
51
52 public boolean matchesAttribute(String namespace, String name) {
53 return a.matchesAttribute(namespace, name)
54 || b.matchesAttribute(namespace, name);
55 }
56
57 public boolean matchesText() {
58 return a.matchesText() || b.matchesText();
59 }
60
61 }