Add ability to process xpath expressions during parse #733
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work toward getodk/collect#5620
This adds a new
XPathProcessor
forXFormProcessor
that allows a client to inspect every XPath expression in an XForm during parse:I've also added a lock to
XFormParser#parse
that will prevent two forms being parsed at the same time (even using two differentXFormParser
instances) asXPathProcessor
(and existing parse code) manipulates static state that could cause problems if that were to happen.What has been done to verify that this works as intended?
New tests.
Why is this the best possible solution? Were any other approaches considered?
We had initially considered just using our existing bind processing with
XPathExpression#containsFunc
to findpulldata
, but we realised that we needed a more general solution to be able to detect a custom function anywhere in the form (as it could appear in any xpath expression). I'm not a fan of the static state I've added here, but it felt like a losing battle to avoid it givenXFormParser
was already not thread safe in any way. Down the line, we should look at improving that so clients like Collect can parse multiple forms in parallel.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
Stopping two forms from being parsed simultaneously is probably the riskiest change here. As far as I know, Collect doesn't do this on purpose, but it might be that it's a possibility with things like auto update or match exactly. That said, if that was happening, I'd potentially rather we crash the app than end up with whatever could happen mixing state from two form parses.