Example usage for org.jdom2 Element getAttributeValue

List of usage examples for org.jdom2 Element getAttributeValue

Introduction

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

Prototype

public String getAttributeValue(final String attname) 

Source Link

Document

This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.

Usage

From source file:de.openVJJ.plugins.PointsToLineOfBestFit.java

License:Open Source License

/**
 * for restoring from saved configuration
 * @param element XML Element// www .  j a  v a  2  s .  co  m
 */
public void setConfig(Element element) {
    Element myConfigElement = element.getChild(ELEMENT_NAME_PointsToLineOfBestFit_CONFIG);
    if (myConfigElement != null) {
        String val = myConfigElement.getAttributeValue("directionx");
        if (val != null) {
            xDirection = Boolean.parseBoolean(val);
        }
        val = myConfigElement.getAttributeValue("minLength");
        if (val != null) {
            minLength = Integer.parseInt(val);
        }
    }
    super.setConfig(element);
}

From source file:de.openVJJ.plugins.XuggleWebCam.java

License:Open Source License

/**
 * for restoring from saved configuration
 * @param element XML Element/*w  ww  .  j ava  2 s . co  m*/
 */
public void setConfig(Element element) {
    Element myConfigElement = element.getChild(ELEMENT_NAME_XuggleWebCam_CONFIG);
    if (myConfigElement != null) {
        String val = myConfigElement.getAttributeValue("driverName");
        if (val != null) {
            driverName = val;
        }
        val = myConfigElement.getAttributeValue("deviceName");
        if (val != null) {
            deviceName = val;
        }
        val = myConfigElement.getAttributeValue("framerateLimit");
        if (val != null) {
            framerateLimit = Integer.parseInt(val);
        }
    }
    super.setConfig(element);
}

From source file:de.relaunch64.popelganda.database.CustomScripts.java

License:Open Source License

/**
 * Returns the script name from the script at the position {@code index}.
 * /*www. ja v a2s . co m*/
 * @param pos the index position of the script which name should be fetched
 * @return the script name from the script at the position {@code index}
 */
public String getScriptName(int pos) {
    // retrieve element
    Element el = retrieveElement(pos);
    // check for valid value
    if (el != null) {
        return el.getAttributeValue(ATTR_NAME);
    }
    return null;
}

From source file:de.relaunch64.popelganda.database.CustomScripts.java

License:Open Source License

/**
 * Finds the script with the name {@code name} and returns its
 * data base index number.//from ww  w.  j  ava  2  s .c o m
 * 
 * @param name The name of the script that should be found.
 * @return The index number of the found script in the XML data base,
 * or -1 if no such script with the name {@code name} exists (or {@code name}
 * was {@code null} or empty).
 */
public int findScript(String name) {
    if (null == name || name.trim().isEmpty())
        return -1;
    // trim spaces
    name = name.trim();
    // create a list of all author elements from the author xml file
    try {
        List<Element> scriptList = scriptFile.getRootElement().getChildren();
        // and an iterator for the loop below
        Iterator<Element> iterator = scriptList.iterator();
        // counter for the return value if a found synonym matches the parameter
        int cnt = 0;

        while (iterator.hasNext()) {
            Element script = iterator.next();
            // if synonym-index-word matches the parameter string, return the position
            if (name.equalsIgnoreCase(script.getAttributeValue(ATTR_NAME))) {
                return cnt;
            }
            // else increase counter
            cnt++;
        }
        // if no author was found, return -1
        return -1;
    } catch (IllegalStateException e) {
        return -1;
    }
}

From source file:de.relaunch64.popelganda.database.CustomScripts.java

License:Open Source License

/**
 * Removes the script at the index {@code index}. Use {@link #findScript(java.lang.String) findScript()}
 * to find the index of a script by name.
 *  /*ww  w  .  java  2s  .c om*/
 * @param index the index of the script that should be removed
 * @return {@code true} if removal was successful
 */
public boolean removeScript(int index) {
    List<Element> children = scriptFile.getRootElement().getChildren();
    try {
        Element el = children.remove(index);
        if (el != null) {
            // reset document
            scriptFile = new Document(new Element(ROOT_NAME));
            // iterate and add remaining elements
            for (Element e : children)
                addScript(e.getAttributeValue(ATTR_NAME), e.getText());
            return true;
        }
    } catch (UnsupportedOperationException | IndexOutOfBoundsException | IllegalAddException ex) {
        return false;
    }
    return false;
}

