use of org.kxml2.kdom.Element in project javarosa by opendatakit.
the class ChildProcessingTest method worksWithOneChild.
@Test
public void worksWithOneChild() {
Element el = new Element();
el.addChild(ELEMENT, el.createElement(null, "Child Name"));
assertTrue(XFormParser.childOptimizationsOk(el));
}
use of org.kxml2.kdom.Element in project ETSMobile-Android2 by ApplETS.
the class Helper method convertToSoapObject.
public static Object convertToSoapObject(Element element) {
if (element.getChildCount() == 0 || (element.getChildCount() == 1 && !(element.getChild(0) instanceof Element))) {
SoapPrimitive primitive = new SoapPrimitive(element.getNamespace(), element.getName(), element.getChildCount() == 1 ? element.getText(0) : null);
return primitive;
} else {
SoapObject obj = new SoapObject(element.getNamespace(), element.getName());
for (int i = 0; i < element.getChildCount(); i++) {
Element childElement = element.getElement(i);
Object childObject = convertToSoapObject(childElement);
if (childObject instanceof SoapObject) {
SoapObject soapObj = (SoapObject) childObject;
obj.addProperty(soapObj.getName(), childObject);
} else {
SoapPrimitive primitive = (SoapPrimitive) childObject;
obj.addProperty(primitive.getName(), primitive);
}
}
return obj;
}
}
use of org.kxml2.kdom.Element in project ETSMobile-Android2 by ApplETS.
the class ExtendedSoapSerializationEnvelope method GetSoapObject.
public SoapObject GetSoapObject(Element detailElement) {
try {
XmlSerializer xmlSerializer = XmlPullParserFactory.newInstance().newSerializer();
StringWriter writer = new StringWriter();
xmlSerializer.setOutput(writer);
detailElement.write(xmlSerializer);
xmlSerializer.flush();
XmlPullParser xpp = new KXmlParser();
xpp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
xpp.setInput(new StringReader(writer.toString()));
xpp.nextTag();
SoapObject soapObj = new SoapObject(detailElement.getNamespace(), detailElement.getName());
readSerializable(xpp, soapObj);
return soapObj;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
use of org.kxml2.kdom.Element in project collect by opendatakit.
the class EncryptionUtils method writeSubmissionManifest.
private static void writeSubmissionManifest(EncryptedFormInformation formInfo, File submissionXml, List<File> mediaFiles) throws EncryptionException {
Document d = new Document();
d.setStandalone(true);
d.setEncoding(UTF_8);
Element e = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, DATA);
e.setPrefix(null, XML_ENCRYPTED_TAG_NAMESPACE);
e.setAttribute(null, ID, formInfo.formId);
if (formInfo.formVersion != null) {
e.setAttribute(null, VERSION, formInfo.formVersion);
}
e.setAttribute(null, ENCRYPTED, "yes");
d.addChild(0, Node.ELEMENT, e);
int idx = 0;
Element c;
c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, BASE64_ENCRYPTED_KEY);
c.addChild(0, Node.TEXT, formInfo.base64RsaEncryptedSymmetricKey);
e.addChild(idx++, Node.ELEMENT, c);
c = d.createElement(XML_OPENROSA_NAMESPACE, META);
c.setPrefix("orx", XML_OPENROSA_NAMESPACE);
{
Element instanceTag = d.createElement(XML_OPENROSA_NAMESPACE, INSTANCE_ID);
instanceTag.addChild(0, Node.TEXT, formInfo.instanceMetadata.instanceId);
c.addChild(0, Node.ELEMENT, instanceTag);
}
e.addChild(idx++, Node.ELEMENT, c);
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, NEW_LINE);
if (mediaFiles != null) {
for (File file : mediaFiles) {
c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, MEDIA);
Element fileTag = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, FILE);
fileTag.addChild(0, Node.TEXT, file.getName() + ".enc");
c.addChild(0, Node.ELEMENT, fileTag);
e.addChild(idx++, Node.ELEMENT, c);
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, NEW_LINE);
}
}
c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, ENCRYPTED_XML_FILE);
c.addChild(0, Node.TEXT, submissionXml.getName() + ".enc");
e.addChild(idx++, Node.ELEMENT, c);
c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, BASE64_ENCRYPTED_ELEMENT_SIGNATURE);
c.addChild(0, Node.TEXT, formInfo.getBase64EncryptedElementSignature());
e.addChild(idx, Node.ELEMENT, c);
FileOutputStream fout = null;
OutputStreamWriter writer = null;
try {
fout = new FileOutputStream(submissionXml);
writer = new OutputStreamWriter(fout, UTF_8);
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(writer);
// setting the response content type emits the xml header.
// just write the body here...
d.writeChildren(serializer);
serializer.flush();
writer.flush();
fout.getChannel().force(true);
writer.close();
} catch (Exception ex) {
String msg = "Error writing submission.xml for encrypted submission: " + submissionXml.getParentFile().getName();
Timber.e(ex, "%s due to : %s ", msg, ex.getMessage());
throw new EncryptionException(msg, ex);
} finally {
IOUtils.closeQuietly(writer);
IOUtils.closeQuietly(fout);
}
}
Aggregations