Search in sources :

Example 11 with DefaultHandler

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Attributes(org.xml.sax.Attributes) IOException(java.io.IOException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 12 with DefaultHandler

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
}
Also used : CipherTransformer(org.syncany.chunk.CipherTransformer) Transformer(org.syncany.chunk.Transformer) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CipherTransformer(org.syncany.chunk.CipherTransformer) SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory) DefaultHandler(org.xml.sax.helpers.DefaultHandler)

Example 13 with DefaultHandler

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;
}
Also used : Attributes(org.xml.sax.Attributes) DefaultHandler(org.xml.sax.helpers.DefaultHandler)

Example 14 with DefaultHandler

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");
}
Also used : DefaultHandler(org.xml.sax.helpers.DefaultHandler)

Example 15 with DefaultHandler

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Test(org.testng.annotations.Test)

Aggregations

DefaultHandler (org.xml.sax.helpers.DefaultHandler)139 InputStream (java.io.InputStream)61 Metadata (org.apache.tika.metadata.Metadata)59 ParseContext (org.apache.tika.parser.ParseContext)52 Test (org.junit.Test)43 Attributes (org.xml.sax.Attributes)39 SAXParser (javax.xml.parsers.SAXParser)35 SAXException (org.xml.sax.SAXException)34 ByteArrayInputStream (java.io.ByteArrayInputStream)30 SAXParserFactory (javax.xml.parsers.SAXParserFactory)25 IOException (java.io.IOException)24 Parser (org.apache.tika.parser.Parser)22 InputSource (org.xml.sax.InputSource)21 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)20 TikaInputStream (org.apache.tika.io.TikaInputStream)20 ContentHandler (org.xml.sax.ContentHandler)20 File (java.io.File)17 AutoDetectParser (org.apache.tika.parser.AutoDetectParser)17 BodyContentHandler (org.apache.tika.sax.BodyContentHandler)16 FileInputStream (java.io.FileInputStream)14