Search in sources :

Example 16 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class MainFrame method getShowTabIconNamesButton.

private JToggleButton getShowTabIconNamesButton() {
    if (showTabIconNamesButton == null) {
        showTabIconNamesButton = new ZapToggleButton();
        showTabIconNamesButton.setIcon(new ImageIcon(WorkbenchPanel.class.getResource("/resource/icon/ui_tab_icon.png")));
        showTabIconNamesButton.setToolTipText(Constant.messages.getString("view.toolbar.showNames"));
        showTabIconNamesButton.setSelectedIcon(new ImageIcon(WorkbenchPanel.class.getResource("/resource/icon/ui_tab_text.png")));
        showTabIconNamesButton.setSelectedToolTipText(Constant.messages.getString("view.toolbar.showIcons"));
        showTabIconNamesButton.setSelected(Model.getSingleton().getOptionsParam().getViewParam().getShowTabNames());
        DisplayUtils.scaleIcon(showTabIconNamesButton);
        showTabIconNamesButton.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                boolean showTabNames = getShowTabIconNamesButton().isSelected();
                setShowTabNames(showTabNames);
                Model.getSingleton().getOptionsParam().getViewParam().setShowTabNames(showTabNames);
                try {
                    Model.getSingleton().getOptionsParam().getViewParam().getConfig().save();
                } catch (ConfigurationException e) {
                    LOGGER.error(e.getMessage(), e);
                }
            }
        });
    }
    return showTabIconNamesButton;
}
Also used : ImageIcon(javax.swing.ImageIcon) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ActionEvent(java.awt.event.ActionEvent) ZapToggleButton(org.zaproxy.zap.view.ZapToggleButton)

Example 17 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class Constant method initializeFilesAndDirectories.

