001: /*
002: * $Id: GenUtil.java,v 1.4 2002/02/25 19:50:55 valis Exp $
003: *
004: * ==========================================================================
005: *
006: * The JGenerator Software License, Version 1.0
007: *
008: * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * 2. Redistributions in binary form must reproduce the above copyright
017: * notice, this list of conditions and the following disclaimer in
018: * the documentation and/or other materials provided with the
019: * distribution.
020: *
021: * 3. The end-user documentation included with the redistribution, if
022: * any, must include the following acknowlegement:
023: * "This product includes software developed by Dmitry Skavish
024: * (skavish@usa.net, http://www.flashgap.com/)."
025: * Alternately, this acknowlegement may appear in the software itself,
026: * if and wherever such third-party acknowlegements normally appear.
027: *
028: * 4. The name "The JGenerator" must not be used to endorse or promote
029: * products derived from this software without prior written permission.
030: * For written permission, please contact skavish@usa.net.
031: *
032: * 5. Products derived from this software may not be called "The JGenerator"
033: * nor may "The JGenerator" appear in their names without prior written
034: * permission of Dmitry Skavish.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: */
050:
051: package org.openlaszlo.iv.flash;
052:
053: import java.io.*;
054: import java.util.*;
055:
056: import org.openlaszlo.iv.flash.api.*;
057: import org.openlaszlo.iv.flash.parser.*;
058: import org.openlaszlo.iv.flash.util.*;
059: import org.openlaszlo.iv.flash.context.*;
060:
061: /**
062: * @deprecated It is now prefered to use the API directly since it has gotten
063: * easier to use, and supports more advanced features. This class
064: * only provides an interface to the most basic capabilities of
065: * JGenerator.
066: *
067: * The class provides high-level API to the JGenerator<br>
068: * <br>
069: * Usage:<br>
070: * <pre>
071: * // install directory "c:\\jgenerator-v1.1.3" and log to console
072: * GenUtil.init( "c:\\jgenerator-v1.1.3", false );
073: * ...
074: * try {
075: * // parse file
076: * Object flashFile = GenUtil.parse( "d:\\templates\\cooltemplate.swt" );<br>
077: *
078: * // define parameters. if your parameters are case unsensitive, you have to set
079: * // property iv.flash.varCaseSensitive in iv.properties file to false and add the
080: * // parameters' names in uppercase
081: * Hashtable parms = new Hashtable();
082: * 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>
083: *
084: * // process file with given parameters
085: * GenUtil.process( flashFile, parms );<br>
086: *
087: * // generate file
088: * InputStream is = GenUtil.generate( flashFile );<br>
089: *
090: * // write to disk
091: * OutputStream out = new FileOutputStream( "d:\\movies\\coolmovie.swf" );
092: * int size;
093: * byte[] buffer = new byte[4096];
094: * while( (size=is.read(buffer, 0, buffer.length))>0 ) out.write(buffer, 0, size);
095: * out.close();
096: * } catch( IVException e ) {
097: * Log.logRB( e );
098: * }
099: *
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 parse(String name) throws IVException,
116: FileNotFoundException {
117: return FlashFile.parse(name);
118: }
119:
120: /**
121: * Process given FlashFile object using given user parameters
122: *
123: * @param file FlashFile object obtained from parse method.
124: * @param parms Hashtable of parameters. If property iv.flash.varCaseSensitive in iv.properties file
125: * set to false then parameter names <b>have</b> to be in uppercase.
126: * @exception IVException thrown if some generator problems occured
127: * @author Dmitry Skavish
128: * @version 1.0
129: */
130: public static void process(Object file, Hashtable parms)
131: throws IVException {
132: Context context = new StandardContext(parms);
133: ((FlashFile) file).processFile(context);
134: }
135:
136: /**
137: * Generate .swf file from given FlashFile
138: *
139: * @param file FlashFile object ibtained from process method
140: * @return InputStream (ByteArrayInputStream)
141: * @author Dmitry Skavish
142: * @version 1.0
143: */
144: public static InputStream generate(Object file) throws IVException {
145: FlashOutput fout = ((FlashFile) file).generate();
146: return new ByteArrayInputStream(fout.getBuf(), 0, fout
147: .getSize());
148: }
149:
150: /**
151: * Initialization. Has to be called once before all the others methods.
152: *
153: * @param installDir specifies absolute path to the directory where JGenerator is installed
154: * @param logToFile if true logging will be to log file (the one listed in the iv.properties file)
155: * otherwise to console
156: * @author Dmitry Skavish
157: * @version 1.0
158: */
159: public static void init(String installDir, boolean logToFile) {
160: Util.init(installDir);
161: if (!logToFile) {
162: Log.setLogToConsole();
163: }
164: }
165:
166: }
|