| 6 | import java.util.Properties; |
| 7 | |
| 8 | public class Config { |
| 9 | |
| 10 | private static final String CONFIG_FILENAME = "loc.cfg"; // The name of the config file |
| 11 | |
| 12 | private static final String X_API_KEY = "CONFIG.X_API_KEY"; // API Authentication key |
| 13 | private static final String RESPONSE_FORMAT = "CONFIG.RESPONSE_FORMAT"; // xml | json |
| 14 | |
| 15 | private static final String STORE_RESPONSE = "CONFIG.STORE_RESPONSE"; // true | false |
| 16 | |
| 17 | private static final String ROOT_URL = "CONFIG.ROOT_URL"; // https://api.data.gov/congress/v3 |
| 18 | private static final String OUTPUT_FOLDER = "CONFIG.OUTPUT_FOLDER"; // output |
| 19 | |
| 20 | private static final String BILL_CHAMBER = "BILL.CHAMBER"; // hr | s | sjres | hjres |
| 21 | private static final String BILL_NUMBER = "BILL.NUMBER"; // 21 |
| 22 | private static final String BILL_URL = "BILL.URL"; // bill |
| 23 | private static final String BILL_CONGRESS = "BILL.CONGRESS"; // 117 |
| 24 | |
| 25 | /** |
| 26 | * getProperty |
| 27 | * |
| 28 | * Get a config property from the specified config file |
| 29 | * |
| 30 | * @param property_name The property name to retrieve from the config file. |
| 31 | * |
| 32 | * @return String |
| 33 | */ |
| 34 | private static String getProperty(String property_name) { |
| 35 | Properties prop = new Properties(); |
| 36 | |
| 37 | try (FileInputStream fis = new FileInputStream(CONFIG_FILENAME)) { |
| 38 | prop.load(fis); |
| 39 | } catch (FileNotFoundException ex) { |
| 40 | Utils.outputMessageAndBail("Cannot find the config file " + CONFIG_FILENAME); |
| 41 | } catch (IOException ex) { |
| 42 | Utils.outputMessageAndBail("Unable to read the config file " + CONFIG_FILENAME); |
| 43 | } |
| 44 | |
| 45 | String p = prop.getProperty(property_name); |
| 46 | if (p == null) { |
| 47 | Utils.outputMessageAndBail("Unable to find property " + property_name); |
| 48 | } |
| 49 | |
| 50 | p = p.replaceAll("\\s+", ""); // no config values should have whitespaces |
| 51 | |
| 52 | if (p.equals("")) { |
| 53 | Utils.outputMessageAndBail("Check your config file, " + property_name + " was not set"); |
| 54 | } |
| 55 | |
| 56 | return p; |
| 57 | } |
| 58 | |
| 59 | // ************************************ |
| 60 | // Config Section |
| 61 | // ************************************ |
| 62 | |
| 63 | /** |
| 64 | * getApiKey |
| 65 | * |
nothing calls this directly
no outgoing calls
no test coverage detected