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


Java DOMElementWriter类代码示例

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


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

示例1: xmlSaveProperties

import org.apache.tools.ant.util.DOMElementWriter; //导入依赖的package包/类
/**
 * Output the properties as xml output.
 * @param props the properties to save
 * @param os    the output stream to write to (Note this gets closed)
 * @throws IOException on error in writing to the stream
 */
protected void xmlSaveProperties(Properties props,
                                 OutputStream os) throws IOException {
    // create XML document
    Document doc = getDocumentBuilder().newDocument();
    Element rootElement = doc.createElement(PROPERTIES);

    List<Tuple> sorted = sortProperties(props);

    // output properties
    for (Tuple tuple : sorted) {
        Element propElement = doc.createElement(PROPERTY);
        propElement.setAttribute(ATTR_NAME, tuple.key);
        propElement.setAttribute(ATTR_VALUE, tuple.value);
        rootElement.appendChild(propElement);
    }

    try (Writer wri = new OutputStreamWriter(os, "UTF8")) {
        wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        new DOMElementWriter().write(rootElement, wri, 0, "\t");
        wri.flush();
    } catch (IOException ioe) {
        throw new BuildException("Unable to write XML file", ioe);
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:31,代码来源:EchoProperties.java

示例2: endTestSuite

import org.apache.tools.ant.util.DOMElementWriter; //导入依赖的package包/类
/**
 * The whole testsuite ended.
 * @param suite the testsuite.
 * @throws BuildException on error.
 */
public void endTestSuite(final JUnitTest suite) throws BuildException {
    rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount());
    rootElement.setAttribute(ATTR_FAILURES, "" + suite.failureCount());
    rootElement.setAttribute(ATTR_ERRORS, "" + suite.errorCount());
    rootElement.setAttribute(ATTR_SKIPPED, "" + suite.skipCount());
    rootElement.setAttribute(
        ATTR_TIME, "" + (suite.getRunTime() / ONE_SECOND));
    if (out != null) {
        Writer wri = null;
        try {
            wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8"));
            wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
            (new DOMElementWriter()).write(rootElement, wri, 0, "  ");
        } catch (final IOException exc) {
            throw new BuildException("Unable to write log file", exc);
        } finally {
            if (wri != null) {
                try {
                    wri.flush();
                } catch (final IOException ex) {
                    // ignore
                }
            }
            if (out != System.out && out != System.err) {
                FileUtils.close(wri);
            }
        }
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:35,代码来源:CassandraXMLJUnitResultFormatter.java

示例3: writeDOMTree

import org.apache.tools.ant.util.DOMElementWriter; //导入依赖的package包/类
/**
 * Write the DOM tree to a file.
 * @param doc the XML document to dump to disk.
 * @param file the filename to write the document to. Should obviously be a .xml file.
 * @throws IOException thrown if there is an error while writing the content.
 */
protected void writeDOMTree(Document doc, File file) throws IOException {
    try (OutputStream os = Files.newOutputStream(file.toPath());
         PrintWriter wri = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(os), "UTF8"))) {
        wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
        new DOMElementWriter().write(doc.getDocumentElement(), wri, 0,
            "  ");
        wri.flush();
        // writers do not throw exceptions, so check for them.
        if (wri.checkError()) {
            throw new IOException("Error while writing DOM content");
        }
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:20,代码来源:XMLResultAggregator.java

示例4: endTestSuite

import org.apache.tools.ant.util.DOMElementWriter; //导入依赖的package包/类
/**
 * The whole testsuite ended.
 * @param suite the testsuite.
 * @throws BuildException on error.
 */
@Override
public void endTestSuite(final JUnitTest suite) throws BuildException {
    rootElement.setAttribute(ATTR_TESTS, Long.toString(suite.runCount()));
    rootElement.setAttribute(ATTR_FAILURES, Long.toString(suite.failureCount()));
    rootElement.setAttribute(ATTR_ERRORS, Long.toString(suite.errorCount()));
    rootElement.setAttribute(ATTR_SKIPPED, Long.toString(suite.skipCount()));
    rootElement.setAttribute(
        ATTR_TIME, Double.toString(suite.getRunTime() / ONE_SECOND));
    if (out != null) {
        Writer wri = null;
        try {
            wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8"));
            wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
            new DOMElementWriter().write(rootElement, wri, 0, "  ");
        } catch (final IOException exc) {
            throw new BuildException("Unable to write log file", exc);
        } finally {
            if (wri != null) {
                try {
                    wri.flush();
                } catch (final IOException ex) {
                    // ignore
                }
            }
            if (out != System.out && out != System.err) {
                FileUtils.close(wri);
            }
        }
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:36,代码来源:XMLJUnitResultFormatter.java

示例5: getPolicy

import org.apache.tools.ant.util.DOMElementWriter; //导入依赖的package包/类
public DOMElementWriter.XmlNamespacePolicy getPolicy() {
    String s = getValue();
    if (IGNORE.equalsIgnoreCase(s)) {
        return DOMElementWriter.XmlNamespacePolicy.IGNORE;
    }
    if (ELEMENTS.equalsIgnoreCase(s)) {
        return
            DOMElementWriter.XmlNamespacePolicy.ONLY_QUALIFY_ELEMENTS;
    }
    if (ALL.equalsIgnoreCase(s)) {
        return DOMElementWriter.XmlNamespacePolicy.QUALIFY_ALL;
    }
    throw new BuildException("Invalid namespace policy: " + s);
}
 
开发者ID:apache,项目名称:ant,代码行数:15,代码来源:EchoXML.java

示例6: buildFinished

import org.apache.tools.ant.util.DOMElementWriter; //导入依赖的package包/类
/**
 * Fired when the build finishes, this adds the time taken and any
 * error stacktrace to the build element and writes the document to disk.
 *
 * @param event An event with any relevant extra information.
 *              Will not be <code>null</code>.
 */
@Override
public void buildFinished(BuildEvent event) {
    long totalTime = System.currentTimeMillis() - buildElement.startTime;
    buildElement.element.setAttribute(TIME_ATTR, DefaultLogger.formatTime(totalTime));

    if (event.getException() != null) {
        buildElement.element.setAttribute(ERROR_ATTR, event.getException().toString());
        // print the stacktrace in the build file it is always useful...
        // better have too much info than not enough.
        Throwable t = event.getException();
        Text errText = doc.createCDATASection(StringUtils.getStackTrace(t));
        Element stacktrace = doc.createElement(STACKTRACE_TAG);
        stacktrace.appendChild(errText);
        synchronizedAppend(buildElement.element, stacktrace);
    }
    String outFilename = getProperty(event, "XmlLogger.file", "log.xml");
    String xslUri = getProperty(event, "ant.XmlLogger.stylesheet.uri", "log.xsl");

    try (OutputStream stream =
        outStream == null ? Files.newOutputStream(Paths.get(outFilename)) : outStream;
            Writer out = new OutputStreamWriter(stream, "UTF8")) {
        out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        if (xslUri.length() > 0) {
            out.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslUri
                + "\"?>\n\n");
        }
        new DOMElementWriter().write(buildElement.element, out, 0, "\t");
        out.flush();
    } catch (IOException exc) {
        throw new BuildException("Unable to write log file", exc);
    }
    buildElement = null;
}
 
开发者ID:apache,项目名称:ant,代码行数:41,代码来源:XmlLogger.java

示例7: writeLog

import org.apache.tools.ant.util.DOMElementWriter; //导入依赖的package包/类
/**
 * Write the log file to disk.
 *
 * @param   event       Build event
 */
private void writeLog(BuildEvent event) {
    long totalTime = System.currentTimeMillis() - buildElement.startTime;
    buildElement.element.setAttribute(TIME_ATTR,
            DateUtils.formatElapsedTime(totalTime));

    if (event.getException() != null) {
        buildElement.element.setAttribute(ERROR_ATTR,
                event.getException().toString());
        // print the stacktrace in the build file it is always useful...
        // better have too much info than not enough.
        Throwable t = event.getException();
        Text errText = doc.createCDATASection(StringUtils.getStackTrace(t));
        Element stacktrace = doc.createElement(STACKTRACE_TAG);
        stacktrace.appendChild(errText);
        buildElement.element.appendChild(stacktrace);
    }

    String outFilename = event.getProject().getProperty("XmlLogger.file");
    if (outFilename == null) {
        outFilename = "log.xml";
    }
    String xslUri
            = event.getProject().getProperty("ant.XmlLogger.stylesheet.uri");
    if (xslUri == null) {
        xslUri = "log.xsl";
    }
    Writer out = null;
    try {
        // specify output in UTF8 otherwise accented characters will blow
        // up everything
        OutputStream stream = outStream;
        if (stream == null) {
            stream = new FileOutputStream(outFilename);
        }
        out = new OutputStreamWriter(stream, "UTF8");
        out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
        if (xslUri.length() > 0) {
            out.write("<?xml-stylesheet type=\"text/xsl\" href=\""
                    + xslUri + "\"?>\n\n");
        }

        (new DOMElementWriter()).write(buildElement.element, out, 0, "\t");
        out.flush();
    } catch (IOException exc) {
        throw new BuildException("Unable to write log file", exc);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                throw new BuildException("Unable to close log file", e);
            }
        }
    }
}
 
开发者ID:ModelN,项目名称:build-management,代码行数:61,代码来源:FrequentXmlLogger.java


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