use of org.xml.sax.helpers.DefaultHandler in project spring-security-oauth by spring-projects.
the class GoogleServiceImpl method getLastTenPicasaPictureURLs.
public List<String> getLastTenPicasaPictureURLs() {
// byte[] bytes = getGoogleRestTemplate().getForObject(URI.create("https://picasaweb.google.com/data/feed/api/user/default"), byte[].class);
byte[] bytes = getGoogleRestTemplate().getForObject(URI.create("https://picasaweb.google.com/data/feed/api/user/default?kind=photo&max-results=10"), byte[].class);
InputStream photosXML = new ByteArrayInputStream(bytes);
final List<String> photoUrls = new ArrayList<String>();
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(false);
parserFactory.setXIncludeAware(false);
parserFactory.setNamespaceAware(true);
try {
SAXParser parser = parserFactory.newSAXParser();
parser.parse(photosXML, new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if ("http://search.yahoo.com/mrss/".equals(uri) && "thumbnail".equalsIgnoreCase(localName)) {
int width = 0;
try {
width = Integer.parseInt(attributes.getValue("width"));
if (width > 100 && width < 200) {
//just do the thumbnails that are between 100 and 200 px...
photoUrls.add(attributes.getValue("url"));
}
} catch (NumberFormatException e) {
//fall through...
}
}
}
});
return photoUrls;
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
} catch (SAXException e) {
throw new IllegalStateException(e);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
use of org.xml.sax.helpers.DefaultHandler in project syncany by syncany.
the class MultiCipherStreamsTest method testSaxParserWithMultiCipherTransformer.
public void testSaxParserWithMultiCipherTransformer(List<CipherSpec> cipherSuites) throws Exception {
String xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<database version=\"1\">\n" + " <databaseVersions>\n" + " <databaseVersion>\n" + " </databaseVersion>\n" + " </databaseVersions>\n" + " <databaseVersions>\n" + " <databaseVersion>\n" + " </databaseVersion>\n" + " </databaseVersions>\n" + " <databaseVersions>\n" + " <databaseVersion>\n" + " </databaseVersion>\n" + " </databaseVersions>\n" + " <databaseVersions>\n" + " <databaseVersion>\n" + " </databaseVersion>\n" + " </databaseVersions>\n" + "</database>";
Transformer cipherTransformer = new CipherTransformer(cipherSuites, masterKey);
// Test encrypt
byte[] encryptedData = doEncrypt(StringUtil.toBytesUTF8(xmlStr), cipherTransformer);
// Test decrypt with SAX parser
InputStream is = cipherTransformer.createInputStream(new ByteArrayInputStream(encryptedData));
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(is, new DefaultHandler());
// Success if it does not throw an exception
// Regular CipherInputStream does NOT work with GCM mode
// GcmCompatibleCipherInputStream fixes this!
// See http://bouncy-castle.1462172.n4.nabble.com/Using-AES-GCM-NoPadding-with-javax-crypto-CipherInputStream-td4655271.html
// and http://bouncy-castle.1462172.n4.nabble.com/using-GCMBlockCipher-with-CipherInputStream-td4655147.html
}
use of org.xml.sax.helpers.DefaultHandler in project FBReaderJ by geometer.
the class AndroidFontUtil method getFontAssetMap.
private static Map<String, String[]> getFontAssetMap() {
if (ourFontAssetMap == null) {
ourFontAssetMap = new HashMap<String, String[]>();
XmlUtil.parseQuietly(ZLFile.createFileByPath("fonts/fonts.xml"), new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if ("font".equals(localName)) {
ourFontAssetMap.put(attributes.getValue("family"), new String[] { "fonts/" + attributes.getValue("regular"), "fonts/" + attributes.getValue("bold"), "fonts/" + attributes.getValue("italic"), "fonts/" + attributes.getValue("boldItalic") });
}
}
});
}
return ourFontAssetMap;
}
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