List of usage examples for org.jdom2 Element removeContent
@Override public Content removeContent(final int index)
From source file:org.artifactory.update.md.v130beta6.ChecksumsConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Element extension = root.getChild("extension"); // rename the extensions to additionalInfo extension.setName("additionalInfo"); // now get the sha1 and md5 values Element sha1Node = extension.getChild("sha1"); String sha1 = null;// w ww . jav a2 s. com if (sha1Node != null) { sha1 = sha1Node.getValue(); extension.removeContent(sha1Node); } else { log.debug("SHA1 checksum not found, setting it to {}", sha1); } Element md5Node = extension.getChild("md5"); String md5 = null; if (md5Node != null) { md5 = md5Node.getValue(); extension.removeContent(md5Node); } else { log.debug("MD5 checksum not found, setting it to {}", md5); } // create the new checksums nodes Element checksumsInfo = new Element("checksumsInfo"); extension.addContent(checksumsInfo); Element checksums = new Element("checksums"); checksumsInfo.addContent(checksums); addChecksum(checksums, ChecksumType.sha1, sha1); addChecksum(checksums, ChecksumType.md5, md5); }
From source file:org.artifactory.update.security.v3.AclRepoKeysConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element aclsTag = doc.getRootElement().getChild("acls"); @SuppressWarnings({ "unchecked" }) List<Element> acls = aclsTag.getChildren(); for (Element acl : acls) { Element permissionTarget = acl.getChild("permissionTarget"); Element repoKeyElement = permissionTarget.getChild("repoKey"); permissionTarget.removeContent(repoKeyElement); // create the new element - repoKeys and add to the acl Element repoKeys = new Element("repoKeys"); repoKeyElement.setName("string"); // the xstream element name repoKeys.addContent(repoKeyElement); permissionTarget.addContent(repoKeys); }//ww w. ja v a2 s. c o m }
From source file:org.artifactory.version.converter.v100.BackupToElementConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Element backupDir = root.getChild("backupDir", ns); if (backupDir != null) { root.removeContent(backupDir); backupDir.setName("dir"); log.debug("Renamed 'backupDir' to 'dir'"); }//from w w w .j a v a 2s. c o m Element backupCron = root.getChild("backupCronExp", ns); if (backupCron != null) { root.removeContent(backupCron); backupCron.setName("cronExp"); log.debug("Renamed 'backupCronExp' to 'cronExp'"); } if (backupDir != null && backupCron != null) { // create the new <backup> element and place before the localRepositories Element backup = new Element("backup", ns); backup.addContent(backupDir); backup.addContent(backupCron); int localReposLocation = root.indexOf(root.getChild("localRepositories", ns)); root.addContent(localReposLocation, backup); } else { log.debug("No backup elements found"); } }
From source file:org.artifactory.version.converter.v130.AnnonAccessUnderSecurityConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Element annonAccess = root.getChild("anonAccessEnabled", ns); if (annonAccess == null) { log.debug("Element anonAccessEnabled not found"); return;// w w w.j a v a 2 s . co m } root.removeContent(annonAccess); Element security = root.getChild("security", ns); if (security == null) { security = new Element("security", ns); security.addContent(annonAccess); // serverName, anonAccessEnabled, fileUploadMaxSizeMb, dateFormat int location = findLastLocation(root, "serverName", "anonAccessEnabled", "fileUploadMaxSizeMb", "dateFormat"); root.addContent(location + 1, security); } else { security.addContent(0, annonAccess); } }
From source file:org.artifactory.version.converter.v130.BackupListConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Element backup = root.getChild("backup", ns); if (backup != null) { int location = root.indexOf(backup); root.removeContent(location); Element backups = new Element("backups", ns); backups.addContent(backup);//from w w w . j a va2 s . c o m root.addContent(location, backups); } }
From source file:org.artifactory.version.converter.v131.LdapAuthenticationPatternsConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Element security = root.getChild("security", ns); if (security != null) { Element ldapSettings = security.getChild("ldapSettings", ns); if (ldapSettings != null) { Element userDn = ldapSettings.getChild("userDnPattern", ns); if (userDn != null) { log.debug("Moving userDnPattern under authenticationPatterns"); int location = ldapSettings.indexOf(userDn); ldapSettings.removeContent(userDn); Element authPatterns = new Element("authenticationPatterns", ns); Element authPattern = new Element("authenticationPattern", ns); authPattern.addContent(userDn); authPatterns.addContent(authPattern); ldapSettings.addContent(location, authPatterns); }/*www . ja v a 2 s . c o m*/ } else { log.debug("No ldap settings found"); } } }
From source file:org.artifactory.version.converter.v132.LdapListConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Element security = root.getChild("security", ns); if (security == null) { log.debug("No security settings defned"); return;//from w w w . j a v a 2 s. c o m } Element oldLdapSettings = security.getChild("ldapSettings", ns); if (oldLdapSettings == null) { log.debug("No ldap settings configured"); return; } int location = security.indexOf(oldLdapSettings); security.removeContent(oldLdapSettings); Element ldapSettings = new Element("ldapSettings", ns); security.addContent(location, ldapSettings); String ldapUrl = oldLdapSettings.getChildText("ldapUrl", ns); // manager dn and password only relevant for search based authentications String managerDn = oldLdapSettings.getChildText("managerDn", ns); String managerPassword = oldLdapSettings.getChildText("managerPassword", ns); // convert authentication patterns Element authPatternsElement = oldLdapSettings.getChild("authenticationPatterns", ns); List authPatterns = authPatternsElement.getChildren("authenticationPattern", ns); log.debug("Found {} patterns to convert" + authPatterns.size()); // create new ldap setting for each authentication pattern int ldapKeyIndex = 1; for (Object pattern : authPatterns) { Element authPattern = (Element) pattern; Element ldapSetting = new Element("ldapSetting", ns); ldapSettings.addContent(ldapSetting); // add the key ldapSetting.addContent(createTextElement("key", ns, "ldap" + ldapKeyIndex++)); // set enabled true ldapSetting.addContent(createTextElement("enabled", ns, "true")); // add the ldap url ldapSetting.addContent(createTextElement("ldapUrl", ns, ldapUrl)); // add user dn if not empty String userDn = authPattern.getChildText("userDnPattern", ns); if (userDn != null) { ldapSetting.addContent(createTextElement("userDnPattern", ns, userDn)); } // create and add search element if search filter exists String searchFilter = authPattern.getChildText("searchFilter", ns); if (searchFilter != null) { Element search = new Element("search", ns); ldapSetting.addContent(search); search.addContent(createTextElement("searchFilter", ns, searchFilter)); String searchBase = authPattern.getChildText("searchBase", ns); if (searchBase != null) { search.addContent(createTextElement("searchBase", ns, searchBase)); } String searchSubTree = authPattern.getChildText("searchSubTree", ns); if (searchSubTree != null) { search.addContent(createTextElement("searchSubTree", ns, searchSubTree)); } if (managerDn != null) { search.addContent(createTextElement("managerDn", ns, managerDn)); } if (managerPassword != null) { search.addContent(createTextElement("managerPassword", ns, managerPassword)); } } } }
From source file:org.artifactory.version.converter.v142.RepoIncludeExcludePatternsConverter.java
License:Open Source License
private void setPatternsElements(Element repoElement, Element patternElement, Namespace ns) { if (patternElement == null) { return;/*from www .j a va2s . c om*/ } repoElement.removeContent(patternElement); int location; Element lookForElement = repoElement.getChild("includesPattern", ns); if (lookForElement != null) { location = repoElement.indexOf(lookForElement); repoElement.addContent(location + 1, patternElement); return; } lookForElement = repoElement.getChild("type", ns); if (lookForElement != null) { location = repoElement.indexOf(lookForElement); repoElement.addContent(location + 1, patternElement); return; } lookForElement = repoElement.getChild("description", ns); if (lookForElement != null) { location = repoElement.indexOf(lookForElement); repoElement.addContent(location + 1, patternElement); return; } lookForElement = repoElement.getChild("key", ns); location = repoElement.indexOf(lookForElement); repoElement.addContent(location + 1, patternElement); }
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 w w.j a v a 2 s . c om*/ 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.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 w w . j a v a 2s.c o m Element repositoryRef = new Element("repositoryRef", namespace); repositoryRef.setText(repo); includedRepositories.addContent(repositoryRef); }); indexer.addContent(new Text("\n ")); indexer.addContent(includedRepositories); } indexer.removeContent(excludedRepositories); }