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;
}
}
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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
Aggregations