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

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

Introduction

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

Prototype

public void addProperty(String key, Object value) 

Source Link

Usage

From source file:ffx.autoparm.Keyword_poltype.java

/**
 * This method sets up configuration properties in the following precedence
 * order: 1.) Java system properties a.) -Dkey=value from the Java command
 * line b.) System.setProperty("key","value") within Java code.
 *
 * 2.) Structure specific properties (for example pdbname.properties)
 *
 * 3.) User specific properties (~/.ffx/ffx.properties)
 *
 * 4.) System wide properties (file defined by environment variable
 * FFX_PROPERTIES)/* w ww .  j  ava 2s  .c om*/
 *
 * 5.) Internal force field definition.
 *
 * @since 1.0
 * @param file a {@link java.io.File} object.
 * @return a {@link org.apache.commons.configuration.CompositeConfiguration}
 * object.
 */
public static CompositeConfiguration loadProperties(File file) {
    /**
     * Command line options take precedences.
     */
    CompositeConfiguration properties = new CompositeConfiguration();
    properties.addConfiguration(new SystemConfiguration());

    /**
     * Structure specific options are 2nd.
     */
    if (file != null && file.exists() && file.canRead()) {

        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String prmfilename = br.readLine().split(" +")[1];
            File prmfile = new File(prmfilename);
            if (prmfile.exists() && prmfile.canRead()) {
                properties.addConfiguration(new PropertiesConfiguration(prmfile));
                properties.addProperty("propertyFile", prmfile.getCanonicalPath());
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }

    //      /**
    //       * User specific options are 3rd.
    //       */
    //      String filename = System.getProperty("user.home") + File.separator
    //            + ".ffx/ffx.properties";
    //      File userPropFile = new File(filename);
    //      if (userPropFile.exists() && userPropFile.canRead()) {
    //         try {
    //            properties.addConfiguration(new PropertiesConfiguration(
    //                  userPropFile));
    //         } catch (Exception e) {
    //            logger.info("Error loading " + filename + ".");
    //         }
    //      }
    //
    //      /**
    //       * System wide options are 2nd to last.
    //       */
    //      filename = System.getenv("FFX_PROPERTIES");
    //      if (filename != null) {
    //         File systemPropFile = new File(filename);
    //         if (systemPropFile.exists() && systemPropFile.canRead()) {
    //            try {
    //               properties.addConfiguration(new PropertiesConfiguration(
    //                     systemPropFile));
    //            } catch (Exception e) {
    //               logger.info("Error loading " + filename + ".");
    //            }
    //         }
    //      }
    /**
     * Echo the interpolated configuration.
     */
    if (logger.isLoggable(Level.FINE)) {
        Configuration config = properties.interpolatedConfiguration();
        Iterator<String> i = config.getKeys();
        while (i.hasNext()) {
            String s = i.next();
            logger.fine("Key: " + s + ", Value: " + Arrays.toString(config.getList(s).toArray()));
        }
    }

    return properties;
}

From source file:ffx.utilities.Keyword.java

/**
 * This method sets up configuration properties in the following precedence
 * * order://from  www .  j  a  v  a  2 s .  com
 *
 * 1.) Structure specific properties (for example pdbname.properties)
 *
 * 2.) Java system properties a.) -Dkey=value from the Java command line b.)
 * System.setProperty("key","value") within Java code.
 *
 * 3.) User specific properties (~/.ffx/ffx.properties)
 *
 * 4.) System wide properties (file defined by environment variable
 * FFX_PROPERTIES)
 *
 * 5.) Internal force field definition.
 *
 * @since 1.0
 * @param file a {@link java.io.File} object.
 * @return a {@link org.apache.commons.configuration.CompositeConfiguration}
 * object.
 */
public static CompositeConfiguration loadProperties(File file) {
    /**
     * Command line options take precedence.
     */
    CompositeConfiguration properties = new CompositeConfiguration();

    /**
     * Structure specific options are first.
     */
    if (file != null) {
        String filename = file.getAbsolutePath();
        filename = org.apache.commons.io.FilenameUtils.removeExtension(filename);
        String propertyFilename = filename + ".properties";
        File structurePropFile = new File(propertyFilename);
        if (structurePropFile.exists() && structurePropFile.canRead()) {
            try {
                properties.addConfiguration(new PropertiesConfiguration(structurePropFile));
                properties.addProperty("propertyFile", structurePropFile.getCanonicalPath());
            } catch (ConfigurationException | IOException e) {
                logger.log(Level.INFO, " Error loading {0}.", filename);
            }
        } else {
            propertyFilename = filename + ".key";
            structurePropFile = new File(propertyFilename);
            if (structurePropFile.exists() && structurePropFile.canRead()) {
                try {
                    properties.addConfiguration(new PropertiesConfiguration(structurePropFile));
                    properties.addProperty("propertyFile", structurePropFile.getCanonicalPath());
                } catch (ConfigurationException | IOException e) {
                    logger.log(Level.INFO, " Error loading {0}.", filename);
                }
            }
        }
    }

    /**
     * Java system properties
     *
     * a.) -Dkey=value from the Java command line
     *
     * b.) System.setProperty("key","value") within Java code.
     */
    properties.addConfiguration(new SystemConfiguration());

    /**
     * User specific options are 3rd.
     */
    String filename = System.getProperty("user.home") + File.separator + ".ffx/ffx.properties";
    File userPropFile = new File(filename);
    if (userPropFile.exists() && userPropFile.canRead()) {
        try {
            properties.addConfiguration(new PropertiesConfiguration(userPropFile));
        } catch (ConfigurationException e) {
            logger.log(Level.INFO, " Error loading {0}.", filename);
        }
    }

    /**
     * System wide options are 2nd to last.
     */
    filename = System.getenv("FFX_PROPERTIES");
    if (filename != null) {
        File systemPropFile = new File(filename);
        if (systemPropFile.exists() && systemPropFile.canRead()) {
            try {
                properties.addConfiguration(new PropertiesConfiguration(systemPropFile));
            } catch (ConfigurationException e) {
                logger.log(Level.INFO, " Error loading {0}.", filename);
            }
        }
    }

    /**
     * Echo the interpolated configuration.
     */
    if (logger.isLoggable(Level.FINE)) {
        //Configuration config = properties.interpolatedConfiguration();
        Iterator<String> i = properties.getKeys();
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\n %-30s %s\n", "Property", "Value"));
        while (i.hasNext()) {
            String s = i.next();
            //sb.append(String.format(" %-30s %s\n", s, Arrays.toString(config.getList(s).toArray())));
            sb.append(String.format(" %-30s %s\n", s, Arrays.toString(properties.getList(s).toArray())));
        }
        logger.fine(sb.toString());
    }

    return properties;
}

From source file:com.germinus.easyconf.AggregatedProperties.java

private void addIncludedPropertiesSources(Configuration newConf, CompositeConfiguration loadedConf) {
    CompositeConfiguration tempConf = new CompositeConfiguration();
    tempConf.addConfiguration(prefixedSystemConfiguration);
    tempConf.addConfiguration(newConf);/*w ww . j a v a 2 s. co m*/
    tempConf.addConfiguration(systemConfiguration);
    tempConf.addProperty(Conventions.COMPANY_ID_PROPERTY, companyId);
    tempConf.addProperty(Conventions.COMPONENT_NAME_PROPERTY, componentName);
    String[] fileNames = tempConf.getStringArray(Conventions.INCLUDE_PROPERTY);
    for (int i = fileNames.length - 1; i >= 0; i--) {
        String iteratedFileName = fileNames[i];
        addPropertiesSource(iteratedFileName, loadedConf);
    }
}

From source file:de.chdev.artools.loga.lang.KeywordLoader.java

private List<Configuration> getAllConfigurations() {
    List<Configuration> localConfigurationList = new ArrayList<Configuration>();
    try {/*from   w  w  w. ja va  2  s  . c o  m*/
        // File path = new File("./config");

        // File[] listFiles = path.listFiles();

        FilenameFilter filter = new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                if (name.startsWith("keywords")) {
                    return true;
                } else {
                    return false;
                }
            }

        };

        /* TESTCODE */
        // Bundle location = Activator.getDefault().getBundle();
        // Enumeration entryPaths =
        // Activator.getDefault().getBundle().getEntryPaths("/");
        URL configEntry = Activator.getDefault().getBundle().getEntry("config");
        URL configPath = FileLocator.resolve(configEntry);
        File path = new File(configPath.getFile());
        // String[] list2 = resFile.list();
        // File file = new ConfigurationScope().getLocation().toFile();
        // String[] list = file.list();
        // IProject project = root.getProject();
        // IFolder files = project.getFolder("");
        // IResource[] members = files.members();
        /* TESTCODE END */

        String[] fileNames = path.list(filter);
        supportedLanguages.clear();

        for (String fileName : fileNames) {
            File fileObj = new File(path, fileName);
            CompositeConfiguration configuration = new CompositeConfiguration();

            PropertiesConfiguration keywords = new PropertiesConfiguration(fileObj);
            configuration.addConfiguration(keywords);
            configuration.addProperty("filename", fileName);
            localConfigurationList.add(configuration);
            supportedLanguages.add(configuration.getString("language.name"));
            nameConfigMap.put(configuration.getString("language.name"), configuration);
        }

        // for (String fileName : fileNames) {
        // CompositeConfiguration configuration = new
        // CompositeConfiguration();
        //
        // PropertiesConfiguration keywords = new PropertiesConfiguration(
        // "config/" + fileName);
        // configuration.addConfiguration(keywords);
        // configuration.addProperty("filename", fileName);
        // localConfigurationList.add(configuration);
        // }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return localConfigurationList;
}

