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.thinkberg.moxo.dav.PropPatchHandler.java

License:Apache License

private void setProperty(Element root, FileObject object, Element el) {
    List propList = el.elements();
    for (Object propElObject : propList) {
        Element propEl = (Element) propElObject;
        for (int i = 0; i < propEl.nodeCount(); i++) {
            propEl.node(i).detach();/*  ww  w  . j  a  v  a2 s.c  o m*/
        }
        root.add(propEl.detach());
    }
}

From source file:com.thinkberg.webdav.data.DavResource.java

License:Apache License

/**
 * Add the value for a given property to the result document. If the value
 * is missing or can not be added for some reason it will return false to
 * indicate a missing property.//from   w  w w. ja  va2s .  co  m
 *
 * @param root         the root element for the result document fragment
 * @param propertyName the property name to query
 * @return true for successful addition and false for missing data
 */
protected boolean getPropertyValue(Element root, String propertyName, boolean ignoreValue) {
    LogFactory.getLog(getClass()).debug(String.format("[%s].get('%s')", object.getName(), propertyName));
    if (PROP_CREATION_DATE.equals(propertyName)) {
        return addCreationDateProperty(root, ignoreValue);
    } else if (PROP_DISPLAY_NAME.equals(propertyName)) {
        return addGetDisplayNameProperty(root, ignoreValue);
    } else if (PROP_GET_CONTENT_LANGUAGE.equals(propertyName)) {
        return addGetContentLanguageProperty(root, ignoreValue);
    } else if (PROP_GET_CONTENT_LENGTH.equals(propertyName)) {
        return addGetContentLengthProperty(root, ignoreValue);
    } else if (PROP_GET_CONTENT_TYPE.equals(propertyName)) {
        return addGetContentTypeProperty(root, ignoreValue);
    } else if (PROP_GET_ETAG.equals(propertyName)) {
        return addGetETagProperty(root, ignoreValue);
    } else if (PROP_GET_LAST_MODIFIED.equals(propertyName)) {
        return addGetLastModifiedProperty(root, ignoreValue);
    } else if (PROP_LOCK_DISCOVERY.equals(propertyName)) {
        return addLockDiscoveryProperty(root, ignoreValue);
    } else if (PROP_RESOURCETYPE.equals(propertyName)) {
        return addResourceTypeProperty(root, ignoreValue);
    } else if (PROP_SOURCE.equals(propertyName)) {
        return addSourceProperty(root, ignoreValue);
    } else if (PROP_SUPPORTED_LOCK.equals(propertyName)) {
        return addSupportedLockProperty(root, ignoreValue);
    } else {
        // handle non-standard properties (keep a little separate)
        if (PROP_QUOTA.equals(propertyName)) {
            return addQuotaProperty(root, ignoreValue);
        } else if (PROP_QUOTA_USED.equals(propertyName)) {
            return addQuotaUsedProperty(root, ignoreValue);
        } else if (PROP_QUOTA_AVAILABLE_BYTES.equals(propertyName)) {
            return addQuotaAvailableBytesProperty(root, ignoreValue);
        } else if (PROP_QUOTA_USED_BYTES.equals(propertyName)) {
            return addQuotaUsedBytesProperty(root, ignoreValue);
        } else {
            try {
                Object propertyValue = object.getContent().getAttribute(propertyName);
                if (null != propertyValue) {
                    if (((String) propertyValue).startsWith("<")) {
                        try {
                            Document property = DocumentHelper.parseText((String) propertyValue);
                            if (ignoreValue) {
                                property.clearContent();
                            }
                            root.add(property.getRootElement().detach());
                            return true;
                        } catch (DocumentException e) {
                            LogFactory.getLog(getClass()).error("property value unparsable", e);
                            return false;
                        }
                    } else {
                        Element el = root.addElement(propertyName);
                        if (!ignoreValue) {
                            el.addText((String) propertyValue);
                        }
                        return true;
                    }

                }
            } catch (FileSystemException e) {
                LogFactory.getLog(this.getClass())
                        .error(String.format("property '%s' is not supported", propertyName), e);
            }
        }
    }

    return false;
}

From source file:com.thoughtworks.cruise.ConfigureCruiseUsingApi.java

License:Apache License

private void addUserAsAdmin(Document group, String username) {
    Element auth = (Element) group.selectSingleNode("//authorization");
    if (auth == null) {
        Element element = new DefaultElement("authorization");
        element.add(admins(username));
    } else if (auth.selectSingleNode(".//admins") != null) {
        user(username, (Element) auth.selectSingleNode(".//admins"));
    } else {/*from   w  w  w.  j a  v  a 2  s.  c o m*/
        auth.add(admins(username));
    }
}

