List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
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();// www.java 2 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.sun.syndication.io.impl.RSS20Generator.java
License:Open Source License
protected void populateChannel(Channel channel, Element eChannel) { super.populateChannel(channel, eChannel); String generator = channel.getGenerator(); if (generator != null) { eChannel.addContent(generateSimpleElement("generator", generator)); }//w ww. j a v a 2s.c o m int ttl = channel.getTtl(); if (ttl > -1) { eChannel.addContent(generateSimpleElement("ttl", String.valueOf(ttl))); } List categories = channel.getCategories(); for (int i = 0; i < categories.size(); i++) { eChannel.addContent(generateCategoryElement((Category) categories.get(i))); } }
From source file:com.sun.syndication.io.impl.RSS20Generator.java
License:Open Source License
public void populateItem(Item item, Element eItem, int index) { super.populateItem(item, eItem, index); Element eDescription = eItem.getChild("description", getFeedNamespace()); if (eDescription != null) eDescription.removeAttribute("type"); String author = item.getAuthor(); if (author != null) { eItem.addContent(generateSimpleElement("author", author)); }/*from w w w . ja v a 2s . c om*/ String comments = item.getComments(); if (comments != null) { eItem.addContent(generateSimpleElement("comments", comments)); } Guid guid = item.getGuid(); if (guid != null) { Element eGuid = generateSimpleElement("guid", guid.getValue()); if (!guid.isPermaLink()) { eGuid.setAttribute("isPermaLink", "false"); } eItem.addContent(eGuid); } }
From source file:com.sun.syndication.io.impl.SyModuleGenerator.java
License:Open Source License
public void generate(Module module, Element element) { SyModule syModule = (SyModule) module; if (syModule.getUpdatePeriod() != null) { Element updatePeriodElement = new Element("updatePeriod", SY_NS); updatePeriodElement.addContent(syModule.getUpdatePeriod()); element.addContent(updatePeriodElement); }/*from w w w.j a va 2s .c o m*/ Element updateFrequencyElement = new Element("updateFrequency", SY_NS); updateFrequencyElement.addContent(String.valueOf(syModule.getUpdateFrequency())); element.addContent(updateFrequencyElement); if (syModule.getUpdateBase() != null) { Element updateBaseElement = new Element("updateBase", SY_NS); updateBaseElement.addContent(DateParser.formatW3CDateTime(syModule.getUpdateBase())); element.addContent(updateBaseElement); } }
From source file:com.tactfactory.harmony.generator.androidxml.manifest.ManifestActivity.java
License:Open Source License
@Override public Element toElement(Namespace ns) { Element result = new Element(ELEMENT_ACTIVITY); this.addAttribute(result, ns, ATTRIBUTE_NAME, this.name); this.addAttribute(result, ns, ATTRIBUTE_THEME, this.theme); this.addAttribute(result, ns, ATTRIBUTE_LABEL, this.label); this.addAttribute(result, ns, ATTRIBUTE_EXPORTED, this.exported); if (this.intentFilters != null) { for (ManifestIntentFilter intentFilter : this.intentFilters) { result.addContent(intentFilter.toElement(ns)); }//from ww w . j ava 2 s . c om } return result; }
From source file:com.tactfactory.harmony.generator.androidxml.manifest.ManifestIntentFilter.java
License:Open Source License
@Override public Element toElement(Namespace ns) { Element result = new Element(ELEMENT_INTENT_FILTER); this.addAttribute(result, ns, ATTRIBUTE_LABEL, this.label); if (this.actionName != null) { Element actionElement = new Element(ELEMENT_ACTION); this.addAttribute(actionElement, ns, ATTRIBUTE_NAME, this.actionName); result.addContent(actionElement); }/*from w w w .j a v a 2s . co m*/ if (this.categoryName != null) { Element categoryElement = new Element(ELEMENT_CATEGORY); this.addAttribute(categoryElement, ns, ATTRIBUTE_NAME, this.categoryName); result.addContent(categoryElement); } if (this.data != null) { for (ManifestData data : this.data) { result.addContent(data.toElement(ns)); } } return result; }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
public void addActivity(ManifestActivity activity) { ConsoleUtils.displayDebug(String.format("Add activity %s to manifest.", activity.getName())); // Load Root element final Element rootNode = this.getDocument().getRootElement(); // Load Name space (required for manipulate attributes) final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID); // Find Application Node Element findActivity = null;/*from ww w .ja v a 2 s .c o m*/ // Find a element final Element applicationNode = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION); if (applicationNode != null) { findActivity = this.findActivityNamed(activity.getName(), ns); // If not found Node, create it if (findActivity == null) { applicationNode.addContent(activity.toElement(ns)); // Clean manifest applicationNode.sortChildren(ABC_COMPARATOR); } } }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Adds a service to the manifest./*from ww w .j av a2 s.co m*/ * @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//from w w w . jav a 2 s . co m * @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 a va2s. c o 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); }