Search in sources :

Example 56 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project eclipse-cs by checkstyle.

the class ConfigurationType method getPropertyResolver.

/**
 * Gets the property resolver for this configuration type used to expand property values within
 * the checkstyle configuration.
 *
 * @param checkConfiguration
 *          the actual check configuration
 * @return the property resolver
 * @throws IOException
 *           error creating the property resolver
 * @throws URISyntaxException
 */
protected PropertyResolver getPropertyResolver(ICheckConfiguration config, CheckstyleConfigurationFile configFile) throws IOException, URISyntaxException {
    MultiPropertyResolver multiResolver = new MultiPropertyResolver();
    multiResolver.addPropertyResolver(new ResolvablePropertyResolver(config));
    File f = URIUtil.toFile(configFile.getResolvedConfigFileURL().toURI());
    if (f != null) {
        multiResolver.addPropertyResolver(new StandardPropertyResolver(f.toString()));
    } else {
        multiResolver.addPropertyResolver(new StandardPropertyResolver(configFile.getResolvedConfigFileURL().toString()));
    }
    multiResolver.addPropertyResolver(new ClasspathVariableResolver());
    multiResolver.addPropertyResolver(new SystemPropertyResolver());
    if (configFile.getAdditionalPropertiesBundleStream() != null) {
        ResourceBundle bundle = new PropertyResourceBundle(configFile.getAdditionalPropertiesBundleStream());
        multiResolver.addPropertyResolver(new ResourceBundlePropertyResolver(bundle));
    }
    return multiResolver;
}
Also used : PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) CheckstyleConfigurationFile(net.sf.eclipsecs.core.config.CheckstyleConfigurationFile) File(java.io.File) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 57 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project clusterMaker2 by RBVI.

the class Console method findAndReadConfigIfGivenAndSetMode.

/**
 * Looks through the input variables to see if a config file is defined. If
 * so all parameters are read from this config file. If some do not exist, a
 * warning is given, but the program continues. It may be the case that
 * these parameters are unwanted or belong to an unused implementation. It
 * also looks if a mode was given and sets this, otherwise the default is
 * used.
 *
 * It also checks whether input AND output files/directories are given,
 * which is compulsory when starting with the console and not with the gui.
 *
 * @return boolean value if an input and an output file (both) are given.
 * @throws InvalidInputFileException
 *             If the given config class does not end in .conf.
 */
