Example usage for org.jdom2 Element removeChildren

List of usage examples for org.jdom2 Element removeChildren

Introduction

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

Prototype

public boolean removeChildren(final String cname, final Namespace ns) 

Source Link

Document

This removes all child elements (one level deep) with the given local name and belonging to the given namespace.

Usage

From source file:jodtemplate.pptx.preprocessor.FormatTagsPreprocessor.java

License:Apache License

@Override
public Document process(final Map<String, Object> context, final Document document, final Slide slide,
        final Resources resources, final Configuration configuration) {
    final IteratorIterable<Element> apElements = document
            .getDescendants(Filters.element(PPTXDocument.P_ELEMENT, getNamespace()));
    final List<Element> apElementsList = new ArrayList<>();
    while (apElements.hasNext()) {
        apElementsList.add(apElements.next());
    }//from  w  w  w.  j  a v a 2s .c  o m
    for (Element ap : apElementsList) {
        final List<Element> apChildrenList = ap.getChildren();
        if (apChildrenList.size() != 0) {
            final List<Element> arabrElementsListResult = processArAndABrElements(apChildrenList,
                    configuration.getParserFactory().createParser());
            int firstArElementIndex = ap.indexOf(ap.getChild(PPTXDocument.R_ELEMENT, getNamespace()));
            if (firstArElementIndex < 0) {
                firstArElementIndex = 0;
            }
            ap.removeChildren(PPTXDocument.R_ELEMENT, getNamespace());
            ap.removeChildren(PPTXDocument.BR_ELEMENT, getNamespace());
            ap.addContent(firstArElementIndex, arabrElementsListResult);
        }
    }
    return document;
}

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());
                }//www.  ja  v a  2 s  .  com
                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

private void mergeUsers(Element root, Namespace namespace) {
    Element child = root.getChild("users", namespace);
    List users = child.getChildren("user", namespace);
    Map<String, Element> usernameToGroups = Maps.newHashMap();
    if (users != null && !users.isEmpty()) {
        Iterator iterator = users.iterator();
        while (iterator.hasNext()) {
            Element userElement = (Element) iterator.next();
            Element userNameElement = userElement.getChild("username", namespace);
            String userName = userNameElement.getText();
            String lowerCaseUsername = userName.toLowerCase();
            userNameElement.setText(lowerCaseUsername);
            if (!usernameToGroups.containsKey(lowerCaseUsername)) {
                usernameToGroups.put(lowerCaseUsername, userElement);
                addGroupsToUser(userElement, userElement, namespace);
                copyEmails(namespace, usernameToGroups, userElement, lowerCaseUsername);
            } else {
                String isAdmin = userElement.getChild("admin").getText();
                Element existingUserElement = usernameToGroups.get(lowerCaseUsername);
                addGroupsToUser(existingUserElement, userElement, namespace);
                if (Boolean.parseBoolean(isAdmin)) {
                    usernameToGroups.put(lowerCaseUsername, userElement);
                }//w  ww  .j  a va2s. c o  m
                copyEmails(namespace, usernameToGroups, existingUserElement, lowerCaseUsername);
                addGroupsToUser(userElement, existingUserElement, namespace);
                iterator.remove();
            }
        }
    }
    root.removeChildren("users", namespace);
    Element usersElement = new Element("users", namespace);
    root.addContent(usersElement);
    for (Map.Entry<String, Element> elementEntry : usernameToGroups.entrySet()) {
        Element newUser = elementEntry.getValue();
        Element userElement = new Element("user", namespace);
        userElement.setContent(newUser.cloneContent());
        usersElement.addContent(userElement);
    }
}

From source file:org.mycore.mods.MCRExtractRelatedItemsEventHandler.java

License:Open Source License

private Element cloneRelatedItem(Element relatedItem) {
    Element mods = (Element) (relatedItem.clone());
    mods.setName("mods");
    mods.removeAttribute("type");
    mods.removeAttribute("href", MCRConstants.XLINK_NAMESPACE);
    mods.removeAttribute("type", MCRConstants.XLINK_NAMESPACE);
    mods.removeChildren("part", MCRConstants.MODS_NAMESPACE);
    return mods;/*w  w w  .  jav a  2 s  .  c o m*/
}