Example usage for org.jdom2 Element getAttributeValue

List of usage examples for org.jdom2 Element getAttributeValue

Introduction

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

Prototype

public String getAttributeValue(final String attname) 

Source Link

Document

This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.

Usage

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/*from  w  w  w . j av  a  2s  .c om*/
 */
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.speedment.codgen.example.uml.TransformDelegator.java

License:Open Source License

default Type updateType(Element element) {
    final String name = element.getAttributeValue("name");
    final String pack = element.getAttributeValue("package");
    return TypeStore.INST.get(name).setName(pack + name);
}

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

License:Open Source License

protected WireFeed parseChannel(Element rssRoot) {
    Channel channel = (Channel) super.parseChannel(rssRoot);

    Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
    Element eCloud = eChannel.getChild("cloud", getRSSNamespace());
    if (eCloud != null) {
        Cloud cloud = new Cloud();
        String att = eCloud.getAttributeValue("domain");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        if (att != null) {
            cloud.setDomain(att);/* ww  w  .  j  a v  a2  s .c o  m*/
        }
        att = eCloud.getAttributeValue("port");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        if (att != null) {
            cloud.setPort(Integer.parseInt(att.trim()));
        }
        att = eCloud.getAttributeValue("path");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        if (att != null) {
            cloud.setPath(att);
        }
        att = eCloud.getAttributeValue("registerProcedure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        if (att != null) {
            cloud.setRegisterProcedure(att);
        }
        att = eCloud.getAttributeValue("protocol");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        if (att != null) {
            cloud.setProtocol(att);
        }
        channel.setCloud(cloud);
    }
    return channel;
}

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);//  w  ww  .  j a  va 2 s. c om
        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.sun.syndication.io.impl.RSS092Parser.java

License:Open Source License

protected List parseCategories(List eCats) {
    List cats = null;/*ww w  .  j a v a 2  s .co  m*/
    if (eCats.size() > 0) {
        cats = new ArrayList();
        for (int i = 0; i < eCats.size(); i++) {
            Category cat = new Category();
            Element e = (Element) eCats.get(i);
            String att = e.getAttributeValue("domain");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            if (att != null) {
                cat.setDomain(att);
            }
            cat.setValue(e.getText());
            cats.add(cat);
        }
    }
    return cats;
}

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

License:Open Source License

protected Item parseItem(Element rssRoot, Element eItem) {
    Item item = super.parseItem(rssRoot, eItem);
    Element e = eItem.getChild("pubDate", getRSSNamespace());
    if (e != null) {
        item.setPubDate(DateParser.parseDate(e.getText()));
    }//from  w w w .  j  av a  2s. co m
    e = eItem.getChild("expirationDate", getRSSNamespace());
    if (e != null) {
        item.setExpirationDate(DateParser.parseDate(e.getText()));
    }
    e = eItem.getChild("description", getRSSNamespace());
    if (e != null) {
        String type = e.getAttributeValue("type");
        if (type != null) {
            item.getDescription().setType(type);
        }
    }
    return item;
}

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

License:Open Source License

public Item parseItem(Element rssRoot, Element eItem) {
    Item item = super.parseItem(rssRoot, eItem);
    item.setExpirationDate(null);/*w ww  . j  a  v  a 2 s.  c  o m*/

    Element e = eItem.getChild("author", getRSSNamespace());
    if (e != null) {
        item.setAuthor(e.getText());
    }

    e = eItem.getChild("guid", getRSSNamespace());
    if (e != null) {
        Guid guid = new Guid();
        String att = e.getAttributeValue("isPermaLink");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        if (att != null) {
            guid.setPermaLink(att.equalsIgnoreCase("true"));
        }
        guid.setValue(e.getText());
        item.setGuid(guid);
    }

    e = eItem.getChild("comments", getRSSNamespace());
    if (e != null) {
        item.setComments(e.getText());
    }

    return item;
}

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

License:Open Source License

protected Description parseItemDescription(Element rssRoot, Element eDesc) {
    Description desc = super.parseItemDescription(rssRoot, eDesc);
    String att = eDesc.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
    if (att == null) {
        att = "text/html";
    }//  w w w  . j av  a 2  s  .  c  om
    desc.setType(att);
    return desc;
}

From source file:com.tactfactory.harmony.ProjectContext.java

License:Open Source License

/**
 * Extract Project NameSpace from AndroidManifest file.
 *
 * @param manifest Manifest File//from  w  w w . j  a v a  2s .  c  o  m
 * @return Project Name Space
 */
public static void loadNameSpaceFromManifest(final File manifest) {
    String result = null;
    SAXBuilder builder;
    Document doc;

    if (manifest.exists()) {
        // Make engine
        builder = new SAXBuilder();
        try {
            // Load XML File
            doc = builder.build(manifest);

            // Load Root element
            final Element rootNode = doc.getRootElement();

            // Get Name Space from package declaration
            result = rootNode.getAttributeValue("package");
            result = result.replaceAll("\\.", HarmonyContext.DELIMITER);
        } catch (final JDOMException e) {
            ConsoleUtils.displayError(e);
        } catch (final IOException e) {
            ConsoleUtils.displayError(e);
        }
    }

    if (result != null) {
        ApplicationMetadata.INSTANCE.setProjectNameSpace(result.trim());
    }
}

From source file:com.tactfactory.harmony.utils.XMLUtils.java

License:Open Source License

/**
 * Add a node to the XML node if it doesn't contains it already.
 * @param newNode The node to add// ww w . j a  va2s  .  co m
 * @param id The attribute name to compare
 * @param baseNode The node to add the new node to.
 * @return True if the node was added successfully.
 * False if the node already exists before.
 */
public static boolean addValue(final Element newNode, final String id, final Element baseNode) {

    Element findElement = null;

    // Debug Log
    ConsoleUtils.displayDebug("Update String : " + newNode.getAttributeValue(id));

    findElement = findNode(baseNode, newNode, id);

    // If not found Node, create it
    if (findElement == null) {
        baseNode.addContent(newNode);
        return true;
    } else {
        newNode.setText(findElement.getText());
        return false;
    }
}