public void initializeFilesAndDirectories() {
    FileCopier copier = new FileCopier();
    File f = null;
    // Set up the version from the manifest
    PROGRAM_VERSION = getVersionFromManifest();
    PROGRAM_TITLE = PROGRAM_NAME + " " + PROGRAM_VERSION;
    if (zapHome == null) {
        zapHome = getDefaultHomeDirectory(true);
    }
    zapHome = getAbsolutePath(zapHome);
    f = new File(zapHome);
    FILE_CONFIG = zapHome + FILE_CONFIG;
    FOLDER_SESSION = zapHome + FOLDER_SESSION;
    DBNAME_UNTITLED = zapHome + DBNAME_UNTITLED;
    ACCEPTED_LICENSE = zapHome + ACCEPTED_LICENSE;
    DIRBUSTER_CUSTOM_DIR = zapHome + DIRBUSTER_DIR;
    FUZZER_DIR = zapHome + FUZZER_DIR;
    FOLDER_LOCAL_PLUGIN = zapHome + FOLDER_LOCAL_PLUGIN;
    try {
        System.setProperty(SYSTEM_PAROS_USER_LOG, zapHome);
        if (!f.isDirectory()) {
            if (!f.mkdir()) {
                // ZAP: report failure to create directory
                System.out.println("Failed to create directory " + f.getAbsolutePath());
            }
        }
        // Setup the logging
        File logFile = new File(zapHome + "/log4j.properties");
        if (!logFile.exists()) {
            copier.copy(new File(zapInstall, "xml/log4j.properties"), logFile);
        }
        System.setProperty("log4j.configuration", logFile.getAbsolutePath());
        PropertyConfigurator.configure(logFile.getAbsolutePath());
        f = new File(FILE_CONFIG);
        if (!f.isFile()) {
            this.copyDefaultConfigs(f, false);
        }
        f = new File(FOLDER_SESSION);
        if (!f.isDirectory()) {
            LOG.info("Creating directory " + FOLDER_SESSION);
            if (!f.mkdir()) {
                // ZAP: report failure to create directory
                System.out.println("Failed to create directory " + f.getAbsolutePath());
            }
        }
        f = new File(DIRBUSTER_CUSTOM_DIR);
        if (!f.isDirectory()) {
            LOG.info("Creating directory " + DIRBUSTER_CUSTOM_DIR);
            if (!f.mkdir()) {
                // ZAP: report failure to create directory
                System.out.println("Failed to create directory " + f.getAbsolutePath());
            }
        }
        f = new File(FUZZER_DIR);
        if (!f.isDirectory()) {
            LOG.info("Creating directory " + FUZZER_DIR);
            if (!f.mkdir()) {
                // ZAP: report failure to create directory
                System.out.println("Failed to create directory " + f.getAbsolutePath());
            }
        }
        f = new File(FOLDER_LOCAL_PLUGIN);
        if (!f.isDirectory()) {
            LOG.info("Creating directory " + FOLDER_LOCAL_PLUGIN);
            if (!f.mkdir()) {
                // ZAP: report failure to create directory
                System.out.println("Failed to create directory " + f.getAbsolutePath());
            }
        }
        f = new File(zapHome, FOLDER_FILTER);
        if (!f.isDirectory()) {
            LOG.info("Creating directory: " + f.getAbsolutePath());
            if (!f.mkdir()) {
                System.out.println("Failed to create directory " + f.getAbsolutePath());
            }
        }
    } catch (Exception e) {
        System.err.println("Unable to initialize home directory! " + e.getMessage());
        e.printStackTrace(System.err);
        System.exit(1);
    }
    // Upgrade actions
    try {
        try {
            // ZAP: Changed to use ZapXmlConfiguration, to enforce the same character encoding when reading/writing configurations.
            XMLConfiguration config = new ZapXmlConfiguration(FILE_CONFIG);
            config.setAutoSave(false);
            long ver = config.getLong("version");
            if (ver == VERSION_TAG) {
            // Nothing to do
            } else if (isDevBuild() || isDailyBuild()) {
            // Nothing to do
            } else {
                // Backup the old one
                LOG.info("Backing up config file to " + FILE_CONFIG + ".bak");
                f = new File(FILE_CONFIG);
                try {
                    copier.copy(f, new File(FILE_CONFIG + ".bak"));
                } catch (IOException e) {
                    String msg = "Failed to backup config file " + FILE_CONFIG + " to " + FILE_CONFIG + ".bak " + e.getMessage();
                    System.err.println(msg);
                    LOG.error(msg, e);
                }
                if (ver == V_PAROS_TAG) {
                    upgradeFrom1_1_0(config);
                    upgradeFrom1_2_0(config);
                }
                if (ver <= V_1_0_0_TAG) {
                // Nothing to do
                }
                if (ver <= V_1_1_0_TAG) {
                    upgradeFrom1_1_0(config);
                }
                if (ver <= V_1_2_0_TAG) {
                    upgradeFrom1_2_0(config);
                }
                if (ver <= V_1_2_1_TAG) {
                // Nothing to do
                }
                if (ver <= V_1_3_0_TAG) {
                // Nothing to do
                }
                if (ver <= V_1_3_1_TAG) {
                // Nothing to do
                }
                if (ver <= V_1_4_1_TAG) {
                    upgradeFrom1_4_1(config);
                }
                if (ver <= V_2_0_0_TAG) {
                    upgradeFrom2_0_0(config);
                }
                if (ver <= V_2_1_0_TAG) {
                // Nothing to do
                }
                if (ver <= V_2_2_0_TAG) {
                    upgradeFrom2_2_0(config);
                }
                if (ver <= V_2_3_1_TAG) {
                    upgradeFrom2_3_1(config);
                }
                if (ver <= V_2_4_3_TAG) {
                    upgradeFrom2_4_3(config);
                }
                if (ver <= V_2_5_0_TAG) {
                    upgradeFrom2_5_0(config);
                }
                LOG.info("Upgraded from " + ver);
                // Update the version
                config.setProperty("version", VERSION_TAG);
                config.save();
            }
        } catch (ConfigurationException | ConversionException | NoSuchElementException e) {
            //  if there is any error in config file (eg config file not exist, corrupted),
            //  overwrite previous configuration file 
            // ZAP: changed to use the correct file
            copier.copy(getPathDefaultConfigFile().toFile(), new File(FILE_CONFIG));
        }
    } catch (Exception e) {
        System.err.println("Unable to upgrade config file " + FILE_CONFIG + " " + e.getMessage());
        e.printStackTrace(System.err);
        System.exit(1);
    }
    // ZAP: Init i18n
    String lang;
    Locale locale = Locale.ENGLISH;
    try {
        // Select the correct locale
        // ZAP: Changed to use ZapXmlConfiguration, to enforce the same character encoding when reading/writing configurations.
        XMLConfiguration config = new ZapXmlConfiguration(FILE_CONFIG);
        config.setAutoSave(false);
        lang = config.getString(OptionsParamView.LOCALE, OptionsParamView.DEFAULT_LOCALE);
        if (lang.length() == 0) {
            lang = OptionsParamView.DEFAULT_LOCALE;
        }
        String[] langArray = lang.split("_");
        locale = new Locale(langArray[0], langArray[1]);
    } catch (Exception e) {
        System.out.println("Failed to initialise locale " + e);
    }
    Locale.setDefault(locale);
    messages = new I18N(locale);
}
Also used : ConversionException(org.apache.commons.configuration.ConversionException) Locale(java.util.Locale) IOException(java.io.IOException) FileCopier(org.parosproxy.paros.model.FileCopier) ConversionException(org.apache.commons.configuration.ConversionException) InvalidParameterException(java.security.InvalidParameterException) ParseException(java.text.ParseException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) File(java.io.File) NoSuchElementException(java.util.NoSuchElementException) I18N(org.zaproxy.zap.utils.I18N)

