当前位置: 首页>>代码示例>>Java>>正文


Java KXmlSerializer类代码示例

本文整理汇总了Java中org.kxml2.io.KXmlSerializer的典型用法代码示例。如果您正苦于以下问题:Java KXmlSerializer类的具体用法?Java KXmlSerializer怎么用?Java KXmlSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KXmlSerializer类属于org.kxml2.io包,在下文中一共展示了KXmlSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: print

import org.kxml2.io.KXmlSerializer; //导入依赖的package包/类
private void print(KXmlSerializer serializer, String timestamp) throws IOException {
    serializer.startTag(ns, XmlReportConstants.TESTSUITE);
    serializer.attribute(ns, XmlReportConstants.ATTR_NAME, name);
    serializer.attribute(ns, XmlReportConstants.ATTR_TESTS, Integer.toString(outcomes.size()));
    serializer.attribute(ns, XmlReportConstants.ATTR_FAILURES, Integer.toString(failuresCount));
    serializer.attribute(ns, XmlReportConstants.ATTR_ERRORS, Integer.toString(errorsCount));
    serializer.attribute(ns, XmlReportConstants.ATTR_TIME, "0");
    serializer.attribute(ns, XmlReportConstants.TIMESTAMP, timestamp);
    serializer.attribute(ns, XmlReportConstants.HOSTNAME, "localhost");
    serializer.startTag(ns, XmlReportConstants.PROPERTIES);
    serializer.endTag(ns, XmlReportConstants.PROPERTIES);

    for (Outcome outcome : outcomes) {
        print(serializer, outcome);
    }

    serializer.endTag(ns, XmlReportConstants.TESTSUITE);
}
 
开发者ID:dryganets,项目名称:vogar,代码行数:19,代码来源:XmlReportPrinter.java

示例2: print

import org.kxml2.io.KXmlSerializer; //导入依赖的package包/类
void print(KXmlSerializer serializer, TestIdentifier testId, TestResult testResult)
        throws IOException {

    serializer.startTag(ns, TESTCASE);
    serializer.attribute(ns, ATTR_NAME, getTestName(testId));
    serializer.attribute(ns, ATTR_CLASSNAME, testId.getClassName());
    long elapsedTimeMs = testResult.getEndTime() - testResult.getStartTime();
    serializer.attribute(ns, ATTR_TIME, Double.toString((double)elapsedTimeMs / 1000.f));

    switch (testResult.getStatus()) {
        case FAILURE:
            printFailedTest(serializer, FAILURE, testResult.getStackTrace());
            break;
        case ASSUMPTION_FAILURE:
            printFailedTest(serializer, SKIPPED_TAG, testResult.getStackTrace());
            break;
        case IGNORED:
            serializer.startTag(ns, SKIPPED_TAG);
            serializer.endTag(ns, SKIPPED_TAG);
            break;
    }

    serializer.endTag(ns, TESTCASE);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:XmlTestRunListener.java

示例3: 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();
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:27,代码来源:XFormsManifestXmlTable.java

示例4: 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();
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:26,代码来源:XFormsXmlTable.java

示例5: 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;

}
 
开发者ID:medic,项目名称:javarosa,代码行数:23,代码来源:XFormSerializer.java

示例6: printFailure

import org.kxml2.io.KXmlSerializer; //导入依赖的package包/类
void printFailure(KXmlSerializer serializer, String type, Throwable t)
        throws IOException {
    serializer.startTag(ns, TESTCASE);
    printAttributes(serializer);

    serializer.startTag(ns, type);
    String message = t.getMessage();
    if (message != null && message.length() > 0) {
        serializer.attribute(ns, ATTR_MESSAGE, t.getMessage());
    }
    serializer.attribute(ns, ATTR_TYPE, t.getClass().getName());
    serializer.text(sanitize(BaseTestRunner.getFilteredTrace(t)));
    serializer.endTag(ns, type);

    serializer.endTag(ns, TESTCASE);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:XmlReportPrinter.java

示例7: 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;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:22,代码来源:XFormSerializer.java

示例8: 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);
    }
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:19,代码来源:XPathExpression.java

示例9: 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) {
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:XmlTestRunListener.java

示例10: printTestResults

import org.kxml2.io.KXmlSerializer; //导入依赖的package包/类
void printTestResults(KXmlSerializer serializer, String timestamp, long elapsedTime)
        throws IOException {
    serializer.startTag(ns, TESTSUITE);
    String name = getTestSuiteName();
    if (name != null) {
        serializer.attribute(ns, ATTR_NAME, name);
    }
    serializer.attribute(ns, ATTR_TESTS, Integer.toString(mRunResult.getNumTests()));
    serializer.attribute(ns, ATTR_FAILURES, Integer.toString(
            mRunResult.getNumAllFailedTests()));
    // legacy - there are no errors in JUnit4
    serializer.attribute(ns, ATTR_ERRORS, "0");
    serializer.attribute(ns, ATTR_SKIPPED, Integer.toString(mRunResult.getNumTestsInState(
            TestStatus.IGNORED)));

    serializer.attribute(ns, ATTR_TIME, Double.toString((double) elapsedTime / 1000.f));
    serializer.attribute(ns, TIMESTAMP, timestamp);
    serializer.attribute(ns, HOSTNAME, mHostName);

    serializer.startTag(ns, PROPERTIES);
    for (Map.Entry<String,String> entry: getPropertiesAttributes().entrySet()) {
        serializer.startTag(ns, PROPERTY);
        serializer.attribute(ns, "name", entry.getKey());
        serializer.attribute(ns, "value", entry.getValue());
        serializer.endTag(ns, PROPERTY);
    }
    serializer.endTag(ns, PROPERTIES);

    Map<TestIdentifier, TestResult> testResults = mRunResult.getTestResults();
    for (Map.Entry<TestIdentifier, TestResult> testEntry : testResults.entrySet()) {
        print(serializer, testEntry.getKey(), testEntry.getValue());
    }

    serializer.endTag(ns, TESTSUITE);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:XmlTestRunListener.java

示例11: printFailedTest

import org.kxml2.io.KXmlSerializer; //导入依赖的package包/类
private void printFailedTest(KXmlSerializer serializer, String tag, String stack)
        throws IOException {
    serializer.startTag(ns, tag);
    // TODO: get message of stack trace ?
    // String msg = testResult.getStackTrace();
    // if (msg != null && msg.length() > 0) {
    //     serializer.attribute(ns, ATTR_MESSAGE, msg);
    // }
    // TODO: get class name of stackTrace exception
    // serializer.attribute(ns, ATTR_TYPE, testId.getClassName());
    serializer.text(sanitize(stack));
    serializer.endTag(ns, tag);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:XmlTestRunListener.java

示例12: 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();
  }
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:38,代码来源:FragmentedCsvFormatter.java

示例13: 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;
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:15,代码来源:XFormSerializer.java

示例14: 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;
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:15,代码来源:XFormSerializer.java

示例15: 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();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:38,代码来源:XmlReportPrinter.java


注:本文中的org.kxml2.io.KXmlSerializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。