List of usage examples for org.jdom2 Element getNamespace
public Namespace getNamespace()
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);// ww w . j a va2s .co m Element backups = new Element("backups", ns); backups.addContent(backup); root.addContent(location, backups); } }
From source file:org.artifactory.version.converter.v130.LdapSettings130Converter.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"); return;//from w w w. j a v a 2s. c o m } Element ldap = security.getChild("ldapSettings", ns); if (ldap == null) { log.debug("no ldap settings"); return; } ldap.removeChild("authenticationMethod", ns); ldap.removeChild("searchAuthPasswordAttributeName", ns); }
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.j a v a 2s. com } else { log.debug("No ldap settings found"); } } }
From source file:org.artifactory.version.converter.v132.BackupKeyConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Element backupsElement = root.getChild("backups", ns); List backups = null;// www .j a v a 2 s . co m if (backupsElement != null) { backups = backupsElement.getChildren("backup", ns); int generatedKeyIndex = 1; Iterator iterator = backups.iterator(); while (iterator.hasNext()) { Element backup = (Element) iterator.next(); Element cronExp = backup.getChild("cronExp", ns); if (cronExp == null) { log.debug("Removing a backup without cron expression"); iterator.remove(); //backupsElement.removeContent(backup); } else { // generate backup unique key and add to the backup element String key = "backup" + generatedKeyIndex++; Element keyElement = new Element("key", ns); keyElement.setText(key); backup.addContent(0, keyElement); log.debug("Generated key '{}' for backup element", key); } } } if (backupsElement == null || backups.isEmpty()) { log.debug("No backups 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;/* w ww . j a v a2 s . com*/ } 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.v134.BackupExcludedVirtualRepoConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Set<Object> virtualRepoKeys = Sets.newHashSet(); Element virtualRepositories = root.getChild("virtualRepositories", ns); if (virtualRepositories != null) { List repos = virtualRepositories.getChildren("virtualRepository", ns); for (Object repo : repos) { Element repoElem = (Element) repo; Element key = repoElem.getChild("key", ns); virtualRepoKeys.add(key.getText()); }/* w ww . j ava2 s. c o m*/ } Element backups = root.getChild("backups", ns); if (backups != null) { List backupsList = backups.getChildren("backup", ns); for (Object backup : backupsList) { Element backupElement = (Element) backup; Element excludedRepositories = backupElement.getChild("excludedRepositories", ns); if (excludedRepositories != null) { List excludedRepoList = excludedRepositories.getChildren("repositoryRef", ns); Iterator excludedRepoIterator = excludedRepoList.iterator(); while (excludedRepoIterator.hasNext()) { Element excludedRepo = (Element) excludedRepoIterator.next(); if (virtualRepoKeys.contains(excludedRepo.getText())) { excludedRepoIterator.remove(); } } } } } }
From source file:org.artifactory.version.converter.v135.ProxyNTHostConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Element proxiesElement = root.getChild("proxies", ns); if (proxiesElement != null) { List proxies = proxiesElement.getChildren("proxy", ns); for (Object proxyObj : proxies) { Element proxy = (Element) proxyObj; Element domain = proxy.getChild("domain", ns); if (domain != null) { Element ntHost = new Element("ntHost", ns); ntHost.setText(getHostName()); // insert the ntHost element right before the domain element proxy.addContent(proxy.indexOf(domain), ntHost); }/* w w w .j a v a 2s .c o m*/ } } }
From source file:org.artifactory.version.converter.v136.IndexerCronRemoverConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); /*// w w w. j a v a 2 s. co m <indexer> <cronExp>0 /1 * * * ?</cronExp> </indexer> to: <indexer> <indexingIntervalHours>24</indexingIntervalHours> </indexer> */ Element indexerElement = root.getChild("indexer", ns); if (indexerElement != null) { log.debug("Removing indexer cron expression."); indexerElement.removeContent(); log.debug("Adding default indexer interval."); Element intervalElement = new Element("indexingIntervalHours", ns); intervalElement.setText("24"); indexerElement.addContent(0, intervalElement); } }
From source file:org.artifactory.version.converter.v136.RepositoryTypeConverter.java
License:Open Source License
/** * Convert a <type> on a remote repository to a <type> on any repo - move the type after the description * if it exists.//from ww w . j av a 2 s . c om * * @param doc */ @Override @SuppressWarnings({ "unchecked" }) public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Element remoteRepositories = root.getChild("remoteRepositories", ns); if (remoteRepositories != null) { List repos = remoteRepositories.getChildren("remoteRepository", ns); for (Object repo : repos) { Element repoElem = (Element) repo; Element type = repoElem.getChild("type", ns); if (type != null) { log.debug("Relocating type..."); repoElem.removeChild("type", ns); //Try to place it first after the decription if exists, else after the key Element sibling = repoElem.getChild("description", ns); if (sibling == null) { sibling = repoElem.getChild("key", ns); } if (sibling != null) { repoElem.addContent(repoElem.indexOf(sibling) + 1, type); log.debug("Type relocated."); } else { log.warn("Type could be relocated - cannot determine proper location."); } } } } }
From source file:org.artifactory.version.converter.v141.ProxyDefaultConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); Element proxiesElement = root.getChild("proxies", ns); if (proxiesElement == null || proxiesElement.getChildren().isEmpty()) { log.debug("No proxies found"); return;/*from w w w. j a v a 2 s . c om*/ } List proxies = proxiesElement.getChildren(); Element repositoriesElement = root.getChild("remoteRepositories", ns); List remoteRepos = repositoriesElement.getChildren(); if (remoteRepos == null || remoteRepos.size() == 0) { log.debug("No remote repos found"); return; } Element defaultCandidate = null; for (Object remoteRepoObj : remoteRepos) { Element remoteRepo = (Element) remoteRepoObj; Element remoteRepoProxy = remoteRepo.getChild("proxyRef", ns); if (remoteRepoProxy == null) { //If the remote repository does not have a proxy, we can stop right here. return; } if (defaultCandidate != null && !remoteRepoProxy.getText().equals(defaultCandidate.getText())) { return; } if (defaultCandidate == null) { defaultCandidate = remoteRepoProxy; } } for (Object proxyObj : proxies) { Element proxy = (Element) proxyObj; Element proxyKey = proxy.getChild("key", ns); if (proxyKey.getText().equals(defaultCandidate.getText())) { if (proxy.getChild("defaultProxy", ns) == null) { // RTFACT-2450 Element element = new Element("defaultProxy", ns); element.setText("true"); proxy.addContent(element); } break; } } }