Search in sources :

Example 56 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory 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 57 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory 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 58 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory 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 59 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory 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)

Example 60 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project android by JetBrains.

the class ServiceXmlParser method parseManifestForPermissions.

private void parseManifestForPermissions(@NotNull File f) {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(f, new DefaultHandler() {

            @Override
            public void startElement(String uri, String localName, String tagName, Attributes attributes) throws SAXException {
                if (tagName.equals(SdkConstants.TAG_USES_PERMISSION) || tagName.equals(SdkConstants.TAG_USES_PERMISSION_SDK_23) || tagName.equals(SdkConstants.TAG_USES_PERMISSION_SDK_M)) {
                    String permission = attributes.getValue(SdkConstants.ANDROID_NS_NAME_PREFIX + SdkConstants.ATTR_NAME);
                    // Most permissions are "android.permission.XXX", so for readability, just remove the prefix if present
                    permission = permission.replace(SdkConstants.ANDROID_PKG_PREFIX + SdkConstants.ATTR_PERMISSION + ".", "");
                    myDeveloperServiceMetadata.addPermission(permission);
                }
            }
        });
    } catch (Exception e) {
        // This method shouldn't crash the user for any reason, as showing permissions is just
        // informational, but log a warning so developers can see if they make a mistake when
        // creating their service.
        LOG.warn("Failed to read permissions from AndroidManifest.xml", e);
    }
}
Also used : Attributes(org.xml.sax.Attributes) SAXParser(javax.xml.parsers.SAXParser) URISyntaxException(java.net.URISyntaxException) TemplateProcessingException(com.android.tools.idea.templates.FreemarkerUtils.TemplateProcessingException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException)

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