Package org.apache.xerces.parsers

Examples of org.apache.xerces.parsers.SAXParser


    }
   
    public void testLocatorReturnsNullSystemIDWithRelativeURL()
      throws ParsingException, IOException {
       
        XMLReader reader = new SAXParser();
        reader = new LocatorFilter(reader);
        Builder builder = new Builder(reader);
        InputStream in = new FileInputStream("data/quirks.xhtml");
        try {
            builder.build(in);
View Full Code Here


      StringReader s = new StringReader(doc);
      builder.build(s);
    }
   
    public void testMisbehavingParserInternalDTDSubset() throws IOException {
        XMLReader reader = new SAXParser();
        reader = new MalformedDTDFilter(reader);
        Builder builder = new Builder(reader);
        try {
            builder.build(validDoc, "http://www.example.com");
            fail("didn't catch malformed internal DTD subset");
View Full Code Here

              if(matcher.find()){
                xml = removeMatched(xml,matcher.start(),matcher.end());
              }
            }
           
            SAXParser parser = new SAXParser();
           
            String   dtd = getDTD(xml, false);
            String[] xsd = getXSD(xml, false);
           
            // Validation configuration
            if((dtd==null && xsd==null) || !params.getUseDTD()){
              parser.setFeature("http://xml.org/sax/features/validation", false);
            } else {
              parser.setFeature("http://xml.org/sax/features/validation", true);
              parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
            }
            if(xsd!=null && params.getUseDTD()){
//              parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
//              parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", xsd);
              parser.setFeature("http://apache.org/xml/features/validation/schema", true);
              parser.setFeature("http://xml.org/sax/features/namespaces", true);
            }
           
            parser.setFeature("http://xml.org/sax/features/use-entity-resolver2", true);
            parser.setEntityResolver(new DTDResolver(getDTDResolvers(),
                input.getFile().getLocation().makeAbsolute().toFile().getParentFile()));
            parser.setErrorHandler(new XMLValidationHandler(resource));
           
            parser.parse(new InputSource(new StringReader(xml))); //new ByteArrayInputStream(xml.getBytes(charset))));
           
          } catch(Exception ex){
            // ignore
            //HTMLPlugin.logException(ex);
          }
View Full Code Here

    * @param schemaURLDeque The mapping of schema URLs to other URLs that will
    * be used as the actual locations of those schemas, in the schema parse order.
    */
   private static void parse(XMLInputSource source, Object handler, EntityResolver resolver, LookupDeque schemaURLDeque)
   {
      SAXParser parser = null;
      XMLParserConfiguration config = null;

      // Try to get a parser for the given grammar from the pool

      synchronized (s_saxParserMap)
      {
         List holderList = (List)s_saxParserMap.get(getKey(schemaURLDeque));

         if (holderList != null)
         {
            SAXHolder holder = null;

            while (holderList.size() > 0 && holder == null)
            {
               holder = (SAXHolder)((SoftReference)holderList.remove(holderList.size() - 1)).get();
            }

            if (holder != null)
            {
               parser = holder.getParser();
               config = holder.getConfig();
            }
         }
      }

      ClassLoader classLoaderSaved = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(XMLUtil.class.getClassLoader());

      // Parse the source stream

      try
      {
         // If the attempt to retrieve a parser failed, create a new one

         if (parser == null)
         {
            config = getParserConfiguration(schemaURLDeque);
            parser = new SAXParser(config);
            parser.setProperty(BUFFER_SIZE_PROPERTY, BUFFER_SIZE);
         }

         parser.setContentHandler((handler instanceof ContentHandler) ? (ContentHandler)handler : DEFAULT_HANDLER);
         parser.setErrorHandler((handler instanceof ErrorHandler) ? (ErrorHandler)handler : DEFAULT_HANDLER);
         parser.setDTDHandler((handler instanceof DTDHandler) ? (DTDHandler)handler : DEFAULT_HANDLER);
         parser.setEntityResolver((resolver != null) ? resolver : DEFAULT_HANDLER);

         if (handler instanceof LexicalHandler)
         {
            parser.setProperty(LEXICAL_HANDLER_PROPERTY, handler);
         }

         if (handler instanceof IncrementalHandler && config instanceof XMLPullParserConfiguration)
         {
            IncrementalHandler incrementalHandler = (IncrementalHandler)handler;
            XMLPullParserConfiguration pullConfig = (XMLPullParserConfiguration)config;

            pullConfig.setInputSource(source);
            parser.reset();

            while (!incrementalHandler.isComplete() && pullConfig.parse(false)) ;
         }
         else
         {
            parser.parse(source);
         }
      }
      catch (XMLParseException e)
      {
         throw convertException(e);
      }
      catch (Exception e)
      {
         throw new XMLException("err.xml.parse", e);
      }
      finally
      {
         // Put the parser back into the pool, using a soft reference

         if (parser != null)
         {
            try
            {
               parser.setContentHandler(DEFAULT_HANDLER);
               parser.setEntityResolver(DEFAULT_HANDLER);
               parser.setErrorHandler(DEFAULT_HANDLER);
               parser.setDTDHandler(DEFAULT_HANDLER);
               parser.setProperty(LEXICAL_HANDLER_PROPERTY, null);
               parser.reset();

               if (config instanceof XMLPullParserConfiguration)
               {
                  ((XMLPullParserConfiguration)config).cleanup();
               }
View Full Code Here

    /** the Entity Resolver */
    protected Resolver resolver = null;

    public XercesParser ()
    throws SAXException {
        this.parser = new SAXParser();

        this.parser.setFeature("http://xml.org/sax/features/validation", false);
        this.parser.setFeature("http://xml.org/sax/features/namespaces", true);
    }
View Full Code Here

        // it's not all that good to have a concrete dependency on Xerces
        // and a particular version, at that.
        // but schema support in the Xerces series of parsers is variable
        // and some of the configuration details differ.
        // At least this way seems reliable
        SAXParser parser = new SAXParser();
   
        // Set features
        parser.setFeature(NAMESPACES_FEATURE_ID, true);
        parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, false);
        parser.setFeature(VALIDATION_FEATURE_ID, true);
        parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
        parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, false);
        parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, false);
   
        // Set properties
        parser.setProperty(NONAMESPACE_SCHEMA_LOCATION_PROPERTY_ID, "schema.xsd");
   
        XMLUnitHandler handler = new XMLUnitHandler(schemaSource);
   
        // Set handlers
        parser.setContentHandler(handler);
        parser.setErrorHandler(handler);
        parser.setEntityResolver(handler);
   
        // parse document
        parser.parse(documentSource);
        handler.reportErrors();
    }
View Full Code Here

        }

        DTDReader   handler = new DTDReader();

        try {
            SAXParser  parser = new SAXParser( );
            parser.setProperty( "http://xml.org/sax/properties/declaration-handler", handler );
            System.out.println( "argv = " + argv[0] );
            parser.parse( argv[0] );

        } catch ( Exception ex ){
            ex.printStackTrace();
        }
View Full Code Here

       
        // construct handler
        DefaultHandler handler = new DocumentTracer();

        // construct parser; set features
        XMLReader parser = new SAXParser();
        try {
            parser.setFeature("http://xml.org/sax/features/namespaces", true);
        }
        catch (SAXException e) {
            e.printStackTrace(System.err);
        }
        try {
            parser.setFeature("http://xml.org/sax/features/validation", true);
        }
        catch (SAXException e) {
            e.printStackTrace(System.err);
        }

        // set handlers
        parser.setContentHandler(handler);
        parser.setDTDHandler(handler);
        parser.setErrorHandler(handler);
        try {
            parser.setProperty("http://xml.org/sax/properties/declaration-handler", handler);
        }
        catch (SAXException e) {
            e.printStackTrace(System.err);
        }
        try {
            parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
        }
        catch (SAXException e) {
            e.printStackTrace(System.err);
        }

        // parser files
        for (int i = 0; i < argv.length; i++) {
            String arg = argv[i];
            System.err.println("# argv["+i+"]: "+arg);
            //print(arg);
            try {
                parser.parse(arg);
            }
            catch (SAXException e) {
                Exception ex = e.getException();
                throw ex != null ? ex : e;
            }
View Full Code Here

   * @throws Exception Exception, if an error occured while
   *                   generating the parser table
   */
  private ParserTable parseGrammar(File grammarFile) throws Exception
  {
    final SAXParser parser = new SAXParser();
    final SAXGrammarGenerator gg = new SAXGrammarGenerator();

    parser.setContentHandler(gg);

    info("parsing grammar file " + grammarFile.getName() + "...");
    parser.parse(grammarFile.getAbsolutePath());

    info("building parser table...");
    final Grammar g = gg.getGrammar();

    if (g == null)
View Full Code Here

    /** the Entity Resolver */
    protected Resolver resolver = null;

    public XercesParser ()
    throws SAXException {
        this.parser = new SAXParser();

        this.parser.setFeature("http://xml.org/sax/features/validation", false);
        this.parser.setFeature("http://xml.org/sax/features/namespaces", true);
    }
View Full Code Here

TOP

Related Classes of org.apache.xerces.parsers.SAXParser

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.