use of org.springframework.context.NoSuchMessageException in project head by mifos.
the class FieldConfigurationHelper method getLocalSpecificFieldNames.
public static String getLocalSpecificFieldNames(String fieldName, UserContext userContext) {
try {
String configuredLabel = getConfiguredFieldName(fieldName, userContext);
if (configuredLabel != null) {
return configuredLabel;
}
Locale locale = ApplicationContextProvider.getBean(PersonnelServiceFacade.class).getUserPreferredLocale();
return ApplicationContextProvider.getBean(MessageSource.class).getMessage(fieldName, null, locale);
} catch (NoSuchMessageException e) {
/*
* I think the theory here is that it is better to show the user
* something, than just make it an internal error. Not sure whether
* that is what is going on for sure, though.
*/
return fieldName;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.springframework.context.NoSuchMessageException in project spring-framework by spring-projects.
the class XmlWebApplicationContextTests method withoutMessageSource.
@Test
@SuppressWarnings("resource")
public void withoutMessageSource() throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setParent(root);
wac.setServletContext(sc);
wac.setNamespace("testNamespace");
wac.setConfigLocations(new String[] { "/org/springframework/web/context/WEB-INF/test-servlet.xml" });
wac.refresh();
try {
wac.getMessage("someMessage", null, Locale.getDefault());
fail("Should have thrown NoSuchMessageException");
} catch (NoSuchMessageException ex) {
// expected;
}
String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
assertTrue("Default message returned", "default".equals(msg));
}
use of org.springframework.context.NoSuchMessageException in project spring-framework by spring-projects.
the class MessageTag method doEndTag.
/**
* Resolves the message, escapes it if demanded,
* and writes it to the page (or exposes it as variable).
* @see #resolveMessage()
* @see org.springframework.web.util.HtmlUtils#htmlEscape(String)
* @see org.springframework.web.util.JavaScriptUtils#javaScriptEscape(String)
* @see #writeMessage(String)
*/
@Override
public int doEndTag() throws JspException {
try {
// Resolve the unescaped message.
String msg = resolveMessage();
// HTML and/or JavaScript escape, if demanded.
msg = htmlEscape(msg);
msg = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(msg) : msg;
// Expose as variable, if demanded, else write to the page.
if (this.var != null) {
pageContext.setAttribute(this.var, msg, TagUtils.getScope(this.scope));
} else {
writeMessage(msg);
}
return EVAL_PAGE;
} catch (IOException ex) {
throw new JspTagException(ex.getMessage(), ex);
} catch (NoSuchMessageException ex) {
throw new JspTagException(getNoSuchMessageExceptionDescription(ex));
}
}
use of org.springframework.context.NoSuchMessageException in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method getApplications.
@Override
public List<ApplicationSummary> getApplications(String orcid) {
List<OrcidOauth2TokenDetail> tokenDetails = orcidOauth2TokenService.findByUserName(orcid);
List<ApplicationSummary> applications = new ArrayList<ApplicationSummary>();
Map<Pair<String, Set<ScopePathType>>, ApplicationSummary> existingApplications = new HashMap<Pair<String, Set<ScopePathType>>, ApplicationSummary>();
if (tokenDetails != null && !tokenDetails.isEmpty()) {
for (OrcidOauth2TokenDetail token : tokenDetails) {
if (token.getTokenDisabled() == null || !token.getTokenDisabled()) {
ClientDetailsEntity client = clientDetailsEntityCacheManager.retrieve(token.getClientDetailsId());
if (client != null) {
ApplicationSummary applicationSummary = new ApplicationSummary();
// Check the scopes
Set<ScopePathType> scopesGrantedToClient = ScopePathType.getScopesFromSpaceSeparatedString(token.getScope());
Map<ScopePathType, String> scopePathMap = new HashMap<ScopePathType, String>();
String scopeFullPath = ScopePathType.class.getName() + ".";
for (ScopePathType tempScope : scopesGrantedToClient) {
try {
scopePathMap.put(tempScope, localeManager.resolveMessage(scopeFullPath + tempScope.toString()));
} catch (NoSuchMessageException e) {
LOGGER.warn("No message to display for scope " + tempScope.toString());
}
}
//If there is at least one scope in this token, fill the application summary element
if (!scopePathMap.isEmpty()) {
applicationSummary.setScopePaths(scopePathMap);
applicationSummary.setOrcidHost(orcidUrlManager.getBaseHost());
applicationSummary.setOrcidUri(orcidUrlManager.getBaseUriHttp() + "/" + client.getId());
applicationSummary.setOrcidPath(client.getId());
applicationSummary.setName(client.getClientName());
applicationSummary.setWebsiteValue(client.getClientWebsite());
applicationSummary.setApprovalDate(token.getDateCreated());
applicationSummary.setTokenId(String.valueOf(token.getId()));
// Add member information
if (!PojoUtil.isEmpty(client.getGroupProfileId())) {
ProfileEntity member = profileEntityCacheManager.retrieve(client.getGroupProfileId());
applicationSummary.setGroupOrcidPath(member.getId());
applicationSummary.setGroupName(getMemberDisplayName(member));
}
if (shouldBeAddedToTheApplicationsList(applicationSummary, scopesGrantedToClient, existingApplications)) {
applications.add(applicationSummary);
}
}
}
}
}
}
return applications;
}
Aggregations