下面列出了javax.xml.bind.helpers.ValidationEventLocatorImpl#javax.xml.bind.ValidationEventLocator 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Output parse errors.
*
* @param fullResourceName the full resource name
* @param vec the vec
* @param xsdURL the xsd URL
*/
private static void outputParseErrors(
String fullResourceName, ValidationEventCollector vec, URL xsdURL) {
if (vec.hasEvents()) {
for (ValidationEvent ve : vec.getEvents()) {
String msg = ve.getMessage();
ValidationEventLocator vel = ve.getLocator();
String message =
String.format(
"%s %s %s %s %s %d %s %d %s",
Localisation.getField(ParseXML.class, "ParseXML.failedToValidate"),
fullResourceName,
Localisation.getField(ParseXML.class, "ParseXML.usingXSD"),
xsdURL.toString(),
Localisation.getField(ParseXML.class, "ParseXML.line"),
vel.getLineNumber(),
Localisation.getField(ParseXML.class, "ParseXML.column"),
vel.getColumnNumber(),
msg);
ConsoleManager.getInstance().error(ParseXML.class, message);
}
}
}
protected final void handleStartDocument(NamespaceContext nsc) throws SAXException {
visitor.startDocument(new LocatorEx() {
public ValidationEventLocator getLocation() {
return new ValidationEventLocatorImpl(this);
}
public int getColumnNumber() {
return getCurrentLocation().getColumnNumber();
}
public int getLineNumber() {
return getCurrentLocation().getLineNumber();
}
public String getPublicId() {
return getCurrentLocation().getPublicId();
}
public String getSystemId() {
return getCurrentLocation().getSystemId();
}
},nsc);
}
@Nullable
@OverrideOnDemand
protected String getErrorFieldName (@Nullable final ValidationEventLocator aLocator)
{
if (aLocator != null)
{
// Source object found?
final Object aObj = aLocator.getObject ();
if (aObj != null)
return "obj: " + aObj.toString ();
// Source node found?
final Node aNode = aLocator.getNode ();
if (aNode != null)
return XMLWriter.getNodeAsString (aNode);
}
return null;
}
protected final void handleStartDocument(NamespaceContext nsc) throws SAXException {
visitor.startDocument(new LocatorEx() {
public ValidationEventLocator getLocation() {
return new ValidationEventLocatorImpl(this);
}
public int getColumnNumber() {
return getCurrentLocation().getColumnNumber();
}
public int getLineNumber() {
return getCurrentLocation().getLineNumber();
}
public String getPublicId() {
return getCurrentLocation().getPublicId();
}
public String getSystemId() {
return getCurrentLocation().getSystemId();
}
},nsc);
}
protected final void handleStartDocument(NamespaceContext nsc) throws SAXException {
visitor.startDocument(new LocatorEx() {
public ValidationEventLocator getLocation() {
return new ValidationEventLocatorImpl(this);
}
public int getColumnNumber() {
return getCurrentLocation().getColumnNumber();
}
public int getLineNumber() {
return getCurrentLocation().getLineNumber();
}
public String getPublicId() {
return getCurrentLocation().getPublicId();
}
public String getSystemId() {
return getCurrentLocation().getSystemId();
}
},nsc);
}
/**
* 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();
}
public Snapshot(LocatorEx loc) {
columnNumber = loc.getColumnNumber();
lineNumber = loc.getLineNumber();
systemId = loc.getSystemId();
publicId = loc.getPublicId();
ValidationEventLocator vel = loc.getLocation();
offset = vel.getOffset();
url = vel.getURL();
object = vel.getObject();
node = vel.getNode();
}
public Snapshot(LocatorEx loc) {
columnNumber = loc.getColumnNumber();
lineNumber = loc.getLineNumber();
systemId = loc.getSystemId();
publicId = loc.getPublicId();
ValidationEventLocator vel = loc.getLocation();
offset = vel.getOffset();
url = vel.getURL();
object = vel.getObject();
node = vel.getNode();
}
public Snapshot(LocatorEx loc) {
columnNumber = loc.getColumnNumber();
lineNumber = loc.getLineNumber();
systemId = loc.getSystemId();
publicId = loc.getPublicId();
ValidationEventLocator vel = loc.getLocation();
offset = vel.getOffset();
url = vel.getURL();
object = vel.getObject();
node = vel.getNode();
}
/**
* 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();
}
private String getLocationDescription(ValidationEvent event) {
ValidationEventLocator locator = event.getLocator();
if (locator == null) {
return "XML with location unavailable";
} else {
StringBuffer msg = new StringBuffer();
URL url = locator.getURL();
Object obj = locator.getObject();
Node node = locator.getNode();
int line = locator.getLineNumber();
if (url == null && line == -1) {
if (obj != null) {
msg.append("obj: ");
msg.append(obj);
} else if (node != null) {
msg.append("node: ");
msg.append(node);
}
} else {
msg.append("line ");
msg.append(line);
if (url != null) {
msg.append(" of ");
msg.append(url);
}
}
return msg.toString();
}
}
public Snapshot(LocatorEx loc) {
columnNumber = loc.getColumnNumber();
lineNumber = loc.getLineNumber();
systemId = loc.getSystemId();
publicId = loc.getPublicId();
ValidationEventLocator vel = loc.getLocation();
offset = vel.getOffset();
url = vel.getURL();
object = vel.getObject();
node = vel.getNode();
}
/**
* 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();
}
/**
* 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();
}
@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 Snapshot(LocatorEx loc) {
columnNumber = loc.getColumnNumber();
lineNumber = loc.getLineNumber();
systemId = loc.getSystemId();
publicId = loc.getPublicId();
ValidationEventLocator vel = loc.getLocation();
offset = vel.getOffset();
url = vel.getURL();
object = vel.getObject();
node = vel.getNode();
}
@Override
protected ValidationEventLocator getLocation() {
return locator.getLocation();
}
public ValidationEventLocator getLocation() {
return new ValidationEventLocatorImpl(locator);
}
public ValidationEventLocator getCurrentLocation(String fieldName) {
return new ValidationEventLocatorExImpl(cycleDetectionStack.peek(),fieldName);
}
public ValidationEventLocator getLocation() {
return new ValidationEventLocatorImpl(locator);
}
public ValidationEventLocator getLocation() {
return this;
}
@Override
protected ValidationEventLocator getLocation() {
return locator.getLocation();
}
public ValidationEventLocator getLocation() {
return new ValidationEventLocatorImpl(getCurrentLocation());
}
public ValidationEventLocator getLocator() {
return locator;
}
public ValidationEventLocator getCurrentLocation(String fieldName) {
return new ValidationEventLocatorExImpl(cycleDetectionStack.peek(),fieldName);
}
public ValidationEventLocator getLocator() {
return locator;
}
public ValidationEventLocator getLocation() {
return new ValidationEventLocatorImpl(getCurrentLocation());
}
public ValidationEventLocator getCurrentLocation(String fieldName) {
return new ValidationEventLocatorExImpl(cycleDetectionStack.peek(),fieldName);
}
public ValidationEventLocator getCurrentLocation(String fieldName) {
return new ValidationEventLocatorExImpl(cycleDetectionStack.peek(),fieldName);
}
public ValidationEventLocator getLocation() {
return new ValidationEventLocatorImpl(locator);
}