From source file:ffx.potential.utils.PotentialsFileOpener.java

/**
 * At present, parses the PDB, XYZ, INT, or ARC file from the constructor
 * and creates MolecularAssembly and properties objects.
 *///  w w  w.j  a  v  a 2s  .  c o m
@Override
public void run() {
    int numFiles = allFiles.length;
    for (int i = 0; i < numFiles; i++) {
        File fileI = allFiles[i];
        Path pathI = allPaths[i];
        MolecularAssembly assembly = new MolecularAssembly(pathI.toString());
        assembly.setFile(fileI);
        CompositeConfiguration properties = Keyword.loadProperties(fileI);
        ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
        ForceField forceField = forceFieldFilter.parse();
        String patches[] = properties.getStringArray("patch");
        for (String patch : patches) {
            logger.info(" Attempting to read force field patch from " + patch + ".");
            CompositeConfiguration patchConfiguration = new CompositeConfiguration();
            try {
                patchConfiguration.addProperty("propertyFile", fileI.getCanonicalPath());
            } catch (IOException e) {
                logger.log(Level.INFO, " Error loading {0}.", patch);
            }
            patchConfiguration.addProperty("parameters", patch);
            forceFieldFilter = new ForceFieldFilter(patchConfiguration);
            ForceField patchForceField = forceFieldFilter.parse();
            forceField.append(patchForceField);
            if (RotamerLibrary.addRotPatch(patch)) {
                logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
            }
        }
        assembly.setForceField(forceField);
        if (new PDBFileFilter().acceptDeep(fileI)) {
            filter = new PDBFilter(fileI, assembly, forceField, properties);
        } else if (new XYZFileFilter().acceptDeep(fileI)) {
            filter = new XYZFilter(fileI, assembly, forceField, properties);
        } else if (new INTFileFilter().acceptDeep(fileI) || new ARCFileFilter().accept(fileI)) {
            filter = new INTFilter(fileI, assembly, forceField, properties);
        } else {
            throw new IllegalArgumentException(
                    String.format(" File %s could not be recognized as a valid PDB, XYZ, INT, or ARC file.",
                            pathI.toString()));
        }
        if (filter.readFile()) {
            if (!(filter instanceof PDBFilter)) {
                Utilities.biochemistry(assembly, filter.getAtomList());
            }
            filter.applyAtomProperties();
            assembly.finalize(true, forceField);
            //ForceFieldEnergy energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints());
            ForceFieldEnergy energy;
            if (nThreads > 0) {
                energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints(), nThreads);
            } else {
                energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints());
            }
            assembly.setPotential(energy);
            assemblies.add(assembly);
            propertyList.add(properties);

            if (filter instanceof PDBFilter) {
                PDBFilter pdbFilter = (PDBFilter) filter;
                List<Character> altLocs = pdbFilter.getAltLocs();
                if (altLocs.size() > 1 || altLocs.get(0) != ' ') {
                    StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ ");
                    for (Character c : altLocs) {
                        // Do not report the root conformer.
                        if (c == ' ') {
                            continue;
                        }
                        altLocString.append(format("(%s) ", c));
                    }
                    altLocString.append("]\n");
                    logger.info(altLocString.toString());
                }

                /**
                 * Alternate conformers may have different chemistry, so
                 * they each need to be their own MolecularAssembly.
                 */
                for (Character c : altLocs) {
                    if (c.equals(' ') || c.equals('A')) {
                        continue;
                    }
                    MolecularAssembly newAssembly = new MolecularAssembly(pathI.toString());
                    newAssembly.setForceField(assembly.getForceField());
                    pdbFilter.setAltID(newAssembly, c);
                    pdbFilter.clearSegIDs();
                    if (pdbFilter.readFile()) {
                        String fileName = assembly.getFile().getAbsolutePath();
                        newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                        filter.applyAtomProperties();
                        newAssembly.finalize(true, assembly.getForceField());
                        //energy = new ForceFieldEnergy(newAssembly, filter.getCoordRestraints());
                        if (nThreads > 0) {
                            energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints(), nThreads);
                        } else {
                            energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints());
                        }
                        newAssembly.setPotential(energy);
                        assemblies.add(newAssembly);
                    }
                }
            }
        } else {
            logger.warning(String.format(" Failed to read file %s", fileI.toString()));
        }
    }
    activeAssembly = assemblies.get(0);
    activeProperties = propertyList.get(0);
}

From source file:com.liferay.portal.configuration.easyconf.ClassLoaderAggregateProperties.java

private void _addIncludedPropertiesSources(Configuration newConfiguration,
        CompositeConfiguration loadedCompositeConfiguration) {

    CompositeConfiguration tempCompositeConfiguration = new CompositeConfiguration();

    tempCompositeConfiguration.addConfiguration(_prefixedSystemConfiguration);
    tempCompositeConfiguration.addConfiguration(newConfiguration);
    tempCompositeConfiguration.addConfiguration(_systemConfiguration);
    tempCompositeConfiguration.addProperty(Conventions.COMPANY_ID_PROPERTY, _companyId);
    tempCompositeConfiguration.addProperty(Conventions.COMPONENT_NAME_PROPERTY, _componentName);

    String[] fileNames = tempCompositeConfiguration.getStringArray(Conventions.INCLUDE_PROPERTY);
    //Modification start
    for (int i = fileNames.length - 1; i >= 0; i--) {
        String fileName = fileNames[i];
        //Modification end
        URL url = null;/*from  w  w w  .ja  va2 s  . c o m*/

        try {
            url = _classLoader.getResource(fileName);
        } catch (RuntimeException re) {
            if (fileName.startsWith("file:/")) {
                throw re;
            }

            fileName = "file:/".concat(fileName);

            url = _classLoader.getResource(fileName);
        }

        _addPropertiesSource(fileName, url, loadedCompositeConfiguration);
    }
}

From source file:cz.mzk.editor.server.config.EditorConfigurationImpl.java

public EditorConfigurationImpl() {
    File dir = new File(WORKING_DIR);
    if (!dir.exists()) {
        boolean mkdirs = dir.mkdirs();
        if (!mkdirs) {
            LOGGER.error("cannot create directory '" + dir.getAbsolutePath() + "'");
            throw new RuntimeException("cannot create directory '" + dir.getAbsolutePath() + "'");
        }/*from w  w w  .j  av  a 2 s  . com*/
    }
    File confFile = new File(CONFIGURATION);
    if (!confFile.exists()) {
        try {
            confFile.createNewFile();
        } catch (IOException e) {
            LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
            throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'");
        }
        FileOutputStream confFos;
        try {
            confFos = new FileOutputStream(confFile);
        } catch (FileNotFoundException e) {
            LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
            throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'");
        }
        try {
            try {
                new Properties().store(confFos, "configuration file for module metadata editor");
            } catch (IOException e) {
                LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
                throw new RuntimeException(
                        "cannot create configuration file '" + confFile.getAbsolutePath() + "'");
            }
        } finally {
            try {
                if (confFos != null)
                    confFos.close();
            } catch (IOException e) {
                LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
                throw new RuntimeException(
                        "cannot create configuration file '" + confFile.getAbsolutePath() + "'");
            } finally {
                confFos = null;
            }
        }
    }

    CompositeConfiguration constconf = new CompositeConfiguration();
    PropertiesConfiguration file = null;
    try {
        file = new PropertiesConfiguration(confFile);
    } catch (ConfigurationException e) {
        LOGGER.error(e.getMessage(), e);
        new RuntimeException("cannot read configuration");
    }
    file.setReloadingStrategy(new FileChangedReloadingStrategy());
    constconf.addConfiguration(file);
    constconf.setProperty(ServerConstants.EDITOR_HOME, WORKING_DIR);
    this.configuration = constconf;

    String hostname = configuration.getString(EditorClientConfiguration.Constants.HOSTNAME, "editor.mzk.cz");
    if (hostname.contains("://")) {
        hostname = hostname.substring(hostname.indexOf("://") + "://".length());
    }
    File imagesDir = new File(ServerConstants.DEFAULT_IMAGES_LOCATION + hostname + File.separator);
    if (!imagesDir.exists()) {
        boolean mkdirs = imagesDir.mkdirs();
        if (!mkdirs) {
            LOGGER.error("cannot create directory '" + imagesDir.getAbsolutePath() + "'");
            throw new RuntimeException("cannot create directory '" + imagesDir.getAbsolutePath() + "'");
        }
    }
    constconf.setProperty(ServerConstants.IMAGES_LOCATION,
            ServerConstants.DEFAULT_IMAGES_LOCATION + hostname + File.separator);
    EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration();
    for (Iterator it = environmentConfiguration.getKeys(); it.hasNext();) {
        String key = (String) it.next();
        Object value = environmentConfiguration.getProperty(key);
        key = key.replaceAll("_", ".");
        key = key.replaceAll("\\.\\.", "__");
        constconf.addProperty(key, value);
    }
}

