本文整理汇总了Java中org.kxml2.io.KXmlSerializer.setOutput方法的典型用法代码示例。如果您正苦于以下问题:Java KXmlSerializer.setOutput方法的具体用法?Java KXmlSerializer.setOutput怎么用?Java KXmlSerializer.setOutput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kxml2.io.KXmlSerializer
的用法示例。
在下文中一共展示了KXmlSerializer.setOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: serializeElements
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
private static void serializeElements(XPathNodeset nodeset, OutputStream output) throws IOException {
KXmlSerializer serializer = new KXmlSerializer();
try {
serializer.setOutput(output, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
DataModelSerializer s = new DataModelSerializer(serializer);
DataInstance instance = nodeset.getInstance();
Vector<TreeReference> refs = nodeset.getReferences();
for (TreeReference ref : refs) {
AbstractTreeElement treeElement = instance.resolveReference(ref);
s.serialize(treeElement);
}
}
示例6: generateDocument
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
/**
* Creates a report file and populates it with the report data from the completed tests.
*/
private void generateDocument(File reportDir, long elapsedTime) {
String timestamp = getTimestamp();
OutputStream stream = null;
try {
stream = createOutputResultStream(reportDir);
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(stream, SdkConstants.UTF_8);
serializer.startDocument(SdkConstants.UTF_8, null);
serializer.setFeature(
"http://xmlpull.org/v1/doc/features.html#indent-output", true);
// TODO: insert build info
printTestResults(serializer, timestamp, elapsedTime);
serializer.endDocument();
String msg = String.format("XML test result file generated at %s. %s" ,
getAbsoluteReportPath(), mRunResult.getTextSummary());
Log.logAndDisplay(LogLevel.INFO, LOG_TAG, msg);
} catch (IOException e) {
Log.e(LOG_TAG, "Failed to generate report data");
// TODO: consider throwing exception
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException ignored) {
}
}
}
}
示例7: 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();
}
示例8: 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;
}
}
示例9: 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;
}
}
示例10: generateReports
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public int generateReports(String directory) {
File parent = new File(directory);
parent.mkdirs();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
TimeZone gmt = TimeZone.getTimeZone("GMT");
dateFormat.setTimeZone(gmt);
dateFormat.setLenient(true);
String timestamp = dateFormat.format(new Date());
for (Suite suite : suites.values()) {
FileOutputStream stream = null;
try {
stream = new FileOutputStream(new File(parent, "TEST-" + suite.name + ".xml"));
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(stream, "UTF-8");
serializer.startDocument("UTF-8", null);
serializer.setFeature(
"http://xmlpull.org/v1/doc/features.html#indent-output", true);
suite.print(serializer, timestamp);
serializer.endDocument();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException ignored) {
ignored.printStackTrace();
}
}
}
}
return suites.size();
}
示例11: 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);
}
}
示例12: 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();
}
}
示例13: DeviceReportWriter
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public DeviceReportWriter(OutputStream outputStream) throws IOException {
os = outputStream;
serializer = new KXmlSerializer();
serializer.setOutput(os, "UTF-8");
serializer.setPrefix("", XMLNS);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
}
示例14: printSubtree
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public static void printSubtree(Element root, OutputStream out) {
try {
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(out, "UTF-8");
root.getOwnerDocument().write(serializer, root, null);
} catch (IOException ex) {
System.err.println("IOException when serializing: " + ex);
}
}
示例15: printSubtree
import org.kxml2.io.KXmlSerializer; //导入方法依赖的package包/类
public void printSubtree() {
try {
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(System.out, "UTF-8");
getOwnerDocument().write(serializer, this, null);
} catch (IOException ex) {
//#debug warn
System.out.println("Could not print subtree: " + ex);
}
}