當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageSourceResolvable類代碼示例

本文整理匯總了Java中org.springframework.context.MessageSourceResolvable的典型用法代碼示例。如果您正苦於以下問題:Java MessageSourceResolvable類的具體用法?Java MessageSourceResolvable怎麽用?Java MessageSourceResolvable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MessageSourceResolvable類屬於org.springframework.context包,在下文中一共展示了MessageSourceResolvable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMessage

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
@Override
public final String getMessage(MessageSourceResolvable resolvable, Locale locale)
		throws NoSuchMessageException {

	String[] codes = resolvable.getCodes();
	if (codes == null) {
		codes = new String[0];
	}
	for (String code : codes) {
		String msg = getMessageInternal(code, resolvable.getArguments(), locale);
		if (msg != null) {
			return msg;
		}
	}
	String defaultMessage = resolvable.getDefaultMessage();
	if (defaultMessage != null) {
		return renderDefaultMessage(defaultMessage, resolvable.getArguments(), locale);
	}
	if (codes.length > 0) {
		String fallback = getDefaultMessage(codes[0]);
		if (fallback != null) {
			return fallback;
		}
	}
	throw new NoSuchMessageException(codes.length > 0 ? codes[codes.length - 1] : null, locale);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:AbstractMessageSource.java

示例2: resolveArguments

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
/**
 * Searches through the given array of objects, finds any MessageSourceResolvable
 * objects and resolves them.
 * <p>Allows for messages to have MessageSourceResolvables as arguments.
 * @param args array of arguments for a message
 * @param locale the locale to resolve through
 * @return an array of arguments with any MessageSourceResolvables resolved
 */
@Override
protected Object[] resolveArguments(Object[] args, Locale locale) {
	if (args == null) {
		return new Object[0];
	}
	List<Object> resolvedArgs = new ArrayList<Object>(args.length);
	for (Object arg : args) {
		if (arg instanceof MessageSourceResolvable) {
			resolvedArgs.add(getMessage((MessageSourceResolvable) arg, locale));
		}
		else {
			resolvedArgs.add(arg);
		}
	}
	return resolvedArgs.toArray(new Object[resolvedArgs.size()]);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:AbstractMessageSource.java

示例3: messageSourceResolvable

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
@Test
public void messageSourceResolvable() {
	// first code valid
	String[] codes1 = new String[] {"message.format.example3", "message.format.example2"};
	MessageSourceResolvable resolvable1 = new DefaultMessageSourceResolvable(codes1, null, "default");
	assertTrue("correct message retrieved", MSG_TXT3_US.equals(sac.getMessage(resolvable1, Locale.US)));

	// only second code valid
	String[] codes2 = new String[] {"message.format.example99", "message.format.example2"};
	MessageSourceResolvable resolvable2 = new DefaultMessageSourceResolvable(codes2, null, "default");
	assertTrue("correct message retrieved", MSG_TXT2_US.equals(sac.getMessage(resolvable2, Locale.US)));

	// no code valid, but default given
	String[] codes3 = new String[] {"message.format.example99", "message.format.example98"};
	MessageSourceResolvable resolvable3 = new DefaultMessageSourceResolvable(codes3, null, "default");
	assertTrue("correct message retrieved", "default".equals(sac.getMessage(resolvable3, Locale.US)));

	// no code valid, no default
	String[] codes4 = new String[] {"message.format.example99", "message.format.example98"};
	MessageSourceResolvable resolvable4 = new DefaultMessageSourceResolvable(codes4);

	exception.expect(NoSuchMessageException.class);
	sac.getMessage(resolvable4, Locale.US);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:StaticMessageSourceTests.java

示例4: requestContext

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
	assertEquals("test message", rc.getMessage("test"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null));
	assertEquals("test message", rc.getMessage("test", "default"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
	assertEquals("default", rc.getMessage("testa", "default"));
	assertEquals("default", rc.getMessage("testa", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
	assertEquals("test message", rc.getMessage(resolvable));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:MessageTagTests.java

示例5: requestContext

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
	assertEquals("theme test message", rc.getThemeMessage("themetest"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (String[]) null));
	assertEquals("theme test message", rc.getThemeMessage("themetest", "default"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (Object[]) null, "default"));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", new String[] {"arg1"}));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] {"arg1"})));
	assertEquals("default", rc.getThemeMessage("themetesta", "default"));
	assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
	assertEquals("theme test message", rc.getThemeMessage(resolvable));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:ThemeTagTests.java

示例6: convert

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
protected Warns convert(List<ObjectError> errors) {
    Warns warns = Warns.init();
    errors.forEach((oe) -> {
        String field = "";
        if (1 == oe.getCodes().length) {
            field = bindField(oe.getCodes()[0]);
        } else if (1 < oe.getCodes().length) {
            // low: プリフィックスは冗長なので外してます
            field = bindField(oe.getCodes()[1]);
        }
        List<String> args = Arrays.stream(oe.getArguments())
                .filter((arg) -> !(arg instanceof MessageSourceResolvable))
                .map(Object::toString)
                .collect(Collectors.toList());
        String message = oe.getDefaultMessage();
        if (0 <= oe.getCodes()[0].indexOf("typeMismatch")) {
            message = oe.getCodes()[2];
        }
        warns.add(field, message, args.toArray(new String[0]));
    });
    return warns;
}
 
開發者ID:jkazama,項目名稱:sample-boot-hibernate,代碼行數:23,代碼來源:RestErrorAdvice.java

示例7: api

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
@Bean
public Docket api(){
    return new Docket(DocumentationType.SWAGGER_2)
    		.useDefaultResponseMessages(false)
            .forCodeGeneration(false)
            .alternateTypeRules(
                    getAlternateTypeRule(Collection.class, WildcardType.class, List.class,
                            WildcardType.class),
                    getAlternateTypeRule(Stream.class, WildcardType.class, List.class,
                            WildcardType.class),
                    getAlternateTypeRule(DeferredResult.class, List.class, WildcardType.class,
                            List.class, WildcardType.class))
            .ignoredParameterTypes(PagedResourcesAssembler.class, Pageable.class)
            .directModelSubstitute(MessageSourceResolvable.class, String.class)
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.regex("/api/.*"))
        .build()
        .apiInfo(apiInfo());
}
 
開發者ID:bozzo,項目名稱:ipplan-api,代碼行數:21,代碼來源:SwaggerConfig.java

示例8: convertValueToText

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
@Override
public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
	{
		if (value instanceof I18nMessage) {
			return ((I18nMessage) value).i18n();
		}
		if (value instanceof MessageSourceResolvable) {
			return ((MessageSourceResolvable) value).getDefaultMessage();
		}
		String s = value.toString();
		if (s != null && s.length() > 0) {
			return s;
		}
	}
	return super.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
}
 
開發者ID:BrainTech,項目名稱:svarog,代碼行數:17,代碼來源:AbstractViewerTree.java

示例9: getColumnClass

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
@Override
public Class<?> getColumnClass(int columnIndex) {
	switch (columnIndex) {

	case INDEX_COLUMN :
			return Integer.class;

	case NAME_COLUMN :
		return String.class;

	case TYPE_COLUMN :
		return MessageSourceResolvable.class;

	case BLOCKING_COLUMN :
		return Boolean.class;

	case ENABLED_COLUMN :
		return Boolean.class;

	default :
		throw new SanityCheckException("Unsupported index [" + columnIndex + "]");

	}
}
 
開發者ID:BrainTech,項目名稱:svarog,代碼行數:25,代碼來源:AtomFilterChainTableModel.java

示例10: parse2

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
private MessageSourceResolvable parse2(String code, Object[] args, String defaultMessage) {

		List<MessageSourceResolvable> params = new ArrayList<>();

		Matcher m = pattern.matcher(code);
		boolean result = m.find();
		if (!result) {
			return new DefaultMessageSourceResolvable(new String[] { code }, getArgs(params, args), defaultMessage);
		}

		StringBuffer sb = new StringBuffer();
		do {
			String s = m.group(1);
			params.add(create(sb.toString(), s));
			m.appendReplacement(sb, "[]");
			result = m.find();
		} while (result);
		m.appendTail(sb);

		return new DefaultMessageSourceResolvable(new String[] { code, sb.toString() }, getArgs(params, args),
				defaultMessage);
	}
 
開發者ID:agwlvssainokuni,項目名稱:springapp,代碼行數:23,代碼來源:DeindexMessageSource.java

示例11: testRequestContext

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
public void testRequestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
	assertEquals("test message", rc.getMessage("test"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null));
	assertEquals("test message", rc.getMessage("test", "default"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
	assertEquals("default", rc.getMessage("testa", "default"));
	assertEquals("default", rc.getMessage("testa", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
	assertEquals("test message", rc.getMessage(resolvable));
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:17,代碼來源:MessageTagTests.java

示例12: testRequestContext

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
public void testRequestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
	assertEquals("theme test message", rc.getThemeMessage("themetest"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (String[]) null));
	assertEquals("theme test message", rc.getThemeMessage("themetest", "default"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (Object[]) null, "default"));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", new String[] {"arg1"}));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] {"arg1"})));
	assertEquals("default", rc.getThemeMessage("themetesta", "default"));
	assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
	assertEquals("theme test message", rc.getThemeMessage(resolvable));
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:17,代碼來源:ThemeTagTests.java

示例13: equals

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
@Override
public boolean equals(Object other) {
	if (this == other) {
		return true;
	}
	if (!(other instanceof MessageSourceResolvable)) {
		return false;
	}
	MessageSourceResolvable otherResolvable = (MessageSourceResolvable) other;
	return ObjectUtils.nullSafeEquals(getCodes(), otherResolvable.getCodes()) &&
			ObjectUtils.nullSafeEquals(getArguments(), otherResolvable.getArguments()) &&
			ObjectUtils.nullSafeEquals(getDefaultMessage(), otherResolvable.getDefaultMessage());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:DefaultMessageSourceResolvable.java

示例14: getMessage

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
@Override
public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
	if (this.parentMessageSource != null) {
		return this.parentMessageSource.getMessage(resolvable, locale);
	}
	else {
		if (resolvable.getDefaultMessage() != null) {
			return renderDefaultMessage(resolvable.getDefaultMessage(), resolvable.getArguments(), locale);
		}
		String[] codes = resolvable.getCodes();
		String code = (codes != null && codes.length > 0 ? codes[0] : null);
		throw new NoSuchMessageException(code, locale);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:DelegatingMessageSource.java

示例15: getArguments

import org.springframework.context.MessageSourceResolvable; //導入依賴的package包/類
/**
 * For some reason Spring puts MessageSourceResolvable as argument so need to remove it
 */
private List<String> getArguments(ObjectError error) {
	if (error.getArguments() == null) {
		return emptyList();
	}
	return Arrays.stream(error.getArguments())
			.filter(arg -> !(arg instanceof MessageSourceResolvable))
			.map(Object::toString)
			.collect(toList());
}
 
開發者ID:TulevaEE,項目名稱:onboarding-service,代碼行數:13,代碼來源:InputErrorsConverter.java


注:本文中的org.springframework.context.MessageSourceResolvable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。