List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname, final Namespace ns)
This returns the attribute value for the attribute with the given name and within the given Namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Remove the launcher category from the intent filter * of the given activity.//from w w w. j a v a2 s .c o m * * @param activityName The activity to remove the launcher category from */ public void removeLauncherIntentFilter(String activityName) { // Load Root element final Element rootNode = this.getDocument().getRootElement(); // Load Name space (required for manipulate attributes) final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID); Element activity = this.findActivityNamed(activityName, ns); Element foundCategory = null; List<Element> intentFilters = activity.getChildren(ManifestConstants.ELEMENT_INTENT_FILTER); if (intentFilters != null) { for (Element intentFilter : intentFilters) { List<Element> categories = intentFilter.getChildren(ManifestConstants.ELEMENT_CATEGORY); if (categories != null) { for (Element category : categories) { String categoryName = category.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns); if ("android.intent.category.LAUNCHER".equals(categoryName)) { foundCategory = category; } } if (foundCategory != null) { intentFilter.removeContent(foundCategory); } } } } }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Find the activity named "name"//w w w .ja v a 2 s. c o m * @param name The name * @param namespace The namespace * @return The found activity. null if none found. */ private Element findActivityNamed(String name, Namespace namespace) { Element result = null; List<Element> activities = this.getActivities(); for (final Element activity : activities) { // Load attribute value if (activity.hasAttributes() && activity.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, namespace).equals(name)) { result = activity; break; } } return result; }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Add a permission to manifest.//from w w w. j a v a2 s.c om * @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 w w .j a v a2 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 w w. ja v a 2s . 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.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Get all services from the manifest./*w w w . j a va 2 s . com*/ * @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.platform.android.updater.HomeActivityUpdaterAndroid.java
License:Open Source License
/** * Add a button to main.xml./*from w ww. java2 s . 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); }
From source file:com.tactfactory.harmony.updater.impl.XmlAndroid.java
License:Open Source License
@Override public void save() { // Clean code this.rootNode.sortChildren(new Comparator<Element>() { @Override/*from ww w . ja va 2s .c om*/ public int compare(final Element o1, final Element o2) { final String metaName1 = o1.getAttributeValue(XML_ELEMENT_NAME, XmlAndroid.this.namespace); final String metaName2 = o2.getAttributeValue(XML_ELEMENT_NAME, XmlAndroid.this.namespace); final TranslationMetadata meta1 = ApplicationMetadata.INSTANCE.getTranslates().get(metaName1); final TranslationMetadata meta2 = ApplicationMetadata.INSTANCE.getTranslates().get(metaName2); if (meta1 != null && meta2 != null) { final int groupScore = meta1.getGroup().getValue() - meta2.getGroup().getValue(); if (groupScore != 0) { return groupScore; } } return metaName1.compareToIgnoreCase(metaName2); } }); XMLUtils.writeXMLToFile(doc, this.file); }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MfencedReplacer.java
License:Apache License
private void replaceMfenced(final Element mfencedElement, final Element insideContent) { assert mfencedElement != null; // but insideContent can be null final Namespace ns = mfencedElement.getNamespace(); Element replacement = new Element(ROW, ns); String openStr = getProperty(DEFAULT_OPEN); String closeStr = getProperty(DEFAULT_CLOSE); if (openStr.isEmpty() || closeStr.isEmpty()) { LOGGER.warning("Default open or close fence not set"); }/*from w ww . j a va 2s .com*/ if (!isEnabled(FORCE_DEFAULT_OPEN)) { openStr = mfencedElement.getAttributeValue(OPEN_FENCE, openStr); } if (!isEnabled(FORCE_DEFAULT_CLOSE)) { closeStr = mfencedElement.getAttributeValue(CLOSE_FENCE, closeStr); } replacement.addContent(new Element(OPERATOR, ns).setText(openStr)); if (insideContent != null) { if (isEnabled(ADD_INNER_ROW)) { replacement.addContent(insideContent); } else { replacement.addContent(insideContent.removeContent()); } } replacement.addContent(new Element(OPERATOR, ns).setText(closeStr)); final Element parent = mfencedElement.getParentElement(); final int index = parent.indexOf(mfencedElement); parent.removeContent(index); if (isEnabled(ADD_OUTER_ROW)) { parent.addContent(index, replacement); } else { parent.addContent(index, replacement.removeContent()); } LOGGER.fine("Mfenced element converted"); }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MfencedReplacer.java
License:Apache License
private char[] getSeparators(final Element element) { assert element != null; if (isEnabled(FORCE_DEFAULT_SEPARATORS)) { return getProperty(DEFAULT_SEPARATORS).toCharArray(); }/* ww w.ja va 2 s . c om*/ return element.getAttributeValue(SEPARATORS, getProperty(DEFAULT_SEPARATORS)).trim().toCharArray(); }