Example usage for java.util ResourceBundle containsKey

List of usage examples for java.util ResourceBundle containsKey

Introduction

In this page you can find the example usage for java.util ResourceBundle containsKey.

Prototype

public boolean containsKey(String key) 

Source Link

Document

Determines whether the given key is contained in this ResourceBundle or its parent bundles.

Usage

From source file:org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer.java

/**
 * Obtain a group's display name/*ww  w  .ja  va 2  s. c o m*/
 */
private String groupDisplayName(String group) {
    ResourceBundle b = (ResourceBundle) beanInfo.getBeanDescriptor().getValue(RESOURCE_BUNDLE);
    if (b == null) {
        return group;
    }
    String key = new StringBuilder(group).append(".displayName").toString();
    if (b.containsKey(key)) {
        return b.getString(key);
    } else {
        return group;
    }
}

From source file:org.apache.jmeter.util.JMeterUtils.java

private static String getResStringDefault(String key, String defaultValue, Locale forcedLocale) {
    if (key == null) {
        return null;
    }/*ww  w  .  ja va2s .  c o m*/
    // Resource keys cannot contain spaces, and are forced to lower case
    String resKey = key.replace(' ', '_'); // $NON-NLS-1$ // $NON-NLS-2$
    resKey = resKey.toLowerCase(java.util.Locale.ENGLISH);
    String resString = null;
    try {
        ResourceBundle bundle = resources;
        if (forcedLocale != null) {
            bundle = ResourceBundle.getBundle("org.apache.jmeter.resources.messages", forcedLocale); // $NON-NLS-1$
        }
        if (bundle.containsKey(resKey)) {
            resString = bundle.getString(resKey);
        } else {
            log.warn("ERROR! Resource string not found: [" + resKey + "]");
            resString = defaultValue;
        }
        if (ignoreResorces) { // Special mode for debugging resource handling
            return "[" + key + "]";
        }
    } catch (MissingResourceException mre) {
        if (ignoreResorces) { // Special mode for debugging resource handling
            return "[?" + key + "?]";
        }
        log.warn("ERROR! Resource string not found: [" + resKey + "]", mre);
        resString = defaultValue;
    }
    return resString;
}

From source file:org.apache.sling.scripting.sightly.impl.engine.extension.I18nRuntimeExtension.java

private String getTranslation(ResourceBundleProvider resourceBundleProvider, String basename, String key,
        Locale locale) {//from w  w w .  j av a2 s. com
    ResourceBundle resourceBundle;
    if (StringUtils.isNotEmpty(basename)) {
        resourceBundle = resourceBundleProvider.getResourceBundle(basename, locale);
    } else {
        resourceBundle = resourceBundleProvider.getResourceBundle(locale);
    }
    if (resourceBundle != null && resourceBundle.containsKey(key)) {
        return resourceBundle.getString(key);
    }
    return null;
}

From source file:org.asqatasun.webapp.report.expression.I18nExpression.java

/**
 * Retrieve a i18n among the Collection of resourceBundle associated with
 * the instance//w  w  w. ja va  2 s. c  o  m
 * 
 * @param key
 * @return 
 */
private String retrieveI18nValue(String key) {
    for (ResourceBundle rb : resourceBundleList) {
        if (rb.containsKey(key)) {
            return rb.getString(key);
        }
    }
    return key;
}

From source file:org.asqatasun.webapp.report.layout.builder.SubtitleBuilderImpl.java

/**
 * Retrieve a i18n among the Collection of resourceBundle associated with
 * the instance/*from   w ww  .  j  av  a  2s .  c om*/
 * 
 * @param key
 * @param resourceBundleList
 * @return 
 */
private String retrieveI18nValue(String key, Collection<ResourceBundle> resourceBundleList) {
    for (ResourceBundle rb : resourceBundleList) {
        if (rb.containsKey(key)) {
            return rb.getString(key);
        }
    }
    return key;
}

From source file:org.bremersee.pagebuilder.DefaultPageControlFactory.java

private List<PageSizeSelectorOptionDto> buildPageSizeSelectorOptions(final int selectedPageSize, // NOSONAR
        final Locale locale) {

    final int pageSizeSelectorMinValue = getPageSizeSelectorMinValue();
    final int pageSizeSelectorMaxValue = getMaxResultsSelectorMaxValue();
    final int pageSizeSelectorStep = getPageSizeSelectorStep();

    Validate.isTrue(0 < pageSizeSelectorMinValue && pageSizeSelectorMinValue <= pageSizeSelectorMaxValue,
            "0 < pageSizeSelectorMinValue && pageSizeSelectorMinValue "
                    + "<= pageSizeSelectorMaxValue must be 'true'");

    if (pageSizeSelectorMaxValue > pageSizeSelectorMinValue) {
        Validate.isTrue(pageSizeSelectorStep > 0, "pageSizeSelectorStep > 0 must be 'true'");
    }/*from  w w  w.j  a va2s .  c o m*/

    Validate.isTrue(selectedPageSize > 0, "selectedMaxResults > 0 must be 'true'");

    boolean selctedValueAdded = false;
    TreeSet<PageSizeSelectorOptionDto> options = new TreeSet<>();
    for (int i = pageSizeSelectorMinValue; i <= pageSizeSelectorMaxValue; i = i + pageSizeSelectorStep) {
        if (i == selectedPageSize) {
            options.add(new PageSizeSelectorOptionDto(i, Integer.valueOf(i).toString(), true)); // NOSONAR
            selctedValueAdded = true;
        } else {
            options.add(new PageSizeSelectorOptionDto(i, Integer.valueOf(i).toString(), false)); // NOSONAR
        }
    }

    if (isSelectAllEntriesAvailable()) {

        ResourceBundle resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE_NAME,
                locale == null ? Locale.getDefault() : locale);
        String displayedValue;
        if (resourceBundle.containsKey("pageBuilderFactory.pageSizeSelector.max")) {
            displayedValue = resourceBundle.getString("pageBuilderFactory.pageSizeSelector.max");
        } else {
            displayedValue = "Max";
        }

        if (Integer.MAX_VALUE == selectedPageSize) {
            options.add(new PageSizeSelectorOptionDto(Integer.MAX_VALUE, displayedValue, true));
            selctedValueAdded = true;
        } else {
            options.add(new PageSizeSelectorOptionDto(Integer.MAX_VALUE, displayedValue, false));
        }
    }
    if (!selctedValueAdded) {
        options.add(
                new PageSizeSelectorOptionDto(selectedPageSize, Integer.valueOf(selectedPageSize).toString(), // NOSONAR
                        true));
    }
    return Collections.unmodifiableList(new ArrayList<>(options));
}

From source file:org.broadinstitute.cga.tools.gatk.walkers.cancer.mutect.MuTect.java

@Override
public void initialize() {
    if (MTAC.NOOP) {
        return;/*from  w w  w  . j  a  va 2s .com*/
    }

    //setting version info
    // TODO: refactor into getMuTectVersion()
    final String gatkVersion = CommandLineGATK.getVersionNumber();
    ResourceBundle resources = TextFormattingUtils.loadResourceBundle("MuTectText");
    final String mutectVersion = resources.containsKey("version") ? resources.getString("version")
            : "<unknown>";
    final String combinedVersion = "MuTect:" + mutectVersion + " Gatk:" + gatkVersion;

    logger.info("VERSION INFO: " + combinedVersion);

    refReader = this.getToolkit().getReferenceDataSource().getReference();
    callStatsGenerator = new CallStatsGenerator(MTAC.ENABLE_QSCORE_OUTPUT);

    // check that we have at least one tumor bam
    for (SAMReaderID id : getToolkit().getReadsDataSource().getReaderIDs()) {
        if (id.getTags().getPositionalTags().size() == 0) {
            throw new RuntimeException("BAMs must be tagged as either 'tumor' or 'normal'");
        }

        for (String tag : id.getTags().getPositionalTags()) {
            if (BAM_TAG_TUMOR.equalsIgnoreCase(tag)) {
                hasTumorBam = true;
                tumorSAMReaderIDs.add(id);

                // fill in the sample name if necessary
                if (MTAC.TUMOR_SAMPLE_NAME == null) {
                    try {
                        if (getToolkit().getReadsDataSource().getHeader(id).getReadGroups().size() == 0) {
                            throw new RuntimeException(
                                    "No Read Groups found for Tumor BAM -- Read Groups are Required, or supply tumor_sample_name!");
                        }
                        MTAC.TUMOR_SAMPLE_NAME = getToolkit().getReadsDataSource().getHeader(id).getReadGroups()
                                .get(0).getSample();
                    } catch (NullPointerException npe) {
                        MTAC.TUMOR_SAMPLE_NAME = "tumor";
                    }
                }
            } else if (BAM_TAG_NORMAL.equalsIgnoreCase(tag)) {
                hasNormalBam = true;
                normalSAMReaderIDs.add(id);

                // fill in the sample name if necessary
                if (MTAC.NORMAL_SAMPLE_NAME == null) {
                    try {
                        if (getToolkit().getReadsDataSource().getHeader(id).getReadGroups().size() == 0) {
                            throw new RuntimeException(
                                    "No Read Groups found for Normal BAM -- Read Groups are Required, or supply normal_sample_name!");
                        }

                        MTAC.NORMAL_SAMPLE_NAME = getToolkit().getReadsDataSource().getHeader(id)
                                .getReadGroups().get(0).getSample();
                    } catch (NullPointerException npe) {
                        MTAC.NORMAL_SAMPLE_NAME = "normal";
                    }
                }
            } else {
                throw new RuntimeException("Unknown BAM tag '" + tag + "' must be either 'tumor' or 'normal'");
            }
        }
    }

    if (!hasTumorBam) {
        throw new RuntimeException("At least one BAM tagged as 'tumor' required");
    }

    if (!hasNormalBam) {
        MTAC.NORMAL_LOD_THRESHOLD = -1 * Float.MAX_VALUE;
        MTAC.NORMAL_DBSNP_LOD_THRESHOLD = -1 * Float.MAX_VALUE;
        MTAC.NORMAL_ARTIFACT_LOD_THRESHOLD = Float.MAX_VALUE;
        MTAC.NORMAL_SAMPLE_NAME = "none";
    }

    this.contaminantAlternateFraction = Math.max(MTAC.MINIMUM_MUTATION_CELL_FRACTION,
            MTAC.FRACTION_CONTAMINATION);

    // coverage related initialization
    double powerConstantEps = Math.pow(10, -1 * (MTAC.POWER_CONSTANT_QSCORE / 10));

    this.tumorPowerCalculator = new TumorPowerCalculator(powerConstantEps, MTAC.TUMOR_LOD_THRESHOLD,
            this.contaminantAlternateFraction);
    this.normalNovelSitePowerCalculator = new NormalPowerCalculator(powerConstantEps,
            MTAC.NORMAL_LOD_THRESHOLD);
    this.normalDbSNPSitePowerCalculator = new NormalPowerCalculator(powerConstantEps,
            MTAC.NORMAL_DBSNP_LOD_THRESHOLD);
    this.strandArtifactPowerCalculator = new TumorPowerCalculator(powerConstantEps,
            MTAC.STRAND_ARTIFACT_LOD_THRESHOLD, 0.0f);

    stdCovWriter = new CoverageWiggleFileWriter(COVERAGE_FILE);
    q20CovWriter = new CoverageWiggleFileWriter(COVERAGE_20_Q20_FILE);
    powerWriter = new CoverageWiggleFileWriter(POWER_FILE);
    tumorDepthWriter = new CoverageWiggleFileWriter(TUMOR_DEPTH_FILE);
    normalDepthWriter = new CoverageWiggleFileWriter(NORMAL_DEPTH_FILE);

    // to force output, all we have to do is lower the initial tumor lod threshold to -infinity
    if (MTAC.FORCE_OUTPUT) {
        MTAC.INITIAL_TUMOR_LOD_THRESHOLD = -Float.MAX_VALUE;
    }

    // initialize the call-stats file
    out.println("##" + combinedVersion);
    out.println(callStatsGenerator.generateHeader());

    // initialize the VCF output
    if (vcf != null) {
        // TODO: fix for multisample mode
        Set<String> samples = new HashSet<String>();
        samples.add(MTAC.TUMOR_SAMPLE_NAME);
        samples.add(MTAC.NORMAL_SAMPLE_NAME);
        Set<VCFHeaderLine> headerInfo = VCFGenerator.getVCFHeaderInfo();
        vcf.writeHeader(new VCFHeader(headerInfo, samples));
    }

    lastTime = System.currentTimeMillis();
}

