List of usage examples for org.jdom2 Element setText
public Element setText(final String text)
From source file:org.artifactory.version.converter.v110.SnapshotNonUniqueValueConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); List localRepos = root.getChild("localRepositories", ns).getChildren(); for (Object localRepo1 : localRepos) { Element localRepo = (Element) localRepo1; Element snapshotBehavior = localRepo.getChild("snapshotVersionBehavior", ns); if (snapshotBehavior != null && "nonunique".equals(snapshotBehavior.getText())) { log.debug("Changing value 'nonunique' to 'non-unique' for repo {}", localRepo.getChildText("key", ns)); snapshotBehavior.setText("non-unique"); }/* ww w. jav a2 s .c om*/ } }
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;/*w ww .jav a 2 s.c o 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
private Element createTextElement(String name, Namespace ns, String value) { Element userDnElement = new Element(name, ns); userDnElement.setText(value); return userDnElement; }
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); }//from w w w .jav a 2 s . co 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(); /*//from w w w. j ava2s . c o 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.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;/* w ww.j ava2 s . co m*/ } 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; } } }
From source file:org.artifactory.version.converter.v1410.GcSystemPropertyConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.info(/*from w w w.ja va 2 s . c o m*/ "Converting garbage collector system property to a cron expression based configuration descriptor."); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element gcConfigCronExpElement = new Element("cronExp", namespace); gcConfigCronExpElement.setText("0 0 /4 * * ?"); Element gcConfigElement = new Element("gcConfig", namespace); gcConfigElement.addContent(gcConfigCronExpElement); rootElement.addContent(gcConfigElement); log.info("Finished converting the garbage collector system property."); }
From source file:org.artifactory.version.converter.v1412.IndexerCronExpPropertyConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.info("Converting indexer indexingIntervalHours property to a cron expression based " + "configuration descriptor."); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element indexerElement = rootElement.getChild("indexer", namespace); if (indexerElement != null) { // Remove indexingIntervalHours property Element indexingIntervalHours = indexerElement.getChild("indexingIntervalHours", namespace); int intervalElementIndex = indexerElement.indexOf(indexingIntervalHours); if (indexingIntervalHours != null) { indexingIntervalHours.detach(); // Add cron expression property Element cronExpElement = new Element("cronExp", namespace); cronExpElement.setText("0 23 5 * * ?"); indexerElement.addContent(intervalElementIndex, cronExpElement); }/*from www . ja va 2 s.c om*/ } log.info("Finished converting the indexer indexingIntervalHours property."); }
From source file:org.artifactory.version.converter.v1414.AssumedOfflineConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.debug("Converting failedRetrievalCachePeriodSecs"); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element remoteRepositoriesElement = rootElement.getChild("remoteRepositories", namespace); if (remoteRepositoriesElement == null) { log.debug("No remote repository exists"); return;/* ww w.j a va 2 s .c o m*/ } List remoteRepositories = remoteRepositoriesElement.getChildren(); for (Object o : remoteRepositories) { Element remoteRepo = (Element) o; Element failedRetrievalElement = remoteRepo.getChild("failedRetrievalCachePeriodSecs", namespace); if (failedRetrievalElement != null) { failedRetrievalElement.setName("assumedOfflinePeriodSecs"); failedRetrievalElement.setText("300"); } } log.debug("Finished converting failedRetrievalCachePeriodSecs"); }
From source file:org.artifactory.version.converter.v1414.CleanupConfigConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.debug(// w ww . j a v a 2 s . co m "Converting artifacts cleanup system property to a cron expression based configuration descriptor."); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); // Create cron expression element with random times from 04:00AM to 05:59AM Element cronExpElement = new Element("cronExp", namespace); int minutes = RandomUtils.nextInt(60); // 0-59 int hours = RandomUtils.nextInt(2) + 4; // 4-5 cronExpElement.setText("0 " + minutes + " " + hours + " * * ?"); Element cleanupElement = new Element("cleanupConfig", namespace); cleanupElement.addContent(cronExpElement); rootElement.addContent(cleanupElement); log.debug("Finished converting the artifacts cleanup system property."); }