Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

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

Prototype

public List<Element> getChildren(final String cname) 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element with the given local name and belonging to no namespace, returned as Element objects.

Usage

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

License:Open Source License

@Override
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {
    final Item item = super.parseItem(rssRoot, eItem, locale);

    final Element eSource = eItem.getChild("source", getRSSNamespace());
    if (eSource != null) {
        final Source source = new Source();
        // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        final String url = eSource.getAttributeValue("url");
        source.setUrl(url);/*  ww w . j  a  v a 2s  .c o m*/
        source.setValue(eSource.getText());
        item.setSource(source);
    }

    // 0.92 allows one enclosure occurrence, 0.93 multiple just saving to write some code.
    // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
    final List<Element> eEnclosures = eItem.getChildren("enclosure");

    if (!eEnclosures.isEmpty()) {

        final List<Enclosure> enclosures = new ArrayList<Enclosure>();

        for (final Element eEnclosure : eEnclosures) {

            final Enclosure enclosure = new Enclosure();
            // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            final String url = eEnclosure.getAttributeValue("url");
            if (url != null) {
                enclosure.setUrl(url);
            }

            // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            final String length = eEnclosure.getAttributeValue("length");
            enclosure.setLength(NumberParser.parseLong(length, 0L));

            // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            final String type = eEnclosure.getAttributeValue("type");
            if (type != null) {
                enclosure.setType(type);
            }

            enclosures.add(enclosure);

        }

        item.setEnclosures(enclosures);
    }

    // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
    final List<Element> categories = eItem.getChildren("category");
    item.setCategories(parseCategories(categories));

    return item;
}

From source file:com.seleniumtests.util.squashta.TaScriptGenerator.java

License:Apache License

/**
 * Read a test element in an XML testNG file
 * @param test         the test element to read
 * @param testDefs      list of test definitions to update
 * @param testngFile   testNgFile read// w  ww  .  j  a  v a 2s.  com
 */
private void readTestTag(Element test, List<SquashTaTestDef> testDefs, File testngFile) {
    boolean cucumberTest = false;
    String cucumberNamedTest = "";
    boolean exclude = false;

    // search cucumber parameters among test parameters
    // does test specifies precise cucumber properties (cucumberTests / cucumberTags)
    for (Element param : test.getChildren("parameter")) {
        if ("cucumberTests".equals(param.getAttributeValue("name"))
                || "cucumberTags".equals(param.getAttributeValue("name"))) {
            cucumberTest = true;
            cucumberNamedTest = param.getAttributeValue("value");

            if (!cucumberNamedTest.isEmpty()) {
                break;
            }
        }
    }

    for (Element param : test.getChildren("parameter")) {
        if (XML_EXCLUDE.equals(param.getAttributeValue("name"))) {
            exclude = true;
        }
    }

    // is this test a cucumber test ? (calling specific runner)
    for (Element pack : test.getDescendants(new ElementFilter("package"))) {
        if (pack.getAttributeValue("name").contains("com.seleniumtests.core.runner")) {
            cucumberTest = true;
        }
    }

    if (!exclude) {
        if (cucumberTest) {
            testDefs.add(
                    new SquashTaTestDef(testngFile, test.getAttributeValue("name"), true, cucumberNamedTest));
        } else {
            testDefs.add(new SquashTaTestDef(testngFile, test.getAttributeValue("name"), false, ""));
        }
    }
}

From source file:com.seleniumtests.util.squashta.TaScriptGenerator.java

License:Apache License

/**
 * Search for tests in TestNG files//from  ww  w .  j  ava 2  s . c o  m
 * @param path
 * @param application
 * @return
 */
public List<SquashTaTestDef> parseTestNgXml() {

    // look for feature file into data folder
    File dir = Paths.get(srcPath, "data", application, "testng").toFile();
    if (!dir.exists()) {
        return new ArrayList<>();
    }

    File[] testngFiles = dir.listFiles((d, filename) -> filename.endsWith(".xml"));

    List<SquashTaTestDef> testDefs = new ArrayList<>();

    for (File testngFile : testngFiles) {

        Document doc;
        SAXBuilder sxb = new SAXBuilder();
        sxb.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        try {

            doc = sxb.build(testngFile);
        } catch (Exception e) {
            logger.error(String.format("Fichier %s illisible: %s", testngFile, e.getMessage()));
            return testDefs;
        }

        Element suite = doc.getRootElement();
        if (!"suite".equalsIgnoreCase(suite.getName())) {
            continue;
        }

        for (Element test : suite.getChildren("test")) {
            readTestTag(test, testDefs, testngFile);

        }
    }

    return testDefs;
}

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

License:Open Source License

