KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > iv > flash > api > ExportAssets


1 /*
2  * $Id: ExportAssets.java,v 1.6 2002/07/15 22:39:32 skavish 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.api;
52
53 import java.io.PrintStream JavaDoc;
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 /**
60  * Class represents ExportAssets tag
61  * <p>
62  * The ExportAssets tag exports assets from the flash file so that other flash files
63  * can ImportAssets as linked assets.
64  * <p>
65  * ExportAssets makes repetitive portions of a flash movie or a series of flash movies
66  * available for import. For example, ten flash movies that are all part of the same website can share an
67  * embedded custom font if one movie embeds the font and sets the font to "export".
68  * Exporting gives the font a special identifier string. As well as sharing embedded fonts,
69  * a flash can share other symbol types (linked assets) like movie clips, buttons and sounds.
70  * <P>
71  * Objects of this class have two vectors:<BR>
72  * <ul>
73  * <li>vector of FlashDefs
74  * <li>vector of names under which these FlashDef's are exported
75  * </ul>
76  *
77  * @author Dmitry Skavish
78  * @see ImportAssets
79  */

80 public class ExportAssets extends FlashObject {
81
82     private IVVector defs; // vector of FlashDef objects (flash definitions)
83
private IVVector names; // vector of names of definitions (from {@link #defs} vector)
84

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 JavaDoc 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 JavaDoc name = p.getString();
116             // if name starts with jgenerator prefix do not add it, it's our library
117
// if( !name.startsWith(PropertyManager.mxLibrarySymbolPrefix) ) {
118
if (true) {
119                 o.defs.addElement( def );
120                 o.names.addElement( name );
121             }
122             // add definition to file export table
123
// !!! possible problem with apply(), it does not update export table
124
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             // I am not sure about this, it has to be checked !!!!!!!!!!
142
/*if( def instanceof FontDef ) {
143                 defs.setElementAt( fc.addFont((FontDef)def), i );
144             }*/

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 JavaDoc name = (String JavaDoc) 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 JavaDoc out, String JavaDoc indent ) {
164         out.println( indent+"ExportAssets:" );
165         for( int i=0; i<defs.size(); i++ ) {
166             FlashDef def = (FlashDef) defs.elementAt(i);
167             String JavaDoc name = (String JavaDoc) 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 JavaDoc name = (String JavaDoc) 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 JavaDoc name = (String JavaDoc) 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