001: /*
002: * $Id: ExportAssets.java,v 1.6 2002/07/15 22:39:32 skavish 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.api;
052:
053: import java.io.PrintStream;
054: import org.openlaszlo.iv.flash.parser.*;
055: import org.openlaszlo.iv.flash.util.*;
056: import org.openlaszlo.iv.flash.commands.*;
057: import org.openlaszlo.iv.flash.context.Context;
058:
059: /**
060: * Class represents ExportAssets tag
061: * <p>
062: * The ExportAssets tag exports assets from the flash file so that other flash files
063: * can ImportAssets as linked assets.
064: * <p>
065: * ExportAssets makes repetitive portions of a flash movie or a series of flash movies
066: * available for import. For example, ten flash movies that are all part of the same website can share an
067: * embedded custom font if one movie embeds the font and sets the font to "export".
068: * Exporting gives the font a special identifier string. As well as sharing embedded fonts,
069: * a flash can share other symbol types (linked assets) like movie clips, buttons and sounds.
070: * <P>
071: * Objects of this class have two vectors:<BR>
072: * <ul>
073: * <li>vector of FlashDefs
074: * <li>vector of names under which these FlashDef's are exported
075: * </ul>
076: *
077: * @author Dmitry Skavish
078: * @see ImportAssets
079: */
080: public class ExportAssets extends FlashObject {
081:
082: private IVVector defs; // vector of FlashDef objects (flash definitions)
083: private IVVector names; // vector of names of definitions (from {@link #defs} vector)
084:
085: public ExportAssets() {
086: }
087:
088: public int getTag() {
089: return Tag.EXPORTASSETS;
090: }
091:
092: public IVVector getDefs() {
093: return defs;
094: }
095:
096: public IVVector getNames() {
097: return names;
098: }
099:
100: public void addAsset(String name, FlashDef def) {
101: if (defs == null) {
102: names = new IVVector();
103: defs = new IVVector();
104: }
105: names.addElement(name);
106: defs.addElement(def);
107: }
108:
109: public static ExportAssets parse(Parser p) {
110: ExportAssets o = new ExportAssets();
111: int num = p.getUWord();
112: o.defs = new IVVector(num);
113: o.names = new IVVector(num);
114: for (int i = 0; i < num; i++) {
115: FlashDef def = p.getDef(p.getUWord());
116: String name = p.getString();
117: // if name starts with jgenerator prefix do not add it, it's our library
118: // if( !name.startsWith(PropertyManager.mxLibrarySymbolPrefix) ) {
119: if (true) {
120: o.defs.addElement(def);
121: o.names.addElement(name);
122: }
123: // add definition to file export table
124: // !!! possible problem with apply(), it does not update export table
125: p.getFile().addDefInAssets(name.toUpperCase(), def);
126: }
127: if (o.defs.size() == 0)
128: return null;
129: return o;
130: }
131:
132: public void collectDeps(DepsCollector dc) {
133: for (int i = 0; i < defs.size(); i++) {
134: FlashDef def = (FlashDef) defs.elementAt(i);
135: dc.addDep(def);
136: }
137: }
138:
139: public void collectFonts(FontsCollector fc) {
140: for (int i = 0; i < defs.size(); i++) {
141: FlashDef def = (FlashDef) defs.elementAt(i);
142: def.collectFonts(fc);
143: // I am not sure about this, it has to be checked !!!!!!!!!!
144: /*if( def instanceof FontDef ) {
145: defs.setElementAt( fc.addFont((FontDef)def), i );
146: }*/
147: }
148: }
149:
150: public void write(FlashOutput fob) {
151: int tagPos = fob.getPos();
152: fob.skip(6);
153:
154: fob.writeWord(defs.size());
155: for (int i = 0; i < defs.size(); i++) {
156: FlashDef def = (FlashDef) defs.elementAt(i);
157: String name = (String) names.elementAt(i);
158: fob.writeDefID(def);
159: fob.writeStringZ(name);
160: }
161:
162: fob.writeLongTagAt(getTag(), fob.getPos() - tagPos - 6, tagPos);
163: }
164:
165: public void printContent(PrintStream out, String indent) {
166: out.println(indent + "ExportAssets:");
167: for (int i = 0; i < defs.size(); i++) {
168: FlashDef def = (FlashDef) defs.elementAt(i);
169: String name = (String) names.elementAt(i);
170: out.println(indent + " name=" + name + ", defID="
171: + def.getID());
172: }
173: }
174:
175: protected boolean _isConstant() {
176: for (int i = 0; i < names.size(); i++) {
177: String name = (String) names.elementAt(i);
178: if (Util.hasVar(name))
179: return false;
180: }
181: return true;
182: }
183:
184: public void apply(Context context) {
185: for (int i = 0; i < names.size(); i++) {
186: String name = (String) names.elementAt(i);
187: name = context.apply(name);
188: names.setElementAt(name, i);
189: }
190: }
191:
192: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
193: super .copyInto(item, copier);
194: ((ExportAssets) item).defs = defs.getCopy(copier);
195: ((ExportAssets) item).names = (IVVector) names.clone();
196: return item;
197: }
198:
199: public FlashItem getCopy(ScriptCopier copier) {
200: return copyInto(new ExportAssets(), copier);
201: }
202: }
|