Commits

Juan Carlos Picado Herrera committed c808061

Comments (0)

Files changed (20)

encuestame-business/src/main/java/org/encuestame/business/service/AbstractBaseService.java

 import org.encuestame.business.service.imp.MailServiceOperations;
 import org.encuestame.business.setup.DirectorySetupOperations;
 import org.encuestame.core.util.ConvertDomainBean;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.persistence.domain.Email;
 import org.encuestame.persistence.domain.EmailList;
 import org.encuestame.persistence.domain.EmailSubscribe;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.utils.DateUtil;
+import org.encuestame.utils.MD5Utils;
 import org.encuestame.utils.RelativeTimeEnum;
 import org.encuestame.utils.web.TweetPollBean;
 import org.encuestame.utils.web.UnitEmails;

encuestame-business/src/main/java/org/encuestame/business/service/AbstractSurveyService.java

 import org.encuestame.core.social.LinkedInAPIOperations;
 import org.encuestame.core.util.ConvertDomainBean;
 import org.encuestame.core.util.InternetUtils;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.core.util.SocialUtils;
 import org.encuestame.persistence.dao.IHashTagDao;
 import org.encuestame.persistence.dao.ITweetPoll;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnmeFailOperation;
+import org.encuestame.utils.MD5Utils;
 import org.encuestame.utils.RestFullUtil;
 import org.encuestame.utils.ShortUrlProvider;
 import org.encuestame.utils.TweetPublishedMetadata;

encuestame-business/src/main/java/org/encuestame/business/service/PictureService.java

 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.encuestame.core.files.PathUtil;
 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.domain.security.UserAccount.PictureSource;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.PictureUtils;
+import org.encuestame.utils.exception.EnMeGenericException;
 import org.springframework.stereotype.Service;
 
+import com.sun.java.swing.plaf.gtk.GTKConstants.WidgetType;
+
 /**
  * Picture / Image Service.
  * @author Picado, Juan juanATencuestame.org
     }
 
     /**
-     * Get Profile Picture.
-     * @param id
-     * @param username
-     * @param pictureType
+     * Return a gravatar picture url.
+     * @param email
+     * @param size
+     * @return
+     * @throws EnMeGenericException
+     */
+    private byte[] getGravatarPicture(final String email, final PictureType size) throws EnMeGenericException {
+        log.debug("getGravatarPicture "+size);
+        log.debug("getGravatarPicture "+email);
+        return PictureUtils.downloadGravatar(email, size.toInt());
+    }
+
+    /**
+     *
+     * @param size
+     * @param account
      * @return
      * @throws IOException
-     * @throws EnMeNoResultsFoundException
      */
