List of usage examples for org.dom4j.dom DOMElement addElement
public Element addElement(String name)
From source file:com.thoughtworks.go.server.domain.xml.JobPlanXmlViewModel.java
License:Apache License
private DOMElement getXmlForJobPlan(XmlWriterContext writerContext, WaitingJobPlan waitingJobPlan) { JobPlan jobPlan = waitingJobPlan.jobPlan(); DOMElement root = new DOMElement("job"); root.addAttribute("name", jobPlan.getName()).addAttribute("id", String.valueOf(jobPlan.getJobId())); root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrlFor(writerContext.getBaseUrl(), jobPlan.getIdentifier())); root.addElement("buildLocator").addText(jobPlan.getIdentifier().buildLocator()); if (!StringUtils.isBlank(waitingJobPlan.envName())) { root.addElement("environment").addText(waitingJobPlan.envName()); }/* w w w .ja v a 2 s .c o m*/ if (!jobPlan.getResources().isEmpty()) { DOMElement resources = new DOMElement("resources"); for (Resource resource : jobPlan.getResources()) { resources.addElement("resource").addCDATA(resource.getName()); } root.add(resources); } if (!jobPlan.getVariables().isEmpty()) { DOMElement envVars = new DOMElement("environmentVariables"); for (EnvironmentVariable environmentVariable : jobPlan.getVariables()) { envVars.addElement("variable").addAttribute("name", environmentVariable.getName()) .addText(environmentVariable.getDisplayValue()); } root.add(envVars); } return root; }
From source file:com.thoughtworks.go.server.domain.xml.JobXmlViewModel.java
License:Apache License
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"); for (Property property : writerContext.propertiesForJob(jobInstance.getId())) { properties.addElement("property").addAttribute("name", property.getKey()).addCDATA(property.getValue()); }//www .j a v a 2 s . c o m 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; }
From source file:com.thoughtworks.go.server.domain.xml.PipelineXmlViewModel.java
License:Apache License
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); }/*w w w . j a v a 2s . co m*/ 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; }
From source file:com.thoughtworks.go.server.domain.xml.PipelineXmlViewModel.java
License:Apache License
private void addTimelineLink(DOMElement root, String baseUrl, final String rel, final PipelineTimelineEntry entry) { root.addElement("link").addAttribute("rel", rel).addAttribute("href", httpUrlForPipeline(baseUrl, entry.getId(), pipeline.getName())); }
From source file:com.thoughtworks.go.server.domain.xml.StageXmlViewModel.java
License:Apache License
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"); }// w w w . jav a2s .c o m return document; }
From source file:GnuCash.GnuCashDocument.java
License:Open Source License
public void addCommodity(String isin, String symbol, String name, String space) { setBook();/* w w w. j a va2s .c o m*/ //Element e=book.addElement("gnc:commodity"); DOMElement e = new DOMElement("gnc:commodity"); e.addAttribute("version", CMDTY_VERSION); e.addNamespace("cmdty", "http://www.gnucash.org/XML/cmdty"); e.addElement("cmdty:space").setText(space); e.addElement("cmdty:id").setText(symbol); e.addElement("cmdty:xcode").setText(isin); e.addElement("cmdty:name").setText(name); e.addElement("cmdty:fraction").setText(CMDTY_FRACTION); e.addElement("cmdty:get_quotes"); e.addElement("cmdty:quote_source").setText(CMDTY_QUOTE_SOURCE); e.addElement("cmdty:quote_tz"); book.elements("commodity").add(1, e); modified = true; /* * <gnc:commodity version="2.0.0"> <cmdty:space>XETRA</cmdty:space> <cmdty:id>586590</cmdty:id> <cmdty:name>Grenkeleasing AG</cmdty:name> <cmdty:fraction>10000</cmdty:fraction> <cmdty:get_quotes/> <cmdty:quote_source>vwd</cmdty:quote_source> <cmdty:quote_tz/> </gnc:commodity> */ }