protected Item parseItem(Element rssRoot, Element eItem) {
    Item item = super.parseItem(rssRoot, eItem);

    Element e = eItem.getChild("source", getRSSNamespace());
    if (e != null) {
        Source source = new Source();
        String url = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        source.setUrl(url);//from   w w w  .j  a va 2s  . c  o m
        source.setValue(e.getText());
        item.setSource(source);
    }

    // 0.92 allows one enclosure occurrence, 0.93 multiple
    // just saving to write some code.
    List eEnclosures = eItem.getChildren("enclosure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
    if (eEnclosures.size() > 0) {
        List enclosures = new ArrayList();
        for (int i = 0; i < eEnclosures.size(); i++) {
            e = (Element) eEnclosures.get(i);

            Enclosure enclosure = new Enclosure();
            String att = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            if (att != null) {
                enclosure.setUrl(att);
            }
            att = e.getAttributeValue("length");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            enclosure.setLength(NumberParser.parseLong(att, 0L));

            att = e.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            if (att != null) {
                enclosure.setType(att);
            }
            enclosures.add(enclosure);
        }
        item.setEnclosures(enclosures);
    }

    List eCats = eItem.getChildren("category");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
    item.setCategories(parseCategories(eCats));

    return item;
}

From source file:com.tactfactory.harmony.generator.androidxml.AttrsFile.java

License:Open Source License

/**
 * Constructor. /*from   w  ww . ja  va  2s. co m*/
 * 
 * @param adapter The adapter
 * @param xmlPath The xml path
 */
public AttrsFile(IAdapter adapter, String xmlPath) {
    super(adapter, xmlPath);

    Element root = this.getDocument().getRootElement();
    List<Element> styleables = root.getChildren(ELEMENT_STYLEABLE);
    for (Element styleable : styleables) {
        this.styleables.add(new Styleable(styleable));
    }

    List<Element> attrs = root.getChildren(ELEMENT_ATTR);
    for (Element attr : attrs) {
        this.attrs.add(new Styleable.Attr(attr));
    }
}

From source file:com.tactfactory.harmony.generator.androidxml.ColorsFile.java

License:Open Source License

/**
 * Constructor./*from   w  w w. java2 s.  co  m*/
 * 
 * @param adapter The adapter
 * @param dimenFilePath The file path
 */
public ColorsFile(IAdapter adapter, String dimenFilePath) {
    super(adapter, dimenFilePath);
    Element root = this.getDocument().getRootElement();
    List<Element> dimens = root.getChildren(ELEMENT_COLOR);
    for (Element dimen : dimens) {
        this.dimens.add(new Dimen(dimen));
    }

}

From source file:com.tactfactory.harmony.generator.androidxml.DimensFile.java

License:Open Source License

/**
 * Constructor.//  w ww  .java  2s .c om
 * 
 * @param adapter The adapter
 * @param dimenFilePath The file path
 */
public DimensFile(IAdapter adapter, String dimenFilePath) {
    super(adapter, dimenFilePath);
    Element root = this.getDocument().getRootElement();
    List<Element> dimens = root.getChildren(ELEMENT_DIMEN);
    for (Element dimen : dimens) {
        this.dimens.add(new Dimen(dimen));
    }

}

From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java

License:Open Source License

/**
 * Get the list of all the launcher activities names.
 * @return The launcher activities names
 *//*from  ww w. j  a v  a2 s. c o m*/
public List<String> getLauncherActivitiesNames() {
    // Load Root element
    final Element rootNode = this.getDocument().getRootElement();

    // Load Name space (required for manipulate attributes)
    final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID);

    List<String> result = new ArrayList<String>();
    List<Element> activities = this.getActivities();
    if (activities != null) {
        for (Element activity : activities) {
            List<Element> intentFilters = activity.getChildren(ManifestConstants.ELEMENT_INTENT_FILTER);

            if (intentFilters != null) {
                for (Element intentFilter : intentFilters) {
                    List<Element> categories = intentFilter.getChildren(ManifestConstants.ELEMENT_CATEGORY);

                    if (categories != null) {
                        for (Element category : categories) {
                            String categoryName = category.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME,
                                    ns);
                            if ("android.intent.category.LAUNCHER".equals(categoryName)) {
                                result.add(activity.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns));
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}

From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java

License:Open Source License

/**
 * Remove the launcher category from the intent filter 
 * of the given activity./*w w  w . j ava2  s .c o m*/
 * 
 * @param activityName The activity to remove the launcher category from
 */
public void removeLauncherIntentFilter(String activityName) {
    // Load Root element
    final Element rootNode = this.getDocument().getRootElement();

    // Load Name space (required for manipulate attributes)
    final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID);

    Element activity = this.findActivityNamed(activityName, ns);
    Element foundCategory = null;
    List<Element> intentFilters = activity.getChildren(ManifestConstants.ELEMENT_INTENT_FILTER);

    if (intentFilters != null) {
        for (Element intentFilter : intentFilters) {
            List<Element> categories = intentFilter.getChildren(ManifestConstants.ELEMENT_CATEGORY);

            if (categories != null) {
                for (Element category : categories) {
                    String categoryName = category.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns);
                    if ("android.intent.category.LAUNCHER".equals(categoryName)) {
                        foundCategory = category;
                    }
                }

                if (foundCategory != null) {
                    intentFilter.removeContent(foundCategory);
                }
            }
        }
    }
}

From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java

License:Open Source License

/**
 * Get the activities.//from  w  w w .  ja  v a2s .c o m
 * @return The list of activities.
 */
private List<Element> getActivities() {
    List<Element> result = null;
    Element appNode = this.getDocument().getRootElement().getChild(ManifestConstants.ELEMENT_APPLICATION);
    result = appNode.getChildren(ManifestConstants.ELEMENT_ACTIVITY);
    return result;
}