Example usage for org.jdom2 Element setText

List of usage examples for org.jdom2 Element setText

Introduction

In this page you can find the example usage for org.jdom2 Element setText.

Prototype

public Element setText(final String text) 

Source Link

Document

Sets the content of the element to be the text given.

Usage

From source file:org.artifactory.version.converter.v144.MultiLdapXmlConverter.java

License:Open Source License

@Override
public void convert(Document doc) {
    Element rootElement = doc.getRootElement();
    Namespace namespace = rootElement.getNamespace();
    Element securityElement = rootElement.getChild("security", namespace);
    if (securityElement != null) {
        Element ldapSettings = securityElement.getChild("ldapSettings", namespace);
        if (ldapSettings != null) {
            String firstLdapKey = null;
            String ldapKeyToUse = null;
            List ldapSettingList = ldapSettings.getChildren("ldapSetting", namespace);
            if (ldapSettingList != null && !ldapSettingList.isEmpty()) {
                for (Object ldapSettingObject : ldapSettingList) {
                    Element ldapSetting = (Element) ldapSettingObject;
                    Element key = ldapSetting.getChild("key", namespace);
                    if (firstLdapKey == null) {
                        firstLdapKey = key.getValue();
                    }/*from  w ww .  j ava2  s.c  o  m*/
                    Element enabledElement = ldapSetting.getChild("enabled", namespace);
                    if (Boolean.parseBoolean(enabledElement.getValue())) {
                        ldapKeyToUse = ldapSetting.getChild("key", namespace).getValue();
                    }
                }
            }
            if (ldapKeyToUse == null && firstLdapKey != null) {
                ldapKeyToUse = firstLdapKey;
            }
            if (ldapKeyToUse != null) {
                Element ldapGroupSettings = securityElement.getChild("ldapGroupSettings", namespace);
                if (ldapGroupSettings != null) {
                    List ldapGroupList = ldapGroupSettings.getChildren("ldapGroupSetting", namespace);
                    if (ldapGroupList != null && !ldapGroupList.isEmpty()) {
                        for (Object ldapGroupSettingObject : ldapGroupList) {
                            Element ldapGroupSetting = (Element) ldapGroupSettingObject;
                            Element enabledLdapElement = new Element("enabledLdap", namespace);
                            enabledLdapElement.setText(ldapKeyToUse);
                            Element enabledContent = ldapGroupSetting.getChild("enabled", namespace);
                            int index = ldapGroupSetting.indexOf(enabledContent);
                            ldapGroupSetting.addContent(index, enabledLdapElement);
                            ldapGroupSetting.removeContent(enabledContent);
                        }
                    }
                }
            }
        }
    }
}

From source file:org.artifactory.version.converter.v147.DefaultRepoLayoutConverter.java

License:Open Source License

public Element getRepoLayoutElement(Namespace namespace, String name, String artifactPathPattern,
        String distinctiveDescriptorPathPattern, String descriptorPathPattern,
        String folderIntegrationRevisionRegExp, String fileIntegrationRevisionRegExp) {

    Element repoLayoutElement = new Element("repoLayout", namespace);

    Element nameElement = new Element("name", namespace);
    nameElement.setText(name);
    repoLayoutElement.addContent(nameElement);

    Element artifactPathPatternElement = new Element("artifactPathPattern", namespace);
    artifactPathPatternElement.setText(artifactPathPattern);
    repoLayoutElement.addContent(artifactPathPatternElement);

    Element distinctiveDescriptorPathPatternElement = new Element("distinctiveDescriptorPathPattern",
            namespace);//from w  w w  . j a  va  2 s . c  o m
    distinctiveDescriptorPathPatternElement.setText(distinctiveDescriptorPathPattern);
    repoLayoutElement.addContent(distinctiveDescriptorPathPatternElement);

    Element descriptorPathPatternElement = new Element("descriptorPathPattern", namespace);
    descriptorPathPatternElement.setText(descriptorPathPattern);
    repoLayoutElement.addContent(descriptorPathPatternElement);

    if (StringUtils.isNotBlank(folderIntegrationRevisionRegExp)) {
        Element folderIntegrationRevisionRegExpElement = new Element("folderIntegrationRevisionRegExp",
                namespace);
        folderIntegrationRevisionRegExpElement.setText(folderIntegrationRevisionRegExp);
        repoLayoutElement.addContent(folderIntegrationRevisionRegExpElement);
    }

    if (StringUtils.isNotBlank(fileIntegrationRevisionRegExp)) {
        Element fileIntegrationRevisionRegExpElement = new Element("fileIntegrationRevisionRegExp", namespace);
        fileIntegrationRevisionRegExpElement.setText(fileIntegrationRevisionRegExp);
        repoLayoutElement.addContent(fileIntegrationRevisionRegExpElement);
    }

    return repoLayoutElement;
}

From source file:org.artifactory.version.converter.v147.DefaultRepoLayoutConverter.java

License:Open Source License

