List of usage examples for org.apache.commons.configuration HierarchicalINIConfiguration getProperty
public Object getProperty(String key)
From source file:org.jboss.pressgang.ccms.contentspec.client.Client.java
/** * Sets the configuration options from the csprocessor.ini configuration file * * @param location The location of the csprocessor.ini file (eg. /home/<USERNAME>/.config/) * @return Returns false if an error occurs otherwise true *//*from w w w . ja va 2 s .c om*/ protected boolean setConfigOptions(final String location) { final String fixedLocation = ClientUtilities.fixConfigLocation(location); final HierarchicalINIConfiguration configReader; // Good point to check for a shutdown allowShutdownToContinueIfRequested(); // Checks if the file exists in the specified location final File file = new File(location); if (file.exists() && !file.isDirectory()) { JCommander.getConsole().println(ClientUtilities.getMessage("CONFIG_LOADING_MSG", location)); // Initialise the configuration reader with the skynet.ini content try { configReader = new HierarchicalINIConfiguration(fixedLocation); } catch (ConfigurationException e) { command.printError(ClientUtilities.getMessage("ERROR_INI_NOT_FOUND_MSG"), false); return false; } catch (Exception e) { command.printError(ClientUtilities.getMessage("ERROR_PROCESSING_CONFIG_MSG"), false); return false; } } else if (location.equals(Constants.DEFAULT_CONFIG_LOCATION)) { JCommander.getConsole().println(ClientUtilities.getMessage("CONFIG_CREATING_MSG", location)); firstRun = true; // Save the configuration file try { // Make sure the directory exists if (file.getParentFile() != null) { // TODO Check that this succeeded file.getParentFile().mkdirs(); } // Save the config FileUtilities.saveFile(file, ConfigConstants.DEFAULT_CONFIG_FILE, Constants.FILE_ENCODING); } catch (IOException e) { printError(ClientUtilities.getMessage("ERROR_FAILED_CREATING_CONFIG_MSG"), false); return false; } return setConfigOptions(location); } else { command.printError(ClientUtilities.getMessage("ERROR_INI_NOT_FOUND_MSG"), false); return false; } // Good point to check for a shutdown allowShutdownToContinueIfRequested(); /* Read in the servers from the config file */ if (!readServersFromConfig(configReader)) { return false; } // Read in the root directory if (!configReader.getRootNode().getChildren("directory").isEmpty()) { // Load the root content specs directory if (configReader.getProperty("directory.root") != null && !configReader.getProperty("directory.root").equals("")) { clientConfig.setRootDirectory( ClientUtilities.fixDirectoryPath(configReader.getProperty("directory.root").toString())); } // Load the install directory if (configReader.getProperty("directory.install") != null && !configReader.getProperty("directory.install").equals("")) { clientConfig.setInstallPath( ClientUtilities.fixDirectoryPath(configReader.getProperty("directory.install").toString())); } } // Read in the publican build options if (!configReader.getRootNode().getChildren("publican").isEmpty()) { // Load the publican setup values if (configReader.getProperty("publican.build..parameters") != null && !configReader.getProperty("publican.build..parameters").equals("")) { clientConfig .setPublicanBuildOptions(configReader.getProperty("publican.build..parameters").toString()); } if (configReader.getProperty("publican.preview..format") != null && !configReader.getProperty("publican.preview..format").equals("")) { clientConfig .setPublicanPreviewFormat(configReader.getProperty("publican.preview..format").toString()); } if (configReader.getProperty("publican.common_content") != null && !configReader.getProperty("publican.common_content").equals("")) { clientConfig.setPublicanCommonContentDirectory(ClientUtilities .fixDirectoryPath(configReader.getProperty("publican.common_content").toString())); } } else { clientConfig.setPublicanBuildOptions(Constants.DEFAULT_PUBLICAN_OPTIONS); clientConfig.setPublicanPreviewFormat(Constants.DEFAULT_PUBLICAN_FORMAT); } // Read in the jDocbook build options if (!configReader.getRootNode().getChildren("jDocbook").isEmpty()) { // Load the jDocbook setup values if (configReader.getProperty("jDocbook.build..parameters") != null && !configReader.getProperty("jDocbook.build..parameters").equals("")) { clientConfig .setjDocbookBuildOptions(configReader.getProperty("jDocbook.build..parameters").toString()); } if (configReader.getProperty("jDocbook.preview..format") != null && !configReader.getProperty("jDocbook.preview..format").equals("")) { clientConfig .setjDocbookPreviewFormat(configReader.getProperty("jDocbook.preview..format").toString()); } } else { clientConfig.setjDocbookBuildOptions(Constants.DEFAULT_JDOCBOOK_OPTIONS); clientConfig.setjDocbookPreviewFormat(Constants.DEFAULT_JDOCBOOK_FORMAT); } /* Read in the zanata details from the config file */ if (!readZanataDetailsFromConfig(configReader)) { return false; } // Read in the publishing information if (!configReader.getRootNode().getChildren("publish").isEmpty()) { // Load the koji hub url if (configReader.getProperty("publish.koji..huburl") != null && !configReader.getProperty("publish.koji..huburl").equals("")) { clientConfig.setKojiHubUrl(configReader.getProperty("publish.koji..huburl").toString()); } // Load the publish command name if (configReader.getProperty("publish.command") != null && !configReader.getProperty("publish.command").equals("")) { clientConfig.setPublishCommand(configReader.getProperty("publish.command").toString()); } } // Read in the editor settings readEditorSettingsFromConfig(configReader); // Read in the defaults readDefaultDetailsFromConfig(configReader); return true; }
From source file:org.jboss.pressgang.ccms.contentspec.client.Client.java
protected boolean readEditorSettingsFromConfig(final HierarchicalINIConfiguration configReader) { if (!configReader.getRootNode().getChildren("editor").isEmpty()) { // Load the editor command if (configReader.getProperty("editor.command") != null && !configReader.getProperty("editor.command").equals("")) { clientConfig.setEditorCommand(configReader.getProperty("editor.command").toString()); }// www.ja v a2 s .c o m // Load the requiresTerminalCommand if (configReader.getProperty("editor.requiresTerminal") != null && !configReader.getProperty("editor.requiresTerminal").equals("")) { clientConfig.setEditorRequiresTerminal( Boolean.parseBoolean(configReader.getProperty("editor.requiresTerminal").toString())); } } return true; }
From source file:org.jboss.pressgang.ccms.contentspec.client.Client.java
/** * Read the Default settings from a INI Configuration file. * * @param configReader The initialized configuration reader to read * the server configuration from file. * @return True if everything was read in correctly otherwise false. *//*from w ww. ja v a2s. com*/ protected boolean readDefaultDetailsFromConfig(final HierarchicalINIConfiguration configReader) { if (!configReader.getRootNode().getChildren("defaults").isEmpty()) { final ConfigDefaults defaults = new ConfigDefaults(); // Load the server value if (configReader.getProperty("defaults.server") != null && !configReader.getProperty("defaults.server").equals("")) { defaults.setServer(Boolean.parseBoolean(configReader.getProperty("defaults.server").toString())); } // Load the firstname value if (configReader.getProperty("defaults.firstname") != null && !configReader.getProperty("defaults.firstname").equals("")) { defaults.setFirstname(configReader.getProperty("defaults.firstname").toString()); } // Load the surname value if (configReader.getProperty("defaults.surname") != null && !configReader.getProperty("defaults.surname").equals("")) { defaults.setSurname(configReader.getProperty("defaults.surname").toString()); } // Load the email value if (configReader.getProperty("defaults.email") != null && !configReader.getProperty("defaults.email").equals("")) { defaults.setEmail(configReader.getProperty("defaults.email").toString()); } clientConfig.setDefaults(defaults); } return true; }