Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

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

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java

License:Apache License

/**
 * element/*from  www .ja  v a 2s  .  c  o  m*/
 *
 * @param element
 * @param properties
 */
private static void updateElement(Element element, Map<String, String> properties) {
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith("tools:")) {
            continue;
        }
        String keyNoPrefix = key;
        String[] values = StringUtils.split(key, ":");
        if (values.length > 1) {
            keyNoPrefix = values[1];
        }
        if (null == entry.getValue()) {
            continue;
        } else {
            Attribute attribute = element.attribute(keyNoPrefix);
            if (null != attribute) {
                attribute.setValue(entry.getValue());
            } else {
                element.addAttribute(key, entry.getValue());
            }
        }
    }
}

From source file:com.taobao.android.builder.tools.manifest.ManifestHelper.java

License:Apache License

public static void collectBundleInfo(AppVariantContext appVariantContext, BundleInfo bundleInfo, File manifest,
        List<AndroidLibrary> androidLibraries) throws DocumentException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(getModifyManifestFile(manifest, appVariantContext));// ?XML
    Element root = document.getRootElement();// 

    List<? extends Node> metadataNodes = root.selectNodes("//meta-data");
    for (Node node : metadataNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        if (attribute.getValue().equals("label")) {
            Attribute labelAttribute = element.attribute("value");
            bundleInfo.setName(labelAttribute.getValue());
        } else if (attribute.getValue().equals("description")) {
            Attribute descAttribute = element.attribute("value");
            bundleInfo.setDesc(descAttribute.getValue());
        }/*from w  ww.j a v a 2  s  .  c om*/
    }

    addComponents(bundleInfo, root);

    if (null != androidLibraries) {
        for (AndroidLibrary depLib : androidLibraries) {
            SAXReader reader2 = new SAXReader();
            Document document2 = reader2.read(getModifyManifestFile(depLib.getManifest(), appVariantContext));// ?XML
            Element root2 = document2.getRootElement();// 
            addComponents(bundleInfo, root2);
        }
    }

}

From source file:com.taobao.android.builder.tools.manifest.ManifestHelper.java

License:Apache License

private static void addComponents(BundleInfo bundleInfo, Element root) {
    List<? extends Node> serviceNodes = root.selectNodes("//service");
    for (Node node : serviceNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        addToList(bundleInfo.getServices(), attribute.getValue());
    }/*ww  w. j  ava2  s  . c o  m*/
    List<? extends Node> receiverNodes = root.selectNodes("//receiver");
    for (Node node : receiverNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        addToList(bundleInfo.getReceivers(), attribute.getValue());
    }
    List<? extends Node> providerNodes = root.selectNodes("//provider");
    for (Node node : providerNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        addToList(bundleInfo.getContentProviders(), attribute.getValue());
    }
    List<? extends Node> activityNodes = root.selectNodes("//activity");
    for (Node node : activityNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        addToList(bundleInfo.getActivities(), attribute.getValue());
    }
}

From source file:com.thoughtworks.cruise.api.feeds.CCTrayFeedXml.java

License:Apache License

@com.thoughtworks.gauge.Step("Verify cctray feed contains stage <stageName> job <jobName> with current activity <activity> with label <label> and last status <status>")
public void verifyCctrayFeedContainsStageJobWithCurrentActivityWithLabelAndLastStatus(String stageName,
        String jobName, String activity, String label, String status) throws Exception {

    Element node = jobNode(stageName, jobName);

    assertThat(node.attribute("activity").getStringValue(), is(activity));
    assertThat(node.attribute("lastBuildStatus").getStringValue(), is(status));
    assertThat(node.attribute("lastBuildLabel").getStringValue(), is(label));
}

From source file:com.thoughtworks.cruise.api.feeds.CCTrayFeedXml.java

License:Apache License

@com.thoughtworks.gauge.Step("Verify cctray feed contains stage <stageName> with current activity <activity> with label <label> and last status <status>")
public void verifyCctrayFeedContainsStageWithCurrentActivityWithLabelAndLastStatus(String stageName,
        String activity, String label, String status) throws Exception {

    Element node = stageNode(stageName);

    assertThat(node.attribute("activity").getStringValue(), is(activity));
    assertThat(node.attribute("lastBuildStatus").getStringValue(), is(status));
    assertThat(node.attribute("lastBuildLabel").getStringValue(), is(label));
}

From source file:com.thoughtworks.cruise.api.feeds.CCTrayFeedXml.java

License:Apache License

@com.thoughtworks.gauge.Step("Verify cctray feed contains stage <stageName> with relative weburl <webUrl>")
public void verifyCctrayFeedContainsStageWithRelativeWeburl(String stageName, String webUrl) throws Exception {

    String expectedWebUrl = "/pipelines/" + state.currentRuntimePipelineName() + webUrl;

    Element node = stageNode(stageName);

    String actualWebUrl = node.attribute("webUrl").getStringValue();

    assertThat(actualWebUrl, containsString(expectedWebUrl));
}

From source file:com.thoughtworks.cruise.api.feeds.CCTrayFeedXml.java

License:Apache License

@com.thoughtworks.gauge.Step("Verify cctray feed contains stage <stageName> and job <jobName> with relative weburl <webUrl>")
public void verifyCctrayFeedContainsStageAndJobWithRelativeWeburl(String stageName, String jobName,
        String webUrl) throws Exception {

    String expectedWebUrl = "/tab/build/detail/" + state.currentRuntimePipelineName() + webUrl;

    Element node = jobNode(stageName, jobName);

    String actualWebUrl = node.attribute("webUrl").getStringValue();

    assertThat(actualWebUrl, containsString(expectedWebUrl));
}

From source file:com.thoughtworks.cruise.context.configuration.ConflictingConfiguration.java

License:Apache License

private void pointPasswordFileToAbsolutePath(CruiseConfigDom dom, File passwordProperties) throws IOException {
    Element passwordFile = dom.getPasswordFile();
    passwordFile.attribute("path").setValue(passwordProperties.getCanonicalPath());
}

From source file:com.thoughtworks.cruise.context.configuration.DeletePackageConfiguration.java

License:Apache License

private void pointPasswordFileToAbsolutePath(CruiseConfigDom dom) throws IOException {
    File destination = config.copyPasswordFile(getClass().getResource("/config/password.properties"));
    Element passwordFile = dom.getPasswordFile();
    passwordFile.attribute("path").setValue(destination.getCanonicalPath());
}

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

License:Apache License

@com.thoughtworks.gauge.Step("Verify stage <stageName> has attribute <attribute> set to <value> where null means <defaultValue>")
public void verifyStageHasAttributeSetToWhereNullMeans(String stageName, String attribute, String value,
        String defaultValue) throws Exception {
    CruiseConfigDom dom = configuration.provideDomAsAdmin();
    Element stage = dom.getStage(state.currentRuntimePipelineName(), stageName);
    Attribute attr = stage.attribute(attribute);
    if (attr == null) {
        assertThat(defaultValue, is(value));
    } else {//from  w w  w  . ja  va2  s . com
        assertThat(attr.getValue(), is(value));
    }
}