1 50 51 package org.openlaszlo.iv.flash.url; 52 53 import java.io.*; 54 import java.net.*; 55 import java.util.*; 56 import org.openlaszlo.iv.flash.api.*; 57 import org.openlaszlo.iv.flash.util.*; 58 59 72 public abstract class IVUrl { 73 74 public static final String ENCODING = "genc"; 75 77 protected Hashtable parms; 78 79 86 public static IVUrl newUrl( String surl ) throws IVException { 87 return newUrl( surl, null ); 88 } 89 90 97 public static IVUrl newUrl( String surl, FlashFile flashFile ) throws IVException { 98 if( surl.startsWith("fgjdbc:///") ) { 99 return new JDBCUrl( surl ); 100 } else if( surl.startsWith("fgjava:///") ) { 101 return new JavaUrl( surl ); 102 } else if( surl.startsWith("fgjs:///") ) { 103 try { 105 return (IVUrl) Util.newInstance( 106 "org.openlaszlo.iv.flash.url.JSUrl", 107 new Class [] {String .class, FlashFile.class}, 108 new Object [] {surl, flashFile}); 109 } catch( Exception e ) { 110 throw new IVException(e); 111 } 112 } else if( surl.startsWith("fgfilter:///") ) { 113 return new FilterUrl( surl, flashFile ); 114 } else if ( surl.startsWith("ftp://") || surl.startsWith("fgftp://") ) { 115 try { 116 return (IVUrl) Util.newInstance( 117 "org.openlaszlo.iv.flash.url.FTPUrl", 118 new Class [] { String .class, Boolean .class }, 119 new Object [] { surl, new Boolean (surl.startsWith("fgftp://")) }); 120 } catch( Exception e ) { 121 throw new IVException(e); 122 } 123 } else { 124 try { 125 URL url = new URL(surl); 126 return new URLUrl( url ); 127 } catch( MalformedURLException e ) { 128 return new FileUrl( surl, flashFile ); 129 } 130 } 131 } 132 133 138 public abstract String getName(); 139 140 146 public abstract InputStream getInputStream() throws IOException; 147 148 156 public String getParameter( String name ) { 157 if( parms == null ) return null; 158 return (String ) parms.get(name.toLowerCase()); 159 } 160 161 166 public long lastModified() { 167 return 0; 168 } 169 170 173 public void refresh() { 174 } 175 176 182 public String getEncoding() { 183 return getParameter(ENCODING); 184 } 185 186 191 public boolean hasDataReady() { 192 return false; 193 } 194 195 199 public String [][] getData() throws IOException { 200 return null; 201 } 202 203 public String toString() { 204 return getName(); 205 } 206 207 212 public String getRef() { 213 return null; 214 } 215 216 223 protected void parse( String s ) throws IVException { 224 int idx = s.indexOf('?'); 225 if( idx >= 0 ) parse(s, idx); 226 } 227 228 235 protected void parse( String s, int idx ) { 236 parms = Util.parseUrlParms(s, idx); 237 } 238 239 245 protected InputStream arrayToStream( String [][] data ) { 246 StringBuffer sb = new StringBuffer ( data.length*data[0].length*10 ); 247 for( int i=0; i<data.length; i++ ) { 248 int ilen = data[i].length; 249 for( int j=0; j<ilen; j++ ) { 250 String s = data[i][j]; 251 if( s == null ) sb.append("\"\""); 252 else { 253 sb.append("\""); 254 sb.append(s); 255 sb.append("\""); 256 } 257 if( j+1 < ilen ) sb.append(','); 258 } 259 sb.append('\n'); 260 } 261 String str = new String ( sb ); 262 return new ByteArrayInputStream( str.getBytes() ); 263 } 264 265 } 266 | Popular Tags |