-    public byte[] getProfilePicture(
-            final String username,
-            final PictureType pictureType) throws IOException, EnMeNoResultsFoundException{
-        final StringBuilder url = new StringBuilder(getAccountUserPicturePath(username));
+    private byte[] getProfilePicture(final PictureType size, final UserAccount account) throws IOException{
+        final StringBuilder url = new StringBuilder(this.getPicturePath(account.getAccount()));
         url.append("/file");
-        url.append(pictureType.toString());
+        url.append(size.toInt().toString());
         url.append(".jpg");
         log.debug("getProfileURl "+url);
         final File file = new File(url.toString());
         is.close();
         log.debug("getProfileURl "+bytes);
         return bytes;
-
     }
 
     /**
-     * Return real path folder for user account.
+     * Get Profile Picture.
+     * @param id
+     * @param username
+     * @param pictureType
      * @return
-     * @throws EnMeNoResultsFoundException
+     * @throws IOException
+     * @throws EnMeGenericException
      */
-    public String getAccountUserPicturePath(final String username)
-           throws EnMeNoResultsFoundException{
+    public byte[] getProfilePicture(
+            final String username,
+            final PictureType pictureType) throws IOException, EnMeGenericException {
+        log.debug("getProfilePicture "+username);
+        log.debug("getProfilePicture "+pictureType.toString());
         final UserAccount user = getUserAccount(username);
-        log.debug("getAccountUserPicturePath "+user);
-        return this.getPicturePath(user.getAccount());
+        if (user.getPictureSource().equals(PictureSource.UPLOADED)) {
+            return this.getProfilePicture(pictureType, user);
+        } else if (user.getPictureSource().equals(PictureSource.GRAVATAR)) {
+            return this.getGravatarPicture(user.getUserEmail(), pictureType);
+        } else {
+            return this.getGravatarPicture(user.getUserEmail(), pictureType);
+        }
     }
 
+
+    /**
+     * Picture Type.
+     * @author Picado, Juan juanATencuestame.org
+     * @since Jul 3, 2011
+     */
     public enum PictureType {
         ICON,
         THUMBNAIL,
         DEFAULT,
+        PROFILE,
         PREVIEW,
         WEB;
 
             if (this == ICON) { pictureSize = "_22"; }
             else if (this == THUMBNAIL) { pictureSize = "_64"; }
             else if (this == DEFAULT) { pictureSize = "_128"; }
+            else if (this == PROFILE) { pictureSize = "_256"; }
             else if (this == PREVIEW) { pictureSize = "_375"; }
             else if (this == WEB) { pictureSize = "_900"; }
             return pictureSize;
         }
+
+        /**
+         * To integer.
+         * @return
+         */
+        public Integer toInt() {
+            Integer pictureSize = 64;
+            if (this == ICON) { pictureSize = 22; }
+            else if (this == THUMBNAIL) { pictureSize = 64; }
+            else if (this == DEFAULT) { pictureSize = 128; }
+            else if (this == PROFILE) { pictureSize = 256; }
+            else if (this == PREVIEW) { pictureSize = 375; }
+            else if (this == WEB) { pictureSize = 900; }
+            return pictureSize;
+        }
     }
 }

encuestame-business/src/main/java/org/encuestame/business/service/PollService.java

 import org.apache.commons.logging.LogFactory;
 import org.encuestame.business.service.imp.IPollService;
 import org.encuestame.core.util.ConvertDomainBean;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.persistence.dao.IFolder;
 import org.encuestame.persistence.domain.Email;
 import org.encuestame.persistence.domain.question.Question;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnMePollNotFoundException;
+import org.encuestame.utils.MD5Utils;
 import org.encuestame.utils.web.FolderBean;
 import org.encuestame.utils.web.QuestionBean;
 import org.encuestame.utils.web.UnitLists;

encuestame-business/src/main/java/org/encuestame/business/service/SurveyService.java

 import org.encuestame.business.service.imp.ISurveyService;
 import org.encuestame.business.service.social.api.TwitterAPITemplate;
 import org.encuestame.core.util.ConvertDomainBean;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.persistence.domain.question.Question;
 import org.encuestame.persistence.domain.question.QuestionAnswer;
 import org.encuestame.persistence.domain.question.QuestionPattern;
 import org.encuestame.persistence.domain.survey.Survey;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.utils.MD5Utils;
 import org.encuestame.utils.RestFullUtil;
 import org.encuestame.utils.web.QuestionAnswerBean;
 import org.encuestame.utils.web.FolderBean;

encuestame-business/src/main/java/org/encuestame/business/service/imp/IPictureService.java

 
 import org.encuestame.business.service.PictureService.PictureType;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.exception.EnMeGenericException;
 
 /**
  * Picture Service.
  */
 public interface IPictureService {
 
-
-    /**
-     * Return real path folder for user account.
-     * @return
-     * @throws EnMeNoResultsFoundException
-     */
-    String getAccountUserPicturePath(final String account)
-                                    throws EnMeNoResultsFoundException;
-
     /**
      * Get Profile Picture.
      * @param id
      * @throws FileNotFoundException
      * @throws IOException
      * @throws EnMeNoResultsFoundException
+     * @throws EnMeGenericException
      */
     byte[] getProfilePicture(
             final String username,
-            final PictureType pictureType) throws FileNotFoundException, IOException, EnMeNoResultsFoundException;
+            final PictureType pictureType) throws FileNotFoundException, IOException, EnMeNoResultsFoundException, EnMeGenericException;
 }

