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

The following examples show how to use org.xml.sax.SAXParseException#getLineNumber() . 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: DtdValidatorUtil.java    From hop with Apache License 2.0 6 votes vote down vote up
private void allErrors( SAXParseException e ) {
  nrErrors++;
  if ( errorMessage == null ) {
    errorMessage = "";
  }
  errorMessage += Const.CR + Const.CR + "Error Nr." + nrErrors + " (";
  switch ( error ) {
    case 0:
      errorMessage += "Warning";
      break;
    case 1:
      errorMessage += "Error";
      break;
    case 2:
      errorMessage += "FatalError";
      break;
    default:
      break;
  }
  errorMessage +=
    ")"
      + Const.CR + "              Public ID: " + e.getPublicId() + Const.CR + "              System ID: "
      + e.getSystemId() + Const.CR + "              Line number: " + e.getLineNumber() + Const.CR
      + "              Column number: " + e.getColumnNumber() + Const.CR + "              Message: "
      + e.getMessage();
}
 
Example 2
Source File: XmlErrorHandler.java    From teamengine with Apache License 2.0 6 votes vote down vote up
/**
 * Prints the error to STDOUT, used to be consistent with TEAM Engine error
 * handler.
 * 
 */
void printError(String type, SAXParseException e) {
    PrintWriter logger = new PrintWriter(System.out);
    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();
}
 
Example 3
Source File: DefaultValidationErrorHandler.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void error(SAXParseException e) throws SAXException {
    if (errorCount >= ERROR_COUNT_LIMIT) {
        // Ignore all errors after reaching the limit
        return;
    } else if (errorCount == 0) {
        // Print a warning before the first error
        System.err.println(SAXMessageFormatter.formatMessage(locale,
                    "errorHandlerNotSet", new Object [] {errorCount}));
    }

    String systemId = e.getSystemId();
    if (systemId == null) {
        systemId = "null";
    }
    String message = "Error: URI=" + systemId +
        " Line=" + e.getLineNumber() +
        ": " + e.getMessage();
    System.err.println(message);
    errorCount++;
}
 
Example 4
Source File: DefaultValidationErrorHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void error(SAXParseException e) throws SAXException {
    if (errorCount >= ERROR_COUNT_LIMIT) {
        // Ignore all errors after reaching the limit
        return;
    } else if (errorCount == 0) {
        // Print a warning before the first error
        System.err.println(SAXMessageFormatter.formatMessage(locale,
                    "errorHandlerNotSet", new Object [] {errorCount}));
    }

    String systemId = e.getSystemId();
    if (systemId == null) {
        systemId = "null";
    }
    String message = "Error: URI=" + systemId +
        " Line=" + e.getLineNumber() +
        ": " + e.getMessage();
    System.err.println(message);
    errorCount++;
}
 
Example 5
Source File: DefaultValidationErrorHandler.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public void error(SAXParseException e) throws SAXException {
    if (errorCount >= ERROR_COUNT_LIMIT) {
        // Ignore all errors after reaching the limit
        return;
    } else if (errorCount == 0) {
        // Print a warning before the first error
        System.err.println(SAXMessageFormatter.formatMessage(locale,
                    "errorHandlerNotSet", new Object [] {errorCount}));
    }

    String systemId = e.getSystemId();
    if (systemId == null) {
        systemId = "null";
    }
    String message = "Error: URI=" + systemId +
        " Line=" + e.getLineNumber() +
        ": " + e.getMessage();
    System.err.println(message);
    errorCount++;
}
 
Example 6
Source File: PAPPolicyReader.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void warning(SAXParseException exception) throws SAXException {
    if (log.isWarnEnabled()) {
        String message = null;
        message = "Warning on line " + exception.getLineNumber() + ": "
                + exception.getMessage();
        log.warn(message);
    }
}
 
Example 7
Source File: ErrorReceiver.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the human readable string representation of the
 * {@link org.xml.sax.Locator} part of the specified
 * {@link SAXParseException}.
 *
 * @return  non-null valid object.
 */
protected final String getLocationString( SAXParseException e ) {
    if(e.getLineNumber()!=-1 || e.getSystemId()!=null) {
        int line = e.getLineNumber();
        return ModelMessages.CONSOLE_ERROR_REPORTER_LINE_X_OF_Y(line==-1?"?":Integer.toString( line ),
            getShortName( e.getSystemId()));
    } else {
        return ""; //for unkown location just return empty string
    }
}
 
Example 8
Source File: ErrorReceiver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the human readable string representation of the
 * {@link org.xml.sax.Locator} part of the specified
 * {@link SAXParseException}.
 *
 * @return  non-null valid object.
 */
protected final String getLocationString( SAXParseException e ) {
    if(e.getLineNumber()!=-1 || e.getSystemId()!=null) {
        int line = e.getLineNumber();
        return ModelMessages.CONSOLE_ERROR_REPORTER_LINE_X_OF_Y(line==-1?"?":Integer.toString( line ),
            getShortName( e.getSystemId()));
    } else {
        return ""; //for unkown location just return empty string
    }
}
 
Example 9
Source File: ErrorReceiver.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the human readable string representation of the
 * {@link org.xml.sax.Locator} part of the specified
 * {@link SAXParseException}.
 *
 * @return  non-null valid object.
 */
protected final String getLocationString( SAXParseException e ) {
    if(e.getLineNumber()!=-1 || e.getSystemId()!=null) {
        int line = e.getLineNumber();
        return Messages.format( Messages.LINE_X_OF_Y,
            line==-1?"?":Integer.toString( line ),
            getShortName( e.getSystemId() ) );
    } else {
        return Messages.format( Messages.UNKNOWN_LOCATION );
    }
}
 
Example 10
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 11
Source File: EdfiRecordParser.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@Override
public void warning(final SAXParseException ex) throws SAXException {
    Source elementSource = new ElementSourceImpl(new ElementSource() {

        @Override
        public String getResourceId() {
            return source.getResourceId();
        }

        @Override
        public int getVisitBeforeLineNumber() {
            return ex.getLineNumber();
        }

        @Override
        public int getVisitBeforeColumnNumber() {
            return ex.getColumnNumber();
        }

        @Override
        public String getElementType() {
            return source.getResourceId();
        }
    });

    messageReport.warning(reportStats, elementSource, BaseMessageCode.BASE_0026, ex.getMessage());
}
 
Example 12
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 13
Source File: PolicyReader.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void warning(SAXParseException exception) throws SAXException {
    if (log.isWarnEnabled()) {
        String message = null;
        message = "Warning on line " + exception.getLineNumber() + ": "
                + exception.getMessage();
        log.warn(message);
    }
}
 
Example 14
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 15
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 16
Source File: SimpleHandlerAdapter.java    From cloudhopper-commons with Apache License 2.0 4 votes vote down vote up
private String getLocationString(SAXParseException ex) {
    return ex.getSystemId() + " line:" + ex.getLineNumber() + " col:" + ex.getColumnNumber();
}
 
Example 17
Source File: XjcLogAdapter.java    From jaxb2-maven-plugin with Apache License 2.0 4 votes vote down vote up
private String getLocation(final SAXParseException e) {

        final String exceptionId = e.getPublicId() == null ? e.getSystemId() : e.getPublicId();
        return exceptionId + " [" + e.getLineNumber() + "," + e.getColumnNumber() + "] ";
    }
 
Example 18
Source File: XmlParser.java    From cloudhopper-commons with Apache License 2.0 4 votes vote down vote up
private String getLocationString(SAXParseException ex) {
    return ex.getSystemId() + " line:" + ex.getLineNumber() + " col:" + ex.getColumnNumber();
}
 
Example 19
Source File: ValidationEventLocatorImpl.java    From jdk1.8-source-analysis with Apache License 2.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: 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();
}