From source file:com.thoughtworks.cruise.ConfigureCruiseUsingApi.java

License:Apache License

private void user(String username, Element admins) {
    DefaultElement user = new DefaultElement("user");
    user.setText(username);//w w w .j  a  v  a2 s  . c  o m
    admins.add(user);
}

From source file:com.thoughtworks.cruise.ConfigureCruiseUsingApi.java

License:Apache License

@com.thoughtworks.gauge.Step("Create pipeline <pipelineName> using template <templateName>")
public void createPipelineUsingTemplate(final String pipelineName, final String templateName) throws Exception {
    editPipelineGroup(new PipelineGroupEditAction() {

        public void applyEdit(Document group) {
            Element pipelines = (Element) group.selectSingleNode("//pipelines");
            Element pipeline = new DefaultElement("pipeline");
            pipeline.addAttribute("name", pipelineName);
            pipeline.addAttribute("template", templateName);
            DefaultElement materials = new DefaultElement("materials");
            DefaultElement hg = new DefaultElement("hg");
            hg.addAttribute("url", "some-url");
            materials.add(hg);/* ww  w  .  j a  v a  2s  .c o  m*/
            pipeline.add(materials);
            pipelines.add(pipeline);
            scenarioState.pushPipeline(pipelineName, pipelineName);
        }
    });
}

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

License:Apache License

public void appendFetchArtifacts(String pipelineName, String stageName, String job, String pipelineFetchFrom,
        String stageFetchFrom, String path, String dest) {
    Element jobElement = getJob(pipelineName, stageName, job);
    Element tasks = (Element) jobElement.selectSingleNode("tasks");
    if (tasks == null) {
        tasks = ((Element) jobElement).addElement("tasks");
    }/* ww w .ja va  2s. com*/

    Element fetchArtifact = new DefaultElement("fetchartifact");
    fetchArtifact.addAttribute("pipeline", pipelineFetchFrom);
    fetchArtifact.addAttribute("stage", stageFetchFrom);
    fetchArtifact.addAttribute("job", job);
    fetchArtifact.addAttribute("srcfile", path);
    fetchArtifact.addAttribute("dest", dest);

    tasks.add(fetchArtifact);
}

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

License:Apache License

public void appendFetchDirectory(String pipelineName, String firstStage, String secondStage, String job,
        String path, String dest) {
    Element jobElement = getJob(pipelineName, secondStage, job);
    Element tasks = (Element) jobElement.selectSingleNode("tasks");

    Element fetchArtifact = new DefaultElement("fetchartifact");
    fetchArtifact.addAttribute("stage", firstStage);
    fetchArtifact.addAttribute("job", job);
    fetchArtifact.addAttribute("srcdir", path);
    fetchArtifact.addAttribute("dest", dest);

    tasks.add(fetchArtifact);

}

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

License:Apache License

public void setApprovalTypeForStage(String pipelineName, String stageName, String type) {
    Element stage = getStage(pipelineName, stageName);
    Element approval = stage.element("approval");
    if (approval == null) {
        approval = new DefaultElement("approval");
        Element jobs = stage.element("jobs");
        if (jobs != null) {
            jobs.detach();//  w ww. ja va2s . c  o m
            stage.add(approval);
            stage.add(jobs);
        } else {
            stage.add(approval);
        }
    }
    Attribute attribute = approval.attribute("type");
    if (attribute != null) {
        attribute.setValue(type);
    } else {
        approval.addAttribute("type", type);
    }
}

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

License:Apache License

public void updateLicense(String license, String user) {
    Element licenseElement = (Element) root().selectSingleNode("//license");
    licenseElement.clearContent();/*w w w  . ja  va2  s.  c om*/
    licenseElement.add(new DefaultText(license));
    licenseElement.addAttribute("user", user);
}

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

License:Apache License

public void updateBuildFile(String pipelineName, String stageName, String jobName, String buildType,
        String buildFile) {/*w  w  w . j  a  v  a 2s.co  m*/
    String xpath = String.format(
            "//pipelines/pipeline[@name='%s']/stage[@name='%s']/jobs/job[@name='%s']/tasks", pipelineName,
            stageName, jobName);
    Element element = (Element) document.selectSingleNode(xpath);
    element.clearContent();
    Element newElement = new DefaultElement(buildType);
    newElement.addAttribute("buildfile", buildFile);
    element.add(newElement);

}