Announcement Announcement Module
Collapse
No announcement yet.
How do I get all keys/messages from properties file ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I get all keys/messages from properties file ?

    Greetings everyone,

    I'm looking for a way to get all possible keys in a properties file, preferredly (is that even a word?) if I can use a prefix or something.

    Suppose I have:
    tokens_pt_BR.properties file
    Code:
    # Arquivo para internacionalização de termos (palavras, mensagens)
    titl.objService.serv_search=Tela de Pesquisa de Serviços
    titl.objService.serv_new=Tela de Inclusão de Serviços
    titl.objService.serv_edit=Tela de Edição de Serviços
    titl.objService.serv_newset=Tela de Inclusão em Lote de Serviços
    
    menu_bus_configuration=Configuração
    menu_company=Empresa
    menu_service=Serviços
    menu_category=Categoria
    menu_reason_suspension=Motivos Suspensão
    menu_research=Pesquisas
    menu_group=Grupos
    menu_password_data=Dados Senhas
    menu_hierarchy=Hierarquia
    menu_new_region=Nova Região
    menu_new_branch=Nova Agencia
    menu_tech_configuration=Configuracao Técnica
    menu_branch=Agência
    menu_terminal=Terminais
    menu_panel=Paineis
    menu_message=Mensagens
    menu_sender=Emissores
    menu_permission=Permissões
    menu_usergroup=Grupos de Usuário
    menu_user=Usuário
    
    obj_Service=Serviço
    serv_pk_id=identificador
    serv_nm_nome=nome
    serv_qt_attendanceAvgTime=Média de Atendimento (hh:mm)
    serv_qt_attendanceMaxTime=Tempo Limite de Atendimento (hh:mm)
    
    serv_new=Incluir
    serv_edit=Editar
    serv_delete=Excluir
    serv_newset=Incluir Lote
    serv_save=Salvar
    serv_cancel=Cancelar
    serv_search=Abrir
    And then I'd like to do something like:
    beans.xml
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
      <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
          <list>
            <value>tokens</value>
          </list>
        </property>
      </bean>
    </beans>
    To be used with:
    Tester.java
    Code:
    import org.springframework.context.MessageSource;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class MessageSourceTester
    {
        public static void main(String[] args) {
            MessageSource resources = new ClassPathXmlApplicationContext("beans.xml");
            List<Message> messageList = resources.getMessages();
            // or
            List<Message> messageList2 = resources.getMessages("titl.objService");
    
            for (Message m : messageList)
            {
                 System.out.println(m.getKey() + " = " + m.getValue());
            }
        }
    }
    Any clues on how to solve this ?

    Regards,

    Renato Back
Working...
X