Example usage for java.util MissingResourceException getMessage

List of usage examples for java.util MissingResourceException getMessage

Introduction

In this page you can find the example usage for java.util MissingResourceException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.roda.wui.api.controllers.BrowserHelper.java

public static List<SupportedMetadataTypeBundle> retrieveSupportedMetadata(User user, IndexedAIP aip,
        IndexedRepresentation representation, Locale locale) throws GenericException {
    Messages messages = RodaCoreFactory.getI18NMessages(locale);
    List<String> types = RodaUtils.copyList(RodaCoreFactory.getRodaConfiguration()
            .getList(RodaConstants.UI_BROWSER_METADATA_DESCRIPTIVE_TYPES));

    List<SupportedMetadataTypeBundle> supportedMetadata = new ArrayList<>();

    if (types != null) {
        for (String id : types) {
            String type = id;// www  .j  a  va  2 s . com
            String version = null;
            if (id.contains(RodaConstants.METADATA_VERSION_SEPARATOR)) {
                version = id.substring(id.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR) + 1,
                        id.length());
                type = id.substring(0, id.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR));
            }
            String key = RodaConstants.I18N_UI_BROWSE_METADATA_DESCRIPTIVE_TYPE_PREFIX + type;
            if (version != null) {
                key += RodaConstants.METADATA_VERSION_SEPARATOR + version.toLowerCase();
            }
            String label = messages.getTranslation(key, type);

            String template = null;
            Set<MetadataValue> values = new HashSet<>();
            try (InputStream templateStream = RodaCoreFactory
                    .getConfigurationFileAsStream(RodaConstants.METADATA_TEMPLATE_FOLDER + "/"
                            + ((version != null) ? type + RodaConstants.METADATA_VERSION_SEPARATOR + version
                                    : type)
                            + RodaConstants.METADATA_TEMPLATE_EXTENSION)) {

                if (templateStream != null) {
                    template = IOUtils.toString(templateStream, RodaConstants.DEFAULT_ENCODING);
                    values = ServerTools.transform(template);
                    for (MetadataValue mv : values) {
                        String generator = mv.get("auto-generate");
                        if (generator != null && generator.length() > 0) {
                            String value;
                            if (representation != null) {
                                value = ServerTools.autoGenerateRepresentationValue(representation, generator);
                            } else {
                                value = ServerTools.autoGenerateAIPValue(aip, user, generator);
                            }

                            if (value != null) {
                                mv.set("value", value);
                            }
                        }
                        String labels = mv.get("label");
                        String labelI18N = mv.get("labeli18n");
                        if (labels != null && labelI18N != null) {
                            Map<String, String> labelsMaps = JsonUtils.getMapFromJson(labels);
                            try {
                                labelsMaps.put(locale.toString(),
                                        RodaCoreFactory.getI18NMessages(locale).getTranslation(labelI18N));
                            } catch (MissingResourceException e) {
                                LOGGER.debug("Missing resource: {}", labelI18N);
                            }
                            labels = JsonUtils.getJsonFromObject(labelsMaps);
                            mv.set("label", labels);
                        }

                        String i18nPrefix = mv.get("optionsLabelI18nKeyPrefix");
                        if (i18nPrefix != null) {
                            Map<String, String> terms = messages.getTranslations(i18nPrefix, String.class,
                                    false);
                            if (terms.size() > 0) {
                                try {
                                    String options = mv.get("options");
                                    List<String> optionsList = JsonUtils.getListFromJson(options, String.class);

                                    if (optionsList != null) {
                                        Map<String, Map<String, String>> i18nMap = new HashMap<>();
                                        for (int i = 0; i < optionsList.size(); i++) {
                                            String value = optionsList.get(i);
                                            String translation = terms.get(i18nPrefix + "." + value);
                                            if (translation == null) {
                                                translation = value;
                                            }
                                            Map<String, String> term = new HashMap<>();
                                            term.put(locale.toString(), translation);
                                            i18nMap.put(value, term);
                                        }
                                        mv.set("optionsLabels", JsonUtils.getJsonFromObject(i18nMap));
                                    }
                                } catch (MissingResourceException e) {
                                    LOGGER.error(e.getMessage(), e);
                                }
                            }
                        }

                    }
                }
            } catch (IOException e) {
                LOGGER.error("Error getting the template from the stream", e);
            }

            supportedMetadata.add(new SupportedMetadataTypeBundle(id, type, version, label, template, values));
        }
    }
    return supportedMetadata;
}