本文整理汇总了Java中org.javarosa.core.model.QuestionDef类的典型用法代码示例。如果您正苦于以下问题:Java QuestionDef类的具体用法?Java QuestionDef怎么用?Java QuestionDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QuestionDef类属于org.javarosa.core.model包,在下文中一共展示了QuestionDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSelectItemText
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
/**
* Attempts to return the specified Item (from a select or 1select) text.
* Will check for text in the following order:<br/>
* Localized Text (long form) -> Localized Text (no special form) <br />
* If no textID is available, method will return this item's labelInnerText.
* @param sel the selection (item), if <code>null</code> will throw a IllegalArgumentException
* @return Question Text. <code>null</code> if no text for this element exists (after all fallbacks).
* @throws RunTimeException if this method is called on an element that is NOT a QuestionDef
* @throws IllegalArgumentException if Selection is <code>null</code>
*/
public String getSelectItemText(Selection sel){
//throw tantrum if this method is called when it shouldn't be or sel==null
if(!(getFormElement() instanceof QuestionDef)) throw new RuntimeException("Can't retrieve question text for non-QuestionDef form elements!");
if(sel == null) throw new IllegalArgumentException("Cannot use null as an argument!");
//Just in case the selection hasn't had a chance to be initialized yet.
if(sel.index == -1) { sel.attachChoice(this.getQuestion()); }
//check for the null id case and return labelInnerText if it is so.
String tid = sel.choice.getTextID();
if(tid == null || tid == "") return substituteStringArgs(sel.choice.getLabelInnerText());
//otherwise check for 'long' form of the textID, then for the default form and return
String returnText;
returnText = getIText(tid, "long");
if(returnText == null) returnText = getIText(tid,null);
return substituteStringArgs(returnText);
}
示例2: getCaptionHierarchy
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
/**
* Returns a hierarchical list of FormEntryCaption objects for the given
* FormIndex
*
* @param index
* @return list of FormEntryCaptions in hierarchical order
*/
public FormEntryCaption[] getCaptionHierarchy(FormIndex index) {
List<FormEntryCaption> captions = new ArrayList<FormEntryCaption>();
FormIndex remaining = index;
while (remaining != null) {
remaining = remaining.getNextLevel();
FormIndex localIndex = index.diff(remaining);
IFormElement element = form.getChild(localIndex);
if (element != null) {
FormEntryCaption caption = null;
if (element instanceof GroupDef)
caption = new FormEntryCaption(getForm(), localIndex);
else if (element instanceof QuestionDef)
caption = new FormEntryPrompt(getForm(), localIndex);
if (caption != null) {
captions.add(caption);
}
}
}
FormEntryCaption[] captionArray = new FormEntryCaption[captions.size()];
return captions.toArray(captionArray);
}
示例3: attachChoice
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
public void attachChoice (QuestionDef q) {
if (q.getDynamicChoices() != null) //can't attach dynamic choices because they aren't guaranteed to exist yet
return;
SelectChoice choice = null;
if (index != -1 && index < q.getNumChoices()) {
choice = q.getChoice(index);
} else if (xmlValue != null && xmlValue.length() > 0) {
choice = q.getChoiceForValue(xmlValue);
}
if (choice != null) {
attachChoice(choice);
} else {
throw new XPathTypeMismatchException("value " + xmlValue + " could not be loaded into question " + q.getTextID()
+ ". Check to see if value " + xmlValue + " is a valid option for question " + q.getTextID() + ".");
}
}
示例4: parseUpload
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
protected QuestionDef parseUpload(IFormElement parent, Element e, int controlUpload) {
List<String> usedAtts = new ArrayList<String>();
usedAtts.add("mediatype");
// get media type value
String mediaType = e.getAttributeValue(null, "mediatype");
// parse the control
QuestionDef question = parseControl(parent, e, controlUpload, usedAtts);
// apply the media type value to the returned question def.
if ("image/*".equals(mediaType)) {
// NOTE: this could be further expanded.
question.setControlType(Constants.CONTROL_IMAGE_CHOOSE);
} else if("audio/*".equals(mediaType)) {
question.setControlType(Constants.CONTROL_AUDIO_CAPTURE);
} else if ("video/*".equals(mediaType)) {
question.setControlType(Constants.CONTROL_VIDEO_CAPTURE);
}
return question;
}
示例5: parseQuestionLabel
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
private void parseQuestionLabel (QuestionDef q, Element e) {
String label = getLabel(e);
String ref = e.getAttributeValue("", REF_ATTR);
List<String> usedAtts = new ArrayList<String>();
usedAtts.add(REF_ATTR);
if (ref != null) {
if (ref.startsWith(ITEXT_OPEN) && ref.endsWith(ITEXT_CLOSE)) {
String textRef = ref.substring(ITEXT_OPEN.length(), ref.indexOf(ITEXT_CLOSE));
verifyTextMappings(textRef, "Question <label>", true);
q.setTextID(textRef);
} else {
throw new RuntimeException("malformed ref [" + ref + "] for <label>");
}
} else {
q.setLabelInnerText(label);
}
if(XFormUtils.showUnusedAttributeWarning(e, usedAtts)){
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
}
}
示例6: parseHint
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
private void parseHint (QuestionDef q, Element e) {
List<String> usedAtts = new ArrayList<String>();
usedAtts.add(REF_ATTR);
String hint = getXMLText(e, true);
String hintInnerText = getLabel(e);
String ref = e.getAttributeValue("", REF_ATTR);
if (ref != null) {
if (ref.startsWith(ITEXT_OPEN) && ref.endsWith(ITEXT_CLOSE)) {
String textRef = ref.substring(ITEXT_OPEN.length(), ref.indexOf(ITEXT_CLOSE));
verifyTextMappings(textRef, "<hint>", false);
q.setHelpTextID(textRef);
} else {
throw new RuntimeException("malformed ref [" + ref + "] for <hint>");
}
} else {
q.setHelpInnerText(hintInnerText);
q.setHelpText(hint);
}
if(XFormUtils.showUnusedAttributeWarning(e, usedAtts)){
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
}
}
示例7: testNonLocalizedText
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
public void testNonLocalizedText(){
FormEntryController fec = fpi.getFormEntryController();
fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
boolean testFlag = false;
Localizer l = fpi.getFormDef().getLocalizer();
l.setDefaultLocale(l.getAvailableLocales()[0]);
l.setLocale(l.getAvailableLocales()[0]);
do{
if(fpi.getCurrentQuestion()==null) continue;
QuestionDef q = fpi.getCurrentQuestion();
fep = fpi.getFormEntryModel().getQuestionPrompt();
String t = fep.getQuestionText();
if(t==null) continue;
if(t.equals("Non-Localized label inner text!")) testFlag = true;
}while(fec.stepToNextEvent()!=FormEntryController.EVENT_END_OF_FORM);
if(!testFlag) fail("Failed to fallback to labelInnerText in testNonLocalizedText()");
}
示例8: testFlagObservers
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
public void testFlagObservers () {
QuestionDef q = new QuestionDef();
QuestionObserver qo = new QuestionObserver();
q.registerStateObserver(qo);
if (qo.flag || qo.q != null || qo.flags != 0) {
fail("Improper state in question observer");
}
q.unregisterStateObserver(qo);
if (qo.flag) {
fail("Localization observer updated after unregistered");
}
}
示例9: testAnswerConstraint
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
public void testAnswerConstraint(){
IntegerData ans = new IntegerData(13);
FormEntryController fec = fpi.getFormEntryController();
fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
do{
QuestionDef q = fpi.getCurrentQuestion();
if(q==null || q.getTextID() == null || q.getTextID() == "")continue;
if(q.getTextID().equals("constraint-test")){
int response = fec.answerQuestion(ans, true);
if(response == FormEntryController.ANSWER_CONSTRAINT_VIOLATED){
fail("Answer Constraint test failed.");
}else if(response == FormEntryController.ANSWER_OK){
break;
}else{
fail("Bad response from fec.answerQuestion()");
}
}
}while(fec.stepToNextEvent()!=FormEntryController.EVENT_END_OF_FORM);
}
示例10: createSimpleGroupReference
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
public static FormDef createSimpleGroupReference() {
FormDef theform = new FormDef();
QuestionDef question1 = new QuestionDef();
GroupDef group1 = new GroupDef();
QuestionDef question11 = new QuestionDef();
QuestionDef question12 = new QuestionDef();
group1.addChild(question11);
group1.addChild(question12);
QuestionDef question2 = new QuestionDef();
theform.addChild(question1);
theform.addChild(group1);
theform.addChild(question2);
return theform;
}
示例11: createView
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
public void createView() {
//#if javarosa.usepolishlocalisation
//setHint(Locale.get("hint.TypeOrScan"));
//#else
setHint("Type in your answer");
//#endif
//#style textBox
tf = new TextField("", "", 200, TextField.ANY);
if(qDef.instanceNode.required)
tf.setLabel("*"+((QuestionDef)qDef.element).getLongText()); //visual symbol for required
else
tf.setLabel(((QuestionDef)qDef.element).getLongText());
this.append(tf);
this.addNavigationButtons();
if (((QuestionDef)qDef.element).getHelpText()!=null){
setHint(((QuestionDef)qDef.element).getHelpText());
}
}
示例12: getSelectItemText
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
/**
* Attempts to return the specified Item (from a select or 1select) text.
* Will check for text in the following order:<br/>
* Localized Text (long form) -> Localized Text (no special form) <br />
* If no textID is available, method will return this item's labelInnerText.
*
* @param sel the selection (item), if <code>null</code> will throw a IllegalArgumentException
* @return Question Text. <code>null</code> if no text for this element exists (after all fallbacks).
* @throws IllegalArgumentException if Selection is <code>null</code>
*/
public String getSelectItemText(Selection sel) {
//throw tantrum if this method is called when it shouldn't be or sel==null
if (!(getFormElement() instanceof QuestionDef))
throw new RuntimeException("Can't retrieve question text for non-QuestionDef form elements!");
if (sel == null) throw new IllegalArgumentException("Cannot use null as an argument!");
//Just in case the selection hasn't had a chance to be initialized yet.
if (sel.index == -1) {
sel.attachChoice(this.getQuestion());
}
//check for the null id case and return labelInnerText if it is so.
String tid = sel.choice.getTextID();
if (tid == null || "".equals(tid)) {
return substituteStringArgs(sel.choice.getLabelInnerText());
}
//otherwise check for 'long' form of the textID, then for the default form and return
String returnText;
returnText = getIText(tid, "long");
if (returnText == null) returnText = getIText(tid, null);
return substituteStringArgs(returnText);
}
示例13: attachChoice
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
public void attachChoice(QuestionDef q) {
if (q.getDynamicChoices() != null) //can't attach dynamic choices because they aren't guaranteed to exist yet
return;
SelectChoice choice = null;
if (index != -1 && index < q.getNumChoices()) {
choice = q.getChoice(index);
} else if (xmlValue != null && xmlValue.length() > 0) {
choice = q.getChoiceForValue(xmlValue);
}
if (choice != null) {
attachChoice(choice);
} else {
throw new XPathTypeMismatchException("value " + xmlValue + " could not be loaded into question " + q.getTextID()
+ ". Check to see if value " + xmlValue + " is a valid option for question " + q.getTextID() + ".");
}
}
示例14: parseUpload
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
protected QuestionDef parseUpload(IFormElement parent, Element e, int controlUpload) {
Vector<String> usedAtts = new Vector<String>();
usedAtts.addElement("mediatype");
QuestionDef question = parseControl(parent, e, controlUpload, usedAtts);
String mediaType = e.getAttributeValue(null, "mediatype");
if ("image/*".equals(mediaType)) {
// NOTE: this could be further expanded.
question.setControlType(Constants.CONTROL_IMAGE_CHOOSE);
} else if ("audio/*".equals(mediaType)) {
question.setControlType(Constants.CONTROL_AUDIO_CAPTURE);
} else if ("video/*".equals(mediaType)) {
question.setControlType(Constants.CONTROL_VIDEO_CAPTURE);
}
return question;
}
示例15: parseControlChildren
import org.javarosa.core.model.QuestionDef; //导入依赖的package包/类
private void parseControlChildren(Element e, QuestionDef question, IFormElement parent,
boolean isSelect) {
for (int i = 0; i < e.getChildCount(); i++) {
int type = e.getType(i);
Element child = (type == Node.ELEMENT ? e.getElement(i) : null);
if (child == null) {
continue;
}
String childName = child.getName();
if (LABEL_ELEMENT.equals(childName) || HINT_ELEMENT.equals(childName)
|| HELP_ELEMENT.equals(childName) || CONSTRAINT_ELEMENT.equals(childName)) {
parseHelperText(question, child);
} else if (isSelect && "item".equals(childName)) {
parseItem(question, child);
} else if (isSelect && "itemset".equals(childName)) {
parseItemset(question, child);
} else if (actionHandlers.containsKey(childName)) {
actionHandlers.get(childName).handle(this, child, question);
}
}
}