Example usage for org.apache.commons.configuration CompositeConfiguration getString

List of usage examples for org.apache.commons.configuration CompositeConfiguration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration CompositeConfiguration getString.

Prototype

public String getString(String key, String defaultValue) 

Source Link

Usage

From source file:ffx.xray.parsers.MTZFilter.java

/**
 * {@inheritDoc}/*from  w ww  .j a v a  2  s .  com*/
 */
@Override
public ReflectionList getReflectionList(File mtzFile, CompositeConfiguration properties) {
    ByteOrder byteOrder = ByteOrder.nativeOrder();
    FileInputStream fileInputStream;
    DataInputStream dataInputStream;
    try {
        fileInputStream = new FileInputStream(mtzFile);
        dataInputStream = new DataInputStream(fileInputStream);

        byte headerOffset[] = new byte[4];
        byte bytes[] = new byte[80];
        int offset = 0;

        // Eat "MTZ" title.
        dataInputStream.read(bytes, offset, 4);
        String mtzstr = new String(bytes);

        // Header offset.
        dataInputStream.read(headerOffset, offset, 4);

        // Machine stamp.
        dataInputStream.read(bytes, offset, 4);
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
        int stamp = byteBuffer.order(ByteOrder.BIG_ENDIAN).getInt();
        String stampstr = Integer.toHexString(stamp);
        switch (stampstr.charAt(0)) {
        case '1':
        case '3':
            if (byteOrder.equals(ByteOrder.LITTLE_ENDIAN)) {
                byteOrder = ByteOrder.BIG_ENDIAN;
            }
            break;
        case '4':
            if (byteOrder.equals(ByteOrder.BIG_ENDIAN)) {
                byteOrder = ByteOrder.LITTLE_ENDIAN;
            }
            break;
        }

        byteBuffer = ByteBuffer.wrap(headerOffset);
        int headerOffsetI = byteBuffer.order(byteOrder).getInt();

        // skip to header and parse
        dataInputStream.skipBytes((headerOffsetI - 4) * 4);

        for (Boolean parsing = true; parsing; dataInputStream.read(bytes, offset, 80)) {
            mtzstr = new String(bytes);
            parsing = parseHeader(mtzstr);
        }
    } catch (EOFException e) {
        String message = " MTZ end of file reached.";
        logger.log(Level.WARNING, message, e);
        return null;
    } catch (IOException e) {
        String message = " MTZ IO exception.";
        logger.log(Level.WARNING, message, e);
        return null;
    }

    // column identifiers
    foString = sigFoString = rFreeString = null;
    if (properties != null) {
        foString = properties.getString("fostring", null);
        sigFoString = properties.getString("sigfostring", null);
        rFreeString = properties.getString("rfreestring", null);
    }
    h = k = l = fo = sigFo = rFree = -1;
    fPlus = sigFPlus = fMinus = sigFMinus = rFreePlus = rFreeMinus = -1;
    fc = phiC = -1;
    boolean print = false;
    parseColumns(print);
    parseFcColumns(print);

    if (fo < 0 && fPlus < 0 && sigFo < 0 && sigFPlus < 0 && fc < 0 && phiC < 0) {
        logger.info(" The MTZ header contains insufficient information to generate the reflection list.");
        logger.info(" For non-default column labels set fostring/sigfostring in the properties file.");
        return null;
    }

    Column column;
    if (fo > 0) {
        column = (Column) columns.get(fo);
    } else if (fPlus > 0) {
        column = (Column) columns.get(fPlus);
    } else {
        column = (Column) columns.get(fc);
    }
    Dataset dataSet = (Dataset) dataSets.get(column.id - dsetOffset);

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(format("\n Reading %s\n\n", mtzFile.getName()));
        sb.append(format(" Setting up reflection list based on MTZ file.\n"));
        sb.append(format("  Space group number: %d (name: %s)\n", spaceGroupNum,
                SpaceGroup.spaceGroupNames[spaceGroupNum - 1]));
        sb.append(format("  Resolution:         %8.3f\n", 0.999999 * resHigh));
        sb.append(format("  Cell:               %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", dataSet.cell[0],
                dataSet.cell[1], dataSet.cell[2], dataSet.cell[3], dataSet.cell[4], dataSet.cell[5]));
        logger.info(sb.toString());
    }

    Crystal crystal = new Crystal(dataSet.cell[0], dataSet.cell[1], dataSet.cell[2], dataSet.cell[3],
            dataSet.cell[4], dataSet.cell[5], SpaceGroup.spaceGroupNames[spaceGroupNum - 1]);

    double sampling = 0.6;
    if (properties != null) {
        sampling = properties.getDouble("sampling", 0.6);
    }
    Resolution resolution = new Resolution(0.999999 * resHigh, sampling);

    return new ReflectionList(crystal, resolution, properties);
}

