logo
down
shadow

Java Multiple ResourceBundles


Java Multiple ResourceBundles

By : ThanhNienDiCho
Date : January 10 2021, 01:49 PM
This might help you I want to load multiple property files from various packages as ResourceBundle. Can I achieve that in Java , Extend java.util.PropertyResourceBundle and call setParent.
code :


Share : facebook icon twitter icon
JSP and ResourceBundles

JSP and ResourceBundles


By : user3548319
Date : March 29 2020, 07:55 AM
wish of those help Yes, the below is a copy of my answer at Is there a shorthand for ? as mentioned in Bozho's comment on your question. But since that question is actually Spring-targeted, my answer wasn't fully applicable there. Your question is however not Spring-targeted, but just plain JSP/Servlet targeted and can therefore not be closed as exact dupe. So I think the answer is better at its place here:
code :
package com.example.i18n;

import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;

public class Text extends ResourceBundle {

    private static final String TEXT_ATTRIBUTE_NAME = "text";
    private static final String TEXT_BASE_NAME = "com.example.i18n.text";

    private Text(Locale locale) {
        setLocale(locale);
    }

    public static void setFor(HttpServletRequest request) {
        if (request.getSession().getAttribute(TEXT_ATTRIBUTE_NAME) == null) {
            request.getSession().setAttribute(TEXT_ATTRIBUTE_NAME, new Text(request.getLocale()));
        }
    }

    public static Text getCurrentInstance(HttpServletRequest request) {
        return (Text) request.getSession().getAttribute(TEXT_ATTRIBUTE_NAME);
    }

    public void setLocale(Locale locale) {
        if (parent == null || !parent.getLocale().equals(locale)) {
            setParent(getBundle(TEXT_BASE_NAME, locale));
        }
    }    

    @Override
    public Enumeration<String> getKeys() {
        return parent.getKeys();
    }

    @Override
    protected Object handleGetObject(String key) {
        return parent.getObject(key);
    }

}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    Text.setFor((HttpServletRequest) request);
    chain.doFilter(request, response);
}
<p>${text['home.paragraph']}</p>
Text.getCurrentInstance(request).setLocale(newLocale);
java.util.logging, ResourceBundles, SAAJ: exception on loading Glassfish OSGi webapp bundle

java.util.logging, ResourceBundles, SAAJ: exception on loading Glassfish OSGi webapp bundle


By : Francisco Robles
Date : March 29 2020, 07:55 AM
Hope this helps Never got to the bottom of this, but manifest voodoo eventually made it go away (with all of the javax.xml.ws / javax.ws.rs packages in Import-Package rather than on the bundle classpath WEB-INF/lib).
It was also possible to work around it by using
code :
-Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl 
Multiple ResourceBundles with Spring and JSTL

Multiple ResourceBundles with Spring and JSTL


By : Sergey RIght
Date : March 29 2020, 07:55 AM
will be helpful for those in need Here's my problem: I want to organize my resource bundle files so that I have the messages in one file and the labels in another. For this I created two .properties files which I declared in my spring configuration files. The actual declaration is this: , I think the correct basenames should be:
code :
    <value>classpath:/ro/gui</value>
    <value>classpath:/strings/messages</value>
Java ResourceBundles does not read utf-8 characters correctly - after upgrading Eclipse

Java ResourceBundles does not read utf-8 characters correctly - after upgrading Eclipse


By : PhantomGam3r
Date : March 29 2020, 07:55 AM
hope this fix your issue Eventually I didn't create a new workspace - I wanted my code to work under any platform, "in any condition". So I resolved it by changing the code to use Properties instead of Resources. As input parameter I used a Reader with "utf-8" encoding set:
code :

    ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
    Resource[] fileInJar = resourceResolver.getResources(filePath);
    Properties properties = new Properties();
    BufferedReader reader = new BufferedReader(new InputStreamReader(fileInJar[0].getInputStream(), "UTF-8"));
    properties.load(reader);
Java ResourceBundles umlauts messed up

Java ResourceBundles umlauts messed up


By : Keoni Takekawa
Date : March 29 2020, 07:55 AM
I hope this helps you . ResourceBundle loads contents in ISO-8859-1 format when converted to Strings. One solution (bad-hack?) I use in my project is the following:
I get the String value, get the bytes of it and create a new String with UTF-8 encoding. This solves my issues with umlauts.
Related Posts Related Posts :
  • how to use izpack to make my jar application to installer?
  • What is meant by src in Java Eclipse?
  • Create a mirrored linked list in Java
  • Examples of good JPA Java Desktop Application
  • Translate Java to Python -- signing strings with PEM certificate files
  • Algorithm Analysis tool for java
  • Java serial comm API - what does inputstream.read() return if a timeout occurs?
  • How do I make a background thread in Java that allows the main application to exit completely? This works in Linux, but
  • How to add an image dynamically at runtime in java
  • Java App on Mac asking for allow network connections everytime
  • Best actively maintained Java XMPP Library?
  • Multi-Threaded Application - Help with some pseudo code!
  • Scoping a StringBuilder inside a for loop
  • How to specify hash algorithm when updating LDAP via Java?
  • Class not found exception (org.apache.openjpa.enhance.PersistenceCapable) thrown in a client of WLS 10
  • In Java ,where in memory are class functions put?
  • How do I test expectedExceptionsMessageRegExp (exception message) using TestNG?
  • Help In understanding Multi Dimentional Arrays
  • No bean named '...' is defined and Spring @Resource annotation
  • Singleton design pattern vs Singleton beans in Spring container
  • flashvars object was not working in mozilla browser
  • Shell script to import mysql dump file
  • What are the best practices to separate data from users
  • May I use com.google.code prefix for my packages?
  • How to set classpath in manifest file , while creating JAR from eclipse?
  • dealing with voice in java
  • Error: java.security.AccessControlException: Access denied
  • How to verify the root trust of a ceritifcate
  • Searching for a standalone JSP compiler
  • Spring 2.5 managed servlets: howto?
  • iBatis get executed sql
  • GRAPH: find an algorithm to determine the shortest path from one point to another in a rectangular maze?
  • Efficient JSON encoding for data that may be binary, but is often text
  • How to Read Java File Structure using Java?
  • Java-Hibernate-Newbie: How do I acces the values from this list?
  • Smallest executable for Windows
  • Java: matching two different type of array
  • how to accept valid e-mail id in text box?
  • How can I know where a Null Pointer Exception originated?
  • Memory limited image processing in server
  • How to serialize Java primitives using Jersey REST
  • Casting objects to Integer,string ,
  • Using Java how can I plot the path of a sprite in a straight line?
  • IntelliJ shortcut for inserting a null check?
  • Eclipselink and update trigger on multiple access to the database
  • How to ICMPs and traceroutes in Java
  • "NOT_SUPPORTED_BY_GUI" Exception in JCo
  • Controlling the order of PicoContainer startup
  • Transposing and Untransposing a String in java
  • Spring MVC- several parts/views from a controller
  • Critical tools that every Java Developer should have in his toolbelt?
  • How to get the compression ratio for a GZipped file?
  • Does TestNG has runner like SpringJUnit4ClassRunner
  • Understanding Java Wait and Notify methods
  • Sorting a text file by date - Date looks like DD/MM/YYYY
  • Subtracting days in a Calendar object
  • How to store and retrieve object of a swing component in database, java
  • Java invalid stream header Problem
  • How to send parameters with same encoding from javascript?
  • Authentication and authorization frameworks for java GUI applications
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk