本文整理汇总了Java中org.javarosa.form.api.FormEntryModel类的典型用法代码示例。如果您正苦于以下问题:Java FormEntryModel类的具体用法?Java FormEntryModel怎么用?Java FormEntryModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FormEntryModel类属于org.javarosa.form.api包,在下文中一共展示了FormEntryModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FormInstanceValidator
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
public FormInstanceValidator(InputStream formInput, InputStream instanceInput) throws Exception {
theForm = XFormUtils.getFormFromInputStream(formInput);
savedModel = XFormParser.restoreDataModel(instanceInput, null);
TreeElement templateRoot = theForm.getInstance().getRoot().deepCopy(true);
//sanity check instance names before loading
if (!savedModel.getRoot().getName().equals(templateRoot.getName()) || savedModel.getRoot().getMult() != 0) {
System.out.println("Instance model name does not match xform instance name.");
System.out.println("Instance: " + savedModel.getName() + " Xform: " + templateRoot.getName());
System.exit(1);
}
model = new FormEntryModel(theForm);
controller = new FormEntryController(model);
//Populate XForm Model
// TreeReference tr = TreeReference.rootRef();
// tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);
// templateRoot.populate(savedRoot, f);
//
// f.getInstance().setRoot(templateRoot);
}
示例2: init
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
public void init(){
String xf_name = FORM_NAME;
FileInputStream is;
try {
is = new FileInputStream(xf_name);
} catch (FileNotFoundException e) {
System.err.println("Error: the file '" + xf_name
+ "' could not be found!");
throw new RuntimeException("Error: the file '" + xf_name
+ "' could not be found!");
}
// Parse the form
xform = XFormUtils.getFormFromInputStream(is);
femodel = new FormEntryModel(xform);
fec = new FormEntryController(femodel);
if( xform == null ) {
System.out.println("\n\n==================================\nERROR: XForm has failed validation!!");
} else {
}
}
示例3: countUnansweredQuestions
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
/**
* @param countRequiredOnly
* if true count only the questions that are unanswered and also
* required
* @return number of unanswered questions
*/
public static int countUnansweredQuestions(FormEntryModel model, boolean countRequiredOnly) {
//ctsims - Made this list only count relevant questions
int counter = 0;
for(FormIndex index = model.incrementIndex(FormIndex.createBeginningOfFormIndex());!index.isEndOfFormIndex();index = model.incrementIndex(index)) {
if(!model.isIndexRelevant(index)) {
continue;
}
if(model.getEvent(index) == FormEntryController.EVENT_QUESTION) {
FormEntryPrompt prompt = model.getQuestionPrompt(index);
if(prompt.getAnswerValue() == null) {
if(!countRequiredOnly || prompt.isRequired()) {
counter++;
}
}
}
}
return counter;
}
示例4: countQuestionsToIndex
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
/**
* @param model Form entry model to test index against
* @return number of unanswered questions
*/
public static int countQuestionsToIndex(FormEntryModel model, FormIndex last) {
//ctsims - Made this list only count relevant questions
int counter = 0;
for(FormIndex index = model.incrementIndex(FormIndex.createBeginningOfFormIndex());!index.equals(last);index = model.incrementIndex(index)) {
if(!model.isIndexRelevant(index)) {
continue;
}
if(model.getEvent(index) == FormEntryController.EVENT_QUESTION) {
counter++;
}
}
return counter;
}
示例5: getWidget
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
/**
* NOTE: Only applicable for Questions right now, not any other kind of IFormElement
* @param questionIndex
* @param form
* @param initViewState
* @return
*/
public ChatterboxWidget getWidget (FormIndex questionIndex, FormEntryModel model, int initViewState) {
IWidgetStyle collapsedStyle = null;
IWidgetStyleEditable expandedStyle = null;
FormEntryPrompt prompt = model.getQuestionPrompt(questionIndex);
int controlType = prompt.getControlType();
int dataType = prompt.getDataType();
String appearanceAttr = prompt.getAppearanceHint();
collapsedStyle = new CollapsedWidget();
((CollapsedWidget)collapsedStyle).setSeekable(this.readOnly);
expandedStyle = widgetFactory.getWidget(controlType,dataType,appearanceAttr);
if (collapsedStyle == null || expandedStyle == null) {
throw new IllegalStateException("No appropriate widget to render question");
}
expandedStyle.registerMultimediaController(mediaController);
ChatterboxWidget widget = new ChatterboxWidget(cbox, prompt, initViewState, collapsedStyle, expandedStyle);
prompt.register(widget);
return widget;
}
示例6: getRepeatJunctureWidget
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
public ChatterboxWidget getRepeatJunctureWidget (FormIndex index, FormEntryModel model, Chatterbox cbox) {
FormEntryCaption capt = model.getCaptionPrompt(index);
Vector<String> choices = capt.getRepetitionsText();
FormEntryCaption.RepeatOptions repopt = capt.getRepeatOptions();
FakedFormEntryPrompt prompt = new FakedFormEntryPrompt(repopt.header, Constants.CONTROL_SELECT_ONE, Constants.DATATYPE_TEXT);
for (int i = 0; i < choices.size(); i++) {
prompt.addSelectChoice(new SelectChoice(null, choices.elementAt(i), "rep" + i, false));
}
if (repopt.add != null) {
prompt.addSelectChoice(new SelectChoice(null, repopt.add, "new", false));
}
if (repopt.delete != null) {
prompt.addSelectChoice(new SelectChoice(null, repopt.delete, "del", false));
}
prompt.addSelectChoice(new SelectChoice(null, repopt.done, "done", false));
return new ChatterboxWidget(cbox, prompt, ChatterboxWidget.VIEW_EXPANDED, new CollapsedWidget(), new SelectOneEntryWidget(ChoiceGroup.EXCLUSIVE));
}
示例7: setup
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
public FormEntryController setup(InstanceInitializationFactory factory) {
form.setEvaluationContext(getEC());
form.initialize(true, factory, preferredLocale);
if(recording) {
session = new Session();
currentStep = new Step();
} else {
currentStep = session.getSteps().elementAt(0);
}
FormEntryModel fem = new FormEntryModel(form);
FormEntryController fec = FormEntryController.buildRecordingController(fem);
return fec;
}
示例8: FormInstanceValidator
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
public FormInstanceValidator(InputStream formInput, InputStream instanceInput) throws Exception {
theForm = XFormUtils.getFormFromInputStream(formInput);
savedModel = XFormParser.restoreDataModel(instanceInput, null);
TreeElement templateRoot = theForm.getInstance().getRoot().deepCopy(true);
//sanity check instance names before loading
if (!savedModel.getRoot().getName().equals(templateRoot.getName()) || savedModel.getRoot().getMult() != 0) {
System.out.println("Instance model name does not match xform instance name.");
System.out.println("Instance: " + savedModel.getName() + " Xform: " + templateRoot.getName());
System.exit(1);
}
model = new FormEntryModel(theForm);
controller = new FormEntryController(model);
//Populate XForm Model
// TreeReference tr = TreeReference.rootRef();
// tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);
// templateRoot.populate(savedRoot, f);
//
// f.getInstance().setRoot(templateRoot);
}
示例9: isXFormValid
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
protected StringBuilder isXFormValid(File xformFile) throws ParserConfigurationException, SAXException, IOException
{
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
dBuilder.parse(xformFile);
byte[] xformRawData = Files.readAllBytes(xformFile.toPath());
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xformRawData);
FormDef formDef = XFormUtils.getFormFromInputStream(byteArrayInputStream);
FormEntryModel formEntryModel = new FormEntryModel(formDef);
StringBuilder fieldErrors = new StringBuilder();
inspectFields(formEntryModel, formDef, fieldErrors);
return fieldErrors;
}
示例10: validateUserAnswersOneAtATime
import org.javarosa.form.api.FormEntryModel; //导入依赖的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);
}
示例11: listQuestions
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
private static void listQuestions (FormDef f, int indent, StringBuilder sb) {
//using fec to walk through form (instead of old recursive algorithm)
FormEntryModel femodel = new FormEntryModel(f);
FormEntryController fec = new FormEntryController(femodel);
fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
IFormElement fe;
do{
fe = femodel.getCaptionPrompt().getFormElement();
if(fe instanceof QuestionDef){
listQuestion(f,(QuestionDef)fe,fec,indent,sb);
}else if(fe instanceof GroupDef){
if (listGroup(f, (GroupDef)fe, indent, sb)) {
indent += 1;
}
}
}while(fec.stepToNextEvent()!=fec.EVENT_END_OF_FORM);
//Old Recursive Algorithm
// if (fe instanceof QuestionDef) {
// listQuestion(f, (QuestionDef)fe, indent, sb);
// } else {
// if (fe instanceof GroupDef) {
// if (listGroup(f, (GroupDef)fe, indent, sb)) {
// indent += 1;
// }
// }
//
// for (int i = 0; i < fe.getChildren().size(); i++) {
// listQuestions(f, fe.getChild(i), indent, sb);
// }
// }
}
示例12: listQuestion
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
private static void listQuestion (FormDef f, QuestionDef q,FormEntryController fec, int indent, StringBuilder sb) {
FormEntryModel femodel = fec.getModel();
TreeElement instanceNode = getInstanceNode(f.getInstance(), q.getBind());
String caption = "";
FormEntryPrompt fep = femodel.getQuestionPrompt();
caption = fep.getLongText();
int type = instanceNode.getDataType();
if (q.getControlType() != Constants.CONTROL_TRIGGER) {
println(sb, indent, "Question: \"" + caption + "\"");
println(sb, indent + 1, "Type: " + printType(type));
} else {
println(sb, indent, "Info: \"" + caption + "\"");
}
if (q.getControlType() == Constants.CONTROL_SELECT_ONE || q.getControlType() == Constants.CONTROL_SELECT_MULTI) {
printChoices(f,q,fec, indent + 1, sb);
}
printProperty("relevant", f, instanceNode, indent + 1, sb);
printProperty("required", f, instanceNode, indent + 1, sb);
printProperty("readonly", f, instanceNode, indent + 1, sb);
String defaultValue = printDefault(instanceNode);
if (defaultValue != null) {
println(sb, indent + 1, "Default: " + defaultValue);
}
if (instanceNode.getConstraint() != null) {
println(sb, indent + 1, "Constraint: " + printCondition(instanceNode.getConstraint().constraint));
}
println(sb);
}
示例13: printChoices
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
private static void printChoices (FormDef f,QuestionDef q,FormEntryController fec,int indent, StringBuilder sb) {
FormEntryModel femodel = fec.getModel();
println(sb, indent, "Choices: " + q.getNumChoices());
// for (int i = 0; i < q.getNumChoices(); i++) {
for (SelectChoice choice : q.getChoices()){
println(sb, indent + 1, "\"" + femodel.getQuestionPrompt().getSelectChoiceText(choice) + "\"");
}
}
示例14: listGroup
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
private static boolean listGroup (FormDef f, GroupDef g, int indent, StringBuilder sb) {
FormEntryModel femodel = new FormEntryModel(f);
boolean repeat = g.getRepeat();
String caption = ExtUtil.nullIfEmpty(femodel.getCaptionPrompt().getLongText());
TreeElement instanceNode = getInstanceNode(f.getInstance(), g.getBind());
String relevant = printConditionalProperty("relevant", f, instanceNode);
String readonly = printConditionalProperty("readonly", f, instanceNode);
if (repeat || caption != null || (relevant != null || readonly != null)) {
println(sb, indent, (repeat ? "Repeat" : "Group") + ":" + (caption != null ? " \"" + caption + "\"" : ""));
if (relevant != null) {
println(sb, indent + 1, relevant);
}
if (readonly != null) {
println(sb, indent + 1, readonly);
}
println(sb);
return true;
} else {
return false;
}
}
示例15: FormSummaryView
import org.javarosa.form.api.FormEntryModel; //导入依赖的package包/类
public FormSummaryView(FormEntryModel model) {
//#style View_All_Form
super("Form Overview", List.IMPLICIT);
this.model = model;
createView();
addCommand(CMD_EXIT);
// TODO: handle readonly
if (true) {
addCommand(CMD_SAVE_EXIT);
}
}