本文整理汇总了Java中org.javarosa.xform.parse.XFormParser类的典型用法代码示例。如果您正苦于以下问题:Java XFormParser类的具体用法?Java XFormParser怎么用?Java XFormParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XFormParser类属于org.javarosa.xform.parse包,在下文中一共展示了XFormParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FormInstanceValidator
import org.javarosa.xform.parse.XFormParser; //导入依赖的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: FormInstanceValidator
import org.javarosa.xform.parse.XFormParser; //导入依赖的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);
}
示例3: hasHelp
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
/**
* Determine if this prompt has any help, whether text or multimedia.
*/
public boolean hasHelp() {
if(this.getQuestion().getQuestionString(XFormParser.HELP_ELEMENT) != null){
return true;
}
Vector<String> forms = new Vector<String>();
forms.addElement(TEXT_FORM_AUDIO);
forms.addElement(TEXT_FORM_IMAGE);
forms.addElement(TEXT_FORM_VIDEO);
for (String form : forms) {
String media = getHelpMultimedia(form);
if (media != null && !"".equals(media)) {
return true;
}
}
return false;
}
示例4: handle
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
/**
* Handle pollsensor node, creating a new PollSensor action with the node that sensor data will be written to.
*
* @param e pollsensor Element
* @param parent FormDef for the form being parsed
*/
@Override
public void handle(XFormParser p, Element e, Object parent) {
String event = e.getAttributeValue(null, "event");
FormDef form = (FormDef)parent;
PollSensorAction action;
String ref = e.getAttributeValue(null, "ref");
if (ref != null) {
XPathReference dataRef = new XPathReference(ref);
dataRef = XFormParser.getAbsRef(dataRef, TreeReference.rootRef());
TreeReference treeRef = FormInstance.unpackReference(dataRef);
p.registerActionTarget(treeRef);
action = new PollSensorAction(treeRef);
} else {
action = new PollSensorAction();
}
form.getActionController().registerEventListener(event, action);
}
示例5: hasHelp
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
/**
* Determine if this prompt has any help, whether text or multimedia.
*/
public boolean hasHelp() {
if(this.getQuestion().getQuestionString(XFormParser.HELP_ELEMENT) != null){
return true;
}
Vector<String> forms = new Vector<>();
forms.addElement(TEXT_FORM_AUDIO);
forms.addElement(TEXT_FORM_IMAGE);
forms.addElement(TEXT_FORM_VIDEO);
for (String form : forms) {
String media = getHelpMultimedia(form);
if (media != null && !"".equals(media)) {
return true;
}
}
return false;
}
示例6: inflatePreviousAnswers
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public void inflatePreviousAnswers(byte[] bytes) {
TreeElement savedRoot = XFormParser.restoreDataModel(bytes, null).getRoot();
for(int t=0; t<savedRoot.getNumChildren(); t++) {
TreeElement childElement = savedRoot.getChildAt(t);
if(answers == null) {
answers = new HashMap<String, String>();
}
try {
//Log.d(LOG, "HERE IS " + childElement.getValue().getValue());
answers.put(childElement.getName(), String.valueOf(childElement.getValue().getValue()));
} catch(NullPointerException e) {
// there is no value here
//Log.e(LOG, "no value for " + childElement.getName());
continue;
}
}
form_def.preloadInstance(savedRoot);
}
示例7: importData
import org.javarosa.xform.parse.XFormParser; //导入依赖的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;
}
}
示例8: validateUserAnswersOneAtATime
import org.javarosa.xform.parse.XFormParser; //导入依赖的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);
}
示例9: parseFormDefinition
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
private static synchronized final XFormParserWithBindEnhancements parseFormDefinition(String xml,
BaseFormParserForJavaRosa parser) throws ODKIncompleteSubmissionData {
StringReader isr = null;
try {
isr = new StringReader(xml);
Document doc = XFormParser.getXMLDocument(isr);
return new XFormParserWithBindEnhancements(parser, doc);
} catch (Exception e) {
throw new ODKIncompleteSubmissionData(e, Reason.BAD_JR_PARSE);
} finally {
isr.close();
}
}
示例10: registerModule
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public void registerModule() {
String[] classes = {
"org.javarosa.model.xform.XPathReference",
"org.javarosa.xpath.XPathConditional"
};
PrototypeManager.registerPrototypes(classes);
PrototypeManager.registerPrototypes(XPathParseTool.xpathClasses);
RestoreUtils.xfFact = new IXFormyFactory () {
public TreeReference ref (String refStr) {
return FormInstance.unpackReference(new XPathReference(refStr));
}
public IDataPayload serializeInstance (FormInstance dm) {
try {
return (new XFormSerializingVisitor()).createSerializedPayload(dm);
} catch (IOException e) {
return null;
}
}
public FormInstance parseRestore(byte[] data, Class restorableType) {
return XFormParser.restoreDataModel(data, restorableType);
}
public IAnswerData parseData (String textVal, int dataType, TreeReference ref, FormDef f) {
return XFormAnswerDataParser.getAnswerData(textVal, dataType, XFormParser.ghettoGetQuestionDef(dataType, f, ref));
}
public String serializeData(IAnswerData data) {
return (String)(new XFormAnswerDataSerializer().serializeAnswerData(data));
}
public IConditionExpr refToPathExpr(TreeReference ref) {
return new XPathConditional(XPathPathExpr.fromRef(ref));
}
};
}
示例11: unusedAttWarning
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public static String unusedAttWarning(Element e, List<String> usedAtts){
String warning = "Warning: ";
List<String> ua = getUnusedAttributes(e,usedAtts);
warning+=ua.size()+" Unrecognized attributes found in Element ["+e.getName()+"] and will be ignored: ";
warning+="[";
for(int i=0;i<ua.size();i++){
warning+=ua.get(i);
if(i!=ua.size()-1) warning+=",";
}
warning+="] ";
warning+="Location:\n"+XFormParser.getVagueLocation(e);
return warning;
}
示例12: getConstraintText
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public String getConstraintText(IAnswerData attemptedValue) {
// new constraint spec uses "alert" form XForm spec 8.2.4
// http://www.w3.org/TR/xforms/#ui-commonelems
String newConstraintMsg = this.localizeText(getQuestion().getQuestionString(XFormParser.CONSTRAINT_ELEMENT));
if(newConstraintMsg != null){
return newConstraintMsg;
}
//default to old logic
return getConstraintText(null, attemptedValue);
}
示例13: getHintText
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
/**
* Get hint text (helper text displayed along with question).
* ONLY RELEVANT to Question elements!
* Will throw runTimeException if this is called for anything that isn't a Question.
* Returns null if no hint text is available
*/
public String getHintText() {
if (!(element instanceof QuestionDef)) {
throw new RuntimeException("Can't get HintText for Elements that are not Questions!");
}
QuestionDef qd = (QuestionDef)element;
return localizeText(qd.getQuestionString(XFormParser.HINT_ELEMENT));
}
示例14: getHelpText
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
/**
* Get help text (helper text displayed when requested by user).
* ONLY RELEVANT to Question elements!
* Will throw runTimeException if this is called for anything that isn't a Question.
* Returns null if no hint text is available
*/
public String getHelpText() {
if (!(element instanceof QuestionDef)) {
throw new RuntimeException("Can't get HelpText for Elements that are not Questions!");
}
QuestionDef qd = (QuestionDef)element;
return localizeText(qd.getQuestionString(XFormParser.HELP_ELEMENT));
}
示例15: getHandler
import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public static IElementHandler getHandler() {
return new IElementHandler() {
public void handle(XFormParser p, Element e, Object parent) {
// the generic parseAction() method in XFormParser already checks to make sure
// that parent is an IFormElement, and throws an exception if it is not
p.parseSetValueAction(((IFormElement) parent).getActionController(), e);
}
};
}