Search in sources :

Example 6 with StringData

use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.

the class QuestionDataGroupTests method setUp.

public void setUp() throws Exception {
    super.setUp();
    stringData = new StringData("Answer Value");
    integerData = new IntegerData(4);
    stringReference = new IDataReference() {

        String reference = "stringValue";

        public Object getReference() {
            return reference;
        }

        public void setReference(Object reference) {
            this.reference = (String) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.reference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(reference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    integerReference = new IDataReference() {

        Integer intReference = new Integer(15);

        public Object getReference() {
            return intReference;
        }

        public void setReference(Object reference) {
            this.intReference = (Integer) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.intReference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(intReference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    intElement = new TreeElement("intElement");
    intElement.setValue(integerData);
    stringElement = new TreeElement(stringElementName);
    stringElement.setValue(stringData);
    group = new TreeElement(groupName);
}
Also used : PrototypeFactory(org.javarosa.core.util.externalizable.PrototypeFactory) IDataReference(org.javarosa.core.model.IDataReference) DataOutputStream(java.io.DataOutputStream) IntegerData(org.javarosa.core.model.data.IntegerData) IOException(java.io.IOException) StringData(org.javarosa.core.model.data.StringData) DataInputStream(java.io.DataInputStream) DeserializationException(org.javarosa.core.util.externalizable.DeserializationException) TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement)

Example 7 with StringData

use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.

the class XFormAnswerDataSerializerTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    stringData = new StringData(stringDataValue);
    stringElement.setValue(stringData);
    integerData = new IntegerData(integerDataValue);
    intElement.setValue(integerData);
    dateData = new DateData(dateDataValue);
    dateElement.setValue(dateData);
    timeData = new TimeData(timeDataValue);
    timeElement.setValue(timeData);
    serializer = new XFormAnswerDataSerializer();
}
Also used : XFormAnswerDataSerializer(org.javarosa.xform.util.XFormAnswerDataSerializer) DateData(org.javarosa.core.model.data.DateData) TimeData(org.javarosa.core.model.data.TimeData) IntegerData(org.javarosa.core.model.data.IntegerData) StringData(org.javarosa.core.model.data.StringData)

Example 8 with StringData

use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.

the class XPathEvalTest method createCountNonEmptyTestInstance.

public FormInstance createCountNonEmptyTestInstance() {
    TreeElement data = new TreeElement("data");
    TreeElement path = new TreeElement("path", 0);
    path.addChild(new TreeElement("child", 0));
    path.addChild(new TreeElement("child", 1));
    data.addChild(path);
    data.addChild(new TreeElement("path", 1));
    path = new TreeElement("path", 2);
    path.setValue(new StringData("some value"));
    data.addChild(path);
    path = new TreeElement("path", 3);
    path.addChild(new TreeElement("child", 0));
    data.addChild(path);
    data.addChild(new TreeElement("path", 4));
    return new FormInstance(data);
}
Also used : StringData(org.javarosa.core.model.data.StringData) FormInstance(org.javarosa.core.model.instance.FormInstance) TreeElement(org.javarosa.core.model.instance.TreeElement)

Example 9 with StringData

use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.

the class XPathEvalTest method createTestDataForIndexedRepeatFunction.

private FormInstance createTestDataForIndexedRepeatFunction(Integer indexNodeValue) {
    TreeElement root = new TreeElement("data");
    TreeElement repeat = new TreeElement("repeat");
    TreeElement repeatChild = new TreeElement("name");
    repeatChild.setAnswer(new StringData("A"));
    repeat.addChild(repeatChild);
    root.addChild(repeat);
    repeat = new TreeElement("repeat");
    repeatChild = new TreeElement("name");
    repeatChild.setAnswer(new StringData("B"));
    repeat.addChild(repeatChild);
    root.addChild(repeat);
    repeat = new TreeElement("repeat");
    repeatChild = new TreeElement("name");
    repeatChild.setAnswer(new StringData("C"));
    repeat.addChild(repeatChild);
    root.addChild(repeat);
    TreeElement index = new TreeElement("index1");
    if (indexNodeValue != null) {
        index.setValue(new IntegerData(1));
    }
    return new FormInstance(root);
}
Also used : IntegerData(org.javarosa.core.model.data.IntegerData) StringData(org.javarosa.core.model.data.StringData) FormInstance(org.javarosa.core.model.instance.FormInstance) TreeElement(org.javarosa.core.model.instance.TreeElement)

Example 10 with StringData

use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.

the class XFormAnswerDataParser method getAnswerData.

public static IAnswerData getAnswerData(String text, int dataType, QuestionDef q) {
    String trimmedText = text.trim();
    if (trimmedText.length() == 0)
        trimmedText = null;
    switch(dataType) {
        case Constants.DATATYPE_NULL:
        case Constants.DATATYPE_UNSUPPORTED:
        case Constants.DATATYPE_TEXT:
        case Constants.DATATYPE_BARCODE:
        case Constants.DATATYPE_BINARY:
            return new StringData(text);
        case Constants.DATATYPE_INTEGER:
            try {
                return (trimmedText == null ? null : new IntegerData(Integer.parseInt(trimmedText)));
            } catch (NumberFormatException nfe) {
                return null;
            }
        case Constants.DATATYPE_LONG:
            try {
                return (trimmedText == null ? null : new LongData(Long.parseLong(trimmedText)));
            } catch (NumberFormatException nfe) {
                return null;
            }
        case Constants.DATATYPE_DECIMAL:
            try {
                return (trimmedText == null ? null : new DecimalData(Double.parseDouble(trimmedText)));
            } catch (NumberFormatException nfe) {
                return null;
            }
        case Constants.DATATYPE_CHOICE:
            Selection selection = getSelection(text, q);
            return (selection == null ? null : new SelectOneData(selection));
        case Constants.DATATYPE_CHOICE_LIST:
            return new SelectMultiData(getSelections(text, q));
        case Constants.DATATYPE_DATE_TIME:
            Date dt = (trimmedText == null ? null : DateUtils.parseDateTime(trimmedText));
            return (dt == null ? null : new DateTimeData(dt));
        case Constants.DATATYPE_DATE:
            Date d = (trimmedText == null ? null : DateUtils.parseDate(trimmedText));
            return (d == null ? null : new DateData(d));
        case Constants.DATATYPE_TIME:
            Date t = (trimmedText == null ? null : DateUtils.parseTime(trimmedText));
            return (t == null ? null : new TimeData(t));
        case Constants.DATATYPE_BOOLEAN:
            if (trimmedText == null) {
                return null;
            } else {
                if (trimmedText.equals("1")) {
                    return new BooleanData(true);
                }
                if (trimmedText.equals("0")) {
                    return new BooleanData(false);
                }
                return trimmedText.equals("t") ? new BooleanData(true) : new BooleanData(false);
            }
        case Constants.DATATYPE_GEOPOINT:
            if (trimmedText == null) {
                return new GeoPointData();
            }
            try {
                UncastData uncast = new UncastData(trimmedText);
                // silly...
                GeoPointData gp = new GeoPointData();
                return gp.cast(uncast);
            } catch (Exception e) {
                return null;
            }
        case Constants.DATATYPE_GEOSHAPE:
            if (trimmedText == null) {
                return new GeoShapeData();
            }
            try {
                UncastData uncast = new UncastData(trimmedText);
                // silly...
                GeoShapeData gs = new GeoShapeData();
                return gs.cast(uncast);
            } catch (Exception e) {
                return null;
            }
        case Constants.DATATYPE_GEOTRACE:
            if (trimmedText == null) {
                return new GeoTraceData();
            }
            try {
                UncastData uncast = new UncastData(trimmedText);
                // silly...
                GeoTraceData gl = new GeoTraceData();
                return gl.cast(uncast);
            } catch (Exception e) {
                return null;
            }
        default:
            return new UncastData(trimmedText);
    }
}
Also used : SelectOneData(org.javarosa.core.model.data.SelectOneData) Selection(org.javarosa.core.model.data.helper.Selection) IntegerData(org.javarosa.core.model.data.IntegerData) GeoPointData(org.javarosa.core.model.data.GeoPointData) LongData(org.javarosa.core.model.data.LongData) Date(java.util.Date) DecimalData(org.javarosa.core.model.data.DecimalData) BooleanData(org.javarosa.core.model.data.BooleanData) GeoTraceData(org.javarosa.core.model.data.GeoTraceData) SelectMultiData(org.javarosa.core.model.data.SelectMultiData) DateData(org.javarosa.core.model.data.DateData) GeoShapeData(org.javarosa.core.model.data.GeoShapeData) DateTimeData(org.javarosa.core.model.data.DateTimeData) TimeData(org.javarosa.core.model.data.TimeData) UncastData(org.javarosa.core.model.data.UncastData) DateTimeData(org.javarosa.core.model.data.DateTimeData) StringData(org.javarosa.core.model.data.StringData)

Aggregations

StringData (org.javarosa.core.model.data.StringData)19 IntegerData (org.javarosa.core.model.data.IntegerData)7 TreeElement (org.javarosa.core.model.instance.TreeElement)6 DateData (org.javarosa.core.model.data.DateData)4 TimeData (org.javarosa.core.model.data.TimeData)4 Date (java.util.Date)3 IDataReference (org.javarosa.core.model.IDataReference)3 DateTimeData (org.javarosa.core.model.data.DateTimeData)3 DecimalData (org.javarosa.core.model.data.DecimalData)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)3 LongData (org.javarosa.core.model.data.LongData)3 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)3 FormInstance (org.javarosa.core.model.instance.FormInstance)3 Test (org.junit.Test)3 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 RandomString (net.bytebuddy.utility.RandomString)2 FormDef (org.javarosa.core.model.FormDef)2 BooleanData (org.javarosa.core.model.data.BooleanData)2