List of usage examples for org.jdom2 Element Element
public Element(final String name)
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); }/*w w w . j a v a2s . c o 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
@Override protected Element getDefaultRoot() { Namespace androidNs = Namespace.getNamespace("android", "http://schemas.android.com/apk/res/android"); Element rootElement = new Element("manifest"); rootElement.addNamespaceDeclaration(androidNs); rootElement.setAttribute("package", ApplicationMetadata.INSTANCE.getProjectNameSpace()); rootElement.setAttribute("versionCode", "1", androidNs); rootElement.setAttribute("versionName", "@string/app_version", androidNs); return rootElement; }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Add a permission to manifest.//ww w .j a va2 s. co 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
/** * Adds a service to the manifest./*from w ww . jav a 2 s . c o 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/* w ww. 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./*w w w. j av a2s .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.platform.winphone.updater.XmlProjectWinphone.java
License:Open Source License
public void open(String file) { this.file = file; if (TactFileUtils.exists(file)) { this.doc = XMLUtils.openXMLFile(file); } else {//from w ww. j a v a 2s. com Element rootElement = new Element(XML_ELEMENT_ROOT); this.doc = new Document(rootElement); } // Load Root element this.rootNode = doc.getRootElement(); }
From source file:com.tactfactory.harmony.platform.winphone.updater.XmlProjectWinphone.java
License:Open Source License
public void addCompileFile(String filename, String depends) { final Element newNode = new Element(XML_ELEMENT_COMPILE); newNode.setAttribute(XML_ATTRIBUT_INCLUDE, filename); if (depends != null) { Element childDepends = new Element(XML_ELEMENT_DEPENDENT); childDepends.addContent(depends); newNode.addContent(childDepends); }/*from w ww .jav a 2 s .c o m*/ Element itemGroup = this.findFirstItemGroup(XML_ELEMENT_COMPILE); this.removeIfExists(itemGroup, XML_ELEMENT_COMPILE, filename); itemGroup.addContent(newNode); }
From source file:com.tactfactory.harmony.platform.winphone.updater.XmlProjectWinphone.java
License:Open Source License
public void addApplicationDefinitionFile(String filename) { final Element newNode = new Element(XML_ELEMENT_APPLICATION); newNode.setAttribute(XML_ATTRIBUT_INCLUDE, filename); Element subtype = new Element(XML_ELEMENT_SUBTYPE); subtype.setText(XML_CONTENT_DESIGNER); Element generator = new Element(XML_ELEMENT_GENERATOR); generator.setText(XML_CONTENT_MSBUILD_COMPILE); newNode.addContent(subtype);// w ww . j a va2s . co m newNode.addContent(generator); Element itemGroup = this.findFirstItemGroup(XML_ELEMENT_APPLICATION); this.removeIfExists(itemGroup, XML_ELEMENT_APPLICATION, filename); itemGroup.addContent(newNode); }
From source file:com.tactfactory.harmony.platform.winphone.updater.XmlProjectWinphone.java
License:Open Source License
public void addPageFile(String filename) { final Element newNode = new Element(XML_ELEMENT_PAGE); newNode.setAttribute(XML_ATTRIBUT_INCLUDE, filename); Element subtype = new Element(XML_ELEMENT_SUBTYPE); subtype.setText(XML_CONTENT_DESIGNER); Element generator = new Element(XML_ELEMENT_GENERATOR); generator.setText(XML_CONTENT_MSBUILD_COMPILE); newNode.addContent(subtype);/*from ww w . j ava 2 s . com*/ newNode.addContent(generator); Element itemGroup = this.findFirstItemGroup(XML_ELEMENT_PAGE); this.removeIfExists(itemGroup, XML_ELEMENT_PAGE, filename); itemGroup.addContent(newNode); }