當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。