Example usage for org.jdom2 Element removeChild

List of usage examples for org.jdom2 Element removeChild

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:com.rometools.rome.io.impl.RSS094Generator.java

License:Open Source License

@Override
protected void populateItem(final Item item, final Element eItem, final int index) {
    super.populateItem(item, eItem, index);

    final Description description = item.getDescription();
    if (description != null && description.getType() != null) {
        final Element eDescription = eItem.getChild("description", getFeedNamespace());
        eDescription.setAttribute(new Attribute("type", description.getType()));
    }/*from www  .j  a  va2 s .c om*/
    eItem.removeChild("expirationDate", getFeedNamespace());
}

From source file:com.sun.syndication.io.impl.RSS094Generator.java

License:Open Source License

protected void populateItem(Item item, Element eItem, int index) {
    super.populateItem(item, eItem, index);

    Description description = item.getDescription();
    if (description != null && description.getType() != null) {
        Element eDescription = eItem.getChild("description", getFeedNamespace());
        eDescription.setAttribute(new Attribute("type", description.getType()));
    }/*from   w w w  .ja v  a2 s .c o m*/
    eItem.removeChild("expirationDate", getFeedNamespace());
}

From source file:fr.rt.acy.locapic.gps.TrackService.java

License:Open Source License

/**
 * Methode qui creer l'element JDOM pour la nouvelle localisation (<trkpt> pour track point)
 * Utilise la localisation passe en parametre et l'attribut de classe GSA (String)
 * @param loc - la nouvelle localisation
 * @return Element - element JDOM representant la position
 *///from  w  w  w .  j  a  v a2 s  . c  om
