org.eclipse.wst.internet.cache_1.0.400.v201004280700

16:49:02.736 INFO  jd.cli.Main - Decompiling org.eclipse.wst.internet.cache_1.0.400.v201004280700.jar
package org.eclipse.wst.internet.cache.internal;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Random;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Cache
{
  private static final String URI = "uri";
  private static final String LOCATION = "location";
  private static final String ENTRY = "entry";
  private static final String CACHE = "cache";
  private static final String LAST_MODIFIED = "lastModified";
  private static final String EXPIRATION_TIME = "expirationTime";
  private static final String FILE_PROTOCOL = "file:///";
  private static final String CACHE_FILE = "cache.xml";
  private static final String CACHE_EXTENSION = ".cache";
  private static final String CACHE_PREFIX = "wtpcache";
  private static final String CACHE_SUFFIX = null;
  private static final long TIMEOUT = 86400000L;
  private static Cache cacheInstance = null;
  private Hashtable cache;
  private Set uncached;
  private File cacheLocation = null;
  
  protected Cache(IPath cacheLocation)
  {
    this.cacheLocation = cacheLocation.toFile();
    cache = new Hashtable();
    uncached = new HashSet();
  }
  
  public static Cache getInstance()
  {
    return cacheInstance;
  }
  
  public String getResource(String uri)
  {
    if (uri == null) {
      return null;
    }
    CacheEntry result = (CacheEntry)cache.get(uri);
    if (result == null)
    {
      if (!uncached.contains(uri)) {
        result = cacheResource(uri);
      }
    }
    else if (result.hasExpired()) {
      result = refreshCacheEntry(result);
    }
    if ((result == null) || (result.getLocalFile() == null)) {
      return null;
    }
    return "file:///" + cacheLocation.toString() + "/" + result.getLocalFile();
  }
  
  protected String[] getUncachedURIs()
  {
    return (String[])uncached.toArray(new String[uncached.size()]);
  }
  
  protected void clearUncachedURIs()
  {
    uncached.clear();
  }
  
  protected void addUncachedURI(String uri)
  {
    CacheJob.startJob();
    uncached.add(uri);
  }
  
  protected CacheEntry cacheResource(String uri)
  {
    CacheEntry cacheEntry = null;
    URLConnection conn = null;
    InputStream is = null;
    OutputStream os = null;
    try
    {
      URL url = new URL(uri);
      conn = url.openConnection();
      conn.connect();
      if (conn.getUseCaches())
      {
        is = conn.getInputStream();
        
        Random rand = new Random();
        String fileName = rand.nextInt() + ".cache";
        File file = new File(cacheLocation, fileName);
        while (!file.createNewFile())
        {
          fileName = rand.nextInt() + ".cache";
          file = new File(cacheLocation, fileName);
        }
        os = new FileOutputStream(file);
        byte[] bytes = new byte['?'];
        int bytelength;
        while ((bytelength = is.read(bytes)) != -1)
        {
          int bytelength;
          os.write(bytes, 0, bytelength);
        }
        long lastModified = conn.getLastModified();
        long expiration = conn.getExpiration();
        if (expiration == 0L) {
          expiration = System.currentTimeMillis() + 86400000L;
        }
        cacheEntry = new CacheEntry(uri, fileName, lastModified, expiration);
        cache.put(uri, cacheEntry);
      }
    }
    catch (Exception localException)
    {
      addUncachedURI(uri);
    }
    finally
    {
      if (is != null) {
        try
        {
          is.close();
        }
        catch (IOException localIOException1) {}
      }
      if (os != null) {
        try
        {
          os.close();
        }
        catch (IOException localIOException2) {}
      }
    }
    return cacheEntry;
  }
  
  protected CacheEntry refreshCacheEntry(CacheEntry cacheEntry)
  {
    URLConnection conn = null;
    InputStream is = null;
    OutputStream os = null;
    try
    {
      URL url = new URL(cacheEntry.getURI());
      conn = url.openConnection();
      conn.connect();
      
      long lastModified = conn.getLastModified();
      if (lastModified > cacheEntry.getLastModified())
      {
        long expiration = conn.getExpiration();
        if (expiration == 0L) {
          expiration = System.currentTimeMillis() + 86400000L;
        }
        is = conn.getInputStream();
        
        String localFile = cacheEntry.getLocalFile();
        
        File tempFile = File.createTempFile("wtpcache", CACHE_SUFFIX);
        tempFile.deleteOnExit();
        
        os = new FileOutputStream(tempFile);
        byte[] bytes = new byte['?'];
        int bytelength;
        while ((bytelength = is.read(bytes)) != -1)
        {
          int bytelength;
          os.write(bytes, 0, bytelength);
        }
        is.close();
        os.close();
        deleteFile(cacheEntry.getURI());
        File f = new File(cacheLocation, localFile);
        tempFile.renameTo(f);
        cacheEntry.setExpiration(expiration);
        cacheEntry.setLastModified(lastModified);
      }
      else
      {
        long expiration = conn.getExpiration();
        if (expiration == 0L) {
          expiration = System.currentTimeMillis() + 86400000L;
        }
        cacheEntry.setExpiration(expiration);
      }
    }
    catch (Exception localException) {}finally
    {
      if (is != null) {
        try
        {
          is.close();
        }
        catch (IOException localIOException1) {}
      }
      if (os != null) {
        try
        {
          os.close();
        }
        catch (IOException localIOException2) {}
      }
    }
    return cacheEntry;
  }
  
  public String[] getCachedURIs()
  {
    Set keyset = cache.keySet();
    return (String[])keyset.toArray(new String[keyset.size()]);
  }
  
  protected void close()
  {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try
    {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document cachedoc = builder.newDocument();
      Element rootelem = cachedoc.createElement("cache");
      cachedoc.appendChild(rootelem);
      
      Enumeration uris = cache.keys();
      while (uris.hasMoreElements())
      {
        String key = (String)uris.nextElement();
        CacheEntry cacheEntry = (CacheEntry)cache.get(key);
        if (cacheEntry != null)
        {
          Element entry = cachedoc.createElement("entry");
          entry.setAttribute("uri", key);
          entry.setAttribute("location", cacheEntry.getLocalFile());
          entry.setAttribute("expirationTime", String.valueOf(cacheEntry.getExpirationTime()));
          entry.setAttribute("lastModified", String.valueOf(cacheEntry.getLastModified()));
          rootelem.appendChild(entry);
        }
      }
      TransformerFactory tFactory = TransformerFactory.newInstance();
      Transformer transformer = tFactory.newTransformer();
      Source input = new DOMSource(cachedoc);
      IPath stateLocation = Platform.getStateLocation(CachePlugin.getDefault().getBundle());
      Result output = new StreamResult(stateLocation.toString() + "/" + "cache.xml");
      transformer.transform(input, output);
    }
    catch (Exception localException)
    {
      System.out.println("Unable to store internet cache.");
    }
    cacheInstance = null;
  }
  
  protected static void open(IPath cacheLocation)
  {
    cacheInstance = new Cache(cacheLocation);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try
    {
      IPath stateLocation = cacheLocation;
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document cachedoc = builder.parse(stateLocation.toString() + "/" + "cache.xml");
      Element rootelem = cachedoc.getDocumentElement();
      NodeList entries = rootelem.getChildNodes();
      int numEntries = entries.getLength();
      for (int i = 0; i < numEntries; i++)
      {
        Node entry = entries.item(i);
        if ((entry instanceof Element))
        {
          Element e = (Element)entry;
          if (e.getNodeName().equals("entry"))
          {
            String uri = e.getAttribute("uri");
            String location = e.getAttribute("location");
            String lm = e.getAttribute("lastModified");
            String et = e.getAttribute("expirationTime");
            long lastModified = -1L;
            long expirationTime = -1L;
            try
            {
              lastModified = Long.parseLong(lm);
            }
            catch (NumberFormatException localNumberFormatException1) {}
            try
            {
              expirationTime = Long.parseLong(et);
            }
            catch (NumberFormatException localNumberFormatException2) {}
            if ((uri != null) && (location != null)) {
              cacheInstancecache.put(uri, new CacheEntry(uri, location, lastModified, expirationTime));
            }
          }
        }
      }
    }
    catch (FileNotFoundException localFileNotFoundException) {}catch (Exception localException)
    {
      System.out.println("Unable to load cache.");
    }
  }
  
  public void clear()
  {
    Enumeration keys = cache.keys();
    while (keys.hasMoreElements())
    {
      String key = (String)keys.nextElement();
      
      deleteFile(key);
    }
    cache.clear();
  }
  
  public void deleteEntry(String uri)
  {
    if (uri == null) {
      return;
    }
    deleteFile(uri);
    cache.remove(uri);
  }
  
  protected void deleteFile(String uri)
  {
    CacheEntry cacheEntry = (CacheEntry)cache.get(uri);
    if (cacheEntry != null)
    {
      String location = cacheLocation.toString() + "/" + cacheEntry.getLocalFile();
      File file = new File(location);
      if (!file.delete()) {
        System.out.println("Unable to delete file " + location + " from cache.");
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.Cache
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

public class CacheEntry
{
  private String uri;
  private String localFile;
  private long lastModified;
  private long expirationTime;
  
  public CacheEntry(String uri, String localFile, long lastModified, long expirationTime)
  {
    this.uri = uri;
    this.localFile = localFile;
    this.lastModified = lastModified;
    this.expirationTime = expirationTime;
  }
  
  public boolean hasExpired()
  {
    if ((expirationTime != -1L) && (System.currentTimeMillis() > expirationTime)) {
      return true;
    }
    return false;
  }
  
  public void setExpiration(long expirationTime)
  {
    this.expirationTime = expirationTime;
  }
  
  public long getExpirationTime()
  {
    return expirationTime;
  }
  
  public String getURI()
  {
    return uri;
  }
  
  public String getLocalFile()
  {
    return localFile;
  }
  
  public long getLastModified()
  {
    return lastModified;
  }
  
  public void setLastModified(long lastModified)
  {
    this.lastModified = lastModified;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.CacheEntry
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

import java.text.MessageFormat;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class CacheJob
  extends Job
{
  private static final long SCHEDULE_TIME = 3600000L;
  private static CacheJob job = null;
  
  public CacheJob()
  {
    super(CacheMessages._UI_CACHE_MONITOR_NAME);
  }
  
  protected IStatus run(IProgressMonitor monitor)
  {
    boolean allSuccessful = true;
    Cache cache = Cache.getInstance();
    String[] uncachedURIs = cache.getUncachedURIs();
    int numUncachedURIs = uncachedURIs.length;
    
    cache.clearUncachedURIs();
    monitor.beginTask(CacheMessages._UI_CACHE_MONITOR_NAME, numUncachedURIs);
    try
    {
      IStatus localIStatus;
      for (int i = 0; i < numUncachedURIs; i++)
      {
        if (monitor.isCanceled())
        {
          for (int j = i; j < numUncachedURIs; j++) {
            cache.addUncachedURI(uncachedURIs[j]);
          }
          return Status.CANCEL_STATUS;
        }
        String uri = uncachedURIs[i];
        monitor.setTaskName(MessageFormat.format(CacheMessages._UI_CACHE_MONITOR_CACHING, new Object[] { uri }));
        
        String cachedURI = cache.getResource(uri);
        if (cachedURI == null) {
          allSuccessful = false;
        }
        monitor.worked(1);
      }
      monitor.done();
      return Status.OK_STATUS;
    }
    finally
    {
      if (!allSuccessful) {
        startJob(3600000L);
      }
    }
  }
  
  protected static void startJob()
  {
    if (job == null) {
      startJob(0L);
    }
  }
  
  private static void startJob(long delay)
  {
    job = new CacheJob();
    job.setPriority(50);
    job.schedule(delay);
  }
  
  protected static void stopJob()
  {
    if (job != null) {
      job.cancel();
    }
    job = null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.CacheJob
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

import org.eclipse.osgi.util.NLS;

public class CacheMessages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.wst.internet.cache.internal.CachePluginResources";
  public static String _UI_CONFIRM_CLEAR_CACHE_DIALOG_TITLE;
  public static String _UI_CONFIRM_CLEAR_CACHE_DIALOG_MESSAGE;
  public static String _UI_CONFIRM_DELETE_CACHE_ENTRY_DIALOG_TITLE;
  public static String _UI_CONFIRM_DELETE_CACHE_ENTRY_DIALOG_MESSAGE;
  public static String _UI_BUTTON_CLEAR_CACHE;
  public static String _UI_BUTTON_DELETE_ENTRY;
  public static String _UI_PREF_CACHE_ENTRIES_TITLE;
  public static String _UI_PREF_CACHE_CACHE_OPTION;
  public static String _UI_PREF_CACHE_ABOUT;
  public static String _UI_PREF_PROMPT_FOR_DISAGREED_LICENSES;
  public static String _UI_CACHE_MONITOR_NAME;
  public static String _UI_CACHE_MONITOR_CACHING;
  public static String _UI_CACHE_DIALOG_LICENSE_STATEMENT1;
  public static String _UI_CACHE_DIALOG_LICENSE_STATEMENT2;
  public static String _UI_CACHE_DIALOG_LICENSE_STATEMENT2_NO_INTERNAL;
  public static String _UI_CACHE_DIALOG_LICENSE_STATEMENT2_NO_BROWSER;
  public static String _UI_CACHE_DIALOG_AGREE_BUTTON;
  public static String _UI_CACHE_DIALOG_DISAGREE_BUTTON;
  public static String _UI_CACHE_DIALOG_TITLE;
  public static String _UI_LOADING_LICENSE;
  public static String _LOG_INFO_WTP_NO_USER_INTERACTION;
  public static String WTP_NO_USER_INTERACTION_SYSTEM_PROP;
  
  static
  {
    NLS.initializeMessages("org.eclipse.wst.internet.cache.internal.CachePluginResources", CacheMessages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.CacheMessages
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

public class CachePlugin
  extends AbstractUIPlugin
{
  public static final String PLUGIN_ID = "org.eclipse.wst.internet.cache";
  private static CachePlugin plugin;
  
  public CachePlugin()
  {
    plugin = this;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    ToCacheRegistryReader.getInstance().readRegistry();
    Cache.open(Platform.getStateLocation(getBundle()));
    if (getPluginPreferences().contains("cacheEnabled")) {
      setCacheEnabled(getPluginPreferences().getBoolean("cacheEnabled"));
    } else {
      setCacheEnabled(false);
    }
    Preferences prefs = getPluginPreferences();
    LicenseRegistry registry = LicenseRegistry.getInstance();
    String[] licenses = registry.getLicenses();
    int numLicenses = licenses.length;
    for (int i = 0; i < numLicenses; i++)
    {
      int state = prefs.getInt(licenses[i]);
      if (state == LicenseRegistry.LICENSE_AGREE.intValue()) {
        registry.agreeLicense(licenses[i]);
      } else if (state == LicenseRegistry.LICENSE_DISAGREE.intValue()) {
        registry.disagreeLicense(licenses[i]);
      }
    }
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    Preferences prefs = getPluginPreferences();
    LicenseRegistry registry = LicenseRegistry.getInstance();
    String[] licenses = registry.getLicenses();
    int numLicenses = licenses.length;
    for (int i = 0; i < numLicenses; i++)
    {
      Integer state = registry.getLicenseState(licenses[i]);
      if (state == LicenseRegistry.LICENSE_DISAGREE_THIS_SESSION) {
        state = LicenseRegistry.LICENSE_DISAGREE;
      }
      prefs.setValue(licenses[i], state.intValue());
    }
    Cache.getInstance().close();
    CacheJob.stopJob();
    super.stop(context);
    plugin = null;
  }
  
  public static CachePlugin getDefault()
  {
    return plugin;
  }
  
  public void setCacheEnabled(boolean enabled)
  {
    getPluginPreferences().setValue("cacheEnabled", enabled);
    CacheJob.stopJob();
  }
  
  public boolean isCacheEnabled()
  {
    if (getPluginPreferences().contains("cacheEnabled")) {
      return getPluginPreferences().getBoolean("cacheEnabled");
    }
    return true;
  }
  
  public void setPromptDisagreedLicenses(boolean prompt)
  {
    getPluginPreferences().setValue("promptDisagreedLicenses", prompt);
  }
  
  public boolean shouldPrompt()
  {
    if (getPluginPreferences().contains("promptDisagreedLicenses")) {
      return getPluginPreferences().getBoolean("promptDisagreedLicenses");
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.CachePlugin
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

import org.eclipse.core.resources.IFile;
import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverExtension;
import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;

public class CacheURIResolverExtension
  implements URIResolverExtension
{
  public String resolve(IFile file, String baseLocation, String publicId, String systemId)
  {
    if (CachePlugin.getDefault().isCacheEnabled())
    {
      String resource = null;
      if (systemId != null) {
        resource = URIHelper.normalize(systemId, baseLocation, null);
      }
      if ((resource != null) && ((resource.startsWith("http:")) || (resource.startsWith("ftp:"))))
      {
        ToCacheResource toCacheResource = ToCacheRegistryReader.getInstance().getResourceToCache(resource);
        if ((toCacheResource == null) || (LicenseRegistry.getInstance().hasLicenseBeenAccepted(resource, toCacheResource.getLicense()))) {
          return Cache.getInstance().getResource(resource);
        }
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.CacheURIResolverExtension
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

import org.eclipse.jface.wizard.ProgressMonitorPart;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

class LicenseAcceptanceDialog$1
  implements ProgressListener
{
  final LicenseAcceptanceDialog this$0;
  private final ProgressMonitorPart val$monitor;
  private final StackLayout val$stackLayout;
  private final Browser val$browser;
  private final Composite val$licenseTextComposite;
  
  LicenseAcceptanceDialog$1(LicenseAcceptanceDialog paramLicenseAcceptanceDialog, ProgressMonitorPart paramProgressMonitorPart, StackLayout paramStackLayout, Browser paramBrowser, Composite paramComposite)
  {
    this$0 = paramLicenseAcceptanceDialog;val$monitor = paramProgressMonitorPart;val$stackLayout = paramStackLayout;val$browser = paramBrowser;val$licenseTextComposite = paramComposite;
  }
  
  public void changed(ProgressEvent event)
  {
    if (total != 0) {
      val$monitor.internalWorked(current * 100 / total);
    }
  }
  
  public void completed(ProgressEvent event)
  {
    val$monitor.done();
    
    val$stackLayout.topControl = val$browser;
    LicenseAcceptanceDialog.access$0(this$0).setEnabled(true);
    val$licenseTextComposite.layout();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.LicenseAcceptanceDialog.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Hashtable;
import org.eclipse.jface.dialogs.IconAndMessageDialog;
import org.eclipse.jface.wizard.ProgressMonitorPart;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;

public class LicenseAcceptanceDialog
  extends IconAndMessageDialog
{
  private static Hashtable dialogsInUse = new Hashtable();
  private String url;
  private String licenseURL;
  private Button agreeButton = null;
  
  protected LicenseAcceptanceDialog(Shell parent, String url, String licenseURL)
  {
    super(parent);
    this.url = url;
    this.licenseURL = licenseURL;
  }
  
  protected void configureShell(Shell shell)
  {
    super.configureShell(shell);
    shell.setText(CacheMessages._UI_CACHE_DIALOG_TITLE);
    shell.setImage(null);
  }
  
  protected Control createButtonBar(Composite parent)
  {
    Composite buttonBar = new Composite(parent, 0);
    GridLayout layout = new GridLayout();
    numColumns = 0;
    makeColumnsEqualWidth = true;
    buttonBar.setLayout(layout);
    GridData gd = new GridData(64);
    buttonBar.setLayoutData(gd);
    
    agreeButton = createButton(buttonBar, 0, 
      CacheMessages._UI_CACHE_DIALOG_AGREE_BUTTON, false);
    agreeButton.setEnabled(false);
    
    createButton(buttonBar, 1, 
      CacheMessages._UI_CACHE_DIALOG_DISAGREE_BUTTON, false);
    
    return buttonBar;
  }
  
  protected Control createContents(Composite parent)
  {
    Composite composite = new Composite(parent, 0);
    GridLayout layout = new GridLayout();
    composite.setLayout(layout);
    GridData gd = new GridData(4);
    widthHint = 500;
    composite.setLayoutData(gd);
    
    Label licenseText1 = new Label(composite, 0);
    licenseText1.setText(CacheMessages._UI_CACHE_DIALOG_LICENSE_STATEMENT1);
    Label urlText = new Label(composite, 64);
    gd = new GridData(4, 128, true, false, 1, 1);
    urlText.setLayoutData(gd);
    urlText.setText(url);
    new Label(composite, 0);
    Label licenseText2 = new Label(composite, 64);
    gd = new GridData(4, 128, true, false, 1, 1);
    licenseText2.setLayoutData(gd);
    try
    {
      Composite licenseTextComposite = new Composite(composite, 0);
      StackLayout stackLayout = new StackLayout();
      licenseTextComposite.setLayout(stackLayout);
      gd = new GridData(4, 4, true, true);
      heightHint = 400;
      licenseTextComposite.setLayoutData(gd);
      
      Composite monitorComposite = new Composite(licenseTextComposite, 0);
      monitorComposite.setLayout(new GridLayout());
      gd = new GridData(4, 4, true, true);
      heightHint = 400;
      monitorComposite.setLayoutData(gd);
      ProgressMonitorPart monitor = new ProgressMonitorPart(monitorComposite, new GridLayout());
      gd = new GridData(4, 1024, true, true);
      monitor.setLayoutData(gd);
      monitor.beginTask(CacheMessages._UI_LOADING_LICENSE, 100);
      topControl = monitorComposite;
      
      Browser browser = new Browser(licenseTextComposite, 2048);
      gd = new GridData(4, 4, true, true);
      
      browser.setUrl(licenseURL);
      if (licenseURL.startsWith("jar:"))
      {
        InputStream licenseStream = null;
        InputStreamReader isreader = null;
        BufferedReader breader = null;
        try
        {
          URL browserURL = new URL(licenseURL);
          licenseStream = browserURL.openStream();
          isreader = new InputStreamReader(licenseStream);
          breader = new BufferedReader(isreader);
          
          StringBuffer sb = new StringBuffer();
          String str;
          while ((str = breader.readLine()) != null)
          {
            String str;
            sb.append(str);
          }
          browser.setText(sb.toString());
        }
        finally
        {
          if (licenseStream != null) {
            licenseStream.close();
          }
          if (isreader != null) {
            isreader.close();
          }
          if (breader != null) {
            breader.close();
          }
        }
      }
      browser.setLayoutData(gd);
      browser.addProgressListener(new ProgressListener()
      {
        private final ProgressMonitorPart val$monitor;
        private final StackLayout val$stackLayout;
        private final Browser val$browser;
        private final Composite val$licenseTextComposite;
        
        public void changed(ProgressEvent event)
        {
          if (total != 0) {
            val$monitor.internalWorked(current * 100 / total);
          }
        }
        
        public void completed(ProgressEvent event)
        {
          val$monitor.done();
          
          val$stackLayout.topControl = val$browser;
          agreeButton.setEnabled(true);
          val$licenseTextComposite.layout();
        }
      });
      licenseText2.setText(CacheMessages._UI_CACHE_DIALOG_LICENSE_STATEMENT2);
    }
    catch (Exception localException1)
    {
      try
      {
        CachePlugin.getDefault().getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(licenseURL));
        licenseText2.setText(CacheMessages._UI_CACHE_DIALOG_LICENSE_STATEMENT2_NO_INTERNAL);
      }
      catch (Exception localException2)
      {
        licenseText2.setText(MessageFormat.format(CacheMessages._UI_CACHE_DIALOG_LICENSE_STATEMENT2_NO_BROWSER, new Object[] { licenseURL }));
      }
    }
    createButtonBar(composite);
    
    return composite;
  }
  
  protected Image getImage()
  {
    return getInfoImage();
  }
  
  public static boolean promptForLicense(Shell parent, String url, String licenseURL)
    throws IOException
  {
    boolean agreedToLicense = false;
    boolean newDialog = true;
    LicenseAcceptanceDialog dialog = null;
    if (dialogsInUse.containsKey(licenseURL))
    {
      newDialog = false;
      dialog = (LicenseAcceptanceDialog)dialogsInUse.get(licenseURL);
    }
    else
    {
      InputStream is = null;
      try
      {
        URL urlObj = new URL(licenseURL);
        is = urlObj.openStream();
        
        dialog = new LicenseAcceptanceDialog(parent, url, licenseURL);
        dialogsInUse.put(licenseURL, dialog);
        dialog.setBlockOnOpen(true);
      }
      catch (Exception localException)
      {
        throw new IOException("The license cannot be opened.");
      }
      finally
      {
        if (is != null) {
          try
          {
            is.close();
          }
          catch (IOException localIOException) {}
        }
      }
    }
    if (dialog != null)
    {
      dialog.open();
      if (dialog.getReturnCode() == 0) {
        agreedToLicense = true;
      }
      if (newDialog) {
        dialogsInUse.remove(licenseURL);
      }
    }
    return agreedToLicense;
  }
  
  public boolean close()
  {
    if (agreeButton != null)
    {
      agreeButton.dispose();
      agreeButton = null;
    }
    return super.close();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.LicenseAcceptanceDialog
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

class LicenseRegistry$1
  implements Runnable
{
  final LicenseRegistry this$0;
  private final String val$url;
  private final String val$licenseURL;
  private final LicenseRegistry.Accepted val$accepted;
  
  LicenseRegistry$1(LicenseRegistry paramLicenseRegistry, String paramString1, String paramString2, LicenseRegistry.Accepted paramAccepted)
  {
    this$0 = paramLicenseRegistry;val$url = paramString1;val$licenseURL = paramString2;val$accepted = paramAccepted;
  }
  
  public void run()
  {
    try
    {
      if (LicenseAcceptanceDialog.promptForLicense(null, val$url, val$licenseURL)) {
        val$accepted.accepted = 0;
      } else {
        val$accepted.accepted = 1;
      }
    }
    catch (Exception localException)
    {
      val$accepted.accepted = 2;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.LicenseRegistry.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

class LicenseRegistry$Accepted
{
  public static final int ACCEPTED = 0;
  public static final int NOT_ACCEPTED = 1;
  public static final int NOT_DETERMINED = 2;
  public int accepted;
  final LicenseRegistry this$0;
  
  LicenseRegistry$Accepted(LicenseRegistry paramLicenseRegistry, Accepted paramAccepted)
  {
    this(paramLicenseRegistry);
  }
  
  private LicenseRegistry$Accepted(LicenseRegistry paramLicenseRegistry)
  {
    this$0 = paramLicenseRegistry;
    
    accepted = 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.LicenseRegistry.Accepted
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

import java.text.MessageFormat;
import java.util.Hashtable;
import java.util.Set;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.Display;

public class LicenseRegistry
{
  protected static Integer LICENSE_UNSPECIFIED = new Integer(0);
  protected static Integer LICENSE_AGREE = new Integer(1);
  protected static Integer LICENSE_DISAGREE = new Integer(2);
  protected static Integer LICENSE_DISAGREE_THIS_SESSION = new Integer(3);
  protected static LicenseRegistry instance = null;
  private boolean DO_NOT_PROMPT = false;
  protected Hashtable licenses;
  
  protected LicenseRegistry()
  {
    licenses = new Hashtable();
    if (System.getProperty(CacheMessages.WTP_NO_USER_INTERACTION_SYSTEM_PROP, "false").equals("true"))
    {
      CachePlugin.getDefault().getLog().log(new Status(1, "org.eclipse.wst.internet.cache", 0, MessageFormat.format(CacheMessages._LOG_INFO_WTP_NO_USER_INTERACTION, new Object[] { CacheMessages.WTP_NO_USER_INTERACTION_SYSTEM_PROP }), null));
      DO_NOT_PROMPT = true;
    }
  }
  
  public static LicenseRegistry getInstance()
  {
    if (instance == null) {
      instance = new LicenseRegistry();
    }
    return instance;
  }
  
  public void addLicense(String url)
  {
    if ((url != null) && (!licenses.containsKey(url))) {
      licenses.put(url, LICENSE_UNSPECIFIED);
    }
  }
  
  protected void agreeLicense(String url)
  {
    if (licenses.containsKey(url)) {
      licenses.put(url, LICENSE_AGREE);
    }
  }
  
  protected void disagreeLicense(String url)
  {
    if (licenses.containsKey(url)) {
      licenses.put(url, LICENSE_DISAGREE);
    }
  }
  
  private void disagreeLicenseThisSession(String url)
  {
    if (licenses.containsKey(url)) {
      licenses.put(url, LICENSE_DISAGREE_THIS_SESSION);
    }
  }
  
  public boolean hasLicenseBeenAccepted(String url, String licenseURL)
  {
    if (DO_NOT_PROMPT) {
      return true;
    }
    if (licenses.containsKey(licenseURL))
    {
      Integer agreed = (Integer)licenses.get(licenseURL);
      if (agreed == LICENSE_AGREE) {
        return true;
      }
      if (agreed == LICENSE_DISAGREE)
      {
        if (!CachePlugin.getDefault().shouldPrompt()) {
          return false;
        }
        licenses.put(licenseURL, LICENSE_DISAGREE_THIS_SESSION);
      }
      else if (agreed == LICENSE_DISAGREE_THIS_SESSION)
      {
        return false;
      }
      int licenseAcceptance = promptToAcceptLicense(url, licenseURL);
      if (licenseAcceptance == 0)
      {
        agreeLicense(licenseURL);
        return true;
      }
      if (licenseAcceptance == 1)
      {
        disagreeLicenseThisSession(licenseURL);
        return false;
      }
      return false;
    }
    return true;
  }
  
  protected int promptToAcceptLicense(String url, String licenseURL)
  {
    Accepted accepted = new Accepted(null);
    Display.getDefault().syncExec(new Runnable()
    {
      private final String val$url;
      private final String val$licenseURL;
      private final LicenseRegistry.Accepted val$accepted;
      
      public void run()
      {
        try
        {
          if (LicenseAcceptanceDialog.promptForLicense(null, val$url, val$licenseURL)) {
            val$accepted.accepted = 0;
          } else {
            val$accepted.accepted = 1;
          }
        }
        catch (Exception localException)
        {
          val$accepted.accepted = 2;
        }
      }
    });
    return accepted;
  }
  
  protected String[] getLicenses()
  {
    return (String[])licenses.keySet().toArray(new String[licenses.keySet().size()]);
  }
  
  protected Integer getLicenseState(String url)
  {
    return (Integer)licenses.get(url);
  }
  
  private class Accepted
  {
    public static final int ACCEPTED = 0;
    public static final int NOT_ACCEPTED = 1;
    public static final int NOT_DETERMINED = 2;
    
    private Accepted() {}
    
    Accepted(Accepted paramAccepted)
    {
      this();
    }
    
    public int accepted = 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.LicenseRegistry
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Set;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;

public class ToCacheRegistryReader
{
  protected static final String PLUGIN_ID = "org.eclipse.wst.internet.cache";
  protected static final String EXTENSION_POINT_ID = "cacheresource";
  protected static final String ATT_URL = "url";
  protected static final String ATT_LICENSE = "license";
  private static ToCacheRegistryReader registryReader = null;
  private Hashtable resourcesToCache = new Hashtable();
  
  public static ToCacheRegistryReader getInstance()
  {
    if (registryReader == null) {
      registryReader = new ToCacheRegistryReader();
    }
    return registryReader;
  }
  
  public void readRegistry()
  {
    IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry();
    IExtensionPoint point = pluginRegistry.getExtensionPoint("org.eclipse.wst.internet.cache", "cacheresource");
    if (point != null)
    {
      IConfigurationElement[] elements = point.getConfigurationElements();
      for (int i = 0; i < elements.length; i++)
      {
        ToCacheResource toCacheResource = readElement(elements[i]);
        if (toCacheResource != null)
        {
          resourcesToCache.put(toCacheResource.getURL(), toCacheResource);
          LicenseRegistry.getInstance().addLicense(toCacheResource.getLicense());
        }
      }
    }
  }
  
  protected ToCacheResource readElement(IConfigurationElement element)
  {
    if (element.getName().equals("cacheresource"))
    {
      String url = element.getAttribute("url");
      if (url != null)
      {
        String license = element.getAttribute("license");
        try
        {
          URI licenseURI = new URI(license);
          if (!licenseURI.isAbsolute())
          {
            Bundle pluginBundle = Platform.getBundle(element.getDeclaringExtension().getContributor().getName());
            URL licenseURL = pluginBundle.getEntry(license);
            if (licenseURL != null) {
              license = FileLocator.resolve(licenseURL).toExternalForm();
            }
          }
        }
        catch (URISyntaxException localURISyntaxException) {}catch (IOException localIOException) {}
        return new ToCacheResource(url, license);
      }
    }
    return null;
  }
  
  public String[] getURIsToCache()
  {
    return (String[])resourcesToCache.keySet().toArray(new String[resourcesToCache.size()]);
  }
  
  public ToCacheResource getResourceToCache(String url)
  {
    return (ToCacheResource)resourcesToCache.get(url);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.ToCacheRegistryReader
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal;

public class ToCacheResource
{
  private String url;
  private String license;
  
  public ToCacheResource(String url, String license)
  {
    this.url = url;
    this.license = license;
  }
  
  public String getURL()
  {
    return url;
  }
  
  public String getLicense()
  {
    return license;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.ToCacheResource
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.cache.internal.preferences;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.wst.internet.cache.internal.CachePlugin;

class CachePreferencePage$1
  implements SelectionListener
{
  final CachePreferencePage this$0;
  
  CachePreferencePage$1(CachePreferencePage paramCachePreferencePage)
  {
    this$0 = paramCachePreferencePage;
  }
  
  public void widgetDefaultSelected(SelectionEvent e)
  {
    widgetSelected(e);
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    boolean disabled = this$0.enabledButton.getSelection();
    CachePlugin.getDefault().setCacheEnabled(!disabled);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.cache.internal.preferences.CachePreferencePage.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.inte
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