-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
145 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.roknauta.pilot.suport; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.MessageSource; | ||
import org.springframework.context.NoSuchMessageException; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.context.i18n.LocaleContextHolder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.context.annotation.ApplicationScope; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.HashMap; | ||
|
||
@ApplicationScope // qdo for multilíngua tem que rever | ||
@Component | ||
/* | ||
* Resolve referências internas de properties e cacheia todos os properties. | ||
*/ | ||
public class Msg extends HashMap<String, String> { | ||
|
||
@Autowired | ||
@Lazy | ||
private MessageSource messageSource; | ||
|
||
private static final String START_REFERENCE = "${"; | ||
private static final String END_REFERENCE = "}"; | ||
|
||
/* | ||
* obtém o valor da chave, priorizando o properties da configuração. | ||
*/ | ||
private String _internalGet(final String key) { | ||
try { | ||
return messageSource.getMessage(key, null, LocaleContextHolder.getLocale()); | ||
} catch (NoSuchMessageException e) { | ||
return key; | ||
} | ||
|
||
} | ||
|
||
private String _get(final String key) { | ||
|
||
return _get(key, ""); | ||
} | ||
|
||
private String _get(final String key, String cacheKey) { | ||
|
||
if (super.containsKey(cacheKey)) { | ||
// se a chave já está cacheada, retorna | ||
return super.get(cacheKey); | ||
} else { | ||
// substitui as referências internas ${} | ||
String tmpKey = key; | ||
String message = _internalGet(tmpKey); | ||
// procura referência ${} e substitui. | ||
do { | ||
tmpKey = StringUtils.substringBetween(message, START_REFERENCE, END_REFERENCE); | ||
if (tmpKey == null) { | ||
break; | ||
} | ||
message = message.replace(START_REFERENCE + tmpKey + END_REFERENCE, _internalGet(tmpKey)); | ||
} while (true); | ||
|
||
// coloca a chave e valor no cache | ||
super.put(cacheKey, message); | ||
|
||
return message; | ||
} | ||
} | ||
|
||
@Override | ||
public String get(Object key) { | ||
return this._get((String) key); | ||
} | ||
|
||
public String get(String key, Object... params) { | ||
final MessageFormat format = new MessageFormat(this._get(key)); | ||
return format.format(params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" | ||
<faces-config version="4.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" | ||
version="2.0"> | ||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee | ||
https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_4_0.xsd"> | ||
<application> | ||
<resource-bundle> | ||
<base-name>messages</base-name> | ||
<var>msg</var> | ||
</resource-bundle> | ||
<locale-config> | ||
<default-locale>pt_BR</default-locale> | ||
<supported-locale>pt</supported-locale> | ||
<supported-locale>pt_BR</supported-locale> | ||
</locale-config> | ||
<!-- <el-resolver>com.logOne.agendamento.web.support.EmptyToNullStringELResolver</el-resolver>--> | ||
</application> | ||
</faces-config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:h="http://java.sun.com/jsf/html" | ||
xmlns:h="http://xmlns.jcp.org/jsf/html" | ||
xmlns:p="http://primefaces.org/ui" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> | ||
|
||
<ui:composition template="layout/template.xhtml"> | ||
<ui:define name="content"> | ||
<h:form> | ||
<p:messages id="messages" showDetail="true" closable="true"> | ||
<p:autoUpdate /> | ||
</p:messages> | ||
<h:panelGrid columns="1"> | ||
<p:outputLabel value="#{msg['name']}" for="nome"/> | ||
<p:inputText id="nome" value="#{pessoaController.nome}"/> | ||
<p:commandButton value="#{msg['save']}" action="#{pessoaController.salvar}"/> | ||
</h:panelGrid> | ||
</h:form> | ||
</ui:define> | ||
</ui:composition> | ||
<h:head> | ||
<title>#{msg['title']}</title> | ||
</h:head> | ||
<h:body> | ||
<h:form> | ||
<p:messages id="messages" showDetail="true" closable="true"> | ||
<p:autoUpdate/> | ||
</p:messages> | ||
<p:tabView dynamic="true"> | ||
<p:tab title="Cadastro"> | ||
<p:panel header="Painel"> | ||
<h:panelGrid columns="1"> | ||
<p:outputLabel value="#{msg['name']}" for="@next"/> | ||
<p:inputText id="nome" value="#{pessoaController.nome}"/> | ||
</h:panelGrid> | ||
<p:commandButton value="#{msg['save']}" action="#{pessoaController.salvar()}"/> | ||
</p:panel> | ||
</p:tab> | ||
<p:tab title="Dat"> | ||
<!--<p:panel header="Painel"> | ||
<h:panelGrid columns="1"> | ||
<p:outputLabel value="#{msg['name']}" for="@next"/> | ||
<p:inputText id="nome" value="#{pessoaController.nome}"/> | ||
</h:panelGrid> | ||
<p:commandButton value="#{msg['save']}" action="#{pessoaController.salvar()}"/> | ||
</p:panel>--> | ||
</p:tab> | ||
</p:tabView> | ||
</h:form> | ||
</h:body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.