org.apache.xerces.xni.parser.XMLParseException Java Examples

The following examples show how to use org.apache.xerces.xni.parser.XMLParseException. 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: HtmlUnitNekoHtmlParser.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/** @see DefaultErrorHandler#warning(String,String,XMLParseException) */
@Override
public void warning(final String domain, final String key,
        final XMLParseException exception) throws XNIException {
    listener_.warning(exception.getMessage(),
            url_,
            html_,
            exception.getLineNumber(),
            exception.getColumnNumber(),
            key);
}
 
Example #2
Source File: XercesXmlValidator.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public void fatalError(String domain, String key, XMLParseException e) throws XNIException {
	if (warn) {
		ConfigurationWarnings.add(null, log, e.getMessage());
	}
	throw new XNIException(e);
}
 
Example #3
Source File: XercesXmlValidator.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public void error(String domain, String key, XMLParseException e) throws XNIException {
	// In case the XSD doesn't exist throw an exception to prevent the
	// the adapter from starting.
	if (e.getMessage() != null && e.getMessage().startsWith("schema_reference.4: Failed to read schema document '")) {
		throw e;
	}
	if (warn) {
		ConfigurationWarnings.add(null, log, e.getMessage());
	}
}
 
Example #4
Source File: NekoDOMParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void warning( String domain, String key, XMLParseException warningException ) throws XNIException {
    if (HTMLParserFactory.isParserWarningsEnabled()) {
        System.out.println( "At line " + warningException.getLineNumber() + ", column " + warningException.getColumnNumber() + ": " + warningException.getMessage() );
    }

    Enumeration listeners = HTMLParserFactory.getHTMLParserListeners().elements();
    while (listeners.hasMoreElements()) {
        ((HTMLParserListener) listeners.nextElement()).warning( _url, warningException.getMessage(), warningException.getLineNumber(), warningException.getColumnNumber() );
    }
}
 
Example #5
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void warning(String arg0, String arg1, XMLParseException arg2)
        throws XNIException {
  if(DEBUG_GENERAL) {
    Out.println("warning:");
    arg2.printStackTrace(Err.getPrintWriter());
  }
}
 
Example #6
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/** @see DefaultErrorHandler#warning(String,String,XMLParseException) */
@Override
public void warning(final String domain, final String key,
        final XMLParseException exception) throws XNIException {
    listener_.warning(exception.getMessage(),
            url_,
            html_,
            exception.getLineNumber(),
            exception.getColumnNumber(),
            key);
}
 
Example #7
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/** @see DefaultErrorHandler#error(String,String,XMLParseException) */
@Override
public void error(final String domain, final String key,
        final XMLParseException exception) throws XNIException {
    listener_.error(exception.getMessage(),
            url_,
            html_,
            exception.getLineNumber(),
            exception.getColumnNumber(),
            key);
}
 
Example #8
Source File: HtmlUnitNekoHtmlParser.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
@Override
public void fatalError(final String domain, final String key,
        final XMLParseException exception) throws XNIException {
    listener_.error(exception.getMessage(),
            url_,
            html_,
            exception.getLineNumber(),
            exception.getColumnNumber(),
            key);
}
 
Example #9
Source File: HtmlUnitNekoHtmlParser.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/** @see DefaultErrorHandler#error(String,String,XMLParseException) */
@Override
public void error(final String domain, final String key,
        final XMLParseException exception) throws XNIException {
    listener_.error(exception.getMessage(),
            url_,
            html_,
            exception.getLineNumber(),
            exception.getColumnNumber(),
            key);
}
 
Example #10
Source File: XSDValidator.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
public static void doDiagnostics(DOMDocument document, XMLEntityResolver entityResolver,
		List<Diagnostic> diagnostics, CancelChecker monitor) {

	try {
		XMLErrorReporter reporter = new LSPErrorReporterForXSD(document, diagnostics);

		XMLGrammarPreparser grammarPreparser = new LSPXMLGrammarPreparser();
		XMLSchemaLoader schemaLoader = createSchemaLoader(reporter);

		grammarPreparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, schemaLoader);

		grammarPreparser.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY,
				new XMLGrammarPoolImpl());
		grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE,
				false);
		grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
		grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_PREFIXES_FEATURE, true);
		grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, true);
		grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE, true);

		grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE,
				true);
		grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE,
				true);
		grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE,
				true);

		// Add LSP content handler to stop XML parsing if monitor is canceled.
		// grammarPreparser.setContentHandler(new LSPContentHandler(monitor));

		// Add LSP error reporter to fill LSP diagnostics from Xerces errors
		grammarPreparser.setProperty("http://apache.org/xml/properties/internal/error-reporter", reporter);

		if (entityResolver != null) {
			grammarPreparser.setEntityResolver(entityResolver);
		}

		String content = document.getText();
		String uri = document.getDocumentURI();
		InputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
		XMLInputSource is = new XMLInputSource(null, uri, uri, inputStream, null);
		grammarPreparser.getLoader(XMLGrammarDescription.XML_SCHEMA);
		grammarPreparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, is);
	} catch (IOException | CancellationException | XMLParseException exception) {
		// ignore error
	} catch (Exception e) {
		LOGGER.log(Level.SEVERE, "Unexpected XSDValidator error", e);
	}
}
 
