Package net.sourceforge.javautil.common.io.impl

Examples of net.sourceforge.javautil.common.io.impl.SystemFile


  public Object coerce(Object original, Class target) {
    if (original instanceof CharSequence) {
      String url = String.valueOf( original );
      if (url.startsWith("file:/")) {
        return url.endsWith("/") || IVirtualDirectory.class.isAssignableFrom(target) ? new SystemDirectory( url.substring(6) ) : new SystemFile( url.substring(6) );
      } else if (url.startsWith(VirtualArtifactSystem.VAS_PROTOCOL + ":")) {
        String host = url.split(":")[1];
        String path = url.substring((VirtualArtifactSystem.VAS_PROTOCOL + ":" + host + ":").length());
        VirtualArtifactSystem vas = VirtualArtifactSystem.get(host, true);
        return url.endsWith("/") ? vas.getDirectory(new SimplePath(path), true) : vas.getFile(new SimplePath(path), true);
      } else {
        return url.endsWith("/") || IVirtualDirectory.class.isAssignableFrom(target) ? new SystemDirectory(url) : new SystemFile(url);
      }
    } else if (original instanceof IVirtualArtifact) {
      String url = ((IVirtualArtifact)original).getURL().toExternalForm();
      if (original instanceof IVirtualDirectory && !url.endsWith("/")) url += "/";
     
View Full Code Here


     
      if ( urlPath.startsWith("file:") ) urlPath = urlPath.substring(5);
      if ( urlPath.indexOf('!')>0 ) urlPath = urlPath.substring(0, urlPath.indexOf('!'));
     
      File file = new File(urlPath);
      return file.isDirectory() ? new SystemDirectory(file) : new ZippedDirectory(new SystemFile(file));
    } catch (UnsupportedEncodingException e) {
      throw ThrowableManagerRegistry.caught(e);
    }
  }
View Full Code Here

  /**
   * @param artifact The artifact in question
   * @return A {@link SystemFile} or a {@link SystemDirectory} wrapper depending on the type of the file
   */
  public static ISystemArtifact getSystemArtifact (File artifact) {
    return artifact.isFile() ? new SystemFile(artifact) : new SystemDirectory(artifact);
  }
View Full Code Here

 
  /**
   * @param file The file for which a {@link ISystemArtifact} is desired
   * @return A valid system artifact wrapper
   */
  public static ISystemArtifact toSystem (File file) { return file.isDirectory() ? new SystemDirectory(file) : new SystemFile(file); }
View Full Code Here

  public Object execute(GroovyCLIContext ctx, CommandLineArgumentsStandard arguments) {
    PassedArgument arg = arguments.getArgument(0);
   
    String filename = (String) arg.getValue();
    SystemFile file = new SystemFile(filename);
   
    if (file.isExists()) {
      try {
        Class clazz = compiler.parseClass(file.getInputStream());
        if (Script.class.isAssignableFrom(clazz)) {
          Script script = (Script) ReflectionUtil.newInstance(clazz, new Class[] { Binding.class }, ctx.getUI().getDomain());
          return script.run();
        } else {
          ctx.getUI().error("File is not a script: " + filename + ": " + clazz, null);
View Full Code Here

    public void setOptional(boolean optional) { this.optional = optional; }
   
    public String getSystemPath() { return systemPath; }
    public void setSystemPath(String systemPath) { this.systemPath = systemPath; }
   
    public ISystemArtifact getSystemArtifact() { return this.isSystemReference() ? new SystemFile(systemPath) : null; }
View Full Code Here

    IVirtualArtifact va = VirtualArtifactSystem.getArtifactFor(url);
    if (va == null) {
      if (url.getProtocol().equals("jar")) {
        String path = url.getPath();
        if (path.startsWith("file://")) path = path.substring(7);
        va = new ZippedDirectory(new SystemFile(path));
      } else if (url.getProtocol().equals("file")) {
        String path = url.getPath();
        File target = new File(path);
        if (target.isDirectory()) {
          va = new SystemDirectory(target);
        } else {
          if (ArchiveUtil.isArchive(target)) {
            va = new ZippedDirectory(new SystemFile(target));
          }
        }
      }
    } else {
      if (va instanceof VirtualArtifactWrapped) {
View Full Code Here

    } catch (IOException e) {
      throw ThrowableManagerRegistry.caught(new RuntimeException(url.toExternalForm(), e));
    }
  }
 
  @Override public IVirtualArtifact getVirtualArtifact() { return new SystemFile(file); }
View Full Code Here

    return "".equals(result.trim()) ? defaultDirectory : new SystemDirectory(result);
  }

  public SystemFile getFile(String prompt, SystemFile defaultFile) {
    String result = this.captureRawInput(prompt + (defaultFile != null ? "[default=" + defaultFile.getPath().toString("/") + "]" : "") + ": ");
    return "".equals(result.trim()) ? defaultFile : new SystemFile(result);
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.javautil.common.io.impl.SystemFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.