public Element createLocationElement(Location loc) {
    // Creation de notre objet Element contenant notre nouvelle position
    Element locElement = new Element("trkpt", ns);
    // Ajout des attributs lattitude et longitude
    locElement.setAttribute("lat", String.valueOf(loc.getLatitude()));
    locElement.setAttribute("lon", String.valueOf(loc.getLongitude()));

    // Nature du fix (position GPS) : 2d ou 3d, utilise pour l'integration ou non de l'altitude, du vdop (et donc du pdop)
    String locFix = "2d";
    /*
     * Ajout de l'altitude
     */
    if (loc.hasAltitude()) {
        Element locAltitude = new Element("ele", ns);
        locAltitude.setText(String.valueOf(loc.getAltitude()));
        locElement.addContent(locAltitude);
        locFix = "3d";
    }
    /*
     * Creation de la date
     */
    // Recup de la date au format POSIX (millisecondes depuis 1970)
    long posixTime = (long) loc.getTime();
    // Creation d'un objet Date a partir du temps POSIX
    Date date = new Date(posixTime);
    // Creation d'un format de date
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");
    // Creation d'un StringBuilder a partir de notre format et de notre date
    StringBuilder formattedDateBuilder = new StringBuilder(sdf.format(date));
    // On ajoute 2 caractere au builder
    formattedDateBuilder.append("Z"); // Z => indication de fuseau horaire // TODO verif
    // T (pour Time), permet de couper la chaine entre la date et l'heure
    formattedDateBuilder.insert(10, "T");
    // Creation de la chaine a partir du Builder
    String formattedDate = formattedDateBuilder.toString();
    //Log.v(TAG, "TIME => "+formattedDate);

    // Ajout de la date (element XML)
    Element locTime = new Element("time", ns);
    locTime.setText(formattedDate);
    locElement.addContent(locTime);

    /*
     * gestion du fix et de la precision DOP (NMEA, $GPGSA)
     */
    // Creation d'attributs de type Element, modifie ci apres
    Element locFixElem = new Element("fix", ns);
    Element locSats = new Element("sat", ns);
    Element locHdop = new Element("hdop", ns);
    Element locVdop = new Element("vdop", ns);
    Element locPdop = new Element("pdop", ns);
    // Creation d'attributs de type chaine pour les infos DOP
    String pdop = "";
    String hdop = "";
    String vdop = "";

    String nbSat = String.valueOf(loc.getExtras().getInt("satellites"));
    // Si on a une chaine GSA
    // chaine de test : GSA = "$GPGSA,A,2,19,28,14,18,27,22,31,39,,,,,1.7,1.0,1.3*35XX";
    if (GSA != null) {
        String[] gsarray = GSA.split(",");
        pdop = gsarray[gsarray.length - 3];
        hdop = gsarray[gsarray.length - 2];
        vdop = gsarray[gsarray.length - 1].substring(0, gsarray[gsarray.length - 1].length() - 5);
        // Si le fix dans la chaine vaut 2 ET que l'altitude de l'objet loc vaut 0.0 : on met 2d dans notre fix
        // Si le fix vaut 3, on met 3d dans notre fix
        // Tout ca parce que l'attribut hasAltitude de la classe Location n'a pas de valeurs pour les objets location retourne par le systeme de certains telephone (teste avec un Nexus 5)
        if ((gsarray[2].equals("2") && loc.getAltitude() == 0.0) || gsarray[2].equals("3"))
            locFix = gsarray[2] + "d";
        // On fait plus confiance a la chaine NMEA.GSA pour l'utilisation de l'altitude fournit par le locationListener
        // Si le fix dans la chaine GSA vaut 2d, on enleve l'altitude qui a ete prise dans l'objet loc et qui peut-etre une valeur bidon (ex : par defaut = 0m) 
        if (locFix.equals("2d"))
            locElement.removeChild("ele", ns);
    }
    /*
     * Ajout fix et DOP
     */
    locFixElem.setText(locFix);
    locElement.addContent(locFixElem);
    // Si nombre de satellite pas nul, on ajoute l'element <sat>n</sat>
    if (nbSat != null && !nbSat.equals("0")) {
        locSats.setText(nbSat);
        locElement.addContent(locSats);
    }
    // Si hdop pas egal a "", on ajoute l'element <hdop>x</hdop>
    if (!hdop.equals("")) {
        locHdop.setText(hdop);
        locElement.addContent(locHdop);
        // Si vdop pas egal a "" ET notre fix vaut 3d, on ajoute l'element <vdop>x</vdop> ...
        if (!vdop.equals("") && locFix.equals("3d")) {
            locVdop.setText(vdop);
            locElement.addContent(locVdop);
            // ... et l'element pdop donne par la chaine GSA ou calcule a partir de hdop et vdop
            if (!pdop.equals("")) {
                locPdop.setText(pdop);
            } else {
                // Si pas de PDOP mais qu'on a V et HDOP alors calcul de PDOP
                double hdopv = Float.parseFloat(hdop);
                double vdopv = Float.parseFloat(vdop);
                locPdop.setText(String.valueOf(Math.sqrt(hdopv * hdopv + vdopv * vdopv)));
            }
            locElement.addContent(locPdop);
        }
    }
    return locElement;
}

From source file:jodtemplate.pptx.postprocessor.StylePostprocessor.java

License:Apache License

private void cleanApPrElement(final Element apPr) {
    if (apPr != null) {
        apPr.removeChild(PPTXDocument.BUNONE_ELEMENT, getNamespace());
        apPr.removeChild(PPTXDocument.BUCHAR_ELEMENT, getNamespace());
        apPr.removeChild(PPTXDocument.BUAUTONUM_ELEMENT, getNamespace());
        apPr.removeChild(PPTXDocument.BUFONT_ELEMENT, getNamespace());
    }// w ww.  java 2 s .  co  m
}

From source file:org.artifactory.repo.virtual.interceptor.transformer.PomTransformer.java

License:Open Source License

/**
 * Create a central child removal method so that we can also track any changes made to the POM file
 *
 * @param toRemoveFrom  Element to remove a child from
 * @param childToRemove Name of child to remove from element
 * @param namespace     Namespace of current document
 *///from   w  w  w . j  a  v  a 2s .co  m
private void removeChild(Element toRemoveFrom, String childToRemove, Namespace namespace) {
    boolean removed = toRemoveFrom.removeChild(childToRemove, namespace);
    if (!pomChanged && removed) {
        pomChanged = true;
    }
}

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;//w ww.j a  v a2 s . c  om
    }

    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.v136.RepositoryTypeConverter.java

