Java Code Examples for org.w3c.dom.DOMError#SEVERITY_FATAL_ERROR

The following examples show how to use org.w3c.dom.DOMError#SEVERITY_FATAL_ERROR . 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: DOMErrorHandlerImpl.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation of DOMErrorHandler.handleError that
 * adds copy of error to list for later retrieval.
 *
 */
public boolean handleError(DOMError error) {
    boolean fail = true;
    String severity = null;
    if (error.getSeverity() == DOMError.SEVERITY_WARNING) {
        fail = false;
        severity = "[Warning]";
    } else if (error.getSeverity() == DOMError.SEVERITY_ERROR) {
        severity = "[Error]";
    } else if (error.getSeverity() == DOMError.SEVERITY_FATAL_ERROR) {
        severity = "[Fatal Error]";
    }
    
    System.err.println(severity + ": " + error.getMessage() + "\t");
    System.err.println("Type : " + error.getType() + "\t" + "Related Data: "
            + error.getRelatedData() + "\t" + "Related Exception: "
            + error.getRelatedException() );
    
    return fail;
}
 
Example 2
Source File: DOMNormalizer.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw new AbortException();
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw new AbortException();
}
 
Example 3
Source File: DOMNormalizer.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw new AbortException();
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw new AbortException();
}
 
Example 4
Source File: DOMNormalizer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw abort;
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw abort;
}
 
Example 5
Source File: DOMNormalizer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw new AbortException();
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw new AbortException();
}
 
Example 6
Source File: DOMNormalizer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw new AbortException();
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw new AbortException();
}
 
Example 7
Source File: DOMNormalizer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw abort;
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw abort;
}
 
Example 8
Source File: XMLSchemaLoader.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
void reportDOMFatalError(Exception e) {
    if (fErrorHandler != null) {
        DOMErrorImpl error = new DOMErrorImpl();
        error.fException = e;
        error.fMessage = e.getMessage();
        error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
        fErrorHandler.getErrorHandler().handleError(error);
    }
}
 
Example 9
Source File: XMLSchemaLoader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void reportDOMFatalError(Exception e) {
    if (fErrorHandler != null) {
        DOMErrorImpl error = new DOMErrorImpl();
        error.fException = e;
        error.fMessage = e.getMessage();
        error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
        fErrorHandler.getErrorHandler().handleError(error);
    }
}
 
Example 10
Source File: XMLSchemaLoader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void reportDOMFatalError(Exception e) {
    if (fErrorHandler != null) {
        DOMErrorImpl error = new DOMErrorImpl();
        error.fException = e;
        error.fMessage = e.getMessage();
        error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
        fErrorHandler.getErrorHandler().handleError(error);
    }
}
 
Example 11
Source File: XMLSchemaLoader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
void reportDOMFatalError(Exception e) {
    if (fErrorHandler != null) {
        DOMErrorImpl error = new DOMErrorImpl();
        error.fException = e;
        error.fMessage = e.getMessage();
        error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
        fErrorHandler.getErrorHandler().handleError(error);
    }
}
 
Example 12
Source File: XMLSchemaLoader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void reportDOMFatalError(Exception e) {
    if (fErrorHandler != null) {
        DOMErrorImpl error = new DOMErrorImpl();
        error.fException = e;
        error.fMessage = e.getMessage();
        error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
        fErrorHandler.getErrorHandler().handleError(error);
    }
}
 
Example 13
Source File: DOMParserImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document from a location identified by an URI reference.
 * If the URI contains a fragment identifier (see section 4.1 in ), the
 * behavior is not defined by this specification.
 *
 */
public Document parseURI (String uri) throws LSException {

    //If DOMParser insstance is already busy parsing another document when this
    // method is called, then raise INVALID_STATE_ERR according to DOM L3 LS spec
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    XMLInputSource source = new XMLInputSource (null, uri, null);
    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (source);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e){
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
                DOMErrorImpl error = new DOMErrorImpl ();
                error.fException = e;
                error.fMessage = e.getMessage ();
                error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
                fErrorHandler.getErrorHandler ().handleError (error);
            }
            if (DEBUG) {
                e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}
 
Example 14
Source File: DOMParserImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document from a location identified by an URI reference.
 * If the URI contains a fragment identifier (see section 4.1 in ), the
 * behavior is not defined by this specification.
 *
 */
public Document parseURI (String uri) throws LSException {

    //If DOMParser insstance is already busy parsing another document when this
    // method is called, then raise INVALID_STATE_ERR according to DOM L3 LS spec
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    XMLInputSource source = new XMLInputSource (null, uri, null);
    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (source);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e){
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
                DOMErrorImpl error = new DOMErrorImpl ();
                error.fException = e;
                error.fMessage = e.getMessage ();
                error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
                fErrorHandler.getErrorHandler ().handleError (error);
            }
            if (DEBUG) {
                e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}
 
Example 15
Source File: DOMParserImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Parse an XML document from a location identified by an URI reference.
 * If the URI contains a fragment identifier (see section 4.1 in ), the
 * behavior is not defined by this specification.
 *
 */
