1 50 51 package org.openlaszlo.iv.flash.api; 52 53 import java.io.PrintStream ; 54 import org.openlaszlo.iv.flash.parser.*; 55 import org.openlaszlo.iv.flash.util.*; 56 import org.openlaszlo.iv.flash.commands.*; 57 import org.openlaszlo.iv.flash.context.Context; 58 59 80 public class ExportAssets extends FlashObject { 81 82 private IVVector defs; private IVVector names; 85 public ExportAssets() {} 86 87 public int getTag() { 88 return Tag.EXPORTASSETS; 89 } 90 91 public IVVector getDefs() { 92 return defs; 93 } 94 95 public IVVector getNames() { 96 return names; 97 } 98 99 public void addAsset( String name, FlashDef def ) { 100 if( defs == null ) { 101 names = new IVVector(); 102 defs = new IVVector(); 103 } 104 names.addElement(name); 105 defs.addElement(def); 106 } 107 108 public static ExportAssets parse( Parser p ) { 109 ExportAssets o = new ExportAssets(); 110 int num = p.getUWord(); 111 o.defs = new IVVector(num); 112 o.names = new IVVector(num); 113 for( int i=0; i<num; i++ ) { 114 FlashDef def = p.getDef( p.getUWord() ); 115 String name = p.getString(); 116 if (true) { 119 o.defs.addElement( def ); 120 o.names.addElement( name ); 121 } 122 p.getFile().addDefInAssets(name.toUpperCase(), def); 125 } 126 if( o.defs.size() == 0 ) return null; 127 return o; 128 } 129 130 public void collectDeps( DepsCollector dc ) { 131 for( int i=0; i<defs.size(); i++ ) { 132 FlashDef def = (FlashDef) defs.elementAt(i); 133 dc.addDep(def); 134 } 135 } 136 137 public void collectFonts( FontsCollector fc ) { 138 for( int i=0; i<defs.size(); i++ ) { 139 FlashDef def = (FlashDef) defs.elementAt(i); 140 def.collectFonts(fc); 141 145 } 146 } 147 148 public void write( FlashOutput fob ) { 149 int tagPos = fob.getPos(); 150 fob.skip(6); 151 152 fob.writeWord( defs.size() ); 153 for( int i=0; i<defs.size(); i++ ) { 154 FlashDef def = (FlashDef) defs.elementAt(i); 155 String name = (String ) names.elementAt(i); 156 fob.writeDefID( def ); 157 fob.writeStringZ(name); 158 } 159 160 fob.writeLongTagAt( getTag(), fob.getPos()-tagPos-6, tagPos ); 161 } 162 163 public void printContent( PrintStream out, String indent ) { 164 out.println( indent+"ExportAssets:" ); 165 for( int i=0; i<defs.size(); i++ ) { 166 FlashDef def = (FlashDef) defs.elementAt(i); 167 String name = (String ) names.elementAt(i); 168 out.println(indent+" name="+name+", defID="+def.getID()); 169 } 170 } 171 172 protected boolean _isConstant() { 173 for( int i=0; i<names.size(); i++ ) { 174 String name = (String ) names.elementAt(i); 175 if( Util.hasVar(name) ) return false; 176 } 177 return true; 178 } 179 180 public void apply( Context context ) { 181 for( int i=0; i<names.size(); i++ ) { 182 String name = (String ) names.elementAt(i); 183 name = context.apply(name); 184 names.setElementAt(name, i); 185 } 186 } 187 188 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 189 super.copyInto( item, copier ); 190 ((ExportAssets)item).defs = defs.getCopy(copier); 191 ((ExportAssets)item).names = (IVVector) names.clone(); 192 return item; 193 } 194 195 public FlashItem getCopy( ScriptCopier copier ) { 196 return copyInto( new ExportAssets(), copier ); 197 } 198 } 199 | Popular Tags |