License:Open Source License

/**
 * Convert a &lt;type&gt; on a remote repository to a &lt;type&gt; on any repo - move the type after the description
 * if it exists./*from w w  w. j  a  v  a  2s.  co 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.v147.DefaultRepoLayoutConverter.java

License:Open Source License

private void removeRepoType(Element repositoryElement, boolean isRemote, Namespace namespace) {
    Element typeElement = repositoryElement.getChild("type", namespace);
    if (typeElement != null) {

        String repoKey = repositoryElement.getChild("key", namespace).getText();
        log.debug("Removing repository type definition from '{}'", repoKey);
        repositoryElement.removeChild("type", namespace);

        if (isRemote && "maven1".equals(typeElement.getText())) {

            Element remoteRepoLayoutRefElement = new Element("remoteRepoLayoutRef", namespace);
            remoteRepoLayoutRefElement.setText(RepoLayoutUtils.MAVEN_1_DEFAULT_NAME);

            log.debug("Appending Maven 1 remote repository layout reference to '{}'", repoKey);
            appendElementAfter(repositoryElement, remoteRepoLayoutRefElement, namespace,
                    "listRemoteFolderItems", "synchronizeProperties", "shareConfiguration",
                    "unusedArtifactsCleanupPeriodHours", "unusedArtifactsCleanupEnabled",
                    "remoteRepoChecksumPolicyType", "missedRetrievalCachePeriodSecs",
                    "failedRetrievalCachePeriodSecs", "retrievalCachePeriodSecs", "fetchSourcesEagerly",
                    "fetchJarsEagerly", "storeArtifactsLocally", "hardFail", "offline", "url");
        }/*  w ww .  j a v a2 s .com*/
    }
}

From source file:org.artifactory.version.converter.v147.UnusedArtifactCleanupSwitchConverter.java

License:Open Source License

@Override
public void convert(Document doc) {
    log.info("Starting the unused artifact cleanup switch conversion");

    Element rootElement = doc.getRootElement();
    Namespace namespace = rootElement.getNamespace();

    log.debug("Converting remote repositories");
    Element remoteRepositoriesElement = rootElement.getChild("remoteRepositories", namespace);
    if (remoteRepositoriesElement != null) {
        List<Element> remoteRepositoryElements = remoteRepositoriesElement.getChildren("remoteRepository",
                namespace);/*from  w  w w .j av a 2s  .c o m*/
        if (remoteRepositoryElements != null && !remoteRepositoryElements.isEmpty()) {

            for (Element remoteRepositoryElement : remoteRepositoryElements) {
                log.debug("Removing unused artifact cleanup switch from '{}'",
                        remoteRepositoryElement.getChild("key", namespace).getText());

                remoteRepositoryElement.removeChild("unusedArtifactsCleanupEnabled", namespace);
            }
        }
    }

    log.info("Ending the unused artifact cleanup switch conversion");
}

From source file:org.artifactory.version.converter.v160.SingleRepoTypeConverter.java

License:Open Source License

private void removeEnabledFieldsFromRepo(Element repo, boolean virtualRepo) {
    for (RepoType repoType : RepoType.values()) {
        if (repoType.equals(RepoType.P2)) {
            Element p2 = repo.getChild("p2", repo.getNamespace());
            if (p2 != null) {
                if (p2.getChild("enabled", p2.getNamespace()) != null) {
                    p2.removeChild("enabled", p2.getNamespace());
                }//from   ww  w. ja v  a  2s.  c  o  m
            }
        } else if (!repoType.equals(RepoType.YUM)) {
            //Special handle for YUM config as a repo can still be chosen to be of YUM type but with auto-calc off
            String field = resolveFieldName(repoType, virtualRepo);
            if (repo.getChild(field, repo.getNamespace()) != null) {
                repo.removeChild(field, repo.getNamespace());
            }
        } else {
            // If the repo type is YUM then we shouldn't remove any field
        }
    }
}