From source file:de.relaunch64.popelganda.database.Settings.java

License:Open Source License

/**
 * Retrieves settings for the mainfont (the font used for the main-entry-textfield).
 * @param what (indicates, which font-characteristic we want to have. use following constants:<br>
 * - FONTNAME<br>//w  w w  .j a v  a  2s.  c  o m
 * - FONTSIZE<br>
 * - FONTCOLOR<br>
 * - FONTSTYLE<br>
 * - FONTWEIGHT<br>
 * @return the related font-information as string.
 */
public String getMainFont(int what) {
    Element el = root.getChild(SETTING_MAINFONT);
    String retval = "";
    if (el != null) {
        switch (what) {
        case FONTNAME:
            retval = el.getText();
            break;
        case FONTSIZE:
            retval = el.getAttributeValue("size");
            break;
        }
    }
    return retval;
}

From source file:de.relaunch64.popelganda.database.Settings.java

License:Open Source License

/**
 * Retrieves the main font as font-object.
 * @return the main-font as {@code Font} variable.
 *//*  ww  w  .ja v a  2  s . c o m*/
public Font getMainFont() {
    Element el = root.getChild(SETTING_MAINFONT);
    int fsize = Integer.parseInt(el.getAttributeValue("size"));
    return new Font(el.getText(), Font.PLAIN, fsize);
}

From source file:de.relaunch64.popelganda.database.Settings.java

License:Open Source License

public ArrayList<Object[]> getReopenFiles() {
    // get reopen files
    Element el = root.getChild(SETTING_REOPEN_FILES);
    // check if we have any
    if (null == el)
        return null;
    // create return value
    ArrayList<Object[]> rofiles = new ArrayList<>();
    // retrieve all children, each element representing one
    // file that should be re-opened
    List<Element> children = el.getChildren();
    // iterate all children
    for (Element e : children) {
        // get file path
        File f = new File(e.getText());
        // check if exists
        if (f.exists()) {
            // get compiler value
            String attr_c = e.getAttributeValue(ATTR_ASM);
            String attr_s = e.getAttributeValue(ATTR_SCRIPT);
            // init defaults
            Assembler assembler = Assemblers.ASM_KICKASSEMBLER;
            int script = -1;
            // check if we have compiler value
            try {
                if (attr_c != null)
                    assembler = Assemblers.byID(Integer.parseInt(attr_c));
                if (attr_s != null)
                    script = Integer.parseInt(attr_s);
            } catch (NumberFormatException ex) {
                assembler = Assemblers.ASM_KICKASSEMBLER;
                script = -1;/*ww  w . j a v  a  2 s  .  c o  m*/
            }
            // add compiler and filepath to return value
            rofiles.add(new Object[] { f, assembler, script });
        }
    }
    return rofiles;
}

From source file:de.smartics.maven.alias.domain.AliasesProcessor.java

License:Apache License

private AliasExtension createExtension(final Element extensionElement) {
    final AliasExtension.Builder builder = new AliasExtension.Builder();

    final Attribute env = extensionElement.getAttribute("env");
    if (env != null) {
        builder.withEnv(env.getValue());
    }/* w  ww . j  a  va2  s.c  om*/

    final String name = extensionElement.getChildTextNormalize("name", nsAlias);
    final String template = extensionElement.getChildTextNormalize("template", nsAlias);
    final String comment = readComment(extensionElement);

    final Element commentElement = extensionElement.getChild("comment", nsAlias);
    if (commentElement != null) {
        final String mnemonic = commentElement.getAttributeValue("mnemonic");
        builder.withMnemonic(mnemonic);
    }

    builder.withName(name).withTemplate(template).withComment(comment);

    appendApplyTos(extensionElement, builder);

    return builder.build();
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.AbstractArtifactClusionAdderV2.java

License:Apache License

public void addClusions(final Element matchElement) {
    if (matchElement != null) {
        final List<Element> clusionElements = matchElement.getChildren(elementId, NS);
        for (final Element clusionElement : clusionElements) {
            final ArtifactClusion clusion = new ArtifactClusion();
            String artifact = clusionElement.getAttributeValue("artifact");
            String[] split = split(artifact, ":", 2);
            final String groupId = split.length == 2 ? split[0] : null;
            final String artifactId = split.length == 2 ? split[1] : split[0];
            clusion.setGroupId(groupId);
            clusion.setArtifactId(artifactId);
            add(clusion);//from  w  w w.j  a  v  a2 s  .c  om
        }
    }
}