markap14 commented on code in PR #11130:
URL: https://github.com/apache/nifi/pull/11130#discussion_r3261402797
##########
nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/parameter/ParameterContext.java:
##########
@@ -188,4 +188,22 @@ public interface ParameterContext extends ParameterLookup,
ComponentAuthorizable
* @return True if this inherits from the given ParameterContext
*/
boolean inheritsFrom(String parameterContextId);
+
+ /**
+ * Extracts the referenced parameter name from a one-to-one parameter
value reference.
+ * A one-to-one reference is a parameter value whose entire content is
exactly <code>#{parameterName}</code>
+ * with no surrounding text.
+ *
+ * @param value the parameter value to check
+ * @return the referenced parameter name if the value is a one-to-one
reference, or null otherwise
+ */
+ static String extractOneToOneParameterReference(final String value) {
+ if (value == null || value.length() < 4) {
+ return null;
+ }
+ if (value.startsWith("#{") && value.endsWith("}") &&
value.indexOf('}') == value.length() - 1) {
Review Comment:
This is a bit overly simplistic. It does not account for things like quoted
parameter names. So it will work with `#{MyParam}` and properly catches issues
like `#{a}b}}` But it misses cases like `#{'My Parameter'}`
We should instead probably make use of
`ExpressionLanguageAgnosticParameterParser`, and do something along the lines
of:
```
final ParameterParser parser = new
ExpressionLanguageAgnosticParameterParser();
final ParameterTokenList tokenList = parser.parseTokens(value);
final List<ParameterToken> tokens = tokenList.toList();
if (tokens.size() != 1) {
logger.warn("Invalid Parameter Reference: " + value);
}
final ParameterToken firstToken = tokens.getFirst();
if (!firstToken.isParameterReference()) {
logger.warn("Invalid Parameter Reference: " + value);
}
return tokenList.toReferenceList().getFirst().getParameterName();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]