Package org.apache.xerces.parsers

Examples of org.apache.xerces.parsers.SAXParser


    }

    // private methods
    private synchronized void writeToSAX(ContentHandler handler) {
        // nothing must go wrong with this parse...
        SAXParser parser = fGrammar.getSAXParser();
        StringReader aReader = new StringReader(fData);
        InputSource aSource = new InputSource(aReader);
        parser.setContentHandler(handler);
        try {
            parser.parse(aSource);
        } catch (SAXException e) {
            // this should never happen!
            // REVISIT:  what to do with this?; should really not
            // eat it...
        } catch (IOException i) {
View Full Code Here


        // note that this should never produce errors or require
        // entity resolution, so just a barebones configuration with
        // a couple of feature  set will do fine
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
        fSAXParser = new SAXParser(config);
        return fSAXParser;
    }
View Full Code Here

        throws ServiceException {
        //InputSource requestSource = new InputSource((Reader) tempReader);
        InputSource requestSource = new InputSource(reader);

        // instantiante parsers and content handlers
        XMLReader parser = new SAXParser();
        this.currentRequest = new DispatcherHandler();

        // read in XML file and parse to content handler
        try {
            parser.setContentHandler(currentRequest);
            parser.parse(requestSource);
        } catch (SAXException e) {
            //SAXException does not sets initCause(). Instead, it holds its own "exception" field.
            if(e.getException() != null && e.getCause() == null){
                e.initCause(e.getException());
            }
View Full Code Here

     * @param xml  input stream representing the GETMAP file
     * @param SchemaUrl location of the schemas. Normally use ".../capabilities/sld/StyleLayerDescriptor.xsd"
     * @return list of SAXExceptions (0 if the file's okay)
     */
    public List validateGETMAP(InputSource xml, String SchemaUrl) {
        SAXParser parser = new SAXParser();

        try {
            parser.setFeature("http://xml.org/sax/features/validation", true);
            parser.setFeature("http://apache.org/xml/features/validation/schema", true);
            parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
                false);

            parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
                SchemaUrl);
            // parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation","http://www.opengis.net/sld "+SchemaUrl);
            parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
                "http://www.opengis.net/ows " + SchemaUrl);

            Validator handler = new Validator();
            parser.setErrorHandler(handler);
            parser.parse(xml);

            return handler.errors;
        } catch (java.io.IOException ioe) {
            ArrayList al = new ArrayList();
            al.add(new SAXParseException(ioe.getLocalizedMessage(), null));
View Full Code Here

     *        ".../schemas/sld/StyleLayerDescriptor.xsd"
     *
     * @return list of SAXExceptions (0 if the file's okay)
     */
    public List validateSLD(InputSource xml, ServletContext servContext) {
        SAXParser parser = new SAXParser();

        try {
            // this takes care of spaces in the path to the file
            URL schemaFile = servContext.getResource("/schemas/sld/StyledLayerDescriptor.xsd");

            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info(new StringBuffer("Validating SLD with ").append(schemaFile.toString())
                                                                    .toString());
            }

            String schemaUrl = schemaFile.toString();

            //     1. tell the parser to validate the XML document vs the schema
            //     2. does not validate the schema (the GML schema is *not* valid.  This is
            //              an OGC blunder)
            //     3. tells the validator that the tags without a namespace are actually
            //              SLD tags.
            //     4. tells the validator to 'override' the SLD schema that a user may
            //              include with the one inside geoserver.
            parser.setFeature("http://xml.org/sax/features/validation", true);
            parser.setFeature("http://apache.org/xml/features/validation/schema", true);
            parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
                false);

            parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
                schemaUrl);
            parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
                "http://www.opengis.net/sld " + schemaUrl);

            //parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation","http://www.opengis.net/ows "+SchemaUrl);
            Validator handler = new Validator();
            parser.setErrorHandler(handler);
            parser.parse(xml);

            return handler.errors;
        } catch (java.io.IOException ioe) {
            ArrayList al = new ArrayList();
            al.add(new SAXParseException(ioe.getLocalizedMessage(), null));
View Full Code Here

        InputStream instream = istream;

      ContentHandler contentHandler = new XML2ObjectContentHandler(new TestXML2Object());  
    long start = System.currentTimeMillis();

      XMLReader parser = new SAXParser();
      parser.setContentHandler(contentHandler);
      parser.parse(new InputSource(instream));

    long end = System.currentTimeMillis();
    System.out.println("Zeit: " + (end-start));
    }
View Full Code Here

           org.xml.sax.SAXException
  {
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor("foo.xsl");
    XSLTProcessor processor2 = XSLTProcessorFactory.getProcessor("foo2.xsl");
  
    SAXParser parser = new SAXParser();
   
    parser.setDocumentHandler(processor);
    processor.setDocumentHandler(processor2);
    processor2.setOutputStream(System.out);
   
    parser.parse(new InputSource("foo.xml"));
  }
View Full Code Here

        if (test_file.isDirectory())
            throw new Exception("The specified path " + file_path + " refers to a directory, not to a file.");

        // Prepare the XML parser with the validation feature on and the error handler
        // set to throw exceptions on all warnings and errors
        XMLReader reader = new SAXParser();
        reader.setFeature("http://xml.org/sax/features/validation", true);
        reader.setErrorHandler(new org.vocvark.XMLParsers.ParsingXMLErrorHandler());
        ParseFileHandler handler;

        // Choose the correct type handler based on the type of XML file
        if (document_type.equals("feature_list")) {
            handler = new FeatureListHandler();
        } else {
            // Throw an exception if an unknown type of XML file is specified
            throw new Exception("Invalid type of XML file specified. The XML file type " + document_type + " is not known.");
        }

        // Parse the file so that the contents are available in the parsed_file_contents field of the handler
        reader.setContentHandler(handler);
        try {
            reader.parse(file_path);
        } catch (SAXParseException e) // throw an exception if the file is not a valid XML file
        {
            throw new Exception("The " + file_path + " file is not a valid XML file.\n\nDetails of the problem: " + e.getMessage() +
                    "\n\nThis error is likely in the region of line " + e.getLineNumber() + ".");
        } catch (SAXException e) // throw an exception if the file is not an XML file of the correct type
View Full Code Here

    {
      // Fallback if this fails (implemented in createIncrementalSAXSource) is
      // to attempt Xerces-1 incremental setup. Can't do tail-call in
      // constructor, so create new, copy Xerces-1 initialization,
      // then throw it away... Ugh.
      IncrementalSAXSource_Xerces dummy=new IncrementalSAXSource_Xerces(new SAXParser());
      this.fParseSomeSetup=dummy.fParseSomeSetup;
      this.fParseSome=dummy.fParseSome;
      this.fIncrementalParser=dummy.fIncrementalParser;
    }
  }
View Full Code Here

    catch(NoSuchMethodException e)
    {
      // Xerces version mismatch; neither Xerces1 nor Xerces2 succeeded.
      // Fall back on filtering solution.
      IncrementalSAXSource_Filter iss=new IncrementalSAXSource_Filter();
      iss.setXMLReader(new SAXParser());
      return iss;
    }
  }
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.