public Document parseURI (String uri) throws LSException {

    //If DOMParser insstance is already busy parsing another document when this
    // method is called, then raise INVALID_STATE_ERR according to DOM L3 LS spec
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    XMLInputSource source = new XMLInputSource (null, uri, null);
    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (source);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e){
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
                DOMErrorImpl error = new DOMErrorImpl ();
                error.fException = e;
                error.fMessage = e.getMessage ();
                error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
                fErrorHandler.getErrorHandler ().handleError (error);
            }
            if (DEBUG) {
                e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}
 
Example 16
Source File: DOMErrorHandlerWrapper.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Report a fatal error. Fatal errors usually occur when the document
 * is not well-formed and signifies that the parser cannot continue
 * normal operation.
 * <p>
 * <strong>Note:</strong> The error handler should <em>always</em>
 * throw an <code>XNIException</code> from this method. This exception
 * can either be the same exception that is passed as a parameter to
 * the method or a new XNI exception object. If the registered error
 * handler fails to throw an exception, the continuing operation of
 * the parser is undetermined.
 *
 * @param domain    The domain of the fatal error. The domain can be
 *                  any string but is suggested to be a valid URI. The
 *                  domain can be used to conveniently specify a web
 *                  site location of the relevent specification or
 *                  document pertaining to this fatal error.
 * @param key       The fatal error key. This key can be any string
 *                  and is implementation dependent.
 * @param exception Exception.
 *
 * @throws XNIException Thrown to signal that the parser should stop
 *                      parsing the document.
 */
public void fatalError(String domain, String key,
                       XMLParseException exception) throws XNIException {
    fDOMError.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
    fDOMError.fException = exception;
    fErrorCode.setValues(domain, key);
    String domErrorType = DOMErrorTypeMap.getDOMErrorType(fErrorCode);
    fDOMError.fType = (domErrorType != null) ? domErrorType : key;
    fDOMError.fRelatedData = fDOMError.fMessage = exception.getMessage();
    DOMLocatorImpl locator = fDOMError.fLocator;
    if (locator != null) {
        locator.fColumnNumber = exception.getColumnNumber();
        locator.fLineNumber = exception.getLineNumber();
        locator.fUtf16Offset = exception.getCharacterOffset();
        locator.fUri = exception.getExpandedSystemId();
        locator.fRelatedNode = fCurrentNode;
    }
    if (fDomErrorHandler != null) {
        fDomErrorHandler.handleError(fDOMError);
    }
}
 
Example 17
Source File: DOMParserImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document from a location identified by an URI reference.
 * If the URI contains a fragment identifier (see section 4.1 in ), the
 * behavior is not defined by this specification.
 *
 */
public Document parseURI (String uri) throws LSException {

    //If DOMParser insstance is already busy parsing another document when this
    // method is called, then raise INVALID_STATE_ERR according to DOM L3 LS spec
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    XMLInputSource source = new XMLInputSource (null, uri, null);
    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (source);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e){
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
                DOMErrorImpl error = new DOMErrorImpl ();
                error.fException = e;
                error.fMessage = e.getMessage ();
                error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
                fErrorHandler.getErrorHandler ().handleError (error);
            }
            if (DEBUG) {
                e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}
 
Example 18
Source File: DOMParserImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document from a resource identified by an
 * <code>LSInput</code>.
 *
 */
public Document parse (LSInput is) throws LSException {

    // need to wrap the LSInput with an XMLInputSource
    XMLInputSource xmlInputSource = dom2xmlInputSource (is);
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (xmlInputSource);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e) {
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
               DOMErrorImpl error = new DOMErrorImpl ();
               error.fException = e;
               error.fMessage = e.getMessage ();
               error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
               fErrorHandler.getErrorHandler().handleError (error);
            }
            if (DEBUG) {
               e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}
 
Example 19
Source File: DOMParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document from a location identified by an URI reference.
 * If the URI contains a fragment identifier (see section 4.1 in ), the
 * behavior is not defined by this specification.
 *
 */
public Document parseURI (String uri) throws LSException {

    //If DOMParser insstance is already busy parsing another document when this
    // method is called, then raise INVALID_STATE_ERR according to DOM L3 LS spec
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    XMLInputSource source = new XMLInputSource (null, uri, null, false);
    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (source);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e){
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
                DOMErrorImpl error = new DOMErrorImpl ();
                error.fException = e;
                error.fMessage = e.getMessage ();
                error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
                fErrorHandler.getErrorHandler ().handleError (error);
            }
            if (DEBUG) {
                e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}
 
Example 20
Source File: DOMParserImpl.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Parse an XML document from a resource identified by an
 * <code>LSInput</code>.
 *
 */
public Document parse (LSInput is) throws LSException {

    // need to wrap the LSInput with an XMLInputSource
    XMLInputSource xmlInputSource = dom2xmlInputSource (is);
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (xmlInputSource);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e) {
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
               DOMErrorImpl error = new DOMErrorImpl ();
               error.fException = e;
               error.fMessage = e.getMessage ();
               error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
               fErrorHandler.getErrorHandler().handleError (error);
            }
            if (DEBUG) {
               e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}