Search in sources :

Example 6 with NoSuchMessageException

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);
    }
}
Also used : Locale(java.util.Locale) NoSuchMessageException(org.springframework.context.NoSuchMessageException) MessageSource(org.springframework.context.MessageSource) PersonnelServiceFacade(org.mifos.application.admin.servicefacade.PersonnelServiceFacade) NoSuchMessageException(org.springframework.context.NoSuchMessageException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException)

Example 7 with NoSuchMessageException

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));
}
Also used : XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) NoSuchMessageException(org.springframework.context.NoSuchMessageException) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 8 with NoSuchMessageException

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));
    }
}
Also used : NoSuchMessageException(org.springframework.context.NoSuchMessageException) IOException(java.io.IOException) JspTagException(javax.servlet.jsp.JspTagException)

Example 9 with NoSuchMessageException

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;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) NoSuchMessageException(org.springframework.context.NoSuchMessageException) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationSummary(org.orcid.pojo.ApplicationSummary) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

NoSuchMessageException (org.springframework.context.NoSuchMessageException)9 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 Properties (java.util.Properties)2 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 JspTagException (javax.servlet.jsp.JspTagException)1 Pair (org.apache.commons.lang3.tuple.Pair)1 PersonnelServiceFacade (org.mifos.application.admin.servicefacade.PersonnelServiceFacade)1 ConfigurationException (org.mifos.config.exceptions.ConfigurationException)1 OrcidOauth2TokenDetail (org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)1 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)1 ApplicationSummary (org.orcid.pojo.ApplicationSummary)1 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)1