Search in sources :

Example 71 with SAXParser

use of javax.xml.parsers.SAXParser in project jmeter by apache.

the class DefaultSamplerCreator method isPotentialXml.

/**
     * Tries parsing to see if content is xml
     * @param postData String
     * @return boolean
     */
private static boolean isPotentialXml(String postData) {
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser saxParser = spf.newSAXParser();
        XMLReader xmlReader = saxParser.getXMLReader();
        ErrorDetectionHandler detectionHandler = new ErrorDetectionHandler();
        xmlReader.setContentHandler(detectionHandler);
        xmlReader.setErrorHandler(detectionHandler);
        xmlReader.parse(new InputSource(new StringReader(postData)));
        return !detectionHandler.isErrorDetected();
    } catch (ParserConfigurationException | SAXException | IOException e) {
        return false;
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 72 with SAXParser

use of javax.xml.parsers.SAXParser in project maven-plugins by apache.

the class JiraXML method parse.

void parse(InputSource xmlSource) throws MojoExecutionException {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(xmlSource, this);
    } catch (Throwable t) {
        throw new MojoExecutionException("Failed to parse JIRA XML.", t);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 73 with SAXParser

use of javax.xml.parsers.SAXParser in project intellij-community by JetBrains.

the class ImportedToGeneralTestEventsConverter method parseTestResults.

public static void parseTestResults(Reader reader, final DefaultHandler contentHandler) throws IOException {
    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        parser.parse(new InputSource(reader), contentHandler);
    } catch (ParserConfigurationException | SAXException e) {
        throw new IOException(e);
    } finally {
        reader.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 74 with SAXParser

use of javax.xml.parsers.SAXParser in project intellij-community by JetBrains.

the class EclipseXmlProfileReader method readSettings.

/**
   * Reads either basic profile info (name) or all the settings depending on whether <code>settings</code> parameter is null.
   * 
   * @param input The input stream to read from.
   * @throws SchemeImportException
   */
protected void readSettings(InputStream input) throws SchemeImportException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(false);
    SAXParser parser;
    try {
        parser = spf.newSAXParser();
        parser.parse(input, this);
    } catch (Exception e) {
        if (e.getCause() instanceof NonEclipseXmlFileException) {
            throw new SchemeImportException("The input file is not a valid Eclipse XML profile.");
        } else {
            throw new SchemeImportException(e);
        }
    }
}
Also used : SchemeImportException(com.intellij.openapi.options.SchemeImportException) SAXParser(javax.xml.parsers.SAXParser) SchemeImportException(com.intellij.openapi.options.SchemeImportException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 75 with SAXParser

use of javax.xml.parsers.SAXParser in project intellij-community by JetBrains.

the class EclipseThemeReader method readSettings.

protected void readSettings(InputStream input) throws SchemeImportException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(false);
    SAXParser parser;
    try {
        parser = spf.newSAXParser();
        parser.parse(input, this);
    } catch (Exception e) {
        if (e.getCause() instanceof NotAnEclipseThemeException) {
            throw new SchemeImportException("The input file is not a valid Eclipse theme.");
        } else {
            throw new SchemeImportException(e);
        }
    }
}
Also used : SchemeImportException(com.intellij.openapi.options.SchemeImportException) SAXParser(javax.xml.parsers.SAXParser) SchemeImportException(com.intellij.openapi.options.SchemeImportException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

SAXParser (javax.xml.parsers.SAXParser)235 SAXParserFactory (javax.xml.parsers.SAXParserFactory)142 SAXException (org.xml.sax.SAXException)112 InputSource (org.xml.sax.InputSource)95 IOException (java.io.IOException)80 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)71 DefaultHandler (org.xml.sax.helpers.DefaultHandler)37 XMLReader (org.xml.sax.XMLReader)36 File (java.io.File)35 ByteArrayInputStream (java.io.ByteArrayInputStream)28 StringReader (java.io.StringReader)27 InputStream (java.io.InputStream)24 Attributes (org.xml.sax.Attributes)22 SAXSource (javax.xml.transform.sax.SAXSource)17 SAXParseException (org.xml.sax.SAXParseException)17 ArrayList (java.util.ArrayList)13 JAXBContext (javax.xml.bind.JAXBContext)12 Unmarshaller (javax.xml.bind.Unmarshaller)12 FileNotFoundException (java.io.FileNotFoundException)10 ValidationEvent (javax.xml.bind.ValidationEvent)9