1 4 5 9 10 package org.openlaszlo.utils; 11 12 import java.awt.geom.Rectangle2D ; 13 import java.awt.geom.AffineTransform ; 14 15 import java.io.*; 16 17 import org.openlaszlo.server.LPS; 18 import org.openlaszlo.iv.flash.api.*; 19 import org.openlaszlo.iv.flash.api.action.*; 20 import org.openlaszlo.iv.flash.api.image.*; 21 import org.openlaszlo.iv.flash.api.sound.*; 22 import org.openlaszlo.iv.flash.api.text.*; 23 import org.openlaszlo.iv.flash.util.*; 24 import org.openlaszlo.iv.flash.cache.*; 25 26 import org.apache.log4j.*; 27 28 31 public class SWFUtils { 32 33 private static Logger mLogger = Logger.getLogger(SWFUtils.class); 34 35 40 public static InputStream getErrorMessageSWF(String message) { 41 String w = LPS.getProperty("swf.error.msg.width", "400"); 42 String h = LPS.getProperty("swf.error.msg.height", "200"); 43 String p = LPS.getProperty("swf.error.msg.pixels", "14"); 44 45 int TWIP = 20; 46 47 int wd = Integer.parseInt(w); 48 int ht = Integer.parseInt(h); 49 int pi = Integer.parseInt(p); 50 51 try { 52 FlashFile file = FlashFile.newFlashFile(); 53 Script script = new Script(1); 54 script.setMain(); 55 file.setMainScript(script); 56 Frame frame = script.newFrame(); 57 String fontFileName = LPS.getMiscDirectory() + 58 File.separator + "vera.fft"; 59 60 Font font = FontDef.load(fontFileName, file); 61 Text text = Text.newText(); 62 TextItem item = new TextItem(message, font, pi*TWIP, AlphaColor.black); 63 text.addTextItem(item); 64 text.setBounds(GeomHelper.newRectangle(0, 0, wd*TWIP, ht*TWIP)); 65 frame.addInstance(text, 1, new AffineTransform (), null); 66 return file.generate().getInputStream(); 67 } catch (Exception e) { 68 return null; 70 } 71 } 72 73 76 public static boolean hasSWFHeader(InputStream is) throws IOException { 77 byte[] fileHdr = new byte[8]; 80 81 if( is.read(fileHdr, 0, 8) != 8 ) { 82 return false; 83 } 84 85 if( fileHdr[1] != 'W' || fileHdr[2] != 'S' ) { 86 return false; 87 } 88 89 if( fileHdr[0] != 'C' && fileHdr[0] != 'F' ) { 92 return false; 93 } 94 95 return true; 96 } 97 } 98 | Popular Tags |