本文整理汇总了Java中play.data.validation.Validation类的典型用法代码示例。如果您正苦于以下问题:Java Validation类的具体用法?Java Validation怎么用?Java Validation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Validation类属于play.data.validation包,在下文中一共展示了Validation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bindBean
import play.data.validation.Validation; //导入依赖的package包/类
/**
* Invokes the plugins before using the internal bindBean.
*/
public static void bindBean(RootParamNode rootParamNode, String name, Object bean) {
// Let a chance to plugins to bind this object
Object result = Play.pluginCollection.bindBean(rootParamNode, name, bean);
if (result != null) {
return;
}
ParamNode paramNode = rootParamNode.getChild(name);
try {
internalBindBean(paramNode, bean, new BindingAnnotations());
} catch (Exception e) {
Validation.addError(paramNode.getOriginalKey(), "validation.invalid");
}
}
示例2: renderTemplate
import play.data.validation.Validation; //导入依赖的package包/类
/**
* Render a specific template.
*
* @param templateName The template name.
* @param args The template data.
*/
protected static void renderTemplate(String templateName, Map<String,Object> args) {
// Template datas
Scope.RenderArgs templateBinding = Scope.RenderArgs.current();
templateBinding.data.putAll(args);
templateBinding.put("session", Scope.Session.current());
templateBinding.put("request", Http.Request.current());
templateBinding.put("flash", Scope.Flash.current());
templateBinding.put("params", Scope.Params.current());
templateBinding.put("errors", Validation.errors());
try {
Template template = TemplateLoader.load(template(templateName));
throw new RenderTemplate(template, templateBinding.data);
} catch (TemplateNotFoundException ex) {
if (ex.isSourceAvailable()) {
throw ex;
}
StackTraceElement element = PlayException.getInterestingStrackTraceElement(ex);
if (element != null) {
throw new TemplateNotFoundException(templateName, Play.classes.getApplicationClass(element.getClassName()), element.getLineNumber());
} else {
throw ex;
}
}
}
示例3: getBindingForErrors
import play.data.validation.Validation; //导入依赖的package包/类
protected static Map<String, Object> getBindingForErrors(Exception e, boolean isError) {
Map<String, Object> binding = new HashMap<String, Object>();
if (!isError) {
binding.put("result", e);
} else {
binding.put("exception", e);
}
binding.put("session", Scope.Session.current());
binding.put("request", Http.Request.current());
binding.put("flash", Scope.Flash.current());
binding.put("params", Scope.Params.current());
binding.put("play", new Play());
try {
binding.put("errors", Validation.errors());
} catch (Exception ex) {
//Logger.error(ex, "Error when getting Validation errors");
}
return binding;
}
示例4: ftpserver_export_user_sessions
import play.data.validation.Validation; //导入依赖的package包/类
@Check("adminFtpServer")
public static void ftpserver_export_user_sessions(@Required String user_session_ref) throws Exception {
if (Validation.hasErrors()) {
notFound();
}
response.contentType = "text/csv";
String contentDisposition = "%1$s; filename*=UTF-8''%2$s; filename=\"%2$s\"";
response.setHeader("Content-Disposition", String.format(contentDisposition, "attachment", "FTP_activity_" + Loggers.dateFilename(System.currentTimeMillis()) + ".csv"));
try {
FTPActivity.getAllUserActivitiesCSV(user_session_ref, response.out);
} catch (Exception e) {
if (e.getMessage().equals("noindex")) {
renderText("(No data)");
}
}
IOUtils.closeQuietly(response.out);
}
示例5: save
import play.data.validation.Validation; //导入依赖的package包/类
public static void save(@Required(message = "validation.requiere.email") String email,
@Required(message = "validation.requiere.name") String name,
@Required String preferredLang, String twitter, String organization,
String timeZone, String web) {
checkAuthenticity();
User current = getCurrentUser();
User user = DarwinFactory.getInstance().loadUser(email);
if (user != null && !Validation.hasErrors()) {
if (current.getEmail().equals(email) || current.isAdminUser()) {
Logger.debug("Edit profile "+email+", name="+name+", preferredLang="+preferredLang);
user.setName(name);
user.setPreferredLang(preferredLang);
// Save SinfonierUser fields
SinfonierUser sinfonierUser = (SinfonierUser) user.getImplementation();
sinfonierUser.setTwitter(twitter);
sinfonierUser.setOrganization(organization);
sinfonierUser.setTimeZoneID(timeZone);
sinfonierUser.setWeb(web);
user.save();
// TODO: Change render when Bug #19153 is fixed in Darwin library.
//showUserProfile(email);
render("Profile/index.html", user);
} else {
forbidden();
}
} else if (Validation.hasErrors()) {
params.flash();
render("Profile/edit.html", user);
} else {
notFound();
}
}
示例6: authenticate
import play.data.validation.Validation; //导入依赖的package包/类
public static void authenticate(@Required String username, String password, boolean remember) throws Throwable {
if (!Play.mode.isDev()) {
Validation.required("password", password);
} else {
if (password == null) {
password = "";
}
}
if (Validation.hasErrors()) {
badRequestJson();
}
// Check tokens
String userId = (String) Security.invoke("authenticate", username, password);
if (userId == null) {
validation.addError("global", "login.error");
forbiddenJson();
}
// Mark user as connected
session.put("username", userId);
// Remember if needed
if (remember) {
Date expiration = new Date();
String duration = Play.configuration.getProperty("secure.rememberme.duration","30d");
expiration.setTime(expiration.getTime() + Time.parseDuration(duration) * 1000 );
response.setCookie("rememberme", Crypto.sign(username + "-" + expiration.getTime()) + "-" + username + "-" + expiration.getTime(), duration);
}
Security.invoke("afterAuthenticate", userId);
okJson();
}
示例7: serve404
import play.data.validation.Validation; //导入依赖的package包/类
public void serve404(GrizzlyRequest request, GrizzlyResponse response, NotFound e) {
Logger.warn("404 -> %s %s (%s)", request.getMethod(), request.getRequestURI(), e.getMessage());
response.setStatus(404);
response.setContentType("text/html");
Map<String, Object> binding = new HashMap<String, Object>();
binding.put("result", e);
binding.put("session", Scope.Session.current());
binding.put("request", Http.Request.current());
binding.put("flash", Scope.Flash.current());
binding.put("params", Scope.Params.current());
binding.put("play", new Play());
try {
binding.put("errors", Validation.errors());
} catch (Exception ex) {
//
}
String format = Request.current().format;
response.setStatus(404);
// Do we have an ajax request? If we have then we want to display some text even if it is html that is requested
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With")) && (format == null || format.equals("html"))) {
format = "txt";
}
if (format == null) {
format = "txt";
}
response.setContentType(MimeTypes.getContentType("404." + format, "text/plain"));
String errorHtml = TemplateLoader.load("errors/404." + format).render(binding);
try {
response.getOutputStream().write(errorHtml.getBytes("utf-8"));
} catch (Exception fex) {
Logger.error(fex, "(utf-8 ?)");
}
}
示例8: _ifErrors
import play.data.validation.Validation; //导入依赖的package包/类
public static void _ifErrors(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
if (Validation.hasErrors()) {
body.call();
TagContext.parent().data.put("_executeNextElse", false);
} else {
TagContext.parent().data.put("_executeNextElse", true);
}
}
示例9: _ifError
import play.data.validation.Validation; //导入依赖的package包/类
public static void _ifError(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
if (args.get("arg") == null) {
throw new TemplateExecutionException(template.template, fromLine, "Please specify the error key", new TagInternalException("Please specify the error key"));
}
if (Validation.hasError(args.get("arg").toString())) {
body.call();
TagContext.parent().data.put("_executeNextElse", false);
} else {
TagContext.parent().data.put("_executeNextElse", true);
}
}
示例10: _errorClass
import play.data.validation.Validation; //导入依赖的package包/类
public static void _errorClass(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
if (args.get("arg") == null) {
throw new TemplateExecutionException(template.template, fromLine, "Please specify the error key", new TagInternalException("Please specify the error key"));
}
if (Validation.hasError(args.get("arg").toString())) {
out.print("hasError");
}
}
示例11: _error
import play.data.validation.Validation; //导入依赖的package包/类
public static void _error(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
if (args.get("arg") == null && args.get("key") == null) {
throw new TemplateExecutionException(template.template, fromLine, "Please specify the error key", new TagInternalException("Please specify the error key"));
}
String key = args.get("arg") == null ? args.get("key") + "" : args.get("arg") + "";
Error error = Validation.error(key);
if (error != null) {
if (args.get("field") == null) {
out.print(error.message());
} else {
out.print(error.message(args.get("field") + ""));
}
}
}
示例12: get
import play.data.validation.Validation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T get(String key, Class<T> type) {
try {
checkAndParse();
// TODO: This is used by the test, but this is not the most convenient.
return (T) Binder.bind(getRootParamNode(), key, type, type, null);
} catch (Exception e) {
Validation.addError(key, "validation.invalid");
return null;
}
}
示例13: serve404
import play.data.validation.Validation; //导入依赖的package包/类
public void serve404(HttpServletRequest servletRequest, HttpServletResponse servletResponse, NotFound e) {
Logger.warn("404 -> %s %s (%s)", servletRequest.getMethod(), servletRequest.getRequestURI(), e.getMessage());
servletResponse.setStatus(404);
servletResponse.setContentType("text/html");
Map<String, Object> binding = new HashMap<String, Object>();
binding.put("result", e);
binding.put("session", Scope.Session.current());
binding.put("request", Http.Request.current());
binding.put("flash", Scope.Flash.current());
binding.put("params", Scope.Params.current());
binding.put("play", new Play());
try {
binding.put("errors", Validation.errors());
} catch (Exception ex) {
//
}
String format = Request.current().format;
servletResponse.setStatus(404);
// Do we have an ajax request? If we have then we want to display some text even if it is html that is requested
if ("XMLHttpRequest".equals(servletRequest.getHeader("X-Requested-With")) && (format == null || format.equals("html"))) {
format = "txt";
}
if (format == null) {
format = "txt";
}
servletResponse.setContentType(MimeTypes.getContentType("404." + format, "text/plain"));
String errorHtml = TemplateLoader.load("errors/404." + format).render(binding);
try {
servletResponse.getOutputStream().write(errorHtml.getBytes(Response.current().encoding));
} catch (Exception fex) {
Logger.error(fex, "(encoding ?)");
}
}
示例14: validateAndSave
import play.data.validation.Validation; //导入依赖的package包/类
public boolean validateAndSave() {
if (Validation.current().valid(this).ok) {
save();
return true;
}
return false;
}
示例15: create
import play.data.validation.Validation; //导入依赖的package包/类
public void create() throws Exception {
PlayBootstrap.validate(Validation.required("name", name), Validation.min("planned_date", planned_date, DARDB.get().getPreviousSendTime()));
DAREvent event = new DAREvent();
event.creator = AJSController.getUserProfileLongName();
event.created_at = System.currentTimeMillis();
event.planned_date = planned_date;
event.name = validateEventName();
event.save();
}