Package org.xml.sax

Examples of org.xml.sax.XMLReader


      InputStream is = file.openStream();

      try{
         InputSource input = new InputSource(is);
         input.setSystemId(file.toURI().toString());
         XMLReader reader = XMLReaderFactory.createXMLReader();
         reader.setEntityResolver(new JBossEntityResolver());
         SAXSource source = new SAXSource(reader, input);
         JAXBElement<TranslatorMetaDataGroup> elem = um.unmarshal(source, TranslatorMetaDataGroup.class);
         TranslatorMetaDataGroup deployment = elem.getValue();
         return deployment;
      }     
View Full Code Here


    public void parse(InputStream is) throws Exception {
        //DocumentTable store = new ProfiledDocumentTable(File.createTempFile("dtm_profile", "csv"));
        IDocumentTable store = new DocumentTable();
        DocumentTableBuilder handler = new DocumentTableBuilder(store);
        XMLReader reader = getXMLReader(handler);
        reader.parse(new InputSource(new BufferedInputStream(is)));
    }
View Full Code Here

        XMLReader reader = getXMLReader(handler);
        reader.parse(new InputSource(new BufferedInputStream(is)));
    }

    protected static final XMLReader getXMLReader(DocumentTableBuilder handler) throws Exception {
        final XMLReader myReader;

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        SAXParser parser = factory.newSAXParser();
        myReader = parser.getXMLReader();

        // setup handlers (requires saxHandler)
        myReader.setContentHandler(handler);
        myReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
        myReader.setFeature("http://xml.org/sax/features/validation", true);
        myReader.setFeature("http://apache.org/xml/features/validation/dynamic", true);
        myReader.setFeature("http://apache.org/xml/features/validation/schema", true);

        return myReader;
    }
View Full Code Here

         */
        public LocationResponse(HttpURLConnection connection) throws IOException {
            super(connection);
            if(connection.getResponseCode() < 400) {
                try {
                    XMLReader xr=Utils.createXMLReader();
                    ;
                    LocationResponseHandler handler=new LocationResponseHandler();
                    xr.setContentHandler(handler);
                    xr.setErrorHandler(handler);

                    xr.parse(new InputSource(connection.getInputStream()));
                    this.location=handler.loc;
                }
                catch(SAXException e) {
                    throw new RuntimeException("Unexpected error parsing ListAllMyBuckets xml", e);
                }
View Full Code Here

        public ListBucketResponse(HttpURLConnection connection) throws IOException {
            super(connection);
            if(connection.getResponseCode() < 400) {
                try {
                    XMLReader xr=Utils.createXMLReader();
                    ListBucketHandler handler=new ListBucketHandler();
                    xr.setContentHandler(handler);
                    xr.setErrorHandler(handler);

                    xr.parse(new InputSource(connection.getInputStream()));

                    this.name=handler.getName();
                    this.prefix=handler.getPrefix();
                    this.marker=handler.getMarker();
                    this.delimiter=handler.getDelimiter();
View Full Code Here

        public ListAllMyBucketsResponse(HttpURLConnection connection) throws IOException {
            super(connection);
            if(connection.getResponseCode() < 400) {
                try {
                    XMLReader xr=Utils.createXMLReader();
                    ;
                    ListAllMyBucketsHandler handler=new ListAllMyBucketsHandler();
                    xr.setContentHandler(handler);
                    xr.setErrorHandler(handler);

                    xr.parse(new InputSource(connection.getInputStream()));
                    this.entries=handler.getEntries();
                }
                catch(SAXException e) {
                    throw new RuntimeException("Unexpected error parsing ListAllMyBuckets xml", e);
                }
View Full Code Here

   
    // Create a SAXParser
    SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        spf.setValidating(true);
        XMLReader reader = null;

    // set the features on the parser
    try{
          SAXParser parser = spf.newSAXParser();
          parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); //$NON-NLS-1$ //$NON-NLS-2$
          parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", nameSpaceMap.keySet().toArray())//$NON-NLS-1$
          reader = parser.getXMLReader();
    } catch (SAXException err) {
            throw new TeiidComponentException(err);
        } catch (ParserConfigurationException err) {
            throw new TeiidComponentException(err);
        }
   
    // place the schema into the customized entity resolver so that we can
    // resolve the schema elements
    EntityResolver xmlEntityResolver = new MultiEntityResolver(nameSpaceMap);
    reader.setEntityResolver(xmlEntityResolver);

    // Create the specialized error handler so that we can get any warnings,
    // errors, or fatal errors back from validation
    MMErrorHandler errorHandler = new MMErrorHandler();   
    reader.setErrorHandler(errorHandler);
   
    // create the input stream for the xml document to be parsed
    InputSource source = new InputSource(xmlStream);
   
    try{
        reader.parse(source);
    } catch(SAXException se){
      throw new TeiidComponentException(se);
    } catch(IOException io){
      throw new TeiidComponentException(io);
    }
View Full Code Here

    }
    byte[] b = bArray.toByteArray();
    try {
      ParseErrorHandler errHandler = new ParseErrorHandler();
      errHandler.setExitOnError(false);
      XMLReader parser = (XMLReader)Class.forName(parserName).newInstance();
      parser.setFeature("http://xml.org/sax/features/validation",true);
      parser.setErrorHandler(errHandler);
      parser.parse(new InputSource(new ByteArrayInputStream(b)));
      if (errHandler.hasErrors()) {
        return false;
      }
      logger.debug("XML Document is valid!");
      return true;
View Full Code Here

        // Parse document
        try {

            BasicUserMappingContentHandler contentHandler = new BasicUserMappingContentHandler();

            XMLReader parser = XMLReaderFactory.createXMLReader();
            parser.setContentHandler(contentHandler);
            parser.parse(mapFile.getAbsolutePath());

            mappingTime = mapFile.lastModified();
            mapping = contentHandler.getUserMapping();

        }
View Full Code Here

            throws XQueryException {
        this.loadDocument(is);
    }

    private static final XMLReader getXMLReader(final DocumentTableBuilder handler, final boolean parseAsHtml, final boolean resolveEntity) {
        final XMLReader myReader;
        try {
            if(parseAsHtml) {
                Class clazz = ClassResolver.get(HTML_PARSER_CLASS);
                assert (clazz != null);
                myReader = ObjectUtils.<XMLReader> instantiate(clazz);
            } else {
                final SAXParserFactory factory;
                if(hasSunXerces) {
                    factory = ObjectUtils.instantiate("com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl", null);
                } else {
                    factory = SAXParserFactory.newInstance();
                }
                factory.setNamespaceAware(true);
                SAXParser parser = factory.newSAXParser();
                myReader = parser.getXMLReader();
            }
        } catch (Exception e) {
            throw new XQRTException("Creating SAX XMLReader failed", e);
        }
        // setup handlers (requires saxHandler)
        myReader.setContentHandler(handler);
        try {
            myReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
            myReader.setFeature("http://xml.org/sax/features/validation", true); // Validate the document and report validity errors.
            if(!parseAsHtml) {
                myReader.setFeature("http://apache.org/xml/features/validation/dynamic", true); // The parser will validate the document only if a grammar is specified.  
                myReader.setFeature("http://apache.org/xml/features/validation/schema", true); // Turn on XML Schema validation by inserting an XML Schema validator into the pipeline.  
            }
        } catch (Exception e) {
            throw new XQRTException("Configuaring SAX XMLReader failed.", e);
        }
        // setup entity resolver
        if(resolveEntity) {
            org.apache.xml.resolver.CatalogManager catalog = org.apache.xml.resolver.CatalogManager.getStaticManager();
            catalog.setIgnoreMissingProperties(true);
            catalog.setPreferPublic(true);
            catalog.setUseStaticCatalog(false);
            EntityResolver resolver = new org.apache.xml.resolver.tools.CatalogResolver(catalog);
            myReader.setEntityResolver(resolver);
        }
        return myReader;
    }
View Full Code Here

TOP

Related Classes of org.xml.sax.XMLReader

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.