1 49 50 package org.openlaszlo.iv.flash.fop; 51 52 import org.openlaszlo.iv.flash.util.*; 53 54 import org.openlaszlo.iv.flash.api.*; 55 56 import org.apache.fop.apps.*; 57 import org.apache.fop.messaging.MessageHandler; 58 import org.apache.fop.viewer.*; 59 60 import org.xml.sax.*; 61 import org.apache.xerces.parsers.*; 62 63 import java.io.*; 64 import java.net.*; 65 import java.util.*; 66 67 74 75 class FOToSWF 76 { 77 private InputSource xslFOInput; 78 private OutputStream swfOutputStream; 79 80 86 87 public void setXSLFOInputSource( InputSource input_source ) 88 { 89 this.xslFOInput = input_source; 90 } 91 92 98 99 public void setOutputStream( OutputStream output_stream ) 100 { 101 this.swfOutputStream = output_stream; 102 } 103 104 107 108 public void generate( ) throws IVException, IOException, FOPException 109 { 110 FOPHelper fh = new FOPHelper(); 111 112 fh.setXSLFOInputSource( this.xslFOInput ); 113 114 fh.render(); 115 116 Script s = fh.getScript(); 117 118 FlashFile f = FlashFile.newFlashFile( ); 119 120 s.setMain(); 121 122 f.setMainScript( s ); 123 124 f.setFrameSize( fh.getMaxPageBounds() ); 125 126 FlashOutput fob = f.generate( ); 127 128 BufferedOutputStream bos = new BufferedOutputStream( this.swfOutputStream ); 129 bos.write( fob.getBuf( ), 0, fob.getSize( ) ); 130 bos.flush( ); 131 bos.close( ); 132 } 133 134 139 140 public static void main( String args[] ) 141 { 142 FOToSWF starter = new FOToSWF(); 143 String temp; 144 boolean inputFilePassed = false; 145 146 try 147 { 148 Util.init( ); 149 Log.setLogToConsole( ); 150 151 if ( args.length < 3 ) 153 { 154 printHelp( "Requierd arguments missing." ); 155 } 156 157 temp = getParameterByName( args, "-fo" ); 159 if ( temp != null ) 160 { 161 starter.setXSLFOInputSource( new InputSource( temp ) ); 162 inputFilePassed = true; 163 } 164 165 167 if ( ! inputFilePassed ) 168 { 169 printHelp( "Input file missing, use argument \"-fo <infile>\"." ); 170 } 171 172 174 temp = getParameterByName( args, "-swf" ); 175 if ( temp != null ) 176 { 177 starter.setOutputStream( new FileOutputStream( temp ) ); 178 } 179 else 180 { 181 printHelp( "Output file missing, use argument \"-swf <outfile>\"." ); 182 } 183 184 186 starter.generate( ); 187 188 System.exit( 0 ); 189 } 190 catch ( Exception e ) 191 { 192 e.printStackTrace(); 193 } 194 } 195 196 197 199 206 private static String getParameterByName( String args[], String name ) 207 { 208 for ( int i = 0; i < args.length; i++ ) 209 { 210 if ( args[ i ].equals( name ) ) 211 { 212 if ( ( i + 1 ) < args.length ) 213 return args[ i + 1 ]; 214 else 215 return null; 216 } 217 } 218 219 return null; 220 } 221 222 229 private static boolean checkParameterByName( String args[], String name ) 230 { 231 for ( int i = 0; i < args.length; i++ ) 232 { 233 if ( args[ i ].equals( name ) ) 234 return true; 235 } 236 237 return false; 238 } 239 240 245 private static void printHelp( String error_msg ) 246 { 247 System.out.println( "USAGE" ); 248 System.out.println( "" ); 249 System.out.println( "SWFStarter [options] -fo infile -swf outfile" ); 250 System.out.println( "" ); 251 System.out.println( " [INPUT]" ); 252 System.out.println( " -fo infile xsl:fo input file" ); 253 System.out.println( "" ); 254 System.out.println( " [OUTPUT]" ); 255 System.out.println( " -swf outfile input will be rendered as swf format into the outfile" ); 256 System.out.println( "" ); 257 System.out.println( " [Examples]" ); 258 System.out.println( " SWFStarter -fo myfile.fo myfile.swf" ); 259 System.out.println( "" ); 260 System.out.println( "ERROR: " + error_msg ); 261 System.out.println( "" ); 262 263 System.exit( -1 ); 264 } 265 } 266 | Popular Tags |