Search in sources :

Example 86 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project GCViewer by chewiebug.

the class DataReaderIBM_J9_5_0 method read.

public GCModel read() throws IOException {
    if (getLogger().isLoggable(Level.INFO))
        getLogger().info("Reading IBM J9 5.0 format...");
    try (InputStream inStream = this.inputStream) {
        final GCModel model = new GCModel();
        model.setFormat(GCModel.Format.IBM_VERBOSE_GC);
        DefaultHandler handler = new IBMJ9SAXHandler(gcResource, model);
        // Use the default (non-validating) parser
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setValidating(false);
        javax.xml.parsers.SAXParser saxParser;
        try {
            saxParser = factory.newSAXParser();
            saxParser.parse(inStream, handler);
        } catch (ParserConfigurationException e) {
            final IOException exception = new IOException(e.toString());
            exception.initCause(e);
            throw exception;
        } catch (SAXException e) {
            // TODO: if(e.getMessage().startsWith("XML document structures must start and end within the same entity")) {
            if (e instanceof SAXParseException && ((SAXParseException) e).getColumnNumber() == 1) {
            // ignore. this just means a xml tag terminated.
            } else {
                final IOException exception = new IOException(e.toString());
                exception.initCause(e);
                throw exception;
            }
        }
        return model;
    } finally {
        if (getLogger().isLoggable(Level.INFO))
            getLogger().info("Done reading.");
    }
}
Also used : InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) GCModel(com.tagtraum.perf.gcviewer.model.GCModel) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 87 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project Fling by entertailion.

the class RampClient method parseXml.

private void parseXml(Reader reader) {
    try {
        InputSource inStream = new org.xml.sax.InputSource();
        inStream.setCharacterStream(reader);
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        AppHandler appHandler = new AppHandler();
        xr.setContentHandler(appHandler);
        xr.parse(inStream);
        connectionServiceUrl = appHandler.getConnectionServiceUrl();
        state = appHandler.getState();
        protocol = appHandler.getProtocol();
    } catch (Exception e) {
        Log.e(LOG_TAG, "parse device description", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader) ProtocolException(org.apache.http.ProtocolException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 88 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project Fling by entertailion.

the class FlingFrame method onBroadcastFound.

public void onBroadcastFound(final BroadcastAdvertisement advert) {
    if (advert.getLocation() != null) {
        new Thread(new Runnable() {

            public void run() {
                Log.d(LOG_TAG, "location=" + advert.getLocation());
                HttpResponse response = new HttpRequestHelper().sendHttpGet(advert.getLocation());
                if (response != null) {
                    String appsUrl = null;
                    Header header = response.getLastHeader(HEADER_APPLICATION_URL);
                    if (header != null) {
                        appsUrl = header.getValue();
                        if (!appsUrl.endsWith("/")) {
                            appsUrl = appsUrl + "/";
                        }
                        Log.d(LOG_TAG, "appsUrl=" + appsUrl);
                    }
                    try {
                        InputStream inputStream = response.getEntity().getContent();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                        InputSource inStream = new org.xml.sax.InputSource();
                        inStream.setCharacterStream(reader);
                        SAXParserFactory spf = SAXParserFactory.newInstance();
                        SAXParser sp = spf.newSAXParser();
                        XMLReader xr = sp.getXMLReader();
                        BroadcastHandler broadcastHandler = new BroadcastHandler();
                        xr.setContentHandler(broadcastHandler);
                        xr.parse(inStream);
                        Log.d(LOG_TAG, "modelName=" + broadcastHandler.getDialServer().getModelName());
                        // devices like ChromeCast devices
                        if (broadcastHandler.getDialServer().getModelName().equals(CHROME_CAST_MODEL_NAME)) {
                            Log.d(LOG_TAG, "ChromeCast device found: " + advert.getIpAddress().getHostAddress());
                            DialServer dialServer = new DialServer(advert.getLocation(), advert.getIpAddress(), advert.getPort(), appsUrl, broadcastHandler.getDialServer().getFriendlyName(), broadcastHandler.getDialServer().getUuid(), broadcastHandler.getDialServer().getManufacturer(), broadcastHandler.getDialServer().getModelName());
                            trackedServers.add(dialServer);
                        }
                    } catch (Exception e) {
                        Log.e(LOG_TAG, "parse device description", e);
                    }
                }
            }
        }).start();
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Header(org.apache.http.Header) BufferedReader(java.io.BufferedReader) SAXParser(javax.xml.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 89 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project iosched by google.

the class SVGParser method parse.

static SVG parse(InputSource data, SVGHandler handler) throws SVGParseException {
    try {
        final Picture picture = new Picture();
        handler.setPicture(picture);
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        xr.setContentHandler(handler);
        xr.setFeature("http://xml.org/sax/features/validation", false);
        if (DISALLOW_DOCTYPE_DECL) {
            try {
                xr.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            } catch (SAXNotRecognizedException e) {
                DISALLOW_DOCTYPE_DECL = false;
            }
        }
        xr.parse(data);
        SVG result = new SVG(picture, handler.bounds);
        // Skip bounds if it was an empty pic
        if (!Float.isInfinite(handler.limits.top)) {
            result.setLimits(handler.limits);
        }
        return result;
    } catch (Exception e) {
        Log.e(TAG, "Failed to parse SVG.", e);
        throw new SVGParseException(e);
    }
}
Also used : Picture(android.graphics.Picture) SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) XMLReader(org.xml.sax.XMLReader) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 90 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project groovy-core by groovy.

the class XmlUtil method newSAXParser.

private static SAXParser newSAXParser(boolean namespaceAware, boolean validating, Schema schema1) throws ParserConfigurationException, SAXException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(validating);
    factory.setNamespaceAware(namespaceAware);
    factory.setSchema(schema1);
    return factory.newSAXParser();
}
Also used : SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

SAXParserFactory (javax.xml.parsers.SAXParserFactory)183 SAXParser (javax.xml.parsers.SAXParser)141 InputSource (org.xml.sax.InputSource)76 SAXException (org.xml.sax.SAXException)75 IOException (java.io.IOException)62 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)53 XMLReader (org.xml.sax.XMLReader)37 DefaultHandler (org.xml.sax.helpers.DefaultHandler)27 InputStream (java.io.InputStream)22 File (java.io.File)21 SAXSource (javax.xml.transform.sax.SAXSource)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 StringReader (java.io.StringReader)15 Unmarshaller (javax.xml.bind.Unmarshaller)13 Attributes (org.xml.sax.Attributes)13 JAXBContext (javax.xml.bind.JAXBContext)12 SAXParseException (org.xml.sax.SAXParseException)10 InputStreamReader (java.io.InputStreamReader)9 ArrayList (java.util.ArrayList)9 ValidationEvent (javax.xml.bind.ValidationEvent)9