本文整理汇总了Java中org.kxml2.io.KXmlSerializer.flush方法的典型用法代码示例。如果您正苦于以下问题:Java KXmlSerializer.flush方法的具体用法?Java KXmlSerializer.flush怎么用?Java KXmlSerializer.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kxml2.io.KXmlSerializer
的用法示例。
在下文中一共展示了KXmlSerializer.flush方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateXmlManifestList
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public void generateXmlManifestList(PrintWriter output, CallingContext cc) throws IOException, ODKDatastoreException {
Document d = new Document();
d.setStandalone(true);
d.setEncoding(HtmlConsts.UTF8_ENCODE);
Element e = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.MANIFEST_TAG);
e.setPrefix(null, XML_TAG_NAMESPACE);
d.addChild(0, Node.ELEMENT, e);
int idx = 0;
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
// build XML table of form information
BinaryContentManipulator manifest = form.getManifestFileset();
if ( manifest != null ) {
int fileCount = manifest.getAttachmentCount(cc);
for ( int i = 1 ; i <= fileCount ; ++i ) {
idx = generateManifestXmlEntry(d, e, idx, form.getUri(), manifest, i, cc);
}
}
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(output);
// setting the response content type emits the xml header.
// just write the body here...
d.writeChildren(serializer);
serializer.flush();
}
示例2: generateXmlListOfForms
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public void generateXmlListOfForms(PrintWriter output, CallingContext cc) throws IOException, ODKDatastoreException {
Document d = new Document();
d.setStandalone(true);
d.setEncoding(HtmlConsts.UTF8_ENCODE);
Element e = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.XFORMS_TAG);
e.setPrefix(null, XML_TAG_NAMESPACE);
d.addChild(0, Node.ELEMENT, e);
int idx = 0;
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
// build XML table of form information
for (IForm form : forms) {
if (!form.hasValidFormDefinition() || !form.getDownloadEnabled())
continue;
idx = generateFormXmlEntry(d, e, idx, form, cc);
}
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(output);
// setting the response content type emits the xml header.
// just write the body here...
d.writeChildren(serializer);
serializer.flush();
}
示例3: elementToString
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public static String elementToString(Element e){
KXmlSerializer serializer = new KXmlSerializer();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
String s=null;
try {
serializer.setOutput(dos, null);
e.write(serializer);
serializer.flush();
s = new String(bos.toByteArray(),"UTF-8");
return s;
}catch (UnsupportedEncodingException uce){
uce.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
return null;
}
示例4: elementToString
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public static String elementToString(Element e) {
KXmlSerializer serializer = new KXmlSerializer();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
String s;
try {
serializer.setOutput(dos, null);
e.write(serializer);
serializer.flush();
s = new String(bos.toByteArray(), "UTF-8");
return s;
} catch (UnsupportedEncodingException uce) {
uce.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
return null;
}
示例5: emitXmlWrappedCsv
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
private void emitXmlWrappedCsv(List<Row> resultTable, List<String> headers) throws IOException {
Document d = new Document();
d.setStandalone(true);
d.setEncoding(HtmlConsts.UTF8_ENCODE);
Element e = d.createElement(XML_TAG_NAMESPACE, XML_TAG_ENTRIES);
d.addChild(0, Node.ELEMENT, e);
int idx = 0;
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
if (websafeCursorString != null) {
Element cursor = d.createElement(XML_TAG_NAMESPACE, XML_TAG_CURSOR);
e.addChild(idx++, Node.ELEMENT, cursor);
cursor.addChild(0, Node.TEXT, websafeCursorString);
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
}
Element header = d.createElement(XML_TAG_NAMESPACE, XML_TAG_HEADER);
e.addChild(idx++, Node.ELEMENT, header);
header.addChild(0, Node.TEXT, generateCommaSeperatedElements(headers));
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
Element resultRow;
// generate rows
for (Row row : resultTable) {
resultRow = d.createElement(XML_TAG_NAMESPACE, XML_TAG_RESULT);
e.addChild(idx++, Node.ELEMENT, resultRow);
String csvRow = generateCommaSeperatedElements(row.getFormattedValues());
resultRow.addChild(0, Node.TEXT, csvRow);
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
}
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(output);
// setting the response content type emits the xml header.
// just write the body here...
d.writeChildren(serializer);
serializer.flush();
}
示例6: getStream
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public static ByteArrayOutputStream getStream(Document doc) {
KXmlSerializer serializer = new KXmlSerializer();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
try {
serializer.setOutput(dos, null);
doc.write(serializer);
serializer.flush();
return bos;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例7: getUtfBytes
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public static byte[] getUtfBytes(Document doc) {
KXmlSerializer serializer = new KXmlSerializer();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
Writer osw = new OutputStreamWriter(bos, "UTF-8");
serializer.setOutput(osw);
doc.write(serializer);
serializer.flush();
return bos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例8: soap
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public Vector<?> soap(HttpServletRequest req) throws JSONException,
IOException {
JSONObject json = new JSONObject(IO.read(req));
// TODO: Route to SOAP ...
String action = req.getAttribute(Route.ACTION).toString();
if (action == null) {
throw new JSONException("Missing SOAP action.");
}
final Route route = router.route(action);
if (route == null) {
throw new JSONException("Not support action:" + action);
}
final SoapObject so = new SoapObject(route.getNameSpace(),
route.getAction());
Envelope envelope = createEnvelope(so, IO.toElement(json, route.getNameSpace(),
route.getAction()));
KXmlSerializer xmlWriter = new KXmlSerializer();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
xmlWriter.setOutput(outputStream, "UTF-8");
envelope.write(xmlWriter);
xmlWriter.flush();
Logger.getLogger(Soaper.class.getName()).info(outputStream.toString());
HttpTransportSE ht = getHttpTransportSE(route.getSoapUrl());
try {
ht.call(so.getName(), envelope);
Vector<?> ro = (Vector<?>) envelope.getResponse();
return ro;
} catch (HttpResponseException | XmlPullParserException | SoapFault e) {
throw new JSONException(e);
}
}
示例9: processSchema
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
private static void processSchema(FormDef form) {
Document schemaDoc = InstanceSchema.generateInstanceSchema(form);
KXmlSerializer serializer = new KXmlSerializer();
try {
serializer.setOutput(System.out, null);
schemaDoc.write(serializer);
serializer.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: writeSubmissionManifest
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
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) {
ex.printStackTrace();
String msg = "Error writing submission.xml for encrypted submission: "
+ submissionXml.getParentFile().getName();
Log.e(t, msg);
throw new EncryptionException(msg, ex);
} finally {
IOUtils.closeQuietly(writer);
IOUtils.closeQuietly(fout);
}
}