aboutsummaryrefslogtreecommitdiffstats
path: root/cps-path-parser/src/main/java/org
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-11-27 15:38:41 +0000
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-12-02 13:30:15 +0000
commitd262e1c3f4671673a02ea402366a8c9b93fe4e53 (patch)
tree8805f57e86733f5766e02eed6bb218f54f000282 /cps-path-parser/src/main/java/org
parent7cd33c3f6784b5df58cb242847719c4faec7eca3 (diff)
[Cps Path Parser] Introduce Attribute axis
Add grammar and tests for attribute-axis to match cps paths like: //books/@title which should return the titles of all books (a subsequent patch will implement the logic). The syntax is compatible with XPath standard. Issue-ID: CPS-2416 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I25164b23670147c504f0f0f6c0cc8ff15997f2a3
Diffstat (limited to 'cps-path-parser/src/main/java/org')
-rw-r--r--cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java7
-rw-r--r--cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java10
2 files changed, 17 insertions, 0 deletions
diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
index b67d70847c..d0deb7defc 100644
--- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
+++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
@@ -131,6 +131,13 @@ public class CpsPathBuilder extends CpsPathBaseListener {
}
@Override
+ public void exitAttributeAxis(final CpsPathParser.AttributeAxisContext ctx) {
+ final String attributeName = ctx.leafName().getText();
+ normalizedXpathBuilder.append("/@").append(attributeName);
+ cpsPathQuery.setAttributeAxisAttributeName(attributeName);
+ }
+
+ @Override
public void exitTextFunctionCondition(final TextFunctionConditionContext ctx) {
cpsPathQuery.setTextFunctionConditionLeafName(ctx.leafName().getText());
cpsPathQuery.setTextFunctionConditionValue(unwrapQuotedString(ctx.StringLiteral().getText()));
diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java
index 03602b64f6..3612ec57fb 100644
--- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java
+++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java
@@ -40,6 +40,7 @@ public class CpsPathQuery {
private String descendantName;
private List<LeafCondition> leafConditions;
private String ancestorSchemaNodeIdentifier = "";
+ private String attributeAxisAttributeName = "";
private String textFunctionConditionLeafName;
private String textFunctionConditionValue;
private List<String> booleanOperators;
@@ -66,6 +67,15 @@ public class CpsPathQuery {
}
/**
+ * Has attribute axis been included in cpsPath.
+ *
+ * @return boolean value.
+ */
+ public boolean hasAttributeAxis() {
+ return !(attributeAxisAttributeName.isEmpty());
+ }
+
+ /**
* Have leaf value conditions been included in cpsPath.
*
* @return boolean value.