Search in sources :

Example 1 with XFormAnswerDataSerializer

use of org.javarosa.xform.util.XFormAnswerDataSerializer 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 2 with XFormAnswerDataSerializer

use of org.javarosa.xform.util.XFormAnswerDataSerializer in project javarosa by opendatakit.

the class XFormSerializingVisitor method serializeInstance.

/*
         * (non-Javadoc)
         * @see org.javarosa.core.model.utils.IInstanceSerializingVisitor#serializeDataModel(org.javarosa.core.model.IFormDataModel)
         */
public byte[] serializeInstance(FormInstance model, IDataReference ref) throws IOException {
    init();
    rootRef = FormInstance.unpackReference(ref);
    if (this.serializer == null) {
        this.setAnswerDataSerializer(new XFormAnswerDataSerializer());
    }
    model.accept(this);
    if (theXmlDoc != null) {
        return XFormSerializer.getUtfBytes(theXmlDoc);
    } else {
        return null;
    }
}
Also used : XFormAnswerDataSerializer(org.javarosa.xform.util.XFormAnswerDataSerializer)

Example 3 with XFormAnswerDataSerializer

use of org.javarosa.xform.util.XFormAnswerDataSerializer in project javarosa by opendatakit.

the class XFormSerializingVisitor method createSerializedPayload.

public IDataPayload createSerializedPayload(FormInstance model, IDataReference ref) throws IOException {
    init();
    rootRef = FormInstance.unpackReference(ref);
    if (this.serializer == null) {
        this.setAnswerDataSerializer(new XFormAnswerDataSerializer());
    }
    model.accept(this);
    if (theXmlDoc != null) {
        // TODO: Did this strip necessary data?
        byte[] form = XFormSerializer.getUtfBytes(theXmlDoc);
        if (dataPointers.size() == 0) {
            return new ByteArrayPayload(form, null, IDataPayload.PAYLOAD_TYPE_XML);
        }
        MultiMessagePayload payload = new MultiMessagePayload();
        payload.addPayload(new ByteArrayPayload(form, "xml_submission_file", IDataPayload.PAYLOAD_TYPE_XML));
        for (IDataPointer pointer : dataPointers) {
            payload.addPayload(new DataPointerPayload(pointer));
        }
        return payload;
    } else {
        return null;
    }
}
Also used : XFormAnswerDataSerializer(org.javarosa.xform.util.XFormAnswerDataSerializer) DataPointerPayload(org.javarosa.core.services.transport.payload.DataPointerPayload) ByteArrayPayload(org.javarosa.core.services.transport.payload.ByteArrayPayload) MultiMessagePayload(org.javarosa.core.services.transport.payload.MultiMessagePayload) IDataPointer(org.javarosa.core.data.IDataPointer)

Example 4 with XFormAnswerDataSerializer

use of org.javarosa.xform.util.XFormAnswerDataSerializer in project javarosa by opendatakit.

the class XFormsModule method registerModule.

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));
        }
    };
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) IConditionExpr(org.javarosa.core.model.condition.IConditionExpr) IXFormyFactory(org.javarosa.core.model.util.restorable.IXFormyFactory) IOException(java.io.IOException) XFormAnswerDataSerializer(org.javarosa.xform.util.XFormAnswerDataSerializer) TreeReference(org.javarosa.core.model.instance.TreeReference) FormDef(org.javarosa.core.model.FormDef) FormInstance(org.javarosa.core.model.instance.FormInstance) XPathConditional(org.javarosa.xpath.XPathConditional) IDataPayload(org.javarosa.core.services.transport.payload.IDataPayload)

Example 5 with XFormAnswerDataSerializer

use of org.javarosa.xform.util.XFormAnswerDataSerializer in project javarosa by opendatakit.

the class SMSSerializingVisitor method createSerializedPayload.

public IDataPayload createSerializedPayload(FormInstance model, IDataReference ref) throws IOException {
    init();
    rootRef = FormInstance.unpackReference(ref);
    if (this.serializer == null) {
        this.setAnswerDataSerializer(new XFormAnswerDataSerializer());
    }
    model.accept(this);
    if (theSmsStr != null) {
        byte[] form = theSmsStr.getBytes("UTF-16");
        return new ByteArrayPayload(form, null, IDataPayload.PAYLOAD_TYPE_SMS);
    } else {
        return null;
    }
}
Also used : XFormAnswerDataSerializer(org.javarosa.xform.util.XFormAnswerDataSerializer) ByteArrayPayload(org.javarosa.core.services.transport.payload.ByteArrayPayload)

Aggregations

XFormAnswerDataSerializer (org.javarosa.xform.util.XFormAnswerDataSerializer)7 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 ByteArrayPayload (org.javarosa.core.services.transport.payload.ByteArrayPayload)2 IOException (java.io.IOException)1 IDataPointer (org.javarosa.core.data.IDataPointer)1 FormDef (org.javarosa.core.model.FormDef)1 IConditionExpr (org.javarosa.core.model.condition.IConditionExpr)1 DateData (org.javarosa.core.model.data.DateData)1 IntegerData (org.javarosa.core.model.data.IntegerData)1 StringData (org.javarosa.core.model.data.StringData)1 TimeData (org.javarosa.core.model.data.TimeData)1 FormInstance (org.javarosa.core.model.instance.FormInstance)1 TreeReference (org.javarosa.core.model.instance.TreeReference)1 IXFormyFactory (org.javarosa.core.model.util.restorable.IXFormyFactory)1 DataPointerPayload (org.javarosa.core.services.transport.payload.DataPointerPayload)1 IDataPayload (org.javarosa.core.services.transport.payload.IDataPayload)1 MultiMessagePayload (org.javarosa.core.services.transport.payload.MultiMessagePayload)1 XPathConditional (org.javarosa.xpath.XPathConditional)1