当前位置: 首页>>代码示例>>Java>>正文


Java Validation类代码示例

本文整理汇总了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");
    }

}
 
开发者ID:eBay,项目名称:restcommander,代码行数:21,代码来源:Binder.java

示例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;
        }
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:31,代码来源:Controller.java

示例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;
    }
 
开发者ID:eBay,项目名称:restcommander,代码行数:22,代码来源:PlayHandler.java

示例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);
}
 
开发者ID:hdsdi3g,项目名称:MyDMAM,代码行数:21,代码来源:Manager.java

示例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();
  }
}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:36,代码来源:ProfileSinfonier.java

示例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();
}
 
开发者ID:sismics,项目名称:play-restsecure,代码行数:35,代码来源:RestSecure.java

示例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 ?)");
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:34,代码来源:PlayGrizzlyAdapter.java

示例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);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:9,代码来源:FastTags.java

示例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);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:12,代码来源:FastTags.java

示例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");
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:9,代码来源:FastTags.java

示例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") + ""));
        }
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:15,代码来源:FastTags.java

示例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;
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:12,代码来源:Scope.java

示例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 ?)");
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:34,代码来源:ServletWrapper.java

示例14: validateAndSave

import play.data.validation.Validation; //导入依赖的package包/类
public boolean validateAndSave() {
    if (Validation.current().valid(this).ok) {
        save();
        return true;
    }
    return false;
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:8,代码来源:GenericModel.java

示例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();
}
 
开发者ID:hdsdi3g,项目名称:MyDMAM,代码行数:11,代码来源:AJS_DAR_EventNew.java


注:本文中的play.data.validation.Validation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。