org.xml.sax.ErrorHandler Java Examples

The following examples show how to use org.xml.sax.ErrorHandler. 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: SourceLocationAddOn.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(
    Outline outline,
    Options opt,
    ErrorHandler errorHandler ) {

    for( ClassOutline ci : outline.getClasses() ) {
        JDefinedClass impl = ci.implClass;
        if (ci.getSuperClass() == null) {
            JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
            $loc.annotate(XmlLocation.class);
            $loc.annotate(XmlTransient.class);

            impl._implements(Locatable.class);

            impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);

            JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
            JVar $newLoc = setter.param(Locator.class, "newLocator");
            setter.body().assign($loc, $newLoc);
        }
    }

    return true;
}
 
Example #2
Source File: JAXPParser.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void parse( InputSource source, ContentHandler handler,
    ErrorHandler errorHandler, EntityResolver entityResolver )
    
    throws SAXException, IOException {
    
    try {
        XMLReader reader = factory.newSAXParser().getXMLReader();
        reader = new XMLReaderEx(reader);
        
        reader.setContentHandler(handler);
        if(errorHandler!=null)
            reader.setErrorHandler(errorHandler);
        if(entityResolver!=null)
            reader.setEntityResolver(entityResolver);
        reader.parse(source);
    } catch( ParserConfigurationException e ) {
        // in practice this won't happen
        SAXParseException spe = new SAXParseException(e.getMessage(),null,e);
        errorHandler.fatalError(spe);
        throw spe;
    }
}
 
Example #3
Source File: JaxbIndexPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {

	for (final PackageOutline packageOutline : outline
			.getAllPackageContexts()) {
		final StringBuilder sb = new StringBuilder();
		for (final ClassOutline classOutline : packageOutline.getClasses()) {
			sb.append(CodeModelUtils.getLocalClassName(classOutline.ref));
			sb.append("\n");
		}

		final JTextFile indexFile = new JTextFile("jaxb.index");
		indexFile.setContents(sb.toString());
		packageOutline._package().addResourceFile(indexFile);
	}
	return true;
}
 
Example #4
Source File: ValidatorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void validate(final String xsdFile, final Source src, final Result result) throws Exception {
    try {
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(new File(ValidatorTest.class.getResource(xsdFile).toURI()));

        // Get a Validator which can be used to validate instance document
        // against this grammar.
        Validator validator = schema.newValidator();
        ErrorHandler eh = new ErrorHandlerImpl();
        validator.setErrorHandler(eh);

        // Validate this instance document against the
        // Instance document supplied
        validator.validate(src, result);
    } catch (Exception ex) {
        throw ex;
    }
}
 
Example #5
Source File: PluginImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) {
    for( ClassOutline co : model.getClasses() ) {
        CPluginCustomization c = co.target.getCustomizations().find(Const.NS,"code");
        if(c==null)
            continue;   // no customization --- nothing to inject here

        c.markAsAcknowledged();
        // TODO: ideally you should validate this DOM element to make sure
        // that there's no typo/etc. JAXP 1.3 can do this very easily.
        String codeFragment = DOMUtils.getElementText(c.element);

        // inject the specified code fragment into the implementation class.
        co.implClass.direct(codeFragment);
    }

    return true;
}
 
Example #6
Source File: AbstractSAXParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Allow an application to register an error event handler.
 *
 * <p>If the application does not register an error handler, all
 * error events reported by the SAX parser will be silently
 * ignored; however, normal processing may not continue.  It is
 * highly recommended that all SAX applications implement an
 * error handler to avoid unexpected bugs.</p>
 *
 * <p>Applications may register a new or different handler in the
 * middle of a parse, and the SAX parser must begin using the new
 * handler immediately.</p>
 *
 * @param errorHandler The error handler.
 * @see #getErrorHandler
 */
public void setErrorHandler(ErrorHandler errorHandler) {

    try {
        XMLErrorHandler xeh = (XMLErrorHandler) fConfiguration.getProperty(ERROR_HANDLER);
        if (xeh instanceof ErrorHandlerWrapper) {
            ErrorHandlerWrapper ehw = (ErrorHandlerWrapper) xeh;
            ehw.setErrorHandler(errorHandler);
        }
        else {
            fConfiguration.setProperty(ERROR_HANDLER,
                    new ErrorHandlerWrapper(errorHandler));
        }
    }
    catch (XMLConfigurationException e) {
        // do nothing
    }

}
 
Example #7
Source File: XsdBasedValidator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected Schema getCompiledSchema(Source[] schemas,
        LSResourceResolver lsResourceResolver,
        ErrorHandler errorHandler) {
    
    Schema schema = null;
    
    // Create a compiled Schema object.
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    schemaFactory.setResourceResolver(lsResourceResolver);
    schemaFactory.setErrorHandler(errorHandler);
    try {
        schema = schemaFactory.newSchema(schemas);            
    } catch(SAXException ex) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "getCompiledSchema", ex);
    } 
    
    return schema;
}
 
Example #8
Source File: DefaultDocumentLoader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a JAXP DocumentBuilder that this bean definition reader
 * will use for parsing XML documents. Can be overridden in subclasses,
 * adding further initialization of the builder.
 * @param factory the JAXP DocumentBuilderFactory that the DocumentBuilder
 * should be created with
 * @param entityResolver the SAX EntityResolver to use
 * @param errorHandler the SAX ErrorHandler to use
 * @return the JAXP DocumentBuilder
 * @throws ParserConfigurationException if thrown by JAXP methods
 */
protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory,
		@Nullable EntityResolver entityResolver, @Nullable ErrorHandler errorHandler)
		throws ParserConfigurationException {

	DocumentBuilder docBuilder = factory.newDocumentBuilder();
	if (entityResolver != null) {
		docBuilder.setEntityResolver(entityResolver);
	}
	if (errorHandler != null) {
		docBuilder.setErrorHandler(errorHandler);
	}
	return docBuilder;
}
 
Example #9
Source File: SchemaBuilderImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param eh Error handler to receive errors while building the schema.
 */
public SchemaBuilderImpl(ErrorHandler eh) {
    this(eh,
            new CascadingDatatypeLibraryFactory(new DatatypeLibraryLoader(),
            new BuiltinDatatypeLibraryFactory(new DatatypeLibraryLoader())),
            new SchemaPatternBuilder());
}
 
Example #10
Source File: ToSAXHandler.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.xml.sax.ErrorHandler#fatalError(SAXParseException)
 */
public void fatalError(SAXParseException exc) throws SAXException {
    super.fatalError(exc);

    m_needToCallStartDocument = false;

    if (m_saxHandler instanceof ErrorHandler) {
        ((ErrorHandler)m_saxHandler).fatalError(exc);
    }
}
 
Example #11
Source File: ModelLoader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void parse(InputSource source, ContentHandler handler,
            ErrorHandler errorHandler, EntityResolver entityResolver ) throws SAXException, IOException {
            // set up the chain of handlers.
            handler = wrapBy( new ExtensionBindingChecker(XMLConstants.W3C_XML_SCHEMA_NS_URI,opt,errorReceiver), handler );
            handler = wrapBy( new IncorrectNamespaceURIChecker(errorReceiver), handler );
            handler = wrapBy( new CustomizationContextChecker(errorReceiver), handler );
//          handler = wrapBy( new VersionChecker(controller), handler );

            baseParser.parse( source, handler, errorHandler, entityResolver );
        }
 
Example #12
Source File: SchemaBuilderImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param eh Error handler to receive errors while building the schema.
 * @param datatypeLibraryFactory This is consulted to locate datatype
 * libraries.
 * @param pb Used to build patterns.
 */
public SchemaBuilderImpl(ErrorHandler eh,
        DatatypeLibraryFactory datatypeLibraryFactory,
        SchemaPatternBuilder pb) {
    this.parent = null;
    this.eh = eh;
    this.datatypeLibraryFactory = datatypeLibraryFactory;
    this.pb = pb;
    this.inheritNs = "";
    this.openIncludes = null;
}
 
Example #13
Source File: SchemaBuilderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param eh Error handler to receive errors while building the schema.
 */
public SchemaBuilderImpl(ErrorHandler eh) {
    this(eh,
            new CascadingDatatypeLibraryFactory(new DatatypeLibraryLoader(),
            new BuiltinDatatypeLibraryFactory(new DatatypeLibraryLoader())),
            new SchemaPatternBuilder());
}
 
Example #14
Source File: ToSAXHandler.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.xml.sax.ErrorHandler#fatalError(SAXParseException)
 */
public void fatalError(SAXParseException exc) throws SAXException {
    super.fatalError(exc);

    m_needToCallStartDocument = false;

    if (m_saxHandler instanceof ErrorHandler) {
        ((ErrorHandler)m_saxHandler).fatalError(exc);
    }
}
 
