下面列出了javax.xml.bind.ValidationEvent#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Reports an error to the user, and asks if s/he wants
* to recover. If the canRecover flag is false, regardless
* of the client instruction, an exception will be thrown.
*
* Only if the flag is true and the user wants to recover from an error,
* the method returns normally.
*
* The thrown exception will be catched by the unmarshaller.
*/
public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
ValidationEventHandler eventHandler = parent.getEventHandler();
boolean recover = eventHandler.handleEvent(event);
// if the handler says "abort", we will not return the object
// from the unmarshaller.getResult()
if(!recover) aborted = true;
if( !canRecover || !recover )
throw new SAXParseException2( event.getMessage(), locator,
new UnmarshalException(
event.getMessage(),
event.getLinkedException() ) );
}
public void reportError( ValidationEvent ve ) throws SAXException {
ValidationEventHandler handler;
try {
handler = marshaller.getEventHandler();
} catch( JAXBException e ) {
throw new SAXException2(e);
}
if(!handler.handleEvent(ve)) {
if(ve.getLinkedException() instanceof Exception)
throw new SAXException2((Exception)ve.getLinkedException());
else
throw new SAXException2(ve.getMessage());
}
}
/**
* Reports an error to the user, and asks if s/he wants
* to recover. If the canRecover flag is false, regardless
* of the client instruction, an exception will be thrown.
*
* Only if the flag is true and the user wants to recover from an error,
* the method returns normally.
*
* The thrown exception will be catched by the unmarshaller.
*/
public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
ValidationEventHandler eventHandler = parent.getEventHandler();
boolean recover = eventHandler.handleEvent(event);
// if the handler says "abort", we will not return the object
// from the unmarshaller.getResult()
if(!recover) aborted = true;
if( !canRecover || !recover )
throw new SAXParseException2( event.getMessage(), locator,
new UnmarshalException(
event.getMessage(),
event.getLinkedException() ) );
}
/**
* Rather than ignore any XML parsing events, we will log these with a
* short message indicating where the parsing failed accompanied with
* a corresponding stack trace. An exception is not being thrown
* because the events could be benign and we would not want to halt
* execution of the process. For example, if the Amazon Pay API's
* started returning a new element in the XML that the SDK did not
* know about, that's OK, and we don't want to kill the program
* because something new is discovered.
*/
public boolean handleEvent(ValidationEvent event) {
try {
String message = "XML Parse Event at "
+ "Line " + event.getLocator().getLineNumber()
+ ", Column " + event.getLocator().getColumnNumber()
+ ": Message=" + event.getMessage();
StringWriter sw = new StringWriter();
new Exception(message).printStackTrace(new PrintWriter(sw));
log.debug(sw.toString());
} catch (Exception e) {
throw new AmazonClientException("Encountered an Exception: ", e);
}
return true;
}
public void reportError( ValidationEvent ve ) throws SAXException {
ValidationEventHandler handler;
try {
handler = marshaller.getEventHandler();
} catch( JAXBException e ) {
throw new SAXException2(e);
}
if(!handler.handleEvent(ve)) {
if(ve.getLinkedException() instanceof Exception)
throw new SAXException2((Exception)ve.getLinkedException());
else
throw new SAXException2(ve.getMessage());
}
}
/**
* Reports an error to the user, and asks if s/he wants
* to recover. If the canRecover flag is false, regardless
* of the client instruction, an exception will be thrown.
*
* Only if the flag is true and the user wants to recover from an error,
* the method returns normally.
*
* The thrown exception will be catched by the unmarshaller.
*/
public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
ValidationEventHandler eventHandler = parent.getEventHandler();
boolean recover = eventHandler.handleEvent(event);
// if the handler says "abort", we will not return the object
// from the unmarshaller.getResult()
if(!recover) aborted = true;
if( !canRecover || !recover )
throw new SAXParseException2( event.getMessage(), locator,
new UnmarshalException(
event.getMessage(),
event.getLinkedException() ) );
}
/**
* Reports an error to the user, and asks if s/he wants
* to recover. If the canRecover flag is false, regardless
* of the client instruction, an exception will be thrown.
*
* Only if the flag is true and the user wants to recover from an error,
* the method returns normally.
*
* The thrown exception will be catched by the unmarshaller.
*/
public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
ValidationEventHandler eventHandler = parent.getEventHandler();
boolean recover = eventHandler.handleEvent(event);
// if the handler says "abort", we will not return the object
// from the unmarshaller.getResult()
if(!recover) aborted = true;
if( !canRecover || !recover )
throw new SAXParseException2( event.getMessage(), locator,
new UnmarshalException(
event.getMessage(),
event.getLinkedException() ) );
}
public void reportError( ValidationEvent ve ) throws SAXException {
ValidationEventHandler handler;
try {
handler = marshaller.getEventHandler();
} catch( JAXBException e ) {
throw new SAXException2(e);
}
if(!handler.handleEvent(ve)) {
if(ve.getLinkedException() instanceof Exception)
throw new SAXException2((Exception)ve.getLinkedException());
else
throw new SAXException2(ve.getMessage());
}
}
/**
* Reports an error to the user, and asks if s/he wants
* to recover. If the canRecover flag is false, regardless
* of the client instruction, an exception will be thrown.
*
* Only if the flag is true and the user wants to recover from an error,
* the method returns normally.
*
* The thrown exception will be catched by the unmarshaller.
*/
public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
ValidationEventHandler eventHandler = parent.getEventHandler();
boolean recover = eventHandler.handleEvent(event);
// if the handler says "abort", we will not return the object
// from the unmarshaller.getResult()
if(!recover) aborted = true;
if( !canRecover || !recover )
throw new SAXParseException2( event.getMessage(), locator,
new UnmarshalException(
event.getMessage(),
event.getLinkedException() ) );
}
public void reportError( ValidationEvent ve ) throws SAXException {
ValidationEventHandler handler;
try {
handler = marshaller.getEventHandler();
} catch( JAXBException e ) {
throw new SAXException2(e);
}
if(!handler.handleEvent(ve)) {
if(ve.getLinkedException() instanceof Exception)
throw new SAXException2((Exception)ve.getLinkedException());
else
throw new SAXException2(ve.getMessage());
}
}
/**
* Reports an error to the user, and asks if s/he wants
* to recover. If the canRecover flag is false, regardless
* of the client instruction, an exception will be thrown.
*
* Only if the flag is true and the user wants to recover from an error,
* the method returns normally.
*
* The thrown exception will be catched by the unmarshaller.
*/
public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
ValidationEventHandler eventHandler = parent.getEventHandler();
boolean recover = eventHandler.handleEvent(event);
// if the handler says "abort", we will not return the object
// from the unmarshaller.getResult()
if(!recover) aborted = true;
if( !canRecover || !recover )
throw new SAXParseException2( event.getMessage(), locator,
new UnmarshalException(
event.getMessage(),
event.getLinkedException() ) );
}
public void reportError( ValidationEvent ve ) throws SAXException {
ValidationEventHandler handler;
try {
handler = marshaller.getEventHandler();
} catch( JAXBException e ) {
throw new SAXException2(e);
}
if(!handler.handleEvent(ve)) {
if(ve.getLinkedException() instanceof Exception)
throw new SAXException2((Exception)ve.getLinkedException());
else
throw new SAXException2(ve.getMessage());
}
}
public String getValidationEventsAsString() {
String s = "";
for (ValidationEvent event : validationEvents) {
s += event.getMessage() + "\n";
}
return s;
}
public boolean handleEvent(ValidationEvent event) {
// CXF-1194/CXF-7438 this hack is specific to MTOM, so pretty safe to leave in
// here before calling the origHandler.
String msg = event.getMessage();
if ((msg.startsWith("cvc-type.3.1.2") || msg.startsWith("cvc-complex-type.2.2"))
&& msg.contains(marshaller.getLastMTOMElementName().getLocalPart())) {
return true;
}
if (origHandler != null) {
return origHandler.handleEvent(event);
}
return false;
}
@Override
public boolean handleEvent(ValidationEvent event) {
if (event.getSeverity() == ValidationEvent.FATAL_ERROR || event.getSeverity() == ValidationEvent.ERROR) {
ValidationEventLocator locator = event.getLocator();
String message = event.getMessage();
int line = locator.getLineNumber();
int column = locator.getColumnNumber();
log.error("Error at [line=" + line + ", column=" + column + "]: " + message);
throw new Error(event.getLinkedException());
}
return true;
}
@Override
public boolean handleEvent(ValidationEvent ve) {
String msg = ve.getMessage();
ValidationEventLocator vel = ve.getLocator();
Node node = vel.getNode();
String name = node!=null?node.getLocalName():"null";
logger.error( "node : {}.{}: {}", name, vel.getOffset(), msg );
return false;
}
@Override
public boolean handleEvent(ValidationEvent ve) {
String msg = ve.getMessage();
ValidationEventLocator vel = ve.getLocator();
logger.error( "location : {}.{}: {}", vel.getLineNumber(), vel.getColumnNumber(), msg );
return false;
}
public boolean handleEvent(ValidationEvent event) {
// if the original handler has already handled the event, no need for us
// to do anything, otherwise if not yet handled, then do this 'hack'
if (origHandler != null && origHandler.handleEvent(event)) {
return true;
}
// hack for CXF-3453
String msg = event.getMessage();
return msg != null
&& msg.contains(":Id")
&& (msg.startsWith("cvc-type.3.1.1")
|| msg.startsWith("cvc-type.3.2.2")
|| msg.startsWith("cvc-complex-type.3.1.1")
|| msg.startsWith("cvc-complex-type.3.2.2"));
}
@Override
public boolean handleEvent(ValidationEvent validationEvent) {
ValidationEventLocator locator = validationEvent.getLocator();
lineNumber = locator.getLineNumber();
columnNumber = locator.getColumnNumber();
message = validationEvent.getMessage();
return false;
}
public final boolean handleEvent (@Nonnull final ValidationEvent aEvent)
{
final IErrorLevel aErrorLevel = getErrorLevel (aEvent.getSeverity ());
final SingleErrorBuilder aErrBuilder = SingleError.builder ().setErrorLevel (aErrorLevel);
final ValidationEventLocator aLocator = aEvent.getLocator ();
aErrBuilder.setErrorLocation (new SimpleLocation (getLocationResourceID (aLocator),
aLocator != null ? aLocator.getLineNumber ()
: ILocation.ILLEGAL_NUMBER,
aLocator != null ? aLocator.getColumnNumber ()
: ILocation.ILLEGAL_NUMBER))
.setErrorFieldName (getErrorFieldName (aLocator));
// Message may be null in some cases (e.g. when a linked exception is
// present), but is not allowed to be null!
String sMsg = aEvent.getMessage ();
if (sMsg == null)
{
if (aEvent.getLinkedException () != null)
{
sMsg = aEvent.getLinkedException ().getMessage ();
if (sMsg == null)
sMsg = "Exception";
}
else
{
// Does this ever happen????
sMsg = "Validation event";
}
}
aErrBuilder.setErrorText (sMsg).setLinkedException (aEvent.getLinkedException ());
// call our callback
onEvent (aErrBuilder.build ());
// Continue processing?
return continueProcessing (aErrorLevel);
}