org.eclipse.mylyn.commons.identity.core_0.9.1.v20120425-0100

16:46:22.935 INFO  jd.cli.Main - Decompiling org.eclipse.mylyn.commons.identity.core_0.9.1.v20120425-0100.jar
package org.eclipse.mylyn.commons.identity.core.spi;

import java.io.Serializable;
import org.eclipse.mylyn.commons.identity.core.IIdentity;
import org.eclipse.mylyn.commons.identity.core.IProfile;

public final class Profile
  implements IProfile, Serializable
{
  private static final long serialVersionUID = -1079729573911113939L;
  private String city;
  private String country;
  private String email;
  private final IIdentity identity;
  private String name;
  private int timeZoneOffset;
  
  public Profile(IIdentity identity)
  {
    this.identity = identity;
  }
  
  public String getCity()
  {
    return city;
  }
  
  public String getCountry()
  {
    return country;
  }
  
  public String getEmail()
  {
    return email;
  }
  
  public IIdentity getIdentity()
  {
    return identity;
  }
  
  public String getName()
  {
    return name;
  }
  
  public int getTimeZoneOffset()
  {
    return timeZoneOffset;
  }
  
  public void setCity(String city)
  {
    this.city = city;
  }
  
  public void setCountry(String country)
  {
    this.country = country;
  }
  
  public void setEmail(String email)
  {
    this.email = email;
  }
  
  public void setName(String name)
  {
    this.name = name;
  }
  
  public void setTimeZoneOffset(int timeZoneOffset)
  {
    this.timeZoneOffset = timeZoneOffset;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.identity.core.spi.Profile
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.identity.core.spi;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.commons.identity.core.IIdentity;

public abstract class IdentityConnector
{
  public abstract ProfileImage getImage(IIdentity paramIIdentity, int paramInt1, int paramInt2, IProgressMonitor paramIProgressMonitor)
    throws CoreException;
  
  public abstract boolean supportsImageSize(int paramInt1, int paramInt2);
  
  public abstract void updateProfile(Profile paramProfile, IProgressMonitor paramIProgressMonitor)
    throws CoreException;
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.identity.core.spi.IdentityConnector
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.identity.core.spi;

import java.io.Serializable;
import org.eclipse.mylyn.commons.identity.core.IProfileImage;

public final class ProfileImage
  implements IProfileImage, Serializable
{
  private static final long serialVersionUID = 8211724823497362719L;
  byte[] data;
  int width;
  int height;
  String format;
  long timestamp;
  
  public ProfileImage(byte[] data, int width, int height, String format)
  {
    this.data = data;
    this.width = width;
    this.height = height;
    this.format = format;
    timestamp = System.currentTimeMillis();
  }
  
  public byte[] getData()
  {
    return data;
  }
  
  public int getWidth()
  {
    return width;
  }
  
  public int getHeight()
  {
    return height;
  }
  
  public String getFormat()
  {
    return format;
  }
  
  public long getTimestamp()
  {
    return timestamp;
  }
  
  public void setTimestamp(long timestamp)
  {
    this.timestamp = timestamp;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.identity.core.spi.ProfileImage
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.identity.core.spi;

import org.eclipse.mylyn.commons.identity.core.IIdentityService;

public abstract class AbstractIdentityService
  implements IIdentityService
{}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.identity.core.spi.AbstractIdentityService
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.identity.core;

import java.io.Serializable;
import org.eclipse.core.runtime.Assert;

public class Account
  implements Serializable
{
  private static final long serialVersionUID = 3670630150657553390L;
  private final String id;
  private String kind;
  private String name;
  private String url;
  
  public static Account id(String id)
  {
    Assert.isNotNull(id);
    return new Account(id);
  }
  
  private Account(String id)
  {
    this.id = id;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    Account other = (Account)obj;
    if (id == null)
    {
      if (id != null) {
        return false;
      }
    }
    else if (!id.equals(id)) {
      return false;
    }
    if (kind == null)
    {
      if (kind != null) {
        return false;
      }
    }
    else if (!kind.equals(kind)) {
      return false;
    }
    if (name == null)
    {
      if (name != null) {
        return false;
      }
    }
    else if (!name.equals(name)) {
      return false;
    }
    if (url == null)
    {
      if (url != null) {
        return false;
      }
    }
    else if (!url.equals(url)) {
      return false;
    }
    return true;
  }
  
  public String getId()
  {
    return id;
  }
  
  public String getKind()
  {
    return kind;
  }
  
  public String getName()
  {
    return name;
  }
  
  public String getUrl()
  {
    return url;
  }
  
  public int hashCode()
  {
    int result = 1;
    result = 31 * result + (id == null ? 0 : id.hashCode());
    result = 31 * result + (kind == null ? 0 : kind.hashCode());
    result = 31 * result + (name == null ? 0 : name.hashCode());
    result = 31 * result + (url == null ? 0 : url.hashCode());
    return result;
  }
  
  public Account kind(String kind)
  {
    this.kind = kind;
    return this;
  }
  
  public Account name(String name)
  {
    this.name = name;
    return this;
  }
  
  public Account url(String url)
  {
    this.url = url;
    return this;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.identity.core.Account
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.identity.core;

public abstract interface IProfileImage
{
  public abstract byte[] getData();
  
  public abstract int getWidth();
  
  public abstract int getHeight();
  
  public abstract String getFormat();
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.identity.core.IProfileImage
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.identity.core;

public abstract interface IProfile
{
  public abstract String getCity();
  
  public abstract String getCountry();
  
  public abstract String getEmail();
  
  public abstract IIdentity getIdentity();
  
  public abstract String getName();
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.identity.core.IProfile
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.identity.core;

import java.beans.PropertyChangeListener;
import java.util.UUID;
import java.util.concurrent.Future;

public abstract interface IIdentity
{
  public abstract void addAccount(Account paramAccount);
  
  public abstract void addPropertyChangeListener(PropertyChangeListener paramPropertyChangeListener);
  
  public abstract Account getAccountById(String paramString);
  
  public abstract Account getAccountByKind(String paramString);
  
  public abstract Account[] getAccounts();
  
  public abstract String[] getAliases();
  
  public abstract UUID getId();
  
  public abstract void removeAccount(Account paramAccount);
  
  public abstract void removePropertyChangeListener(PropertyChangeListener paramPropertyChangeListener);
  
  public abstract Future<IProfileImage> requestImage(int paramInt1, int paramInt2);
  
  public abstract Future<IProfile> requestProfile();
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.identity.core.IIdentity
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.identity.core;

public abstract interface IIdentityService
{
  public abstract IIdentity getIdentity(Account paramAccount);
  
  public abstract IIdentity[] getIdentities();
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.identity.core.IIdentityService
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.mylyn.commons.identity.core.IProfile;
import org.eclipse.mylyn.commons.identity.core.spi.Profile;

class Identity$2
  extends Identity.FutureJob<IProfile>
{
  Identity$2(Identity paramIdentity, String $anonymous0)
  {
    super($anonymous0);
  }
  
  protected IStatus run(IProgressMonitor monitor)
  {
    try
    {
      Profile profile = new Profile(this$0);
      Identity.access$0(this$0).updateProfile(profile, monitor);
      this$0.setProfile(profile);
      return success(profile);
    }
    catch (Throwable t)
    {
      IStatus localIStatus;
      return error(t);
    }
    finally
    {
      done();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.Identity.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.mylyn.commons.identity.core.Account;
import org.eclipse.mylyn.commons.identity.core.IIdentity;
import org.eclipse.mylyn.commons.identity.core.IProfile;
import org.eclipse.mylyn.commons.identity.core.IProfileImage;
import org.eclipse.mylyn.commons.identity.core.spi.Profile;
import org.eclipse.mylyn.commons.identity.core.spi.ProfileImage;

public class Identity
  implements IIdentity
{
  private final Set<Account> accounts;
  private final UUID id;
  private List<ProfileImage> images;
  private final List<PropertyChangeListener> listeners;
  private final IdentityModel model;
  private Profile profile;
  private boolean refreshProfile;
  
  private static abstract class FutureJob<T>
    extends Job
    implements Future<T>
  {
    private boolean cancelled;
    private final AtomicReference<Throwable> futureException = new AtomicReference();
    private final AtomicReference<T> futureResult = new AtomicReference();
    private final CountDownLatch resultLatch = new CountDownLatch(1);
    
    public FutureJob(String name)
    {
      super();
    }
    
    public boolean cancel(boolean mayInterruptIfRunning)
    {
      cancelled = true;
      return cancel();
    }
    
    public T get()
      throws InterruptedException, ExecutionException
    {
      resultLatch.await();
      return (T)getFutureResult();
    }
    
    public T get(long timeout, TimeUnit unit)
      throws InterruptedException, ExecutionException, TimeoutException
    {
      if (!resultLatch.await(timeout, unit)) {
        throw new TimeoutException();
      }
      return (T)getFutureResult();
    }
    
    public boolean isCancelled()
    {
      return cancelled;
    }
    
    public boolean isDone()
    {
      return getResult() != null;
    }
    
    private T getFutureResult()
      throws ExecutionException
    {
      Throwable t = (Throwable)futureException.get();
      if (t != null) {
        throw new ExecutionException(t);
      }
      return (T)futureResult.get();
    }
    
    protected void done()
    {
      if (resultLatch.getCount() > 0L) {
        error(new RuntimeException());
      }
      resultLatch.countDown();
    }
    
    protected IStatus error(Throwable t)
    {
      futureException.set(t);
      resultLatch.countDown();
      if ((t instanceof OperationCanceledException)) {
        return Status.CANCEL_STATUS;
      }
      return Status.OK_STATUS;
    }
    
    protected IStatus success(T result)
    {
      futureResult.set(result);
      resultLatch.countDown();
      return Status.OK_STATUS;
    }
  }
  
  private static final class FutureResult<T>
    implements Future<T>
  {
    private final T result;
    
    private FutureResult(T result)
    {
      this.result = result;
    }
    
    public boolean cancel(boolean mayInterruptIfRunning)
    {
      return true;
    }
    
    public T get()
      throws InterruptedException, ExecutionException
    {
      return (T)result;
    }
    
    public T get(long timeout, TimeUnit unit)
      throws InterruptedException, ExecutionException, TimeoutException
    {
      return (T)result;
    }
    
    public boolean isCancelled()
    {
      return false;
    }
    
    public boolean isDone()
    {
      return true;
    }
  }
  
  public Identity(IdentityModel model)
  {
    this.model = model;
    id = UUID.randomUUID();
    accounts = new CopyOnWriteArraySet();
    listeners = new CopyOnWriteArrayList();
  }
  
  public void addAccount(Account account)
  {
    accounts.add(account);
    refreshProfile = true;
  }
  
  public void addPropertyChangeListener(PropertyChangeListener listener)
  {
    listeners.add(listener);
  }
  
  public Account[] getAccounts()
  {
    return (Account[])accounts.toArray(new Account[accounts.size()]);
  }
  
  public Account getAccountById(String id)
  {
    if (id == null) {
      return null;
    }
    for (Account account : accounts) {
      if (id.equals(account.getId())) {
        return account;
      }
    }
    return null;
  }
  
  public Account getAccountByKind(String kind)
  {
    if (kind == null) {
      return null;
    }
    for (Account account : accounts) {
      if (kind.equals(account.getKind())) {
        return account;
      }
    }
    return null;
  }
  
  public String[] getAliases()
  {
    Set<String> aliases = new HashSet(accounts.size());
    for (Account account : accounts) {
      aliases.add(account.getId());
    }
    return (String[])aliases.toArray(new String[aliases.size()]);
  }
  
  public UUID getId()
  {
    return id;
  }
  
  public boolean is(Account account)
  {
    return accounts.contains(account);
  }
  
  public boolean is(String id)
  {
    return getAccountById(id) != null;
  }
  
  public void removeAccount(Account account)
  {
    accounts.remove(account);
  }
  
  public void removePropertyChangeListener(PropertyChangeListener listener)
  {
    listeners.remove(listener);
  }
  
  public synchronized Future<IProfileImage> requestImage(final int preferredWidth, final int preferredHeight)
  {
    if (images != null) {
      for (ProfileImage image : images) {
        if ((image.getWidth() == preferredWidth) && (image.getHeight() == preferredHeight)) {
          return new FutureResult(image, null);
        }
      }
    }
    FutureJob<IProfileImage> job = new FutureJob(Messages.Identity_Retrieving_Image)
    {
      protected IStatus run(IProgressMonitor monitor)
      {
        try
        {
          ProfileImage image = model.getImage(Identity.this, preferredWidth, preferredHeight, monitor);
          if (image != null) {
            addImage(image);
          }
          return success(image);
        }
        catch (Throwable t)
        {
          IStatus localIStatus;
          return error(t);
        }
        finally
        {
          done();
        }
      }
    };
    job.schedule();
    return job;
  }
  
  public Future<IProfile> requestProfile()
  {
    if ((profile != null) && (!refreshProfile)) {
      return new FutureResult(profile, null);
    }
    refreshProfile = false;
    FutureJob<IProfile> job = new FutureJob(Messages.Identity_Retrieving_Profile)
    {
      protected IStatus run(IProgressMonitor monitor)
      {
        try
        {
          Profile profile = new Profile(Identity.this);
          model.updateProfile(profile, monitor);
          setProfile(profile);
          return success(profile);
        }
        catch (Throwable t)
        {
          IStatus localIStatus;
          return error(t);
        }
        finally
        {
          done();
        }
      }
    };
    job.schedule();
    return job;
  }
  
  private void firePropertyChangeEvent(String propertyName, Object oldValue, Object newValue)
  {
    PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, oldValue, newValue);
    for (PropertyChangeListener listener : listeners) {
      listener.propertyChange(event);
    }
  }
  
  protected synchronized void addImage(ProfileImage image)
  {
    if (images == null) {
      images = new ArrayList();
    }
    images.add(image);
    firePropertyChangeEvent("image", null, image);
  }
  
  protected synchronized void removeImage(ProfileImage image)
  {
    if (images != null) {
      images.remove(image);
    }
  }
  
  protected void setProfile(Profile profile)
  {
    this.profile = profile;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.Identity
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core.gravatar;

import java.util.regex.Pattern;

public abstract interface IGravatarConstants
{
  public static final String URL = "http://www.gravatar.com/avatar/";
  public static final String HASH_REGEX = "[0-9a-f]{32}";
  public static final Pattern HASH_PATTERN = Pattern.compile("[0-9a-f]{32}");
  public static final int HASH_LENGTH = 32;
  public static final String HASH_ALGORITHM = "MD5";
  public static final String CHARSET = "CP1252";
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.gravatar.IGravatarConstants
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core.gravatar;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.IAdaptable;

public abstract class GravatarUtils
{
  private static String digest(String value)
  {
    String hashed = null;
    try
    {
      byte[] input = value.getBytes("CP1252");
      byte[] digested = MessageDigest.getInstance("MD5").digest(input);
      hashed = new BigInteger(1, digested).toString(16);
      int padding = 32 - hashed.length();
      if (padding > 0)
      {
        char[] zeros = new char[padding];
        Arrays.fill(zeros, '0');
        hashed = new String(zeros) + hashed;
      }
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      hashed = null;
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      hashed = null;
    }
    return hashed;
  }
  
  public String getAdaptedHash(Object element)
  {
    if (element == null) {
      return null;
    }
    String hash = null;
    IGravatarHashProvider provider = null;
    if ((element instanceof IGravatarHashProvider)) {
      provider = (IGravatarHashProvider)element;
    } else if ((element instanceof IAdaptable)) {
      provider = (IGravatarHashProvider)((IAdaptable)element).getAdapter(IGravatarHashProvider.class);
    }
    if (provider != null)
    {
      hash = provider.getGravatarHash();
    }
    else
    {
      String potentialHash = element.toString();
      if (isValidHash(potentialHash)) {
        hash = potentialHash;
      } else {
        hash = getHash(potentialHash);
      }
    }
    return hash;
  }
  
  public static boolean isValidHash(String hash)
  {
    return (hash != null) && (hash.length() == 32) && (IGravatarConstants.HASH_PATTERN.matcher(hash).matches());
  }
  
  public static String getHash(String email)
  {
    String hash = null;
    if (email != null)
    {
      email = email.trim().toLowerCase(Locale.US);
      if (email.length() > 0) {
        hash = digest(email);
      }
    }
    return hash;
  }
  
  public static boolean isValidEmail(String alias)
  {
    return (alias != null) && (alias.contains("@"));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.gravatar.GravatarUtils
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core.gravatar;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.identity.core.Account;
import org.eclipse.mylyn.commons.identity.core.IIdentity;
import org.eclipse.mylyn.commons.identity.core.spi.IdentityConnector;
import org.eclipse.mylyn.commons.identity.core.spi.Profile;
import org.eclipse.mylyn.commons.identity.core.spi.ProfileImage;

public class GravatarConnector
  extends IdentityConnector
{
  public static final String KIND = "org.eclipse.mylyn.commons.identity.gravatar";
  private final GravatarStore store;
  private final int DEFAULT_SIZE = 80;
  private final Map<String, Long> noImageHashByTimeStamp = new ConcurrentHashMap();
  
  public GravatarConnector()
  {
    store = new GravatarStore();
  }
  
  public ProfileImage getImage(IIdentity identity, int preferredWidth, int preferredHeight, IProgressMonitor monitor)
    throws CoreException
  {
    String id = getHash(identity);
    if (id == null) {
      return null;
    }
    if (noImageHashByTimeStamp.containsKey(id)) {
      return null;
    }
    identity.addAccount(Account.id(id).kind("org.eclipse.mylyn.commons.identity.gravatar"));
    
    int size = getSize(preferredWidth);
    try
    {
      gravatar = store.loadGravatarByHash(id, size, null);
    }
    catch (IOException e)
    {
      Gravatar gravatar;
      throw new CoreException(new Status(4, "org.eclipse.mylyn.commons.identity.gravatar", e.getMessage(), e));
    }
    Gravatar gravatar;
    if (gravatar != null) {
      return new ProfileImage(gravatar.getBytes(), size, size, "jpg");
    }
    noImageHashByTimeStamp.put(id, Long.valueOf(System.currentTimeMillis()));
    
    return null;
  }
  
  private int getSize(int preferredSize)
  {
    if ((preferredSize < 1) && (preferredSize > 512)) {
      return 80;
    }
    return preferredSize;
  }
  
  public boolean supportsImageSize(int preferredWidth, int preferredHeight)
  {
    return (preferredWidth >= 1) && (preferredWidth <= 512) && (preferredHeight >= 1) && (preferredHeight <= 512) && (preferredWidth == preferredHeight);
  }
  
  public void updateProfile(Profile profile, IProgressMonitor monitor)
    throws CoreException
  {}
  
  private String getHash(IIdentity identity)
  {
    Account account = identity.getAccountByKind("org.eclipse.mylyn.commons.identity.gravatar");
    if ((account != null) && 
      (GravatarUtils.isValidHash(account.getId()))) {
      return account.getId();
    }
    String[] arrayOfString;
    int j = (arrayOfString = identity.getAliases()).length;
    for (int i = 0; i < j; i++)
    {
      String alias = arrayOfString[i];
      if (GravatarUtils.isValidEmail(alias)) {
        return GravatarUtils.getHash(alias);
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.gravatar.GravatarConnector
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core.gravatar;

public abstract interface IGravatarCallback
{
  public abstract void loaded(Gravatar paramGravatar);
  
  public abstract void error(Exception paramException);
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.gravatar.IGravatarCallback
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core.gravatar;

public enum GravatarStore$Rating
{
  G,  PG,  R,  X;
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.gravatar.GravatarStore.Rating
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core.gravatar;

import java.io.Serializable;
import org.eclipse.core.runtime.Assert;

public class Gravatar
  implements Serializable
{
  private static final long serialVersionUID = 7303486086217698261L;
  private final String id;
  private final long updateTime;
  private final byte[] bytes;
  
  public Gravatar(String id, long updateTime, byte[] bytes)
  {
    Assert.isNotNull(id, "Id cannot be null");
    Assert.isNotNull(bytes, "Bytes cannot be null");
    this.id = id;
    this.updateTime = updateTime;
    this.bytes = bytes;
  }
  
  public int hashCode()
  {
    return id.hashCode();
  }
  
  public boolean equals(Object obj)
  {
    if (obj == this) {
      return true;
    }
    if ((obj instanceof Gravatar)) {
      return getId().equals(((Gravatar)obj).getId());
    }
    return false;
  }
  
  public byte[] getBytes()
  {
    byte[] copy = new byte[bytes.length];
    System.arraycopy(bytes, 0, copy, 0, copy.length);
    return copy;
  }
  
  public String toString()
  {
    return id;
  }
  
  public String getId()
  {
    return id;
  }
  
  public long getUpdateTime()
  {
    return updateTime;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.gravatar.Gravatar
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core.gravatar;

public abstract class GravatarCallbackAdapter
  implements IGravatarCallback
{
  public void loaded(Gravatar avatar) {}
  
  public void error(Exception exception) {}
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.gravatar.GravatarCallbackAdapter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core.gravatar;

public abstract interface IGravatarHashProvider
{
  public abstract String getGravatarHash();
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.commons.identity.core.gravatar.IGravatarHashProvider
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.commons.identity.core.gravatar;

import java.io.IOException;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;

public class GravatarStore
  implements Serializable, ISchedulingRule
{
  public static final int TIMEOUT = 30000;
  public static final int BUFFER_SIZE = 8192;
  private static final long serialVersionUID = 6084425297832914970L;
  
  public static enum Rating
  {
    G,  PG,  R,  X;
  }
  
  private long lastRefresh = 0L;
  private final String url;
  private Map<String, Gravatar> avatars;
  
  public GravatarStore()
  {
    this("http://www.gravatar.com/avatar/");
  }
  
  public GravatarStore(String url)
  {
    Assert.isNotNull(url, "Url cannot be null");
    if (!url.endsWith("/")) {
      url = url + "/";
    }
    this.url = url;
  }
  
  public boolean isCacheEnabled()
  {
    return avatars != null;
  }
  
  public void setCacheEnabled(boolean cacheEnabled)
  {
    if ((cacheEnabled) && (avatars == null)) {
      avatars = Collections.synchronizedMap(new HashMap());
    } else if ((!cacheEnabled) && (avatars != null)) {
      avatars = null;
    }
  }
  
  public long getRefreshTime()
  {
    return lastRefresh;
  }
  
  public boolean containsGravatar(String hash)
  {
    return (hash != null) && (avatars != null) ? avatars.containsKey(hash) : false;
  }
  
  public GravatarStore scheduleRefresh()
  {
    Job refresh = new Job(Messages.GravatarStore_RefreshJobName)
    {
      protected IStatus run(IProgressMonitor monitor)
      {
        refresh(monitor);
        return Status.OK_STATUS;
      }
    };
    refresh.setRule(this);
    refresh.schedule();
    return this;
  }
  
  public GravatarStore refresh(IProgressMonitor monitor)
  {
    if (avatars == null) {
      return this;
    }
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    String[] entries = null;
    synchronized (avatars)
    {
      entries = new String[avatars.size()];
      entries = (String[])avatars.keySet().toArray(entries);
    }
    monitor.beginTask("", entries.length);
    String[] arrayOfString1;
    int j = (arrayOfString1 = entries).length;
    for (int i = 0; i < j; i++)
    {
      String entry = arrayOfString1[i];
      if (monitor.isCanceled()) {
        break;
      }
      monitor.setTaskName(MessageFormat.format(Messages.GravatarStore_LoadingAvatar, new Object[] { entry }));
      try
      {
        loadGravatarByHash(entry);
      }
      catch (IOException localIOException) {}
      monitor.worked(1);
    }
    monitor.done();
    lastRefresh = System.currentTimeMillis();
    return this;
  }
  
  public GravatarStore loadGravatarByHash(final String hash, final IGravatarCallback callback)
  {
    String title = MessageFormat.format(Messages.GravatarStore_LoadingAvatar, new Object[] { hash });
    Job job = new Job(title)
    {
      protected IStatus run(IProgressMonitor monitor)
      {
        try
        {
          Gravatar avatar = loadGravatarByHash(hash);
          if ((avatar != null) && (callback != null)) {
            callback.loaded(avatar);
          }
        }
        catch (IOException e)
        {
          if (callback != null) {
            callback.error(e);
          }
        }
        return Status.OK_STATUS;
      }
    };
    job.setRule(this);
    job.schedule();
    return this;
  }
  
  public GravatarStore loadGravatarByEmail(String email, IGravatarCallback callback)
  {
    loadGravatarByHash(GravatarUtils.getHash(email), callback);
    return this;
  }
  
  public Gravatar loadGravatarByHash(String hash)
    throws IOException
  {
    return loadGravatarByHash(hash, -1, null);
  }
  
  /* Error */
  public Gravatar loadGravatarByHash(String hash, int size, Rating rating)
    throws IOException
  {
    // Byte code:
    //   0: iload_2
    //   1: iconst_m1
    //   2: if_icmpeq +19 -> 21
    //   5: iload_2
    //   6: iconst_1
    //   7: if_icmplt +10 -> 17
    //   10: iload_2
    //   11: sipush 512
    //   14: if_icmple +7 -> 21
    //   17: iconst_0
    //   18: goto +4 -> 22
    //   21: iconst_1
    //   22: ldc 8
    //   24: invokestatic 287	org/eclipse/core/runtime/Assert:isLegal	(ZLjava/lang/String;)Z
    //   27: pop
    //   28: aload_1
    //   29: invokestatic 301	org/eclipse/mylyn/internal/commons/identity/core/gravatar/GravatarUtils:isValidHash	(Ljava/lang/String;)Z
    //   32: ifne +5 -> 37
    //   35: aconst_null
    //   36: areturn
    //   37: aconst_null
    //   38: astore 4
    //   40: new 144	java/lang/StringBuilder
    //   43: dup
    //   44: aload_0
    //   45: getfield 259	org/eclipse/mylyn/internal/commons/identity/core/gravatar/GravatarStore:url	Ljava/lang/String;
    //   48: invokestatic 271	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   51: invokespecial 273	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   54: aload_1
    //   55: invokevirtual 275	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   58: ldc 5
    //   60: invokevirtual 275	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   63: invokevirtual 272	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   66: astore 5
    //   68: iload_2
    //   69: iconst_m1
    //   70: if_icmpeq +29 -> 99
    //   73: new 144	java/lang/StringBuilder
    //   76: dup
    //   77: aload 5
    //   79: invokestatic 271	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   82: invokespecial 273	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   85: ldc 3
    //   87: invokevirtual 275	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   90: iload_2
    //   91: invokevirtual 274	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
    //   94: invokevirtual 272	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   97: astore 5
    //   99: aload_3
    //   100: ifnull +35 -> 135
    //   103: new 144	java/lang/StringBuilder
    //   106: dup
    //   107: aload 5
    //   109: invokestatic 271	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   112: invokespecial 273	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   115: ldc 2
    //   117: invokevirtual 275	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   120: aload_3
    //   121: invokevirtual 300	org/eclipse/mylyn/internal/commons/identity/core/gravatar/GravatarStore$Rating:name	()Ljava/lang/String;
    //   124: invokevirtual 269	java/lang/String:toLowerCase	()Ljava/lang/String;
    //   127: invokevirtual 275	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   130: invokevirtual 272	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   133: astore 5
    //   135: new 147	java/net/URL
    //   138: dup
    //   139: aload 5
    //   141: invokespecial 282	java/net/URL:<init>	(Ljava/lang/String;)V
    //   144: invokevirtual 283	java/net/URL:openConnection	()Ljava/net/URLConnection;
    //   147: checkcast 146	java/net/HttpURLConnection
    //   150: astore 6
    //   152: aload 6
    //   154: sipush 30000
    //   157: invokevirtual 279	java/net/HttpURLConnection:setConnectTimeout	(I)V
    //   160: aload 6
    //   162: iconst_0
    //   163: invokevirtual 280	java/net/HttpURLConnection:setUseCaches	(Z)V
    //   166: aload 6
    //   168: invokevirtual 278	java/net/HttpURLConnection:connect	()V
    //   171: aload 6
    //   173: invokevirtual 277	java/net/HttpURLConnection:getResponseCode	()I
    //   176: sipush 200
    //   179: if_icmpeq +5 -> 184
    //   182: aconst_null
    //   183: areturn
    //   184: new 138	java/io/ByteArrayOutputStream
    //   187: dup
    //   188: invokespecial 263	java/io/ByteArrayOutputStream:<init>	()V
    //   191: astore 7
    //   193: aload 6
    //   195: invokevirtual 281	java/net/HttpURLConnection:getInputStream	()Ljava/io/InputStream;
    //   198: astore 8
    //   200: sipush 8192
    //   203: newarray <illegal type>
    //   205: astore 9
    //   207: iconst_m1
    //   208: istore 10
    //   210: goto +13 -> 223
    //   213: aload 7
    //   215: aload 9
    //   217: iconst_0
    //   218: iload 10
    //   220: invokevirtual 265	java/io/ByteArrayOutputStream:write	([BII)V
    //   223: aload 8
    //   225: aload 9
    //   227: invokevirtual 267	java/io/InputStream:read	([B)I
    //   230: dup
    //   231: istore 10
    //   233: iconst_m1
    //   234: if_icmpne -21 -> 213
    //   237: goto +17 -> 254
    //   240: astore 11
    //   242: aload 8
    //   244: invokevirtual 266	java/io/InputStream:close	()V
    //   247: goto +4 -> 251
    //   250: pop
    //   251: aload 11
    //   253: athrow
    //   254: aload 8
    //   256: invokevirtual 266	java/io/InputStream:close	()V
    //   259: goto +4 -> 263
    //   262: pop
    //   263: new 158	org/eclipse/mylyn/internal/commons/identity/core/gravatar/Gravatar
    //   266: dup
    //   267: aload_1
    //   268: invokestatic 276	java/lang/System:currentTimeMillis	()J
    //   271: aload 7
    //   273: invokevirtual 264	java/io/ByteArrayOutputStream:toByteArray	()[B
    //   276: invokespecial 292	org/eclipse/mylyn/internal/commons/identity/core/gravatar/Gravatar:<init>	(Ljava/lang/String;J[B)V
    //   279: astore 4
    //   281: aload_0
    //   282: getfield 260	org/eclipse/mylyn/internal/commons/identity/core/gravatar/GravatarStore:avatars	Ljava/util/Map;
    //   285: ifnull +16 -> 301
    //   288: aload_0
    //   289: getfield 260	org/eclipse/mylyn/internal/commons/identity/core/gravatar/GravatarStore:avatars	Ljava/util/Map;
    //   292: aload_1
    //   293: aload 4
    //   295: invokeinterface 307 3 0
    //   300: pop
    //   301: aload 4
    //   303: areturn
    // Line number table:
    //   Java source line #203	-> byte code offset #0
    //   Java source line #204	-> byte code offset #28
    //   Java source line #205	-> byte code offset #35
    //   Java source line #208	-> byte code offset #37
    //   Java source line #209	-> byte code offset #40
    //   Java source line #210	-> byte code offset #68
    //   Java source line #211	-> byte code offset #73
    //   Java source line #213	-> byte code offset #99
    //   Java source line #214	-> byte code offset #103
    //   Java source line #216	-> byte code offset #135
    //   Java source line #217	-> byte code offset #152
    //   Java source line #218	-> byte code offset #160
    //   Java source line #219	-> byte code offset #166
    //   Java source line #221	-> byte code offset #171
    //   Java source line #222	-> byte code offset #182
    //   Java source line #225	-> byte code offset #184
    //   Java source line #226	-> byte code offset #193
    //   Java source line #228	-> byte code offset #200
    //   Java source line #229	-> byte code offset #207
    //   Java source line #230	-> byte code offset #210
    //   Java source line #231	-> byte code offset #213
    //   Java source line #230	-> byte code offset #223
    //   Java source line #233	-> byte code offset #240
    //   Java source line #235	-> byte code offset #242
    //   Java source line #236	-> byte code offset #250
    //   Java source line #238	-> byte code offset #251
    //   Java source line #235	-> byte code offset #254
    //   Java source line #236	-> byte code offset #262
    //   Java source line #239	-> byte code offset #263
    //   Java source line #240	-> byte code offset #281
    //   Java source line #241	-> byte code offset #288
    //   Java source line #243	-> byte code offset #301
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	304	0	this	GravatarStore
    //   0	304	1	hash	String
    //   0	304	2	size	int
    //   0	304	3	rating	Rating
    //   38	264	4	avatar	Gravatar
    //   66	74	5	location	String
    //   150	44	6	connection	java.net.HttpURLConnection
    //   191	81	7	output	java.io.ByteArrayOutputStream
    //   198	57	8	input	java.io.InputStream
    //   205	21	9	buffer	byte[]
    //   208	24	10	read	int
    //   240	12	11	localObject	Object
    //   250	1	12	localIOException1	IOException
    //   262	1	13	localIOException2	IOException
    // Exception table:
    //   from	to	target	type
    //   200	240	240	finally
    //   242	247	250	java/io/IOException
    //   254	259	262	java/io/IOException
  }
  
  public Gravatar loadGravatarByEmail(String email)
    throws IOException
  {
 
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd