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 asselected(choices, /data/q). - ComparisonExpressionCacheFilterStrategy
-
Caches the results of node-comparison predicates (and
and/orof 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
constraintand its message. - ConstraintHint
- Information derived from a constraint, such as a range.
- CsvReader
-
A CSV reader with commons-csv 1.4
CSVFormat.DEFAULTsemantics:"quoting with""escapes,\r,\nor\r\nrecord 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
srcURI (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
srcinto 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
serializeAndDeserializeFormtests). - 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:preloadnode when a form starts, and optionally again when it is finalized. - PropertyManager
-
Device and user properties such as
deviceid,usernameoremail, read byjr:preload="property"and the XPathproperty()function. - QuestionDef
- A question: one form control bound to one instance node.
- QuestionPreloader
-
The
jr:preloadhandlers of a form:date,property,timestampanduid, 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
truekeeps 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 ofStringLengthRangeHint. - 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) ora != 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
5or.25. - XPathNumNegExpr
-
Unary minus,
-a. - XPathPathExpr
-
A location path such as
/data/ageor../name[1]. - XPathProcessor
-
Called for every XPath expression parsed from the form. Port of
XFormParser.XPathProcessor. - XPathQName
-
A qualified name such as
jr:choice-nameorage. - 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 fortrue(any case) or1. -
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
textfor the element's data type. Port ofDefaultAnswerResolver. -
elementMatchesName(
TreeElement element, String name) → bool -
Whether
elementmatchesname: the wildcard*, its name, orprefix:namewith its namespace prefix. -
getXmlDocument(
String source) → KElement -
Parses
sourceand consolidates its text, as JavaRosa'sXFormParser.getXMLDocumentdoes: the document element of the result. -
javaDoubleToString(
double value) → String -
Formats
valueexactly as Java'sDouble.toString(double)(JDK 19+). -
javaParseDouble(
String input) → double? -
Java
Double.parseDouble: trims characters<= ' ', accepts an optional sign,NaN,Infinity, decimal and exponent notation, a trailingf/F/d/D, and hexadecimal floating point. Returnsnullwhere Java throwsNumberFormatException. -
javaParseInt(
String s, {int bits = 32}) → int? -
Java
Integer.parseInt(32-bit) or, withbits64,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
expressionaround the context node ofcontext. -
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;nullwithout children or when the first child isn't text. Port ofXFormParser.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:
changesis 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.