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();
}
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;
}
}
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;
}
}
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));
}
};
}
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;
}
}
Aggregations