1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.lifecycle;
20
21 import java.io.IOException;
22 import java.util.Iterator;
23
24 import org.apache.commons.jxpath.JXPathContext;
25 import org.apache.commons.jxpath.JXPathNotFoundException;
26 import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
27 import org.apache.maven.plugin.MojoExecution;
28 import org.apache.maven.project.harness.Xpp3DomPointerFactory;
29
30 public class MojoExecutionXPathContainer {
31 private JXPathContext context;
32
33 static {
34 JXPathContextReferenceImpl.addNodePointerFactory(new Xpp3DomPointerFactory());
35 }
36
37 public MojoExecutionXPathContainer(MojoExecution mojoExecution) throws IOException {
38 context = JXPathContext.newContext(mojoExecution);
39 }
40
41 public Iterator<?> getIteratorForXPathExpression(String expression) {
42 return context.iterate(expression);
43 }
44
45 public boolean containsXPathExpression(String expression) {
46 return context.getValue(expression) != null;
47 }
48
49 public Object getValue(String expression) {
50 try {
51 return context.getValue(expression);
52 } catch (JXPathNotFoundException e) {
53 return null;
54 }
55 }
56
57 public boolean xPathExpressionEqualsValue(String expression, String value) {
58 return context.getValue(expression) != null
59 && context.getValue(expression).equals(value);
60 }
61 }