Java 8 ValidationEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ValidationEvent class.

This code example shows how to use the following methods:getLinkedException, getLocator, getMessage, getSeverity
	 
	private boolean valid = true;
 
	public boolean handleEvent(ValidationEvent event) {
		System.out.println("\nEVENT");
		System.out.println("SEVERITY:  " + event.getSeverity());
		System.out.println("MESSAGE:  " + event.getMessage());
		System.out.println("LINKED EXCEPTION:  " + event.getLinkedException());
		System.out.println("LOCATOR");
		System.out.println("    LINE NUMBER:  " + event.getLocator().getLineNumber());
		System.out.println("    COLUMN NUMBER:  " + event.getLocator().getColumnNumber());
		System.out.println("    OFFSET:  " + event.getLocator().getOffset());
		System.out.println("    OBJECT:  " + event.getLocator().getObject());
		System.out.println("    NODE:  " + event.getLocator().getNode());
		System.out.println("    URL:  " + event.getLocator().getURL());
		 
		if(event.getLocator().getLineNumber() != 1) // don't need to validate the root element
			valid = false;
		 
		return true; 

7
CodeRank
This code example shows how to use the following methods:getLinkedException, getLocator, getMessage, getSeverity
		return mcPreprocessorXslt;
		 
	} 
	 
    public boolean handleEvent(ValidationEvent ve) {            
      if (ve.getSeverity()==ValidationEvent.FATAL_ERROR 
       || ve.getSeverity()==ValidationEvent.ERROR){
    	   
          ValidationEventLocator  locator = ve.getLocator();
           
          //print message from validation event 
          if (log.isDebugEnabled() || ve.getMessage().length() < 120 ) {
        	  log.warn( printSeverity(ve) + ": " + ve.getMessage() );
          } else { 
        	  /* These messages are long, for example: 
        	   *  
        	   *    unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"style").  
        	   *    Expected elements are <{http://schemas.openxmlformats.org/wordprocessingml/2006/main}annotationRef>, 
        	   *    .... 
        	   *   

7
CodeRank
This code example shows how to use the following methods:getLocator, getMessage, getSeverity
package org.biojava3.aaproperties.xml; 
 
import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.bind.ValidationEventLocator;
 
public class MyValidationEventHandler implements ValidationEventHandler{
	@Override 
	public boolean handleEvent(ValidationEvent ve) {            
		if (ve.getSeverity() == ValidationEvent.FATAL_ERROR ||  ve.getSeverity() == ValidationEvent.ERROR){
			ValidationEventLocator  locator = ve.getLocator();
			//print message from valdation event 
			System.out.println("Message is " + ve.getMessage());
			//output line and column number 
			System.out.println("Column is " + locator.getColumnNumber() + " at line number " + locator.getLineNumber());
			return false; 
		} 
		return true; 
	} 
} 

6
CodeRank
This code example shows how to use the following methods:getLinkedException, getLocator, getMessage, getSeverity
 
    @Override 
    public boolean handleEvent(ValidationEvent event) {
        System.out.println("# XML SCHEMA VALIDATION FAILED: ");
        System.out.println("EVENT");
        System.out.println("SEVERITY:  " + event.getSeverity());
        System.out.println("MESSAGE:  " + event.getMessage());
        System.out.println("LINKED EXCEPTION:  " + event.getLinkedException());
        System.out.println("LOCATOR");
        System.out.println("    LINE NUMBER:  " + event.getLocator().getLineNumber());
        System.out.println("    COLUMN NUMBER:  " + event.getLocator().getColumnNumber());
        System.out.println("    OFFSET:  " + event.getLocator().getOffset());
        System.out.println("    OBJECT:  " + event.getLocator().getObject());
        System.out.println("    NODE:  " + event.getLocator().getNode());
        System.out.println("    URL:  " + event.getLocator().getURL());
        return false; 
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:getSeverity
 
		private List<ValidationEvent> events = new ArrayList<ValidationEvent>();
		 
		@Override 
		public boolean handleEvent(ValidationEvent event) {
			Logger.info("Validation event: %s", event);
			if(event.getSeverity() == ValidationEvent.ERROR || event.getSeverity() == ValidationEvent.FATAL_ERROR)
				events.add(event);
			return true; 
		} 
		 
		@Override 
		public void afterUnmarshal(Object target, Object parent) { 
			super.afterUnmarshal(target, parent); 
			if(!events.isEmpty())
				throw new UnmarshallingError(events);
		} 
	} 
	 
	@Override 
6
CodeRank
This code example shows how to use the following methods:getLocator, getMessage, getSeverity
	 
	private final static Logger logger = LoggerFactory.getLogger(MyValidationEventHandler.class); 
 
	@Override 
	public boolean handleEvent(ValidationEvent ve) {            
		if (ve.getSeverity() == ValidationEvent.FATAL_ERROR ||  ve.getSeverity() == ValidationEvent.ERROR){
			ValidationEventLocator  locator = ve.getLocator();
			//print message from valdation event 
			logger.info("Message is {}", ve.getMessage());
			//output line and column number 
			logger.info("Column is {} at line number {}", locator.getColumnNumber(), locator.getLineNumber());
			 
			return false; 
		} 
		return true; 
	} 
} 
6
CodeRank
This code example shows how to use the following methods:getLocator, getMessage
	private int columnNumber;
	private String message;
 
	@Override 
	public boolean handleEvent(ValidationEvent validationEvent) {
		ValidationEventLocator locator = validationEvent.getLocator();
		lineNumber = locator.getLineNumber();
		columnNumber = locator.getColumnNumber();
		message = validationEvent.getMessage();
		return false; 
	} 
 
	public int getLineNumber() { 
		return lineNumber;
	} 
 
	public int getColumnNumber() { 
		return columnNumber;
	} 
 
5
CodeRank
This code example shows how to use the following methods:getLocator, getMessage, getSeverity
        String errFormat = "Message is %s Column is %d at line number %d\n";
        ValidationEventLocator l;
        int lineNum;
        int colNum;
        String msg;
        if (ve.getSeverity() == ve.FATAL_ERROR
                || ve.getSeverity() == ve.ERROR) {
            l = ve.getLocator();
            lineNum = l.getLineNumber();
            colNum = l.getColumnNumber();
            msg = ve.getMessage();
            Matcher cvsMatcher = cvsRe.matcher(msg);
            if(cvsMatcher.find()) {
                msg = cvsMatcher.group(2).trim();
            } 
 
            errList.add(msg);
        } 
        return true; 
    } 
5
CodeRank
This code example shows how to use the following methods:getLocator, getMessage
		private int columnNumber;
		private String message;
 
		@Override 
		public boolean handleEvent(ValidationEvent validationEvent) {
			ValidationEventLocator locator = validationEvent.getLocator();
			lineNumber = locator.getLineNumber();
			columnNumber = locator.getColumnNumber();
			message = validationEvent.getMessage();
			return false; 
		} 
 
		public int getLineNumber() { 
			return lineNumber;
		} 
 
		public int getColumnNumber() { 
			return columnNumber;
		} 
 
5
CodeRank
This code example shows how to use the following methods:getLinkedException, getMessage
See Code Examples for Java 8 ValidationEvent Methods: