下面列出了org.xml.sax.SAXParseException#getColumnNumber ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** Creates an XMLParseException from a SAXParseException. */
protected static XMLParseException createXMLParseException(SAXParseException exception) {
final String fPublicId = exception.getPublicId();
final String fExpandedSystemId = exception.getSystemId();
final int fLineNumber = exception.getLineNumber();
final int fColumnNumber = exception.getColumnNumber();
XMLLocator location = new XMLLocator() {
public String getPublicId() { return fPublicId; }
public String getExpandedSystemId() { return fExpandedSystemId; }
public String getBaseSystemId() { return null; }
public String getLiteralSystemId() { return null; }
public int getColumnNumber() { return fColumnNumber; }
public int getLineNumber() { return fLineNumber; }
public int getCharacterOffset() { return -1; }
public String getEncoding() { return null; }
public String getXMLVersion() { return null; }
};
return new XMLParseException(location, exception.getMessage(),exception);
}
/** Creates an XMLParseException from a SAXParseException. */
protected static XMLParseException createXMLParseException(SAXParseException exception) {
final String fPublicId = exception.getPublicId();
final String fExpandedSystemId = exception.getSystemId();
final int fLineNumber = exception.getLineNumber();
final int fColumnNumber = exception.getColumnNumber();
XMLLocator location = new XMLLocator() {
public String getPublicId() { return fPublicId; }
public String getExpandedSystemId() { return fExpandedSystemId; }
public String getBaseSystemId() { return null; }
public String getLiteralSystemId() { return null; }
public int getColumnNumber() { return fColumnNumber; }
public int getLineNumber() { return fLineNumber; }
public int getCharacterOffset() { return -1; }
public String getEncoding() { return null; }
public String getXMLVersion() { return null; }
};
return new XMLParseException(location, exception.getMessage(),exception);
}
private void error(String type, SAXParseException e) {
Logger.print(type);
if (e.getLineNumber() >= 0) {
Logger.print(" at line " + e.getLineNumber());
if (e.getColumnNumber() >= 0) {
Logger.print(", column " + e.getColumnNumber());
}
if (e.getSystemId() != null) {
Logger.print(" of " + e.getSystemId());
}
} else {
if (e.getSystemId() != null) {
Logger.print(" in " + e.getSystemId());
}
}
Logger.println(":");
Logger.println(" " + e.getMessage());
Logger.flush();
// System.err.println(type + " at line " + + e.getLineNumber() + ",
// column " + e.getColumnNumber() + " of " + e.getSystemId() + ":");
// System.err.println(" " + e.getMessage());
}
public void testStringTemplate() throws Exception {
StringTemplate t1 = StringTemplate.template("model.goods.goodsAmount")
.add("%goods%", "model.goods.food.name")
.addName("%amount%", "100");
StringTemplate t2 = StringTemplate.template("model.goods.goodsAmount")
.addAmount("%amount%", 50)
.addStringTemplate("%goods%", t1);
Game game = getGame();
Player player = game.getPlayerByNationId("model.nation.dutch");
try {
Validator validator = buildValidator("schema/data/data-stringTemplate.xsd");
validator.validate(buildSource(t2));
} catch (SAXParseException e){
String errMsg = e.getMessage()
+ " at line=" + e.getLineNumber()
+ " column=" + e.getColumnNumber();
fail(errMsg);
}
}
private String createNotifierErrorMessage( Throwable throwable )
{
StringBuilder sb = new StringBuilder( "GML import failed: " );
Throwable rootThrowable = ExceptionUtils.getRootCause( throwable );
if ( rootThrowable == null )
{
rootThrowable = throwable;
}
if ( rootThrowable instanceof SAXParseException )
{
SAXParseException e = (SAXParseException) rootThrowable;
sb.append( e.getMessage() );
if ( e.getLineNumber() >= 0 )
{
sb.append( " On line " ).append( e.getLineNumber() );
if ( e.getColumnNumber() >= 0 )
{
sb.append( " column " ).append( e.getColumnNumber() );
}
}
}
else
{
sb.append( rootThrowable.getMessage() );
}
if ( sb.charAt( sb.length() - 1 ) != '.' )
{
sb.append( '.' );
}
return HtmlUtils.htmlEscape( sb.toString() );
}
private String getMessage(SAXParseException ex) {
final int row = ex.getLineNumber();
final int col = ex.getColumnNumber();
final String sys = ex.getSystemId();
final String pub = ex.getPublicId();
return messagePrefix + "Location [" + (sys != null ? " " + sys : "")
+ (pub != null ? " " + pub : "")
+ (row > 0 ? "{" + row + (col > 0 ? "," + col : "") + "}" : "")
+ "].";
}
/**
* Throws back the exception with the name of the XML file and the position
* where the exception occurred.
*/
@Override
public void error(SAXParseException exception) throws SAXException {
throw new SAXParseException("Error while parsing XML at line "
+ exception.getLineNumber() + " column "
+ exception.getColumnNumber() + ": " + exception.getMessage(), null);
}
/**
* Throws back the exception with the name of the XML file and the position
* where the exception occurred.
*/
@Override
public void fatalError(SAXParseException exception) throws SAXException {
throw new SAXParseException("Fatal error while parsing XML at line "
+ exception.getLineNumber() + " column "
+ exception.getColumnNumber() + ": " + exception.getMessage(), null);
}
private String getMessage(SAXParseException ex) {
final int row = ex.getLineNumber();
final int col = ex.getColumnNumber();
final String sys = ex.getSystemId();
final String pub = ex.getPublicId();
return messagePrefix + "Location [" + (sys != null ? " " + sys : "")
+ (pub != null ? " " + pub : "")
+ (row > 0 ? "{" + row + (col > 0 ? "," + col : "") + "}" : "")
+ "].";
}
/**
* Throws back the exception with the name of the XML file and the position
* where the exception occurred.
*/
public void fatalError(SAXParseException exception) throws SAXException {
throw new SAXParseException("Fatal error while parsing XML at line "
+ exception.getLineNumber() + " column " + exception.getColumnNumber()
+ ": " + exception.getMessage(), null);
}
private void print(SAXParseException e, String header, boolean err) {
String msg = "[" + header + "] " + src.getName() + ", line " +
e.getLineNumber() + ", col " + e.getColumnNumber() + ": " + e.getMessage();
if (err) {
System.err.println(msg);
}
else {
System.out.println(msg);
}
if (logger.isInfoEnabled()) {
logger.info(msg);
}
}
private String message(SAXParseException e) {
return "XML error in " + fileName + ": " +
Exceptions.toMessageString(e)
+ " [" + e.getLineNumber() + ":" + e.getColumnNumber() + "]" +
", input:\n" + getErrorContext(e.getLineNumber());
}
private void tryWrappedLocator(Exception ex) {
if ( Util.THIS.isLoggable() ) /* then */ {
Util.THIS.debug ("DefaultXMLProcessorDetail.tryWrappedLocator: " + ex);
}
// I saw SAXException wrapped in TransformerException and vice versa
Throwable wrapped = null;
if (ex instanceof TransformerException) {
wrapped = ((TransformerException) ex).getException();
} else if (ex instanceof SAXException) {
wrapped = ((SAXException) ex).getException();
} else {
return;
}
// look if wrapped exception does not provide location info
if (wrapped instanceof SAXParseException) {
SAXParseException pex = (SAXParseException) wrapped;
if (pex.getLineNumber() == -1) {
tryWrappedLocator(pex);
} else {
this.columnNumber = pex.getColumnNumber();
this.lineNumber = pex.getLineNumber();
this.publicId = pex.getPublicId();
this.systemId = pex.getSystemId();
}
} else if (wrapped instanceof TransformerException) {
TransformerException wrappedTransformerEx =
(TransformerException) wrapped;
SourceLocator locator = wrappedTransformerEx.getLocator();
if (locator == null) {
tryWrappedLocator(wrappedTransformerEx);
} else {
if (locator.getLineNumber() == -1) {
tryWrappedLocator(wrappedTransformerEx);
} else {
this.columnNumber = locator.getColumnNumber();
this.lineNumber = locator.getLineNumber();
this.publicId = locator.getPublicId();
this.systemId = locator.getSystemId();
}
}
} else if (wrapped instanceof SAXException) {
tryWrappedLocator((SAXException)wrapped);
}
}
private static SAXException toSAXException(final SAXParseException exception) {
final SAXException saxException = new SAXException("Line " + exception.getLineNumber() + ':' + exception.getColumnNumber() + ": " + exception.getMessage());
saxException.setStackTrace(exception.getStackTrace());
return saxException;
}
private String getErrorMessage(SAXParseException ex) {
return "line " + ex.getLineNumber() + " column " + ex.getColumnNumber() + " of " + ex.getSystemId()
+ ": " + ex.getMessage();
}
/**
* Constructs an object from the location information of a SAXParseException.
*
* The object's ColumnNumber, LineNumber, and URL become available from the
* values returned by the locator's getColumnNumber(), getLineNumber(), and
* getSystemId() methods respectively. Node, Object, and Offset are not
* available.
*
* @param e the SAXParseException object that will be used to populate this
* event locator.
* @throws IllegalArgumentException if the SAXParseException is null
*/
public ValidationEventLocatorImpl( SAXParseException e ) {
if( e == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "e" ) );
}
this.url = toURL(e.getSystemId());
this.columnNumber = e.getColumnNumber();
this.lineNumber = e.getLineNumber();
}
/**
* Constructs an object from the location information of a SAXParseException.
*
* The object's ColumnNumber, LineNumber, and URL become available from the
* values returned by the locator's getColumnNumber(), getLineNumber(), and
* getSystemId() methods respectively. Node, Object, and Offset are not
* available.
*
* @param e the SAXParseException object that will be used to populate this
* event locator.
* @throws IllegalArgumentException if the SAXParseException is null
*/
public ValidationEventLocatorImpl( SAXParseException e ) {
if( e == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "e" ) );
}
this.url = toURL(e.getSystemId());
this.columnNumber = e.getColumnNumber();
this.lineNumber = e.getLineNumber();
}
/**
* Constructs an object from the location information of a SAXParseException.
*
* The object's ColumnNumber, LineNumber, and URL become available from the
* values returned by the locator's getColumnNumber(), getLineNumber(), and
* getSystemId() methods respectively. Node, Object, and Offset are not
* available.
*
* @param e the SAXParseException object that will be used to populate this
* event locator.
* @throws IllegalArgumentException if the SAXParseException is null
*/
public ValidationEventLocatorImpl( SAXParseException e ) {
if( e == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "e" ) );
}
this.url = toURL(e.getSystemId());
this.columnNumber = e.getColumnNumber();
this.lineNumber = e.getLineNumber();
}
/**
* Constructs an object from the location information of a SAXParseException.
*
* The object's ColumnNumber, LineNumber, and URL become available from the
* values returned by the locator's getColumnNumber(), getLineNumber(), and
* getSystemId() methods respectively. Node, Object, and Offset are not
* available.
*
* @param e the SAXParseException object that will be used to populate this
* event locator.
* @throws IllegalArgumentException if the SAXParseException is null
*/
public ValidationEventLocatorImpl( SAXParseException e ) {
if( e == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "e" ) );
}
this.url = toURL(e.getSystemId());
this.columnNumber = e.getColumnNumber();
this.lineNumber = e.getLineNumber();
}
/**
* Creates a detailled error notification!
*
* @param e Exception vom Typ SAXParseException
* @return Notification containing Line, Column and Error.
*/
private String saxMsg( SAXParseException e )
{
return "Line: " + e.getLineNumber() + ", Column: " + e.getColumnNumber() + ", Error: " + e.getMessage();
}