1 50 51 package org.openlaszlo.iv.flash.url; 52 53 import java.lang.reflect.*; 54 import java.io.*; 55 import java.util.*; 56 import java.net.*; 57 import java.sql.*; 58 import org.openlaszlo.iv.flash.util.*; 59 import org.openlaszlo.iv.flash.api.*; 60 61 import org.openlaszlo.iv.flash.url.filters.*; 62 63 70 public class FilterUrl extends IVUrl { 71 72 private static Hashtable filters = new Hashtable(); 73 74 private UrlFilter filter; 75 private FlashFile flashFile; 76 77 public FilterUrl( String surl, FlashFile flashFile ) throws IVException { 78 this.flashFile = flashFile; 79 parse( surl ); 80 } 81 82 protected void parse( String s ) throws IVException { 83 int idx = s.indexOf('?'); 84 if( idx < 12 ) { 85 throw new IVException(Resource.INVALURL, new Object [] {s}); 86 } 87 88 String filterName = s.substring(12, idx); 89 try { 90 synchronized(getClass()) { 91 filter = (UrlFilter) filters.get(filterName); 92 if( filter == null ) { 93 Class clazz = Class.forName("org.openlaszlo.iv.flash.url.filters."+filterName); 94 Constructor constructor = clazz.getConstructor(null); 95 filter = (UrlFilter) constructor.newInstance(null); 96 filters.put(filterName, filter); 97 } 98 } 99 } catch( Exception e ) { 100 throw new IVException(Resource.INVALURL, new Object [] {s}, e); 101 } 102 103 parse(s, idx); 104 } 105 106 public String getName() { 107 String name = filter.getClass().getName(); 108 return name.substring( name.lastIndexOf('.')+1 ); 109 } 110 111 public boolean hasDataReady() { 112 return true; 113 } 114 115 public String [][] getData() throws IOException { 116 String datasource = getParameter("datasource"); 117 String [][] data; 118 try { 119 UrlDataSource ds = new UrlDataSource(datasource,flashFile); 120 data = ds.getData(); 121 } catch( IVException e ) { 122 throw new IOException(e.getLocalizedMessage()); 123 } 124 return filter.filter(data, parms); 125 } 126 127 public InputStream getInputStream() throws IOException { 128 return arrayToStream(getData()); 129 } 130 131 } 132 133 | Popular Tags |