Example usage for org.jdom2 Element getNamespace

List of usage examples for org.jdom2 Element getNamespace

Introduction

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

Prototype

public Namespace getNamespace(final String prefix) 

Source Link

Document

Returns the Namespace corresponding to the given prefix in scope for this element.

Usage

From source file:ca.nrc.cadc.vosi.TableReader.java

License:Open Source License

public TableDesc read(Reader reader) throws IOException, InvalidTableSetException {
    try {/*from w w  w  . j  av a  2  s . c  o m*/
        Document doc = parse(reader);
        Element root = doc.getRootElement();
        Namespace xsi = root.getNamespace("xsi");
        return toTable("default", root, xsi);
    } catch (JDOMException ex) {
        throw new InvalidTableSetException("invalid content", ex);
    }
}

From source file:ca.nrc.cadc.vosi.TableSetReader.java

License:Open Source License

private TapSchema toTapSchema(Document doc) {
    TapSchema ret = new TapSchema();
    Element root = doc.getRootElement();
    Namespace xsi = root.getNamespace("xsi");
    if ("tableset".equals(root.getName())) {
        // content is element-form unqualified
        List<Element> sels = root.getChildren("schema");
        for (Element se : sels) {
            String sn = se.getChildTextTrim("name");
            SchemaDesc sd = new SchemaDesc(sn);
            List<Element> tabs = se.getChildren("table");
            for (Element te : tabs) {
                TableDesc td = TableReader.toTable(sn, te, xsi);
                String tn = td.getTableName();
                sd.getTableDescs().add(td);
            }/*w  ww . j ava2  s.  c  o  m*/
            ret.getSchemaDescs().add(sd);
        }
    }
    return ret;
}

From source file:com.tactfactory.harmony.dependencies.android.sdk.AndroidSDKManager.java

License:Open Source License

/**
 * Find the latest SDK Tools link./*from  w ww.j a va  2s  . co m*/
 * 
 * @param platform The user platform
 * @return The latest SDK tools link
 */
public final String findLatestSDKToolsLink(final String platform) {
    String result = null;

    Document document = XMLUtils.getRemoteXML(SDK_URL + XML_REPO_FILE);
    Element root = document.getRootElement();
    Namespace ns = root.getNamespace("sdk");

    Element sdkTool = root.getChild("tool", ns);
    List<Element> sdkArchives = sdkTool.getChild("archives", ns).getChildren();

    for (Element sdkArchive : sdkArchives) {
        if (sdkArchive.getAttribute("os").getValue().equals(platform)) {
            result = SDK_URL + sdkArchive.getChildText("url", 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  w  ww .  jav  a2 s .  co 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

/**
 * Get the list of all the launcher activities names.
 * @return The launcher activities names
 *///from w  w  w.j  ava2s .  c om
public List<String> getLauncherActivitiesNames() {
    // Load Root element
    final Element rootNode = this.getDocument().getRootElement();

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

    List<String> result = new ArrayList<String>();
    List<Element> activities = this.getActivities();
    if (activities != null) {
        for (Element activity : activities) {
            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)) {
                                result.add(activity.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns));
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}

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   www . j a  v a  2  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

/**
 * Add a permission to manifest.//ww w  .java  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.//  w  w w  .ja  v  a  2 s  . c o  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./*from   w w w.  j  a  v  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.j  a v 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);
    }
}