Search in sources :

Example 1 with DOMDocument

use of org.dom4j.dom.DOMDocument in project gocd by gocd.

the class JobXmlViewModelTest method shouldMaskSecureVariables.

@Test
public void shouldMaskSecureVariables() throws IOException, DocumentException {
    EnvironmentVariableConfig envVariable = new EnvironmentVariableConfig(null, "stdVariable", "value1", false);
    EnvironmentVariableConfig secureEnvVariable = new EnvironmentVariableConfig(new GoCipher(), "secureVariable", "value2", true);
    EnvironmentVariablesConfig environmentVariablesConfig = new EnvironmentVariablesConfig();
    environmentVariablesConfig.add(envVariable);
    environmentVariablesConfig.add(secureEnvVariable);
    when(jobPlan.getVariables()).thenReturn(environmentVariablesConfig);
    DOMDocument document = (DOMDocument) jobXmlViewModel.toXml(xmlWriterContext);
    Assert.assertThat(document.asXML(), containsString("<environmentvariables><variable name=\"stdVariable\"><![CDATA[value1]]></variable><variable name=\"secureVariable\"><![CDATA[****]]></variable></environmentvariables>"));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) GoCipher(com.thoughtworks.go.security.GoCipher) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) DOMDocument(org.dom4j.dom.DOMDocument) Test(org.junit.Test)

Example 2 with DOMDocument

use of org.dom4j.dom.DOMDocument in project xwiki-platform by xwiki.

the class Package method toXML.

/**
 * Write the package.xml file to an OutputStream
 *
 * @param out the OutputStream to write to
 * @param context curent XWikiContext
 * @throws IOException when an error occurs during streaming operation
 * @since 2.3M2
 */
