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.tactfactory.harmony.generator.androidxml.ManifestUpdater.java

License:Open Source License

/**
 * Add a permission to manifest.//from w ww  .ja v a2s. com
 * @param permission The permission name
 */
public void addPermission(final String permission) {
    // Load Root element
    final Element rootNode = this.getDocument().getRootElement();

    // Load Name space (required for manipulate attributes)
    final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID);
    boolean setPerm = true;
    for (Element elem : rootNode.getChildren(ManifestConstants.ELEMENT_PERMISSION)) {
        if (elem.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns).equals(permission)) {
            setPerm = false;
            break;
        }
    }

    if (setPerm) {
        final Element permissionElem = new Element(ManifestConstants.ELEMENT_PERMISSION);

        permissionElem.setAttribute(ManifestConstants.ATTRIBUTE_NAME, permission, ns);

        rootNode.addContent(2, permissionElem);
    }
}

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

License:Open Source License

/**
 * Adds a service to the manifest./*from   w  ww.  j a va  2 s .  com*/
 * @param serviceName The service name
 * @param label The service label
 * @param exported If the service is exported
 */
public void addService(final String serviceName, final String label, final boolean exported) {

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

    // Load Name space (required for manipulate attributes)
    final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID);
    final Element appElem = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION);
    boolean setService = true;
    for (Element elem : appElem.getChildren(ManifestConstants.ELEMENT_SERVICE)) {
        if (elem.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns).equals(serviceName)) {
            setService = false;
            break;
        }
    }

    if (setService) {
        final Element permissionElem = new Element(ManifestConstants.ELEMENT_SERVICE);
        permissionElem.setAttribute(ManifestConstants.ATTRIBUTE_NAME, serviceName, ns);
        permissionElem.setAttribute(ManifestConstants.ATTRIBUTE_LABEL, label, ns);
        permissionElem.setAttribute(ManifestConstants.ATTRIBUTE_EXPORTED, String.valueOf(exported), ns);
        appElem.addContent(permissionElem);
    }
}

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

License:Open Source License

/**
 * Adds a content provider to the manifest.xml
 * @param name The name of the provider/* w w  w.j  av  a  2s  .  com*/
 * @param label The label of the provider
 * @param authorities The authorities of the provider
 * @param description The description of the provider
 * @param exported The exported state of the provider
 */
public void addProvider(final String name, final String label, final String authorities,
        final String description, final boolean exported) {
    // Load Root element
    final Element rootNode = this.getDocument().getRootElement();

    // Load Name space (required for manipulate attributes)
    final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID);
    final Element appElem = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION);
    boolean setProvider = true;
    for (Element elem : appElem.getChildren(ManifestConstants.ELEMENT_PROVIDER)) {
        if (elem.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns).equals(name)) {
            setProvider = false;
            break;
        }
    }

    if (setProvider) {
        final Element providerElem = new Element(ManifestConstants.ELEMENT_PROVIDER);
        providerElem.setAttribute(ManifestConstants.ATTRIBUTE_NAME, name, ns);
        providerElem.setAttribute(ManifestConstants.ATTRIBUTE_AUTHORITIES, authorities, ns);
        providerElem.setAttribute(ManifestConstants.ATTRIBUTE_LABEL, label, ns);
        providerElem.setAttribute(ManifestConstants.ATTRIBUTE_DESCRIPTION, description, ns);
        providerElem.setAttribute(ManifestConstants.ATTRIBUTE_EXPORTED, String.valueOf(exported), ns);

        appElem.addContent(providerElem);
    }
}

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

License:Open Source License

/**
 * Get all services from the manifest.//w  w w . ja v  a 2 s.c o  m
 * @return List of service name.
 */
public List<String> getServices() {
    List<String> result = new ArrayList<String>();

    // Load Root element
    final Element rootNode = this.getDocument().getRootElement();
    final Element appElem = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION);

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

    for (Element elem : appElem.getChildren(ManifestConstants.ELEMENT_SERVICE)) {
        result.add(elem.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns));
    }

    return result;
}

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

License:Open Source License

/**
 * Constructor.//from  w w  w. j  a  v a2  s. c  o m
 * 
 * @param adapter The adapter
 * @param styleFilePath The file path
 */
public StylesFile(IAdapter adapter, String styleFilePath) {
    super(adapter, styleFilePath);
    Element root = this.getDocument().getRootElement();
    List<Element> styles = root.getChildren(ELEMENT_STYLE);
    for (Element style : styles) {
        this.styles.add(new Style(style));
    }

}