private void appendRepoLayoutRef(Element repositoryElement, Namespace namespace) {
    Element repoLayoutRefElement = new Element("repoLayoutRef", namespace);
    repoLayoutRefElement.setText(RepoLayoutUtils.MAVEN_2_DEFAULT_NAME);

    log.debug("Appending default layout reference to '{}'",
            repositoryElement.getChild("key", namespace).getText());
    appendElementAfter(repositoryElement, repoLayoutRefElement, namespace, "excludesPattern", "includesPattern",
            "notes", "type", "description", "key");
}

From source file:org.artifactory.version.converter.v147.DefaultRepoLayoutConverter.java

License:Open Source License

private void removeRepoType(Element repositoryElement, boolean isRemote, Namespace namespace) {
    Element typeElement = repositoryElement.getChild("type", namespace);
    if (typeElement != null) {

        String repoKey = repositoryElement.getChild("key", namespace).getText();
        log.debug("Removing repository type definition from '{}'", repoKey);
        repositoryElement.removeChild("type", namespace);

        if (isRemote && "maven1".equals(typeElement.getText())) {

            Element remoteRepoLayoutRefElement = new Element("remoteRepoLayoutRef", namespace);
            remoteRepoLayoutRefElement.setText(RepoLayoutUtils.MAVEN_1_DEFAULT_NAME);

            log.debug("Appending Maven 1 remote repository layout reference to '{}'", repoKey);
            appendElementAfter(repositoryElement, remoteRepoLayoutRefElement, namespace,
                    "listRemoteFolderItems", "synchronizeProperties", "shareConfiguration",
                    "unusedArtifactsCleanupPeriodHours", "unusedArtifactsCleanupEnabled",
                    "remoteRepoChecksumPolicyType", "missedRetrievalCachePeriodSecs",
                    "failedRetrievalCachePeriodSecs", "retrievalCachePeriodSecs", "fetchSourcesEagerly",
                    "fetchJarsEagerly", "storeArtifactsLocally", "hardFail", "offline", "url");
        }/* www . j  ava  2 s .  co  m*/
    }
}

From source file:org.artifactory.version.converter.v147.JfrogRemoteRepoUrlConverter.java

License:Open Source License

@Override
public void convert(Document doc) {
    Element rootElement = doc.getRootElement();
    Namespace namespace = rootElement.getNamespace();
    Element repositories = rootElement.getChild("remoteRepositories", namespace);
    if (repositories != null) {
        List remoteRepos = repositories.getChildren("remoteRepository", namespace);
        if (remoteRepos != null && !remoteRepos.isEmpty()) {
            for (Object remoteRepo : remoteRepos) {
                Element remoteRepoElement = (Element) remoteRepo;
                Element url = remoteRepoElement.getChild("url", namespace);
                if (url != null) {
                    String urlText = url.getText();
                    if (OLD_JFROG_LIBS.equals(urlText)) {
                        url.setText(NEW_JFROG_LIBS);
                    } else if (OLD_JFROG_PLUGINS.equals(urlText)) {
                        url.setText(NEW_JFROG_PLUGINS);
                    }//  w  w w  .  ja  v  a 2  s .  c o  m
                }
            }
        }
    }
}

From source file:org.artifactory.version.converter.v152.BlackDuckProxyConverter.java

License:Open Source License

@Override
public void convert(Document doc) {
    log.info("Converting BlackDuck intergration proxy settings");
    Element rootElement = doc.getRootElement();
    Namespace namespace = rootElement.getNamespace();

    Element defaultProxy = findDefaultProxy(rootElement, namespace);
    Element externalProviders = rootElement.getChild("externalProviders", namespace);
    if (externalProviders == null) {
        return;/* ww w  .  j a  v a 2s  .  c  o  m*/
    }
    Element blackDuckConf = externalProviders.getChild("blackduck", namespace);
    if (defaultProxy != null && blackDuckConf != null) {
        if (blackDuckConf.getChild("proxyRef") != null) {
            return;
        }
        Element proxyTag = new Element("proxyRef", namespace);
        proxyTag.setText(defaultProxy.getChildText("key", namespace));
        blackDuckConf.addContent(proxyTag);
    }
}

From source file:org.artifactory.version.converter.v153.VirtualCacheCleanupConverter.java

License:Open Source License

@Override
public void convert(Document doc) {
    log.info("Adding default virtual cache cleanup");
    Element rootElement = doc.getRootElement();
    Namespace namespace = rootElement.getNamespace();

    if (rootElement.getChild("virtualCacheCleanupConfig") != null)
        return;//from   w  w  w  . ja v a2s .  c  o m
    Element cleanupConfig = rootElement.getChild("cleanupConfig", namespace);
    Element virtualCacheCleanupConfig = new Element("virtualCacheCleanupConfig", namespace);
    Element cronExp = new Element("cronExp", namespace);
    cronExp.setText("0 12 5 * * ?");
    virtualCacheCleanupConfig.addContent(cronExp);
    rootElement.addContent(rootElement.indexOf(cleanupConfig) + 1, virtualCacheCleanupConfig);
}

From source file:org.artifactory.version.converter.v160.AddonsDefaultLayoutConverter.java

