List of usage examples for org.jdom2 Element getNamespace
public Namespace getNamespace()
From source file:org.artifactory.repo.virtual.interceptor.transformer.PomTransformer.java
License:Open Source License
public String transform() { if (pomCleanupPolicy.equals(PomCleanupPolicy.nothing)) { return pomAsString; }/*from w w w. j av a 2 s . com*/ Document pomDocument; try { //delete repositories and pluginsRepositories //Maven model does not preserve layout pomDocument = XmlUtils.parse(pomAsString); } catch (Exception e) { log.warn("Failed to parse pom '{}': ", e.getMessage()); return pomAsString; } Element pomRoot = pomDocument.getRootElement(); Namespace namespace = pomRoot.getNamespace(); removeChild(pomRoot, "repositories", namespace); removeChild(pomRoot, "pluginRepositories", namespace); boolean onlyActiveDefault = pomCleanupPolicy.equals(PomCleanupPolicy.discard_active_reference); //delete repositories and pluginsRepositories in profiles Element profilesElement = pomRoot.getChild("profiles", namespace); if (profilesElement != null) { List profiles = profilesElement.getChildren(); for (Object profile : profiles) { Element profileElement = (Element) profile; if (onlyActiveDefault) { boolean activeByDefault = false; Element activationElement = profileElement.getChild("activation", namespace); if (activationElement != null) { Element activationByDefault = activationElement.getChild("activeByDefault", namespace); if (activationByDefault != null) { activeByDefault = Boolean.parseBoolean(activationByDefault.getText()); } } if (activeByDefault) { deleteProfileRepositories(profileElement, namespace); } } else { deleteProfileRepositories(profileElement, namespace); } } } /** * We might have reached here without the pom actually changing, so return the modified xml only if it was * Actually modified, otherwise it can result with identical looking POMs that calculate to different checksums */ if (pomChanged) { return XmlUtils.outputString(pomDocument); } else { return pomAsString; } }
From source file:org.artifactory.update.security.v6.LdapGroupSettingXmlConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Namespace namespace = root.getNamespace(); Element child = root.getChild("users", namespace); List users = child.getChildren("user", namespace); if (users != null && !users.isEmpty()) { for (Object user : users) { Element userElement = (Element) user; Element groups = userElement.getChild("groups", namespace); if (groups != null) { List groupNames = groups.getChildren("string", namespace); List<String> listOfGroupNames = new ArrayList<>(); for (Object groupName : groupNames) { Element group = (Element) groupName; listOfGroupNames.add(group.getText()); }/*from w ww .j av a 2 s .co m*/ groups.removeChildren("string", namespace); for (String name : listOfGroupNames) { Element userGroup = new Element("userGroup", namespace); userGroup.setText(name); groups.addContent(userGroup); } } } } }
From source file:org.artifactory.update.security.v6.LowercaseUsernameXmlConverter.java
License:Open Source License
@Override public void convert(Document doc) { // 1. aggregate all usenames in a map (username->user element) // 2. for each user check if another lowercase username exists in the map // 2.1 if duplicates doesn't exist, add to the users SET/MAP // 2.2 if duplicates exist, take the admin if there is one (first if not) // 3. attach the users elements to the "users" element (cut it first) // in the acls: // 1. for each ace in acl: // 1.1 if no duplicate -> add to the list of aces // 1.2 if there are duplicates -> merge the mask eg a | b (101 | 010 = 111) // for groups: // 1. Remove duplicates under groups element (change all to lowercase) // 2. Remove duplicates under users groups element (change all to lowercase) // merge aces (same for groups and for users) Element root = doc.getRootElement(); Namespace namespace = root.getNamespace(); mergeGroups(root, namespace);// ww w. ja v a 2s . com mergeUsers(root, namespace); mergeAcls(root, namespace); }
From source file:org.artifactory.version.converter.SnapshotUniqueVersionConverter.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("useSnapshotUniqueVersions", ns); if (snapshotBehavior != null) { // rename the element snapshotBehavior.setName("snapshotVersionBehavior"); String repoKey = localRepo.getChildText("key", ns); log.debug(/*from w w w. ja v a2s .c o m*/ "Renamed element 'useSnapshotUniqueVersions' to " + "'snapshotVersionBehavior' for repo {}", repoKey); // change the element value if (snapshotBehavior.getText().equals("true")) { log.debug("Changed value 'true' to 'deployer' for repo {}", repoKey); snapshotBehavior.setText("deployer"); } else if (snapshotBehavior.getText().equals("false")) { log.debug("Changed value 'false' to 'non-unique' for repo {}", repoKey); snapshotBehavior.setText("non-unique"); } } } }
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);/*from w ww . jav a 2s .c o m*/ backupDir.setName("dir"); log.debug("Renamed 'backupDir' to 'dir'"); } 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.v100.RepositoriesKeysConverter.java
License:Open Source License
@Override @SuppressWarnings({ "unchecked" }) public void convert(Document doc) { Element root = doc.getRootElement(); Namespace ns = root.getNamespace(); // get all local repositories Element localReposWrapper = root.getChild("localRepositories", ns); List localRepos = localReposWrapper.getChildren(); List repos = new ArrayList(localRepos); // and add all remote repositories if any Element remoteReposWrapper = root.getChild("remoteRepositories", ns); if (remoteReposWrapper != null) { List remoteRepos = remoteReposWrapper.getChildren(); if (remoteRepos != null) { repos.addAll(remoteRepos);//from w w w . ja v a2 s . c o m } } for (Object repo : repos) { Element localRepo = (Element) repo; Element keyElement = localRepo.getChild("key", ns); String key = keyElement.getText(); Map<String, String> keys = ArtifactoryHome.get().getArtifactoryProperties().getSubstituteRepoKeys(); if (keys.containsKey(key)) { String newKey = keys.get(key); log.debug("Changing repository key from {} to {}", key, newKey); keyElement.setText(newKey); } } }
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"); }//from w w w . jav a 2 s. com } }
From source file:org.artifactory.version.converter.v120.AnonAccessNameConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Element oldAnnon = root.getChild(OLD_ANNON, root.getNamespace()); if (oldAnnon != null) { oldAnnon.setName(NEW_ANNON);/*w ww. j a v a2 s . co m*/ log.debug("Element {} found and converted", OLD_ANNON); } else { log.debug("Element {} not found", OLD_ANNON); } }
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;/*from www . j ava 2s . c o 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.AnnonAccessUnderSecurityConverter.java
License:Open Source License
private int findLastLocation(Element parent, String... elements) { for (int i = elements.length - 1; i >= 0; i--) { Element child = parent.getChild(elements[i], parent.getNamespace()); if (child != null) { return parent.indexOf(child); }//w w w. j av a2s. co m } return -1; }