001: /*
002: * $Id: ImportAssets.java,v 1.2 2002/02/15 23:44:27 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: * Copyright (c) 2007
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are met:
013: *
014: * 1. Redistributions of source code must retain the above copyright
015: * notice, this list of conditions and the following disclaimer.
016: *
017: * 2. Redistributions in binary form must reproduce the above copyright
018: * notice, this list of conditions and the following disclaimer in
019: * the documentation and/or other materials provided with the
020: * distribution.
021: *
022: * 3. The end-user documentation included with the redistribution, if
023: * any, must include the following acknowlegement:
024: * "This product includes software developed by Dmitry Skavish
025: * (skavish@usa.net, http://www.flashgap.com/)."
026: * Alternately, this acknowlegement may appear in the software itself,
027: * if and wherever such third-party acknowlegements normally appear.
028: *
029: * 4. The name "The JGenerator" must not be used to endorse or promote
030: * products derived from this software without prior written permission.
031: * For written permission, please contact skavish@usa.net.
032: *
033: * 5. Products derived from this software may not be called "The JGenerator"
034: * nor may "The JGenerator" appear in their names without prior written
035: * permission of Dmitry Skavish.
036: *
037: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
038: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
039: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
040: * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
041: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
042: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
043: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
044: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
045: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
046: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
047: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
048: * SUCH DAMAGE.
049: *
050: */
051:
052: package org.openlaszlo.iv.flash.api;
053:
054: import java.io.PrintStream;
055: import org.openlaszlo.iv.flash.parser.*;
056: import org.openlaszlo.iv.flash.util.*;
057: import org.openlaszlo.iv.flash.commands.*;
058: import org.openlaszlo.iv.flash.context.Context;
059:
060: /**
061: * The ImportAssets2 (Flash >= 8) tag imports assets from another swf file as a linked asset.
062: * <P>
063: * "Client" swf files can import assets like fonts that are stored in "server"
064: * swfs (that are ideally cached on an end user's local system).
065: * The importing swf file references the exporting swf file with a URL.
066: * The URL needs to include the asset identifier string.
067: * Imported assets are resolved and stored in a ScriptThread's SCharacter dictionary.
068: * <BR>
069: * Note that the URL can be absolute or relative. If it's relative, it's resolved
070: * relative to the location of the importing swf file.
071: *
072: * @author Henry Minsky
073: * @see ExportAssets
074: * @see ImportedDef
075: */
076: public class ImportAssets2 extends FlashObject {
077:
078: private String url; // the url of the exporting swf file
079: private IVVector defs = new IVVector(); // imported definitions references (ImportedDef)
080: private IVVector names = new IVVector(); // imported definitions names
081:
082: public ImportAssets2() {
083: }
084:
085: public int getTag() {
086: return Tag.IMPORTASSETS2;
087: }
088:
089: public void setUrl(String url) {
090: this .url = url;
091: }
092:
093: public void addAsset(String name, FlashDef def) {
094: names.addElement(name);
095: defs.addElement(def);
096: }
097:
098: public static ImportAssets2 parse(Parser p) {
099: ImportAssets2 o = new ImportAssets2();
100: o.url = p.getString();
101: int reserved1 = p.getUByte();
102: int reserved2 = p.getUByte();
103: int num = p.getUWord();
104: o.defs = new IVVector(num);
105: o.names = new IVVector(num);
106: for (int i = 0; i < num; i++) {
107: int tagID = p.getUWord();
108: ImportedDef idef = new ImportedDef();
109: idef.setID(tagID);
110: p.addDef(idef);
111: String name = p.getString();
112: o.defs.addElement(idef);
113: o.names.addElement(name);
114: }
115: return o;
116: }
117:
118: // we should not collect defs here, it has to be done by other objects
119: /* public void collectDeps( DepsCollector dc ) {
120: }*/
121:
122: /* protected void collectFonts( FontsCollector fc ) {
123: }*/
124:
125: public void write(FlashOutput fob) {
126: int tagPos = fob.getPos();
127: fob.skip(6);
128:
129: fob.writeStringZ(url);
130: fob.writeByte(1); // reserved
131: fob.writeByte(0); // reserved
132: fob.writeWord(defs.size());
133: for (int i = 0; i < defs.size(); i++) {
134: FlashDef def = (FlashDef) defs.elementAt(i);
135: String name = (String) names.elementAt(i);
136: fob.writeDefID(def);
137: fob.writeStringZ(name);
138: }
139:
140: fob.writeLongTagAt(getTag(), fob.getPos() - tagPos - 6, tagPos);
141: }
142:
143: public void printContent(PrintStream out, String indent) {
144: out.println(indent + "ImportAssets2: url=" + url);
145: for (int i = 0; i < defs.size(); i++) {
146: FlashDef def = (FlashDef) defs.elementAt(i);
147: String name = (String) names.elementAt(i);
148: out.println(indent + " name=" + name + ", defID="
149: + def.getID());
150: }
151:
152: }
153:
154: protected boolean _isConstant() {
155: if (Util.hasVar(url))
156: return false;
157: for (int i = 0; i < names.size(); i++) {
158: String name = (String) names.elementAt(i);
159: if (Util.hasVar(name))
160: return false;
161: }
162: return true;
163: }
164:
165: public void apply(Context context) {
166: url = context.apply(url);
167: for (int i = 0; i < names.size(); i++) {
168: String name = (String) names.elementAt(i);
169: name = context.apply(name);
170: names.setElementAt(name, i);
171: }
172: }
173:
174: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
175: super .copyInto(item, copier);
176: ((ImportAssets2) item).url = url;
177: ((ImportAssets2) item).defs = defs.getCopy(copier);
178: ((ImportAssets2) item).names = (IVVector) names.clone();
179: return item;
180: }
181:
182: public FlashItem getCopy(ScriptCopier copier) {
183: return copyInto(new ImportAssets2(), copier);
184: }
185: }
|