License:Open Source License

public Element getRepoLayoutElement(Element repoLayoutsElement, Namespace namespace, String name,
        String artifactPathPattern, String distinctiveDescriptorPathPattern, String descriptorPathPattern,
        String folderIntegrationRevisionRegExp, String fileIntegrationRevisionRegExp) {

    // Maybe the user already configured *-default, if so randomize the name
    for (Element repoLayoutElement : repoLayoutsElement.getChildren()) {
        if (name.equals(repoLayoutElement.getChild("name", namespace).getText())) {
            if (repoLayoutsElement.getChild("art-" + name, namespace) != null) {
                name += RandomStringUtils.randomNumeric(3);
            } else {
                name = "art-" + name;
            }//  www  .ja  v a  2  s .c  o  m
        }
    }

    Element repoLayoutElement = new Element("repoLayout", namespace);

    Element nameElement = new Element("name", namespace);
    nameElement.setText(name);
    repoLayoutElement.addContent(nameElement);

    Element artifactPathPatternElement = new Element("artifactPathPattern", namespace);
    artifactPathPatternElement.setText(artifactPathPattern);
    repoLayoutElement.addContent(artifactPathPatternElement);

    Element distinctiveDescriptorPathPatternElement = new Element("distinctiveDescriptorPathPattern",
            namespace);
    distinctiveDescriptorPathPatternElement.setText(distinctiveDescriptorPathPattern);
    repoLayoutElement.addContent(distinctiveDescriptorPathPatternElement);

    if (StringUtils.isNotBlank(descriptorPathPattern)) {
        Element descriptorPathPatternElement = new Element("descriptorPathPattern", namespace);
        descriptorPathPatternElement.setText(descriptorPathPattern);
        repoLayoutElement.addContent(descriptorPathPatternElement);
    }

    if (StringUtils.isNotBlank(folderIntegrationRevisionRegExp)) {
        Element folderIntegrationRevisionRegExpElement = new Element("folderIntegrationRevisionRegExp",
                namespace);
        folderIntegrationRevisionRegExpElement.setText(folderIntegrationRevisionRegExp);
        repoLayoutElement.addContent(folderIntegrationRevisionRegExpElement);
    }

    if (StringUtils.isNotBlank(fileIntegrationRevisionRegExp)) {
        Element fileIntegrationRevisionRegExpElement = new Element("fileIntegrationRevisionRegExp", namespace);
        fileIntegrationRevisionRegExpElement.setText(fileIntegrationRevisionRegExp);
        repoLayoutElement.addContent(fileIntegrationRevisionRegExpElement);
    }

    return repoLayoutElement;
}

From source file:org.artifactory.version.converter.v160.MavenIndexerConverter.java

License:Open Source License

private void replaceExcludedWithIncluded(Element rootElement, Namespace namespace, Element indexer,
        Element excludedRepositories) {
    List<String> excluded = excludedRepositories.getChildren().stream().map(Element::getText)
            .collect(Collectors.toList());

    if (StringUtils.equals(indexer.getChildText("enabled", namespace), "true")) {
        Element includedRepositories = new Element("includedRepositories", namespace);
        collectRepositories(rootElement, namespace).stream().filter(repo -> !excluded.contains(repo))
                .forEach(repo -> {//  w ww  .jav a2 s. co  m
                    Element repositoryRef = new Element("repositoryRef", namespace);
                    repositoryRef.setText(repo);
                    includedRepositories.addContent(repositoryRef);
                });
        indexer.addContent(new Text("\n        "));
        indexer.addContent(includedRepositories);
    }

    indexer.removeContent(excludedRepositories);
}

From source file:org.artifactory.version.converter.v160.SingleRepoTypeConverter.java

License:Open Source License

private void convertToSingleRepoType(Element repo, String repoKey, List<RepoType> repoTypes,
        boolean virtualRepo) {
    if (repoTypes.size() >= 1) {
        repoTypes.stream().skip(1) // First one is used as the final repository type
                .forEach(repoType -> log.error(
                        "Disabling package '{}' for repo '{}' " + "since only one packaging type is allowed!",
                        repoType, repoKey));
    } else {//from w  ww  .j a va  2s .c  o m
        String layoutRef = repo.getChildText("repoLayoutRef", repo.getNamespace());
        if (StringUtils.equals(layoutRef, "ivy-default")) {
            repoTypes.add(RepoType.Ivy);
        } else if (StringUtils.equals(layoutRef, "gradle-default")) {
            repoTypes.add(RepoType.Gradle);
        } else {
            repoTypes.add(RepoType.Maven);
        }
    }

    // Set the final decided repo type
    RepoType repoType = repoTypes.get(0);
    log.info("Setting repository '{}' to type {}", repoKey, repoType);
    Element typeElement = new Element("type", repo.getNamespace());
    typeElement.setText(String.valueOf(repoType).toLowerCase());
    repo.addContent(2, new Text("\n            "));
    repo.addContent(3, typeElement); // add the type after the key property
    removeEnabledFieldsFromRepo(repo, virtualRepo);
}