本文整理汇总了Java中javax.xml.bind.ValidationEvent.getLocator方法的典型用法代码示例。如果您正苦于以下问题:Java ValidationEvent.getLocator方法的具体用法?Java ValidationEvent.getLocator怎么用?Java ValidationEvent.getLocator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.bind.ValidationEvent
的用法示例。
在下文中一共展示了ValidationEvent.getLocator方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleEvent
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
@Override
public boolean handleEvent(ValidationEvent event) {
try {
System.out.println("\nEVENT");
System.out.println("SEVERITY: " + event.getSeverity());
System.out.println("MESSAGE: " + event.getMessage());
System.out.println("LINKED EXCEPTION: " + event.getLinkedException());
if (event.getLocator() != null) {
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());
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
示例2: formatEvent
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
public static String formatEvent(ValidationEvent e) {
StringBuilder sb = new StringBuilder();
if (e.getLocator() != null) {
appendLocator(sb, e.getLocator());
}
if (e.getMessage() != null) {
sb.append(e.getMessage());
if (e.getLinkedException() != null) {
sb.append(" - ");
}
}
if (e.getLinkedException() != null) {
sb.append(e.getLinkedException().toString());
}
return sb.toString();
}
示例3: handleEvent
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
@Override
public boolean handleEvent(ValidationEvent validationEvent) {
ValidationEventLocator locator = validationEvent.getLocator();
lineNumber = locator.getLineNumber();
columnNumber = locator.getColumnNumber();
message = validationEvent.getMessage();
return false;
}
示例4: getLocation
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
/**
* Calculate a location message for the event
*
*/
private String getLocation(ValidationEvent event) {
StringBuffer msg = new StringBuffer();
ValidationEventLocator locator = event.getLocator();
if( locator != null ) {
URL url = locator.getURL();
Object obj = locator.getObject();
Node node = locator.getNode();
int line = locator.getLineNumber();
if( url!=null || line!=-1 ) {
msg.append( "line " + line );
if( url!=null )
msg.append( " of " + url );
} else if( obj != null ) {
msg.append( " obj: " + obj.toString() );
} else if( node != null ) {
msg.append( " node: " + node.toString() );
}
} else {
msg.append( Messages.format( Messages.LOCATION_UNAVAILABLE ) );
}
return msg.toString();
}
示例5: handleValidationEvent
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
private static boolean handleValidationEvent(ImmutableList.Builder<String> errorList, ValidationEvent validationEvent) {
if (validationEvent.getSeverity() != ValidationEvent.WARNING) {
ValidationEventLocator locator = validationEvent.getLocator();
errorList.add("Line:Col[" + locator.getLineNumber() +
":" + locator.getColumnNumber() +
"]:" + validationEvent.getMessage());
}
return true;
}
示例6: handleEvent
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
/**
* Receive notification of a validation warning or error.
*
* <p>
*
* The ValidationEvent will have a
* {@link javax.xml.bind.ValidationEventLocator} embedded in it that
* indicates where the error or warning occurred.
*
* <p>
*
* If an unchecked runtime exception is thrown from this method, the JAXB
* provider will treat it as if the method returned false and interrupt
* the current unmarshal, validate, or marshal operation.
*
* @param event
* the encapsulated validation event information. It is a provider error if
* this parameter is null.
*
* @return
* true if the JAXB Provider should attempt to continue the current unmarshal,
* validate, or marshal operation after handling this warning/error, false if
* the provider should terminate the current operation with the appropriate
* <tt>UnmarshalException</tt>, <tt>ValidationException</tt>, or
* <tt>MarshalException</tt>.
*
* @throws IllegalArgumentException
* if the event object is null.
*/
@Override
public boolean handleEvent( ValidationEvent event )
{
if (event==null)
throw new IllegalArgumentException( "No validation event was provided!" );
int line = -1;
int col = -1;
if (event.getLocator()!=null)
{
line = event.getLocator().getLineNumber();
col = event.getLocator().getColumnNumber();
}
if (ValidationEvent.FATAL_ERROR==event.getSeverity())
{
LOGGER.warn( "fatal validation error" );
if (line>-1 && col>-1) LOGGER.warn( "> at line " + line + " / column " + col );
LOGGER.warn( "> " + event.getMessage() );
return false;
}
if (ValidationEvent.WARNING==event.getSeverity())
{
LOGGER.warn( "validation warning" );
if (line>-1 && col>-1) LOGGER.warn( "> at line " + line + " / column " + col );
LOGGER.warn( "> " + event.getMessage() );
}
else
{
LOGGER.warn( "validation error" );
if (line>-1 && col>-1) LOGGER.warn( "> at line " + line + " / column " + col );
LOGGER.warn( "> " + event.getMessage() );
}
return true;
}
示例7: handleEvent
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
public boolean handleEvent(ValidationEvent event) {
ValidationEventLocator loc = event.getLocator();
String file = loc.getURL().getFile();
try {
file = URLDecoder.decode(file, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
int lastSlash = file.lastIndexOf('/');
if (lastSlash > 0)
file = file.substring(lastSlash + 1);
String errorMsg = event.getMessage();
if (errorMsg == null) {
Throwable t = event.getLinkedException();
while (t != null && errorMsg == null) {
errorMsg = t.getMessage();
t = t.getCause();
}
}
JOptionPane
.showMessageDialog(null, "<html><h3>Failed to load a custom map</h3><p><i>" + errorMsg
+ "</i></p><br><p>file: \"<b>" + file + "</b>\"<br>line/column: <i>" + loc.getLineNumber()
+ "/" + loc.getColumnNumber() + "</i></p>", "Error: custom map loading failed",
JOptionPane.ERROR_MESSAGE);
log.error(event.toString());
return false;
}
示例8: getErrorLocation
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
/**
* Calculates a location message for the event.
*
* {@link DefaultValidationEventHandler#getLocation(ValidationEvent)}
*/
public static String getErrorLocation(ValidationEvent event)
{
StringBuilder msg = new StringBuilder();
ValidationEventLocator locator = event.getLocator();
if (locator != null)
{
URL url = locator.getURL();
Object obj = locator.getObject();
Node node = locator.getNode();
int line = locator.getLineNumber();
if (url != null || line != -1)
{
msg.append("line " + line);
if (url != null)
msg.append(" of " + url);
}
else if (obj != null)
{
msg.append(" obj: " + obj.toString());
}
else if (node != null)
{
msg.append(" node: " + node.toString());
}
}
else
{
msg.append("Cannot determinate the location of the error/warning");
}
return msg.toString();
}
示例9: handleEvent
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
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);
}
示例10: handleEvent
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
@Override
public boolean handleEvent(ValidationEvent event) {
StringBuilder msg = new StringBuilder();
LogLevel type = LogLevel.ERROR;
switch (event.getSeverity()) {
case ValidationEvent.FATAL_ERROR:
case ValidationEvent.ERROR:
msg.append("Invalid XML content");
type = LogLevel.ERROR;
isValid = false;
break;
case ValidationEvent.WARNING:
msg.append("Warning");
type = LogLevel.WARN;
break;
}
if (event.getLocator() != null) {
msg.append(" at [").append(event.getLocator().getLineNumber())
.append(", ").append(event.getLocator().getColumnNumber()).append("]");
}
msg.append(": ").append(event.getMessage());
log.log(type, msg.toString());
if (!isValid)
cause = msg.toString();
return isValid;
}
示例11: handleEvent
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
@Override
public boolean handleEvent(ValidationEvent ve)
{
if (ve.getSeverity() == ValidationEvent.FATAL_ERROR
|| ve.getSeverity() == ValidationEvent.ERROR)
{
ValidationEventLocator locator = ve.getLocator();
log.error("{}: {} at line={}, column={}", locator.getURL(),
ve.getMessage(), locator.getLineNumber(),
locator.getColumnNumber());
foundErrors = true;
}
return true;
}
示例12: toResponse
import javax.xml.bind.ValidationEvent; //导入方法依赖的package包/类
@Override
public Response toResponse(LensJAXBValidationException e) {
ValidationEvent event = e.getEvent();
ValidationEventLocator vel = event.getLocator();
String msg = "XML Validation Exception: " + event.getMessage() + " at row: " + vel.getLineNumber() + " column: "
+ vel.getColumnNumber();
LensAPIResult lensAPIResult =
LensAPIResult.composedOf(null, new MappedDiagnosticLogSegregationContext().getLogSegragationId(),
LensErrorTO.composedOf(LensCommonErrorCode.INVALID_XML_ERROR.getValue(), msg,
Arrays.toString(e.getStackTrace())), Response.Status.BAD_REQUEST);
return Response.status(Response.Status.BAD_REQUEST).entity(lensAPIResult).build();
}