Example #15
Source File: XMLUtilTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testHandlerLeak() throws Exception {
    ErrorHandler handler = new DefaultHandler();
    EntityResolver resolver = new DefaultHandler();
    Reference<?> handlerRef = new WeakReference<Object>(handler);
    Reference<?> resolverRef = new WeakReference<Object>(resolver);
    XMLUtil.parse(new InputSource(new StringReader("<hello/>")), false, false, handler, resolver);
    handler = null;
    resolver = null;
    assertGC("can collect handler", handlerRef);
    assertGC("can collect resolver", resolverRef);
}
 
Example #16
Source File: ValidateMojo.java    From xml-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Called for validating a single file.
 * 
 * @param pResolver The resolver to use for loading external entities.
 * @param pValidationSet The validators configuration.
 * @param pFile The file to validate.
 * @throws IOException An I/O error occurred.
 * @throws SAXException Parsing the file failed.
 * @throws ParserConfigurationException Creating an XML parser failed.
 */
private void parse( Resolver pResolver, ValidationSet pValidationSet, File pFile , ErrorHandler errorHandler)
    throws IOException, SAXException, ParserConfigurationException
{
    XMLReader xr = newSAXParserFactory( pValidationSet ).newSAXParser().getXMLReader();
    if ( pResolver != null )
    {
        xr.setEntityResolver( pResolver );
    }
    xr.setErrorHandler( errorHandler );
    xr.parse( pFile.toURI().toURL().toExternalForm() );
}
 
Example #17
Source File: FaultDetailHeader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void writeTo(ContentHandler h, ErrorHandler errorHandler) throws SAXException {
    String nsUri = av.nsUri;
    String ln = av.faultDetailTag.getLocalPart();

    h.startPrefixMapping("",nsUri);
    h.startElement(nsUri,ln,ln,EMPTY_ATTS);
    h.startElement(nsUri,wrapper,wrapper,EMPTY_ATTS);
    h.characters(problemValue.toCharArray(),0,problemValue.length());
    h.endElement(nsUri,wrapper,wrapper);
    h.endElement(nsUri,ln,ln);
}
 
Example #18
Source File: PayloadStreamReaderMessage.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
protected void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
    message.writePayloadTo(contentHandler, errorHandler, fragment);
}
 
Example #19
Source File: JAXBSource.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public ErrorHandler getErrorHandler() {
    return errorHandler;
}
 
Example #20
Source File: Parser.java    From Android-RTEditor with Apache License 2.0 4 votes vote down vote up
@Override
public ErrorHandler getErrorHandler() {
    return (theErrorHandler == this) ? null : theErrorHandler;
}
 
Example #21
Source File: IncrementalSAXSource_Filter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void setErrHandler(ErrorHandler handler)
{
  clientErrorHandler=handler;
}
 
Example #22
Source File: SAXParseable.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public SAXParseable(InputSource in, ErrorHandler eh) {
    this(in,eh,new JAXPXMLReaderCreator());
}
 
Example #23
Source File: RelaxNGCompactSchemaCache.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
public RelaxNGCompactSchemaCache (@Nullable final ErrorHandler aErrorHandler,
                                  @Nullable final LSResourceResolver aResourceResolver)
{
  super ("RelaxNGCompact", SchemaFactory.newInstance (XMLConstants.RELAXNG_NS_URI), aErrorHandler, aResourceResolver);
}
 
Example #24
Source File: ValidatorHandlerImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public ErrorHandler getErrorHandler() {
    return fComponentManager.getErrorHandler();
}
 
Example #25
Source File: StAXStream2SAX.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This class is only used internally so this method should never
 * be called.
 */
public void setErrorHandler(ErrorHandler handler) throws
    NullPointerException
{
}
 
Example #26
Source File: DefaultAnnotationParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public ContentHandler getContentHandler(
    AnnotationContext contest, String elementName,
    ErrorHandler errorHandler, EntityResolver entityResolver ) {
    return new DefaultHandler();
}
 
Example #27
Source File: JsonXmlReader.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public ErrorHandler getErrorHandler() {
	return errorHandler;
}
 
Example #28
Source File: IncrementalSAXSource_Filter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void setErrHandler(ErrorHandler handler)
{
  clientErrorHandler=handler;
}
 
Example #29
Source File: ErrorHandlerWrapper.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/** Returns the SAX error handler. */
public ErrorHandler getErrorHandler() {
    return fErrorHandler;
}
 
Example #30
Source File: XSOMParser.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public ErrorHandler getErrorHandler() {
    return userErrorHandler;
}