Example usage for org.dom4j Element add

List of usage examples for org.dom4j Element add

Introduction

In this page you can find the example usage for org.dom4j Element add.

Prototype

void add(Namespace namespace);

Source Link

Document

Adds the given Namespace to this element.

Usage

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void changeHgUrl(String newURL) {
    List<Element> hgs = root().selectNodes("//hg");
    for (Element hg : hgs) {
        Element parent = hg.getParent();
        parent.remove(hg);/*from   www  . java2 s .  co  m*/
        String dest = hg.attributeValue("dest");
        Element newHg = new DefaultElement("hg");
        if (!StringUtils.isEmpty(dest)) {
            newHg.addAttribute("dest", dest);
        }
        newHg.addAttribute("url", newURL);
        parent.add(newHg);
    }
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void setTaskForFirstStage(String pipelineName, SimpleCruiseConfigTag cruiseConfigTag) {
    Element pipelineElement = pipelineElement(pipelineName);
    // Element tasksElement = (Element)
    // pipelineElement.selectSingleNode("stage/jobs/job/tasks");
    Element jobElement = (Element) pipelineElement.selectSingleNode("stage/jobs/job");

    Element tasksElement = jobElement.element("tasks");
    if (tasksElement == null) {
        tasksElement = new DefaultElement("tasks");
        jobElement.add(tasksElement);
    }/*from   www .  j  a v  a 2s.co m*/

    List<Element> taskList = tasksElement.elements();
    for (Element task : taskList) {
        tasksElement.remove(task);
    }

    tasksElement.add(cruiseConfigTag.convertToDomElement());
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void addResourceToAllAgents(String resource) {
    for (Element agent : allAgents()) {
        Element resources = findOrCreateElement(agent, "resources");
        resources.add(resourceElement(resource));
    }//  ww  w  .  j  ava2  s.  c o  m
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private void assignAgentToEnvironment(Element environment, String uuid) {
    Element physical = new DefaultElement("physical");
    physical.addAttribute("uuid", uuid);
    Element envAgents = (Element) environment.selectSingleNode("agents");
    if (envAgents == null) {
        Element envPipelines = (Element) environment.selectSingleNode("pipelines");
        if (envPipelines != null) {
            environment.remove(envPipelines);
        }/*from  www .  j  a  va2 s . c o m*/
        envAgents = new DefaultElement("agents");
        environment.add(envAgents);
        if (envPipelines != null) {
            environment.add(envPipelines);
        }
    }
    envAgents.add(physical);
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private void deassignAgentToEnvironment(Element environment, String uuid) {
    Element physical = new DefaultElement("physical");
    physical.addAttribute("uuid", uuid);
    Element envAgents = (Element) environment.selectSingleNode("agents");
    if (envAgents == null) {
        Element envPipelines = (Element) environment.selectSingleNode("pipelines");
        if (envPipelines != null) {
            environment.remove(envPipelines);
        }//from  ww w.  j  a  v a 2  s  .  c  o  m
        envAgents = new DefaultElement("agents");
        environment.remove(envAgents);
        if (envPipelines != null) {
            environment.add(envPipelines);
        }
    }
    envAgents.add(physical);
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void addResourceToJob(String resource, String jobName) {
    Element resources = findOrCreateElement(job(jobName), "resources");
    if (resources.selectSingleNode("/resource[text()='" + resource + "']") == null) {
        DefaultElement resourceElement = new DefaultElement("resource");
        resourceElement.addText(resource);
        resources.add(resourceElement);
    }// w ww. j  a v a  2 s . c o  m

}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private void addEnvironmentVariable(String name, String value, Element parent, int index) {
    Element variables = findOrCreateAt(parent, index, "environmentvariables");
    Element variableNode = new DefaultElement("variable").addAttribute("name", name);
    variableNode.add(new DefaultElement("value").addText(value));
    variables.add(variableNode);//  ww w . j a  va  2 s  .com
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public static Element findOrCreateAt(Element parent, int index, String childName) {
    Element found = (Element) parent.selectSingleNode(childName);
    if (found == null) {
        List<Element> children = parent.elements();
        if (children.size() == 0) {
            found = new DefaultElement(childName);
            parent.add(found);
            return found;
        }//  www  . ja  va2s.  c  o m
        for (Element child : children) {
            parent.remove(child);
            child.detach();
        }
        for (int i = 0; i < children.size(); i++) {
            Element child = children.get(i);
            if (i == index) {
                found = new DefaultElement(childName);
                parent.add(found);
            }
            parent.add(child);
        }
        // Adding to the end
        if (found == null) {
            found = new DefaultElement(childName);
            parent.add(found);
        }
    }
    return found;
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private Element findOrCreateElement(Element parent, String name) {
    Element childNode = (Element) parent.selectSingleNode(name);
    if (childNode == null) {
        parent.add(childNode = new DefaultElement(name));
    }//from w ww . j a  v a2 s. c  om
    return childNode;
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void pipelineAutoUpdate(String pipelineName) {
    List<Element> materials = materialsForPipeline(pipelineName);
    for (Element material : materials) {
        Attribute autoUpdate = material.attribute("autoUpdate");
        if (autoUpdate == null) {
            material.add(new DefaultAttribute("autoUpdate", "true"));
        } else {/* ww w . j  a v a2  s  .  c  o m*/
            autoUpdate.setValue("true");
        }
    }
}