use of org.xml.sax.helpers.DefaultHandler in project spring-security-oauth by spring-projects.
the class SparklrServiceImpl method getSparklrPhotoIds.
public List<String> getSparklrPhotoIds() throws SparklrException {
try {
InputStream photosXML = new ByteArrayInputStream(sparklrRestTemplate.getForObject(URI.create(sparklrPhotoListURL), byte[].class));
final List<String> photoIds = new ArrayList<String>();
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(false);
parserFactory.setXIncludeAware(false);
parserFactory.setNamespaceAware(false);
SAXParser parser = parserFactory.newSAXParser();
parser.parse(photosXML, new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if ("photo".equals(qName)) {
photoIds.add(attributes.getValue("id"));
}
}
});
return photoIds;
} catch (IOException e) {
throw new IllegalStateException(e);
} catch (SAXException e) {
throw new IllegalStateException(e);
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
}
}
use of org.xml.sax.helpers.DefaultHandler in project intellij-community by JetBrains.
the class RngSchemaValidator method collectInformation.
@Nullable
@Override
public MyValidationMessageConsumer collectInformation(@NotNull final PsiFile file) {
final FileType type = file.getFileType();
if (type != StdFileTypes.XML && type != RncFileType.getInstance()) {
return null;
}
final XmlFile xmlfile = (XmlFile) file;
final XmlDocument document = xmlfile.getDocument();
if (document == null) {
return null;
}
if (type == StdFileTypes.XML) {
final XmlTag rootTag = document.getRootTag();
if (rootTag == null) {
return null;
}
if (!ApplicationLoader.RNG_NAMESPACE.equals(rootTag.getNamespace())) {
return null;
}
} else {
if (!ApplicationManager.getApplication().isUnitTestMode() && MyErrorFinder.hasError(xmlfile)) {
return null;
}
}
final Document doc = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
final MyValidationMessageConsumer consumer = new MyValidationMessageConsumer();
ErrorHandler eh = new DefaultHandler() {
@Override
public void warning(SAXParseException e) {
handleError(e, file, doc, consumer.warning());
}
@Override
public void error(SAXParseException e) {
handleError(e, file, doc, consumer.error());
}
};
RngParser.parsePattern(file, eh, true);
return consumer;
}
use of org.xml.sax.helpers.DefaultHandler in project smali by JesusFreke.
the class BaksmaliOptions method loadResourceIds.
/**
* Load the resource ids from a set of public.xml files.
*
* @param resourceFiles A map of resource prefixes -> public.xml files
*/
public void loadResourceIds(Map<String, File> resourceFiles) throws SAXException, IOException {
for (Map.Entry<String, File> entry : resourceFiles.entrySet()) {
try {
SAXParser saxp = SAXParserFactory.newInstance().newSAXParser();
final String prefix = entry.getKey();
saxp.parse(entry.getValue(), new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attr) throws SAXException {
if (qName.equals("public")) {
String resourceType = attr.getValue("type");
String resourceName = attr.getValue("name").replace('.', '_');
Integer resourceId = Integer.decode(attr.getValue("id"));
String qualifiedResourceName = String.format("%s.%s.%s", prefix, resourceType, resourceName);
resourceIds.put(resourceId, qualifiedResourceName);
}
}
});
} catch (ParserConfigurationException ex) {
throw new RuntimeException(ex);
}
}
}
use of org.xml.sax.helpers.DefaultHandler in project android_frameworks_base by DirtyUnicorns.
the class ExpatPerformanceTest method runSax.
private void runSax() throws IOException, SAXException {
long start = System.currentTimeMillis();
Xml.parse(newInputStream(), Xml.Encoding.UTF_8, new DefaultHandler());
long elapsed = System.currentTimeMillis() - start;
Log.i(TAG, "expat SAX: " + elapsed + "ms");
}
use of org.xml.sax.helpers.DefaultHandler in project jdk8u_jdk by JetBrains.
the class SupplementaryChars method test.
@Test(dataProvider = "supported")
public void test(String xml) throws Exception {
ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
getParser().parse(stream, new DefaultHandler());
stream.close();
}
Aggregations