当前位置: 首页>>代码示例>>Java>>正文


Java XFormUtils.getFormFromInputStream方法代码示例

本文整理汇总了Java中org.javarosa.xform.util.XFormUtils.getFormFromInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java XFormUtils.getFormFromInputStream方法的具体用法?Java XFormUtils.getFormFromInputStream怎么用?Java XFormUtils.getFormFromInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.javarosa.xform.util.XFormUtils的用法示例。


在下文中一共展示了XFormUtils.getFormFromInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	// Very simple class that takes in an xform as an argument then outputs the debug
	// info from the XForm parser
	
	if( args.length != 1 ) {
		System.err.println("Usage: validator <xform>\n\tNOTE: the <xform> must be the full path to the file.");
		return;
	}
	
	String xf_name = args[0];
	FileInputStream is;
	try {
		is = new FileInputStream(xf_name);
	} catch (FileNotFoundException e) {
		System.err.println("Error: the file '" + xf_name + "' could not be found!");
		return;
	}
	
	XFormUtils.getFormFromInputStream(is);
}
 
开发者ID:medic,项目名称:javarosa,代码行数:24,代码来源:MainClass.java

示例2: summarize

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
private void summarize() {
	addToTextArea("\n\n==================================\nForm Summary\n==================================\n");
	updateStatus("Creating Summary");
	
	FileInputStream in;
	try {
		in = new FileInputStream(newForm);
		FormDef f = XFormUtils.getFormFromInputStream(in);
		addToTextArea(FormOverview.overview(f, this.languages.getSelectedItem()));
		addToTextArea("\n\n==================================\nForm Summary Complete\n==================================\n");
		updateStatus("Summary Completed");
	} catch (FileNotFoundException e) {
		addToTextArea("ERROR! File Not Found Exception when attempting to load form " + newForm);
		e.printStackTrace();
		updateStatus("Error while loading form");
	}
	 
	
}
 
开发者ID:medic,项目名称:javarosa,代码行数:20,代码来源:XFormValidatorGUI.java