Example 18 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project opennms by OpenNMS.

the class ReadOnlyRtConfigDao method getProperties.

/**
	 * Retrieves the properties defined in the rt.properties file.
	 * 
	 * @return a <code>java.util.Properties</code> object containing rt plugin defined properties
	 * 
	 * @author <a href="mailto:jonathan@opennms.org">Jonathan Sartin</a>
	 * 
	 */
protected Configuration getProperties() {
    final long now = System.currentTimeMillis();
    if (m_config == null || now > (m_lastUpdated + TIMEOUT)) {
        String propsFile = getFile();
        LOG.debug("loading properties from: {}", propsFile);
        try {
            m_config = new PropertiesConfiguration(propsFile);
            m_lastUpdated = now;
        } catch (final ConfigurationException e) {
            LOG.error("Unable to load RT properties", e);
        }
    }
    return m_config;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 19 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project opennms by OpenNMS.

the class DefaultOtrsConfigDao method getProperties.

/**
	 * Retrieves the properties defined in the otrs.properties file.
	 * 
	 * @return a
	 *         <code>java.util.Properties object containing otrs plugin defined properties
	 * @throws IOException 
	 */
private Configuration getProperties() {
    Configuration config = new PropertiesConfiguration();
    String propsFile = null;
    try {
        propsFile = new File(new File(System.getProperty("opennms.home"), "etc"), "otrs.properties").getCanonicalPath();
        LOG.debug("loading properties from: {}", propsFile);
        config = new PropertiesConfiguration(propsFile);
    } catch (final ConfigurationException e) {
        LOG.error("Unable to load properties from {}", propsFile, e);
    } catch (final IOException e) {
        LOG.error("Exception when trying to find OTRS configuration properties from {}", propsFile, e);
    }
    return config;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) File(java.io.File)

Example 20 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project jangaroo-tools by CoreMedia.

the class PropertyClassGenerator method generate.

@Override
public File generate(File propertiesFile) {
    PropertiesConfiguration p = new PropertiesConfiguration();
    p.setDelimiterParsingDisabled(true);
    Reader r = null;
    try {
        r = new BufferedReader(new InputStreamReader(new FileInputStream(propertiesFile), "UTF-8"));
        p.load(r);
    } catch (IOException e) {
        throw new PropcException("Error while parsing properties file", propertiesFile, e);
    } catch (ConfigurationException e) {
        throw new PropcException("Error while parsing properties file", propertiesFile, e);
    } finally {
        try {
            if (r != null) {
                r.close();
            }
        } catch (IOException e) {
        //not really
        }
    }
    ResourceBundleClass bundle = new ResourceBundleClass(PropcHelper.computeBaseClassName(locations, propertiesFile));
    // Create properties class, which registers itself with the bundle.
    return generateJangarooClass(new PropertiesClass(bundle, PropcHelper.computeLocale(propertiesFile), p, propertiesFile));
}
Also used : InputStreamReader(java.io.InputStreamReader) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ResourceBundleClass(net.jangaroo.properties.model.ResourceBundleClass) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) PropcException(net.jangaroo.properties.api.PropcException) PropertiesClass(net.jangaroo.properties.model.PropertiesClass) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileInputStream(java.io.FileInputStream)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)58 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)24 File (java.io.File)18 IOException (java.io.IOException)18 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)5 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 FileInputStream (java.io.FileInputStream)4 FileWriter (java.io.FileWriter)4 Configuration (org.apache.commons.configuration.Configuration)4 FileNotFoundException (java.io.FileNotFoundException)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 CommonsConfiguration (com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration)2 BufferedWriter (java.io.BufferedWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SQLException (java.sql.SQLException)2