org.eclipse.mylyn.commons.net_3.7.1.v20120425-0100

16:46:24.473 INFO  jd.cli.Main - Decompiling org.eclipse.mylyn.commons.net_3.7.1.v20120425-0100.jar
package org.eclipse.mylyn.commons.net;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.ProgressMonitorWrapper;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.mylyn.internal.commons.net.CommonsNetPlugin;
import org.eclipse.mylyn.internal.commons.net.InfiniteSubProgressMonitor;

public class Policy
{
  public static boolean DEBUG_STREAMS = false;
  
  static
  {
    if ((CommonsNetPlugin.getDefault() != null) && (CommonsNetPlugin.getDefault().isDebugging())) {
      DEBUG_STREAMS = "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.mylyn.commons.net/streams"));
    }
  }
  
  public static void advance(IProgressMonitor monitor, int worked)
  {
    if (monitor.isCanceled()) {
      throw new OperationCanceledException();
    }
    monitor.worked(worked);
  }
  
  public static void checkCanceled(IProgressMonitor monitor)
  {
    if ((monitor != null) && (monitor.isCanceled())) {
      throw new OperationCanceledException();
    }
  }
  
  public static boolean isBackgroundMonitor(IProgressMonitor monitor)
  {
    return monitor instanceof BackgroundProgressMonitor;
  }
  
  public static IProgressMonitor backgroundMonitorFor(IProgressMonitor monitor)
  {
    if (monitor == null) {
      return new NullProgressMonitor();
    }
    return new BackgroundProgressMonitor(monitor);
  }
  
  public static IProgressMonitor monitorFor(IProgressMonitor monitor)
  {
    if (monitor == null) {
      return new NullProgressMonitor();
    }
    return monitor;
  }
  
  public static IProgressMonitor monitorFor(IProgressMonitor monitor, boolean backgroundOperation)
  {
    if (monitor == null) {
      return new NullProgressMonitor();
    }
    if (backgroundOperation) {
      return backgroundMonitorFor(monitor);
    }
    return monitor;
  }
  
  public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks)
  {
    if (monitor == null) {
      return new NullProgressMonitor();
    }
    if ((monitor instanceof NullProgressMonitor)) {
      return monitor;
    }
    if ((monitor instanceof BackgroundProgressMonitor)) {
      return new BackgroundProgressMonitor(new SubProgressMonitor(monitor, ticks));
    }
    return new SubProgressMonitor(monitor, ticks);
  }
  
  public static IProgressMonitor infiniteSubMonitorFor(IProgressMonitor monitor, int ticks)
  {
    if (monitor == null) {
      return new NullProgressMonitor();
    }
    if ((monitor instanceof NullProgressMonitor)) {
      return monitor;
    }
    if ((monitor instanceof BackgroundProgressMonitor)) {
      return new BackgroundProgressMonitor(new InfiniteSubProgressMonitor(monitor, ticks));
    }
    return new InfiniteSubProgressMonitor(monitor, ticks);
  }
  
  private static class BackgroundProgressMonitor
    extends ProgressMonitorWrapper
  {
    protected BackgroundProgressMonitor(IProgressMonitor monitor)
    {
      super();
    }
  }
}

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

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ProgressMonitorWrapper;

