KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > iv > flash > GenUtil


1 /*
2  * $Id: GenUtil.java,v 1.4 2002/02/25 19:50:55 valis Exp $
3  *
4  * ==========================================================================
5  *
6  * The JGenerator Software License, Version 1.0
7  *
8  * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if
22  * any, must include the following acknowlegement:
23  * "This product includes software developed by Dmitry Skavish
24  * (skavish@usa.net, http://www.flashgap.com/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The name "The JGenerator" must not be used to endorse or promote
29  * products derived from this software without prior written permission.
30  * For written permission, please contact skavish@usa.net.
31  *
32  * 5. Products derived from this software may not be called "The JGenerator"
33  * nor may "The JGenerator" appear in their names without prior written
34  * permission of Dmitry Skavish.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
40  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  *
49  */

50
51 package org.openlaszlo.iv.flash;
52
53 import java.io.*;
54 import java.util.*;
55
56 import org.openlaszlo.iv.flash.api.*;
57 import org.openlaszlo.iv.flash.parser.*;
58 import org.openlaszlo.iv.flash.util.*;
59 import org.openlaszlo.iv.flash.context.*;
60
61 /**
62  * @deprecated It is now prefered to use the API directly since it has gotten
63  * easier to use, and supports more advanced features. This class
64  * only provides an interface to the most basic capabilities of
65  * JGenerator.
66  *
67  * The class provides high-level API to the JGenerator<br>
68  * <br>
69  * Usage:<br>
70  * <pre>
71  * // install directory "c:\\jgenerator-v1.1.3" and log to console
72  * GenUtil.init( "c:\\jgenerator-v1.1.3", false );
73  * ...
74  * try {
75  * // parse file
76  * Object flashFile = GenUtil.parse( "d:\\templates\\cooltemplate.swt" );<br>
77  *
78  * // define parameters. if your parameters are case unsensitive, you have to set
79  * // property iv.flash.varCaseSensitive in iv.properties file to false and add the
80  * // parameters' names in uppercase
81  * Hashtable parms = new Hashtable();
82  * parms.put( "DATASRC", "fgjdbc:///?driver=oracle.jdbc.driver.OracleDriver&url=jdbc:oracle:thin:username/password@lifu:1521:rs8i&query=select+*+from+flashtest+where+id>1" );<br>
83  *
84  * // process file with given parameters
85  * GenUtil.process( flashFile, parms );<br>
86  *
87  * // generate file
88  * InputStream is = GenUtil.generate( flashFile );<br>
89  *
90  * // write to disk
91  * OutputStream out = new FileOutputStream( "d:\\movies\\coolmovie.swf" );
92  * int size;
93  * byte[] buffer = new byte[4096];
94  * while( (size=is.read(buffer, 0, buffer.length))>0 ) out.write(buffer, 0, size);
95  * out.close();
96  * } catch( IVException e ) {
97  * Log.logRB( e );
98  * }
99  *
100  * </pre>
101  */

102 public final class GenUtil {
103
104     /**
105      * Parse specified .swt file and return instance of FlashFile object
106      *
107      * @param name name of .swt file to parse. name may be absolute or relative. in last case it's
108      * relative from the current directory.
109      * @return instance of FlashFile.
110      * @exception IVException thrown if some generator problems occured
111      * @exception FileNotFoundException thrown if the given file cannot be found
112      * @author Dmitry Skavish
113      * @version 1.0
114      */

115     public static Object JavaDoc parse( String JavaDoc name ) throws IVException, FileNotFoundException {
116         return FlashFile.parse( name );
117     }
118
119     /**
120      * Process given FlashFile object using given user parameters
121      *
122      * @param file FlashFile object obtained from parse method.
123      * @param parms Hashtable of parameters. If property iv.flash.varCaseSensitive in iv.properties file
124      * set to false then parameter names <b>have</b> to be in uppercase.
125      * @exception IVException thrown if some generator problems occured
126      * @author Dmitry Skavish
127      * @version 1.0
128      */

129     public static void process( Object JavaDoc file, Hashtable parms ) throws IVException {
130         Context context = new StandardContext(parms);
131         ((FlashFile)file).processFile(context);
132     }
133
134     /**
135      * Generate .swf file from given FlashFile
136      *
137      * @param file FlashFile object ibtained from process method
138      * @return InputStream (ByteArrayInputStream)
139      * @author Dmitry Skavish
140      * @version 1.0
141      */

142     public static InputStream generate( Object JavaDoc file ) throws IVException {
143         FlashOutput fout = ((FlashFile)file).generate();
144         return new ByteArrayInputStream(fout.getBuf(), 0, fout.getSize());
145     }
146
147     /**
148      * Initialization. Has to be called once before all the others methods.
149      *
150      * @param installDir specifies absolute path to the directory where JGenerator is installed
151      * @param logToFile if true logging will be to log file (the one listed in the iv.properties file)
152      * otherwise to console
153      * @author Dmitry Skavish
154      * @version 1.0
155      */

156     public static void init( String JavaDoc installDir, boolean logToFile ) {
157         Util.init(installDir);
158         if( !logToFile ) {
159             Log.setLogToConsole();
160         }
161     }
162
163 }
164
Popular Tags