• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java XFormParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.javarosa.xform.parse.XFormParser的典型用法代码示例。如果您正苦于以下问题:Java XFormParser类的具体用法?Java XFormParser怎么用?Java XFormParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



XFormParser类属于org.javarosa.xform.parse包,在下文中一共展示了XFormParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
	}
 
开发者ID:medic,项目名称:javarosa,代码行数:25,代码来源:FormInstanceValidator.java


示例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);
    }
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:25,代码来源:FormInstanceValidator.java


示例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;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:23,代码来源:FormEntryPrompt.java


示例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);
}
 
开发者ID:dimagi,项目名称:commcare-android,代码行数:26,代码来源:PollSensorExtensionParser.java


示例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;
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:23,代码来源:FormEntryPrompt.java


示例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);

}
 
开发者ID:guardianproject,项目名称:CameraV,代码行数:25,代码来源:FormWrapper.java


示例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;

  }
}
 
开发者ID:Last-Mile-Health,项目名称:ODK-Liberia,代码行数:41,代码来源:FormLoaderTask.java


示例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);
}
 
开发者ID:benetech,项目名称:Secure-App-Generator,代码行数:15,代码来源:OdkFormInstanceValidator.java


示例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();
  }
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:15,代码来源:BaseFormParserForJavaRosa.java


示例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));
		}
	};
}
 
开发者ID:medic,项目名称:javarosa,代码行数:39,代码来源:XFormsModule.java


示例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;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:15,代码来源:XFormUtils.java


示例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);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:11,代码来源:FormEntryPrompt.java


示例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));
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:15,代码来源:FormEntryPrompt.java


示例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));
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:15,代码来源:FormEntryPrompt.java


示例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);
        }
    };
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:10,代码来源:SetValueAction.java


示例16: QuestionDef

import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public QuestionDef(int id, int controlType) {
    setID(id);
    setControlType(controlType);
    observers = new Vector();
    mQuestionStrings = new Hashtable<String, QuestionString>();
    extensions = new Vector<QuestionDataExtension>();
    
    //ctsims 7/8/2015 - Some of Will's code seems to assume that there's ~always a label 
    //defined, which is causing problems with blank questions. Adding this for now to ensure things
    //work reliably
    mQuestionStrings.put(XFormParser.LABEL_ELEMENT, new QuestionString(XFormParser.LABEL_ELEMENT, null));
    actionController = new ActionController();
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:14,代码来源:QuestionDef.java


示例17: setTextID

import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public void setTextID(String textID) {
    if (DateUtils.stringContains(textID, ";")) {
        System.err.println("Warning: TextID contains ;form modifier:: \"" + textID.substring(textID.indexOf(";")) + "\"... will be stripped.");
        textID = textID.substring(0, textID.indexOf(";")); //trim away the form specifier
    }
    this.getQuestionString(XFormParser.LABEL_ELEMENT).setTextId(textID);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:8,代码来源:QuestionDef.java


示例18: getHandler

import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public static IElementHandler getHandler() {
    return new IElementHandler() {
        @Override
        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.parseSendAction(((IFormElement) parent).getActionController(), e);
        }
    };
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:11,代码来源:SendAction.java


示例19: getHandler

import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public static IElementHandler getHandler() {
    return new IElementHandler() {
        @Override
        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);
        }
    };
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:11,代码来源:SetValueAction.java


示例20: QuestionDef

import org.javarosa.xform.parse.XFormParser; //导入依赖的package包/类
public QuestionDef(int id, int controlType) {
    setID(id);
    setControlType(controlType);
    mQuestionStrings = new Hashtable<>();
    extensions = new Vector<>();
    
    //ctsims 7/8/2015 - Some of Will's code seems to assume that there's ~always a label 
    //defined, which is causing problems with blank questions. Adding this for now to ensure things
    //work reliably
    mQuestionStrings.put(XFormParser.LABEL_ELEMENT, new QuestionString(XFormParser.LABEL_ELEMENT, null));
    actionController = new ActionController();
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:13,代码来源:QuestionDef.java



注:本文中的org.javarosa.xform.parse.XFormParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NodesListManagerEventType类代码示例发布时间:2022-05-22
下一篇:
Java JWKSet类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap