List of usage examples for javax.naming ConfigurationException ConfigurationException
public ConfigurationException(String explanation)
From source file:uk.ac.ebi.metabolights.utils.isatab.IsaTabUtils.java
/** * Gets the config files from the current study archive folder * @return Name from the line "[Last Opened With Configuration]" in the i_Investigation.txt file, but only if we have the same config, otherwise return the string "default" * @throws IOException//from w w w . ja va2 s . com */ public static File getConfigurationFolderFromStudy(File isaTabFolder, File rootConfigFolder, String defaultConfig) throws IOException, ConfigurationException { logger.debug("Getting configuration folder for " + isaTabFolder.getAbsolutePath()); logger.debug("Root configuration folder " + rootConfigFolder.getAbsolutePath() + ". Default configuration is " + defaultConfig); logger.debug("Looking for lowercase line with text: " + FIELD_NAME_WITH_CONFIGURATION); File investigationFile = getInvestigationFile(isaTabFolder); BufferedReader br = new BufferedReader(new FileReader(investigationFile)); String configFileFolder = DEFAULT_CONFIGURATION_FOLDER; //Just in case we Could not find the config files used in the investigation file try { String line = br.readLine(); String lastPart = null; while (line != null) { if (line.toLowerCase().contains(FIELD_NAME_WITH_CONFIGURATION)) { String[] lineParts = line.split("\""); //The config file name is always separated with " if (lineParts.length > 1) configFileFolder = lineParts[1]; //Should be the name of the *submitters* config file directory //Only use the last part of the path, split on both / and \ if (configFileFolder.contains("/")) { lastPart = configFileFolder.substring(configFileFolder.lastIndexOf("/")); lastPart = lastPart.replace("/", ""); } if (configFileFolder.contains("\\")) { lastPart = configFileFolder.substring(configFileFolder.lastIndexOf("\\")); lastPart = lastPart.replace("\\", ""); } if (lastPart != null) configFileFolder = lastPart; if (configFileFolder.equals("")) configFileFolder = DEFAULT_CONFIGURATION_FOLDER; logger.debug("Configuration line found: " + line); break; //Nothing more to do in this loop } line = br.readLine(); } } finally { br.close(); } //Have to try to fix Windows path problems, example: C:softwareISAcreatorMetaboLightsConfigurationsMetaboLightsConfig20120129 if (configFileFolder.contains(":")) { //Cannot just check for C:, what about D: ?? //So some Windows paths have been used String[] winPath = configFileFolder.split("Configurations"); //Not elegant, but normally configs would be under the ISAcreator folder "/Configurations/" configFileFolder = winPath[1]; } // Build the final config folder File configFolder = new File(rootConfigFolder.getAbsoluteFile() + File.separator + configFileFolder); if (configFolder.exists()) { logger.debug("Configuration found: " + configFolder.getAbsolutePath()); return configFolder; } else { logger.debug("Configuration not found: " + configFolder.getAbsolutePath() + ", using default"); // Build the final config folder with default config configFolder = new File(rootConfigFolder.getAbsoluteFile() + File.separator + defaultConfig); if (configFolder.exists()) { return configFolder; } else { throw new ConfigurationException("Isatab configuration folder does not exists for the study (" + isaTabFolder.getName() + ").\nConfiguration: " + configFileFolder); } } }