本文整理汇总了Java中org.javarosa.core.model.instance.TreeElement.populate方法的典型用法代码示例。如果您正苦于以下问题:Java TreeElement.populate方法的具体用法?Java TreeElement.populate怎么用?Java TreeElement.populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.javarosa.core.model.instance.TreeElement
的用法示例。
在下文中一共展示了TreeElement.populate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadXmlInstance
import org.javarosa.core.model.instance.TreeElement; //导入方法依赖的package包/类
/**
* Load a compatible xml instance into FormDef f
*
* call before f.initialize()!
*/
public static void loadXmlInstance(FormDef f, Document xmlInst) {
TreeElement savedRoot = XFormParser.restoreDataModel(xmlInst, null).getRoot();
TreeElement templateRoot = f.getMainInstance().getRoot().deepCopy(true);
// weak check for matching forms
// TODO: should check that namespaces match?
if (!savedRoot.getName().equals(templateRoot.getName()) || savedRoot.getMult() != 0) {
throw new RuntimeException("Saved form instance does not match template form definition");
}
// populate the data model
TreeReference tr = TreeReference.rootRef();
tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);
templateRoot.populate(savedRoot, f);
// populated model to current form
f.getMainInstance().setRoot(templateRoot);
// if the new instance is inserted into the formdef before f.initialize() is called, this
// locale refresh is unnecessary
// Localizer loc = f.getLocalizer();
// if (loc != null) {
// f.localeChanged(loc.getLocale(), loc);
// }
}
示例2: importData
import org.javarosa.core.model.instance.TreeElement; //导入方法依赖的package包/类
public boolean importData(File instanceFile, FormEntryController fec) {
publishProgress(Collect.getInstance().getString(R.string.survey_loading_reading_data_message));
// convert files into a byte array
byte[] fileBytes = FileUtils.getFileAsBytes(instanceFile);
// get the root of the saved and template instances
TreeElement savedRoot = XFormParser.restoreDataModel(fileBytes, null).getRoot();
TreeElement templateRoot = fec.getModel().getForm().getInstance().getRoot().deepCopy(true);
// weak check for matching forms
if (!savedRoot.getName().equals(templateRoot.getName()) || savedRoot.getMult() != 0) {
Log.e(t, "Saved form instance does not match template form definition");
return false;
} else {
// populate the data model
TreeReference tr = TreeReference.rootRef();
tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);
// Here we set the Collect's implementation of the IAnswerResolver.
// We set it back to the default after select choices have been populated.
XFormParser.setAnswerResolver(new ExternalAnswerResolver());
templateRoot.populate(savedRoot, fec.getModel().getForm());
XFormParser.setAnswerResolver(new DefaultAnswerResolver());
// populated model to current form
fec.getModel().getForm().getInstance().setRoot(templateRoot);
// fix any language issues
// :
// http://bitbucket.org/javarosa/main/issue/5/itext-n-appearing-in-restored-instances
if (fec.getModel().getLanguages() != null) {
fec.getModel().getForm()
.localeChanged(fec.getModel().getLanguage(), fec.getModel().getForm().getLocalizer());
}
return true;
}
}
示例3: validateUserAnswersOneAtATime
import org.javarosa.core.model.instance.TreeElement; //导入方法依赖的package包/类
public int validateUserAnswersOneAtATime() throws Exception {
FormDef formDef = XFormUtils.getFormFromInputStream(new ByteArrayInputStream(getFormModel().getBytes("UTF-8")));
FormEntryModel formEntryModel = new FormEntryModel(formDef);
FormEntryController formEntryController = new FormEntryController(formEntryModel);
TreeElement modelRootElement = formEntryController.getModel().getForm().getInstance().getRoot().deepCopy(true);
TreeElement instanceRootElement = XFormParser.restoreDataModel(getFormInstance().getBytes("UTF-8"), null).getRoot();
populateDataModel(modelRootElement);
modelRootElement.populate(instanceRootElement, formEntryController.getModel().getForm());
populateFormEntryControllerModel(formEntryController, modelRootElement);
fixLanguageIusses(formEntryController);
return createFieldSpecsFromXForms(formEntryController);
}