Example usage for org.apache.commons.configuration FileConfiguration getInt

List of usage examples for org.apache.commons.configuration FileConfiguration getInt

Introduction

In this page you can find the example usage for org.apache.commons.configuration FileConfiguration getInt.

Prototype

int getInt(String key);

Source Link

Document

Get a int associated with the given configuration key.

Usage

From source file:gda.images.camera.PixelToMicronConvertor.java

/**
 * Given a pixel location, returns the three element array of the microglide move required to move an object at that
 * point into the beam.//w w  w .j  a  v  a  2 s .  c om
 *
 * @param xPixel
 * @param yPixel
 * @return the micron movement required
 * @throws IOException
 * @throws ConfigurationException
 */
public double[] movePointToBeam(int xPixel, int yPixel) throws ConfigurationException, IOException {

    // reread the file in case the GUI panel has updated it
    beamDataStore.refreshBeamData();

    // get the current beam data
    BeamData currentBeamData = beamDataStore.getCurrentBeamData();
    String zoomLevelString = currentBeamData.zoomLevel.toString();

    // determine the calibration vectors for this zoom level and the beam's
    // location in pixels
    FileConfiguration configFile = LocalParameters.getXMLConfiguration(CONFIGFILENAME);

    // get the xyz coordinates of the top-left, top-right and bottom-left
    // corners of the image.
    // The movement will be based on those vectors, but normalised by the
    // size of the image in pixels.
    int tlX = configFile.getInt(zoomLevelString + ".tlX");
    int tlY = configFile.getInt(zoomLevelString + ".tlY");
    int tlZ = configFile.getInt(zoomLevelString + ".tlZ");
    int trX = configFile.getInt(zoomLevelString + ".trX");
    int trY = configFile.getInt(zoomLevelString + ".trY");
    int trZ = configFile.getInt(zoomLevelString + ".trZ");
    int blX = configFile.getInt(zoomLevelString + ".blX");
    int blY = configFile.getInt(zoomLevelString + ".blY");
    int blZ = configFile.getInt(zoomLevelString + ".blZ");

    // calculate the micron move in each axis:
    double x = ((currentBeamData.xCentre - xPixel) / IMAGEPIXELWIDTH) * (trX - tlX)
            + ((currentBeamData.yCentre - yPixel) / IMAGEPIXELHEIGHT) * (blX - tlX);
    double y = ((currentBeamData.xCentre - xPixel) / IMAGEPIXELWIDTH) * (trY - tlY)
            + ((currentBeamData.yCentre - yPixel) / IMAGEPIXELHEIGHT) * (blY - tlY);
    double z = ((currentBeamData.xCentre - xPixel) / IMAGEPIXELWIDTH) * (trZ - tlZ)
            + ((currentBeamData.yCentre - yPixel) / IMAGEPIXELHEIGHT) * (blZ - tlZ);

    return new double[] { x, y, z };

}

From source file:gda.jython.authoriser.FileAuthoriser.java

/**
 * @return Vector of strings of the entries in this file
 *//*  www .ja  v  a 2 s  .c o m*/
public UserEntry[] getEntries() {
    try {
        FileConfiguration configFile = openConfigFile();
        UserEntry[] entries = new UserEntry[0];

        @SuppressWarnings("rawtypes")
        Iterator i = configFile.getKeys();
        while (i.hasNext()) {
            String username = (String) i.next();
            if (!username.equals("")) {
                int level = configFile.getInt(username);
                entries = (UserEntry[]) ArrayUtils.add(entries,
                        new UserEntry(username, level, isLocalStaff(username)));
            }
        }

        return entries;

    } catch (Exception e) {
        logger.error(
                "Exception while trying to read file of list of user authorisation levels:" + e.getMessage());
        return null;
    }

}

From source file:gda.util.userOptions.UserOptions.java

public static UserOptions createFromTemplate(String configDir, String configName)
        throws ConfigurationException, IOException, Exception {
    FileConfiguration config = LocalParameters.getXMLConfiguration(configDir, configName, false, true);
    UserOptions options = new UserOptions();
    options.title = config.getString(propTitle);
    options.containsDefault = true;/*from w w  w.  ja  v  a2s.  c om*/
    Integer index = 0;
    while (true) {
        String tag = "options.option(" + index + ").";
        Object description = null;
        try {
            String keyName = config.getString(tag + propKeyName);
            /*
             * stop on last key
             */
            if (keyName == null)
                break;
            description = config.getProperty(tag + propDesc);
            Object type = config.getProperty(tag + propType);
            UserOption<? extends Object, ? extends Object> option;
            if (type != null && type.equals(typeBoolean)) {
                option = new UserOption<Object, Boolean>(description, config.getBoolean(tag + propDefValue));
            } else if (type != null && type.equals(typeString)) {
                option = new UserOption<Object, String>(description, config.getString(tag + propDefValue));
            } else if (type != null && type.equals(typeDouble)) {
                option = new UserOption<Object, Double>(description, config.getDouble(tag + propDefValue));
            } else if (type != null && type.equals(typeInteger)) {
                option = new UserOption<Object, Integer>(description, config.getInt(tag + propDefValue));
            } else {
                option = new UserOption<Object, Object>(description, config.getProperty(tag + propDefValue));
            }
            options.put(keyName, option);
            index++;
        } catch (Exception ex) {
            throw new Exception("Error reading option " + index, ex);
        }
    }
    return options;
}

From source file:org.glite.slcs.acl.impl.XMLFileAccessControlList.java

/**
 * Creates a list of {@link AccessControlRule}s loaded from the
 * {@link FileConfiguration}.//from  w  w w  .jav  a 2s.  c  o  m
 * 
 * @param config
 *            The ACL FileConfiguration object
 * @return A {@link List} of {@link AccessControlRule}s
 */
static private List createACLAccessControlRules(FileConfiguration config) {
    List accessControlRules = new LinkedList();
    // list all rules
    int i = 0;
    while (true) {
        String rulePrefix = "AccessControlRule(" + i + ")";
        i++;
        // get the name and id of the rule
        String ruleGroup = config.getString(rulePrefix + "[@group]");
        if (ruleGroup == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(rulePrefix + ": no more rules");
            }
            // no more ACL rule to read, exit while loop
            break;
        }
        int ruleId = config.getInt(rulePrefix + "[@id]");
        // create an empty rule
        AccessControlRule rule = new AccessControlRule(ruleId, ruleGroup);
        // get the attributes name-value for the rule
        List attributeNames = config.getList(rulePrefix + ".Attribute[@name]");
        if (attributeNames.isEmpty()) {
            LOG.error(rulePrefix + ": no attribute in rule, skipping...");
            // error, skipping
            continue;
        }
        AttributeDefinitions attributeDefinitions = AttributeDefinitionsFactory.getInstance();
        List attributeValues = config.getList(rulePrefix + ".Attribute");
        for (int j = 0; j < attributeNames.size(); j++) {
            String name = (String) attributeNames.get(j);
            String value = (String) attributeValues.get(j);
            Attribute attribute = attributeDefinitions.createAttribute(name, value);
            // add attribute to the rule
            rule.addAttribute(attribute);
        }
        // add the rule to the list
        if (LOG.isDebugEnabled()) {
            LOG.debug("adding rule in ACL: " + rule);
        }
        accessControlRules.add(rule);

    } // while

    return accessControlRules;
}