public void toXML(OutputStream out, XWikiContext context) throws IOException {
    XMLWriter wr = new XMLWriter(out, new OutputFormat("", true, context.getWiki().getEncoding()));
    Document doc = new DOMDocument();
    wr.writeDocumentStart(doc);
    toXML(wr);
    wr.writeDocumentEnd(doc);
}
Also used : OutputFormat(org.dom4j.io.OutputFormat) DOMDocument(org.dom4j.dom.DOMDocument) DOMDocument(org.dom4j.dom.DOMDocument) Document(org.dom4j.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XMLWriter(com.xpn.xwiki.internal.xml.XMLWriter)

Example 3 with DOMDocument

use of org.dom4j.dom.DOMDocument in project xwiki-platform by xwiki.

the class DOMXMLWriterTest method writeVersusWriteOpen.

/**
 * Before 3.0M2 there was a bug where write and writeOpen were reversed.
 *
 * @throws IOException
 * @see "XWIKI-5937"
 */
@Test
public void writeVersusWriteOpen() throws IOException {
    Document doc = new DOMDocument();
    DOMXMLWriter writer = new DOMXMLWriter(doc);
    DOMElement e = new DOMElement("a");
    writer.writeOpen(e);
    writer.write(new DOMElement("b"));
    writer.writeClose(e);
    writer.close();
    Assert.assertNotNull(doc.getRootElement().element("b"));
    doc = new DOMDocument();
    writer = new DOMXMLWriter(doc);
    e = new DOMElement("c");
    writer.write(e);
    writer.write(new DOMElement("d"));
    writer.close();
    Assert.assertNull(doc.getRootElement().element("d"));
}
Also used : DOMDocument(org.dom4j.dom.DOMDocument) Document(org.dom4j.Document) DOMDocument(org.dom4j.dom.DOMDocument) DOMElement(org.dom4j.dom.DOMElement) Test(org.junit.Test)

Example 4 with DOMDocument

use of org.dom4j.dom.DOMDocument in project narayana by jbosstm.

the class XMLResultsServlet method doStatus.

public void doStatus(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/xml");
    response.setHeader("Cache-Control", "no-cache");
    HttpSession session = request.getSession();
    final FullTestResult testResult = (FullTestResult) session.getAttribute(TestConstants.ATTRIBUTE_TEST_RESULT);
    DOMDocument report = new DOMDocument();
    DOMElement testsuite = new DOMElement("testsuite");
    report.setRootElement(testsuite);
    if (testResult == null) {
    // No JUnit test results generated.
    } else {
        List passedTests = testResult.getPassedTests();
        List failedTests = testResult.getFailedTests();
        List errorTests = testResult.getErrorTests();
        final int runCount = testResult.runCount();
        final int errorCount = testResult.errorCount();
        final int failureCount = testResult.failureCount();
        testsuite.addAttribute("name", "com.jboss.transaction.txinterop.interop.InteropTestSuite");
        testsuite.addAttribute("errors", Integer.toString(errorCount));
        testsuite.addAttribute("failures", Integer.toString(failureCount));
        testsuite.addAttribute("hostname", request.getServerName());
        testsuite.addAttribute("tests", Integer.toString(runCount));
        testsuite.addAttribute("timestamp", new Date().toString());
        DOMElement properties = new DOMElement("properties");
        testsuite.add(properties);
        DOMElement status = newPropertyDOMElement("status");
        properties.add(status);
        status.addAttribute("value", "finished");
        long totalDuration = 0;
        if (!passedTests.isEmpty()) {
            Iterator passedTestsIterator = passedTests.iterator();
            while (passedTestsIterator.hasNext()) {
                FullTestResult.PassedTest passedTest = (FullTestResult.PassedTest) passedTestsIterator.next();
                totalDuration += passedTest.duration;
                final String name = passedTest.test.toString();
                final String description = (String) TestConstants.DESCRIPTIONS.get(name);
                testsuite.add(newTestcase(passedTest.test.getClass().getName(), name + ": " + description, passedTest.duration));
            }
        }
        if (!failedTests.isEmpty()) {
            Iterator failedTestsIterator = failedTests.iterator();
            while (failedTestsIterator.hasNext()) {
                FullTestResult.FailedTest failedTest = (FullTestResult.FailedTest) failedTestsIterator.next();
                totalDuration += failedTest.duration;
                final String name = failedTest.test.toString();
                final String description = (String) TestConstants.DESCRIPTIONS.get(name);
                CharArrayWriter charArrayWriter = new CharArrayWriter();
                PrintWriter printWriter = new PrintWriter(charArrayWriter, true);
                failedTest.assertionFailedError.printStackTrace(printWriter);
                printWriter.close();
                charArrayWriter.close();
                testsuite.add(newFailedTestcase(failedTest.test.getClass().getName(), name + ": " + description, failedTest.duration, failedTest.assertionFailedError.getMessage(), charArrayWriter.toString()));
            }
        }
        if (!errorTests.isEmpty()) {
            Iterator errorTestsIterator = errorTests.iterator();
            while (errorTestsIterator.hasNext()) {
                FullTestResult.ErrorTest errorTest = (FullTestResult.ErrorTest) errorTestsIterator.next();
                totalDuration += errorTest.duration;
                final String name = errorTest.test.toString();
                final String description = (String) TestConstants.DESCRIPTIONS.get(name);
                CharArrayWriter charArrayWriter = new CharArrayWriter();
                PrintWriter printWriter = new PrintWriter(charArrayWriter, true);
                errorTest.throwable.printStackTrace(printWriter);
                printWriter.close();
                charArrayWriter.close();
                System.out.println("charArrayWriter.toString()=" + charArrayWriter.toString());
                testsuite.add(newErrorTestcase(errorTest.test.getClass().getName(), name + ": " + description, errorTest.duration, errorTest.throwable.getMessage(), charArrayWriter.toString()));
            }
        }
        // total time of all tests
        testsuite.addAttribute("time", Float.toString(totalDuration / 1000f));
    }
    String logContent = null;
    final String logName = (String) session.getAttribute(TestConstants.ATTRIBUTE_LOG_NAME);
    if (logName != null) {
        try {
            logContent = TestLogController.readLog(logName);
        } catch (final Throwable th) {
            log("Error reading log file", th);
        }
    }
    testsuite.add(new DOMElement("system-out").addCDATA((logContent != null) ? logContent : ""));
    testsuite.add(new DOMElement("system-err").addCDATA(""));
    XMLWriter outputter = new XMLWriter(response.getWriter(), OutputFormat.createPrettyPrint());
    try {
        outputter.write(testsuite);
        outputter.close();
    } catch (IOException e) {
        throw new ServletException(e);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) DOMDocument(org.dom4j.dom.DOMDocument) IOException(java.io.IOException) DOMElement(org.dom4j.dom.DOMElement) XMLWriter(org.dom4j.io.XMLWriter) Date(java.util.Date) CharArrayWriter(java.io.CharArrayWriter) ServletException(javax.servlet.ServletException) Iterator(java.util.Iterator) List(java.util.List) PrintWriter(java.io.PrintWriter)

Example 5 with DOMDocument

use of org.dom4j.dom.DOMDocument in project gocd by gocd.

the class StageXmlViewModel method toXml.

@Override
public Document toXml(XmlWriterContext writerContext) {
    DOMElement root = new DOMElement("stage");
    root.addAttribute("name", stage.getName()).addAttribute("counter", String.valueOf(stage.getCounter()));
    Document document = new DOMDocument(root);
    root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(writerContext.getBaseUrl()));
    StageIdentifier stageId = stage.getIdentifier();
    root.addElement("id").addCDATA(stageId.asURN());
    String pipelineName = stageId.getPipelineName();
    root.addElement("pipeline").addAttribute("name", pipelineName).addAttribute("counter", String.valueOf(stageId.getPipelineCounter())).addAttribute("label", stageId.getPipelineLabel()).addAttribute("href", writerContext.getBaseUrl() + "/api/pipelines/" + pipelineName + "/" + stage.getPipelineId() + ".xml");
    root.addElement("updated").addText(DateUtils.formatISO8601(stage.latestTransitionDate()));
    root.addElement("result").addText(stage.getResult().toString());
    root.addElement("state").addText(stage.status());
    root.addElement("approvedBy").addCDATA(stage.getApprovedBy());
    Element jobs = root.addElement("jobs");
    for (JobInstance jobInstance : stage.getJobInstances()) {
        jobs.addElement("job").addAttribute("href", writerContext.getBaseUrl() + "/api/jobs/" + jobInstance.getId() + ".xml");
    }
    return document;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) JobInstance(com.thoughtworks.go.domain.JobInstance) Element(org.dom4j.Element) DOMElement(org.dom4j.dom.DOMElement) DOMDocument(org.dom4j.dom.DOMDocument) DOMElement(org.dom4j.dom.DOMElement) Document(org.dom4j.Document) DOMDocument(org.dom4j.dom.DOMDocument)

Aggregations

DOMDocument (org.dom4j.dom.DOMDocument)13 Document (org.dom4j.Document)8 DOMElement (org.dom4j.dom.DOMElement)8 IOException (java.io.IOException)5 Element (org.dom4j.Element)3 CharArrayWriter (java.io.CharArrayWriter)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ServletException (javax.servlet.ServletException)2 HttpSession (javax.servlet.http.HttpSession)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 StreamResult (javax.xml.transform.stream.StreamResult)2 MethodInvocationException (org.apache.velocity.exception.MethodInvocationException)2 ParseErrorException (org.apache.velocity.exception.ParseErrorException)2 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)2 DocumentSource (org.dom4j.io.DocumentSource)2 OutputFormat (org.dom4j.io.OutputFormat)2