use of org.javarosa.xml.util.UnfullfilledRequirementsException in project javarosa by opendatakit.
the class XFormParser method parseDoc.
private void parseDoc(Map<String, String> namespacePrefixesByUri) {
final CodeTimer codeTimer = new CodeTimer("Creating FormDef from parsed XML");
_f = new FormDef();
initState();
final String defaultNamespace = _xmldoc.getRootElement().getNamespaceUri(null);
parseElement(_xmldoc.getRootElement(), _f, topLevelHandlers);
collapseRepeatGroups(_f);
final FormInstanceParser instanceParser = new FormInstanceParser(_f, defaultNamespace, reporter, bindings, repeats, itemsets, selectOnes, selectMultis, actionTargets);
// if this assumption is wrong, well, then we're screwed.
if (instanceNodes.size() > 1) {
for (int instanceIndex = 1; instanceIndex < instanceNodes.size(); instanceIndex++) {
final Element instance = instanceNodes.get(instanceIndex);
final String instanceId = instanceNodeIdStrs.get(instanceIndex);
final String ediPath = getPathIfExternalDataInstance(instance.getAttributeValue(null, "src"));
if (ediPath != null) {
try {
/* todo implement better error handling */
_f.addNonMainInstance(ExternalDataInstance.buildFromPath(ediPath, instanceId));
} catch (IOException | UnfullfilledRequirementsException | InvalidStructureException | XmlPullParserException e) {
e.printStackTrace();
}
} else {
FormInstance fi = instanceParser.parseInstance(instance, false, instanceNodeIdStrs.get(instanceNodes.indexOf(instance)), namespacePrefixesByUri);
// same situation as below
loadNamespaces(_xmldoc.getRootElement(), fi);
loadInstanceData(instance, fi.getRoot(), _f);
_f.addNonMainInstance(fi);
}
}
}
// now parse the main instance
if (mainInstanceNode != null) {
FormInstance fi = instanceParser.parseInstance(mainInstanceNode, true, instanceNodeIdStrs.get(instanceNodes.indexOf(mainInstanceNode)), namespacePrefixesByUri);
/*
Load namespaces definition (map of prefixes -> URIs) into a form instance so later it can be used
during the form instance serialization (XFormSerializingVisitor#visit). If the map is not present, then
serializer will provide own prefixes for the namespaces present in the nodes.
This will lead to inconsistency between prefixes used in the form definition (bindings)
and prefixes in the form instance after the instance is restored and inserted into the form definition.
*/
loadNamespaces(_xmldoc.getRootElement(), fi);
addMainInstanceToFormDef(mainInstanceNode, fi);
}
// Clear the caches, as these may not have been initialized
// entirely correctly during the validation steps.
Enumeration<DataInstance> e = _f.getNonMainInstances();
while (e.hasMoreElements()) {
DataInstance instance = e.nextElement();
final AbstractTreeElement treeElement = instance.getRoot();
if (treeElement instanceof TreeElement) {
((TreeElement) treeElement).clearChildrenCaches();
}
treeElement.clearCaches();
}
_f.getMainInstance().getRoot().clearChildrenCaches();
_f.getMainInstance().getRoot().clearCaches();
codeTimer.logDone();
}
Aggregations