private boolean findAndReadConfigIfGivenAndSetMode() throws InvalidInputFileException, ArgsParseException {
    boolean input = false;
    boolean output = false;
    String configPath = TaskConfig.DEFAULTCONFIG;
    for (int i = 0; i < args.length; i++) {
        /* check whether an input file is given */
        if (args[i].trim().equals("-i")) {
            input = true;
            ++i;
        }
        if (args[i].trim().equals("-o")) {
            output = true;
            ++i;
        }
        /* check for mode parameter */
        if (args[i].trim().equals("-mode")) {
            String value = args[i + 1].trim();
            try {
                int md = Integer.parseInt(value);
                if (md == TaskConfig.GENERAL_TRAINING_MODE) {
                    TaskConfig.mode = TaskConfig.GENERAL_TRAINING_MODE;
                } else if (md == TaskConfig.CLUSTERING_MODE) {
                    TaskConfig.mode = TaskConfig.CLUSTERING_MODE;
                } else if (md == TaskConfig.COMPARISON_MODE) {
                    TaskConfig.mode = TaskConfig.COMPARISON_MODE;
                } else if (md == TaskConfig.HIERARICHAL_MODE) {
                    TaskConfig.mode = TaskConfig.HIERARICHAL_MODE;
                } else {
                    throw new ArgsParseException("The given mode is incorrect - it does not exist! " + md);
                }
            } catch (Exception e) {
                throw new ArgsParseException("The given mode is not an interger value: " + value);
            }
            ++i;
        }
        /* check for config parameter */
        if (args[i].trim().equals("-config")) {
            String value = args[i + 1].trim();
            if (value.endsWith(".conf")) {
                TaskConfig.useConfigFile = true;
                TaskConfig.inputConfigPath = value;
                configPath = value;
            } else {
                throw new InvalidInputFileException("An invalid config file was entered. The file must end with '.conf'. Please try again! Given file=" + value);
            }
            ++i;
        }
        /* check for if -cf parameter is set */
        if (args[i].trim().equals("-cf")) {
            TaskConfig.useConfigFile = Boolean.parseBoolean(args[i + 1].trim());
            ++i;
        }
    }
    if (TaskConfig.useConfigFile) {
        try {
            FileInputStream s = new FileInputStream(configPath);
            PropertyResourceBundle configrb = new PropertyResourceBundle(s);
            // log.debug("Using config file " + configPath);
            TaskConfig.initFromConfigFile(configrb);
            FORCEnDLayoutConfig.initFromConfigFile(configrb);
            GeometricClusteringConfig.initSLCFromConfigFile(configrb);
            GeometricClusteringConfig.initKmeansFromConfigFile(configrb);
        } catch (MissingResourceException ex) {
            TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "WARNING: Resources are missing in the given config file: " + TaskConfig.DEFAULTCONFIG + ", key=" + ex.getKey() + ". Either you have defined these parameters in the input, or the default values are used from the " + TaskConfig.DEFAULTCONFIG + ". Or these parameters do not interest you, because they belong to an unused implemtation.");
        } catch (IOException ex) {
            TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR: Unable to read the given config file: " + configPath);
            System.exit(-1);
        } catch (InvalidTypeException ex) {
            TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR: You have perhaps given an incorrect class name of an " + "implemtation. Please note that this is case sensitive.");
            System.exit(-1);
        }
    }
    if (input && output)
        return true;
    else
        return false;
}
Also used : InvalidInputFileException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) InvalidInputFileException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) InvalidTypeException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidTypeException) FileInputStream(java.io.FileInputStream) PropertyResourceBundle(java.util.PropertyResourceBundle) InvalidTypeException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidTypeException)

Example 58 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project mycore by MyCoRe-Org.

the class MCRCombinedResourceBundleControl method newBundle.

@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("New bundle: {}, locale {}", baseName, locale);
    }
    if (locale.equals(Locale.ROOT)) {
        // MCR-1064 fallback should be default language, if property key does not exist
        locale = defaultLocale;
    }
    String bundleName = baseName.substring(baseName.indexOf(':') + 1);
    String filename = CONTROL_HELPER.toBundleName(bundleName, locale) + ".properties";
    try (MCRConfigurationInputStream propertyStream = new MCRConfigurationInputStream(filename)) {
        if (propertyStream.isEmpty()) {
            throw new MissingResourceException(// className
            "Can't find bundle for base name " + baseName + ", locale " + locale, // className
            bundleName + "_" + locale, "");
        }
        return new PropertyResourceBundle(propertyStream);
    }
}
Also used : MCRConfigurationInputStream(org.mycore.common.config.MCRConfigurationInputStream) MissingResourceException(java.util.MissingResourceException) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 59 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project Frankenstein by olir.

the class ProcessingSceneController method filterSetup.

