本文整理汇总了Java中org.thymeleaf.util.Validate类的典型用法代码示例。如果您正苦于以下问题:Java Validate类的具体用法?Java Validate怎么用?Java Validate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Validate类属于org.thymeleaf.util包,在下文中一共展示了Validate类的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: populatePrimitiveValue
import org.thymeleaf.util.Validate; //导入依赖的package包/类
private static void populatePrimitiveValue(FhirContext theContext, IBaseResource theSubscription, String theChildName, String theValue) {
RuntimeResourceDefinition def = theContext.getResourceDefinition(theSubscription);
Validate.isTrue(def.getName().equals("Subscription"), "theResource is not a subscription");
BaseRuntimeChildDefinition statusChild = def.getChildByName(theChildName);
List<IBase> entries = statusChild.getAccessor().getValues(theSubscription);
IPrimitiveType<?> instance;
if (entries.size() == 0) {
BaseRuntimeElementDefinition<?> statusElement = statusChild.getChildByName(theChildName);
instance = (IPrimitiveType<?>) statusElement.newInstance(statusChild.getInstanceConstructorArguments());
statusChild.getMutator().addValue(theSubscription, instance);
} else {
instance = (IPrimitiveType<?>) entries.get(0);
}
instance.setValueAsString(theValue);
}
示例3: 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!");
}
}
示例4: 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);
}
示例5: 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;
}
示例6: 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
示例7: 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();
}
示例8: ConnectionCommand
import org.thymeleaf.util.Validate; //导入依赖的package包/类
public ConnectionCommand(Arguments arguments, String propertyString) {
this.arguments = arguments;
Validate.notEmpty(propertyString, "Invalid connection configuration");
String[] properties = propertyString.split(",");
Validate.isTrue(properties.length == 4, "Invalid connection configuration");
driver = evaluate(properties[0]);
url = evaluate(properties[1]);
username = evaluate(properties[2]);
password = evaluate(properties[3]);
}
示例9: QueryCommand
import org.thymeleaf.util.Validate; //导入依赖的package包/类
public QueryCommand(Arguments arguments, String query) {
Validate.notEmpty(query, "SQL query was not supplied");
this.query = query;
this.jdbcTemplate = (JdbcTemplate) arguments.getContext().getVariables().get(CONNECTION_ATTR_NAME);
this.params = (Object[]) arguments.getLocalVariable(PARAMS_ATTR_NAME);
this.metadataExtractor = new QueryMetadataExtractor(jdbcTemplate);
}
示例10: 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 ) );
}
示例11: 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;
}
示例12: 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;
}
}
示例13: 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;
}
}
示例14: 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;
}
}
示例15: FixedMemoryResourceResolver
import org.thymeleaf.util.Validate; //导入依赖的package包/类
public FixedMemoryResourceResolver(final String templateContent) {
Validate.notNull(templateContent, "Template content must be non-null");
this.templateContent = templateContent;
}