Package com.googlecode.memwords.facade.cards

Source Code of com.googlecode.memwords.facade.cards.FavIconFinderImpl

package com.googlecode.memwords.facade.cards;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.google.inject.Singleton;
import com.googlecode.memwords.facade.cards.parser.FavIconSaxParser;

/**
* Implementation of {@link FavIconFinder}
* @author JB
*/
@Singleton
public class FavIconFinderImpl implements FavIconFinder {

    @Override
    public String findFavIcon(InputSource source, URL baseUrl) throws FavIconException {
        FavIconSaxParser parser = new FavIconSaxParser();
        try {
            // workaround for Java bug #4666701
            if ("".equals(baseUrl.getFile()))  {
                baseUrl = new URL(baseUrl.toString() + "/");
            }
            URI uri = baseUrl.toURI();
            String potentiallyRelativeUrl = parser.findFavIcon(source);
            if (potentiallyRelativeUrl == null) {
                return null;
            }
            return uri.resolve(potentiallyRelativeUrl).toString();
        }
        catch (URISyntaxException e) {
            throw new FavIconException(e);
        }
        catch (SAXException e) {
            throw new FavIconException(e);
        }
        catch (IOException e) {
            throw new FavIconException(e);
        }
    }
}
TOP

Related Classes of com.googlecode.memwords.facade.cards.FavIconFinderImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.