From source file:ffx.ui.MainPanel.java

/**
 * Attempts to load from the supplied data structure
 *
 * @param data Data structure to load from
 * @param file Source file// w w w.  j  a v  a2  s . co m
 * @param commandDescription Description of the command that created this
 * file.
 * @return A thread-based UIDataConverter
 */
private UIDataConverter convertInit(Object data, File file, String commandDescription) {
    if (data == null) {
        return null;
    }

    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    // Create a Force Field.
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    String patches[] = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    ConversionFilter convFilter = null;

    // Decide what parser to use.
    if (biojavaDataFilter.accept(data)) {
        convFilter = new BiojavaFilter((Structure) data, newSystem, forceField, properties);
    } else {
        throw new IllegalArgumentException("Not a recognized data structure.");
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeConvFilter = convFilter;
    return new UIDataConverter(data, file, convFilter, this);
}

From source file:ffx.ui.MainPanel.java

/**
 * Attempts to load the supplied file//from w  ww .  j a  va  2s  .  co  m
 *
 * @param files Files to open
 * @param commandDescription Description of the command that created this
 * file.
 * @return a {@link java.lang.Thread} object.
 */
private UIFileOpener openInit(List<File> files, String commandDescription) {
    if (files == null) {
        return null;
    }
    File file = new File(FilenameUtils.normalize(files.get(0).getAbsolutePath()));
    // Set the Current Working Directory based on this file.
    setCWD(file.getParentFile());

    // Get "filename" from "filename.extension".
    String name = file.getName();
    String extension = FilenameUtils.getExtension(name);

    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();

    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    String patches[] = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    // Decide what parser to use.
    SystemFilter systemFilter = null;
    if (xyzFileFilter.acceptDeep(file)) {
        // Use the TINKER Cartesian Coordinate File Parser.
        systemFilter = new XYZFilter(files, newSystem, forceField, properties);
    } else if (intFileFilter.acceptDeep(file)) {
        // Use the TINKER Internal Coordinate File Parser.
        systemFilter = new INTFilter(files, newSystem, forceField, properties);
    } else {
        // Use the PDB File Parser.
        systemFilter = new PDBFilter(files, newSystem, forceField, properties);
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeFilter = systemFilter;
    //return new UIFileOpener(systemFilter, this);
    UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    return fileOpener;
}

From source file:ffx.ui.MainPanel.java

/**
 * Attempts to load the supplied file/*from w ww  .  j  a v a  2s .co m*/
 *
 * @param file File to open
 * @param commandDescription Description of the command that created this
 * file.
 * @return a {@link java.lang.Thread} object.
 */
private UIFileOpener openInit(File file, String commandDescription) {
    if (file == null || !file.isFile() || !file.canRead()) {
        return null;
    }
    file = new File(FilenameUtils.normalize(file.getAbsolutePath()));
    // Set the Current Working Directory based on this file.
    setCWD(file.getParentFile());

    // Get "filename" from "filename.extension".
    String name = file.getName();
    String extension = FilenameUtils.getExtension(name);

    /**
     * Run a Force Field X script.
     */
    if (extension.equalsIgnoreCase("ffx") || extension.equalsIgnoreCase("groovy")) {
        ModelingShell shell = getModelingShell();
        shell.runFFXScript(file);
        boolean shutDown = Boolean.parseBoolean(System.getProperty("ffx.shutDown", "true"));
        if (java.awt.GraphicsEnvironment.isHeadless() && shutDown) {
            exit();
        } else {
            return null;
        }
    }

    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    // Create a Force Field.
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    String patches[] = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    SystemFilter systemFilter = null;

    // Decide what parser to use.
    if (xyzFileFilter.acceptDeep(file)) {
        // Use the TINKER Cartesian Coordinate File Parser.
        systemFilter = new XYZFilter(file, newSystem, forceField, properties);
    } else if (intFileFilter.acceptDeep(file)) {
        // Use the TINKER Internal Coordinate File Parser.
        systemFilter = new INTFilter(file, newSystem, forceField, properties);
    } else {
        // Use the PDB File Parser.
        systemFilter = new PDBFilter(file, newSystem, forceField, properties);
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeFilter = systemFilter;
    UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    return fileOpener;
    //return new UIFileOpener(systemFilter, this);
}