/* Yougi is a web application conceived to manage user groups or 
 * communities focused on a certain domain of knowledge, whose members are 
 * constantly sharing information and participating in social and educational 
 * events. Copyright (C) 2011 Hildeberto Mendonça.
 * 
 * This application is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by the 
 * Free Software Foundation; either version 2.1 of the License, or (at your 
 * option) any later version.
 * 
 * This application is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 * 
 * There is a full copy of the GNU Lesser General Public License along with 
 * this library. Look for the file license.txt at the root level. If you do not
 * find it, write to the Free Software Foundation, Inc., 59 Temple Place, 
 * Suite 330, Boston, MA 02111-1307 USA.
 * */
package org.cejug.yougi.util;

import de.bripkens.gravatar.Gravatar;
import de.bripkens.gravatar.Rating;
import java.io.UnsupportedEncodingException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 * @author Hildeberto Mendonça
 */
@ManagedBean
@RequestScoped
public class ProfilePictureFinder {

    public String getPictureFromEmail(String email) throws UnsupportedEncodingException {
        return new Gravatar()
                .setSize(85)
                .setHttps(true)
                .setRating(Rating.PARENTAL_GUIDANCE_SUGGESTED)
                .setCustomDefaultImage(this.getDefaultAvatar())
                .getUrl(email);
    }
    
    private String getDefaultAvatar() {
        return "http://cejug.org/ug/images/logo.png";
    }
}

@@ -1114,16 +1114,58 @@
 .util;%0A%0A
+import de.bripkens.gravatar.DefaultImage;%0A
 import d
@@ -1249,36 +1249,114 @@
 .io.
-UnsupportedEncodingException
+IOException;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.MalformedURLException;%0Aimport java.net.URL
 ;%0Aim
@@ -1597,27 +1597,33 @@
 ows 
-UnsupportedEncoding
+MalformedURLException, IO
 Exce
@@ -1645,16 +1645,33 @@
  return 
+this.validateUrl(
 new Grav
@@ -1825,27 +1825,235 @@
 .set
-CustomDefaultImage(
+StandardDefaultImage(DefaultImage.HTTP_404)%0A                .getUrl(email));%0A    %7D%0A%0A    private String validateUrl(String gravataUrl) throws MalformedURLException, IOException %7B%0A        return isNotFound(new URL(gravataUrl)) ? 
 this
@@ -2075,52 +2075,293 @@
 ar()
-)
+ : gravataUrl;
 %0A    
+%7D%0A
     
+%0A
     
-    .getUrl(email);%0A    %7D
+private boolean isNotFound(URL url) throws IOException %7B%0A        HttpURLConnection connection = (HttpURLConnection) url.openConnection();%0A        connection.connect();%0A        return connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND;
 %0A    
+%7D%0A
 %0A   
@@ -2417,27 +2417,8 @@
 rn %22
-http://cejug.org/ug
 /ima

Check if HTTP Status the request of the gravatar is 404