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.b3log.latke.service.LangPropsService.java

/**
 * Gets all language properties as a map by the specified locale.
 *
 * @param locale the specified locale/*from   ww  w. j  a  va  2  s  .  co  m*/
 * @return a map of language configurations
 */
public Map<String, String> getAll(final Locale locale) {
    Map<String, String> ret = LANGS.get(locale);

    if (null == ret) {
        ret = new HashMap<String, String>();
        ResourceBundle langBundle;

        try {
            langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, locale);
        } catch (final MissingResourceException e) {
            LOGGER.log(Level.WARNING, "{0}, using default locale[{1}] instead",
                    new Object[] { e.getMessage(), Latkes.getLocale() });

            try {
                langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, Latkes.getLocale());
            } catch (final MissingResourceException ex) {
                LOGGER.log(Level.WARNING, "{0}, using default lang.properties instead",
                        new Object[] { e.getMessage() });
                langBundle = ResourceBundle.getBundle(Keys.LANGUAGE);
            }
        }

        final Enumeration<String> keys = langBundle.getKeys();

        while (keys.hasMoreElements()) {
            final String key = keys.nextElement();
            final String value = langBundle.getString(key);

            ret.put(key, value);
        }

        LANGS.put(locale, ret);
    }

    return ret;
}

From source file:com.cws.esolutions.security.filters.SessionAuthenticationFilter.java

public void init(final FilterConfig filterConfig) throws ServletException {
    final String methodName = SessionAuthenticationFilter.CNAME
            + "#init(final FilterConfig filterConfig) throws ServletException";

    if (DEBUG) {/*  w  ww  .j  a  v a  2 s . c o  m*/
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("FilterConfig: {}", filterConfig);
    }

    ResourceBundle rBundle = null;

    try {
        if (filterConfig.getInitParameter(SessionAuthenticationFilter.FILTER_CONFIG_PARAM_NAME) == null) {
            ERROR_RECORDER.error("Filter configuration not found. Using default !");

            rBundle = ResourceBundle.getBundle(SessionAuthenticationFilter.FILTER_CONFIG_FILE_NAME);
        } else {
            rBundle = ResourceBundle.getBundle(
                    filterConfig.getInitParameter(SessionAuthenticationFilter.FILTER_CONFIG_PARAM_NAME));
        }

        this.loginURI = rBundle.getString(SessionAuthenticationFilter.LOGIN_URI);
        this.passwordURI = rBundle.getString(SessionAuthenticationFilter.PASSWORD_URI);
        this.ignoreURIs = (StringUtils
                .isNotEmpty(rBundle.getString(SessionAuthenticationFilter.IGNORE_URI_LIST)))
                        ? rBundle.getString(SessionAuthenticationFilter.IGNORE_URI_LIST).trim().split(",")
                        : null;

        if (DEBUG) {
            if (this.ignoreURIs != null) {
                for (String str : this.ignoreURIs) {
                    DEBUGGER.debug(str);
                }
            }
        }
    } catch (MissingResourceException mre) {
        ERROR_RECORDER.error(mre.getMessage(), mre);

        throw new UnavailableException(mre.getMessage());
    }
}

From source file:org.pentaho.reporting.engine.classic.core.filter.ResourceMessageFormatFilter.java

/**
 * Returns the current value for the data source.
 *
 * @param runtime/* www .  j a  v a  2 s. com*/
 *          the expression runtime that is used to evaluate formulas and expressions when computing the value of this
 *          filter.
 * @param element
 * @return the value.
 */
public Object getValue(final ExpressionRuntime runtime, final ReportElement element) {
    if (runtime == null) {
        return null;
    }
    final String resourceId;
    if (resourceIdentifier != null) {
        resourceId = resourceIdentifier;
    } else {
        resourceId = runtime.getConfiguration()
                .getConfigProperty(ResourceBundleFactory.DEFAULT_RESOURCE_BUNDLE_CONFIG_KEY);
    }

    if (resourceId == null) {
        return null;
    }

    try {
        final ResourceBundleFactory resourceBundleFactory = runtime.getResourceBundleFactory();
        final ResourceBundle bundle = resourceBundleFactory.getResourceBundle(resourceId);

        // update the format string, if neccessary ...
        if (ObjectUtilities.equal(formatKey, appliedFormatKey) == false) {
            final String newFormatString = bundle.getString(formatKey);
            messageFormatSupport.setFormatString(newFormatString);
            appliedFormatKey = formatKey;
        }

        messageFormatSupport.setLocale(resourceBundleFactory.getLocale());
        messageFormatSupport.setTimeZone(resourceBundleFactory.getTimeZone());
        return messageFormatSupport.performFormat(runtime.getDataRow());
    } catch (MissingResourceException mre) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to format the value for resource-id " + resourceId + ", was '"
                    + mre.getMessage() + "'");
        }
        return null;
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to format the value for resource-id " + resourceId, e);
        }
        return null;
    }
}