From source file:org.cloudifysource.restclient.messages.MessagesUtils.java

/**
 * returns the message as it appears in the {@link #messageBundle}.
 * No warning is issued if the message is not found.
 * /*ww w.j  a  v a  2s  . c  o m*/
 * @param messageCode
 *            The message key as it is defined in the message bundle.
 * @param arguments
 *            The message arguments
 * @return the formatted message according to the message key.
 */
public static String getFormattedMessageSilently(final String messageCode, final Object... arguments) {

    // the message defaults to the message code
    String formattedMessage = messageCode;
    final ResourceBundle messageBundle = getMessageBundle();
    if (messageBundle.containsKey(messageCode)) {
        String bundleMessage = messageBundle.getString(messageCode);
        if (StringUtils.isNotBlank(bundleMessage)) {
            try {
                formattedMessage = MessageFormat.format(bundleMessage, arguments);
            } catch (final IllegalArgumentException e) {
                // ignore, we will return the message code instead
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Failed to create a MessageFormat with the given pattern [" + bundleMessage
                            + "] and the given arguments " + Arrays.toString(arguments)
                            + ". returning messageCode [" + messageCode + "]");
                }
            }
        }
    }

    return formattedMessage;

}

From source file:org.dataconservancy.packaging.gui.Help.java

public Help(ResourceBundle bundle) {
    this.bundle = bundle;

    for (HelpKey key : HelpKey.values()) {
        if (!bundle.containsKey(key.getProperty())) {
            throw new IllegalArgumentException("Missing resource in bundle: " + key.getProperty());
        }//from w w  w . j  a  v  a2s  .  c om
    }
}

From source file:org.exoplatform.commons.notification.template.TemplateResourceBundle.java

public static String getResourceBundle(String key, Locale locale, String resourceLocale) {
    if (key == null || key.trim().length() == 0) {
        return "";
    }/*  www .  ja v  a 2s. c o  m*/

    if (locale == null || locale.getLanguage().isEmpty()) {
        locale = Locale.ENGLISH;
    }

    ResourceBundle res = null;
    ResourceBundleService bundleService = CommonsUtils.getService(ResourceBundleService.class);
    if (bundleService != null) {
        res = bundleService.getResourceBundle(resourceLocale, locale);
        // if null, try another way
        if (res == null) {
            //
            res = addResourceBundle(bundleService, resourceLocale, locale);
        }
    }
    // still null
    if (res == null || res.containsKey(key) == false) {
        if (key.indexOf(".digest.") < 0) {
            LOG.warn("Can not get resource bundle by key: " + key);
        }
        return key;
    }

    return res.getString(key);
}