org.eclipse.wst.common.environment_1.0.400.v200912181832

16:48:49.787 INFO  jd.cli.Main - Decompiling org.eclipse.wst.common.environment_1.0.400.v200912181832.jar
package org.eclipse.wst.common.environment;

public class Choice
{
  private char shortcut = ' ';
  private String label = null;
  private String description = null;
  
  public Choice() {}
  
  public Choice(char shortcut, String label)
  {
    this.shortcut = shortcut;
    this.label = label;
  }
  
  public Choice(char shortcut, String label, String description)
  {
    this.shortcut = shortcut;
    this.label = label;
    this.description = description;
  }
  
  public String getLabel()
  {
    return label;
  }
  
  public void setLabel(String label)
  {
    this.label = label;
  }
  
  public String getDescription()
  {
    return description;
  }
  
  public void setDescription(String description)
  {
    this.description = description;
  }
  
  public char getShortcut()
  {
    return shortcut;
  }
  
  public void setShortcut(char shortcut)
  {
    this.shortcut = shortcut;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.Choice
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment;

import org.eclipse.core.runtime.IStatus;

public class EnvironmentException
  extends Exception
{
  private static final long serialVersionUID = 3978983275899402036L;
  protected IStatus status = null;
  
  public EnvironmentException() {}
  
  public EnvironmentException(IStatus status)
  {
    super(status == null ? null : status.getMessage());
    this.status = status;
  }
  
  public IStatus getStatus()
  {
    return status;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.EnvironmentException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment;

import org.eclipse.wst.common.environment.uri.IURIFactory;
import org.eclipse.wst.common.environment.uri.IURIScheme;
import org.eclipse.wst.common.environment.uri.URIException;
import org.eclipse.wst.common.internal.environment.eclipse.ConsoleEclipseEnvironment;

public class EnvironmentService
{
  private static IEnvironment environment;
  
  public static IEnvironment getEclipseConsoleEnvironment()
  {
    if (environment == null) {
      environment = new ConsoleEclipseEnvironment();
    }
    return environment;
  }
  
  public static ILog getEclipseLog()
  {
    IEnvironment environment = getEclipseConsoleEnvironment();
    
    return environment.getLog();
  }
  
  public static IURIScheme getEclipseScheme()
  {
    IEnvironment environment = getEclipseConsoleEnvironment();
    IURIScheme scheme = null;
    try
    {
      scheme = environment.getURIFactory().newURIScheme("platform");
    }
    catch (URIException localURIException) {}
    return scheme;
  }
  
  public static IURIScheme getFileScheme()
  {
    IEnvironment environment = getEclipseConsoleEnvironment();
    IURIScheme scheme = null;
    try
    {
      scheme = environment.getURIFactory().newURIScheme("file");
    }
    catch (URIException localURIException) {}
    return scheme;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.EnvironmentService
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment;

import org.eclipse.wst.common.environment.uri.IURIFactory;

public abstract interface IEnvironment
{
  public abstract ILog getLog();
  
  public abstract IStatusHandler getStatusHandler();
  
  public abstract IURIFactory getURIFactory();
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.IEnvironment
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment;

import org.eclipse.core.runtime.IStatus;

public abstract interface ILog
{
  public static final int OK = 0;
  public static final int INFO = 1;
  public static final int WARNING = 2;
  public static final int ERROR = 4;
  
  public abstract boolean isEnabled();
  
  public abstract boolean isEnabled(String paramString);
  
  public abstract void log(int paramInt1, int paramInt2, Object paramObject, String paramString, Throwable paramThrowable);
  
  public abstract void log(int paramInt1, String paramString1, int paramInt2, Object paramObject, String paramString2, Throwable paramThrowable);
  
  public abstract void log(int paramInt1, int paramInt2, Object paramObject, String paramString, IStatus paramIStatus);
  
  public abstract void log(int paramInt1, String paramString1, int paramInt2, Object paramObject, String paramString2, IStatus paramIStatus);
  
  public abstract void log(int paramInt1, int paramInt2, Object paramObject1, String paramString, Object paramObject2);
  
  public abstract void log(int paramInt1, String paramString1, int paramInt2, Object paramObject1, String paramString2, Object paramObject2);
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.ILog
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment;

import org.eclipse.core.runtime.IStatus;

public abstract interface IStatusHandler
{
  public abstract Choice report(IStatus paramIStatus, Choice[] paramArrayOfChoice);
  
  public abstract void report(IStatus paramIStatus)
    throws StatusException;
  
  public abstract void reportError(IStatus paramIStatus);
  
  public abstract void reportInfo(IStatus paramIStatus);
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.IStatusHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment;

import org.eclipse.core.runtime.IStatus;

public class NullStatusHandler
  implements IStatusHandler
{
  public Choice report(IStatus status, Choice[] choices)
  {
    Choice result = null;
    if ((choices != null) && (choices.length > 0)) {
      result = choices[0];
    }
    return result;
  }
  
  public void report(IStatus status)
    throws StatusException
  {}
  
  private boolean reportErrorStatus(IStatus status)
  {
    return false;
  }
  
  public void reportError(IStatus status)
  {
    reportErrorStatus(status);
  }
  
  public void reportInfo(IStatus status) {}
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.NullStatusHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment;

import org.eclipse.core.runtime.IStatus;

public class StatusException
  extends EnvironmentException
{
  private static final long serialVersionUID = 3618141160322119992L;
  protected Choice choice;
  
  public StatusException(IStatus status)
  {
    super(status);
  }
  
  public StatusException(Choice choice)
  {
    this.choice = choice;
  }
  
  public StatusException(IStatus status, Choice choice)
  {
    super(status);
    this.choice = choice;
  }
  
  public Choice getChoice()
  {
    return choice;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.StatusException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment.uri;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public abstract interface IURI
{
  public abstract String toString();
  
  public abstract IURIScheme getURIScheme();
  
  public abstract boolean isPresent();
  
  public abstract boolean isLeaf();
  
  public abstract boolean isReadable();
  
  public abstract boolean isWritable();
  
  public abstract boolean isHierarchical();
  
  public abstract boolean isRelative();
  
  public abstract IURI parent()
    throws URIException;
  
  public abstract IURI append(IURI paramIURI)
    throws URIException;
  
  public abstract InputStream getInputStream()
    throws URIException;
  
  public abstract OutputStream getOutputStream()
    throws URIException;
  
  public abstract void touchLeaf()
    throws URIException;
  
  public abstract void touchFolder()
    throws URIException;
  
  public abstract void erase()
    throws URIException;
  
  public abstract void rename(IURI paramIURI)
    throws URIException;
  
  public abstract void visit(IURIVisitor paramIURIVisitor)
    throws URIException;
  
  public abstract void visit(IURIVisitor paramIURIVisitor, IURIFilter paramIURIFilter)
    throws URIException;
  
  public abstract IURI[] list()
    throws URIException;
  
  public abstract IURI[] list(IURIFilter paramIURIFilter)
    throws URIException;
  
  public abstract boolean isAvailableAsURL();
  
  public abstract URL asURL()
    throws URIException;
  
  public abstract boolean isAvailableAsFile();
  
  public abstract File asFile()
    throws URIException;
  
  public abstract String asString();
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.uri.IURI
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment.uri;

import java.net.URL;

public abstract interface IURIFactory
{
  public abstract IURI newURI(String paramString)
    throws URIException;
  
  public abstract IURI newURI(URL paramURL)
    throws URIException;
  
  public abstract IURIScheme newURIScheme(String paramString)
    throws URIException;
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.uri.IURIFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment.uri;

public abstract interface IURIFilter
{
  public abstract boolean accepts(IURI paramIURI)
    throws URIException;
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.uri.IURIFilter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment.uri;

import java.net.URL;
import org.eclipse.core.runtime.IStatus;

public abstract interface IURIScheme
{
  public abstract IURI newURI(String paramString)
    throws URIException;
  
  public abstract IURI newURI(URL paramURL)
    throws URIException;
  
  public abstract IURI newURI(IURI paramIURI)
    throws URIException;
  
  public abstract String toString();
  
  public abstract boolean isHierarchical();
  
  public abstract boolean isValid(IURI paramIURI);
  
  public abstract IStatus validate(IURI paramIURI);
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.uri.IURIScheme
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment.uri;

public abstract interface IURIVisitor
{
  public abstract boolean visit(IURI paramIURI)
    throws URIException;
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.uri.IURIVisitor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment.uri;

import java.net.URL;
import java.util.Hashtable;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.internal.environment.eclipse.Messages;
import org.eclipse.wst.common.internal.environment.relative.RelativeScheme;

public class SimpleURIFactory
  implements IURIFactory
{
  private Hashtable schemes_ = new Hashtable();
  
  public IURI newURI(String uri)
    throws URIException
  {
    IURIScheme scheme = newURIScheme(uri, false);
    
    return scheme.newURI(uri);
  }
  
  public IURI newURI(URL url)
    throws URIException
  {
    IURIScheme scheme = newURIScheme(url.toString(), false);
    
    return scheme.newURI(url);
  }
  
  public IURIScheme newURIScheme(String schemeOrURI)
    throws URIException
  {
    return newURIScheme(schemeOrURI, true);
  }
  
  public void registerScheme(String protocol, IURIScheme scheme)
  {
    schemes_.put(protocol, scheme);
  }
  
  private IURIScheme newURIScheme(String schemeOrURI, boolean checkForScheme)
    throws URIException
  {
    IURIScheme newScheme = null;
    if (schemeOrURI == null) {
      throw new URIException(
        new Status(4, "id", 0, 
        NLS.bind(Messages.MSG_NULL_ARG_SPECIFIED, "newURIScheme"), null));
    }
    int colon = schemeOrURI.indexOf(':');
    int slash = schemeOrURI.indexOf('/');
    if (((checkForScheme) && (colon == -1)) || 
      ((colon != -1) && (slash == -1)) || (
      (colon != -1) && (colon < slash)))
    {
      if (colon == -1) {
        colon = schemeOrURI.length();
      }
      String protocol = schemeOrURI.substring(0, colon);
      newScheme = (IURIScheme)schemes_.get(protocol);
      if (newScheme == null) {
        throw new URIException(
          new Status(4, "id", 0, 
          NLS.bind(Messages.MSG_SCHEME_NOT_FOUND, schemeOrURI), null));
      }
    }
    else
    {
      if (schemeOrURI.startsWith("/")) {
        throw new URIException(
          new Status(4, "id", 0, 
          NLS.bind(Messages.MSG_ABSOLUTE_PATH_WITHOUT_SCHEME, schemeOrURI), null));
      }
      newScheme = new RelativeScheme();
    }
    return newScheme;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.uri.SimpleURIFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.environment.uri;

import org.eclipse.core.runtime.IStatus;

public class URIException
  extends Exception
{
  private static final long serialVersionUID = 3258130271424756018L;
  protected IStatus status;
  protected IURI uri;
  
  public URIException(IStatus status)
  {
    this.status = status;
  }
  
  public URIException(IStatus status, IURI uri)
  {
    super(status != null ? status.getMessage() : null);
    this.status = status;
    this.uri = uri;
  }
  
  public IStatus getStatus()
  {
    return status;
  }
  
  public IURI getURI()
  {
    return uri;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.environment.uri.URIException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.environment.eclipse;

import org.eclipse.wst.common.environment.IEnvironment;
import org.eclipse.wst.common.environment.ILog;
import org.eclipse.wst.common.environment.IStatusHandler;
import org.eclipse.wst.common.environment.NullStatusHandler;
import org.eclipse.wst.common.environment.uri.IURIFactory;
import org.eclipse.wst.common.environment.uri.SimpleURIFactory;
import org.eclipse.wst.common.internal.environment.uri.file.FileScheme;

public class ConsoleEclipseEnvironment
  implements IEnvironment
{
  private SimpleURIFactory uriFactory_ = null;
  private IStatusHandler statusHandler_ = null;
  
  public ConsoleEclipseEnvironment()
  {
    this(new NullStatusHandler());
  }
  
  public ConsoleEclipseEnvironment(IStatusHandler statusHandler)
  {
    uriFactory_ = new SimpleURIFactory();
    statusHandler_ = statusHandler;
    
    uriFactory_.registerScheme("platform", new EclipseScheme(this));
    uriFactory_.registerScheme("file", new FileScheme());
  }
  
  public ILog getLog()
  {
    return new EclipseLog();
  }
  
  public IStatusHandler getStatusHandler()
  {
    return statusHandler_;
  }
  
  public IURIFactory getURIFactory()
  {
    return uriFactory_;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.environment.eclipse.ConsoleEclipseEnvironment
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.environment.eclipse;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.common.internal.environment.plugin.EnvironmentPlugin;

public class EclipseLog
  implements org.eclipse.wst.common.environment.ILog
{
  private org.eclipse.core.runtime.ILog logger;
  
  public EclipseLog()
  {
    Plugin plugin = EnvironmentPlugin.getInstance();
    
    logger = plugin.getLog();
  }
  
  public boolean isEnabled()
  {
    return Platform.inDebugMode();
  }
  
  public boolean isEnabled(String option)
  {
    return "true".equals(Platform.getDebugOption("org.eclipse.wst.common.environment/trace/" + 
      option));
  }
  
  public void log(int severity, int messageNum, Object caller, String method, Object object)
  {
    if (isEnabled()) {
      switch (severity)
      {
      case 4: 
        if (isEnabled("error"))
        {
          String message = getMessageNumString(messageNum) + "E " + 
            caller + "::" + method + ": object=" + 
            object;
          log(severity, message, null);
        }
        break;
      case 2: 
        if (isEnabled("warning"))
        {
          String message = getMessageNumString(messageNum) + 
            "W " + caller + "::" + method + 
            ": object=" + object;
          log(severity, message, null);
        }
        break;
      case 1: 
        if (isEnabled("info"))
        {
          String message = getMessageNumString(messageNum) + "I " + 
            caller + "::" + method + ": object=" + 
            object;
          log(severity, message, null);
        }
        break;
      }
    }
  }
  
  public void log(int severity, int messageNum, Object caller, String method, IStatus status)
  {
    log(severity, messageNum, caller, method, status);
  }
  
  public void log(int severity, int messageNum, Object caller, String method, Throwable throwable)
  {
    log(severity, messageNum, caller, method, null);
  }
  
  public void log(int severity, String option, int messageNum, Object caller, String method, Object object)
  {
    if (isEnabled(option))
    {
      String message = getMessageNumString(messageNum) + "I " + caller + 
        "::" + method + ": object=" + object;
      log(severity, message, null);
    }
  }
  
  public void log(int severity, String option, int messageNum, Object caller, String method, Throwable throwable)
  {
    if (isEnabled(option))
    {
      String message = getMessageNumString(messageNum) + "I " + caller + 
        "::" + method;
      log(severity, message, throwable);
    }
  }
  
  public void log(int severity, String option, int messageNum, Object caller, String method, IStatus status)
  {
    logger.log(status);
  }
  
  private String getMessageNumString(int messageNum)
  {
    String messageNumString = "IWAB";
    int innerMessageNum = messageNum;
    if ((innerMessageNum > 9999) || (innerMessageNum < 0)) {
      innerMessageNum = 9999;
    }
    messageNumString = messageNumString + new Integer(innerMessageNum).toString();
    return messageNumString;
  }
  
  private void log(int severity, String message, Throwable exc)
  {
    Status status = new Status(severity, "id", 0, message, exc);
    logger.log(status);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.environment.eclipse.EclipseLog
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.environment.eclipse;

import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.environment.IEnvironment;
import org.eclipse.wst.common.environment.uri.IURI;
import org.eclipse.wst.common.environment.uri.IURIScheme;
import org.eclipse.wst.common.environment.uri.URIException;
import org.eclipse.wst.common.internal.environment.relative.RelativeURI;

public class EclipseScheme
  implements IURIScheme
{
  private IEnvironment environment_;
  
  public EclipseScheme(IEnvironment environment)
  {
    environment_ = environment;
  }
  
  public String toString()
  {
    return "platform";
  }
  
  public boolean isHierarchical()
  {
    return true;
  }
  
  public boolean isValid(IURI uri)
  {
    boolean result = true;
    if (uri == null) {
      return false;
    }
    try
    {
      IURIScheme scheme = uri.getURIScheme();
      if (scheme.toString().equals("relative")) {
        return scheme.isValid(uri);
      }
      getPathFromPlatformURI(uri.toString());
    }
    catch (URIException localURIException)
    {
      result = false;
    }
    return result;
  }
  
  public IURI newURI(String uri)
    throws URIException
  {
    String newURI = null;
    if ((uri != null) && (uri.startsWith("platform:")))
    {
      newURI = uri;
    }
    else
    {
      if ((uri == null) || (uri.indexOf(":") != -1)) {
        throw new URIException(
          new Status(4, "id", 0, 
          NLS.bind(Messages.MSG_INVALID_PLATFORM_URL, uri), null));
      }
      if (uri.startsWith("/")) {
        newURI = "platform:/resource" + uri;
      }
    }
    if (newURI == null) {
      return new RelativeURI(uri);
    }
    return new EclipseURI(newURI, environment_);
  }
  
  public IURI newURI(IURI uri)
    throws URIException
  {
    return newURI(uri == null ? null : uri.toString());
  }
  
  public IURI newURI(URL url)
    throws URIException
  {
    return newURI(url == null ? null : url.toString());
  }
  
  public IStatus validate(IURI uri)
  {
    IStatus status = null;
    try
    {
      IURIScheme scheme = uri.getURIScheme();
      if (scheme.toString().equals("relative")) {
        return scheme.validate(uri);
      }
      getPathFromPlatformURI(uri.toString());
      status = Status.OK_STATUS;
    }
    catch (URIException exc)
    {
      status = exc.getStatus();
    }
    return status;
  }
  
  public String getPathFromPlatformURI(String uri)
    throws URIException
  {
    String resourceFile = null;
    URL url = null;
    try
    {
      url = new URL(uri);
    }
    catch (MalformedURLException exc)
    {
      throw new URIException(
        new Status(4, "id", 0, 
        NLS.bind(Messages.MSG_INVALID_PLATFORM_URL, uri), exc));
    }
    if (url.getProtocol().equals("platform"))
    {
      String resourceURL = url.getFile();
      if (resourceURL.startsWith("/resource")) {
        resourceFile = resourceURL.substring(10);
      }
    }
    else
    {
      throw new URIException(
        new Status(4, "id", 0, 
        NLS.bind(Messages.MSG_INVALID_PLATFORM_URL, url.getFile()), null));
    }
    return resourceFile;
  }
  
  public String getURLFromPath(IPath absolutePath)
  {
    return "platform:/resource" + absolutePath;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.environment.eclipse.EclipseScheme
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.environment.eclipse;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.environment.IEnvironment;
import org.eclipse.wst.common.environment.uri.IURI;
import org.eclipse.wst.common.environment.uri.IURIFilter;
import org.eclipse.wst.common.environment.uri.IURIScheme;
import org.eclipse.wst.common.environment.uri.URIException;
import org.eclipse.wst.common.internal.environment.relative.RelativeURI;

public class EclipseURI
  extends RelativeURI
{
  private IEnvironment environment_;
  private EclipseScheme scheme_;
  private File file_;
  
  public EclipseURI(String uri, IEnvironment environment)
  {
    super(uri);
    
    environment_ = environment;
    scheme_ = new EclipseScheme(environment);
    file_ = getFile();
  }
  
  public String toString()
  {
    return uri_;
  }
  
  public void erase()
    throws URIException
  {
    try
    {
      IResource file = getResource();
      if ((file != null) && (file.exists())) {
        if ((file instanceof IFile)) {
          FileResourceUtils.deleteFile((IFile)file, 
            environment_.getStatusHandler());
        } else if ((file instanceof IFolder)) {
          FileResourceUtils.deleteFolder((IFolder)file, 
            environment_.getStatusHandler());
        }
      }
    }
    catch (Exception exc)
    {
      throw new URIException(new Status(4, "id", 0, exc.getMessage(), exc), this);
    }
  }
  
  public InputStream getInputStream()
    throws URIException
  {
    try
    {
      IFile file = (IFile)getResource();
      if (file != null) {
        return file.getContents();
      }
    }
    catch (Throwable exc)
    {
      throw new URIException(new Status(4, "id", 0, exc.getMessage(), exc), this);
    }
    return null;
  }
  
  public OutputStream getOutputStream()
    throws URIException
  {
    IURI parent = parent();
    if (!parent.isPresent()) {
      parent().touchFolder();
    }
    return getOutStream();
  }
  
  public IURIScheme getURIScheme()
  {
    return scheme_;
  }
  
  public boolean isLeaf()
  {
    boolean result = false;
    try
    {
      IResource resource = getResource();
      if ((resource != null) && 
        (resource.exists()) && 
        (resource.getType() == 1)) {
        result = true;
      }
    }
    catch (URIException localURIException)
    {
      result = false;
    }
    return result;
  }
  
  public boolean isPresent()
  {
    boolean result = false;
    try
    {
      IResource resource = getResource();
      if ((resource != null) && (resource.exists())) {
        result = true;
      }
    }
    catch (URIException localURIException)
    {
      result = false;
    }
    return result;
  }
  
  public boolean isReadable()
  {
    boolean result = false;
    try
    {
      IResource resource = getResource();
      if ((resource != null) && (resource.isAccessible())) {
        result = true;
      }
    }
    catch (URIException localURIException)
    {
      result = false;
    }
    return result;
  }
  
  public boolean isRelative()
  {
    return false;
  }
  
  public boolean isWritable()
  {
    boolean result = false;
    try
    {
      IResource resource = getResource();
      if ((resource != null) && 
        (resource.isAccessible()) && 
        (!resource.getResourceAttributes().isReadOnly())) {
        result = true;
      }
    }
    catch (URIException localURIException)
    {
      result = false;
    }
    return result;
  }
  
  public IURI[] list()
    throws URIException
  {
    IResource resource = getResource();
    IURI[] uriChildren = new IURI[0];
    if (resource.getType() == 2)
    {
      IFolder folder = (IFolder)resource;
      try
      {
        IResource[] children = folder.members();
        
        uriChildren = new IURI[children.length];
        for (int index = 0; index < children.length; index++)
        {
          IPath path = children[index].getFullPath();
          uriChildren[index] = new EclipseURI(scheme_.getURLFromPath(path), environment_);
        }
      }
      catch (CoreException localCoreException) {}
    }
    return uriChildren;
  }
  
  public IURI[] list(IURIFilter uriFilter)
    throws URIException
  {
    IResource resource = getResource();
    IURI[] result = new IURI[0];
    if (resource.getType() == 2)
    {
      IFolder folder = (IFolder)resource;
      try
      {
        IResource[] children = folder.members();
        Vector uriChildren = new Vector();
        for (int index = 0; index < children.length; index++)
        {
          IPath path = children[index].getFullPath();
          IURI uri = new EclipseURI(scheme_.getURLFromPath(path), environment_);
          if (uriFilter.accepts(uri)) {
            uriChildren.add(uri);
          }
        }
        result = (IURI[])uriChildren.toArray(new IURI[0]);
      }
      catch (CoreException localCoreException) {}
    }
    return result;
  }
  
  public void rename(IURI newURI)
    throws URIException
  {
    if ((newURI == null) || (!(newURI instanceof EclipseURI))) {
      return;
    }
    try
    {
      EclipseURI newEclipseURI = (EclipseURI)newURI;
      IPath newPath = new Path(scheme_.getPathFromPlatformURI(uri_)).makeAbsolute();
      IResource resource = getResource();
      if (resource != null) {
        resource.move(newPath, true, null);
      }
    }
    catch (CoreException exc)
    {
      exc.printStackTrace();
      throw new URIException(new Status(4, "id", 0, exc.getMessage(), exc));
    }
  }
  
  public void touchFolder()
    throws URIException
  {
    IResource resource = getResource();
    if (resource != null)
    {
      if (resource.getType() == 2)
      {
        IFolder folder = (IFolder)resource;
        try
        {
          if (folder.members().length <= 0) {
            return;
          }
          throw new URIException(
            new Status(4, "id", 0, 
            NLS.bind(Messages.MSG_ERROR_FOLDER_HAS_CHILDREN, folder.toString()), null), 
            this);
        }
        catch (CoreException exc)
        {
          throw new URIException(new Status(4, "id", 0, exc.getMessage(), exc), this);
        }
      }
    }
    else
    {
      IPath newPath = new Path(scheme_.getPathFromPlatformURI(uri_)).makeAbsolute();
      try
      {
        FileResourceUtils.makeFolderPath(newPath, 
          environment_.getStatusHandler());
      }
      catch (CoreException exc)
      {
        throw new URIException(new Status(4, "id", 0, exc.getMessage(), exc), this);
      }
    }
  }
  
  public void touchLeaf()
    throws URIException
  {
    IResource resource = getResource();
    if (resource == null)
    {
      IURI parent = parent();
      if (!parent.isPresent()) {
        parent().touchFolder();
      }
      try
      {
        getOutStream().close();
      }
      catch (IOException exc)
      {
        throw new URIException(new Status(4, "id", 0, exc.getMessage(), exc), this);
      }
    }
  }
  
  private IResource getResource()
    throws URIException
  {
    IPath path = new Path(scheme_.getPathFromPlatformURI(uri_));
    String absolutePathname = path.makeAbsolute().toString();
    
    return FileResourceUtils.findResource(absolutePathname);
  }
  
  private OutputStream getOutStream()
    throws URIException
  {
    IPath file = new Path(scheme_.getPathFromPlatformURI(uri_)).makeAbsolute();
    OutputStream stream = null;
    
    stream = FileResourceUtils.newFileOutputStream(file, 
      environment_.getStatusHandler());
    return stream;
  }
  
  public File asFile()
  {
    return file_;
  }
  
  public boolean isAvailableAsFile()
  {
    return file_ != null;
  }
  
  public URL asURL()
    throws URIException
  {
    URL url = null;
    try
    {
      url = new URL(uri_);
    }
    catch (MalformedURLException exc)
    {
      throw new URIException(new Status(4, "id", 0, exc.getMessage(), exc), this);
    }
    return url;
  }
  
  public boolean isAvailableAsURL()
  {
    URL theURL = null;
    try
    {
      theURL = asURL();
    }
    catch (URIException localURIException) {}
    return theURL != null;
  }
  
  private File getFile()
  {
    String platformRes = "platform:/resource";
    File result = null;
    if (uri_.startsWith(platformRes)) {
      result = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().removeTrailingSeparator().append(uri_.substring(platformRes.length(), uri_.length())).toString());
    }
    return result;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.environment.eclipse.EclipseURI
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.environment.eclipse;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.wst.common.environment.IStatusHandler;

public class FileResourceOutputStream
  extends OutputStream
{
  IPath fFilePath;
  IStatusHandler fStatusHandler;
  ByteArrayOutputStream fByteArrayOutputStream;
  boolean fOpen;
  
  public FileResourceOutputStream(IPath filePath, IStatusHandler statusHandler)
  {
    fFilePath = filePath;
    fStatusHandler = statusHandler;
    fByteArrayOutputStream = new ByteArrayOutputStream();
    fOpen = true;
  }
  
  public void close()
    throws IOException
  {
    if (!fOpen) {
      return;
    }
    fOpen = false;
    fByteArrayOutputStream.close();
    byte[] buffer = fByteArrayOutputStream.toByteArray();
    ByteArrayInputStream tempInputStream = new ByteArrayInputStream(buffer);
    try
    {
      FileResourceUtils.createFile(fFilePath, tempInputStream, fStatusHandler);
    }
    catch (CoreException e)
    {
      throw new IOException(e.getMessage());
    }
  }
  
  public void flush()
    throws IOException
  {
    fByteArrayOutputStream.flush();
  }
  
  public void write(byte[] b)
    throws IOException
  {
    fByteArrayOutputStream.write(b);
  }
  
  public void write(byte[] b, int off, int len)
  {
    fByteArrayOutputStream.write(b, off, len);
  }
  
  public void write(int b)
  {
    fByteArrayOutputStream.write(b);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.environment.eclipse.FileResourceOutputStream
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.environment.eclipse;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Vector;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.environment.Choice;
import org.eclipse.wst.common.environment.IStatusHandler;
import org.eclipse.wst.common.environment.StatusException;
import org.osgi.framework.Bundle;

public final class FileResourceUtils
{
  private static IWorkspace workspace_ = null;
  private static IWorkspaceRoot root_ = null;
  
  public static IWorkspaceRoot getWorkspaceRoot()
  {
    if (root_ == null) {
      root_ = ResourcesPlugin.getWorkspace().getRoot();
    }
    return root_;
  }
  
  public static IWorkspace getWorkspace()
  {
    if (workspace_ == null)
    {
      if (root_ == null) {
        root_ = ResourcesPlugin.getWorkspace().getRoot();
      }
      workspace_ = root_.getWorkspace();
    }
    return workspace_;
  }
  
  public static Choice[] getThreeStateFileOptions()
  {
    Vector choices = new Vector();
    
    choices.add(new Choice('Y', Messages.LABEL_YES));
    choices.add(new Choice('A', Messages.LABEL_YES_TO_ALL));
    choices.add(new Choice('C', Messages.LABEL_CANCEL));
    
    return (Choice[])choices.toArray(new Choice[choices.size()]);
  }
  
  public static IResource findResource(String absolutePathname)
  {
    if (absolutePathname == null) {
      return null;
    }
    return findResource(new Path(absolutePathname));
  }
  
  public static IResource findResource(IPath absolutePath)
  {
    if (absolutePath == null) {
      return null;
    }
    return getWorkspaceRoot().findMember(absolutePath);
  }
  
  public static void copyFile(Plugin plugin, IPath sourcePath, IPath pathname, IPath targetPath, IStatusHandler statusMonitor)
    throws CoreException
  {
    try
    {
      IPath target = targetPath.append(pathname);
      IPath source = sourcePath == null ? pathname : sourcePath.append(pathname);
      InputStream input = plugin.openStream(source);
      createFile(target, input, statusMonitor);
    }
    catch (IOException e)
    {
      throw new CoreException(new Status(4, 
        plugin.getBundle().getSymbolicName(), 
        0, 
        Messages.MSG_ERROR_IO, e));
    }
  }
  
  public static boolean deleteFile(IFile file, IStatusHandler statusMonitor)
    throws CoreException
  {
    if (file.exists())
    {
      if (file.isReadOnly())
      {
        IFile[] files = new IFile[1];
        files[0] = file;
        IStatus status = getWorkspace().validateEdit(files, null);
        if (status.getSeverity() == 4)
        {
          statusMonitor.reportError(status);
          return false;
        }
      }
      file.delete(true, null);
    }
    return true;
  }
  
  public static boolean deleteFolder(IFolder folder, IStatusHandler statusMonitor)
    throws CoreException
  {
    if (!folder.exists()) {
      return true;
    }
    boolean deleted = true;
    IResource[] resources = folder.members();
    for (int i = 0; i < resources.length; i++)
    {
      IResource resource = resources[i];
      if ((resource instanceof IFile)) {
        deleted = deleteFile((IFile)resource, statusMonitor);
      }
      if ((resource instanceof IFolder)) {
        deleted = deleteFolder((IFolder)resource, statusMonitor);
      }
      if (!deleted) {
        break;
      }
    }
    if (deleted)
    {
      folder.delete(true, true, null);
      return true;
    }
    return false;
  }
  
  public static IFile createFile(IPath absolutePath, InputStream inputStream, IStatusHandler statusHandler)
    throws CoreException
  {
    if (!absolutePath.isAbsolute()) {
      throw new CoreException(new Status(4, "ResourceUtils", 0, NLS.bind(Messages.MSG_ERROR_PATH_NOT_ABSOLUTE, absolutePath.toString()), null));
    }
    if (absolutePath.segmentCount() < 1) {
      throw new CoreException(new Status(4, "ResourceUtils", 0, NLS.bind(Messages.MSG_ERROR_PATH_EMPTY, absolutePath.toString()), null));
    }
    if (absolutePath.segmentCount() < 2) {
      throw new CoreException(new Status(4, "ResourceUtils", 0, NLS.bind(Messages.MSG_ERROR_PATH_NOT_FOLDER, absolutePath.toString()), null));
    }
    IContainer parent = makeFolderPath(absolutePath.removeLastSegments(1), statusHandler);
    String fileName = absolutePath.lastSegment();
    
    return makeFile(parent, fileName, inputStream, statusHandler);
  }
  
  public static IFile createFile(IProject project, IPath relativePath, InputStream inputStream, IStatusHandler statusMonitor)
    throws CoreException
  {
    IPath absolutePath = project.getFullPath().append(relativePath);
    return createFile(absolutePath, inputStream, statusMonitor);
  }
  
  public static OutputStream newFileOutputStream(IPath file, IStatusHandler statusHandler)
  {
    return new FileResourceOutputStream(file, statusHandler);
  }
  
  public static IContainer makeFolderPath(IPath absolutePath, IStatusHandler statusHandler)
    throws CoreException
  {
    if (absolutePath.segmentCount() <= 1) {
      return getWorkspaceRoot().getProject(absolutePath.segment(0));
    }
    IContainer parent = makeFolderPath(absolutePath.removeLastSegments(1), statusHandler);
    String folderName = absolutePath.lastSegment();
    
    return makeFolder(parent, folderName, statusHandler);
  }
  
  private static IFolder makeFolder(IContainer parent, String folderName, IStatusHandler statusHandler)
    throws CoreException
  {
    IResource child = parent.findMember(folderName);
    if (child == null)
    {
      IFolder folder = parent.getFolder(new Path(folderName));
      folder.create(true, true, null);
      return folder;
    }
    if (child.getType() == 2) {
      return (IFolder)child;
    }
    throw new CoreException(
      new Status(4, 
      "ResourceUtils", 
      0, 
      
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-2019. Infinite Loop Ltd