From source file:net.jcreate.e3.table.message.ResourceBundleMessageSource.java

/**
 * Return a ResourceBundle for the given basename and code,
 * fetching already generated MessageFormats from the cache.
 * @param basename the basename of the ResourceBundle
 * @param locale the Locale to find the ResourceBundle for
 * @return the resulting ResourceBundle, or <code>null</code> if none
 * found for the given basename and Locale
 *///from w  w  w . ja v  a 2  s.co m
protected ResourceBundle getResourceBundle(String basename, Locale locale) {
    synchronized (this.cachedResourceBundles) {
        Map localeMap = (Map) this.cachedResourceBundles.get(basename);
        if (localeMap != null) {
            ResourceBundle bundle = (ResourceBundle) localeMap.get(locale);
            if (bundle != null) {
                return bundle;
            }
        }
        try {
            ResourceBundle bundle = doGetBundle(basename, locale);
            if (localeMap == null) {
                localeMap = new HashMap();
                this.cachedResourceBundles.put(basename, localeMap);
            }
            localeMap.put(locale, bundle);
            return bundle;
        } catch (MissingResourceException ex) {
            if (logger.isWarnEnabled()) {
                logger.warn(
                        "ResourceBundle [" + basename + "] not found for MessageSource: " + ex.getMessage());
            }
            // Assume bundle not found
            // -> do NOT throw the exception to allow for checking parent message source.
            return null;
        }
    }
}

From source file:com.liferay.portal.servlet.PortletContextListener.java

public void contextInitialized(ServletContextEvent sce) {
    try {//from w  w  w.j a  va  2s . co  m

        // Servlet context

        ServletContext ctx = sce.getServletContext();

        _servletContextName = StringUtil.replace(ctx.getServletContextName(), StringPool.SPACE,
                StringPool.UNDERLINE);

        // Company ids

        _companyIds = StringUtil.split(ctx.getInitParameter("company_id"));

        // Class loader

        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();

        // Initialize portlets

        String[] xmls = new String[] { Http.URLtoString(ctx.getResource("/WEB-INF/portlet.xml")),
                Http.URLtoString(ctx.getResource("/WEB-INF/liferay-portlet.xml")) };

        _portlets = PortletManagerUtil.initWAR(_servletContextName, xmls);

        // Portlet context wrapper

        Iterator itr1 = _portlets.iterator();

        while (itr1.hasNext()) {
            Portlet portlet = (Portlet) itr1.next();

            javax.portlet.Portlet portletInstance = (javax.portlet.Portlet) contextClassLoader
                    .loadClass(portlet.getPortletClass()).newInstance();

            Indexer indexerInstance = null;
            if (Validator.isNotNull(portlet.getIndexerClass())) {
                indexerInstance = (Indexer) contextClassLoader.loadClass(portlet.getIndexerClass())
                        .newInstance();
            }

            Scheduler schedulerInstance = null;
            if (Validator.isNotNull(portlet.getSchedulerClass())) {
                schedulerInstance = (Scheduler) contextClassLoader.loadClass(portlet.getSchedulerClass())
                        .newInstance();
            }

            PreferencesValidator prefsValidator = null;
            if (Validator.isNotNull(portlet.getPreferencesValidator())) {
                prefsValidator = (PreferencesValidator) contextClassLoader
                        .loadClass(portlet.getPreferencesValidator()).newInstance();

                try {
                    if (GetterUtil.getBoolean(PropsUtil.get(PropsUtil.PREFERENCE_VALIDATE_ON_STARTUP))) {

                        prefsValidator.validate(
                                PortletPreferencesSerializer.fromDefaultXML(portlet.getDefaultPreferences()));
                    }
                } catch (Exception e1) {
                    _log.warn("Portlet with the name " + portlet.getPortletId()
                            + " does not have valid default preferences");
                }
            }

            Map resourceBundles = null;

            if (Validator.isNotNull(portlet.getResourceBundle())) {
                resourceBundles = CollectionFactory.getHashMap();

                Iterator itr2 = portlet.getSupportedLocales().iterator();

                while (itr2.hasNext()) {
                    String supportedLocale = (String) itr2.next();

                    Locale locale = new Locale(supportedLocale);

                    try {
                        ResourceBundle resourceBundle = ResourceBundle.getBundle(portlet.getResourceBundle(),
                                locale, contextClassLoader);

                        resourceBundles.put(locale.getLanguage(), resourceBundle);
                    } catch (MissingResourceException mre) {
                        _log.warn(mre.getMessage());
                    }
                }
            }

            Map customUserAttributes = CollectionFactory.getHashMap();

            Iterator itr2 = portlet.getCustomUserAttributes().entrySet().iterator();

            while (itr2.hasNext()) {
                Map.Entry entry = (Map.Entry) itr2.next();

                String attrName = (String) entry.getKey();
                String attrCustomClass = (String) entry.getValue();

                customUserAttributes.put(attrCustomClass,
                        contextClassLoader.loadClass(attrCustomClass).newInstance());
            }

            PortletContextWrapper pcw = new PortletContextWrapper(portlet.getPortletId(), ctx, portletInstance,
                    indexerInstance, schedulerInstance, prefsValidator, resourceBundles, customUserAttributes);

            PortletContextPool.put(portlet.getPortletId(), pcw);
        }

        // Portlet class loader

        String servletPath = ctx.getRealPath("/");
        if (!servletPath.endsWith("/") && !servletPath.endsWith("\\")) {
            servletPath += "/";
        }

        File servletClasses = new File(servletPath + "WEB-INF/classes");
        File servletLib = new File(servletPath + "WEB-INF/lib");

        List urls = new ArrayList();

        if (servletClasses.exists()) {
            urls.add(new URL("file:" + servletClasses + "/"));
        }

        if (servletLib.exists()) {
            String[] jars = FileUtil.listFiles(servletLib);

            for (int i = 0; i < jars.length; i++) {
                urls.add(new URL("file:" + servletLib + "/" + jars[i]));
            }
        }

        URLClassLoader portletClassLoader = new URLClassLoader((URL[]) urls.toArray(new URL[0]),
                contextClassLoader);

        ctx.setAttribute(WebKeys.PORTLET_CLASS_LOADER, portletClassLoader);

        // Portlet display

        String xml = Http.URLtoString(ctx.getResource("/WEB-INF/liferay-display.xml"));

        Map newCategories = PortletManagerUtil.getWARDisplay(_servletContextName, xml);

        for (int i = 0; i < _companyIds.length; i++) {
            String companyId = _companyIds[i];

            Map oldCategories = (Map) WebAppPool.get(companyId, WebKeys.PORTLET_DISPLAY);

            Map mergedCategories = PortalUtil.mergeCategories(oldCategories, newCategories);

            WebAppPool.put(companyId, WebKeys.PORTLET_DISPLAY, mergedCategories);
        }

        // Reinitialize portal properties

        PropsUtil.init();
    } catch (Exception e2) {
        Logger.error(this, e2.getMessage(), e2);
    }
}

From source file:org.exoplatform.wcm.webui.scv.UIPresentationContainer.java

public String getCurrentState() throws Exception {
    UIPresentation presentation = getChild(UIPresentation.class);
    Node node = presentation.getOriginalNode();
    if (node != null) {
        if (node.hasProperty("publication:currentState")) {
            PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance();
            String state = node.getProperty("publication:currentState").getValue().getString();
            try {
                state = portletRequestContext.getApplicationResourceBundle()
                        .getString("PublicationStates." + state);
            } catch (MissingResourceException e) {
                if (LOG.isWarnEnabled()) {
                    LOG.warn(e.getMessage());
                }//w  ww. ja  v a2s .c  om
            }
            return state;
        }
    }
    return "";
}

From source file:org.jahia.services.render.filter.MarkedForDeletionFilter.java

protected String getTemplateOutput(RenderContext renderContext, Resource resource) {
    String out = StringUtils.EMPTY;
    try {/*from w  w  w.j av  a2  s  .  co  m*/
        String template = getTemplateContent();
        resolvedTemplate = null;

        if (StringUtils.isEmpty(template)) {
            return StringUtils.EMPTY;
        }

        ScriptEngine engine = ScriptEngineUtils.getInstance().scriptEngine(templateExtension);
        ScriptContext ctx = new SimpleScriptContext();
        ctx.setWriter(new StringWriter());
        Bindings bindings = engine.createBindings();
        bindings.put("renderContext", renderContext);
        bindings.put("resource", resource);
        final ResourceBundle bundle = ResourceBundles.getInternal(renderContext.getUILocale());
        bindings.put("bundle", bundle);
        bindings.put("i18n", LazyMap.decorate(new HashMap<String, String>(2), new Transformer() {
            public Object transform(Object input) {
                String value = null;
                String key = String.valueOf(input);
                try {
                    value = bundle.getString(key);
                } catch (MissingResourceException e) {
                    value = key;
                }
                return value;
            }
        }));

        ctx.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

        engine.eval(template, ctx);
        out = ((StringWriter) ctx.getWriter()).getBuffer().toString();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return out;
}

From source file:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.java

private ByteArrayInputStream doMetadataRequest(LSID lsid) throws LSIDServerException {
    logger.debug("getting metadata for lsid " + lsid.getLsid());

    try {/*ww w . j  a  va  2s  .c  om*/

        LSIDDataLookup myLookup = new LSIDDataLookup();
        InputStream content = myLookup.lsidData(lsid);
        InputStream content2 = myLookup.lsidData(lsid);
        if (!isEML(content2)) {
            content = getEML(lsid);
        }
        content2.close();
        setCurrentLSID(lsid);

        // based on the doctype choose the appropriate stylesheet
        String styleSheetName = null;
        String _docType = myLookup.getDocType(lsid);

        try {
            ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
            styleSheetName = rb.getString(_docType.replaceAll(":", ""));
        } catch (java.util.MissingResourceException mre) {
            logger.warn("there is no style corresponding to: '" + _docType + "' -- using default");
            styleSheetName = this.DEFAULT_STYLESHEET;
            mre.getMessage();
        }
        InputStream styleSheet = getClass().getResourceAsStream(styleSheetName);
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer(new StreamSource(styleSheet));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        transformer.transform(new StreamSource(content), new StreamResult(out));
        content.close();
        clearState();
        return new ByteArrayInputStream(out.toByteArray());
    } catch (Exception e) {
        throw new LSIDServerException(e, "Error transforming XML for: " + lsid);
    }
}

From source file:de.innovationgate.wgpublisher.webtml.Item.java

/**
* Method getCustomEditor.// ww w  .ja  va2s . c om
* @param editor
* @return Editor code as String
 * @throws WGException 
* @throws UnsupportedEncodingException 
*/
private String getCustomEditorCode() throws WGException {

    FormStatus status = getFormStatus();

    // Calculate output

    PropertyResourceBundle labels = null;
    try {
        labels = (PropertyResourceBundle) ResourceBundle.getBundle(
                "de.innovationgate.wgpublisher.labels.common", pageContext.getRequest().getLocale(),
                this.getClass().getClassLoader());
    } catch (MissingResourceException e) {
        System.out.println(e.getMessage());
    }

    status.mode = TMLFormInfo.EDIT_MODE;

    String frmId = status.formInfo.getFormId();

    StringBuffer editorCode = new StringBuffer("");
    String LS = System.getProperty("line.separator");

    editorCode.append(LS);
    editorCode.append("<div class=\"WGA-Custom-Form\" style=\"display:none;\">");
    editorCode.append(LS);

    StringBuffer submitCode = new StringBuffer();
    submitCode.append("callAction('");
    String action = buildCallActionLink(getSaveaction(), frmId, null, null, null, null);
    submitCode.append(action);
    submitCode.append("')");

    String formStartTag = renderFormStartTag(frmId, submitCode.toString(), "display:inline", null);
    editorCode.append(formStartTag);

    String prefix = this.getPrefix();
    this.setPrefix("");
    editorCode.append(this.getResultString(false));
    this.setPrefix(prefix);

    editorCode.append(renderFormInfo(status.formInfo, this.getTMLContext()));
    editorCode.append(LS);

    editorCode.append(renderAdditionHiddenFormFields());
    editorCode.append(LS);
    editorCode.append("&nbsp;");
    editorCode.append(LS);
    editorCode.append(renderFormEndTag());
    editorCode.append(LS);
    editorCode.append("</div>");

    if (status.thisForm.hasmessages()) {
        editorCode.append("<div class=\"WGA-Custom-Form-Errors\" style=\"display:none;\">");
        for (String message : (List<String>) status.thisForm.getmessages()) {
            editorCode.append(
                    "<div class=\"WGA-Custom-Form-Error-Message\">" + WGUtils.encodeHTML(message) + "</div>");
        }

        editorCode.append("</div>");
    }

    return editorCode.toString();
}

From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTableModel.java

/**
 * Method Declaration.//  w w  w.j  av  a 2 s  . c  o m
 *
 *
 * @param col
 *
 * @return
 *
 * @see
 */
public String getColumnName(int col) {
    if (cachedColumnNames[col] != null) {
        return cachedColumnNames[col];
    }

    String columnName = null;
    String localizedColumnName = null;

    try {
        columnName = ((SearchResultsColumnType) srCols.get(col)).getColumnHeader();
        localizedColumnName = resourceBundle.getString("columnName." + columnName.replaceAll(" ", ""));
    } catch (MissingResourceException ex) {
        System.out.println("Missed: " + columnName);

        localizedColumnName = columnName;
    } catch (IndexOutOfBoundsException ex) {
        log.warn(resourceBundle.getString("error.outOfBounds") + ex.getMessage());
    }

    cachedColumnNames[col] = localizedColumnName;
    return localizedColumnName;
}