Example #11
Source File: CMDTDContentModelProvider.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void error(String domain, String key, XMLParseException exception) throws XNIException {
	// Do nothing
}
 
Example #12
Source File: CMDTDContentModelProvider.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void fatalError(String domain, String key, XMLParseException exception) throws XNIException {
	// Do nothing
}
 
Example #13
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Non-fatal error, print the stack trace but continue processing.
 */
@Override
public void error(String domain, String key, XMLParseException e) {
  e.printStackTrace(Err.getPrintWriter());
}
 
Example #14
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void fatalError(String domain, String key, XMLParseException e)
        throws XNIException {
  throw e;
}
 
Example #15
Source File: CMDTDContentModelProvider.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void warning(String domain, String key, XMLParseException exception) throws XNIException {
	// Do nothing
}
 
Example #16
Source File: AbstractLSPErrorReporter.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
public String reportError(XMLLocator location, String domain, String key, Object[] arguments, short severity,
		Exception exception) throws XNIException {
	// format message
	MessageFormatter messageFormatter = getMessageFormatter(domain);
	String message;
	if (messageFormatter != null) {
		message = messageFormatter.formatMessage(fLocale, key, arguments);
	} else {
		StringBuilder str = new StringBuilder();
		str.append(domain);
		str.append('#');
		str.append(key);
		int argCount = arguments != null ? arguments.length : 0;
		if (argCount > 0) {
			str.append('?');
			for (int i = 0; i < argCount; i++) {
				str.append(arguments[i]);
				if (i < argCount - 1) {
					str.append('&');
				}
			}
		}
		message = str.toString();
	}

	Range adjustedRange = internalToLSPRange(location, key, arguments, xmlDocument);

	if (adjustedRange == null) {
		return null;
	}

	if (!addDiagnostic(adjustedRange, message, toLSPSeverity(severity), key)) {
		return null;
	}

	if (severity == SEVERITY_FATAL_ERROR && !fContinueAfterFatalError && !isIgnoreFatalError(key)) {
		XMLParseException parseException = (exception != null) ? new XMLParseException(location, message, exception)
				: new XMLParseException(location, message);
		throw parseException;
	}
	return message;
}
 
Example #17
Source File: NekoDOMParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void error( String domain, String key, XMLParseException errorException ) throws XNIException {
    Enumeration listeners = HTMLParserFactory.getHTMLParserListeners().elements();
    while (listeners.hasMoreElements()) {
        ((HTMLParserListener) listeners.nextElement()).error( _url, errorException.getMessage(), errorException.getLineNumber(), errorException.getColumnNumber() );
    }
}
 
Example #18
Source File: SchemaBuilder.java    From xml-avro with Apache License 2.0 4 votes vote down vote up
@Override
public void warning(String domain, String key, XMLParseException exception) throws XNIException {
    if (this.exception == null) this.exception = exception;
}
 
Example #19
Source File: SchemaBuilder.java    From xml-avro with Apache License 2.0 4 votes vote down vote up
@Override
public void error(String domain, String key, XMLParseException exception) throws XNIException {
    if (this.exception == null) this.exception = exception;
}
 
Example #20
Source File: SchemaBuilder.java    From xml-avro with Apache License 2.0 4 votes vote down vote up
@Override
public void fatalError(String domain, String key, XMLParseException exception) throws XNIException {
    if (this.exception == null) this.exception = exception;
}
 
Example #21
Source File: XercesXmlValidator.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public void warning(String domain, String key, XMLParseException e) throws XNIException {
	if (warn) {
		ConfigurationWarnings.add(null, log, e.getMessage());
	}
}