From source file:com.tactfactory.harmony.platform.android.updater.HomeActivityUpdaterAndroid.java

License:Open Source License

/**
 * Add a button to main.xml./* ww w .  j  a  va 2s .  c om*/
 * @param text The displayed text
 * @param buttonId The button id
 */
private void addButtonToMainXML(final String text, final String buttonId) {
    String xmlFileName = this.adapter.getRessourceLayoutPath() + "main.xml";
    Document doc = XMLUtils.openXML(xmlFileName);
    Namespace androidNs = doc.getRootElement().getNamespace("android");
    Element linearL = doc.getRootElement().getChild("LinearLayout");

    boolean alreadyExists = false;

    for (Element element : linearL.getChildren("Button")) {
        if (element.getAttributeValue("id", androidNs).equals("@+id/" + buttonId)) {
            alreadyExists = true;
        }
    }

    if (!alreadyExists) {
        Element newButton = new Element("Button");
        newButton.setAttribute("id", "@+id/" + buttonId, androidNs);
        newButton.setAttribute("layout_width", "match_parent", androidNs);
        newButton.setAttribute("layout_height", "wrap_content", androidNs);
        newButton.setAttribute("text", text, androidNs);

        linearL.addContent(newButton);
    }

    XMLUtils.writeXMLToFile(doc, xmlFileName);
}

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

License:Open Source License

/**
 * Find a node in the given node./*from  www. j a  v a2s.  c om*/
 * @param baseNode The node in whom to search.
 * @param newNode The node to search.
 * @param id The attribute name used for the comparison
 * @return The found node or null if the node doesn't exists
 */
public static Element findNode(final Element baseNode, final Element newNode, final String id) {

    Element result = null;

    final List<Element> nodes = baseNode.getChildren(newNode.getName());

    // Look in the children nodes if one node
    // has the corresponding key/value couple
    for (final Element node : nodes) {
        if (node.hasAttributes() && node.getAttributeValue(id).equals(newNode.getAttributeValue(id))) {
            result = node;
        }
    }

    return result;
}

From source file:com.thoughtworks.go.domain.materials.mercurial.HgModificationSplitter.java

License:Apache License

private List<Modification> parseDOMTree(Document document) throws ParseException {
    List<Modification> modifications = new ArrayList<>();

    Element rootElement = document.getRootElement();
    List logEntries = rootElement.getChildren("changeset");
    for (Iterator iterator = logEntries.iterator(); iterator.hasNext();) {
        Element changeset = (Element) iterator.next();
        modifications.add(parseChangeset(changeset));
    }/*from   www . j  a v a 2 s . c om*/

    return modifications;
}

From source file:com.thoughtworks.go.util.SvnLogXmlParser.java

License:Apache License

private List<Modification> parseDOMTree(Document document, String path) throws ParseException {
    List<Modification> modifications = new ArrayList<>();

    Element rootElement = document.getRootElement();
    List logEntries = rootElement.getChildren("logentry");
    for (Iterator iterator = logEntries.iterator(); iterator.hasNext();) {
        Element logEntry = (Element) iterator.next();

        Modification modification = parseLogEntry(logEntry, path);
        if (modification != null) {
            modifications.add(modification);
        }/*from w  w w .ja  v a 2  s.  co  m*/
    }

    return modifications;
}

From source file:com.thoughtworks.go.util.SvnLogXmlParser.java

License:Apache License

private Modification parseLogEntry(Element logEntry, String path) throws ParseException {
    Element logEntryPaths = logEntry.getChild("paths");
    if (logEntryPaths == null) {
        /* Path-based access control forbids us from learning
         * details of this log entry, so skip it. */
        return null;
    }/*from www . ja va2 s  .co  m*/

    Date modifiedTime = convertDate(logEntry.getChildText("date"));
    String author = logEntry.getChildText("author");
    String comment = logEntry.getChildText("msg");
    String revision = logEntry.getAttributeValue("revision");

    Modification modification = new Modification(author, comment, null, modifiedTime, revision);

    List paths = logEntryPaths.getChildren("path");
    for (Iterator iterator = paths.iterator(); iterator.hasNext();) {
        Element node = (Element) iterator.next();
        if (underPath(path, node.getText())) {
            ModifiedAction action = convertAction(node.getAttributeValue("action"));
            modification.createModifiedFile(node.getText(), null, action);
        }
    }

    return modification;
}