From source file:ro.nextreports.server.web.ApplicationLoaderListener.java

private void config() {

    LOG.info("NextReports Server " + ReleaseInfo.getVersion() + " starting ... ");

    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {/*from   w  w w  .jav a  2 s  . c  om*/
        config.addConfiguration(new PropertiesConfiguration(getClass().getResource("/nextserver.properties")));
    } catch (ConfigurationException e) {
        // TODO
        e.printStackTrace();
    }

    File defaultNextServerHomeFolder = new File(System.getProperty("user.home"), ".nextserver");
    String defaultNextServerHome = defaultNextServerHomeFolder.getPath();
    String nextServerHome = config.getString("nextserver.home", defaultNextServerHome);
    LOG.info("nextserver.home = " + nextServerHome);

    String demo = System.getProperty("DEMO");
    LOG.info("DEMO=" + demo);
    boolean installWithDemo = Boolean.valueOf(demo);

    File nextServerHomeFolder = new File(nextServerHome);
    if (!nextServerHomeFolder.exists()) {
        try {
            if (installWithDemo) {
                deployDemoData(nextServerHome);
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Create nextserver home folder: '" + nextServerHomeFolder + "'");
                }
                FileUtils.forceMkdir(nextServerHomeFolder);
            }
        } catch (IOException e) {
            // TODO
            e.printStackTrace();
        }
    }

    System.setProperty("nextserver.home", nextServerHome);

    //      File defaultJaspersHomeFolder = new File(nextServerHome, "jaspers");
    //      String defaultJaspersHome = defaultJaspersHomeFolder.getPath();
    //      String jaspersHome = config.getString("jaspers.home", defaultJaspersHome);
    //      System.setProperty("jaspers.home", jaspersHome);
    //      if (LOG.isDebugEnabled()) {
    //         LOG.debug("jaspers.home = " + jaspersHome);         
    //      }      

    // indexing.file
    ClassPathResource classPathResource = new ClassPathResource("indexing.xml");
    String indexingFile = null;
    try {
        indexingFile = classPathResource.getFile().getAbsolutePath();
    } catch (IOException e) {
        // TODO
        e.printStackTrace();
    }
    System.setProperty("indexing.file", indexingFile);
    if (LOG.isDebugEnabled()) {
        LOG.debug("indexing.file = " + indexingFile);
    }

    //      String baseUrl = config.getString("nextserver.baseUrl");
    //      String reportsUrl = config.getString("reports.url");
    //      if (LOG.isDebugEnabled()) {
    //         LOG.debug("nextserver.baseUrl = " + baseUrl);
    //         LOG.debug("reports.url = " + reportsUrl);
    //      }
}

From source file:umich.ms.batmass.gui.viewers.map2d.components.Map2DZoomLevel.java

private RangeNormalizer createNormalizer(double minNonZero, double max) {
    double curRange = max - minNonZero;

    CompositeConfiguration config = Map2DOptions.getInstance().getConfig();
    // TODO: the default value is set here, in case the user config is messed up
    String normalizerName = config.getString("intensityNormalizer", "LOG");

    RangeNormalizers norm = RangeNormalizers.valueOf(normalizerName);
    RangeNormalizer rangeNormalizer = norm.getRangeNormalizer();
    rangeNormalizer.configure(max, minNonZero, targetRange);

    return rangeNormalizer;
    //        return new RangeNormalizerImplDoNothing();

    // TODO: replaced this version, which was not doing any normalization in the intensity
    // range was smaller than the defined threshold, with the above two lines (i.e. the
    // normalization is always executed)
    // It worked better this way for metabolomics Agilent data, where we had signals
    // of very small and very large intensity. Don't know why, though...
    //        if (curRange <= targetRange) {
    //            // TODO: exp int this case
    //            // if the range is smaller than target, then find exp base
    //            return new RangeNormalizerImplDoNothing();
    //        } else {
    //            // if the range is larger than target, then find log base
    //            double base = FastMath.exp((FastMath.log(max) - FastMath.log(minNonZero)) / targetRange);
    //            return new RangeNormalizerImplLog(base);
    //        }//from  w ww  .j a  v a 2s  .  c om

}