Package org.xml.sax

Examples of org.xml.sax.Parser


        state.markAsProcessed(schemaLocation, importedSchema);

        if (alreadyLoaded) return;
       
        //-- Parser Schema
    Parser parser = null;
    try {
        parser = getSchemaContext().getParser();
    }
    catch(RuntimeException rte) {}
    if (parser == null) {
        throw new SchemaException("Error failed to create parser for import");
    }
    //-- Create Schema object and setup unmarshaller
    SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(getSchemaContext(), state);
    schemaUnmarshaller.setURIResolver(getURIResolver());
    schemaUnmarshaller.setSchema(importedSchema);
    Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
    parser.setDocumentHandler(handler);
    parser.setErrorHandler(handler);

    try {
        InputSource source = new InputSource(uri.getReader());
            source.setSystemId(uri.getAbsoluteURI());
            parser.parse(source);
    }
    catch(java.io.IOException ioe) {
        throw new SchemaException("Error reading import file '"+schemaLocation+"': "+ ioe);
    }
    catch(org.xml.sax.SAXException sx) {
View Full Code Here


     */
    private void init() throws IOException {
        // -- get default parser from Configuration
        _schemaContext = new SchemaContextImpl();

        Parser parser = _schemaContext.getParser();

        if (parser == null) {
            String message = "fatal error: unable to create SAX parser.";
            LOG.warn(message);
            throw new IOException(message);
View Full Code Here

     * @param schemaContext the {@link SchemaContext} to be used
     */
    public void setSchemaContext(final SchemaContext schemaContext) {
        this._schemaContext = schemaContext;
       
        Parser p = _schemaContext.getParser();
        if (p != null) {
            _parser = p;
        }
    }
View Full Code Here

     * @throws IOException if an IOException occurs writing the new source files
     */
    public void generateSource(final InputSource source, final String packageName)
    throws IOException {
        // -- get default parser from Configuration
        Parser parser = null;
        try {
            parser = _internalContext.getParser();
        } catch (RuntimeException rte) {
            // ignore
        }

        if (parser == null) {
            _dialog.notify("fatal error: unable to create SAX parser.");
            return;
        }

        SchemaContext schemaContext = new SchemaContextImpl();
        SchemaUnmarshaller schemaUnmarshaller = null;
        try {
           schemaUnmarshaller = new SchemaUnmarshaller(schemaContext);
        } catch (XMLException e) {
            //--The default constructor cannot throw exception so this should never happen
            //--just log the exception
            e.printStackTrace();
            System.exit(1);
        }

        Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
        parser.setDocumentHandler(handler);
        parser.setErrorHandler(handler);

        try {
            parser.parse(source);
        } catch (java.io.IOException ioe) {
            _dialog.notify("error reading XML Schema file");
            if (_failOnFirstError) {
                throw ioe;
            }
View Full Code Here

     * to create the actual instance.
     * @param className The class name of the {@link Parser} instance to be instantiated.
     * @return An {@link Parser} instance.
     */
    public static Parser instantiateParser (final String className) {
        Parser parser;
        try {
            Class cls;
            cls = Class.forName(className);
            parser = (Parser) cls.newInstance();
            if (LOG.isDebugEnabled()) {
View Full Code Here

        }
        return parser;
    }
   
    public static Parser getParser(final AbstractProperties properties, final String features) {
        Parser parser = null;
        Boolean validation = properties.getBoolean(XMLProperties.PARSER_VALIDATION);
        Boolean namespaces = properties.getBoolean(XMLProperties.NAMESPACES);
        String parserClassName = properties.getString(XMLProperties.PARSER);
        if ((parserClassName == null) || (parserClassName.length() == 0)) {
            SAXParser saxParser = XMLParserUtils.getSAXParser(
View Full Code Here

    public Schema createSchema(InputSource source) throws IOException {
        XMLInstance2SchemaHandler handler = new XMLInstance2SchemaHandler();
        handler.setDefaultGroupOrder(_defaultGroup);

        try {
            Parser parser = _internalContext.getParser();
            if (parser == null) {
                throw new IOException(
                        "fatal error: unable to create SAX parser.");
            }
            parser.setDocumentHandler(handler);
            parser.setErrorHandler(handler);
            parser.parse(source);
        } catch (org.xml.sax.SAXException sx) {
            throw new NestedIOException(sx);
        }
        return handler.getSchema();
    }
View Full Code Here

        //-- keep track of the schemaLocation
        schema.addInclude(include);

        if (alreadyLoaded)
          return;
    Parser parser = null;
    try {
        parser = getSchemaContext().getParser();
    }
    catch(RuntimeException rte) {}
    if (parser == null) {
        throw new SchemaException("Error failed to create parser for include");
    }
    SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(getSchemaContext(), true, state, getURIResolver());

    if (state.cacheIncludedSchemas)
        schemaUnmarshaller.setSchema(includedSchema);
    else
      schemaUnmarshaller.setSchema(schema);
   
    Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
    parser.setDocumentHandler(handler);
    parser.setErrorHandler(handler);

    try {
            InputSource source = new InputSource(uri.getReader());
            source.setSystemId(uri.getAbsoluteURI());
            parser.parse(source);
    }
    catch(java.io.IOException ioe) {
        throw new SchemaException("Error reading include file '"+include+"'");
    }
    catch(org.xml.sax.SAXException sx) {
View Full Code Here

         *
         * @see org.exolab.castor.builder.SourceGenerator
         *      #generateSource(org.xml.sax.InputSource, java.lang.String)
         */
        public void generateSource(final InputSource source, final String packageName) {
            Parser parser = null;
            try {
                parser = _internalContext.getParser();
            } catch (RuntimeException e) {
                throw new BuildException("Unable to create SAX parser.", e);
            }
            if (parser == null) {
                throw new BuildException("Unable to create SAX parser.");
            }

            SchemaContext schemaContext = new SchemaContextImpl();
            SchemaUnmarshaller schemaUnmarshaller = null;
            try {
                schemaUnmarshaller = new SchemaUnmarshaller(schemaContext);
            } catch (XMLException e) {
                throw new BuildException("Unable to create schema unmarshaller.", e);
            }

            Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
            parser.setDocumentHandler(handler);
            parser.setErrorHandler(handler);
            try {
                parser.parse(source);
            } catch (IOException e) {
                String msg = "Can't read input file " + source.getSystemId() + ".\n" + e;
                throw new BuildException(msg, e);
            } catch (SAXException e) {
                String msg = "Can't parse input file " + source.getSystemId() + ".\n" + e;
View Full Code Here

        if (bResolver != null) {
          spHandler.setEntityResolver(bResolver);
        }
        parser.parse(new InputSource(is), spHandler);
      } else {
        Parser parser = (Parser) ReflectUtil.forName(parserClass).newInstance();
        parser.setDocumentHandler(this);
        if (bResolver != null) {
          parser.setEntityResolver(bResolver);
        }
        parser.parse(new InputSource(is));
      }
    } catch (ClassNotFoundException cnfe) {
      throw new CatalogException(CatalogException.UNPARSEABLE);
    } catch (IllegalAccessException iae) {
      throw new CatalogException(CatalogException.UNPARSEABLE);
View Full Code Here

TOP

Related Classes of org.xml.sax.Parser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.