Java Code Examples for org.xml.sax.SAXParseException#getColumnNumber()

The following examples show how to use org.xml.sax.SAXParseException#getColumnNumber() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ErrorHandlerWrapper.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
}
 
Example 2
Source File: SerializationTest.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
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);
        }
    }
 
Example 3
Source File: ErrorHandlerImpl.java    From teamengine with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 4
Source File: ErrorHandlerWrapper.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
}
 
Example 5
Source File: DefaultGmlImportService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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() );
}
 
Example 6
Source File: SiteCatalogParser.java    From swift-k with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 7
Source File: XmlErrorHandler.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: LoggingErrorReceiver.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 : "") + "}" : "")
			+ "].";
}
 
Example 9
Source File: TestUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 10
Source File: TestUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: LoggingErrorReceiver.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 : "") + "}" : "")
			+ "].";
}
 
Example 12
Source File: SchemaValidator.java    From vespa with Apache License 2.0 4 votes vote down vote up
private String message(SAXParseException e) {
    return "XML error in " + fileName + ": " +
            Exceptions.toMessageString(e)
            + " [" + e.getLineNumber() + ":" + e.getColumnNumber() + "]" +
            ", input:\n" + getErrorContext(e.getLineNumber());
}
 
Example 13
Source File: DefaultXMLProcessorDetail.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example 14
Source File: CacheonixXsdTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
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;
      }
 
Example 15
Source File: SchemaValidator.java    From cxf with Apache License 2.0 4 votes vote down vote up
private String getErrorMessage(SAXParseException ex) {
    return "line " + ex.getLineNumber() + " column " + ex.getColumnNumber() + " of " + ex.getSystemId()
            + ": " + ex.getMessage();
}
 
Example 16
Source File: ValidationEventLocatorImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 17
Source File: ValidationEventLocatorImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 18
Source File: ValidationEventLocatorImpl.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 19
Source File: ValidationEventLocatorImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 20
Source File: PNMLSerializer.java    From codebase with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 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(); 
}