class Policy$BackgroundProgressMonitor
  extends ProgressMonitorWrapper
{
  protected Policy$BackgroundProgressMonitor(IProgressMonitor monitor)
  {
    super(monitor);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.net.Policy.BackgroundProgressMonitor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.net.http;

import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.HttpMethod;
import org.eclipse.core.runtime.IProgressMonitor;

public abstract interface CommonHttpMethod3
  extends HttpMethod
{
  public static final String CONTENT_ENCODING = "Content-Encoding";
  public static final String ACCEPT_ENCODING = "Accept-encoding";
  public static final String CONTENT_ENCODING_GZIP = "gzip";
  
  public abstract String getResponseCharSet();
  
  public abstract InputStream getResponseBodyAsStream(IProgressMonitor paramIProgressMonitor)
    throws IOException;
  
  public abstract void releaseConnection(IProgressMonitor paramIProgressMonitor);
}

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

import java.io.IOException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodBase;
import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
import org.eclipse.mylyn.commons.core.operations.OperationUtil;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.WebUtil;
import org.eclipse.mylyn.internal.commons.net.http.CommonGetMethod3;
import org.eclipse.mylyn.internal.commons.net.http.CommonHeadMethod3;
import org.eclipse.mylyn.internal.commons.net.http.CommonPostMethod3;

public abstract class HttpOperation3<T>
{
  private final CommonHttpClient3 client;
  
  public HttpOperation3(CommonHttpClient3 client)
  {
    this.client = client;
  }
  
  protected CommonHttpMethod3 createGetMethod(String requestPath)
  {
    return new CommonGetMethod3(requestPath);
  }
  
  protected CommonHttpMethod3 createPostMethod(String requestPath)
  {
    return new CommonPostMethod3(requestPath);
  }
  
  protected CommonHttpMethod3 createHeadMethod(String requestPath)
  {
    return new CommonHeadMethod3(requestPath);
  }
  
  protected int execute(HttpMethod method, IOperationMonitor monitor)
    throws IOException
  {
    monitor = OperationUtil.convert(monitor);
    if (needsAuthentication()) {
      client.authenticate(monitor);
    }
    int code = executeInternal(method, monitor);
    if (needsReauthentication(code, monitor))
    {
      WebUtil.releaseConnection((HttpMethodBase)method, monitor);
      client.authenticate(monitor);
      
      return executeInternal(method, monitor);
    }
    return code;
  }
  
  private int executeInternal(HttpMethod method, IOperationMonitor monitor)
    throws IOException
  {
    try
    {
      code = WebUtil.execute(client.getHttpClient(), client.getHostConfiguration(monitor), method, monitor);
    }
    catch (IOException e)
    {
      int code;
      WebUtil.releaseConnection((HttpMethodBase)method, monitor);
      throw e;
    }
    catch (RuntimeException e)
    {
      WebUtil.releaseConnection((HttpMethodBase)method, monitor);
      throw e;
    }
    int code;
    return code;
  }
  
  protected final CommonHttpClient3 getClient()
  {
    return client;
  }
  
  protected boolean hasCredentials(AuthenticationCredentials credentials)
  {
    return credentials != null;
  }
  
  protected boolean needsAuthentication()
  {
    return false;
  }
  
  private boolean needsReauthentication(int code, IOperationMonitor monitor)
    throws IOException
  {
    return client.needsReauthentication(code, monitor);
  }
}

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

import java.io.IOException;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.auth.DigestScheme;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
import org.eclipse.mylyn.commons.net.AbstractWebLocation;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.UnsupportedRequestException;
import org.eclipse.mylyn.commons.net.WebUtil;

public class CommonHttpClient3
{
  static final boolean DEBUG_AUTH = Boolean.valueOf(Platform.getDebugOption("org.eclipse.mylyn.commons.http/debug/authentication")).booleanValue();
  private static final String DEFAULT_USER_AGENT = "Apache XML-RPC/3.0";
  volatile DigestScheme digestScheme;
  final HttpClient httpClient;
  private final AbstractWebLocation location;
  
  private static HttpClient createHttpClient(String userAgent)
  {
    HttpClient httpClient = new HttpClient();
    httpClient.setHttpConnectionManager(WebUtil.getConnectionManager());
    httpClient.getParams().setCookiePolicy("rfc2109");
    WebUtil.configureHttpClient(httpClient, userAgent);
    return httpClient;
  }
  
  public CommonHttpClient3(AbstractWebLocation location)
  {
    this(location, createHttpClient("Apache XML-RPC/3.0"));
  }
  
  public CommonHttpClient3(AbstractWebLocation location, HttpClient client)
  {
    this.location = location;
    httpClient = createHttpClient("Apache XML-RPC/3.0");
  }
  
  public HttpClient getHttpClient()
  {
    return httpClient;
  }
  
  public AbstractWebLocation getLocation()
  {
    return location;
  }
  
  public int execute(HttpMethodBase method, IOperationMonitor monitor)
    throws IOException
  {
    HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(getHttpClient(), location, monitor);
    return WebUtil.execute(getHttpClient(), hostConfiguration, method, monitor);
  }
  
  public synchronized HostConfiguration getHostConfiguration(IOperationMonitor monitor)
    throws IOException
  {
    if (location.getUrl() == null) {
      throw new IOException("No URL specified.");
    }
    return WebUtil.createHostConfiguration(httpClient, location, monitor);
  }
  
  protected void authenticate(IOperationMonitor monitor)
    throws IOException
  {}
  
  protected boolean needsReauthentication(int code, IProgressMonitor monitor)
    throws IOException
  {
    AuthenticationType authenticationType;
    if ((code == 401) || (code == 403))
    {
      authenticationType = AuthenticationType.HTTP;
    }
    else
    {
      AuthenticationType authenticationType;
      if (code == 407) {
        authenticationType = AuthenticationType.PROXY;
      } else {
        return false;
      }
    }
    try
    {
      AuthenticationType authenticationType;
      location.requestCredentials(authenticationType, null, monitor);
    }
    catch (UnsupportedRequestException e)
    {
      IOException ioe = new IOException(HttpStatus.getStatusText(code));
      ioe.initCause(e);
      throw ioe;
    }
    catch (UnsupportedOperationException e)
    {
      IOException ioe = new IOException(HttpStatus.getStatusText(code));
      ioe.initCause(e);
      throw ioe;
    }
    return true;
  }
}

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

public class UnsupportedRequestException
  extends Exception
{
  private static final long serialVersionUID = 1L;
  
  public UnsupportedRequestException() {}
  
  public UnsupportedRequestException(String message)
  {
    super(message);
  }
  
  public UnsupportedRequestException(String message, Throwable cause)
  {
    super(message, cause);
  }
  
  public UnsupportedRequestException(Throwable cause)
  {
    super(cause);
  }
}

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

import java.net.Proxy;

class WebLocation$PlatformProxyProvider
  implements IProxyProvider
{
  public Proxy getProxyForHost(String host, String proxyType)
  {
    return WebUtil.getProxy(host, proxyType);
  }
}

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

import java.io.IOException;

public class SslCertificateException
  extends IOException
{
  private static final long serialVersionUID = 1L;
  
  public SslCertificateException() {}
  
  public SslCertificateException(String message)
  {
    super(message);
  }
}

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

import java.net.URL;
import java.text.ParseException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import javax.swing.text.html.HTML.Tag;

@Deprecated
public class HtmlTag
{
  private String tagName;
  private HTML.Tag tagType;
  private boolean isEndTag;
  private HashMap<String, String> attributes;
  private final URL baseUrl;
  private boolean selfTerminating;
  
  public HtmlTag()
  {
    tagName = null;
    tagType = Type.UNKNOWN;
    isEndTag = false;
    attributes = new HashMap();
    baseUrl = null;
  }
  
  public HtmlTag(HtmlTag htmltag)
  {
    tagName = null;
    tagType = Type.UNKNOWN;
    isEndTag = false;
    attributes = new HashMap();
    tagName = tagName;
    baseUrl = baseUrl;
    tagType = tagType;
    isEndTag = isEndTag;
    attributes = ((HashMap)attributes.clone());
  }
  
  public HtmlTag(String s)
    throws ParseException
  {
    attributes = new HashMap();
    setTagName(s);
    baseUrl = null;
  }
  
  public HtmlTag(URL url)
  {
    tagName = null;
    tagType = Type.UNKNOWN;
    isEndTag = false;
    attributes = new HashMap();
    baseUrl = url;
  }
  
  public HTML.Tag getTagType()
  {
    return tagType;
  }
  
  public String getTagName()
  {
    return tagName;
  }
  
  public void setTagName(String s)
    throws IllegalArgumentException
  {
    if ((s == null) || (s.length() == 0)) {
      throw new IllegalArgumentException("Empty tag name");
    }
    if (s.charAt(0) == '/')
    {
      isEndTag = true;
      s = s.substring(1);
    }
    if (s.length() == 0) {
      throw new IllegalArgumentException("Empty tag name");
    }
    tagName = s;
    tagType = ((HTML.Tag)tags.get(s.toUpperCase(Locale.ENGLISH)));
    if (tagType == null) {
      tagType = Type.UNKNOWN;
    }
  }
  
  public boolean isEndTag()
  {
    return isEndTag;
  }
  
  public int getIntAttribute(String s)
    throws NumberFormatException
  {
    return Integer.parseInt(getAttribute(s));
  }
  
  public String getAttribute(String s)
  {
    return (String)attributes.get(s);
  }
  
  public boolean hasAttribute(String s)
  {
    return getAttribute(s) != null;
  }
  
  public void setAttribute(String name, String value)
  {
    attributes.put(name.toLowerCase(Locale.ENGLISH), value);
  }
  
  public StringBuffer getURLs()
  {
    StringBuffer sb = new StringBuffer();
    
    Iterator<String> attributeNames = attributes.keySet().iterator();
    Iterator<String> attributeValues = attributes.values().iterator();
    while (attributeNames.hasNext())
    {
      String attributeName = (String)attributeNames.next();
      if ((attributeName.compareTo("href") == 0) || (attributeName.compareTo("src") == 0))
      {
        String target = (String)attributeValues.next();
        if ((!target.endsWith(".jpg")) && (!target.endsWith(".gif")) && (!target.endsWith(".css")) && 
          (!target.endsWith(".js")) && (!target.startsWith("mailto")) && (target.lastIndexOf("#") == -1) && 
          (target.length() > 0))
        {
          for (int i = 0; i < target.length(); i++)
          {
            char ch = target.charAt(i);
            if (!Character.isWhitespace(ch))
            {
              if (i <= 0) {
                break;
              }
              target = target.substring(i + 1);
              
              break;
            }
          }
          target = target.replace('\\', '/');
          if ((target.startsWith("news:")) || ((target.indexOf("://") != -1) && (target.length() >= 7)))
          {
            if (target.substring(0, 7).compareToIgnoreCase("http://") == 0) {
              sb.append(target);
            }
          }
          else
          {
            String baseDir = baseUrl.getPath();
            int lastSep = -1;
            for (int i = 0; i < baseDir.length(); i++)
            {
              char ch = baseDir.charAt(i);
              if (ch == '/') {
                lastSep = i;
              } else {
                if (ch == '?') {
                  break;
                }
              }
            }
            if (lastSep >= 0) {
              baseDir = baseDir.substring(0, lastSep);
            }
            while ((baseDir.length() > 1) && (baseDir.endsWith("/."))) {
              baseDir = baseDir.substring(0, baseDir.length() - 2);
            }
            if (target.startsWith("//"))
            {
              sb.append(baseUrl.getProtocol() + ":" + target);
            }
            else if (target.startsWith("/"))
            {
              sb.append(baseUrl.getProtocol() + "://" + baseUrl.getHost() + target);
            }
            else
            {
              while (target.startsWith("../"))
              {
                if (baseDir.length() > 0) {
                  baseDir = baseDir.substring(0, baseDir.lastIndexOf("/"));
                }
                target = target.substring(3);
              }
              sb.append(baseUrl.getProtocol() + "://" + baseUrl.getHost() + baseDir + "/" + target);
            }
          }
        }
      }
      else
      {
        attributeValues.next();
      }
    }
    return sb;
  }
  
  public String toString()
  {
    StringBuffer sb = new StringBuffer();
    sb.append('<');
    if (isEndTag) {
      sb.append('/');
    }
    sb.append(tagName);
    Iterator<String> keys = attributes.keySet().iterator();
    Iterator<String> values = attributes.values().iterator();
    while (keys.hasNext())
    {
      String name = (String)keys.next();
      sb.append(' ');
      sb.append(name);
      String value = (String)values.next();
      sb.append("=\"");
      if (value.length() > 0) {
        sb.append(value);
      }
      sb.append('"');
    }
    if (selfTerminating) {
      sb.append('/');
    }
    sb.append('>');
    
    return sb.toString();
  }
  
  public static class Type
    extends HTML.Tag
  {
    public static final HTML.Tag UNKNOWN = new HTML.Tag();
    public static final HTML.Tag THEAD = new Type("THEAD");
    public static final HTML.Tag DOCTYPE = new Type("!DOCTYPE");
    public static final HTML.Tag LABEL = new Type("LABEL");
    
    private Type(String name)
    {
      super();
    }
  }
  
  private static HashMap<String, HTML.Tag> tags = new HashMap();
  
  static
  {
    tags.put("A", HTML.Tag.A);
    tags.put("ADDRESS", HTML.Tag.ADDRESS);
    tags.put("APPLET", HTML.Tag.APPLET);
    tags.put("AREA", HTML.Tag.AREA);
    tags.put("B", HTML.Tag.B);
    tags.put("BASE", HTML.Tag.BASE);
    tags.put("BASEFONT", HTML.Tag.BASEFONT);
    tags.put("BIG", HTML.Tag.BIG);
    tags.put("BLOCKQUOTE", HTML.Tag.BLOCKQUOTE);
    tags.put("BODY", HTML.Tag.BODY);
    tags.put("BR", HTML.Tag.BR);
    tags.put("CAPTION", HTML.Tag.CAPTION);
    tags.put("CENTER", HTML.Tag.CENTER);
    tags.put("CITE", HTML.Tag.CITE);
    tags.put("CODE", HTML.Tag.CODE);
    tags.put("DD", HTML.Tag.DD);
    tags.put("DFN", HTML.Tag.DFN);
    tags.put("DIR", HTML.Tag.DIR);
    tags.put("DIV", HTML.Tag.DIV);
    tags.put("DL", HTML.Tag.DL);
    tags.put("!DOCTYPE", Type.DOCTYPE);
    tags.put("DT", HTML.Tag.DT);
    tags.put("EM", HTML.Tag.EM);
    tags.put("FONT", HTML.Tag.FONT);
    tags.put("FORM", HTML.Tag.FORM);
    tags.put("FRAME", HTML.Tag.FRAME);
    tags.put("FRAMESET", HTML.Tag.FRAMESET);
    tags.put("H1", HTML.Tag.H1);
    tags.put("H2", HTML.Tag.H2);
    tags.put("H3", HTML.Tag.H3);
    tags.put("H4", HTML.Tag.H4);
    tags.put("H5", HTML.Tag.H5);
    tags.put("H6", HTML.Tag.H6);
    tags.put("HEAD", HTML.Tag.HEAD);
    tags.put("HTML", HTML.Tag.HTML);
    tags.put("HR", HTML.Tag.HR);
    tags.put("I", HTML.Tag.I);
    tags.put("IMG", HTML.Tag.IMG);
    tags.put("INPUT", HTML.Tag.INPUT);
    tags.put("ISINDEX", HTML.Tag.ISINDEX);
    tags.put("KBD", HTML.Tag.KBD);
    tags.put("LI", HTML.Tag.LI);
    tags.put("LABEL", Type.LABEL);
    tags.put("LINK", HTML.Tag.LINK);
    tags.put("MAP", HTML.Tag.MAP);
    tags.put("MENU", HTML.Tag.MENU);
    tags.put("META", HTML.Tag.META);
    tags.put("NOFRAMES", HTML.Tag.NOFRAMES);
    tags.put("OBJECT", HTML.Tag.OBJECT);
    tags.put("OL", HTML.Tag.OL);
    tags.put("OPTION", HTML.Tag.OPTION);
    tags.put("P", HTML.Tag.P);
    tags.put("PARAM", HTML.Tag.PARAM);
    tags.put("PRE", HTML.Tag.PRE);
    tags.put("S", HTML.Tag.S);
    tags.put("SAMP", HTML.Tag.SAMP);
    tags.put("SCRIPT", HTML.Tag.SCRIPT);
    tags.put("SELECT", HTML.Tag.SELECT);
    tags.put("SMALL", HTML.Tag.SMALL);
    tags.put("SPAN", HTML.Tag.SPAN);
    tags.put("STRONG", HTML.Tag.STRONG);
    tags.put("STYLE", HTML.Tag.STYLE);
    tags.put("SUB", HTML.Tag.SUB);
    tags.put("SUP", HTML.Tag.SUP);
    tags.put("TABLE", HTML.Tag.TABLE);
    tags.put("TD", HTML.Tag.TD);
    tags.put("TEXTAREA", HTML.Tag.TEXTAREA);
    tags.put("TH", HTML.Tag.TH);
    tags.put("THEAD", Type.THEAD);
    tags.put("TITLE", HTML.Tag.TITLE);
    tags.put("TR", HTML.Tag.TR);
    tags.put("TT", HTML.Tag.TT);
    tags.put("U", HTML.Tag.U);
    tags.put("UL", HTML.Tag.UL);
    tags.put("VAR", HTML.Tag.VAR);
  }
  
  public void setSelfTerminating(boolean terminating)
  {
    selfTerminating = terminating;
  }
  
  public boolean isSelfTerminating()
  {
    return selfTerminating;
  }
}

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

import javax.swing.text.html.HTML.Tag;

public class HtmlTag$Type
  extends HTML.Tag
{
  public static final HTML.Tag UNKNOWN = new HTML.Tag();
  public static final HTML.Tag THEAD = new Type("THEAD");
  public static final HTML.Tag DOCTYPE = new Type("!DOCTYPE");
  public static final HTML.Tag LABEL = new Type("LABEL");
  
  private HtmlTag$Type(String name)
  {
    super(name);
  }
}

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

class HtmlStreamTokenizer$State
{
  static final State EOF = new State();
  static final State COMMENT = new State();
  static final State TEXT = new State();
  static final State TAG = new State();
  static final State WS = new State();
  static final State TAG_QUOTE = new State();
}

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

public enum AuthenticationType
{
  HTTP,  PROXY,  REPOSITORY,  CERTIFICATE;
}

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

public class AuthenticationCredentials
{
  private final String userName;
  private final String password;
  
  public AuthenticationCredentials(String userName, String password)
  {
    if (userName == null) {
      throw new IllegalArgumentException();
    }
    if (password == null) {
      throw new IllegalArgumentException();
    }
    this.userName = userName;
    this.password = password;
  }
  
  public String getUserName()
  {
    return userName;
  }
  
  public String getPassword()
  {
    return password;
  }
  
  public int hashCode()
  {
    int result = 1;
    result = 31 * result + (password == null ? 0 : password.hashCode());
    result = 31 * result + (userName == null ? 0 : userName.hashCode());
    return result;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    AuthenticationCredentials other = (AuthenticationCredentials)obj;
    if (password == null)
    {
      if (password != null) {
        return false;
      }
    }
    else if (!password.equals(password)) {
      return false;
    }
    if (userName == null)
    {
      if (userName != null) {
        return false;
      }
    }
    else if (!userName.equals(userName)) {
      return false;
    }
    return true;
  }
}

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.ProxySelector;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.Dictionary;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.swing.text.html.HTML.Tag;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.DefaultHttpParams;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.commons.httpclient.params.HttpParams;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.httpclient.util.IdleConnectionTimeoutThread;
import org.apache.commons.lang.StringEscapeUtils;
import org.eclipse.core.net.proxy.IProxyData;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.mylyn.commons.core.CoreUtil;
import org.eclipse.mylyn.internal.commons.net.AuthenticatedProxy;
import org.eclipse.mylyn.internal.commons.net.CloneableHostConfiguration;
import org.eclipse.mylyn.internal.commons.net.CommonsNetPlugin;
import org.eclipse.mylyn.internal.commons.net.MonitoredRequest;
import org.eclipse.mylyn.internal.commons.net.PollingInputStream;
import org.eclipse.mylyn.internal.commons.net.PollingProtocolSocketFactory;
import org.eclipse.mylyn.internal.commons.net.PollingSslProtocolSocketFactory;
import org.eclipse.mylyn.internal.commons.net.TimeoutInputStream;
import org.osgi.framework.Bundle;

public class WebUtil
{
  static
  {
    CoreUtil.initializeLoggingSettings();
    
    StringBuilder sb = new StringBuilder();
    sb.append("Mylyn");
    sb.append(getBundleVersion(CommonsNetPlugin.getDefault()));
    
    USER_AGENT_PREFIX = sb.toString();
    sb.setLength(0);
    if (System.getProperty("org.osgi.framework.vendor") != null)
    {
      sb.append(" ");
      sb.append(System.getProperty("org.osgi.framework.vendor"));
      sb.append(stripQualifier(System.getProperty("osgi.framework.version")));
      if (System.getProperty("eclipse.product") != null)
      {
        sb.append(" (");
        sb.append(System.getProperty("eclipse.product"));
        sb.append(")");
      }
    }
    Object parameter = DefaultHttpParams.getDefaultParams().getParameter("http.useragent");
    if (parameter != null)
    {
      String userAgent = parameter.toString();
      if (userAgent != null) {
        if (userAgent.startsWith("Jakarta Commons-"))
        {
          sb.append(" ");
          sb.append(userAgent.substring(16));
        }
        else
        {
          sb.append(" ");
          sb.append(parameter.toString());
        }
      }
    }
    sb.append(" Java/");
    sb.append(System.getProperty("java.version"));
    sb.append(" (");
    sb.append(System.getProperty("java.vendor").split(" ")[0]);
    sb.append(") ");
    
    sb.append(System.getProperty("os.name"));
    sb.append("/");
    sb.append(System.getProperty("os.version"));
    sb.append(" (");
    sb.append(System.getProperty("os.arch"));
    if (System.getProperty("osgi.nl") != null)
    {
      sb.append("; ");
      sb.append(System.getProperty("osgi.nl"));
    }
    sb.append(")");
    
    USER_AGENT_POSTFIX = sb.toString();
  }
  
  private static final String USER_AGENT = USER_AGENT_PREFIX + USER_AGENT_POSTFIX;
  private static final int CONNNECT_TIMEOUT = 60000;
  private static final int SOCKET_TIMEOUT = 180000;
  private static final int HTTP_PORT = 80;
  private static final int HTTPS_PORT = 443;
  private static final int POLL_INTERVAL = 500;
  private static final int POLL_ATTEMPTS = 360;
  private static final String USER_AGENT_PREFIX;
  private static final String USER_AGENT_POSTFIX;
  private static final int BUFFER_SIZE = 4096;
  private static final long CLOSE_TIMEOUT = -1L;
  private static final long CONNECTION_TIMEOUT_INTERVAL = 30000L;
  private static IdleConnectionTimeoutThread idleConnectionTimeoutThread;
  private static MultiThreadedHttpConnectionManager connectionManager;
  private static ProtocolSocketFactory sslSocketFactory = new PollingSslProtocolSocketFactory();
  private static PollingProtocolSocketFactory socketFactory = new PollingProtocolSocketFactory();
  
  public static void configureHttpClient(HttpClient client, String userAgent)
  {
    client.getParams().setBooleanParameter("http.protocol.allow-circular-redirects", true);
    client.getParams().setParameter("http.useragent", getUserAgent(userAgent));
    client.getParams().setConnectionManagerTimeout(30000L);
    
    configureHttpClientConnectionManager(client);
  }
  
  private static void configureHttpClientConnectionManager(HttpClient client)
  {
    client.getHttpConnectionManager().getParams().setSoTimeout(180000);
    client.getHttpConnectionManager().getParams().setConnectionTimeout(60000);
    if (CoreUtil.TEST_MODE)
    {
      client.getHttpConnectionManager().getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 2);
    }
    else
    {
      client.getHttpConnectionManager().getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 100);
      client.getHttpConnectionManager().getParams().setMaxTotalConnections(1000);
    }
  }
  
  private static void configureHttpClientProxy(HttpClient client, HostConfiguration hostConfiguration, AbstractWebLocation location)
  {
    String host = getHost(location.getUrl());
    Proxy proxy;
    Proxy proxy;
    if (isRepositoryHttps(location.getUrl())) {
      proxy = location.getProxyForHost(host, "HTTPS");
    } else {
      proxy = location.getProxyForHost(host, "HTTP");
    }
    if ((proxy != null) && (!Proxy.NO_PROXY.equals(proxy)))
    {
      InetSocketAddress address = (InetSocketAddress)proxy.address();
      hostConfiguration.setProxy(address.getHostName(), address.getPort());
      if ((proxy instanceof AuthenticatedProxy))
      {
        AuthenticatedProxy authProxy = (AuthenticatedProxy)proxy;
        Credentials credentials = getCredentials(authProxy.getUserName(), authProxy.getPassword(), 
          address.getAddress());
        AuthScope proxyAuthScope = new AuthScope(address.getHostName(), address.getPort(), AuthScope.ANY_REALM);
        client.getState().setProxyCredentials(proxyAuthScope, credentials);
      }
    }
    else
    {
      hostConfiguration.setProxyHost(null);
    }
  }
  
  public static void connect(Socket socket, final InetSocketAddress address, final int timeout, IProgressMonitor monitor)
    throws IOException
  {
    Assert.isNotNull(socket);
    
    WebRequest<?> executor = new WebRequest()
    {
      public void abort()
      {
        try
        {
          close();
        }
        catch (IOException localIOException) {}
      }
      
      public Object call()
        throws Exception
      {
        connect(address, timeout);
        return null;
      }
    };
    executeInternal(monitor, executor);
  }
  
  public static HostConfiguration createHostConfiguration(HttpClient client, AbstractWebLocation location, IProgressMonitor monitor)
  {
    Assert.isNotNull(client);
    Assert.isNotNull(location);
    
    String url = location.getUrl();
    String host = getHost(url);
    int port = getPort(url);
    
    configureHttpClientConnectionManager(client);
    
    HostConfiguration hostConfiguration = new CloneableHostConfiguration();
    configureHttpClientProxy(client, hostConfiguration, location);
    
    AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.HTTP);
    if (credentials != null)
    {
      AuthScope authScope = new AuthScope(host, port, AuthScope.ANY_REALM);
      client.getState().setCredentials(authScope, getHttpClientCredentials(credentials, host));
    }
    if (isRepositoryHttps(url))
    {
      AuthenticationCredentials certCredentials = location.getCredentials(AuthenticationType.CERTIFICATE);
      if (certCredentials == null)
      {
        Protocol protocol = new Protocol("https", sslSocketFactory, 443);
        hostConfiguration.setHost(host, port, protocol);
      }
      else
      {
        Protocol protocol = new Protocol("https", new PollingSslProtocolSocketFactory(
          certCredentials.getUserName(), certCredentials.getPassword(), null), 443);
        hostConfiguration.setHost(host, port, protocol);
      }
    }
    else
    {
      Protocol protocol = new Protocol("http", socketFactory, 80);
      hostConfiguration.setHost(host, port, protocol);
    }
    return hostConfiguration;
  }
  
  public static int execute(HttpClient client, HostConfiguration hostConfiguration, HttpMethod method, IProgressMonitor monitor)
    throws IOException
  {
    return execute(client, hostConfiguration, method, null, monitor);
  }
  
  public static int execute(final HttpClient client, final HostConfiguration hostConfiguration, final HttpMethod method, final HttpState state, IProgressMonitor monitor)
    throws IOException
  {
    Assert.isNotNull(client);
    Assert.isNotNull(method);
    
    monitor = Policy.monitorFor(monitor);
    
    MonitoredRequest<Integer> executor = new MonitoredRequest(monitor)
    {
      public void abort()
      {
        super.abort();
        method.abort();
      }
      
      public Integer execute()
        throws Exception
      {
        return Integer.valueOf(client.executeMethod(hostConfiguration, method, state));
      }
    };
    return ((Integer)executeInternal(monitor, executor)).intValue();
  }
  
  public static <T> T execute(IProgressMonitor monitor, WebRequest<T> request)
    throws Throwable
  {
    SubMonitor subMonitor = (monitor instanceof SubMonitor) ? (SubMonitor)monitor : SubMonitor.convert(null);
    
    Future<T> future = CommonsNetPlugin.getExecutorService().submit(request);
    for (;;)
    {
      if (monitor.isCanceled())
      {
        request.abort();
        
        future.cancel(false);
        try
        {
          if (!future.isCancelled()) {
            future.get();
          }
        }
        catch (CancellationException localCancellationException) {}catch (InterruptedException localInterruptedException) {}catch (ExecutionException localExecutionException1) {}
        throw new OperationCanceledException();
      }
      try
      {
        return (T)future.get(500L, TimeUnit.MILLISECONDS);
      }
      catch (ExecutionException e)
      {
        throw e.getCause();
      }
      catch (TimeoutException localTimeoutException)
      {
        subMonitor.setWorkRemaining(20);
        subMonitor.worked(1);
      }
    }
  }
  
  private static <T> T executeInternal(IProgressMonitor monitor, WebRequest<?> request)
    throws IOException
  {
    try
    {
      return (T)execute(monitor, request);
    }
    catch (IOException e)
    {
      throw e;
    }
    catch (RuntimeException e)
    {
      throw e;
    }
    catch (Error e)
    {
      throw e;
    }
    catch (Throwable e)
    {
      throw new RuntimeException(e);
    }
  }
  
  private static String getBundleVersion(Plugin plugin)
  {
    if (plugin == null) {
      return "";
    }
    Object bundleVersion = plugin.getBundle().getHeaders().get("Bundle-Version");
    if (bundleVersion == null) {
      return "";
    }
    return stripQualifier((String)bundleVersion);
  }
  
  public static int getConnectionTimeout()
  {
    return 60000;
  }
  
  static Credentials getCredentials(String username, String password, InetAddress address)
  {
    int i = username.indexOf("\\");
    if ((i > 0) && (i < username.length() - 1) && (address != null)) {
      return new NTCredentials(username.substring(i + 1), password, address.getHostName(), username.substring(0, 
        i));
    }
    return new UsernamePasswordCredentials(username, password);
  }
  
  public static String getHost(String repositoryUrl)
  {
    String result = repositoryUrl;
    int colonSlashSlash = repositoryUrl.indexOf("://");
    if (colonSlashSlash >= 0) {
      result = repositoryUrl.substring(colonSlashSlash + 3);
    }
    int colonPort = result.indexOf(':');
    int requestPath = result.indexOf('/');
    int substringEnd;
    int substringEnd;
    if ((colonPort > 0) && (requestPath > 0))
    {
      substringEnd = Math.min(colonPort, requestPath);
    }
    else
    {
      int substringEnd;
      if (colonPort > 0)
      {
        substringEnd = colonPort;
      }
      else
      {
        int substringEnd;
        if (requestPath > 0) {
          substringEnd = requestPath;
        } else {
          substringEnd = result.length();
        }
      }
    }
    return result.substring(0, substringEnd);
  }
  
  public static Credentials getHttpClientCredentials(AuthenticationCredentials credentials, String host)
  {
    String username = credentials.getUserName();
    String password = credentials.getPassword();
    int i = username.indexOf("\\");
    if ((i > 0) && (i < username.length() - 1) && (host != null)) {
      return new NTCredentials(username.substring(i + 1), password, host, username.substring(0, i));
    }
    return new UsernamePasswordCredentials(username, password);
  }
  
  public static int getPort(String repositoryUrl)
  {
    int colonSlashSlash = repositoryUrl.indexOf("://");
    int firstSlash = repositoryUrl.indexOf("/", colonSlashSlash + 3);
    int colonPort = repositoryUrl.indexOf(':', colonSlashSlash + 1);
    if (firstSlash == -1) {
      firstSlash = repositoryUrl.length();
    }
    if ((colonPort < 0) || (colonPort > firstSlash)) {
      return isRepositoryHttps(repositoryUrl) ? 443 : 80;
    }
    int requ
1 2 3 4 5

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