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 setUpSMTP(String hostName, int port, String username, String password, String tls, String from,
        String adminEmail) {// ww w . j  a  va  2 s. com
    Element serverTag = serverTag();
    DefaultElement mailhost = new DefaultElement("mailhost");
    mailhost.addAttribute("hostname", hostName);
    mailhost.addAttribute("port", String.valueOf(port));
    mailhost.addAttribute("username", username);
    mailhost.addAttribute("password", password);
    mailhost.addAttribute("tls", tls);
    mailhost.addAttribute("from", from);
    mailhost.addAttribute("admin", adminEmail);
    serverTag.add(mailhost);
}

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

License:Apache License

private void addChildrenBack(Element parent, List<Element> children) {
    for (Element element : children) {
        parent.add(element);
    }//from   w  w  w . ja  v  a  2s . c  o  m
}

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

License:Apache License

public void addTaskToJob(String pipelineName, String stageName, String jobName, Element taskElement) {
    Element pipeline = pipelineElement(pipelineName);
    Element job = (Element) pipeline
            .selectSingleNode(String.format("stage[@name='%s']/jobs/job[@name='%s']", stageName, jobName));
    Element tasks = job.element("tasks");
    if (tasks == null) {
        tasks = job.addElement("tasks");
    }//from   w w  w .j a v a2  s  .com
    tasks.add(taskElement);
}

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

License:Apache License

public void moveExistingPipelineToPipelineGroup(String pipeline, String pipelineGroup) {
    Element pipelines = pipelines(pipelineGroup);
    pipelines.add(pipelineElement(pipeline).detach());
}

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

License:Apache License

public void setAllowOnlyKnownUsersToLogin(boolean value) {
    Element security = (Element) document.getRootElement().selectSingleNode("//security");
    if (security == null) {
        security = new DefaultElement("security");
        Element server = (Element) document.getRootElement().selectSingleNode("//server");
        server.add(security);
    }/*  w  w  w.  j  a  v  a2s. com*/
    Attribute allowOnlyKnownUsers = security.attribute("allowOnlyKnownUsersToLogin");
    if (allowOnlyKnownUsers == null) {
        allowOnlyKnownUsers = new DefaultAttribute("allowOnlyKnownUsersToLogin", Boolean.toString(value));
        security.add(allowOnlyKnownUsers);
    } else {
        allowOnlyKnownUsers.setValue(Boolean.toString(value));
    }
}

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

License:Apache License

public void usingPasswordFile(File passwordFile) {
    Element passwordElement = new DefaultElement("passwordFile");
    passwordElement.addAttribute("path", passwordFile.getAbsolutePath());
    Element security = (Element) document.getRootElement().selectSingleNode("//security");
    if (security == null) {
        security = new DefaultElement("security");
        Element server = (Element) document.getRootElement().selectSingleNode("//server");
        server.add(security);
    }//from ww  w .j ava  2  s.c o  m
    security.add(passwordElement);
}

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

License:Apache License

public void addAdmins(String... users) {
    Element security = (Element) document.getRootElement().selectSingleNode("//security");
    Element admins = (Element) document.getRootElement().selectSingleNode("//admins");
    if (admins == null) {
        admins = new DefaultElement("admins");
        security.add(admins);
    }/*w ww.j  a  va  2s  .c  o m*/
    for (String user : users) {
        Element userElement = new DefaultElement("user");
        userElement.addText(user);
        admins.add(userElement);
    }
}

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

License:Apache License

public void addRolesToAdmin(String[] roles) {
    Element security = (Element) document.getRootElement().selectSingleNode("//security");
    Element admins = (Element) document.getRootElement().selectSingleNode("//admins");
    if (admins == null) {
        admins = new DefaultElement("admins");
        security.add(admins);
    }//from w  w  w.jav a 2s  .c  om
    for (String role : roles) {
        Element userElement = new DefaultElement("role");
        userElement.addText(role);
        admins.add(userElement);
    }
}

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

License:Apache License

public void addRoles(String[] splitedroles) {
    Element security = (Element) document.getRootElement().selectSingleNode("//security");
    Element roles = (Element) document.getRootElement().selectSingleNode("//roles");
    if (roles == null) {
        roles = new DefaultElement("roles");
        security.add(roles);
    }// w ww.j a  va 2  s .c  o m
    for (String splitedrole : splitedroles) {
        Element role = new DefaultElement("role");
        role.addAttribute("name", splitedrole);
        roles.add(role);
    }
}

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

License:Apache License

public void addUsersToRole(String roleName, String[] users) {
    Element security = (Element) document.getRootElement().selectSingleNode("//security");
    Element roles = (Element) document.getRootElement().selectSingleNode("//roles");
    if (roles == null) {
        roles = new DefaultElement("roles");
        security.add(roles);
    }/*from   ww w .j a v  a  2 s.com*/
    Element role = (Element) document.getRootElement().selectSingleNode("//role[name='" + roleName + "']");
    if (role == null) {
        role = new DefaultElement("role");
        role.addAttribute("name", roleName);
        roles.add(role);
    }
    for (String user : users) {
        Element userElement = new DefaultElement("user");
        userElement.addText(user);
        role.add(userElement);
    }
}