1 50 51 package org.openlaszlo.iv.flash.util; 52 53 import java.io.*; 54 import java.util.*; 55 56 import org.openlaszlo.iv.flash.api.*; 57 import org.openlaszlo.iv.flash.url.*; 58 import org.openlaszlo.iv.flash.xml.*; 59 60 import org.w3c.dom.*; 61 62 69 public class DataSourceHelper { 70 71 84 public static Object readContextData( String surl, FlashFile flashFile ) 85 throws IVException, IOException 86 { 87 if( surl == null || surl.length() == 0 ) { 88 throw new IOException( "null datasource" ); 89 } 90 91 Object dsrc = null; 92 93 if( surl.charAt(0) == '#' ) { 94 if( surl.charAt(1) == '<' ) { 95 byte[] bytes = flashFile.getEncoding() != null? 97 surl.substring(1).getBytes(flashFile.getEncoding()): 98 PropertyManager.defaultEncoding != null? 99 surl.substring(1).getBytes(PropertyManager.defaultEncoding): 100 surl.substring(1).getBytes(); 101 dsrc = new BufferedUrl( new FlashBuffer(bytes) ); 102 } else { 103 dsrc = new NativeLineReader(surl); 105 } 106 } else { 107 int idx = surl.indexOf(';'); 108 if( idx == -1 ) { 109 dsrc = new BufferedUrl( surl, flashFile ); 110 } else { 111 StringTokenizer st = new StringTokenizer(surl, ";"); 112 IVVector urls = new IVVector(); 113 while( st.hasMoreTokens() ) { 114 IVUrl url = IVUrl.newUrl( st.nextToken(), flashFile ); 115 urls.addElement(url); 116 } 117 dsrc = new MultipleUrlsReader(urls, flashFile); 118 } 119 } 120 121 if( dsrc instanceof BufferedUrl ) { 122 BufferedUrl burl = (BufferedUrl) dsrc; 123 byte[] buf = burl.getFlashBuffer().getBuf(); 124 if( !(buf.length > 3 && (buf[0] == '<' || (buf[0] == -1 && buf[1] == -2 && buf[2] == '<'))) ) { 125 dsrc = Util.getUrlReader(flashFile, burl); 126 } 127 } 128 129 return dsrc; 130 } 131 132 146 public static Object getContextData( String surl, FlashFile flashFile ) 147 throws IVException, IOException 148 { 149 Object dsrc = readContextData(surl, flashFile); 150 151 if( dsrc instanceof LineReader ) { 152 DataSource ds = new DataSource( (LineReader) dsrc ); 153 String [][] data = ds.getData(); 154 return data; 155 } else { 156 try { 157 return XMLHelper.getNode( (IVUrl) dsrc ); 158 } catch( Exception e ) { if( e instanceof IOException ) throw (IOException) e; 160 throw new IVException(e); 161 } 162 } 163 164 } 165 166 } 167 | Popular Tags |