Example usage for org.jdom2 Element indexOf

List of usage examples for org.jdom2 Element indexOf

Introduction

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

Prototype

@Override
    public int indexOf(final Content child) 

Source Link

Usage

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.  j  av a  2 s .  co m*/
        }
    }
}

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   w  ww  . j  a  va2 s. c o  m
 *
 * @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.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 w w  w . j  a va 2s .  c  om
    }

    log.info("Finished converting the indexer indexingIntervalHours property.");
}

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;// w  w  w  . j a v  a2  s  .co m
    }
    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  ww  . j av  a2s. co m
                    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.v147.DefaultRepoLayoutConverter.java

License:Open Source License

private int getIndexOfFirstFoundElement(Element repositoryElement, Namespace namespace,
        String... elementNames) {
    for (String elementName : elementNames) {
        Element child = repositoryElement.getChild(elementName, namespace);
        if (child != null) {
            return repositoryElement.indexOf(child);
        }/* w ww .j  a  va 2s .co m*/
    }

    return -1;
}

From source file:org.artifactory.version.converter.v153.VirtualCacheCleanupConverter.java

License:Open Source License

@Override
public void convert(Document doc) {
    log.info("Adding default virtual cache cleanup");
    Element rootElement = doc.getRootElement();
    Namespace namespace = rootElement.getNamespace();

    if (rootElement.getChild("virtualCacheCleanupConfig") != null)
        return;/*from  www  .  j a  va 2  s .  c  o  m*/
    Element cleanupConfig = rootElement.getChild("cleanupConfig", namespace);
    Element virtualCacheCleanupConfig = new Element("virtualCacheCleanupConfig", namespace);
    Element cronExp = new Element("cronExp", namespace);
    cronExp.setText("0 12 5 * * ?");
    virtualCacheCleanupConfig.addContent(cronExp);
    rootElement.addContent(rootElement.indexOf(cleanupConfig) + 1, virtualCacheCleanupConfig);
}

From source file:org.jreserve.gui.wrapper.jdom.JDomUtil.java

License:Open Source License

public static String getPath(Element e) {
    String path = "";
    while (e != null) {
        String name = e.getName();
        Element parent = e.getParentElement();
        if (parent != null)
            name += "[" + (parent.indexOf(e) + 1) + "]";

        if (path.length() > 0)
            path += "/";
        path += name;//  w w w. j a va2s .  co  m

        e = parent;
    }
    return null;
}

From source file:org.kdp.word.transformer.ListParagraphTransformer.java

License:Apache License

private void processListItemBatch(Context context, Element parent, List<Element> listItems) {
    boolean ordered = false;
    for (Element el : listItems) {
        removeNestedSpanElements(el);/* ww w. j a v a  2s.co  m*/
        normalizeListItemText(el);
        ordered = processItemMarker(el);
        el.getAttributes().clear();
    }
    Element firstItem = listItems.get(0);
    int index = parent.indexOf(firstItem);
    for (Element el : listItems) {
        parent.removeContent(el);
    }
    JDOMFactory factory = context.getJDOMFactory();
    Element ul = factory.element(ordered ? "ol" : "ul");
    for (Element el : listItems) {
        Element li = factory.element("li");
        li.setAttribute("class", "MsoListParagraph");
        for (Content co : el.getContent()) {
            li.addContent(co.clone());
        }
        ul.addContent(li);
    }
    parent.addContent(index, ul);
}

From source file:org.mycore.frontend.editor.MCREditorDefReader.java

License:Open Source License

/**
 * Recursively removes include elements that are direct or indirect children
 * of the given container element and replaces them with the included
 * resource. Includes that may be contained in included resources are
 * recursively resolved, too./*  ww  w.  j  a v  a 2  s .  c  o  m*/
 *
 * @param element
 *            The element where to start resolving includes
 */
private boolean resolveIncludes(Element element) {
    boolean replaced = false;

    String ref = element.getAttributeValue("ref", "");
    ref = tokenSubstitutor.substituteTokens(ref);

    if (element.getName().equals("include")) {
        String uri = element.getAttributeValue("uri");
        if (uri != null) {
            uri = tokenSubstitutor.substituteTokens(uri);
            LOGGER.info("Including " + uri + (ref.length() > 0 ? "#" + ref : ""));
            Element parent = element.getParentElement();
            int pos = parent.indexOf(element);

            Element container = MCRURIResolver.instance().resolve(uri);
            List<Content> found;

            if (ref.length() == 0) {
                found = container.cloneContent();
            } else {
                found = findContent(container, ref);
                ref = "";
            }
            replaced = true;
            parent.addContent(pos, found);
            element.detach();
        }
    } else {
        String id = element.getAttributeValue("id", "");
        if (id.length() > 0) {
            id2component.put(id, element);
        }

        setDefaultAttributes(element);
        resolveChildren(element);
    }

    if (ref.length() > 0) {
        referencing2ref.put(element, ref);
    }
    return replaced;
}