@FXML
public void filterSetup() {
    PropertyResourceBundle bundleConfiguration = (PropertyResourceBundle) ResourceBundle.getBundle("de/serviceflow/frankenstein/bundles/filtersetup", Configuration.getInstance().getLocale());
    FXMLLoader loader = new FXMLLoader(getClass().getResource("FilterSetupPopup.fxml"), bundleConfiguration);
    Stage stage = new Stage();
    try {
        FilterSetupController controller = new FilterSetupController();
        loader.setController(controller);
        stage.setScene(new Scene(loader.load()));
        controller.configure(this, stage);
        stage.setTitle("Edit filter " + selectedFilter.toStringRange());
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.initOwner(btnListFilter.getScene().getWindow());
        stage.showAndWait();
        SegmentVideoFilter f = controller.getSelectedFilterInstance();
        selectedFilter.setType(f);
        processor.applyLocalFilters(filterListData);
        Runnable r = new Runnable() {

            public void run() {
                processor.setPreviewFilter(null);
                processor.seek(ProcessingSceneController.this, position);
            }
        };
        ExecutorThread.getInstance().execute(r);
        Platform.runLater(() -> {
            listViewFilter.refresh();
            drawEditCanvas();
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : SegmentVideoFilter(de.serviceflow.frankenstein.plugin.api.SegmentVideoFilter) Stage(javafx.stage.Stage) IOException(java.io.IOException) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) PropertyResourceBundle(java.util.PropertyResourceBundle) FXML(javafx.fxml.FXML)

Example 60 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project LanternServer by LanternPowered.

the class LanternTranslationManager method loadAssetBundle.

private void loadAssetBundle(Asset asset, Locale locale, boolean refresh) {
    try {
        final InputStream inputStream = asset.getUrl().openStream();
        try {
            final ResourceBundle bundle = new PropertyResourceBundle(inputStream);
            this.bundles.computeIfAbsent(locale, locale0 -> Sets.newConcurrentHashSet()).add(bundle);
            if (refresh) {
                final Set<ResourceKey> refreshKeys = Sets.newHashSet();
                for (ResourceKey key : this.resourceBundlesCache.asMap().keySet()) {
                    Locale locale1 = key.locale == null ? Locale.ENGLISH : key.locale;
                    if (locale1.equals(locale) && bundle.containsKey(key.name)) {
                        refreshKeys.add(key);
                    }
                }
                if (!refreshKeys.isEmpty()) {
                    this.resourceBundlesCache.invalidateAll(refreshKeys);
                }
            }
        } catch (IOException e) {
            Lantern.getLogger().warn("Unable to create the resource bundle for: " + asset.getId(), e);
        }
    } catch (IOException e) {
        Lantern.getLogger().warn("Unable to open the asset stream for: " + asset.getId(), e);
    }
}
Also used : Caffeine(com.github.benmanes.caffeine.cache.Caffeine) ResourceBundleTranslation(org.spongepowered.api.text.translation.ResourceBundleTranslation) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PropertyResourceBundle(java.util.PropertyResourceBundle) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) Sets(com.google.common.collect.Sets) ReloadListener(org.lanternpowered.server.asset.ReloadListener) Asset(org.lanternpowered.api.asset.Asset) ConcurrentMap(java.util.concurrent.ConcurrentMap) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ResourceBundle(java.util.ResourceBundle) Lantern(org.lanternpowered.server.game.Lantern) Locale(java.util.Locale) Map(java.util.Map) Optional(java.util.Optional) Conditions.checkNotNullOrEmpty(org.lanternpowered.server.util.Conditions.checkNotNullOrEmpty) Nullable(javax.annotation.Nullable) Translation(org.spongepowered.api.text.translation.Translation) InputStream(java.io.InputStream) Locale(java.util.Locale) InputStream(java.io.InputStream) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) PropertyResourceBundle(java.util.PropertyResourceBundle)

Aggregations

PropertyResourceBundle (java.util.PropertyResourceBundle)71 InputStream (java.io.InputStream)35 ResourceBundle (java.util.ResourceBundle)33 IOException (java.io.IOException)30 URL (java.net.URL)24 InputStreamReader (java.io.InputStreamReader)23 FileInputStream (java.io.FileInputStream)15 URLConnection (java.net.URLConnection)14 MissingResourceException (java.util.MissingResourceException)13 File (java.io.File)12 FileNotFoundException (java.io.FileNotFoundException)8 Locale (java.util.Locale)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 HashMap (java.util.HashMap)5 MalformedURLException (java.net.MalformedURLException)4 Bundle (org.osgi.framework.Bundle)4 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)3 TemplateReaderWriter (org.eclipse.jface.text.templates.persistence.TemplateReaderWriter)3