javarosa library

The JavaRosa-compatible API of DartRosa: FormDef, the form-entry controller/model/prompts, the XForm parser and its plugin interfaces, for code ported from JavaRosa or needing its full surface.

Most apps should use package:dartrosa/dartrosa.dart instead.

Classes

Action
An XForms action such as <setvalue>.
ActionController
The actions registered on a form element, by event.
BindAttributeProcessor
Handles bind attributes it declares (e.g. ODK Collect's entities saveto).
CmpPivot
A comparison of the validated node with value using op.
CompareToNodeExpression
A predicate comparing a relative path (evaluated on each candidate node) with a value that doesn't depend on the candidate: name = 'x', value > /data/limit, or a two-argument idempotent function such as selected(choices, /data/q).
ComparisonExpressionCacheFilterStrategy
Caches the results of node-comparison predicates (and and/or of two of them) on secondary instances, keyed by the context value.
Condition
A relevant, required or readonly condition. Port of Condition.
Constraint
A bind's constraint and its message.
ConstraintHint
Information derived from a constraint, such as a range.
CsvReader
A CSV reader with commons-csv 1.4 CSVFormat.DEFAULT semantics: " quoting with "" escapes, \r, \n or \r\n record separators, empty lines skipped, no comments, no trimming.
DataBinding
A parsed <bind>. Only used while parsing.
DataInstance
An instance: a tree of TreeElements under a hidden base node.
DateRangeHint
Date bounds (days since the epoch). Port of DateRangeHint.
DecimalRangeHint
Decimal bounds. Port of DecimalRangeHint.
ElementChange
Kinds of change reported to TreeElementListeners, as bit flags.
EqualityExpressionIndexFilterStrategy
Answers [relative-path = value] predicates on a secondary instance from an index of the candidates' values, built on first use.
EvaluationContext
Everything an XPath expression needs to evaluate: the instances, the context node, function handlers, variables and constraint state.
EvaluationEvent
A step of form evaluation, for debugging and tracing.
ExternalDataInstance
A secondary instance loaded from a src URI (jr://file/…, jr://file-csv/…, GeoJSON, or an InstanceProvider).
ExternalDataInstanceProcessor
Called for every external secondary instance. Port of XFormParser.ExternalDataInstanceProcessor.
ExternalInstanceParser
Turns a secondary instance's src into a TreeElement tree.
Extras<T extends Object>
App- or plugin-defined objects attached to a form, at most one per type.
FileInstanceParser
Parses the content of a secondary-instance file of some format.
FilterStrategy
Filters the children of a nodeset by a predicate, or delegates to the next strategy in the chain.
FormDef
A parsed form: its controls, instances, binds, translations and submission settings.
FormDefCodec
Saves a form being filled and restores it later (for app restarts, form caches and JavaRosa's serializeAndDeserializeForm tests).
FormDefProcessor
Called with the finished form. Port of XFormParser.FormDefProcessor.
FormElement
A node of the form's control tree: the form itself, a group, a repeat or a question.
FormEntryCaption
The texts of a group, repeat or question at a form index: label, short/media forms and repeat captions, in the current language with <output>s filled in.
FormEntryController
Navigates a form and answers its questions.
FormEntryFinalizationProcessor
Runs after FormEntryController.finalizeFormEntry (for example ODK Collect's entities).
FormEntryModel
The state of filling a form: the current index and what is at an index (event, prompts, relevance, read-only), plus index arithmetic.
FormEntryPrompt
A question at a form index: its texts, answer, choices, constraint message and state.
FormEvents
XForms events that can trigger actions.
FormInstance
The main instance of a form (also used for inline secondary instances).
GroupDef
A <group> or <repeat>.
IdempotentExpressionCacheFilterStrategy
Caches the results of idempotent predicates (no now(), random(), … and no references) for one batch of evaluations.
InstanceProvider
Supplies secondary instances without reading a file, e.g. from a database (ODK Collect uses this for entity lists).
IntegerRangeHint
Integer bounds. Port of IntegerRangeHint.
ItemsetBinding
The <itemset> of a select question: where its choices come from.
KElement
An element.
KText
A non-element child node.
Localizable
Receives locale changes from a Localizer.
Localizer
Translated text for a form: the itext engine.
MapPropertyManager
A PropertyManager backed by a map.
ModelAttributeProcessor
Called for model attributes it declares. Port of XFormParser.ModelAttributeProcessor.
OsmTag
A key and choices offered by an OSM capture question.
OsmTagItem
One choice of an OsmTag. Port of OSMTagItem.
PreloadHandler
Fills a jr:preload node when a form starts, and optionally again when it is finalized.
PropertyManager
Device and user properties such as deviceid, username or email, read by jr:preload="property" and the XPath property() function.
QuestionDef
A question: one form control bound to one instance node.
QuestionPreloader
The jr:preload handlers of a form: date, property, timestamp and uid, plus any added with addPreloadHandler.
QuestionProcessor
Called for every parsed question. Port of XFormParser.QuestionProcessor.
QuestionWidget
Receives state changes of a registered caption or prompt.
RangeHint<T extends AnswerValue>
A minimum and/or maximum derived from a constraint.
RangeQuestion
A <range> question with its bounds.
RawFilterStrategy
Evaluates the predicate for each child. Only a boolean true keeps a child, so a numeric predicate such as [2] keeps nothing (JavaRosa handles positions through multiplicities, not predicates).
Recalculate
A calculate. Port of Recalculate.
RecordAudioAction
<odk:recordaudio>: asks the app to record audio into targetReference in the background.
SetGeopointAction
<odk:setgeopoint>: records the device location into targetReference.
SetValueAction
<setvalue>: sets target to value when its event fires.
StringLengthRangeHint
String length bounds, e.g. from string-length(.) <= 10. Port of StringLengthRangeHint.
StubSetGeopointAction
Stores "no client implementation", as JavaRosa's default.
TreeElement
A node of an instance: an element (or attribute) with a name, multiplicity, value or children, and model properties such as relevance.
Triggerable
An expression whose result is applied to target nodes: a Condition (relevant/required/readonly) or a Recalculate (calculate).
TriggerableDag
The dependency graph of a form's calculations and relevant, required and readonly conditions: which triggerables a change re-evaluates, and in which order.
ValidateOutcome
Where validating a form stopped: the failing question and why.
XFormParser
Parses an XForm into a FormDef.
XPathArgType
An argument type a XPathFunctionHandler prototype can declare.
XPathArithExpr
a + b, a - b, a * b, a div b, a mod b.
XPathBinaryOpExpr
An expression with two operands.
XPathBoolExpr
a and b, a or b.
XPathCmpExpr
a < b, a > b, a <= b, a >= b.
XPathConditional
A parsed XPath expression used as a condition, calculation or nodeset, together with its source text.
XPathEqExpr
a = b (when equal) or a != b.
XPathExpression
A parsed XPath expression.
XPathFallbackFunctionHandler
Handles any function no built-in or registered handler knows.
XPathFilterExpr
An expression followed by predicates, such as f()[1].
XPathFuncExpr
A function call such as concat(a, 'b').
XPathFunctionHandler
A custom XPath function, such as ODK Collect's pulldata.
XPathNodeset
The result of a path expression: a list of node references.
XPathNumericLiteral
A number literal such as 5 or .25.
XPathNumNegExpr
Unary minus, -a.
XPathPathExpr
A location path such as /data/age or ../name[1].
XPathProcessor
Called for every XPath expression parsed from the form. Port of XFormParser.XPathProcessor.
XPathQName
A qualified name such as jr:choice-name or age.
XPathStep
One step of a location path, such as child::age[1].
XPathStringLiteral
A string literal such as 'yes'.
XPathUnionExpr
a | b. Parsed, but JavaRosa does not support evaluating it.
XPathVariableReference
A variable reference such as $name.

Enums

AnswerStatus
The outcome of answering a question.
ArithOp
Arithmetic operators.
BoolOp
Boolean operators.
CmpOp
Relational operators.
ConditionAction
What a relevant/required/readonly condition does when true or false.
FormEntryEvent
What is at a form index while filling a form.
KNodeType
Kinds of non-element child.
PathStart
Where a location path starts.
RepeatStructure
How repeats are navigated.
StepTest
Kinds of node test in a step.
XPathAxis
XPath axes.

Extensions

FormDefValidation on FormDef
Whole-form validation.
TreeElementPopulate on TreeElement
Filling a template instance tree from a saved one.
XFormInstanceLoading on FormDef
Loading saved instance XML into a parsed form.

Constants

idempotentFunctions → const Set<String>
Functions whose result depends only on their arguments.
namespaceHtml → const String
The XHTML namespace.
namespaceOdk → const String
The ODK namespace.

Functions

boolStr(Object value) → bool
boolean-from-string(): true for true (any case) or 1.
createBinding(KElement element, {required FormDef form, required List<String> usedAttributes, required List<String> passedThroughAttributes, required List<BindAttributeProcessor> processors, required TreeReference absoluteRef(TreeReference relative), required TreeReference parseReference(String nodeset), required XPathConditional parseConditional(String xpath)}) → DataBinding
Builds a DataBinding from a <bind> element.
defaultAnswerResolver(String text, TreeElement element, FormDef form) → AnswerValue?
The default AnswerResolver: parses text for the element's data type. Port of DefaultAnswerResolver.
elementMatchesName(TreeElement element, String name) → bool
Whether element matches name: the wildcard *, its name, or prefix:name with its namespace prefix.
getXmlDocument(String source) → KElement
Parses source and consolidates its text, as JavaRosa's XFormParser.getXMLDocument does: the document element of the result.
javaDoubleToString(double value) → String
Formats value exactly as Java's Double.toString(double) (JDK 19+).
javaParseDouble(String input) → double?
Java Double.parseDouble: trims characters <= ' ', accepts an optional sign, NaN, Infinity, decimal and exponent notation, a trailing f/F/d/D, and hexadecimal floating point. Returns null where Java throws NumberFormatException.
javaParseInt(String s, {int bits = 32}) → int?
Java Integer.parseInt (32-bit) or, with bits 64, Long.parseLong.
javaTrim(String s) → String
Java String.trim(): strips leading and trailing characters <= ' '.
parseXmlExternalInstance(String instanceId, Uint8List bytes) → TreeElement
Parses an XML secondary-instance file: its document element becomes the instance's top-level element. Port of XmlExternalInstance.parse.
parseXPath(String xpath) → XPathExpression
Parses an XPath expression.
pivotsOf(XPathExpression expression, DataInstance? model, EvaluationContext context) → List<Object>
Collects the pivots of expression around the context node of context.
questionForData(DataType dataType, FormDef? form, TreeReference ref) → QuestionDef?
The select question bound to ref, needed to attach choices.
randomUuid() → String
A random (version 4) UUID such as 0f8fad5b-d9cb-469f-a165-70867728950e.
toXPathString(Object value) → String
XPath string().
unpack(Object value) → Object
The single value of a nodeset; other values unchanged.
xmlText(KElement node, {required bool trim, int from = 0}) → String?
The text of node's first child and the text children right after it, optionally trimmed; null without children or when the first child isn't text. Port of XFormParser.getXMLText.

Typedefs

ActionElementHandler = void Function(XFormParser parser, KElement element, FormElement parent)
Handles an action element on its parent form element.
ActionResultProcessor = void Function(TreeReference target, String event)
Receives the reference each triggered action set. Port of ActionController.ActionResultProcessor.
AnswerResolver = AnswerValue? Function(String text, TreeElement element, FormDef form)
Turns a saved answer's text into a typed answer for element.
EvaluationResult = ({TreeReference ref, Object value})
One node a triggerable was applied to, with the value it got.
FormElementListener = void Function(FormElement element, int changes)
Receives state changes of a FormElement (an ElementChange flag set).
KAttribute = ({String name, String namespace, String value})
An attribute: namespace URI ('' for none), local name and value.
RecordAudioListener = void Function(TreeReference absoluteTargetRef, String? quality)
Receives <odk:recordaudio> requests.
TreeElementListener = void Function(TreeElement element, int changes)
Receives state changes of a TreeElement: changes is a combination of ElementChange flags.

Exceptions / Errors

InvalidReferenceException
A reference that can't be used for the requested operation. Port of org.javarosa.core.model.instance.InvalidReferenceException.
PartialElementEncounteredException
Thrown when resolving a reference reaches an element whose content has not been loaded yet. Port of PartialElementEncounteredException.
TriggerableEvaluationException
An error evaluating a calculation or condition, naming the field.
UnpivotableExpressionException
The expression can't be turned into hints.