encuestame-core/src/main/java/org/encuestame/core/util/JSONUtils.java

 import org.codehaus.jackson.JsonFactory;
 import org.codehaus.jackson.JsonGenerator;
 import org.codehaus.jackson.map.ObjectMapper;
-import org.encuestame.core.social.BuzzProfile;
 
 /**
  * Helper to JSON.

encuestame-core/src/main/java/org/encuestame/core/util/MD5Utils.java

-/*
- ************************************************************************************
- * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2010
- * encuestame Development Team.
- * Licensed under the Apache Software License version 2.0
- * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to  in writing,  software  distributed
- * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
- * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
- * specific language governing permissions and limitations under the License.
- ************************************************************************************
- */
-
-package org.encuestame.core.util;
-
-import java.io.UnsupportedEncodingException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-/**
- * MD5 Utils.
- * @author Picado, Juan juan@encuestame.org
- * @since Mar 12, 2010 11:37:48 PM
- * @version $Id: $
- * Taked from shrtlnk project http://tinyurl.com/yfwocal
- */
-public class MD5Utils {
-
-    /**
-     * Convert md5 bytes into hex values
-     * @param data Byte data to be hex'ed
-     * @return Returns the hex representation of the md5sum
-     */
-    private static String convertToHex(byte[] data) {
-        final StringBuffer buf = new StringBuffer();
-        for (byte aData : data) {
-            int halfbyte = (aData >>> 4) & 0x0F;
-            int twoHalfs = 0;
-            do {
-                if ((0 <= halfbyte) && (halfbyte <= 9)) {
-                    buf.append((char) ('0' + halfbyte));
-                }
-                else {
-                    buf.append((char) ('a' + (halfbyte - 10)));
-                }
-                halfbyte = aData & 0x0F;
-            } while (twoHalfs++ < 1);
-        }
-        return buf.toString();
-    }
-
-    /**
-     * Creates an MD5 sum for a text string
-     * @param text The string you want to sum
-     * @return The md5sum
-     * @throws NoSuchAlgorithmException If md5 isn't available
-     * @throws UnsupportedEncodingException If the character encoding isn't available
-     */
-    public static String md5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException  {
-        MessageDigest md;
-        md = MessageDigest.getInstance("MD5");
-        byte[] md5hash;
-        md.update(text.getBytes("iso-8859-1"), 0, text.length());
-        md5hash = md.digest();
-        return convertToHex(md5hash);
-    }
-
-    /**
-     * Cut off the MD5sum, limit to 6 characters. Will still result in 16777216 possible combinations, 2^128 isn't needed
-     * @param text The sum you want shortened
-     * @return The shortened md5sum
-     */
-    public static String shortMD5(String text) {
-        try {
-            return md5(text).substring(0, 6);
-        } catch (NoSuchAlgorithmException e) {
-        } catch (UnsupportedEncodingException e) {
-        }
-        return "";
-    }
-
-    /**
-     * This will sort the URL parameter by parameter.
-     * @param url The URL we want to sort
-     * @return Returns the sorted URL
-     */
-    public static String sortURL(String url) {
-        String[] urlArgs = url.split("&");
-        java.util.Arrays.sort(urlArgs);
-        String ret = "";
-
-        for (String urlArg : urlArgs) {
-            ret = ret + urlArg;
-        }
-        return ret  ;
-    }
-
-    /**
-     * Hex.
-     * @param array
-     * @return
-     */
-    public static String hex(byte[] array) {
-        StringBuffer sb = new StringBuffer();
-        for (int i = 0; i < array.length; ++i) {
-        sb.append(Integer.toHexString((array[i]
-            & 0xFF) | 0x100).substring(1,3));
-        }
-        return sb.toString();
-    }
-
-    /**
-     * Md5 Hex.
-     * @param message
-     * @return
-     */
-    public static String md5Hex (String message) {
-        try {
-        MessageDigest md = MessageDigest.getInstance("MD5");
-        return hex (md.digest(message.getBytes("CP1252")));
-        }
-        catch (NoSuchAlgorithmException e) {
-        }
-        catch (UnsupportedEncodingException e) {
-        }
-        return null;
-    }
-}

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/FileUploadController.java

             String filePath = null;
             try {
                 log.debug("getting file path for this user");
-                filePath = getPictureService().getAccountUserPicturePath(getUserPrincipalUsername());
+                //filePath = getPictureService().getAccountUserPicturePath(getUserPrincipalUsername());
                 InputStream stream = multipartFile.getInputStream();
                 try {
                     //generate thumbnails
             } catch (IOException e) {
                 e.printStackTrace();
                 log.error("File uploaded failed:" + orgName);
-            } catch (EnMeNoResultsFoundException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
             }
             // Save the file here
             mav.addObject("status", "saved");

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/json/UrlShortAddressController.java

 import org.bouncycastle.jce.provider.JCEMac.MD5;
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.mvc.controller.AbstractJsonController;
+import org.encuestame.utils.MD5Utils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;

encuestame-mvc/src/main/java/org/encuestame/mvc/util/WidgetUtil.java

 import javax.servlet.http.HttpServletRequest;
 
 import org.encuestame.core.files.PathUtil;
-import org.encuestame.core.util.MD5Utils;
+import org.encuestame.utils.MD5Utils;
+import org.encuestame.utils.PictureUtils;
 import org.jfree.util.Log;
 
 /**
  */
 public class WidgetUtil {
 
-    private static final String GRAVATAR_URL = "http://www.gravatar.com/avatar/";
-
     private static final String URL = "http://";
 
     private static final Integer REQUEST_SERVER_PORT = 80;
      * @param email
      * @param size
      * @return
+     * @deprecated moved to {@link PictureUtils}
      */
+    @Deprecated
     public final String getGravatar(final String email, Integer size) {
         final String hash = MD5Utils.md5Hex(email);
         StringBuilder gravatarUl = new StringBuilder();
-        gravatarUl.append(WidgetUtil.GRAVATAR_URL);
+        gravatarUl.append(PictureUtils.GRAVATAR_URL);
         gravatarUl.append(hash);
         gravatarUl.append("?s=");
         gravatarUl.append(size);

encuestame-mvc/src/main/java/org/encuestame/mvc/view/PictureProfileFactoryController.java

 import java.io.FileNotFoundException;
 import java.io.IOException;
 
+import org.apache.log4j.Logger;
 import org.encuestame.business.service.PictureService.PictureType;
 import org.encuestame.mvc.controller.AbstractBaseOperations;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.exception.EnMeGenericException;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 public class PictureProfileFactoryController extends AbstractBaseOperations {
 
     /**
-     * Returns the byte[] that contains the requested thumbnail image (128x128 constrained).
-     * @param id The identifier of the image
-     * @return A byte[] that contains the requested image
-     * @throws EnMeNoResultsFoundException
+     * Log.
      */
-    @RequestMapping( value = "/picture/profile/{username}/thumbnail", method = RequestMethod.GET )
-    @ResponseBody
-    public byte[] getPictureThumbnail(
-            @PathVariable String username) throws EnMeNoResultsFoundException{
+    private Logger log = Logger.getLogger(this.getClass());
+
+
+    /**
+     *
+     * @param username
+     * @param pictureType
+     * @return
+     */
+    private byte[] getPicture(String username, final PictureType pictureType){
         byte[] bytes = {};
         username = filterValue(username);
         try {
-            bytes = getPictureService().getProfilePicture(username, PictureType.THUMBNAIL);
+            bytes = getPictureService().getProfilePicture(username, pictureType);
         } catch (FileNotFoundException e) {
-            // if the user doesn't have picture.
-
+            log.error("file not found "+e);
         } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            log.error("IOException "+e);
+        } catch (EnMeGenericException e) {
+            log.error("EnMeGenericException "+e);
         }
         return bytes;
     }
 
     /**
-     * Returns the byte[] that contains the requested master image.
-     * @param id The identifier of the image
+     * Returns the byte[] that contains the requested thumbnail image (128x128 constrained).
+     * @return A byte[] that contains the requested image
+     * @throws EnMeNoResultsFoundException
+     */
+    @RequestMapping( value = "/picture/profile/{username}/thumbnail", method = RequestMethod.GET )
+    @ResponseBody
+    public byte[] getPictureThumbnail(
+            @PathVariable String username){
+        return this.getPicture(username, PictureType.THUMBNAIL);
+    }
+
+    /**
+     * Returns the byte[] that contains the requested default image.
      * @return A byte[] that contains the requested image
      * @throws EnMeNoResultsFoundException
      */
     @RequestMapping( value = "/picture/profile/{username}/default", method = RequestMethod.GET )
     @ResponseBody
     public byte[] getPictureMaster(
-            @PathVariable String username ) throws EnMeNoResultsFoundException{
-        byte[] bytes = {};
-        try {
-            bytes = getPictureService().getProfilePicture(username, PictureType.DEFAULT);
-        } catch (FileNotFoundException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        return bytes;
+            @PathVariable String username ) {
+        return this.getPicture(username, PictureType.DEFAULT);
     }
 
     /**
-     * Returns the byte[] that contains the requested preview image (800x800 constrained)
-     * @param id The identifier of the image
+     * Returns the byte[] that contains the requested preview image (256x256 constrained)
+     * @param username
+     * @return
+     */
+    @RequestMapping( value = "/picture/profile/{username}/profile", method = RequestMethod.GET )
+    @ResponseBody
+    public byte[] getPictureProfile(
+            @PathVariable String username ) {
+        return this.getPicture(username, PictureType.PROFILE);
+    }
+
+    /**
+     * Returns the byte[] that contains the requested preview image (375x375 constrained)
      * @return A byte[] that contains the requested image
      * @throws EnMeNoResultsFoundException
      */
     @RequestMapping( value = "/picture/profile/{username}/preview", method = RequestMethod.GET)
     @ResponseBody
     public byte[] getPicturePreview(
-            @PathVariable String username ) throws EnMeNoResultsFoundException{
-        byte[] bytes = {};
-        try {
-            bytes = getPictureService().getProfilePicture(username,  PictureType.PREVIEW);
-        } catch (FileNotFoundException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        return bytes;
+            @PathVariable String username ){
+          return this.getPicture(username, PictureType.PREVIEW);
+    }
+
+    /**
+     * Returns the byte[] that contains the requested preview image (900x900 constrained)
+     * @param id The identifier of the image
+     * @return A byte[] that contains the requested image
+     * @throws EnMeNoResultsFoundException
+     */
+    @RequestMapping( value = "/picture/profile/{username}/web", method = RequestMethod.GET)
+    @ResponseBody
+    public byte[] getPictureWeb(
+            @PathVariable String username ){
+          return this.getPicture(username, PictureType.WEB);
     }
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/domain/security/UserAccount.java

 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
      */
     private boolean credentialsNonExpired = true;
 
+    /**
+     *
+     */
     private Set<Project> projects = new HashSet<Project>();
 
+    /**
+     *
+     */
     private Set<Permission> secUserPermissions = new HashSet<Permission>();
 
+
+    /**
+     *  Type of Picture.
+     */
+    private PictureSource pictureSource = PictureSource.GRAVATAR;
+
     /**
      * {@link Group}
      */
         this.sharedProfile = sharedProfile;
     }
 
+
+    /**
+     * @return the pictureSource
+     */
+    @Column(name="picture_source")
+    @Enumerated(EnumType.ORDINAL)
+    public PictureSource getPictureSource() {
+        return this.pictureSource == null ? PictureSource.GRAVATAR : this.pictureSource;
+    }
+
+    /**
+     * @param pictureSource the pictureSource to set
+     */
+    public void setPictureSource(final PictureSource pictureSource) {
+        this.pictureSource = pictureSource;
+    }
+
     /* (non-Javadoc)
      * @see java.lang.Object#toString()
      */
                 + ", userProfilePicture=" + userProfilePicture + ", enabled="
                 + enabled + "]";
     }
+
+    /**
+     * Type of picture.
+     * @author Picado, Juan juanATencuestame.org
+     * @since Jul 3, 2011
+     */
+    public enum PictureSource {
+        GRAVATAR,
+        UPLOADED;
+
+        private PictureSource() {
+        }
+
+        /**
+         * To String.
+         */
+        public String toString() {
+            String pictureSize = "_64";
+            if (this == UPLOADED) { pictureSize = "UPLOADED"; }
+            else if (this == GRAVATAR) { pictureSize = "GRAVATAR"; }
+            return pictureSize;
+        }
+    }
  }

encuestame-persistence/src/main/java/org/encuestame/persistence/exception/EnMeExpcetion.java

 /*
  ************************************************************************************
- * Copyright (C) 2001-2009 encuestame: system online surveys Copyright (C) 2009
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
  * encuestame Development Team.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  ************************************************************************************
  */
 package org.encuestame.persistence.exception;
+
+import org.encuestame.utils.exception.EnMeGenericException;
  /**
  * Encuestame Exception.
  * @author Picado, Juan juan@encuestame.org
  * @since May 07, 2009
- * @version $Id$
  */
-public class EnMeExpcetion extends Exception{
+public class EnMeExpcetion extends EnMeGenericException {
 
     /** serial. */
     private static final long serialVersionUID = 7631058192250904935L;

encuestame-utils/pom.xml

                 </configuration>
             </plugin>
             <plugin>
-               <groupId>org.apache.maven.plugins</groupId>
-               <artifactId>maven-jar-plugin</artifactId>
-               <executions>
-                 <execution>
-                   <goals>
-                       <goal>test-jar</goal>
-                    </goals>
-                  </execution>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
                 </executions>
             </plugin>
         </plugins>
         <resources>
             <resource>
-              <directory>src/main/resources/</directory>
-              <includes>
-                <include>*.*</include>
-              </includes>
-              <filtering>true</filtering>
+                <directory>src/main/resources/</directory>
+                <includes>
+                    <include>*.*</include>
+                </includes>
+                <filtering>true</filtering>
             </resource>
         </resources>
     </build>
             <artifactId>jsr250-api</artifactId>
         </dependency>
         <dependency>
-             <groupId>joda-time</groupId>
-             <artifactId>joda-time</artifactId>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-mapper-asl</artifactId>
         </dependency>
         <dependency>
-           <groupId>org.codehaus.jackson</groupId>
-           <artifactId>jackson-mapper-asl</artifactId>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
         </dependency>
     </dependencies>
 </project>

encuestame-utils/src/main/java/org/encuestame/utils/MD5Utils.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2010
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+
+package org.encuestame.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * MD5 Utils.
+ * @author Picado, Juan juan@encuestame.org
+ * @since Mar 12, 2010 11:37:48 PM
+ * @version $Id: $
+ * Taked from shrtlnk project http://tinyurl.com/yfwocal
+ */
+public class MD5Utils {
+
+    /**
+     * Convert md5 bytes into hex values
+     * @param data Byte data to be hex'ed
+     * @return Returns the hex representation of the md5sum
+     */
+    private static String convertToHex(byte[] data) {
+        final StringBuffer buf = new StringBuffer();
+        for (byte aData : data) {
+            int halfbyte = (aData >>> 4) & 0x0F;
+            int twoHalfs = 0;
+            do {
+                if ((0 <= halfbyte) && (halfbyte <= 9)) {
+                    buf.append((char) ('0' + halfbyte));
+                }
+                else {
+                    buf.append((char) ('a' + (halfbyte - 10)));
+                }
+                halfbyte = aData & 0x0F;
+            } while (twoHalfs++ < 1);
+        }
+        return buf.toString();
+    }
+
+    /**
+     * Creates an MD5 sum for a text string
+     * @param text The string you want to sum
+     * @return The md5sum
+     * @throws NoSuchAlgorithmException If md5 isn't available
+     * @throws UnsupportedEncodingException If the character encoding isn't available
+     */
+    public static String md5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException  {
+        MessageDigest md;
+        md = MessageDigest.getInstance("MD5");
+        byte[] md5hash;
+        md.update(text.getBytes("iso-8859-1"), 0, text.length());
+        md5hash = md.digest();
+        return convertToHex(md5hash);
+    }
+
+    /**
+     * Cut off the MD5sum, limit to 6 characters. Will still result in 16777216 possible combinations, 2^128 isn't needed
+     * @param text The sum you want shortened
+     * @return The shortened md5sum
+     */
+    public static String shortMD5(String text) {
+        try {
+            return md5(text).substring(0, 6);
+        } catch (NoSuchAlgorithmException e) {
+        } catch (UnsupportedEncodingException e) {
+        }
+        return "";
+    }
+
+    /**
+     * This will sort the URL parameter by parameter.
+     * @param url The URL we want to sort
+     * @return Returns the sorted URL
+     */
+    public static String sortURL(String url) {
+        String[] urlArgs = url.split("&");
+        java.util.Arrays.sort(urlArgs);
+        String ret = "";
+
+        for (String urlArg : urlArgs) {
+            ret = ret + urlArg;
+        }
+        return ret  ;
+    }
+
+    /**
+     * Hex.
+     * @param array
+     * @return
+     */
+    public static String hex(byte[] array) {
+        StringBuffer sb = new StringBuffer();
+        for (int i = 0; i < array.length; ++i) {
+        sb.append(Integer.toHexString((array[i]
+            & 0xFF) | 0x100).substring(1,3));
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Md5 Hex.
+     * @param message
+     * @return
+     */
+    public static String md5Hex (String message) {
+        try {
+        MessageDigest md = MessageDigest.getInstance("MD5");
+        return hex (md.digest(message.getBytes("CP1252")));
+        }
+        catch (NoSuchAlgorithmException e) {
+        }
+        catch (UnsupportedEncodingException e) {
+        }
+        return null;
+    }
+}

encuestame-utils/src/main/java/org/encuestame/utils/PictureUtils.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2011
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.utils;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.Validate;
+import org.encuestame.utils.exception.EnMeGenericException;
+
+/**
+ * Picture Utils.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Jul 3, 2011
+ */
+public class PictureUtils {
+
+    /**
+     * Gravatar Url.
+     */
+    public static final String GRAVATAR_URL = "http://www.gravatar.com/avatar/";
+
+
+    /**
+     * Get Gravatar.
+     *
+     * @param email
+     * @param size
+     * @return
+     */
+    public static final String getGravatar(final String email, Integer size) {
+        return getUrl(email, size);
+    }
+
+    /**
+     * Get Gravatar URL
+     * @param email
+     * @return
+     */
+    public static String getUrl(final String email, int size) {
+        Validate.notNull(email, "email");
+        final String hash = MD5Utils.md5Hex(email);
+        String params = formatUrlParameters(size);
+        final StringBuffer str = new StringBuffer(PictureUtils.GRAVATAR_URL);
+        str.append(hash);
+        str.append(params);
+        return str.toString();
+    }
+
+    /**
+     * Build gravatar params.
+     * @return
+     */
+    private static String formatUrlParameters(final int size) {
+        final List<String> params = new ArrayList<String>();
+            params.add("s=" + size);
+            params.add("r=" +  Rating.GENERAL_AUDIENCES.getCode());
+        if (params.isEmpty()) {
+            return "";
+        } else {
+            return "?" + StringUtils.join(params.iterator(), "&");
+        }
+    }
+
+    /**
+     * Download the generated gravatar image.
+     * @param email
+     * @return
+     * @throws EnMeGenericException
+     */
+    public static byte[] downloadGravatar(final String email, int size) throws EnMeGenericException {
+        InputStream stream = null;
+        try {
+            URL url = new URL(getUrl(email, size));
+            stream = url.openStream();
+            return IOUtils.toByteArray(stream);
+        } catch (FileNotFoundException e) {
+            return null;
+        } catch (Exception e) {
+            throw new EnMeGenericException(e);
+        } finally {
+            IOUtils.closeQuietly(stream);
+        }
+    }
+
+    /**
+     * Gravatar Rating.
+     * @author Picado, Juan juanATencuestame.org
+     * @since Jul 3, 2011
+     */
+    private enum Rating {
+        GENERAL_AUDIENCES("g"),
+        PARENTAL_GUIDANCE_SUGGESTED("pg"),
+        RESTRICTED("r"),
+        XPLICIT("x");
+        private String code;
+
+        private Rating(String code) {
+            this.code = code;
+        }
+
+        public String getCode() {
+            return code;
+        }
+    }
+}

encuestame-utils/src/main/java/org/encuestame/utils/exception/EnMeGenericException.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2011
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.utils.exception;
+
+/**
+ * EnMe generic exception.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Jul 3, 2011
+ */
+public class EnMeGenericException extends Exception {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 4773692936156441054L;
+
+    /**
+     * Constructor.
+     */
+    public EnMeGenericException() {
+        super();
+    }
+
+    /**
+    * Exception.
+    * @param message message
+    * @param cause cause
+    */
+   public EnMeGenericException(final String message, final Throwable cause) {
+       super(message, cause);
+
+   }
+   /**
+    * Exception.
+    * @param message message
+    */
+   public EnMeGenericException(final String message) {
+       super(message);
+
+   }
+
+   /**
+    * Exception.
+    * @param cause cause
+    */
+   public EnMeGenericException(final Throwable cause) {
+       super(cause);
+   }
+}

encuestame-war/src/main/webapp/WEB-INF/views/home/web/profile.jsp

 <%@ include file="/WEB-INF/jsp/includes/taglibs.jsp"%>
 <div class="profile">
 <h2>${profile.username}</h2>
-
-
-<div>
-    <ul>
-    <li>
-        rss : <a href="<%=request.getContextPath()%>/feed/${profile.username}/tweetpoll.rss">TweetPoll RSS for ${profile.username}</a>
-   </li>
-   <li>
-        atom : <a href="<%=request.getContextPath()%>/feed/${profile.username}/tweetpoll.atom">TweetPoll ATOM for ${profile.username}</a>
-    </li>
-    </ul>
-
+    <div class="profileWrapper">
+        <div class="picture">
+            <a href="<%=request.getContextPath()%>/picture/profile/${profile.username}/preview">
+                <img alt="${profile.username}" src="<%=request.getContextPath()%>/picture/profile/${profile.username}/profile">
+            </a>
+        </div>
+        <ul>
+            <li>
+                rss : <a href="<%=request.getContextPath()%>/feed/${profile.username}/tweetpoll.rss">TweetPoll RSS for ${profile.username}</a>
+            </li>
+            <li>
+                atom : <a href="<%=request.getContextPath()%>/feed/${profile.username}/tweetpoll.atom">TweetPoll ATOM for ${profile.username}</a>
+            </li>
+        </ul>
 </div>
 
 </div>
                 <artifactId>commons-codec</artifactId>
                 <version>1.3</version>
             </dependency>
+	    <dependency>
+                <groupId>commons-io</groupId>
+	        <artifactId>commons-io</artifactId>
+                <version>2.0.1</version>
+	    </dependency>
             <dependency>
                 <groupId>commons-collections</groupId>
                 <artifactId>commons-collections</artifactId>