本文整理汇总了Java中org.thymeleaf.util.Validate.notNull方法的典型用法代码示例。如果您正苦于以下问题:Java Validate.notNull方法的具体用法?Java Validate.notNull怎么用?Java Validate.notNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.thymeleaf.util.Validate
的用法示例。
在下文中一共展示了Validate.notNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveMessage
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
/**
* Resolve a translated value of an object's property.
*
* @param args
* @param key
* @param messageParams
* @return the resolved message
*/
public MessageResolution resolveMessage(final Arguments args, final String key, final Object[] messageParams) {
Validate.notNull(args, "args cannot be null");
Validate.notNull(args.getContext().getLocale(), "Locale in context cannot be null");
Validate.notNull(key, "Message key cannot be null");
if (I18N_VALUE_KEY.equals(key)) {
Object entity = messageParams[0];
String property = (String) messageParams[1];
Locale locale = args.getContext().getLocale();
if (LOG.isTraceEnabled()) {
LOG.trace(String.format("Attempting to resolve translated value for object %s, property %s, locale %s",
entity, property, locale));
}
String resolvedMessage = translationService.getTranslatedValue(entity, property, locale);
if (StringUtils.isNotBlank(resolvedMessage)) {
return new MessageResolution(resolvedMessage);
}
}
return null;
}
示例2: updateJiang
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
public void updateJiang(Jiang jiang, JiangType type) {
Validate.notNull(jiang, "Jiang cannot be null");
Validate.notNull(type, "JiangType cannot be null");
switch (type) {
case MAJOR:
jiangHolder.setMajor(jiang);
if(jiang.equals(jiangHolder.getMinor())) {
jiangHolder.setMinor(null);
}
return;
case MINOR:
jiangHolder.setMinor(jiang);
if(jiang.equals(jiangHolder.getMajor())) {
jiangHolder.setMajor(null);
}
return;
default:
throw new IllegalStateException("Jiang type: " + type + " is not supported yet!");
}
}
示例3: processTemplateCode
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
public String processTemplateCode(final String code, final IContext context) {
Validate.notNull(code, "Code must be non-null");
Validate.notNull(context, "Context must be non-null");
String templateMode = StandardTemplateModeHandlers.HTML5.getTemplateModeName();
IMessageResolver messageResolver = new StandardMessageResolver();
ITemplateResolver templateResolver = new MemoryTemplateResolver(code, templateMode);
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setMessageResolver(messageResolver);
templateEngine.setTemplateResolver(templateResolver);
templateEngine.initialize();
return templateEngine.process("template", context);
}
示例4: getResourceAsStream
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* <p>
* Expected a resource location accepted by Spring's ResourceLoader.
*
* @see org.springframework.core.io.ResourceLoader
*/
@Override
public InputStream getResourceAsStream(TemplateProcessingParameters templateProcessingParameters, String resourceName) {
Validate.notNull(resourceName, "Resource name cannot be null");
try {
return rl.getResource(resourceName).getInputStream();
} catch (Exception e) {
// resource not found results in returning null, see interface documentation
}
return null;
}
示例5: computeResourceName
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
@Override
protected String computeResourceName(final TemplateProcessingParameters templateProcessingParameters) {
String themePath = null;
Theme theme = BroadleafRequestContext.getBroadleafRequestContext().getTheme();
if (theme != null && theme.getPath() != null) {
themePath = theme.getPath();
}
checkInitialized();
final String templateName = templateProcessingParameters.getTemplateName();
Validate.notNull(templateName, "Template name cannot be null");
String unaliasedName = this.getTemplateAliases().get(templateName);
if (unaliasedName == null) {
unaliasedName = templateName;
}
final StringBuilder resourceName = new StringBuilder();
String prefix = this.getPrefix();
if (prefix != null && ! prefix.trim().equals("")) {
if (themePath != null) {
resourceName.append(prefix).append(themePath).append('/').append(templateFolder);
}
}
resourceName.append(unaliasedName);
String suffix = this.getSuffix();
if (suffix != null && ! suffix.trim().equals("")) {
resourceName.append(suffix);
}
return resourceName.toString();
}
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:37,代码来源:BroadleafThymeleafServletContextTemplateResolver.java
示例6: computeResourceName
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
@Override
protected String computeResourceName(final TemplateProcessingParameters templateProcessingParameters) {
String themePath = null;
Theme theme = SparkRequestContext.getSparkRequestContext().getTheme();
if (theme != null && theme.getPath() != null) {
themePath = theme.getPath();
}
checkInitialized();
final String templateName = templateProcessingParameters.getTemplateName();
Validate.notNull(templateName, "Template name cannot be null");
String unaliasedName = this.getTemplateAliases().get(templateName);
if (unaliasedName == null) {
unaliasedName = templateName;
}
final StringBuilder resourceName = new StringBuilder();
String prefix = this.getPrefix();
if (prefix != null && ! prefix.trim().equals("")) {
if (themePath != null) {
resourceName.append(prefix).append(themePath).append('/').append(templateFolder);
}
}
resourceName.append(unaliasedName);
String suffix = this.getSuffix();
if (suffix != null && ! suffix.trim().equals("")) {
resourceName.append(suffix);
}
return resourceName.toString();
}
示例7: getResourceAsStream
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
@Override
public InputStream getResourceAsStream( TemplateProcessingParameters processingParams, String resourceName )
{
Validate.notNull( resourceName, "Resource name cannot be null" );
String templateContent = templates.get( resourceName );
if( templateContent == null )
{
return null;
}
return new ByteArrayInputStream( templateContent.getBytes( UTF_8 ) );
}
示例8: JawrDialectProcessingContextBuilder
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
public JawrDialectProcessingContextBuilder(WebApplicationContext applicationContext, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, ServletWebRequest webRequest) {
Validate.notNull(applicationContext, "WebApplicationContext cannot be null");
Validate.notNull(servletContext, "ServletContext cannot be null");
Validate.notNull(request, "HttpServletRequest cannot be null");
Validate.notNull(response, "HttpServletResponse cannot be null");
Validate.notNull(webRequest, "ServletWebRequest cannot be null");
this.applicationContext = applicationContext;
this.servletContext = servletContext;
this.request = request;
this.response = response;
this.webRequest = webRequest;
}
示例9: getResourceAsStream
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
public InputStream getResourceAsStream(final TemplateProcessingParameters templateProcessingParameters, String resourceName) {
Validate.notNull(resourceName, "Resource name cannot be null");
System.out.println(resourceName);
if (resourceName.startsWith("file:")) {
resourceName = resourceName.substring(5);
}
final File resourceFile = new File(resourceName);
try {
return new FileInputStream(resourceFile);
} catch (final Exception e) {
if (logger.isDebugEnabled()) {
if (logger.isTraceEnabled()) {
logger.trace(
String.format(
"[THYMELEAF][%s][%s] Resource \"%s\" could not be resolved. This can be normal as " +
"maybe this resource is not intended to be resolved by this resolver. " +
"Exception is provided for tracing purposes: ",
TemplateEngine.threadIndex(), templateProcessingParameters.getTemplateName(),
resourceName),
e);
} else {
logger.debug(
String.format(
"[THYMELEAF][%s][%s] Resource \"%s\" could not be resolved. This can be normal as " +
"maybe this resource is not intended to be resolved by this resolver. " +
"Exception message is provided: %s: %s",
TemplateEngine.threadIndex(), templateProcessingParameters.getTemplateName(),
resourceName, e.getClass().getName(), e.getMessage()));
}
}
return null;
}
}
示例10: resolveMessage
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public String resolveMessage(ITemplateContext context, Class<?> origin,
String key, Object[] messageParameters) {
Validate.notNull(context, "Arguments cannot be null");
Locale locale = context.getLocale();
Validate.notNull(locale, "Locale in context cannot be null");
Validate.notNull(key, "Message key cannot be null");
String templateName = context.getTemplateData().getTemplate();
LOG.trace("[THYMELEAF][{}] Resolving message with key \"{}\" for template \"{}\" and locale \"{}\". Messages will be retrieved from Spring's MessageSource infrastructure.", TemplateEngine.threadIndex(), key, templateName, locale);
try {
Map<String, Object> params = new HashMap<>();
for (int i = 0; i < messageParameters.length; i++) {
if (messageParameters[i] instanceof Map) {
// it's safe, because it's intended only for the read-only
// access by String key
params.putAll((Map) messageParameters[i]);
} else {
params.put(String.valueOf(i), messageParameters[i]);
}
}
ResourceResolutionContext resolutionContext = context(resolve(locale), params);
return resources.get(plain(key), resolutionContext)
.notNull()
.asIs();
} catch (MissingValueException e) {
// According to contract for message resolver
return null;
}
}
示例11: resolveMessage
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
@Override
public MessageResolution resolveMessage(Arguments arguments, String key,
Object[] messageParameters) {
Validate.notNull(arguments, "Arguments cannot be null");
Locale locale = arguments.getContext().getLocale();
Validate.notNull(locale, "Locale in context cannot be null");
Validate.notNull(key, "Message key cannot be null");
String templateName = arguments.getTemplateName();
LOG.trace("[THYMELEAF][{}] Resolving message with key \"{}\" for template \"{}\" and locale \"{}\". Messages will be retrieved from Spring's MessageSource infrastructure.", TemplateEngine.threadIndex(), key, templateName, locale);
try {
Map<String, Object> params = new HashMap<>();
for (int i = 0; i < messageParameters.length; i++) {
if (messageParameters[i] instanceof Map) {
params.putAll((Map) messageParameters[i]);
} else {
params.put(String.valueOf(i), messageParameters[i]);
}
}
ResourceResolutionContext context = context(resolve(locale), params);
String resolvedMessage = resources.get(plain(key), context)
.notNull()
.asIs();
// TODO: why was it here?
// resolvedMessage = resolvedMessage.replace("'", "\\'");
return new MessageResolution(resolvedMessage);
} catch (MissingValueException e) {
// According to contract for message resolver
return null;
}
}
示例12: FixedMemoryResourceResolver
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
public FixedMemoryResourceResolver(final String templateContent) {
Validate.notNull(templateContent, "Template content must be non-null");
this.templateContent = templateContent;
}
示例13: MemoryTemplateResolver
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
public MemoryTemplateResolver(final String templateContent, final String templateMode) {
Validate.notNull(templateContent, "Template content must be non-null");
Validate.notNull(templateMode, "Template mode must be non-null");
this.templateContent = templateContent;
this.templateMode = templateMode;
}
示例14: getResourceAsStream
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
@Override
public InputStream getResourceAsStream( TemplateProcessingParameters processingParams, String resourceName )
{
Validate.notNull( resourceName, "Resource name cannot be null" );
return loader.getResourceAsStream( resourceName );
}
示例15: createUserAccount
import org.thymeleaf.util.Validate; //导入方法依赖的package包/类
private void createUserAccount(UserDTO userDTO, HttpServletRequest request, HttpServletResponse response) {
List<Application> applications = applicationRepository.findByUsernameIgnoreCase(userDTO.getLogin());
List<Affiliate> affiliates = affiliateRepository.findByCreatorIgnoreCase(userDTO.getLogin());
PrimaryApplication application = new PrimaryApplication();
Affiliate affiliate = new Affiliate();
AffiliateDetails affiliateDetails = new AffiliateDetails();
MailingAddress mailingAddress = new MailingAddress();
if (applications.size() > 0) {
// FIXME MLDS-308 can we assume the first one is the primary?
application = (PrimaryApplication) applications.get(0);
}
if (affiliates.size() > 0) {
affiliate = affiliates.get(0);
}
application.setUsername(userDTO.getLogin());
affiliateDetails.setFirstName(userDTO.getFirstName());
affiliateDetails.setLastName(userDTO.getLastName());
affiliateDetails.setEmail(userDTO.getEmail());
mailingAddress.setCountry(userDTO.getCountry());
affiliateDetails.setAddress(mailingAddress);
application.setAffiliateDetails(affiliateDetails);
//set a default type for application to create affiliate and usagelog
affiliate.setCreator(userDTO.getLogin());
// MLDS-719 don't default type affiliateDetails.setType(AffiliateType.COMMERCIAL);
//affiliate.setType(AffiliateType.COMMERCIAL);
Validate.notNull(userDTO.getCountry(), "Country is mandatory");
Member member = userDTO.getCountry().getMember();
Validate.notNull(member, "Country must have a responsible member");
application.setMember(member);
affiliate.setHomeMember(member);
affiliateRepository.save(affiliate);
affiliateDetailsRepository.save(affiliateDetails);
applicationRepository.save(application);
affiliate.setApplication(application);
affiliateRepository.save(affiliate);
CommercialUsage commercialUsage = new CommercialUsage();
commercialUsage.setType(affiliate.getType());
commercialUsageResetter.detachAndReset(commercialUsage, userDTO.getInitialUsagePeriod().getStartDate(), userDTO.getInitialUsagePeriod().getEndDate());
commercialUsage = commercialUsageRepository.save(commercialUsage);
affiliate.addCommercialUsage(commercialUsage);
application.setCommercialUsage(commercialUsage);
affiliateAuditEvents.logCreationOf(affiliate);
//FIXME: JH-Add terms of service check and create new exception layer to pass back to angular
User user = userService.createUserInformation(userDTO.getLogin(), userDTO.getPassword(), userDTO.getFirstName(),
userDTO.getLastName(), userDTO.getEmail().toLowerCase(), userDTO.getLangKey(), false);
final Locale locale = Locale.forLanguageTag(user.getLangKey());
String content = createHtmlContentFromTemplate(user, locale, request, response);
mailService.sendActivationEmail(user.getEmail(), content, locale);
}