Search in sources :

Example 11 with DOMDocument

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

the class JobPlanXmlViewModel method toXml.

@Override
public Document toXml(XmlWriterContext writerContext) {
    DOMElement root = new DOMElement("scheduledJobs");
    for (WaitingJobPlan jobPlan : jobPlans) {
        DOMElement jobElement = getXmlForJobPlan(writerContext, jobPlan);
        root.add(jobElement);
    }
    DOMDocument domDocument = new DOMDocument(root);
    return domDocument;
}
Also used : DOMDocument(org.dom4j.dom.DOMDocument) DOMElement(org.dom4j.dom.DOMElement)

Example 12 with DOMDocument

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

the class JobXmlViewModel method toXml.

@Override
public Document toXml(XmlWriterContext writerContext) {
    DOMElement root = new DOMElement("job");
    root.addAttribute("name", jobInstance.getName());
    Document document = new DOMDocument(root);
    root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(writerContext.getBaseUrl()));
    JobIdentifier identifier = jobInstance.getIdentifier();
    root.addElement("id").addCDATA(identifier.asURN());
    String pipelineName = identifier.getPipelineName();
    StageIdentifier stageId = identifier.getStageIdentifier();
    root.addElement("pipeline").addAttribute("name", pipelineName).addAttribute("counter", String.valueOf(stageId.getPipelineCounter())).addAttribute("label", stageId.getPipelineLabel());
    root.addElement("stage").addAttribute("name", stageId.getStageName()).addAttribute("counter", stageId.getStageCounter()).addAttribute("href", StageXmlViewModel.httpUrlFor(writerContext.getBaseUrl(), jobInstance.getStageId()));
    root.addElement("result").addText(jobInstance.getResult().toString());
    root.addElement("state").addText(jobInstance.getState().toString());
    Element properties = root.addElement("properties");
    root.addElement("agent").addAttribute("uuid", jobInstance.getAgentUuid());
    root.addComment("artifacts of type `file` will not be shown. See https://github.com/gocd/gocd/pull/2875");
    Element artifacts = root.addElement("artifacts");
    artifacts.addAttribute("baseUri", writerContext.artifactBaseUrl(identifier)).addAttribute("pathFromArtifactRoot", writerContext.artifactRootPath(identifier));
    JobPlan jobPlan = writerContext.planFor(identifier);
    for (ArtifactPlan artifactPlan : jobPlan.getArtifactPlansOfType(ArtifactPlanType.unit)) {
        artifacts.addElement("artifact").addAttribute("src", artifactPlan.getSrc()).addAttribute("dest", artifactPlan.getDest()).addAttribute("type", artifactPlan.getArtifactPlanType().toString());
    }
    // Retain the top level elements for backward-compatibility
    root.addComment("resources are now intentionally left blank. See https://github.com/gocd/gocd/pull/2875");
    root.addElement("resources");
    root.addComment("environmentvariables are now intentionally left blank. See https://github.com/gocd/gocd/pull/2875");
    root.addElement("environmentvariables");
    return document;
}
Also used : 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)

Example 13 with DOMDocument

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

the class PipelineXmlViewModel method toXml.

@Override
public Document toXml(XmlWriterContext writerContext) {
    DOMElement root = new DOMElement("pipeline");
    root.addAttribute("name", pipeline.getName()).addAttribute("counter", String.valueOf(pipeline.getCounter())).addAttribute("label", pipeline.getLabel());
    Document document = new DOMDocument(root);
    String baseUrl = writerContext.getBaseUrl();
    root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(baseUrl));
    root.addElement("id").addCDATA(pipeline.getPipelineIdentifier().asURN());
    PipelineTimelineEntry pipelineAfter = pipeline.getPipelineAfter();
    if (pipelineAfter != null) {
        addTimelineLink(root, baseUrl, "insertedBefore", pipelineAfter);
    }
    PipelineTimelineEntry pipelineBefore = pipeline.getPipelineBefore();
    if (pipelineBefore != null) {
        addTimelineLink(root, baseUrl, "insertedAfter", pipelineBefore);
    }
    root.addElement("scheduleTime").addText(DateUtils.formatISO8601(pipeline.getScheduledDate()));
    Element materials = root.addElement("materials");
    for (MaterialRevision materialRevision : pipeline.getCurrentRevisions()) {
        populateXml(materials, materialRevision, writerContext);
    }
    Element stages = root.addElement("stages");
    for (StageInstanceModel stage : pipeline.getStageHistory()) {
        if (!(stage instanceof NullStageHistoryItem)) {
            stages.addElement("stage").addAttribute("href", StageXmlViewModel.httpUrlFor(writerContext.getBaseUrl(), stage.getId()));
        }
    }
    root.addElement("approvedBy").addCDATA(pipeline.getApprovedBy());
    return document;
}
Also used : NullStageHistoryItem(com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem) 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) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry)

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