示例3: updateLang

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
private void updateLang() {
	try {
		languages.removeAll();
		FileInputStream in = new FileInputStream(newForm);
		FormDef f = XFormUtils.getFormFromInputStream(in);
		if (f.getLocalizer() != null) {
			String[] locales = f.getLocalizer().getAvailableLocales();
			for (int i = 0; i < locales.length; ++i) {
				languages.add(locales[i]);
			}
			languages.select(f.getLocalizer().getDefaultLocale());
			languages.setVisible(true);
		} else {
			languages.setVisible(false);
		}
	} catch (Exception e) {
		//All failures here should just get swallowed, this is tertiary functionality
		e.printStackTrace();
		languages.setVisible(false);
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:22,代码来源:XFormValidatorGUI.java

示例4: FormInstanceValidator

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的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

示例5: testGeoShapeSupportForEnclosedArea

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
public void testGeoShapeSupportForEnclosedArea() throws Exception {
   // Read the form definition
String FORM_NAME = (new File(PathConst.getTestResourcePath(), "area.xml")).getAbsolutePath();
InputStream is = null;
FormDef formDef = null;
is = new FileInputStream(new File(FORM_NAME));
   formDef = XFormUtils.getFormFromInputStream(is);

   // trigger all calculations
   formDef.initialize(true, new InstanceInitializationFactory());

   // get the calculated area
   IAnswerData areaResult = formDef.getMainInstance().getRoot().getChildAt(1).getValue();

   assertTrue((int) Math.rint((Double) areaResult.getValue()) == 151452);
 }
 
开发者ID:medic,项目名称:javarosa,代码行数:17,代码来源:GeoShapeAreaTest.java

示例6: init

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的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 {
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:24,代码来源:FormParseInit.java

示例7: main

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
    // Very simple class that takes in an xform as an argument then outputs the debug
    // info from the XForm parser

    if( args.length != 1 ) {
        System.err.println("Usage: validator <xform>\n\tNOTE: the <xform> must be the full path to the file.");
        return;
    }

    String xf_name = args[0];
    FileInputStream is;
    try {
        is = new FileInputStream(xf_name);
    } catch (FileNotFoundException e) {
        System.err.println("Error: the file '" + xf_name + "' could not be found!");
        return;
    }

    XFormUtils.getFormFromInputStream(is);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:24,代码来源:MainClass.java

示例8: summarize

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
private void summarize() {
    addToTextArea("\n\n==================================\nForm Summary\n==================================\n");
    updateStatus("Creating Summary");

    FileInputStream in;
    try {
        in = new FileInputStream(newForm);
        FormDef f = XFormUtils.getFormFromInputStream(in);
        addToTextArea(FormOverview.overview(f, this.languages.getSelectedItem()));
        addToTextArea("\n\n==================================\nForm Summary Complete\n==================================\n");
        updateStatus("Summary Completed");
    } catch (FileNotFoundException e) {
        addToTextArea("ERROR! File Not Found Exception when attempting to load form " + newForm);
        e.printStackTrace();
        updateStatus("Error while loading form");
    }


}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:20,代码来源:XFormValidatorGUI.java

示例9: updateLang

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
private void updateLang() {
    try {
        languages.removeAll();
        FileInputStream in = new FileInputStream(newForm);
        FormDef f = XFormUtils.getFormFromInputStream(in);
        if (f.getLocalizer() != null) {
            String[] locales = f.getLocalizer().getAvailableLocales();
            for (int i = 0; i < locales.length; ++i) {
                languages.add(locales[i]);
            }
            languages.select(f.getLocalizer().getDefaultLocale());
            languages.setVisible(true);
        } else {
            languages.setVisible(false);
        }
    } catch (Exception e) {
        //All failures here should just get swallowed, this is tertiary functionality
        e.printStackTrace();
        languages.setVisible(false);
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:22,代码来源:XFormValidatorGUI.java

示例10: FormInstanceValidator

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的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

示例11: initFormDef

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
private void initFormDef(String formName, Vector<QuestionExtensionParser> extensionParsers) {
    InputStream is = this.getClass().getResourceAsStream(formName);

    if (is == null) {
        String errorMessage = "Error: the file '" + formName + "' could not be found!";
        System.err.println(errorMessage);
        throw new RuntimeException(errorMessage);
    }
    if (extensionParsers != null) {
        xform = XFormUtils.getFormFromInputStream(is, extensionParsers);
    } else {
        xform = XFormUtils.getFormFromInputStream(is);
    }

    if (xform == null) {
        System.out.println("\n\n==================================\nERROR: XForm has failed validation!!");
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:19,代码来源:FormParseInit.java

示例12: isXFormValid

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的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;
}
 
开发者ID:benetech,项目名称:Secure-App-Generator,代码行数:15,代码来源:ObtainXFormController.java

示例13: validateUserAnswersOneAtATime

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的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

示例14: loadFormDef

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
/**
 * Helper function to load the form definition from a filepath.
 *
 * @param args is an String array, where the second entry, if present will
 *             be treated as a filename.
 * @return FormDef loaded from filepath present in the argument array
 */
private static FormDef loadFormDef(String[] args) {
    // Redirect output to syserr because sysout is being used for the
    // response, and must be kept clean.
    PrintStream responseStream = System.out;
    System.setOut(System.err);

    InputStream inputStream = System.in;

    // open form file
    if (args.length > 1) {
        String formPath = args[1];

        try {
            inputStream = new FileInputStream(formPath);
        } catch (FileNotFoundException e) {
            System.out.println("Couldn't find file at: " + formPath);
            System.exit(1);
        }
    }

    FormDef form = XFormUtils.getFormFromInputStream(inputStream);

    // reset the system output on exit.
    System.setOut(responseStream);

    return form;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:35,代码来源:Harness.java

示例15: loadInstance

import org.javarosa.xform.util.XFormUtils; //导入方法依赖的package包/类
/**
 * Build a form definition and load a particular form instance into it.
 * The FormDef object returned isn't initialized, and hence will not have
 * 'instance(...)' data set.
 *
 * @param formInput     XML stream of the form definition
 * @param instanceInput XML stream of an instance of the form
 * @return The form definition with the given instance loaded. Returns null
 * if the instance doesn't match the form provided.
 * @throws IOException thrown when XML input streams aren't successfully
 *                     parsed
 */
public static FormDef loadInstance(InputStream formInput,
                                   InputStream instanceInput)
        throws IOException {
    FormDef formDef;
    FormInstance savedModel;

    try {
        formDef = XFormUtils.getFormFromInputStream(formInput);
    } catch (XFormParseException e) {
        throw new IOException(e.getMessage());
    }

    savedModel = XFormParser.restoreDataModel(instanceInput, null);

    // get the root of the saved and template instances
    TreeElement savedRoot = savedModel.getRoot();
    TreeElement templateRoot =
            formDef.getInstance().getRoot().deepCopy(true);

    // weak check for matching forms
    if (!savedRoot.getName().equals(templateRoot.getName()) ||
            savedRoot.getMult() != 0) {
        System.out.println("Instance and template form definition don't match");
        return null;
    } else {
        // populate the data model
        TreeReference tr = TreeReference.rootRef();
        tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);
        templateRoot.populate(savedRoot);

        // populated model to current form
        formDef.getInstance().setRoot(templateRoot);
    }

    return formDef;
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:49,代码来源:FormInstanceLoader.java


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