Example usage for org.jdom2 Element setAttribute

List of usage examples for org.jdom2 Element setAttribute

Introduction

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

Prototype

public Element setAttribute(final String name, final String value, final Namespace ns) 

Source Link

Document

This sets an attribute value for this element.

Usage

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

License:Open Source License

protected void addEntry(Entry entry, Element parent) throws FeedException {
    Element eEntry = new Element("entry", getFeedNamespace());
    if (entry.getXmlBase() != null) {
        eEntry.setAttribute("base", entry.getXmlBase(), Namespace.XML_NAMESPACE);
    }/*  w ww.  j  av  a 2  s . com*/
    populateEntry(entry, eEntry);
    generateForeignMarkup(eEntry, (List) entry.getForeignMarkup());
    checkEntryConstraints(eEntry);
    generateItemModules(entry.getModules(), eEntry);
    parent.addContent(eEntry);
}

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

License:Open Source License

protected void populateChannel(Channel channel, Element eChannel) {
    super.populateChannel(channel, eChannel);
    if (channel.getUri() != null) {
        eChannel.setAttribute("about", channel.getUri(), getRDFNamespace());
    }/*w w  w .  j a va2s.  c  o m*/
    List items = channel.getItems();
    if (items.size() > 0) {
        Element eItems = new Element("items", getFeedNamespace());
        Element eSeq = new Element("Seq", getRDFNamespace());
        for (int i = 0; i < items.size(); i++) {
            Item item = (Item) items.get(i);
            Element eLi = new Element("li", getRDFNamespace());
            String uri = item.getUri();
            if (uri != null) {
                eLi.setAttribute("resource", uri, getRDFNamespace());
            }
            eSeq.addContent(eLi);
        }
        eItems.addContent(eSeq);
        eChannel.addContent(eItems);
    }
}

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

License:Open Source License

protected void populateItem(Item item, Element eItem, int index) {
    super.populateItem(item, eItem, index);
    String link = item.getLink();
    String uri = item.getUri();/*  ww  w. ja va2 s .  c  o m*/

    if (uri != null) {
        eItem.setAttribute("about", uri, getRDFNamespace());
    } else if (link != null) {
        eItem.setAttribute("about", link, getRDFNamespace());
    }

    Description description = item.getDescription();
    if (description != null) {
        eItem.addContent(generateSimpleElement("description", description.getValue()));
    }
    if (item.getModule(getContentNamespace().getURI()) == null && item.getContent() != null) {
        Element elem = new Element("encoded", getContentNamespace());
        elem.addContent(item.getContent().getValue());
        eItem.addContent(elem);
    }
}

From source file:com.tactfactory.harmony.generator.androidxml.manifest.ManifestElement.java

License:Open Source License

protected void addAttribute(final Element element, final Namespace ns, final String attributeName,
        final String attribute) {
    if (attribute != null) {
        element.setAttribute(attributeName, attribute, ns);
    }//  w w  w.  ja  v  a2s  .c  o  m
}

From source file:com.tactfactory.harmony.generator.androidxml.manifest.ManifestElement.java

License:Open Source License

protected void addAttribute(final Element element, final Namespace ns, final String attributeName,
        final Boolean attribute) {
    if (attribute != null) {
        element.setAttribute(attributeName, String.valueOf(attribute), ns);
    }//from  w  w  w.j  a  v a2  s .  com
}

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

License:Open Source License

/**
 * Add a permission to manifest./*from  ww  w . j  av a  2  s.c o  m*/
 * @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

/**
 * Sets the application-level theme.//from w  w w.  j a  va2 s  .co  m
 * @param theme The theme to set
 */
public void setApplicationTheme(String theme) {
    final Element rootNode = this.getDocument().getRootElement();
    final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID);
    final Element appElem = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION);
    appElem.setAttribute(ManifestConstants.ATTRIBUTE_THEME, theme, ns);
}

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

License:Open Source License

/**
 * Adds a service to the manifest.//  w  w  w .j  ava 2 s  .c  om
 * @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  . jav  a  2  s .  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.platform.android.updater.HomeActivityUpdaterAndroid.java

License:Open Source License

/**
 * Add a button to main.xml./*from w w w  .j  av  a  2 s. co  m*/
 * @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);
}