1 50 51 package org.openlaszlo.iv.flash.url; 52 53 import java.io.*; 54 import java.net.*; 55 import org.openlaszlo.iv.flash.util.*; 56 import org.openlaszlo.iv.flash.api.*; 57 58 59 64 public class FileUrl extends IVUrl { 65 66 private File file; 67 private String ref; 68 69 75 public FileUrl( String absolutePath ) throws IVException { 76 int idx = absolutePath.lastIndexOf('#'); 77 if( idx >= 0 ) { 78 ref = absolutePath.substring(idx+1); 79 absolutePath = absolutePath.substring(0, idx); 80 } 81 absolutePath = parseFilePath(absolutePath); 82 file = new File(absolutePath); 83 check(); 84 } 85 86 93 public FileUrl( String name, String path ) throws IVException { 94 file = new File(parseFilePath(path), Util.translatePath(name)); 95 check(); 96 } 97 98 105 public FileUrl( String surl, FlashFile flashFile ) throws IVException { 106 int idx = surl.lastIndexOf('#'); 107 if( idx >= 0 ) { 108 ref = surl.substring(idx+1); 109 surl = surl.substring(0, idx); 110 } 111 String fileurl = parseFilePath(surl); 112 file = new File(fileurl); 113 if( !file.isAbsolute() && flashFile != null ) 114 file = new File(flashFile.getFileDir(), file.getPath()); 115 check(); 116 } 117 118 private String parseFilePath( String s ) throws IVException { 119 int idx = s.indexOf('?'); 120 if( idx >= 0 ) { 121 parse(s, idx); 122 s = s.substring(0,idx); 123 } 124 return Util.translatePath(s); 125 } 126 127 private void check() throws IVException { 128 if( !file.exists() || !file.isFile() ) 129 throw new IVException( Resource.FILENOTFOUND, new Object [] {file.getAbsolutePath()} ); 130 } 131 132 public String getName() { 133 return file.getAbsolutePath(); 134 } 135 136 public long lastModified() { 137 return file.lastModified(); 138 } 139 140 public String getRef() { 141 return ref; 142 } 143 144 public InputStream getInputStream() throws IOException { 145 return new FileInputStream(file); 146 } 147 148 } 149 | Popular Tags |